Skip to content

Commit 2a41d3f

Browse files
feat: show fields inside groups as separate columns in the list view (#7355)
## Description Group fields are shown as one column, this PR changes this so that the individual field is now shown separately. Before change: <img width="1227" alt="before change" src="https://github.com/user-attachments/assets/dfae58fd-8ad2-4329-84fd-ed1d4eb20854"> After change: <img width="1229" alt="after change" src="https://github.com/user-attachments/assets/d4fd78bb-c474-436e-a0f5-cac4638b91a4"> - [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] New feature (non-breaking change which adds functionality) ## 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 - [ ] I have made corresponding changes to the documentation --------- Co-authored-by: Patrik Kozak <35232443+PatrikKozak@users.noreply.github.com>
1 parent c772a32 commit 2a41d3f

File tree

19 files changed

+884
-78
lines changed

19 files changed

+884
-78
lines changed

packages/next/src/views/Version/RenderFieldsToDiff/utilities/countChangedFields.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ArrayFieldClient, BlocksFieldClient, ClientConfig, ClientField } from 'payload'
22

3-
import { fieldShouldBeLocalized } from 'payload/shared'
3+
import { fieldShouldBeLocalized, groupHasName } from 'payload/shared'
44

55
import { fieldHasChanges } from './fieldHasChanges.js'
66
import { getFieldsForRowComparison } from './getFieldsForRowComparison.js'
@@ -114,25 +114,37 @@ export function countChangedFields({
114114

115115
// Fields that have nested fields and nest their fields' data.
116116
case 'group': {
117-
if (locales && fieldShouldBeLocalized({ field, parentIsLocalized })) {
118-
locales.forEach((locale) => {
117+
if (groupHasName(field)) {
118+
if (locales && fieldShouldBeLocalized({ field, parentIsLocalized })) {
119+
locales.forEach((locale) => {
120+
count += countChangedFields({
121+
comparison: comparison?.[field.name]?.[locale],
122+
config,
123+
fields: field.fields,
124+
locales,
125+
parentIsLocalized: parentIsLocalized || field.localized,
126+
version: version?.[field.name]?.[locale],
127+
})
128+
})
129+
} else {
119130
count += countChangedFields({
120-
comparison: comparison?.[field.name]?.[locale],
131+
comparison: comparison?.[field.name],
121132
config,
122133
fields: field.fields,
123134
locales,
124135
parentIsLocalized: parentIsLocalized || field.localized,
125-
version: version?.[field.name]?.[locale],
136+
version: version?.[field.name],
126137
})
127-
})
138+
}
128139
} else {
140+
// Unnamed group field: data is NOT nested under `field.name`
129141
count += countChangedFields({
130-
comparison: comparison?.[field.name],
142+
comparison,
131143
config,
132144
fields: field.fields,
133145
locales,
134146
parentIsLocalized: parentIsLocalized || field.localized,
135-
version: version?.[field.name],
147+
version,
136148
})
137149
}
138150
break

packages/payload/src/exports/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export {
2929
fieldIsVirtual,
3030
fieldShouldBeLocalized,
3131
fieldSupportsMany,
32+
groupHasName,
3233
optionIsObject,
3334
optionIsValue,
3435
optionsAreObjects,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ export type NamedGroupFieldClient = {
770770
export type UnnamedGroupFieldClient = {
771771
admin?: AdminClient & Pick<UnnamedGroupField['admin'], 'hideGutter'>
772772
fields: ClientField[]
773-
} & Omit<FieldBaseClient, 'required'> &
773+
} & Omit<FieldBaseClient, 'name' | 'required'> &
774774
Pick<UnnamedGroupField, 'label' | 'type'>
775775

776776
export type GroupFieldClient = NamedGroupFieldClient | UnnamedGroupFieldClient
@@ -1960,6 +1960,12 @@ export function tabHasName<TField extends ClientTab | Tab>(tab: TField): tab is
19601960
return 'name' in tab
19611961
}
19621962

1963+
export function groupHasName(
1964+
group: Partial<NamedGroupFieldClient>,
1965+
): group is NamedGroupFieldClient {
1966+
return 'name' in group
1967+
}
1968+
19631969
/**
19641970
* Check if a field has localized: true set. This does not check if a field *should*
19651971
* be localized. To check if a field should be localized, use `fieldShouldBeLocalized`.

0 commit comments

Comments
 (0)