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

feat: add option for using the ListDrawer for selecting related item in relationship field #11553

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

swheeler7
Copy link

What?

This PR adds the ability to use the ListDrawer component for selecting related collections for the relationship field instead of the default drop down interface. This exposes the advanced filtering options that the list view provides and provides a good interface for searching for the correct relationship when the workflows may be more complicated. I've added an additional "selectionType" prop to the relationship field admin config that defaults to "dropdown" for compatability with the existing implementation but "drawer" can be passed in as well which enables using the ListDrawer for selecting related components.

Why?

Adding the ability to search through the list view enables advanced workflows or handles edge cases when just using the useAsTitle may not be informative enough to find the related record that the user wants. For example, if we have a collection of oscars nominations and are trying to relate the nomination to the person who recieved the nomination there may be multiple actors with the same name (Michelle Williams, for example: https://www.imdb.com/name/nm0931329/, https://www.imdb.com/name/nm0931332/). It would be hard to search through the current dropdown ui to choose the correct person, but in the list view the user could use other fields to identify the correct person such as an imdb id, description, or anything else they have in the collection for that person. Other advanced workflows could be if there are multiple versions of a record in a collection and the user wants to select the most recent one or just anything where the user needs to see more details about the record that they are setting up the relationship to.

How?

This implementation just re-uses the useListDrawer hook and the ListDrawer component so the code changes are pretty minimal. The main change is a new onListSelect handler that gets passed into the ListDrawer and handles updating the value in the field when a record is selected in the ListDrawer.

There were also a two things that I didn't implement as they would require broader code changes 1) Bulk select from the ListDrawer when a relationship is hasMany - when using bulkSelect in the list drawer the relatedCollection doesn't get returned so this doesn't work for polymorphic relationships. Updating this would involve changing the useListDrawer hook 2) Hide values that are already selected from the ListDrawer - potentially possible by modifying the filterOptions and passing in an additional filter but honestly it may not be desired behaviour to hide values from the ListDrawer as this could be confusing for the user if they don't see records that they are expected to see (maybe if anything make them unselectable and indicate that they are disabled). Currently if an already selected value gets selected the selected value gets replaced by the new value

Screen.Recording.2025-03-05.at.9.34.08.AM.mov

@swheeler7 swheeler7 changed the title feat: Add option for using the ListDrawer for selecting related item in relationship field feat: add option for using the ListDrawer for selecting related item in relationship field Mar 5, 2025
@PP-Tom
Copy link

PP-Tom commented Mar 6, 2025

This is a huge improvement for websites with lots of documents! Much needed, better than scrolling down a long list trying to find the document. Amazing PR.

@jacobsfletch jacobsfletch self-requested a review March 7, 2025 02:57
@swheeler7 swheeler7 marked this pull request as ready for review March 7, 2025 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants