fix(next): prevent errors in globals version view (#12920)

### What?
This PR fixes a runtime error that occurs when opening the "More
versions..." drawer while browsing the versions for a global. It also
fixes a minor runtime error when navigating to a global version view
where an optional chaining operator was missing as the collection
variable would be undefined as we are viewing a global.

This PR also adds an e2e test to ensure the versions drawer is
accessible and renders the appropriate number of versions for globals.

### Why?
To properly render global version views without errors.

### How?
By threading the global slug to the versions drawer and adjusting some
properties of the `renderDocument` server function call there. This PR
also adds an optional chaining operator the `versionUseAsTitle` in the
original view to prevent an error in globals.

Notes:
- This was brought to my attention in Discord by a handful of users

Before: (Missing optional chaining error)


[error1-verions-Editing---Menu---Payload.webm](https://github.com/user-attachments/assets/3dc4dbe4-ee5a-43df-8d25-05128b05e063)

Before: (Versions drawer error)


[error2-versions-Editing---Menu---Payload.webm](https://github.com/user-attachments/assets/98c3e1da-cb0b-4a36-bafd-240f641e8814)


After:


[versions-globals-Dashboard---Payload.webm](https://github.com/user-attachments/assets/c778d3f0-a8fe-4e31-92cb-62da8e6d8cb4)
This commit is contained in:
Said Akhrarov
2025-06-24 13:18:25 -04:00
committed by GitHub
parent 886c07e918
commit 39e95195e1
6 changed files with 89 additions and 18 deletions

View File

@@ -205,6 +205,7 @@ describe('Versions', () => {
const fieldValue = autosaveRelationField.locator('.value-container')
await expect(fieldValue).toContainText('test')
})
test('should show collection versions view level action in collection versions view', async () => {
await page.goto(url.list)
await page.locator('tbody tr .cell-title a').first().click()
@@ -839,6 +840,51 @@ describe('Versions', () => {
await page.goto(url.global(disablePublishGlobalSlug))
await expect(page.locator('#action-save')).not.toBeAttached()
})
test('global — should show versions drawer when SelectComparison more option is clicked', async () => {
await payload.updateGlobal({
slug: draftGlobalSlug,
data: {
title: 'initial title',
},
})
await payload.updateGlobal({
slug: draftGlobalSlug,
data: {
title: 'initial title 2',
},
})
const url = new AdminUrlUtil(serverURL, draftGlobalSlug)
await page.goto(`${url.global(draftGlobalSlug)}/versions`)
const versionsTable = page.locator('.table table')
await expect(versionsTable).toBeVisible()
const versionAnchor = versionsTable.locator('tbody tr.row-1 td.cell-updatedAt a')
await expect(versionAnchor).toBeVisible()
await versionAnchor.click()
const compareFromContainer = page.locator(
'.view-version__version-from .field-type.compare-version',
)
await expect(compareFromContainer).toBeVisible()
const fromSelect = compareFromContainer.locator('.react-select .rs__control')
await expect(fromSelect).toBeVisible()
await fromSelect.click()
const moreVersions = compareFromContainer.locator('.rs__option:has-text("More versions...")')
await expect(moreVersions).toBeVisible()
await moreVersions.click()
const versionDrawer = page.locator('dialog.version-drawer')
await expect(versionDrawer).toBeVisible()
const versionsDrawerTableBody = versionDrawer.locator('main.versions table tbody')
await expect(versionsDrawerTableBody).toBeVisible()
await expect(versionsDrawerTableBody.locator('tr')).toHaveCount(2)
})
})
describe('Scheduled publish', () => {