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 4 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="lableTrue"
NethmiRodrigo marked this conversation as resolved.
Show resolved Hide resolved
labelText={t('Label true', 'Label true')}
NethmiRodrigo marked this conversation as resolved.
Show resolved Hide resolved
value={t(toggleLabelTrue || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setToggleLabelTrue(event.target.value)
}
placeholder={t('On')}
required
/>
<TextInput
id="lableFalse"
NethmiRodrigo marked this conversation as resolved.
Show resolved Hide resolved
labelText={t('Label false', 'Lable false')}
NethmiRodrigo marked this conversation as resolved.
Show resolved Hide resolved
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('');
const [toggleLabelFalse, setToggleLabelFalse] = useState('');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should initialize these values to show the existing labels since this is in the edit modal.
We would have to update the interfaces in types.ts to add toggleOptions to questionOptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated this together with the issues you had requested in the closed PR.You can look at it


// 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('Label true', 'Label true')}
value={t(toggleLabelTrue || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setToggleLabelTrue(event.target.value)}
placeholder={t('On')}
required
/>
<TextInput
id="lableFalse"
labelText={t('Label false', 'Lable false')}
value={t(toggleLabelFalse || '')}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setToggleLabelFalse(event.target.value)}
placeholder={t('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 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.",
"Label false": "Lable false",
"Label true": "Label true",
NethmiRodrigo marked this conversation as resolved.
Show resolved Hide resolved
"labelPlaceholder": "e.g. Type of Anaesthesia",
"lastEditedBy": "Last Edited By",
"loading": "Loading",
Expand All @@ -129,6 +131,8 @@
"noMatchingFormsToDisplay": "No matching forms to display",
"noSchemaLoaded": "No schema loaded",
"noValidationErrorsFound": "No validation errors found",
"Off": "",
"On": "",
"optional": "Optional",
"pageCreated": "New page created",
"pageDeleted": "Page deleted",
Expand Down
Loading