Skip to content
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

Merged
merged 5 commits into from
Sep 27, 2023
Merged

Add collapsible feature in forms #3642

merged 5 commits into from
Sep 27, 2023

Conversation

CarolineDenis
Copy link
Contributor

Fixes #1995

@CarolineDenis CarolineDenis changed the base branch from production to xml-editor June 19, 2023 16:50
@CarolineDenis
Copy link
Contributor Author

part1.mov

@CarolineDenis
Copy link
Contributor Author

part2.mov

Copy link
Member

@maxpatiiuk maxpatiiuk left a 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)

@CarolineDenis
Copy link
Contributor Author

CarolineDenis commented Jun 21, 2023

@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 👍
I still had to use a useEffect and time out. One to avoid to many renderers, the other because it would uncollapse the first time but wouldn't if you add a record with a mistake than wait than collapse.
The useBlockerHandler didn't work because when the element is collapsed it's hidden and therefore non-focusable.

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.

@grantfitzsimmons grantfitzsimmons requested a review from a team June 21, 2023 18:56
Copy link
Member

@grantfitzsimmons grantfitzsimmons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image image

I believe the Specify 6 symbols are more intuitive, where there is a right-facing arrow when collapsed and a downward facing arrow when expanded.

I don't know why I feel this way, since up to collapse and down to expand seems more "logical"– it just feels inverted somehow.

@maxpatiiuk
Copy link
Member

@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.

@maxpatiiuk
Copy link
Member

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.

@maxpatiiuk
Copy link
Member

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 readonly form: HTMLFormElement | undefined; to FormContext->FormMetaType to accomplish this). That, while being a bit more complicated, results in a better UX.

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)

@CarolineDenis
Copy link
Contributor Author

CarolineDenis commented Jun 22, 2023

@maxpatiiuk,
if disabeling the collapse button with "hasBlockers": when adding a new prep, the type of prep is not selected yet so the button is disabled as it should but when we choose the prep hasBlockers becomes false but since there is no re-render the button stays disabled until reload

if using useBlockerHandler: there is an error because the form is not focusable see screen shots.

Screenshot 2023-06-22 at 1 15 13 PM

@maxpatiiuk
Copy link
Member

maxpatiiuk commented Jun 25, 2023

I had this error even with the setTimeout hack:

Screenshot 2023-06-24 at 18 00 43

@maxpatiiuk
Copy link
Member

Feature request: either hide the add/remove buttons when view is collapsed, OR better: expand the subview when add/remove/slider is pressed.

@maxpatiiuk
Copy link
Member

... but since there is no re-render the button stays disabled until reload

that seems like a bug (either with the hook or with your code). That shouldn't be happening as useAllSaveBlockers is supposed to trigger re-render on blockers change.

maxpatiiuk added a commit that referenced this pull request Jun 25, 2023
Fix all of the remaining issues mentioned in the PR
(#3642)
@maxpatiiuk
Copy link
Member

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 git cherry-pick 1417a8c

In either case, the code should still undergo testing as I did only basic testing

Copy link
Member

@maxpatiiuk maxpatiiuk left a 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

@CarolineDenis
Copy link
Contributor Author

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

@grantfitzsimmons grantfitzsimmons self-assigned this Aug 7, 2023
@grantfitzsimmons grantfitzsimmons added this to the 7.9.1 milestone Aug 7, 2023
@grantfitzsimmons grantfitzsimmons modified the milestones: 7.9.1, 7.10 Aug 25, 2023
Copy link
Member

@grantfitzsimmons grantfitzsimmons left a 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>

https://herbrbge71423-issue-1995.test.specifysystems.org/specify/view/collectionobject/349648/?recordsetid=178

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.

Copy link
Member

@grantfitzsimmons grantfitzsimmons left a 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.

@CarolineDenis CarolineDenis merged commit 965c64a into xml-editor Sep 27, 2023
8 of 9 checks passed
@CarolineDenis CarolineDenis deleted the issue-1995 branch September 27, 2023 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Collapsible subviews are missing
3 participants