fix(ui): hide edit button on deleted relationship options (#11005)

### What?
This PR fixes an issue where a deleted relationship entry would lead to
a runtime error if the user clicked on the edit button in ui due to not
having a `doc` available in `handleServerFunction`.

### Why?
To prevent runtime errors during expected usage.

### How?
By hiding the edit button in entries that have been deleted. This is
done for entries where the user does not have read access already.

Fixes #11004

Before:

[Editing---Post-userdelete--before--Payload.webm](https://github.com/user-attachments/assets/33180eba-9be3-418f-92d2-3bad93e3dfae)

After:

[Editing---Post-userdelete--after--Payload.webm](https://github.com/user-attachments/assets/ba1a736b-3422-4fe0-93ae-7e8e6496d1bd)
This commit is contained in:
Said Akhrarov
2025-02-14 14:45:55 -05:00
committed by GitHub
parent 70db44f964
commit cba5c7bcac
2 changed files with 30 additions and 0 deletions

View File

@@ -70,6 +70,7 @@ export const optionsReducer = (state: OptionGroup[], action: Action): OptionGrou
) {
loadedIDs.push({ id, relationTo: relation })
newSubOptions.push({
allowEdit: false,
label: `${i18n.t('general:untitled')} - ID: ${id}`,
relationTo: relation,
value: id,

View File

@@ -185,6 +185,35 @@ describe('relationship', () => {
await expect(locator1).toHaveCount(0)
})
test('should hide edit button in main doc when relationship deleted', async () => {
const createdRelatedDoc = await payload.create({
collection: textFieldsSlug,
data: {
text: 'doc to be deleted',
},
})
const doc = await payload.create({
collection: relationshipFieldsSlug,
data: {
relationship: {
value: createdRelatedDoc.id,
relationTo: textFieldsSlug,
},
},
})
await payload.delete({
collection: textFieldsSlug,
id: createdRelatedDoc.id,
})
await page.goto(url.edit(doc.id))
const editBtn = page.locator(
'#field-relationship button.relationship--single-value__drawer-toggler',
)
await expect(editBtn).toHaveCount(0)
})
// TODO: Flaky test in CI - fix this. https://github.com/payloadcms/payload/actions/runs/8910825395/job/24470963991
test.skip('should clear relationship values', async () => {
await page.goto(url.create)