-
Notifications
You must be signed in to change notification settings - Fork 31
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
Run openByDefault: true
on initRepeatingGroups
#1106
Conversation
Hmm! I think this is something we absolutely should support, as it is kind-of the point behind the |
It seems to break every test where it tries to go through the group step fast (this injects formData?). The group test itself works fine though. It also works to go through frontend-test normally. It is kind of a nightmare to debug the repeating group functionality in the sagas, this is by far the most complicated saga-logic we have right? |
Tests are passing now - great! 🥳
Test the use-case, not the saga. That is, it might be time for us to add a second page in |
Yes this should be relatively straightforward to test if a new page is added. Luckily the tests passed, so I did not have to try to figure out any subtle error in the sagas for now 😅 |
Update: having now added a test case for this by injecting a new layoutPage (and intercepting page order). It is now clear that this very simple fix does not work in the general case. It worked in the SSB app because they are using ProcessdataWrite, which calls initRepeatingGroups again when it changes the data. This caused the group length of the second group to be updated properly when the data changes elsewhere, but this does not happen when not using dataprocessing. Then the question is how to deal with that. InitRepeatingGroups is relatively heavy? And maybe we dont want to call that over and over again? Looking for some feedback on this one. @olemartinorg Will leave this as a draft until we figure out the way forward. |
Kudos, SonarCloud Quality Gate passed! |
If we take a step back to look at what is happening here, is it correct to say that:
In time, I want us to migrate over to a new way of storing the data model in app-frontend-react, which also allows us to store empty groups/objects (which the backend supports, but we throw away). That also means that we should store the In other words, I think this might be a bigger/systemic issue that we should solve at the appropriate level. Instead of quick-fixes and patches, we should make sure our state is stored and manipulated in the way we try to make it look like it does. |
Yes I agree, a quick fix in this case would be to constantly run initRepeatingGroups, but that would probably hurt performance and would just make the code even worse. So I also think this should be handled as a part of refactoring this logic as you suggest. So we should probably just close this PR? |
@bjosttveit Sadly, yep - I think that's best for now. The solution, especially the solution to #555 has been considered to be a breaking change, so maybe we need to introduce a v4 with the proper change at some point. |
Description
This small change fixes an edge-case experienced by SSB. In short, there are two repeating groups working on the same array, they each set parts of the data in the array. The first group has openByDefault: true which causes a new element to be added when entering the first group. The second group has openByDefault: first to open the first row created by the first group. The problem seems to be that, the "first" logic for the second group happens on page load and will not fire because there are no elements in the group at that point. The logic where it opens a new row when empty happens when the react component loads; this will not run either since at that point the first group has already added elements so it is no longer empty. Running the "first" logic again can be problematic since we dont want to just open the first element multiple times. This solution instead runs the normal openByDefault logic (where it adds a new element) also in the initRepeatingGroups (on page load). The consequences of this is that in the groupContainer, the openByDefault logic will not have to run the first time (since it checks the length). The other consequence is that it will set the index (length) and editIndex to 0, making it open. It seems that if multiple rows are added to the first group it will update the length of the second repeating group as well when saving, and importantly, it preserves the editIndex; so it behaves as expected.
I guess I lied when I said "in short" 😅
Fell free to point out any potential problems I might have missed. If it turns out to be too complicated to fix I think we don't have to, as using several groups on the same data is not something we officially support.
Related Issue(s)
Verification/QA
src/layout/layout.d.ts
andlayout.schema.v1.json
, and these are all backwards-compatiblekind/*
label to this PR for proper release notes grouping