Skip to content

Commit 537f58b

Browse files
authored
feat: adds disableGroupBy to fields admin props (#14017)
### What? Adds a new `disableGroupBy` admin config property for fields to control their visibility in the list view GroupBy dropdown. ### Why Previously, the GroupByBuilder was incorrectly using `disableListFilter` to determine which fields to show in the group-by dropdown. ### How - Added new `disableGroupBy` property to the field admin config types. - Updated `GroupByBuilder` to filter fields based on `disableGroupBy` instead of `disableListFilter` --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211511898438807
1 parent ef57d24 commit 537f58b

File tree

11 files changed

+62
-9
lines changed

11 files changed

+62
-9
lines changed

docs/fields/overview.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,9 @@ The following options are available:
616616
| **`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. |
617617
| **`disabled`** | If a field is `disabled`, it is completely omitted from the [Admin Panel](../admin/overview) entirely. |
618618
| **`disableBulkEdit`** | Set `disableBulkEdit` to `true` to prevent fields from appearing in the select options when making edits for multiple documents. Defaults to `true` for UI fields. |
619-
| **`disableListColumn`** | Set `disableListColumn` to `true` to prevent fields from appearing in the list view column selector. |
620-
| **`disableListFilter`** | Set `disableListFilter` to `true` to prevent fields from appearing in the list view filter options. |
619+
| **`disableGroupBy`** | Set `disableGroupBy` to `true` to prevent fields from appearing in the list view groupBy options. Defaults to `false`. |
620+
| **`disableListColumn`** | Set `disableListColumn` to `true` to prevent fields from appearing in the list view column selector. Defaults to `false`. |
621+
| **`disableListFilter`** | Set `disableListFilter` to `true` to prevent fields from appearing in the list view filter options. Defaults to `false`. |
621622
| **`hidden`** | Will transform the field into a `hidden` input type. Its value will still submit with requests in the Admin Panel, but the field itself will not be visible to editors. |
622623

623624
### Field Descriptions

docs/upload/overview.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,18 @@ Each image size also supports `admin` options to control whether it appears in t
202202
width: 400,
203203
height: 300,
204204
admin: {
205+
disableGroupBy: true, // hide from list view groupBy options
205206
disableListColumn: true, // hide from list view columns
206207
disableListFilter: true, // hide from list view filters
207208
},
208209
}
209210
```
210211

211-
| Option | Description |
212-
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
213-
| **`disableListColumn`** | If set to `true`, this image size will not be available as a selectable column in the collection list view. Defaults to `false`. |
214-
| **`disableListFilter`** | If set to `true`, this image size will not be available as a filter option in the collection list view. Defaults to `false`. |
212+
| Option | Description |
213+
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
214+
| **`disableGroupBy`** | If set to `true`, this image size will not be available as a selectable groupBy option in the collection list view. Defaults to `false`. |
215+
| **`disableListColumn`** | If set to `true`, this image size will not be available as a selectable column in the collection list view. Defaults to `false`. |
216+
| **`disableListFilter`** | If set to `true`, this image size will not be available as a filter option in the collection list view. Defaults to `false`. |
215217

216218
This is useful for hiding large or rarely used image sizes from the list view UI while still keeping them available in the API.
217219

packages/payload/src/config/orderable/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export const addOrderableFieldsAndHook = (
8989
admin: {
9090
disableBulkEdit: true,
9191
disabled: true,
92+
disableGroupBy: true,
9293
disableListColumn: true,
9394
disableListFilter: true,
9495
hidden: true,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ type Admin = {
366366
description?: Description
367367
disableBulkEdit?: boolean
368368
disabled?: boolean
369+
/**
370+
* Shows / hides fields from appearing in the list view groupBy options.
371+
* @type boolean
372+
*/
373+
disableGroupBy?: boolean
369374
/**
370375
* Shows / hides fields from appearing in the list view column selector.
371376
* @type boolean
@@ -390,6 +395,11 @@ export type AdminClient = {
390395
description?: StaticDescription
391396
disableBulkEdit?: boolean
392397
disabled?: boolean
398+
/**
399+
* Shows / hides fields from appearing in the list view groupBy options.
400+
* @type boolean
401+
*/
402+
disableGroupBy?: boolean
393403
/**
394404
* Shows / hides fields from appearing in the list view column selector.
395405
* @type boolean

packages/payload/src/uploads/getBaseFields.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
170170
name,
171171
type: 'number',
172172
admin: {
173+
disableGroupBy: true,
173174
disableListColumn: true,
174175
disableListFilter: true,
175176
hidden: true,
@@ -184,7 +185,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
184185
}
185186

186187
// In Payload v4, image size subfields (`url`, `width`, `height`, etc.) should
187-
// default to `disableListColumn: true` and `disableListFilter: true`
188+
// default to `disableGroupBy: true`, `disableListColumn: true` and `disableListFilter: true`
188189
// to avoid cluttering the collection list view and filters by default.
189190
if (uploadOptions.imageSizes) {
190191
uploadFields = uploadFields.concat([
@@ -199,6 +200,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
199200
type: 'group',
200201
admin: {
201202
hidden: true,
203+
...(size.admin?.disableGroupBy && { disableGroupBy: true }),
202204
...(size.admin?.disableListColumn && { disableListColumn: true }),
203205
...(size.admin?.disableListFilter && { disableListFilter: true }),
204206
},
@@ -207,6 +209,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
207209
...url,
208210
admin: {
209211
...url.admin,
212+
...(size.admin?.disableGroupBy && { disableGroupBy: true }),
210213
...(size.admin?.disableListColumn && { disableListColumn: true }),
211214
...(size.admin?.disableListFilter && { disableListFilter: true }),
212215
},
@@ -232,6 +235,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
232235
...width,
233236
admin: {
234237
...width.admin,
238+
...(size.admin?.disableGroupBy && { disableGroupBy: true }),
235239
...(size.admin?.disableListColumn && { disableListColumn: true }),
236240
...(size.admin?.disableListFilter && { disableListFilter: true }),
237241
},
@@ -240,6 +244,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
240244
...height,
241245
admin: {
242246
...height.admin,
247+
...(size.admin?.disableGroupBy && { disableGroupBy: true }),
243248
...(size.admin?.disableListColumn && { disableListColumn: true }),
244249
...(size.admin?.disableListFilter && { disableListFilter: true }),
245250
},
@@ -248,6 +253,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
248253
...mimeType,
249254
admin: {
250255
...mimeType.admin,
256+
...(size.admin?.disableGroupBy && { disableGroupBy: true }),
251257
...(size.admin?.disableListColumn && { disableListColumn: true }),
252258
...(size.admin?.disableListFilter && { disableListFilter: true }),
253259
},
@@ -256,6 +262,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
256262
...filesize,
257263
admin: {
258264
...filesize.admin,
265+
...(size.admin?.disableGroupBy && { disableGroupBy: true }),
259266
...(size.admin?.disableListColumn && { disableListColumn: true }),
260267
...(size.admin?.disableListFilter && { disableListFilter: true }),
261268
},
@@ -264,6 +271,7 @@ export const getBaseUploadFields = ({ collection, config }: Options): Field[] =>
264271
...filename,
265272
admin: {
266273
...filename.admin,
274+
...(size.admin?.disableGroupBy && { disableGroupBy: true }),
267275
...(size.admin?.disableListColumn && { disableListColumn: true }),
268276
...(size.admin?.disableListFilter && { disableListFilter: true }),
269277
},

packages/payload/src/uploads/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,17 @@ export type ImageSize = {
7272
/**
7373
* Admin UI options that control how this image size appears in list views.
7474
*
75-
* NOTE: In Payload v4, these options (`disableListColumn`, `disableListFilter`)
75+
* NOTE: In Payload v4, these options (`disableGroupBy`, `disableListColumn` and `disableListFilter`)
7676
* should default to `true` so image size subfields are hidden from list columns
7777
* and filters by default, reducing noise in the admin UI.
7878
*/
7979
admin?: {
80+
/**
81+
* If set to true, this image size will not be available
82+
* as a selectable groupBy option in the collection list view.
83+
* @default false
84+
*/
85+
disableGroupBy?: boolean
8086
/**
8187
* If set to true, this image size will not be available
8288
* as a selectable column in the collection list view.

packages/plugin-multi-tenant/src/fields/tenantField/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const tenantField = ({
5151
admin: {
5252
allowCreate: false,
5353
allowEdit: false,
54+
disableGroupBy: true,
5455
disableListColumn: true,
5556
disableListFilter: true,
5657
position: 'sidebar',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const GroupByBuilder: React.FC<Props> = ({ collectionSlug, fields }) => {
101101
}}
102102
options={reducedFields.filter(
103103
(field) =>
104-
!field.field.admin.disableListFilter &&
104+
!field.field.admin.disableGroupBy &&
105105
field.value !== 'id' &&
106106
supportedFieldTypes.includes(field.field.type),
107107
)}

test/group-by/collections/Posts/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ export const PostsCollection: CollectionConfig = {
2222
type: 'relationship',
2323
relationTo: categoriesSlug,
2424
},
25+
{
26+
name: 'virtualTitleFromCategory',
27+
type: 'text',
28+
virtual: 'category.title',
29+
admin: {
30+
disableGroupBy: true,
31+
},
32+
},
2533
{
2634
name: 'checkbox',
2735
type: 'checkbox',

test/group-by/e2e.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,20 @@ test.describe('Group By', () => {
804804
).toBeVisible()
805805
})
806806

807+
test('should hide field from groupBy options when admin.disableGroupBy is true', async () => {
808+
await page.goto(url.list)
809+
const { groupByContainer } = await openGroupBy(page)
810+
811+
const field = groupByContainer.locator('#group-by--field-select')
812+
await field.click()
813+
814+
await expect(
815+
field.locator('.rs__option', {
816+
hasText: exactText('Virtual Title From Category'),
817+
}),
818+
).toBeHidden()
819+
})
820+
807821
test.describe('Trash', () => {
808822
test('should show trashed docs in trash view when group-by is active', async () => {
809823
await page.goto(url.list)

0 commit comments

Comments
 (0)