-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: [DHIS2-12544] Add verbose logging to rules engine #3480
Changes from 5 commits
48f00f0
3bc87ae
0ab68f9
5f935db
df09bef
5808152
e33c14a
672511d
7416b7b
e53bc1a
f128b1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,5 +230,5 @@ export type IConvertOutputRulesEffectsValue = {| | |
|}; | ||
|
||
export type Flag = { | ||
debug: boolean | ||
verbose: boolean, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @flow | ||
import { useEffect } from 'react'; | ||
import { useLocationQuery } from '../utils/routing'; | ||
import { rulesEngine } from './rulesEngine'; | ||
|
||
export const useRuleEngineFlags = () => { | ||
// This hook is used to set the verbose flag on the rules engine | ||
// based on the verbose query param in the URL | ||
|
||
const { verbose } = useLocationQuery(); | ||
|
||
const updateFlags = (flags) => { | ||
rulesEngine.setFlags({ ...rulesEngine.getFlags(), ...flags }); | ||
}; | ||
|
||
useEffect(() => { | ||
if (verbose === 'true') { | ||
updateFlags({ verbose: true }); | ||
} else { | ||
updateFlags({ verbose: false }); | ||
} | ||
}, [verbose]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this approach we can in theory run the rules engine before the verbose flag has been set, because an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No special thoughts behind it, just choosing useEffect over useLayoutEffect by default. Switched now 👍 |
||
}; |
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.
As far as I can tell, this will cause the App component to re-render every time the url changes. Consequently, all children will render unless we have a
PureComponent
in the chain. I think it would be beneficial to use aPureComponent
as the child where we use this hook (For a function component: Wrap it in aMemo
).