diff --git a/packages/payload/src/admin/components/elements/PublishMany/index.tsx b/packages/payload/src/admin/components/elements/PublishMany/index.tsx index 8a6f9f18fc..61096181a2 100644 --- a/packages/payload/src/admin/components/elements/PublishMany/index.tsx +++ b/packages/payload/src/admin/components/elements/PublishMany/index.tsx @@ -18,7 +18,7 @@ import './index.scss' const baseClass = 'publish-many' const PublishMany: React.FC = (props) => { - const { collection: { labels: { plural }, slug, versions } = {}, resetParams } = props + const { collection: { slug, labels: { plural }, versions } = {}, resetParams } = props const { routes: { api }, @@ -27,7 +27,7 @@ const PublishMany: React.FC = (props) => { const { permissions } = useAuth() const { toggleModal } = useModal() const { i18n, t } = useTranslation('version') - const { count, getQueryParams, selectAll } = useSelection() + const { getQueryParams, selectAll } = useSelection() const [submitted, setSubmitted] = useState(false) const collectionPermissions = permissions?.collections?.[slug] @@ -41,9 +41,11 @@ const PublishMany: React.FC = (props) => { const handlePublish = useCallback(() => { setSubmitted(true) - requests + void requests .patch( - `${serverURL}${api}/${slug}${getQueryParams({ _status: { not_equals: 'published' } })}`, + `${serverURL}${api}/${slug}${getQueryParams({ + _status: { not_equals: 'published' }, + })}&draft=true`, { body: JSON.stringify({ _status: 'published', diff --git a/test/versions/collections/Autosave.ts b/test/versions/collections/Autosave.ts index cb5f4f0063..b68702cebe 100644 --- a/test/versions/collections/Autosave.ts +++ b/test/versions/collections/Autosave.ts @@ -10,7 +10,7 @@ const AutosavePosts: CollectionConfig = { }, admin: { useAsTitle: 'title', - defaultColumns: ['title', 'description', 'createdAt'], + defaultColumns: ['title', 'description', 'createdAt', '_status'], preview: () => 'https://payloadcms.com', }, versions: { diff --git a/test/versions/e2e.spec.ts b/test/versions/e2e.spec.ts index dd74c94b78..4b2c764186 100644 --- a/test/versions/e2e.spec.ts +++ b/test/versions/e2e.spec.ts @@ -69,6 +69,11 @@ describe('versions', () => { serverURL = config.serverURL const context = await browser.newContext() page = await context.newPage() + url = new AdminUrlUtil(serverURL, draftCollectionSlug) + autosaveURL = new AdminUrlUtil(serverURL, autosaveCollectionSlug) + disablePublishURL = new AdminUrlUtil(serverURL, disablePublishSlug) + customIDURL = new AdminUrlUtil(serverURL, customIDSlug) + postURL = new AdminUrlUtil(serverURL, postCollectionSlug) initPageConsoleErrorCatch(page) }) @@ -78,13 +83,6 @@ describe('versions', () => { }) describe('draft collections', () => { - beforeAll(() => { - url = new AdminUrlUtil(serverURL, draftCollectionSlug) - autosaveURL = new AdminUrlUtil(serverURL, autosaveCollectionSlug) - disablePublishURL = new AdminUrlUtil(serverURL, disablePublishSlug) - customIDURL = new AdminUrlUtil(serverURL, customIDSlug) - }) - // This test has to run before bulk updates that will rename the title test('should delete', async () => { await page.goto(url.list) @@ -122,6 +120,38 @@ describe('versions', () => { await expect(await findTableCell(page, '_status', 'Draft Title')).toContainText('Published') }) + test('bulk publish with autosave documents', async () => { + const title = 'autosave title' + const description = 'autosave description' + await page.goto(autosaveURL.create) + + // fill the fields + await page.locator('#field-title').fill(title) + await page.locator('#field-description').fill(description) + + // wait for autosave + await wait(2000) + + // go to list + await page.goto(autosaveURL.list) + + // expect the status to be draft + await expect(await findTableCell(page, '_status', title)).toContainText('Draft') + + // select the row + // await page.locator('.row-1 .select-row__checkbox').click() + await selectTableRow(page, title) + + // click the publish many + await page.locator('.publish-many__toggle').click() + + // confirm the dialog + await page.locator('#confirm-publish').click() + + // expect the status to be published + await expect(await findTableCell(page, '_status', title)).toContainText('Published') + }) + test('bulk update - should unpublish many', async () => { await page.goto(url.list) @@ -443,15 +473,6 @@ describe('versions', () => { await expect(page.locator('#action-save')).not.toBeAttached() }) - }) - describe('posts collection', () => { - beforeAll(() => { - url = new AdminUrlUtil(serverURL, draftCollectionSlug) - autosaveURL = new AdminUrlUtil(serverURL, autosaveCollectionSlug) - disablePublishURL = new AdminUrlUtil(serverURL, disablePublishSlug) - customIDURL = new AdminUrlUtil(serverURL, customIDSlug) - postURL = new AdminUrlUtil(serverURL, postCollectionSlug) - }) test('should show documents title in relationship even if draft document', async () => { await payload.create({