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

(fix)O3-4320: Remove Irrelevant Properties When Changing Question Type #391

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Bharath-K-Shetty
Copy link
Contributor

@Bharath-K-Shetty Bharath-K-Shetty commented Feb 10, 2025

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

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

@Bharath-K-Shetty
Copy link
Contributor Author

@NethmiRodrigo review required..!

@NethmiRodrigo NethmiRodrigo self-requested a review February 11, 2025 11:57
className={styles.deleteObsGroupQuestionButton}
>
{t('deleteQuestion', 'Delete question')}
{t('deleteQuestion', 'Delete')}
Copy link
Contributor

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')}.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem, looks fine!

Copy link
Collaborator

@NethmiRodrigo NethmiRodrigo left a 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.
Copy link
Collaborator

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

Suggested change
* Adjust these keys as needed for your implementation.

Copy link
Contributor Author

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) || [],
Copy link
Collaborator

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.

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 don't know how it changed maybe accidental..!i will revert it..!

Comment on lines 37 to 46
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'],
Copy link
Collaborator

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'];

@Bharath-K-Shetty
Copy link
Contributor Author

@NethmiRodrigo updated the pr..!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants