-
Notifications
You must be signed in to change notification settings - Fork 59
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) Multi-select component to initialise and display consistently in edit mode #258
Conversation
Size Change: -51 B (0%) Total Size: 1.13 MB ℹ️ View Unchanged
|
thanks @samuelmale LGTM |
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.
A few changes, else looks good to me.
Thanks!
const selectOptions = question.questionOptions.answers | ||
.filter((answer) => !answer.isHidden) | ||
.map((answer, index) => ({ | ||
id: `${question.id}-${answer.concept}`, | ||
concept: answer.concept, | ||
label: answer.label, | ||
key: index, | ||
disabled: answer.disable?.isDisabled, | ||
})); |
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 we memoise this?
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.
In my first approach memoised it but for some reason (will be addressed during the formik migration), some state events weren't properly being propagated. An example is the answer.disable. isDisabled
. This property is computable based on skip logic, when I have it like:
const selectOptions = useMemo(
() =>
question.questionOptions.answers
.filter((answer) => !answer.isHidden)
.map((answer, index) => ({
id: `${question.id}-${answer.concept}`,
concept: answer.concept,
label: answer.label,
key: index,
disabled: answer.disable?.isDisabled,
})),
[question],
);
The new state computation of answer.disable?.isDisabled
doesn't get propagated after skip logic runs. I guess it's the same reason why it wasn't memoised originally.
return selectOptions.filter((item) => field.value?.includes(item.concept)); | ||
} | ||
return []; | ||
}, [isFieldInitializationComplete, field.value]); |
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.
counter
, setCounter
and selectOptions
will also be a dependency.
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.
Well yes but we don't need to subscribe to them to evaluate the initiallySelectedQuestionItems
.
- Subscribing to
selectOptions
introduces a weird bug (I had it as a dep in my initial implementation). - We evaluate the state only if the
counter
is 0 so we don't have to subscribe to it.
…n edit mode (#258) * Centralise select-options state * Use filter
Requirements
Summary
This aims to fix an issue with the multi-select component where it doesn't preselect previously selected values while in edit mode.
Screenshots
https://www.loom.com/share/6a7b2ac48ff7430ba25e6a75da42c1d3
Related Issue
https://openmrs.atlassian.net/browse/O3-3135
Other