Skip to content

Commit ea84e82

Browse files
authored
feat(payload, ui): adds disableListColumn & disableListFilter to fields admin props (#6238)
1 parent 4216d69 commit ea84e82

File tree

13 files changed

+139
-17
lines changed

13 files changed

+139
-17
lines changed

docs/fields/overview.mdx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,21 @@ Example:
163163

164164
In addition to each field's base configuration, you can define specific traits and properties for fields that only have effect on how they are rendered in the Admin panel. The following properties are available for all fields within the `admin` property:
165165

166-
| Option | Description |
167-
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
168-
| `condition` | You can programmatically show / hide fields based on what other fields are doing. [Click here](#conditional-logic) for more info. |
169-
| `components` | All field components can be completely and easily swapped out for custom components that you define. [Click here](#custom-components) for more info. |
170-
| `description` | Helper text to display with the field to provide more information for the editor user. [Click here](#description) for more info. |
171-
| `position` | Specify if the field should be rendered in the sidebar by defining `position: 'sidebar'`. |
172-
| `width` | Restrict the width of a field. you can pass any string-based value here, be it pixels, percentages, etc. This property is especially useful when fields are nested within a `Row` type where they can be organized horizontally. |
173-
| `style` | Attach raw CSS style properties to the root DOM element of a field. |
174-
| `className` | Attach a CSS class name to the root DOM element of a field. |
175-
| `readOnly` | Setting a field to `readOnly` has no effect on the API whatsoever but disables the admin component's editability to prevent editors from modifying the field's value. |
176-
| `disabled` | If a field is `disabled`, it is completely omitted from the Admin panel. |
177-
| `disableBulkEdit` | Set `disableBulkEdit` to `true` to prevent fields from appearing in the select options when making edits for multiple documents. |
178-
| `hidden` | Setting a field's `hidden` property on its `admin` config will transform it into a `hidden` input type. Its value will still submit with the Admin panel's requests, but the field itself will not be visible to editors. |
166+
| Option | Description |
167+
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
168+
| `condition` | You can programmatically show / hide fields based on what other fields are doing. [Click here](#conditional-logic) for more info. |
169+
| `components` | All field components can be completely and easily swapped out for custom components that you define. [Click here](#custom-components) for more info. |
170+
| `description` | Helper text to display with the field to provide more information for the editor user. [Click here](#description) for more info. |
171+
| `position` | Specify if the field should be rendered in the sidebar by defining `position: 'sidebar'`. |
172+
| `width` | Restrict the width of a field. you can pass any string-based value here, be it pixels, percentages, etc. This property is especially useful when fields are nested within a `Row` type where they can be organized horizontally. |
173+
| `style` | Attach raw CSS style properties to the root DOM element of a field. |
174+
| `className` | Attach a CSS class name to the root DOM element of a field. |
175+
| `readOnly` | Setting a field to `readOnly` has no effect on the API whatsoever but disables the admin component's editability to prevent editors from modifying the field's value. |
176+
| `disabled` | If a field is `disabled`, it is completely omitted from the Admin panel. |
177+
| `disableBulkEdit` | Set `disableBulkEdit` to `true` to prevent fields from appearing in the select options when making edits for multiple documents. |
178+
| `disableListColumn` | Set `disableListColumn` to `true` to prevent fields from appearing in the list view column selector. |
179+
| `disableListFilter` | Set `disableListFilter` to `true` to prevent fields from appearing in the list view filter options. |
180+
| `hidden` | Setting a field's `hidden` property on its `admin` config will transform it into a `hidden` input type. Its value will still submit with the Admin panel's requests, but the field itself will not be visible to editors. |
179181

180182
### Custom components
181183

packages/payload/src/fields/config/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const baseAdminFields = joi.object().keys({
2121
.alternatives()
2222
.try(joi.string(), joi.object().pattern(joi.string(), [joi.string()]), joi.function()),
2323
disableBulkEdit: joi.boolean().default(false),
24+
disableListColumn: joi.boolean().default(false),
25+
disableListFilter: joi.boolean().default(false),
2426
disabled: joi.boolean().default(false),
2527
hidden: joi.boolean().default(false),
2628
initCollapsed: joi.boolean().default(false),

packages/payload/src/fields/config/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ type Admin = {
132132
custom?: Record<string, any>
133133
description?: Description
134134
disableBulkEdit?: boolean
135+
/**
136+
* Shows / hides fields from appearing in the list view column selector.
137+
* @type boolean
138+
*/
139+
disableListColumn?: boolean
140+
/**
141+
* Shows / hides fields from appearing in the list view filter options.
142+
* @type boolean
143+
*/
144+
disableListFilter?: boolean
135145
disabled?: boolean
136146
hidden?: boolean
137147
position?: 'sidebar'
@@ -443,6 +453,16 @@ export type UIField = {
443453
/** Extension point to add your custom data. Available in server and client. */
444454
custom?: Record<string, any>
445455
disableBulkEdit?: boolean
456+
/**
457+
* Shows / hides fields from appearing in the list view column selector.
458+
* @type boolean
459+
*/
460+
disableListColumn?: boolean
461+
/**
462+
* Shows / hides fields from appearing in the list view filter options.
463+
* @type boolean
464+
*/
465+
disableListFilter?: boolean
446466
position?: string
447467
width?: string
448468
}

packages/ui/src/elements/ColumnSelector/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { SanitizedCollectionConfig } from 'payload/types'
33

44
import React, { useId } from 'react'
55

6+
import type { Column } from '../Table/index.js'
7+
68
import { Plus } from '../../icons/Plus/index.js'
79
import { X } from '../../icons/X/index.js'
810
import { useEditDepth } from '../../providers/EditDepth/index.js'
@@ -17,6 +19,12 @@ export type Props = {
1719
collectionSlug: SanitizedCollectionConfig['slug']
1820
}
1921

22+
const filterColumnFields = (fields: Column[]): Column[] => {
23+
return fields.filter((field) => {
24+
return !field.admin?.disableListColumn
25+
})
26+
}
27+
2028
export const ColumnSelector: React.FC<Props> = ({ collectionSlug }) => {
2129
const { columns, moveColumn, toggleColumn } = useTableColumns()
2230

@@ -27,18 +35,20 @@ export const ColumnSelector: React.FC<Props> = ({ collectionSlug }) => {
2735
return null
2836
}
2937

38+
const filteredColumns = filterColumnFields(columns)
39+
3040
return (
3141
<DraggableSortable
3242
className={baseClass}
33-
ids={columns.map((col) => col?.accessor)}
43+
ids={filteredColumns.map((col) => col?.accessor)}
3444
onDragEnd={({ moveFromIndex, moveToIndex }) => {
3545
moveColumn({
3646
fromIndex: moveFromIndex,
3747
toIndex: moveToIndex,
3848
})
3949
}}
4050
>
41-
{columns.map((col, i) => {
51+
{filteredColumns.map((col, i) => {
4252
if (!col) return null
4353

4454
const { Label, accessor, active } = col

packages/ui/src/elements/Table/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type Column = {
2121
Label: React.ReactNode
2222
accessor: string
2323
active: boolean
24+
admin?: FieldBase['admin']
2425
cellProps?: Partial<CellComponentProps>
2526
components: {
2627
Cell: React.ReactNode

packages/ui/src/elements/TableColumns/buildColumnState.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export const buildColumnState = (args: Args): Column[] => {
134134
Label,
135135
accessor: name,
136136
active,
137+
admin: {
138+
disableListColumn: field.disableListColumn,
139+
disableListFilter: field.disableListFilter,
140+
},
137141
cellProps: {
138142
...field.cellComponentProps,
139143
...cellProps?.[index],

packages/ui/src/elements/WhereBuilder/reduceFieldMap.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const reduceFieldMap = (fieldMap: Column[], i18n) =>
3232
},
3333
}
3434

35+
if (field.admin?.disableListFilter) return reduced
36+
3537
return [...reduced, formattedField]
3638
}
3739

packages/ui/src/providers/ComponentMap/buildComponentMap/fields.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,10 @@ export const mapFields = (args: {
755755
custom: field?.admin?.custom,
756756
disableBulkEdit:
757757
'admin' in field && 'disableBulkEdit' in field.admin && field.admin.disableBulkEdit,
758+
disableListColumn:
759+
'admin' in field && 'disableListColumn' in field.admin && field.admin.disableListColumn,
760+
disableListFilter:
761+
'admin' in field && 'disableListFilter' in field.admin && field.admin.disableListFilter,
758762
fieldComponentProps,
759763
fieldIsPresentational,
760764
isFieldAffectingData,

packages/ui/src/providers/ComponentMap/buildComponentMap/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export type MappedField = {
7171
cellComponentProps: CellComponentProps
7272
custom?: Record<any, string>
7373
disableBulkEdit?: boolean
74+
disableListColumn?: boolean
75+
disableListFilter?: boolean
7476
disabled?: boolean
7577
fieldComponentProps: FieldComponentProps
7678
fieldIsPresentational: boolean

test/fields/collections/Text/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ const TextFields: CollectionConfig = {
141141
hasMany: true,
142142
maxRows: 4,
143143
},
144+
{
145+
name: 'disableListColumnText',
146+
type: 'text',
147+
admin: {
148+
disableListColumn: true,
149+
disableListFilter: false,
150+
},
151+
},
152+
{
153+
name: 'disableListFilterText',
154+
type: 'text',
155+
admin: {
156+
disableListColumn: false,
157+
disableListFilter: true,
158+
},
159+
},
144160
],
145161
}
146162

0 commit comments

Comments
 (0)