Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DO
$$
BEGIN
IF register_patch('addMultiInstrumentJustification.sql', 'Zachary Hankin', 'Adds the option to request justification for multiple instrument use from the user', '2026-6-15') THEN
UPDATE questions
SET default_config = jsonb_set(
default_config::jsonb,
'{multiJustificationRequired}',
'false'::jsonb,
true
)
WHERE data_type = 'INSTRUMENT_PICKER';
END IF;
END;
$$
LANGUAGE plpgsql;
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const instrumentPickerDefinition: Question<DataType.INSTRUMENT_PICKER> =
config.isMultipleSelect = false;
config.requestTime = false;
config.readPermissions = [];
config.multiJustificationRequired = false;

return config;
},
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/resolvers/types/FieldConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ export class InstrumentPickerConfig extends ConfigBase {

@Field(() => Boolean)
requestTime: boolean;

@Field(() => Boolean)
multiJustificationRequired: boolean;
}

@ObjectType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const QuestionInstrumentPickerFormCommon = ({
const [showIsMultipleSelectCheckbox, setShowIsMultipleSelectCheckbox] =
useState(config.variant === 'dropdown');

const [showJustification, setShowJustification] = useState(false);

return (
<>
<TitledContainer label="Constraints">
Expand Down Expand Up @@ -54,17 +56,6 @@ export const QuestionInstrumentPickerFormCommon = ({
/>
</FormControl>

{showIsMultipleSelectCheckbox && (
<Field
name="config.isMultipleSelect"
component={CheckboxWithLabel}
type="checkbox"
Label={{
label: 'Is multiple select',
}}
data-cy="is-multiple-select"
/>
)}
<Field
name="config.requestTime"
component={CheckboxWithLabel}
Expand All @@ -74,6 +65,28 @@ export const QuestionInstrumentPickerFormCommon = ({
}}
data-cy="request-time"
/>
{showIsMultipleSelectCheckbox && (
<Field
name="config.isMultipleSelect"
component={CheckboxWithLabel}
type="checkbox"
Label={{ label: 'Is multiple select' }}
data-cy="is-multiple-select"
// Using onInput instead of onChange because onChange overwrites the formik handler.
onInput={(event: React.ChangeEvent<HTMLInputElement>) => {
setShowJustification(event.target.checked);
}}
/>
)}
{showIsMultipleSelectCheckbox && showJustification && (
<Field
name="config.multiJustificationRequired"
component={CheckboxWithLabel}
type="checkbox"
Label={{ label: 'Justification Required for Multi Instruments' }}
data-cy="is-multi-just-req"
/>
)}
</TitledContainer>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ export function QuestionaryComponentInstrumentPicker(
{config.requestTime && requestTimeForInstrument && (
<DynamicTimeFields />
)}
{config.requestTime &&
requestTimeForInstrument &&
config.multiJustificationRequired && (
<TextField
key={'Multi-Instrument Justification textbox'}
required={config.multiJustificationRequired}
error={isError}
label={`Justify multiple instrument use:`}
type="string"
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => {
onComplete(e.target.value);
}}
/>
)}
{isError && <DisplayErrorMessage />}
</FormControl>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ fragment fieldConfig on FieldConfig {
readPermissions
isMultipleSelect
requestTime
multiJustificationRequired
instruments {
id
name
Expand Down
Loading