Skip to content

Commit a37abd1

Browse files
fix(ui): published, draft and changed labels should now be correctly displayed (#8382)
Fixes the issue where the published or changed document is always shown as "Changed" instead of "Published" or "Draft" ![image](https://github.com/user-attachments/assets/05581b73-0e17-4b41-96a8-007c8b6161f2) Statuses: - Published - when the current version is also the published version - Changed - when the current version is a draft version but a published version exists - Draft - when the current version is a draft and no published versions exist --------- Co-authored-by: Jessica Chowdhury <jessica@trbl.design>
1 parent a033cfe commit a37abd1

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

packages/payload/src/versions/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type TypeWithVersion<T> = {
3636
createdAt: string
3737
id: string
3838
parent: number | string
39+
publishedLocale?: string
3940
snapshot?: boolean
4041
updatedAt: string
4142
version: T

packages/ui/src/elements/PublishButton/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export const DefaultPublishButton: React.FC<{ label?: string }> = ({ label: labe
4343
const { code } = useLocale()
4444
const label = labelProp || t('version:publishChanges')
4545

46-
const hasNewerVersions = unpublishedVersions?.totalDocs > 0
46+
const hasNewerVersions =
47+
unpublishedVersions?.totalDocs > 0 && unpublishedVersions?.docs[0]?.version?._status === 'draft'
4748
const canPublish = hasPublishPermission && (modified || hasNewerVersions || !publishedDoc)
4849
const operation = useOperation()
4950

packages/ui/src/elements/Status/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ export const Status: React.FC = () => {
4141

4242
let statusToRender: 'changed' | 'draft' | 'published'
4343

44-
if (unpublishedVersions?.docs?.length > 0 && publishedDoc) {
44+
const isChangedFromPublished = unpublishedVersions?.docs?.[0]?.version?._status === 'draft'
45+
46+
if (unpublishedVersions?.docs?.length > 0 && isChangedFromPublished && publishedDoc) {
4547
statusToRender = 'changed'
4648
} else if (!publishedDoc) {
4749
statusToRender = 'draft'
48-
} else if (publishedDoc && unpublishedVersions?.docs?.length <= 1) {
50+
} else if (publishedDoc && unpublishedVersions?.docs?.length <= 2) {
4951
statusToRender = 'published'
5052
}
5153

54+
const lastVersion = unpublishedVersions?.docs?.[0]
55+
56+
if (lastVersion && lastVersion.publishedLocale) {
57+
statusToRender = locale === lastVersion.publishedLocale ? 'published' : 'draft'
58+
}
59+
5260
const performAction = useCallback(
5361
async (action: 'revert' | 'unpublish') => {
5462
let url

test/versions/e2e.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ describe('versions', () => {
647647

648648
await textField.fill('spanish published')
649649
await saveDocAndAssert(page)
650-
await expect(status).toContainText('Changed')
650+
await expect(status).toContainText('Published')
651651

652652
await textField.fill('spanish draft')
653653
await saveDocAndAssert(page, '#action-save-draft')
@@ -662,6 +662,16 @@ describe('versions', () => {
662662
await expect(publishSpecificLocale).toContainText('English')
663663
await publishSpecificLocale.click()
664664

665+
await wait(500)
666+
667+
await expect(async () => {
668+
await expect(
669+
page.locator('.payload-toast-item:has-text("Updated successfully.")'),
670+
).toBeVisible()
671+
}).toPass({
672+
timeout: POLL_TOPASS_TIMEOUT,
673+
})
674+
665675
id = await page.locator('.id-label').getAttribute('title')
666676

667677
const data = await payload.find({

0 commit comments

Comments
 (0)