-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add collapsible feature in forms #3642
Conversation
part1.mov |
part2.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please tell why useBlockerHandler
didn't work for you? If there is a bug with useBlockerHandler then it would be important to know about it and fix it.
If it's just a matter of having to add parentResource
prop, then surely it's simpler than creating a context and two React.useEffects with setTimeouts?
Please tell if there are issues with the following:
useBlockerHandler(parentResource, relationship, hangleExpand);
Simply add this prop to FormTable:
readonly parentResource: SpecifyResource<AnySchema> | undefined;
And in IntegratedRecordSelector, just add this to FormTableCollection:
parentResource={collection.related}
(and no need even to change anything in FormTableCollection)
specifyweb/frontend/js_src/lib/components/FormCells/FormTable.tsx
Outdated
Show resolved
Hide resolved
@maxpatiiuk I used in this latest version "useAllSaveBlockers", it makes the code way more easy to read and I could get rid of the context and avoid a few line of code 👍 ps: the behavior is the same than on the video with the new code, if there is an error in one of the subform it will uncollapse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CarolineDenis the useBlockerHandler hook is intended to automatically uncollapse the subview if the user clicks on the "Save" button, rather than prevent the user from collapsing the subview if there is an error (based on a 2 second timer - a cludge). I was thinking uncollapsing on save button click rather than timer would be less confusing to the user, but am open to suggestions. |
For example consider a case where a field in a collapsed subview becomes invalid as part of an edit to a field outside the subview. That could happen because of business rules. That could also happen because (on xml-editor branch) users can embed the fields from a dependent -to-one relationship directly on the main form, without using a sub view. |
And even if you want to go with the current approach, I still don't think a timer is the right approach. Why not just disable the collapse button if there is an error OR even better, when user clicks on the button, focus the error field instead of collapsing? (that can be done by calling form.reportValidity(). You can add Just look at how few usages of setTimeout there are in the codebase - and all of them are there for a good reason (i.e, for performance, or for auto-dismissing messages) |
@maxpatiiuk, if using useBlockerHandler: there is an error because the form is not focusable see screen shots. |
Feature request: either hide the add/remove buttons when view is collapsed, OR better: expand the subview when add/remove/slider is pressed. |
specifyweb/frontend/js_src/lib/components/FormCells/FormTable.tsx
Outdated
Show resolved
Hide resolved
specifyweb/frontend/js_src/lib/components/FormCells/FormTable.tsx
Outdated
Show resolved
Hide resolved
that seems like a bug (either with the hook or with your code). That shouldn't be happening as |
specifyweb/frontend/js_src/lib/components/FormSliders/IntegratedRecordSelector.tsx
Outdated
Show resolved
Hide resolved
Fix all of the remaining issues mentioned in the PR (#3642)
I fixed all of the remaining issues and fixed the suggested changed and opened a separate PR - #3680 My fix didn't use setTimeout and didn't use useBlockerHandler. I opened a separate PR so that you have a choice of fixing all the issues on your own on this branch and only afterward looking at that PR for reference/suggestions, OR continuing with that PR instead of this one. If you want to carry over just that single commit from that branch to this, you could type In either case, the code should still undergo testing as I did only basic testing |
specifyweb/frontend/js_src/lib/components/FormSliders/IntegratedRecordSelector.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Hope the code makes sense - it's pretty much what you had, just a bit cleaned up
yes makes a lot of sense. Thank you for the push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The collapse behavior is inverted for the Collecting Event subview.
<row>
<cell type="subview" viewname="CollectingEventSub" id="21" label="Collecting Event" name="collectingEvent" colspan="13" rows="5"/>
</row>
Screen.Recording.2023-08-24.at.7.24.01.PM.mov
It is collapsed by default, though in the form definition the collapse
attribute (which would be inside of the initialize
attribute) is not present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was so wrong... it was working correctly, the form definition tripped me up.
Works well with the initialize="collapse=true"
and initialize="collapse=false"
attributes in the XML as well.
Fixes #1995