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; 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 [