feat: add the ability to link existing documents in the join field #12029
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This PR adds a new button to the Join field UI to take an existing document from the joined collection and link it to this joining document instead.
Why?
This is a custom functionality that I needed as part of my own usage of Payload. I found the integration to be a bit difficult — I had to modify the label component and extend it in width up to the
Add new
button to give an impression of a second action. Not to mention that after sending a PATCH request to do the linking, I had to callwindow.location.reload()
because I couldn't come up with a better way to invalidate the table from within a custom component.Since the new functionality was mostly using existing Payload components, I figured I'd try to contribute it back in case you decide that it's useful.
How?
This uses the
ListDrawer
element to display a slide-out panel to browse existing documents that can be linked to the current document.Note
This PR is still not finished — after selection, the document isn't actually being linked. I wanted to get your input on whether this contribution is welcome, and if so, what would be the best way to implement the linking? The only thing I can think of is a
fetch
call, but perhaps there's a better way to do updates from inside Payload client components