Skip to content

Commit

Permalink
(fix): Add min and max values to the JSON schema
Browse files Browse the repository at this point in the history
  • Loading branch information
NethmiRodrigo committed Aug 29, 2024
1 parent 8fd8745 commit 9da98c3
Show file tree
Hide file tree
Showing 5 changed files with 343 additions and 8 deletions.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,5 @@
"*.{ts,tsx}": "eslint --cache --fix --max-warnings 0",
"*.{css,scss,ts,tsx}": "prettier --write --list-different"
},
"packageManager": "[email protected]",
"resolutions": {
"@openmrs/openmrs-form-engine-lib": "portal:/Users/denniskigen/Code/openmrs/openmrs-form-engine-lib",
"@carbon/react": ">1.47.0 <1.50.0"
}
"packageManager": "[email protected]"
}
14 changes: 14 additions & 0 deletions src/components/interactive-builder/add-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
datePickerType && { datePickerFormat: datePickerType }),
questionOptions: {
rendering: renderingType,
...(min && { min }),
...(max && { max }),
...(selectedConcept && { concept: selectedConcept?.uuid }),
...(conceptMappings.length && { conceptMappings }),
...(selectedAnswers.length && {
Expand Down Expand Up @@ -476,13 +478,25 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
id="min"
labelText="Min"
value={min || ''}
invalid={parseInt(min) > parseInt(max)}
invalidText={
parseInt(min) > parseInt(max)
? t('invalidMinMax', 'Min value cannot be greater than max')
: ''
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setMin(event.target.value)}
required
/>
<TextInput
id="max"
labelText="Max"
value={max || ''}
invalid={parseInt(min) > parseInt(max)}
invalidText={
parseInt(min) > parseInt(max)
? t('invalidMinMax', 'Min value cannot be greater than max')
: ''
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setMax(event.target.value)}
required
/>
Expand Down
14 changes: 12 additions & 2 deletions src/components/interactive-builder/edit-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
const [patientIdentifierTypeToLookup, setPatientIdentifierTypeToLookup] = useState('');
const [fieldType, setFieldType] = useState<RenderType | null>(questionToEdit.questionOptions.rendering);
const [isQuestionRequired, setIsQuestionRequired] = useState(false);
const [max, setMax] = useState('');
const [min, setMin] = useState('');
const [max, setMax] = useState(questionToEdit.questionOptions.max ?? '');
const [min, setMin] = useState(questionToEdit.questionOptions.min ?? '');
const [questionId, setQuestionId] = useState('');
const [questionLabel, setQuestionLabel] = useState('');
const [questionType, setQuestionType] = useState<QuestionType | null>(null);
Expand Down Expand Up @@ -277,6 +277,8 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
}),
questionOptions: {
rendering: fieldType ? fieldType : questionToEdit.questionOptions.rendering,
...(min && { min }),
...(max && { max }),
...((selectedConcept || questionToEdit.questionOptions.concept) && {
concept: selectedConcept ? selectedConcept.uuid : questionToEdit.questionOptions.concept,
conceptMappings: conceptMappings?.length ? conceptMappings : questionToEdit.questionOptions.conceptMappings,
Expand Down Expand Up @@ -444,13 +446,21 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
id="min"
labelText="Min"
value={min || ''}
invalid={parseInt(min) > parseInt(max)}
invalidText={
parseInt(min) > parseInt(max) ? t('invalidMinMax', 'Min value cannot be greater than max') : ''
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setMin(event.target.value)}
required
/>
<TextInput
id="max"
labelText="Max"
value={max || ''}
invalid={parseInt(min) > parseInt(max)}
invalidText={
parseInt(min) > parseInt(max) ? t('invalidMinMax', 'Min value cannot be greater than max') : ''
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setMax(event.target.value)}
required
/>
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"inputDummySchema": "Input dummy schema",
"interactiveBuilder": "Interactive Builder",
"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.",
"invalidMinMax": "Min value cannot be greater than max",
"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.",
"labelPlaceholder": "e.g. Type of Anaesthesia",
Expand Down
Loading

0 comments on commit 9da98c3

Please sign in to comment.