fix(ui): issue with schedule publish disappearing on autosave collections (#12078)

Fixes an issue where an autosave being triggered would turn off the
ability to schedule a publish. This happened because we check against
`modified` on the form but with autosave modified is always true.

Now we make an exception for autosave enabled collections when checking
the modified state.
This commit is contained in:
Paul
2025-04-11 15:43:40 +01:00
committed by GitHub
parent 3287f7062f
commit 3a7cd717b2
3 changed files with 28 additions and 1 deletions

View File

@@ -74,11 +74,16 @@ export function PublishButton({ label: labelProp }: PublishButtonClientProps) {
const scheduledPublishEnabled = Boolean(schedulePublish)
// If autosave is enabled the modified will always be true so only conditionally check on modified state
const hasAutosave = Boolean(
typeof entityConfig?.versions?.drafts === 'object' && entityConfig?.versions?.drafts.autosave,
)
const canSchedulePublish = Boolean(
scheduledPublishEnabled &&
hasPublishPermission &&
(globalSlug || (collectionSlug && id)) &&
!modified,
(hasAutosave || !modified),
)
const operation = useOperation()

View File

@@ -18,6 +18,7 @@ const AutosavePosts: CollectionConfig = {
autosave: {
interval: 2000,
},
schedulePublish: true,
},
},
access: {

View File

@@ -655,6 +655,7 @@ describe('Versions', () => {
describe('Scheduled publish', () => {
beforeAll(() => {
url = new AdminUrlUtil(serverURL, draftCollectionSlug)
autosaveURL = new AdminUrlUtil(serverURL, autosaveCollectionSlug)
})
test('should schedule publish', async () => {
@@ -725,6 +726,26 @@ describe('Versions', () => {
timeout: POLL_TOPASS_TIMEOUT,
})
})
test('can still schedule publish once autosave is triggered', async () => {
await page.goto(autosaveURL.create)
await page.locator('#field-title').fill('scheduled publish')
await page.locator('#field-description').fill('scheduled publish description')
await saveDocAndAssert(page)
await page.locator('#field-title').fill('scheduled publish updated')
await waitForAutoSaveToRunAndComplete(page)
await page.locator('#action-save-popup').click()
await expect(async () => {
await expect(page.locator('#schedule-publish')).toBeVisible()
}).toPass({
timeout: POLL_TOPASS_TIMEOUT,
})
})
})
describe('Collections - publish specific locale', () => {