From 70e57fef184f7fcf56344ea755465f246f2253a5 Mon Sep 17 00:00:00 2001 From: Yunsup Sim Date: Thu, 22 Feb 2024 06:39:34 +0900 Subject: [PATCH] fix: Add Context Provider in EditMany Component (#5005) * fix: Add Context Provider in EditMany Component * test: Fix e2e test error --- .../components/elements/EditMany/index.tsx | 83 ++++++++--------- test/fields/e2e.spec.ts | 89 +++++++++++++++++++ 2 files changed, 132 insertions(+), 40 deletions(-) diff --git a/packages/payload/src/admin/components/elements/EditMany/index.tsx b/packages/payload/src/admin/components/elements/EditMany/index.tsx index acb9589eb8..8f1d17a0ea 100644 --- a/packages/payload/src/admin/components/elements/EditMany/index.tsx +++ b/packages/payload/src/admin/components/elements/EditMany/index.tsx @@ -13,6 +13,7 @@ import { fieldTypes } from '../../forms/field-types' import X from '../../icons/X' import { useAuth } from '../../utilities/Auth' import { useConfig } from '../../utilities/Config' +import { DocumentInfoProvider } from '../../utilities/DocumentInfo' import { OperationContext } from '../../utilities/OperationProvider' import { SelectAllStatus, useSelection } from '../../views/collections/List/SelectionProvider' import { Drawer, DrawerToggler } from '../Drawer' @@ -120,53 +121,55 @@ const EditMany: React.FC = (props) => { {t('edit')} - -
-
-
-

- {t('editingLabel', { count, label: getTranslation(plural, i18n) })} -

- -
- - -
-
-
-
- {collection.versions ? ( - - - + + +
+
+

+ {t('editingLabel', { count, label: getTranslation(plural, i18n) })} +

+ +
+ + +
+
+
+
+ {collection.versions ? ( + + + + + ) : ( + - - ) : ( - - )} + )} +
-
- - + + +
) diff --git a/test/fields/e2e.spec.ts b/test/fields/e2e.spec.ts index bbcb70facd..76d7d45caf 100644 --- a/test/fields/e2e.spec.ts +++ b/test/fields/e2e.spec.ts @@ -814,6 +814,95 @@ describe('fields', () => { ).toHaveValue(`${assertGroupText3} duplicate`) }) }) + test('should bulk update', async () => { + await Promise.all([ + payload.create({ + collection: 'array-fields', + data: { + title: 'for test 1', + items: [ + { + text: 'test 1', + }, + { + text: 'test 2', + }, + ], + }, + }), + payload.create({ + collection: 'array-fields', + data: { + title: 'for test 2', + items: [ + { + text: 'test 3', + }, + ], + }, + }), + payload.create({ + collection: 'array-fields', + data: { + title: 'for test 3', + items: [ + { + text: 'test 4', + }, + { + text: 'test 5', + }, + { + text: 'test 6', + }, + ], + }, + }), + ]) + + const bulkText = 'Bulk update text' + await page.goto(url.list) + await page.waitForSelector('.table > table > tbody > tr td.cell-title') + const rows = page.locator('.table > table > tbody > tr', { + has: page.locator('td.cell-title span', { + hasText: 'for test', + }), + }) + const count = await rows.count() + + for (let i = 0; i < count; i++) { + await rows + .nth(i) + .locator('td.cell-_select .checkbox-input__input > input[type="checkbox"]') + .check() + } + await page.locator('.edit-many__toggle').click() + await page.locator('.field-select .rs__control').click() + + const arrayOption = page.locator('.rs__option', { + hasText: exactText('Items'), + }) + + await expect(arrayOption).toBeVisible() + + await arrayOption.click() + const addRowButton = page.locator('#field-items > .btn.array-field__add-row') + + await expect(addRowButton).toBeVisible() + + await addRowButton.click() + + const targetInput = page.locator('#field-items__0__text') + + await expect(targetInput).toBeVisible() + + await targetInput.fill(bulkText) + + await page.locator('.form-submit button[type="submit"].edit-many__publish').click() + await expect(page.locator('.Toastify__toast--success')).toContainText( + 'Updated 3 Array Fields successfully.', + ) + }) }) describe('tabs', () => {