From ab8b2f3fb87864484582b7d819ca307888a9449b Mon Sep 17 00:00:00 2001 From: Patrik Date: Fri, 17 May 2024 14:01:08 -0400 Subject: [PATCH] fix: nested `disableListColumn` in rows (#6412) ## Description Fixes #6407 - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] I have added tests that prove my fix is effective or that my feature works - [x] Existing test suite passes locally with my changes --- .../elements/TableColumns/index.tsx | 8 +++++- test/fields/collections/Row/index.ts | 8 ++++++ test/fields/e2e.spec.ts | 25 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/payload/src/admin/components/elements/TableColumns/index.tsx b/packages/payload/src/admin/components/elements/TableColumns/index.tsx index c67a28c2d9..63b454240a 100644 --- a/packages/payload/src/admin/components/elements/TableColumns/index.tsx +++ b/packages/payload/src/admin/components/elements/TableColumns/index.tsx @@ -9,12 +9,12 @@ import React, { } from 'react' import type { SanitizedCollectionConfig } from '../../../../collections/config/types' -import type { Field } from '../../../../fields/config/types' import type { Props as CellProps } from '../../views/collections/List/Cell/types' import type { ListPreferences } from '../../views/collections/List/types' import type { Column } from '../Table/types' import type { Action } from './columnReducer' +import { type Field, fieldHasSubFields } from '../../../../fields/config/types' import { usePreferences } from '../../utilities/Preferences' import formatFields from '../../views/collections/List/formatFields' import buildColumns from './buildColumns' @@ -35,6 +35,12 @@ export const useTableColumns = (): ITableColumns => useContext(TableColumnContex const filterTableFields = (fields: Field[]): Field[] => { return fields.reduce((acc, field) => { + if (fieldHasSubFields(field)) { + field = { + ...field, + fields: filterTableFields(field.fields), + } + } if (!field.admin?.disableListColumn) acc.push(field) return acc }, []) diff --git a/test/fields/collections/Row/index.ts b/test/fields/collections/Row/index.ts index 631db4cb2f..597825b921 100644 --- a/test/fields/collections/Row/index.ts +++ b/test/fields/collections/Row/index.ts @@ -24,6 +24,14 @@ const RowFields: CollectionConfig = { type: 'text', required: true, }, + { + name: 'disableListColumnText', + type: 'text', + admin: { + disableListColumn: true, + disableListFilter: false, + }, + }, ], }, { diff --git a/test/fields/e2e.spec.ts b/test/fields/e2e.spec.ts index fe7f5e065b..9c7df7f62a 100644 --- a/test/fields/e2e.spec.ts +++ b/test/fields/e2e.spec.ts @@ -2061,6 +2061,31 @@ describe('fields', () => { url = new AdminUrlUtil(serverURL, 'row-fields') }) + test('should not display field in list view column selector if admin.disableListColumn is true', async () => { + await page.goto(url.create) + const idInput = page.locator('input#field-id') + await idInput.fill('000') + const titleInput = page.locator('input#field-title') + await titleInput.fill('Row 000') + const disableListColumnText = page.locator('input#field-disableListColumnText') + await disableListColumnText.fill('Disable List Column Text') + await page.locator('#action-save').click() + await wait(200) + await expect(page.locator('.Toastify')).toContainText('successfully') + + await page.goto(url.list) + await page.locator('.list-controls__toggle-columns').click() + + await expect(page.locator('.column-selector')).toBeVisible() + + // Check if "Disable List Column Text" is not present in the column options + await expect( + page.locator(`.column-selector .column-selector__column`, { + hasText: exactText('Disable List Column Text'), + }), + ).toBeHidden() + }) + test('should show row fields as table columns', async () => { await page.goto(url.create)