Auto-save in new Item Submission form breaks the form#960
Auto-save in new Item Submission form breaks the form#960tdonohue merged 20 commits intoDSpace:mainfrom
Conversation
|
This pull request introduces 2 alerts when merging 4a1c1bf into aa8feb0 - view on LGTM.com new alerts:
|
There was a problem hiding this comment.
Thanks @alemarte!
Everything seems to work well, barring the exceptions you mention in the description.
I do have some inline code comments though.
A note to other reviewers: autosave is disabled by default you need to set environment.submission.autosave.timer to something higher than 0. Also note that the unit is minutes not milliseconds like other periods in the environment file
src/app/submission/form/footer/submission-form-footer.component.ts
Outdated
Show resolved
Hide resolved
tdonohue
left a comment
There was a problem hiding this comment.
@alemarte : I gave this a review & test as well. First, the code looks good overall, but I agree with all the feedback that @artlowel gives above (so those areas should be resolved). I added one general comment inline that I think the timer should be converted to milliseconds -- but that could be done in a follow-up PR (not required here, but it looks like a small change to me).
I tested this by running yarn start and setting the timer: 1 (one minute). It mostly works, but I noticed the following oddities:
- First, if I click around in the submission form (I think it happened when I clicked into the Abstract field), I occasionally see this error appear in Chrome DevTools. This error doesn't seem to affect the submission form, but it should be fixed if possible:
ERROR TypeError: Cannot read property 'includes' of undefined at section-form.component.ts:230 at Array.forEach (<anonymous>) at l.hasMetadataEnrichment (section-form.component.ts:229) at l.updateForm (section-form.component.ts:294) at t._next (section-form.component.ts:352) at t.__tryOrUnsub (Subscriber.js.pre-build-optimizer.js:194) at t.next (Subscriber.js.pre-build-optimizer.js:132) at t._next (Subscriber.js.pre-build-optimizer.js:76) at t.next (Subscriber.js.pre-build-optimizer.js:53) at t._next (distinctUntilChanged.js.pre-build-optimizer.js:55) - I noticed that when the auto-save triggers, I no longer see a notification that the form was saved (in the upper right). I'm assuming that was removed on purpose? I'm OK with it's removal if it caused issues, I just was surprised by it.
- Finally, the first form section never shows the green checkbox unless I enter a name in the "template row" (first row). Here's how I triggered that:
- I opened the form,
- I first entered a name, clicked "Add".
- Then entered a Title & Date
- I still see an orange exclamation mark (even though all required fields now have values).
- If I go back to the Author field and typed something in the "Last Name" of the template row, then it immediately turned into a green checkbox.
- Strangely, I'm also occasionally able to generate an invalid PATCH (HTTP 500 response). I've not yet narrowed down how to reproduce this reliably. But, it occurred when I tried to reproduce (3) above without a file attached. In that scenario, I was again able to reproduce (3) but also started getting 500 responses from the backend each time the autosave triggered. The 500 response seems to be caused by the PATCH payload is trying to "add" and "remove" the same author field multiple times in a single payload (literally the payload has "add" of an author name, then a "remove" then a second "remove" and then an "add" of the same name again). This one may be harder to reproduce though, so I'm uncertain whether it's this PR at fault.
If I turn off autosave (set timer: 0), then I no longer can reproduce (1), (2) or (4). However, (3) still seems to exist.
As most of these issues seem related to the Author field (a repeatable field), it's possible they are all related to #971 (and the issues described in this ticket description). So, I'm OK with this PR moving forward (once other feedback is resolved) since it disables autosave by default. We could move these other issues to the discussion in #971.
| metadata: [], | ||
| // NOTE: every how many minutes submission is saved automatically | ||
| timer: 5 | ||
| timer: 0 |
There was a problem hiding this comment.
I would prefer that we switch this timer to milliseconds (as all other time-based configs use milliseconds instead of minutes). I see that in submission.service.ts, we already are using this timer config to calculate the milliseconds anyways.
While I realize this timer was not created by this PR, I wanted to note this preference as it seems like something that could be easily fixed in this PR & it'd align better with our other configurations. But, if others disagree, we could fix this in a future PR.
There was a problem hiding this comment.
@tdonohue timer has been refactored to handle milliseconds. Still investigating on the other feedbacks...
There was a problem hiding this comment.
- The section metadata is computed asynchronously, so an extra check sounds reasonable in that case. I added it here
- The notifications are displayed only on manual savings (accordingly to the wrapping up comment related to the 835)
- This is the very big side effect of the template row of repeatable fields and is the problem I labeled with (1)
- Is the problem I labeled with (2). The current implementation fix the 'displayed value', but internally form data structures aren't always consistent with the model they'd expect to be.
|
This pull request fixes 1 alert when merging 23cb3bb into 17ca2c4 - view on LGTM.com fixed alerts:
|
Disable autosave when timer is equal to 0
Label Add on Form Array inputs.
Notifications are disabled for submission section savings.
Notifications are enable only for manual submission savings.
Store additions: 1. Form AdditionalData: contains the list of the touched metadata 2. Submission metadata: contains the list of the metadata ids assignable for each section We keep also track whether a section ha focused fields or not.
Autosave deactivated
Section formId added to the section state. Error filtering during the parsing of the submission response.
Minor changes and cleanup.
Lint corrections.
Section metadata dispatched to the store and retrieved in subscription. Added test case for hasMetadataEnrichment.
Test FormSetAdditionalAction.
Section Metadata field tested. Form Touched filter tested.
Submission form Save button disabled when no pending operations are present
Fixed unused imports.
Methods renaming
Autosave timer switched to milliseconds.
Improved form touched state in ngrx store.
|
This pull request introduces 1 alert and fixes 1 when merging 042d2e7 into e867bad - view on LGTM.com new alerts:
fixed alerts:
|
Minor fixes and method computeSectionConfiguredMetadata tested
|
This pull request introduces 1 alert and fixes 1 when merging 8e77fac into e867bad - view on LGTM.com new alerts:
fixed alerts:
|
|
@artlowel @tdonohue I've addressed all your feedbacks. I'll comment all of them in a minute. |
Fixed unused imports.
|
This pull request fixes 1 alert when merging 6cf6dee into e867bad - view on LGTM.com fixed alerts:
|
tdonohue
left a comment
There was a problem hiding this comment.
👍 Looks good to me now, @alemarte ! Your feedback makes sense, and (as you noted) several of my previously reported issues will be resolved in #971 (which is a follow-up ticket to this one).
Therefore, I'm OK with merging this as-is, since it definitely improves the behavior of auto-save. Further fixes/improvements will be made in the solution to #971 (see that ticket for more details).
…e#960) [DSC-1306] feature: client health check Approved-by: Giuseppe Digilio
References
Major issue related to this PR: Fixes #835
Other involved issues are:
#948
#864
#884
#882
#931
Before describing the approach adopted in this PR, it is useful to summarise the problems that it directly or indirectly tries to address.
Having investigated them for a long time, it has been possible to trace the root causes of these problems.
Problems caused by the template/zero row of repeatable fields
Even if the field is correct from an application point of view, the template row is a real form field and follows the validation rules attached to the repeatable field. For this reason we can see a section-level warning. Required repeatable fields get validated incorrectly in submission form #931
Problems caused by the repeatable field without form redrawing
This approach forces the native flow from the used angular library and doesn't work with many of the models implemented in DSPACE, which would need custom patching logic. During submission some Repeatable fields stop working after a few inserts #948
Problems caused by the repeatable field with redraw
Problems caused by lookup functionality
The selected value is not added to the form, but a save submission is evoked. Once the data returns from the server, the form is redrawn.
Problems caused by form redraw
At this moment all the above problems except (5), (6) and (3) (which is a side effect) are mitigated by the redraw which is extremely frequent. The more you reduce the frequency of redraw, the more these problems arise.
But it is clear that redraw in turn causes many side effects and ideally should be avoided as much as possible.
Current workaround to all this mess
Moreover:
We tried to save the focused state of the section in order to postpone the form redraw which causes the emptying of populated fields and the loss of the focus field (6).
The result is that sometimes the redraw is not evoked at all as the user goes from one field to another without ever leaving the form. So we decided to revert (but still in commit history).
It doesn't solve in any way (1) whose fix, as already stated, is expensive to implement and unmaintainable.
Ideal solution: remove the template row from the repeatable field control
Removing the template row from the repeatable fields immediately fix (1), (2), (3).
The added submission's metadata into the store reduces the redraw so that the user experience is fluid most of the time. The redraw remains in case of interaction with lookups.
Moreover
Implementing the lookup so that it directly patches the form could be more than welcome.
Leave the redraw as the only strategy in case the server actually enriches the form with additional data.
In that case a notification will be displayed to the user and it would probably be acceptable to lose the information about the touched fields and have a solution more clean and maintainable.
Checklist
yarn run lintpackage.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.