Skip to content

Commit

Permalink
fix: nested disableListColumn in rows (#6412)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
PatrikKozak committed May 17, 2024
1 parent db5f3f3 commit ab8b2f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
}, [])
Expand Down
8 changes: 8 additions & 0 deletions test/fields/collections/Row/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const RowFields: CollectionConfig = {
type: 'text',
required: true,
},
{
name: 'disableListColumnText',
type: 'text',
admin: {
disableListColumn: true,
disableListFilter: false,
},
},
],
},
{
Expand Down
25 changes: 25 additions & 0 deletions test/fields/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit ab8b2f3

Please sign in to comment.