Skip to content

Commit fb05840

Browse files
fix(ui): duplicate should duplicate as draft by default (#14619)
When duplicating documents it should duplicate as draft when drafts are enabled. It is odd behavior to duplicate a published document and have the copy immediately be published.
1 parent 8901c7b commit fb05840

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

packages/payload/src/collections/operations/create.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export const createOperation = async <
130130
id: duplicateFromID,
131131
collectionConfig,
132132
draftArg: isSavingDraft,
133-
isSavingDraft,
134133
overrideAccess,
135134
req,
136135
selectedLocales,

packages/payload/src/duplicateDocument/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ type GetDuplicateDocumentArgs = {
1717
collectionConfig: SanitizedCollectionConfig
1818
draftArg?: boolean
1919
id: number | string
20-
isSavingDraft?: boolean
2120
overrideAccess?: boolean
2221
req: PayloadRequest
2322
selectedLocales?: string[]
@@ -26,7 +25,6 @@ export const getDuplicateDocumentData = async ({
2625
id,
2726
collectionConfig,
2827
draftArg,
29-
isSavingDraft,
3028
overrideAccess,
3129
req,
3230
selectedLocales,
@@ -96,11 +94,6 @@ export const getDuplicateDocumentData = async ({
9694
req,
9795
})
9896

99-
// for version enabled collections, override the current status with draft, unless draft is explicitly set to false
100-
if (isSavingDraft) {
101-
duplicatedFromDocWithLocales._status = 'draft'
102-
}
103-
10497
const duplicatedFromDoc = await afterRead({
10598
collection: collectionConfig,
10699
context: req.context,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const DuplicateDocument: React.FC<Props> = ({
9595
addQueryPrefix: true,
9696
})}`,
9797
{
98-
body: JSON.stringify({}),
98+
body: JSON.stringify(collectionConfig.versions?.drafts ? { _status: 'draft' } : {}),
9999
headers,
100100
},
101101
)

test/versions/int.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,31 @@ describe('Versions', () => {
431431
})
432432
})
433433

434+
describe('Duplicate', () => {
435+
it('should duplicate a versioned document as a draft', async () => {
436+
const originalDoc = await payload.create({
437+
collection: draftCollectionSlug,
438+
data: {
439+
description: 'Original description',
440+
title: 'Original Title',
441+
_status: 'published',
442+
},
443+
draft: false,
444+
})
445+
446+
const duplicatedDoc = await payload.create({
447+
duplicateFromID: originalDoc.id,
448+
collection: draftCollectionSlug,
449+
data: {
450+
_status: 'draft',
451+
},
452+
draft: true,
453+
})
454+
455+
expect(duplicatedDoc._status).toBe('draft')
456+
})
457+
})
458+
434459
describe('Query operations', () => {
435460
beforeAll(async () => {
436461
// Create test data for query-only tests (pagination, sorting)

0 commit comments

Comments
 (0)