-
Notifications
You must be signed in to change notification settings - Fork 99
(feat) O3-3230: Add rule builder to interactive builder #450
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
base: main
Are you sure you want to change the base?
Conversation
Size Change: +43.9 kB (+1.11%) Total Size: 4.02 MB
ℹ️ View Unchanged
|
e5217ba
to
36cb0b8
Compare
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 @NethmiRodrigo! I realize a bunch of these are nit-picky, but I think one or two of these really need to be addressed.
@@ -21,6 +21,7 @@ module.exports = { | |||
'^dexie$': '<rootDir>/node_modules/dexie', | |||
'^react-i18next$': '<rootDir>/__mocks__/react-i18next.js', | |||
'react-markdown': '<rootDir>/__mocks__/react-markdown.tsx', | |||
'^uuid$': '<rootDir>/node_modules/uuid', |
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'd probably prefer either 'uuid'
or 'require.resolve('uuid')'
here rather than hard-coding a path in node_modules
.
@@ -88,6 +88,7 @@ | |||
"@typescript-eslint/eslint-plugin": "^7.9.0", | |||
"@typescript-eslint/parser": "^7.9.0", | |||
"css-loader": "^6.11.0", | |||
"dayjs": "^1.11.11", |
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.
IIRC, dayjs should be parked as a peer dep.
|
||
export const RuleProvider: React.FC<RuleProviderProps> = ({ children }) => { | ||
const [rules, setRules] = useState<Array<FormRule>>(); | ||
const cachedRules = useMemo(() => rules, [rules]); |
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 think there's a good reason to use useMemo()
on a result from useState()
. This seems like pure overhead.
export const RuleProvider: React.FC<RuleProviderProps> = ({ children }) => { | ||
const [rules, setRules] = useState<Array<FormRule>>(); | ||
const cachedRules = useMemo(() => rules, [rules]); | ||
const updateRules = useCallback((newRules: Array<FormRule>) => setRules(newRules), [setRules]); |
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.
Ditto here. Instead of wrapping in a callback, just pass setRules
from useState()
const rulesForQuestionIndex = rules?.findIndex((rule: FormRule) => rule?.question === question?.id); | ||
const rulesForQuestion = | ||
rulesForQuestionIndex !== -1 && rulesForQuestionIndex !== undefined | ||
? rules?.filter((rule: FormRule) => rule?.question === question?.id) | ||
: [{ id: uuidv4(), isNewRule: false, question: question?.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.
This seems like it could be re-written to be much simpler:
const rulesForQuestionIndex = rules?.findIndex((rule: FormRule) => rule?.question === question?.id); | |
const rulesForQuestion = | |
rulesForQuestionIndex !== -1 && rulesForQuestionIndex !== undefined | |
? rules?.filter((rule: FormRule) => rule?.question === question?.id) | |
: [{ id: uuidv4(), isNewRule: false, question: question?.id }]; | |
const rulesForQuestion = rules?.filter((rule: FormRule) => rule?.question === question?.id) ?? | |
[{ id: uuidv4(), isNewRule: false, question: question?.id }]; |
|
||
interface CustomComboBoxProps { | ||
id: string; | ||
items: Array<Record<string, string>>; |
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.
Shouldn't the type here be a little more specific? I.e., we require a label
property for this to work and it seems like we also expect a concept
property... and ignore anything else.
} | ||
.combobox .multiSelect { | ||
position: relative; | ||
bottom: 8px;// Adjust the z-index to a higher value to ensure it's on top |
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.
- There are a bunch of rules here specified using
px
. All of these should be changed torem
measurements. - The comment here is, um... ???
const prevPageIndex = useRef(-1); | ||
const prevSectionIndex = useRef(-1); | ||
const prevQuestionIndex = useRef(-1); |
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'm a little concerned that these are really intended to be states rather than refs.
* Generates the condition expression based on the provided parameters. | ||
*/ | ||
const getSchemaCondition = ( | ||
condition: string, |
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.
Shouldn't condition
here have a stricter type, i.e., to correspond to the set of known conditions?
*/ | ||
const getArguments = useCallback((expression: string) => { | ||
switch (expression) { | ||
case 'BMI': |
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 general, we seem to have a lot of these that switch on labels rather than some sort of language-independent key, which means that this makes it harder to (eventually) translate this part of the app.
Requirements
Summary
This PR integrates rule builder component into form builder, which provides an user-interface rule builder to build conditional logic for the forms in the form builder. Basically the PR #279, I've made a new PR because I worked off a new branch.
This feature is not under a feature flag, because I'd like us to get feedback on this.
Screenshots
Related Issue
https://issues.openmrs.org/browse/O3-3230
Other