Skip to content

Commit

Permalink
fix(plugin-nested-docs): publishing parent doc should not publish chi…
Browse files Browse the repository at this point in the history
…ld doc (#9958)

## Bug Fix

### Issue
Draft children documents get overwritten when the parent document is
published.

### Fix
Correctly retrieve all documents, including drafts, during the resave
process. Add test to ensure parent documents can be published without
impacting the state of any children docs.
  • Loading branch information
JessChowdhury authored Dec 13, 2024
1 parent 796df37 commit 50e7c24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/plugin-nested-docs/src/hooks/resaveChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ type ResaveArgs = {
const resave = async ({ collection, doc, draft, pluginConfig, req }: ResaveArgs) => {
const parentSlug = pluginConfig?.parentFieldSlug || 'parent'
const parentDocIsPublished = doc._status === 'published'

const children = await req.payload.find({
collection: collection.slug,
depth: 0,
draft,
draft: true,
locale: req.locale,
req,
where: {
Expand Down
13 changes: 13 additions & 0 deletions test/plugin-nested-docs/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,18 @@ describe('Nested Docs Plugin', () => {
// TODO: add back when error states are fixed
// await expect(parentSlugInChild).toHaveValue('/parent-slug-draft')
})

test('Publishing parent doc should not publish child', async () => {
await page.goto(url.edit(childId))
await page.locator(slugClass).nth(0).fill('child-updated-draft')
await page.locator(draftButtonClass).nth(0).click()

await page.goto(url.edit(parentId))
await page.locator(slugClass).nth(0).fill('parent-updated-published')
await page.locator(publishButtonClass).nth(0).click()

await page.goto(url.edit(childId))
await expect(page.locator(slugClass).nth(0)).toHaveValue('child-updated-draft')
})
})
})

0 comments on commit 50e7c24

Please sign in to comment.