From 699793c11c9a721c0668082566d6befe4dd5e275 Mon Sep 17 00:00:00 2001 From: Matias Arriola Date: Fri, 4 Apr 2025 12:29:03 -0300 Subject: [PATCH 1/2] fix: avoid early dispatch of getRulesActions --- .../DataEntryWrapper/useRulesEngine.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/useRulesEngine.js b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/useRulesEngine.js index 61e646ec29..b8b3a435da 100644 --- a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/useRulesEngine.js +++ b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/useRulesEngine.js @@ -24,8 +24,11 @@ export const useRulesEngine = ({ // The problem is the helper methods that take the entire state object. // Refactor the helper methods (getCurrentClientValues, getCurrentClientMainData in rules/actionsCreator) to be more explicit with the arguments. const state = useSelector(stateArg => stateArg); + + // HACK: use this flag as a workaround to avoid dispatching getRulesActions when formFoundation is cached + const isNewForm = useSelector(stateArg => stateArg.formsSectionsFieldsUI['singleEvent-newEvent'] === undefined); useEffect(() => { - if (orgUnit && program && !!formFoundation) { + if (orgUnit && program && !!formFoundation && isNewForm) { dispatch(batchActions([ getRulesActions({ state, @@ -43,6 +46,7 @@ export const useRulesEngine = ({ program, orgUnit, formFoundation, + isNewForm, ]); return !!orgUnit && orgUnitRef.current === orgUnit; From 4b1dbc71884ced9617b55bdd8f44b7eb9586517b Mon Sep 17 00:00:00 2001 From: Matias Arriola Date: Fri, 4 Apr 2025 12:33:41 -0300 Subject: [PATCH 2/2] fix: include hideSectionFieldEffects in the call to postProcessAssignEffects --- .../rules/__tests__/postProcessRulesEffects.test.js | 5 +++++ .../capture-core/rules/postProcessRulesEffects.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core_modules/capture-core/rules/__tests__/postProcessRulesEffects.test.js b/src/core_modules/capture-core/rules/__tests__/postProcessRulesEffects.test.js index de1e01cabb..a70bd9f210 100644 --- a/src/core_modules/capture-core/rules/__tests__/postProcessRulesEffects.test.js +++ b/src/core_modules/capture-core/rules/__tests__/postProcessRulesEffects.test.js @@ -178,6 +178,11 @@ test('Post process rules effects', () => { type: 'ASSIGN', value: null, }, + { + id: 'da1Id', + type: 'ASSIGN', + value: null, + }, { id: 'w75KJ2mc4zz', type: 'ASSIGN', diff --git a/src/core_modules/capture-core/rules/postProcessRulesEffects.js b/src/core_modules/capture-core/rules/postProcessRulesEffects.js index 3cb446f70a..4079b0264d 100644 --- a/src/core_modules/capture-core/rules/postProcessRulesEffects.js +++ b/src/core_modules/capture-core/rules/postProcessRulesEffects.js @@ -143,7 +143,7 @@ export function postProcessRulesEffects( foundation, // $FlowFixMe assignValueEffects, - hideFieldEffects, + hideFieldEffects: filteredHideFieldEffects, }); return [