-
Notifications
You must be signed in to change notification settings - Fork 85
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
(fix)O3-4320: Remove Irrelevant Properties When Changing Question Type #391
base: main
Are you sure you want to change the base?
Conversation
@NethmiRodrigo review required..! |
className={styles.deleteObsGroupQuestionButton} | ||
> | ||
{t('deleteQuestion', 'Delete question')} | ||
{t('deleteQuestion', 'Delete')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change won’t affect the UI since the translation string needs to be updated first. The correct code should be: {t('delete', 'Delete')}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @harshthakkr,
I appreciate your suggestion. However, I’d like to keep the label as "Delete question" because it clearly indicates the action is specific to deleting a question. Since our translation file already includes the key "deleteQuestion" mapped to "Delete question", this provides the necessary context for users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, looks fine!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Bharath-K-Shetty! A couple of suggestions:
@@ -29,6 +29,75 @@ interface QuestionModalProps { | |||
resetIndices: () => void; | |||
} | |||
|
|||
/** | |||
* Mapping of allowed top‑level property keys for each question type. | |||
* Adjust these keys as needed for your implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we allow implementations to change something, its usually to be done through the config schema, since that isn't the case, I'd remove this comment
* Adjust these keys as needed for your implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok @NethmiRodrigo i will remove that comment..!
setFormField((prevFormField) => ({ | ||
...prevFormField, | ||
questions: prevFormField.questions?.filter((_, i) => i !== index) || [], | ||
questions: prevFormField.questions?.filter((q) => q.id !== id) || [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this accidental? Please revert the changes done to the delete question function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't know how it changed maybe accidental..!i will revert it..!
control: ['id', 'label', 'type', 'questionOptions'], | ||
encounterDatetime: ['id', 'label', 'type', 'questionOptions', 'datePickerFormat'], | ||
encounterLocation: ['id', 'label', 'type', 'questionOptions'], | ||
encounterProvider: ['id', 'label', 'type', 'questionOptions'], | ||
encounterRole: ['id', 'label', 'type', 'questionOptions'], | ||
obs: ['id', 'label', 'type', 'questionOptions', 'required'], | ||
obsGroup: ['id', 'label', 'type', 'questionOptions', 'questions'], | ||
patientIdentifier: ['id', 'label', 'type', 'questionOptions'], | ||
testOrder: ['id', 'label', 'type', 'questionOptions'], | ||
programState: ['id', 'label', 'type', 'questionOptions'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we have a requiredProperties array that stores the common required properties so you don't have to define it for every question type? Like:
const requiredProperties = ['id', 'label', 'type', 'questionOptions'];
613401b
to
e4b491f
Compare
e4b491f
to
a360ece
Compare
@NethmiRodrigo updated the pr..! |
Requirements
Summary
This PR implements functionality to clean up form field data when a user changes a question's type in the form builder. A mapping of allowed properties for each question type is defined, and a helper function (cleanFormFieldForType) ensures that only the properties relevant to the newly selected question type are retained. The solution also cleans the nested questionOptions object based on a separate mapping, ensuring required keys like "rendering" remain intact.
Screenshots
Screen.Recording.2025-02-10.183846.mp4
Related Issue
https://openmrs.atlassian.net/browse/O3-4320
Other