Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/payload/src/collections/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export const createOperation = async <
id: duplicateFromID,
collectionConfig,
draftArg: isSavingDraft,
isSavingDraft,
overrideAccess,
req,
selectedLocales,
Expand Down
7 changes: 0 additions & 7 deletions packages/payload/src/duplicateDocument/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type GetDuplicateDocumentArgs = {
collectionConfig: SanitizedCollectionConfig
draftArg?: boolean
id: number | string
isSavingDraft?: boolean
overrideAccess?: boolean
req: PayloadRequest
selectedLocales?: string[]
Expand All @@ -26,7 +25,6 @@ export const getDuplicateDocumentData = async ({
id,
collectionConfig,
draftArg,
isSavingDraft,
overrideAccess,
req,
selectedLocales,
Expand Down Expand Up @@ -96,11 +94,6 @@ export const getDuplicateDocumentData = async ({
req,
})

// for version enabled collections, override the current status with draft, unless draft is explicitly set to false
if (isSavingDraft) {
duplicatedFromDocWithLocales._status = 'draft'
}

const duplicatedFromDoc = await afterRead({
collection: collectionConfig,
context: req.context,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/elements/DuplicateDocument/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const DuplicateDocument: React.FC<Props> = ({
addQueryPrefix: true,
})}`,
{
body: JSON.stringify({}),
body: JSON.stringify(collectionConfig.versions?.drafts ? { _status: 'draft' } : {}),
headers,
},
)
Expand Down
25 changes: 25 additions & 0 deletions test/versions/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,31 @@ describe('Versions', () => {
})
})

describe('Duplicate', () => {
it('should duplicate a versioned document as a draft', async () => {
const originalDoc = await payload.create({
collection: draftCollectionSlug,
data: {
description: 'Original description',
title: 'Original Title',
_status: 'published',
},
draft: false,
})

const duplicatedDoc = await payload.create({
duplicateFromID: originalDoc.id,
collection: draftCollectionSlug,
data: {
_status: 'draft',
},
draft: true,
})

expect(duplicatedDoc._status).toBe('draft')
})
})

describe('Query operations', () => {
beforeAll(async () => {
// Create test data for query-only tests (pagination, sorting)
Expand Down
Loading