fix(next): unnamed, unlabeled groups displayed without label in version view (#13831)

Before, unnamed, unlabelled group were part of an unlabeled collapsible
in the version diff view. This means, all it displayed was a clickable,
empty rectangle. This looks like a bug rather than intended.

This PR displays a new <Unnamed Group> label in these cases.

It also fixes the incorrect `NamedGroupFieldClient` type. Previously,
that type did not include the `name` property, even though it was
available on the client.

Before:
<img width="2372" height="688" alt="Screenshot 2025-09-16 at 18 57
45@2x"
src="https://github.com/user-attachments/assets/0f351f84-a00f-4067-aa40-d0e8fbfd5f0b"
/>


After:

<img width="2326" height="598" alt="Screenshot 2025-09-16 at 18 56
14@2x"
src="https://github.com/user-attachments/assets/bddee841-8218-4a90-a052-9875c5f252c0"
/>


---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211375615406676
This commit is contained in:
Alessio Gravili
2025-09-17 01:38:07 -07:00
committed by GitHub
parent 433c5136fc
commit 8d3b146d2d
53 changed files with 135 additions and 29 deletions

View File

@@ -757,13 +757,6 @@ export type UnnamedGroupField = {
export type GroupField = NamedGroupField | UnnamedGroupField
export type NamedGroupFieldClient = {
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
admin?: AdminClient & Pick<NamedGroupField['admin'], 'hideGutter'>
fields: ClientField[]
} & Omit<FieldBaseClient, 'required'> &
Pick<NamedGroupField, 'interfaceName' | 'type'>
export type UnnamedGroupFieldClient = {
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
admin?: AdminClient & Pick<UnnamedGroupField['admin'], 'hideGutter'>
@@ -771,6 +764,8 @@ export type UnnamedGroupFieldClient = {
} & Omit<FieldBaseClient, 'name' | 'required'> &
Pick<UnnamedGroupField, 'label' | 'type'>
export type NamedGroupFieldClient = Pick<NamedGroupField, 'name'> & UnnamedGroupFieldClient
export type GroupFieldClient = NamedGroupFieldClient | UnnamedGroupFieldClient
export type RowField = {

View File

@@ -14,7 +14,10 @@ import { getFieldPathsModified as getFieldPaths } from '../../getFieldPaths.js'
import { getExistingRowDoc } from './getExistingRowDoc.js'
import { traverseFields } from './traverseFields.js'
function buildFieldLabel(parentLabel: string, label: string): string {
function buildFieldLabel(parentLabel: string, label: string | undefined): string {
if (!label) {
return parentLabel
}
const capitalizedLabel = label.charAt(0).toUpperCase() + label.slice(1)
return parentLabel && capitalizedLabel
? `${parentLabel} > ${capitalizedLabel}`
@@ -570,7 +573,7 @@ export const promise = async ({
? fieldLabelPath
: buildFieldLabel(
fieldLabelPath,
getTranslatedLabel(field?.label || field.name!, req.i18n),
getTranslatedLabel(field?.label || field.name, req.i18n),
),
fields: field.fields,
global,

View File

@@ -2,7 +2,10 @@ import { getTranslation, type I18n } from '@payloadcms/translations'
import type { LabelFunction, StaticLabel } from '../config/types.js'
export const getTranslatedLabel = (label: LabelFunction | StaticLabel, i18n?: I18n): string => {
export const getTranslatedLabel = (
label: LabelFunction | StaticLabel | undefined,
i18n?: I18n,
): string | undefined => {
if (typeof label === 'function') {
return label({ i18n: i18n!, t: i18n!.t })
}