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

initCollapsed not always respected when collapsible is inside of array #5739

Closed
franciscolourenco opened this issue Apr 9, 2024 · 9 comments · Fixed by #5757
Closed

initCollapsed not always respected when collapsible is inside of array #5739

franciscolourenco opened this issue Apr 9, 2024 · 9 comments · Fixed by #5757
Assignees
Labels
status: needs-triage Possible bug which hasn't been reproduced yet status: verified If an issue has been reproduced

Comments

@franciscolourenco
Copy link
Contributor

franciscolourenco commented Apr 9, 2024

Link to reproduction

https://github.com/franciscolourenco/payload/commits/reproduce-collapsibe-inside-array-initCollapsed-not-respected/

Describe the Bug

When a collapsible field is used inside of an array field, the initCollapsed option is not always respected. Particularly, after preferences have been saved for the array, but preferences for a specific array item collapsible have not been saved.
The collapsible inside of an array item whose preferences have not been saved, should respect initCollapsed, however if always starts expanded.

To Reproduce

  1. Create array item
  2. Expand collapsible inside array item
  3. Collapse collapsible inside array item
  4. Create new array item
  5. Verify that the new collapsible is unexpectedly expanded
  6. The same happens for new array item is created afterwards
Screen.Recording.2024-04-09.at.11.57.37.mp4

Payload Version

2.12.1 (latest main)

Adapters and Plugins

No response

@franciscolourenco franciscolourenco added the status: needs-triage Possible bug which hasn't been reproduced yet label Apr 9, 2024
@franciscolourenco
Copy link
Contributor Author

franciscolourenco commented Apr 9, 2024

The same happens in existing posts, for any array item where the collapsed preference has not been saved yet.

@franciscolourenco
Copy link
Contributor Author

Aside: In our use-case it would be preferable if the preferences would not be persisted in the document creation page.

@DanRibbens
Copy link
Contributor

We need to make sure that the preferences for fields only send if the document ID is present. This should be fixed with one small condition being added to the collapsible field as well as any other field level preferences.

@franciscolourenco
Copy link
Contributor Author

@DanRibbens that would be ideal. Although note that the issue in this bug report is not exactly that one. It is specifically related to preferences of collapsibles when used inside of array fields, and happens in existing documents as well, so they can probably be dealt with separately.

It is a less important issue though. What you describe seems more important and would have the most impact in usability.

@franciscolourenco
Copy link
Contributor Author

Created another ticket to track that issue: #5747

@jacobsfletch
Copy link
Member

Hey @franciscolourenco just looked into this and the root of the problem here is exactly what @DanRibbens suggested. In your screen recording I can see that your preferences doc has the key property set to undefined. This should be the ID of the document, but obviously new documents don't have a key yet. They simply shouldn't save any preferences (just as you've described in #5747). This fix will close both issues—initCollapsed was not being respected because it wrongly found preferences which held it open.

@PatrikKozak PatrikKozak self-assigned this Apr 9, 2024
@PatrikKozak PatrikKozak added the status: verified If an issue has been reproduced label Apr 9, 2024
@franciscolourenco
Copy link
Contributor Author

I can reproduce this issue in an existing document, so it seems they are independent issues:

  • If there are no preferences for the array field at all, the initCollapsed option is respected.
  • From the moment that preferences are saved for one of the array items, initCollapsed is ignored for all array items, and it defaults to expanded if an array item doesn't have preferences.

This issue seems minor, but still there:

Existing.Document.mp4

@jacobsfletch
Copy link
Member

Thank you for the follow-up 👍. @PatrikKozak can you look into this?

@PatrikKozak
Copy link
Contributor

@jacobsfletch @franciscolourenco Yup looking into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet status: verified If an issue has been reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants