Skip to content

fix(ui): relationship using list drawer correctly updates when hasMany is true #12176

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

Merged

Conversation

swheeler7
Copy link
Contributor

@swheeler7 swheeler7 commented Apr 21, 2025

What?

This fixes an issue raised by @maximseshuk in this PR #11553. Here is the text of the original comment:

If the field has the property hasMany: true and you select one item, it shows up in the select field, but any additional selected items won't be visible in the select field, even though the data is actually there and can be saved. After refreshing the page, they appear.

In addition I added a fix to an issue where the filterOptions weren't being passed in to the useListDrawer hook properly in polymorphic relationships

How?

Instead of using the push method to update the value state, a new array is created and directly set using useState. I think the issue was because using push mutates the original array.

@maximseshuk
Copy link
Contributor

Thanks

@swheeler7 swheeler7 changed the title fix(ui): relationship using list drawer correctly updates when hasMany = true fix(ui): relationship using list drawer correctly updates when hasMany is true Apr 22, 2025
@swheeler7
Copy link
Contributor Author

@jacobsfletch I updated the listDrawerFilterOptions function as I was getting an error when trying to set the filterOptions with polymorphic relations but maybe there is a way to simplify?

@maximseshuk
Copy link
Contributor

@swheeler7 I tested this fix on my project, but something is still not right. For example, elements now might not appear after two if the element is unknown (i.e., if it wasn't previously selected, it doesn't appear). Filtering with hasMany true still doesn't work.

I'll also try to look into what the problem might be.

@swheeler7
Copy link
Contributor Author

Weird this is what it's looking like for me when I run the fix locally but I could be missing or not understanding the specific case you are talking about:

relationship-drawer-fix.mov

If you have a specific field configuration where it's not working I can try to take a look

@maximseshuk
Copy link
Contributor

@swheeler7 So, indeed, everything works perfectly. I didn't notice that I hadn't replaced the package. Sorry, my mistake. Everything works great within my use case.

@klapec
Copy link
Contributor

klapec commented Apr 28, 2025

Is there anything that's blocking from merging this PR? The relationship drawer is pretty much unusable without this fix.

@jacobsfletch jacobsfletch merged commit 5bd852c into payloadcms:main Apr 28, 2025
76 checks passed
@PP-Tom
Copy link

PP-Tom commented Apr 28, 2025

@swheeler7 one thing I noticed, if you have a dropdown to select a collection and press the 'X' next to it, the entire UI crashes.

@swheeler7
Copy link
Contributor Author

@swheeler7 one thing I noticed, if you have a dropdown to select a collection and press the 'X' next to it, the entire UI crashes.

It looks like this is an issue with the ListDrawer component itself, not specifically it's usage here in the relationship field. This will be an issue anywhere the ListDrawer is used which I think is in the Lexical Relationships feature, the uploads feature, and I think the new query presets feature. Maybe open an issue for it, but if I have time I'll try to create a PR to fix

Copy link
Contributor

🚀 This is included in version v3.36.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants