fix(ui): join table row still shows after deletion (#9783)

<!--

Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.

Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.

The following items will ensure that your PR is handled as smoothly as
possible:

- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Fixes #

-->
### What?
This PR fixes an issue where deleting an entry in a `Join` via the
`Drawer` accessed through the `DrawerLink` would not update the table
until the page was refreshed.

### Why?
For a better, more reactive, deletion experience for end-users. Ideally,
the deletion is reflected in the table right away.

### How?
By passing an `onDrawerDelete` function to the `DrawerLink` which simply
filters out the existing doc according to an id.

Fixes #9580

Before:

[Editing---Post--before-Payload.webm](https://github.com/user-attachments/assets/3dd4df78-bb63-46b1-bf5f-7643935e15ad)

After:

[Editing---Post--after-Payload.webm](https://github.com/user-attachments/assets/97bb604f-41df-4cc9-8c46-9a59a19c72b7)
This commit is contained in:
Said Akhrarov
2024-12-20 20:47:09 -06:00
committed by GitHub
parent ec853c4336
commit a58b9fc230
3 changed files with 58 additions and 3 deletions

View File

@@ -291,6 +291,39 @@ test.describe('Join Field', () => {
await expect(joinField.locator('tbody .row-1')).toContainText('Test Post 1 Updated')
})
test('should update relationship table when document is deleted', async () => {
await page.goto(categoriesURL.edit(categoryID))
const joinField = page.locator('#field-group__relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
const expectedRows = 3
const rows = joinField.locator('.relationship-table tbody tr')
await expect(rows).toHaveCount(expectedRows)
const editButton = joinField.locator(
'tbody tr:first-child td:nth-child(2) button.doc-drawer__toggler',
)
await expect(editButton).toBeVisible()
await editButton.click()
const drawer = page.locator('[id^=doc-drawer_posts_1_]')
await expect(drawer).toBeVisible()
const popupButton = drawer.locator('button.popup-button')
await expect(popupButton).toBeVisible()
await popupButton.click()
const deleteButton = drawer.locator('#action-delete')
await expect(deleteButton).toBeVisible()
await deleteButton.click()
const deleteConfirmModal = page.locator('dialog[id^="delete-"][open]')
await expect(deleteConfirmModal).toBeVisible()
const confirmDeleteButton = deleteConfirmModal.locator('button#confirm-delete')
await expect(confirmDeleteButton).toBeVisible()
await confirmDeleteButton.click()
await expect(drawer).toBeHidden()
// We should have one less row than we started with
await expect(rows).toHaveCount(expectedRows - 1)
})
test('should create join collection from polymorphic relationships', async () => {
await page.goto(categoriesURL.edit(categoryID))
const joinField = page.locator('#field-polymorphic.field-type.join')