Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) O3-3947: Add toggle type questions to interactive builder #350

Merged
merged 14 commits into from
Sep 26, 2024
Merged
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
31 changes: 31 additions & 0 deletions src/components/interactive-builder/add-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
programWorkflow?.uuid,
);
const [programWorkflows, setProgramWorkflows] = useState<Array<ProgramWorkflow>>([]);
const [toggleLabelTrue, setToggleLabelTrue] = useState('');
const [toggleLabelFalse, setToggleLabelFalse] = useState('');

const renderTypeOptions = {
control: ['text'],
Expand Down Expand Up @@ -244,6 +246,12 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
programUuid: selectedProgram.uuid,
workflowUuid: programWorkflow.uuid,
}),
...(renderingType === 'toggle' && {
toggleOptions: {
labelTrue: toggleLabelTrue,
labelFalse: toggleLabelFalse,
},
}),
},
validators: [],
};
Expand Down Expand Up @@ -495,6 +503,29 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setRows(event.target.value)}
required
/>
) : renderingType === 'toggle' ? (
<div>
<TextInput
id="labelTrue"
labelText={t('labelTrue', 'Label true')}
value={t(toggleLabelTrue || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setToggleLabelTrue(event.target.value)
}
placeholder={t('On')}
required
/>
<TextInput
id="labelFalse"
labelText={t('labelFalse', 'Label false')}
value={t(toggleLabelFalse || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setToggleLabelFalse(event.target.value)
}
placeholder={t('Off')}
required
/>
</div>
) : null}

{renderingType !== 'ui-select-extended' && (
Expand Down
27 changes: 27 additions & 0 deletions src/components/interactive-builder/edit-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
questionToEdit?.questionOptions.concept &&
questionToEdit?.questionOptions?.concept !== selectedConcept?.uuid;
const [addInlineDate, setAddInlineDate] = useState(false);
const [toggleLabelTrue, setToggleLabelTrue] = useState(questionToEdit?.questionOptions?.toggleOptions?.labelTrue);
const [toggleLabelFalse, setToggleLabelFalse] = useState(questionToEdit?.questionOptions?.toggleOptions?.labelFalse);

// Maps the data type of a concept to a date picker type.
const datePickerTypeOptions: Record<string, Array<DatePickerTypeOption>> = {
Expand Down Expand Up @@ -300,6 +302,12 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
: questionToEdit.questionOptions.attributeType,
...(selectedProgram && { programUuid: selectedProgram.uuid }),
...(programWorkflow && { workflowUuid: programWorkflow.uuid }),
...(fieldType === 'toggle' && {
toggleOptions: {
labelTrue: toggleLabelTrue,
labelFalse: toggleLabelFalse,
},
}),
},
};

Expand Down Expand Up @@ -463,6 +471,25 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setRows(event.target.value)}
required
/>
) : fieldType === 'toggle' ? (
<div>
<TextInput
id="lableTrue"
labelText={t('labelTrue', 'Label true')}
value={t(toggleLabelTrue || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setToggleLabelTrue(event.target.value)}
placeholder={t('on', 'On')}
required
/>
<TextInput
id="lableFalse"
labelText={t('labelFalse', 'Label false')}
value={t(toggleLabelFalse || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setToggleLabelFalse(event.target.value)}
placeholder={t('off', 'Off')}
required
/>
</div>
) : null}

{questionToEdit.type === 'patientIdentifier' && (
Expand Down
1 change: 1 addition & 0 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const configSchema = {
'text',
'textarea',
'ui-select-extended',
'toggle',
],
},
showSchemaSaveWarning: {
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export interface QuestionOptions {
showDate?: string;
programUuid?: string;
workflowUuid?: string;
toggleOptions?: {
labelTrue: string;
labelFalse: string;
};
NethmiRodrigo marked this conversation as resolved.
Show resolved Hide resolved
}

export interface Answer {
Expand Down
2 changes: 2 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
"interactiveBuilderHelperText": "The Interactive Builder lets you build your form schema without writing JSON code. The Preview tab automatically updates as you build your form. When done, click Save Form to save your form.",
"invalidVersionWarning": "Version can only start with with a number",
"isQuestionRequiredOrOptional": "Is this question a required or optional field? Required fields must be answered before the form can be submitted.",
"labelTrue": "Label true",
"labelFalse": "Label false",
"labelPlaceholder": "e.g. Type of Anaesthesia",
"lastEditedBy": "Last Edited By",
"loading": "Loading",
Expand Down