fix: create new event - save button not working #4
Merged
MiquelAdell merged 2 commits intoversion-101.33.1from May 13, 2025
Merged
fix: create new event - save button not working #4MiquelAdell merged 2 commits intoversion-101.33.1from
MiquelAdell merged 2 commits intoversion-101.33.1from
Conversation
anagperal
approved these changes
Apr 29, 2025
anagperal
left a comment
There was a problem hiding this comment.
thanks @MatiasArriola ! [code-only review]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue: https://app.clickup.com/t/86987atgk
Problem: Save button is unresponsive / does nothing
Cause: In
withSaveHandler.jsthesectionsInitialisedprop isfalse, preventing the call tovalidateAndSave.sectionsInitializedreturns false in case there is any element in the redux stateformsSectionsFieldsUI.singleEvent-newEvent[dataElementId]that does not have thevalidkey.It was observed that under some conditions, dataElements were left out without its
validflag, causing the form to incorrectly not be "initialized", thus preventing save and causing a confusing behavior. Two different scenarios for this behavior were identified.These
validflags are updated after any field change (or just focus/blur), that triggers the rule engine execution.The UI does not give any feedback about pending validations, and some elements may get stuck never getting validated.
Other confusing scenario is that clicking save does nothing, then after changing a field, the save would trigger (without clicking save again), since
waitForFieldValidationsstate becomes false aftersectionsInitializedbecomes true. (withSaveHandler#componentDidUpdate).Cause 1: Navigation and actions dispatched in an incorrect order
It is expected that the redux actions are dispatched in the following order to get the expected state:
1 -
loadNewDataEntry2 -
updateRulesEffectHowever, if you are in the list view, create new event, go back to the list, and create a new event again,
updateRulesEffectwould trigger beforeloadNewDataEntry. This leads to unexpected state.Initial load:
After navigation:
loadNewDataEntryis dispatched afterupdateRulesEffectand between other actions.It would eventually sort itself after some field changes that trigger
UpdateRulesEffects, but inbetween It could lead to the "save not working" issue.Cause:
useRulesEnginehook is a useEffect that triggers theupdateRulesEffect, but sinceformFoundationis cached in subsequent uses, it is triggered beforeloadNewDataEntry.Fix: 699793c Workaround adding a flag based on the observed state, to prevent dispatching the event earlier.
Change risk: low/moderate. This hook is only used in
NewEventDataEntryWrapper.component.jsCause 2: HIDEFIELD inside HIDESECTION programRuleActions
In our instance we had two specific dataElements that were left "orphaned", without setting its
validproperty in theformsSectionsFieldsUIstate.These two fields were targeted by HIDEFIELD actions, and also included in sections targeted by HIDESECTION actions.
The form would only allow saving when the HIDEFIELD action is triggered. Otherwise it would never be updated with the
validflag.Cause:
When the form first loads, it triggers
UpdateRulesEffectswhich includes in the payload a HIDEFIELD and an ASSIGN null for the dataElement. This adds the dataElement to theformsSectionsFieldsUIstate with only the property{ touched: true }(as with the rest of the dataElements). This is coming from theuseRulesEnginehook.After any change to a field,
UpdateRulesEffectsis triggered again, but this time as part of theRulesEffectsForNewSingleEventActionsBatch. This is triggered incapture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/epics/newEventDataEntry.epics.js#runRulesForNewSingleEventThis time, validations are run, and the
validflag is set for each dataElement.For the affected dataElements, the ASSIGN effect would not be included if the HIDEFIELD action condition is not met (but still hidden by its parent section - its
validprop is not set).Fix: 4b1dbc7 include all hidefield effects (with the ones from HIDESECTION) when calculating the subsequent assign effects, so later the dataElement can be validated.
Change risk: high. This is a core function.
Closing thoughts
These changes are just workarounds that need thorough testing (especially "cause 2" fix).
Better fixes that would imply bigger changes might be:
validprop as a mean to check if validations are complete, and use other piece of state or signaling forsectionsInitializedandwaitForFieldValidationsin order to avoid similar issues in the future.UpdateRulesEffects.Sorry for the long text! Will update if anything can be further clarified and or simplified