Skip to content

Commit 89c8290

Browse files
committed
fix(list): View settings labels a group field picked outside the columns
The View settings menu labelled grouping levels from the columns only, so a field the Group level now offers beyond them (the record owner, an object field the view does not show) read as its machine name on the menu's Group row and on its level. The host hands the popover the same label function the toolbar editor uses. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgXeD1yUYqBJm8uzRrP
1 parent 953c8cb commit 89c8290

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎.changeset/36204-group-add-default-field.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'@object-ui/i18n': patch
55
---
66

7-
feat(list): "Add group field" asks which field, and offers only fields that can group
7+
fix(list): "Add group field" asks which field, and offers only fields that can group
88

99
Clause-②: yes (widening) — `@object-ui/components`'s `GroupingEditor` gains the optional props `askFieldOnAdd`, `fieldOptionsLoading` and `fieldLabel`, and its `labels` the optional `noFields`; `@object-ui/i18n` gains the key `list.noGroupableFields` in every locale; nothing removed or renamed
1010
Metadata-protocol: none

‎ui/packages/plugin-list/src/ListView.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7306,6 +7306,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
73067306
setGroupingConfig={changeGrouping}
73077307
groupOptions={groupOptions}
73087308
groupOptionsLoading={groupOptionsLoading}
7309+
groupFieldLabel={groupFieldLabel}
73097310
showColor={toolbarFlags.showColor}
73107311
rowColorConfig={offeredRowColorConfig}
73117312
setRowColorConfig={setRowColorConfig}

‎ui/packages/plugin-list/src/__tests__/ListView.groupAddDefault-36204.test.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,22 @@ describe('"Add group field" opens the field dropdown and groups only on a pick (
205205
expect(onGroupingChange).toHaveBeenLastCalledWith({ fields: [level('industry')] });
206206
});
207207

208+
it('View settings labels a field picked outside the columns, on its level and on the menu\'s Group row', async () => {
209+
// `columns` holds neither Parent account nor Record owner: both are the
210+
// object's own fields, offered after the columns.
211+
const { dataSource, onGroupingChange } = mount({ columns, compactToolbar: true });
212+
await definitionRead(dataSource);
213+
const content = await openDisplayGroup();
214+
fireEvent.click(within(content).getByTestId('grouping-add'));
215+
fireEvent.click(within(screen.getByRole('listbox')).getByRole('option', { name: 'Record owner' }));
216+
expect(onGroupingChange).toHaveBeenLastCalledWith({ fields: [level('owner_id')] });
217+
expect(await within(content).findByTestId('grouping-field-0')).toHaveTextContent('Record owner');
218+
fireEvent.click(within(content).getByTestId('options-back'));
219+
const row = await within(content).findByTestId('options-row-group');
220+
expect(row).toHaveTextContent('Record owner');
221+
expect(row).not.toHaveTextContent('owner_id');
222+
});
223+
208224
it('while the definition is being read the button waits, disabled, without a reason', async () => {
209225
let answer: (value: unknown) => void = () => {};
210226
const { dataSource } = mount({ columns }, new Promise((resolve) => { answer = resolve; }));

‎ui/packages/plugin-list/src/components/ViewSettingsPopover.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ export interface ViewSettingsPopoverProps {
219219
*/
220220
groupOptions?: Array<{ value: string; label: string }>;
221221
groupOptionsLoading?: boolean;
222+
/**
223+
* objectstack#36204 — the label of a field a grouping level holds, as the
224+
* host knows it: `groupOptions` reach past the columns, so a level can hold
225+
* a field `allFields` does not carry. Absent, or answering `undefined`,
226+
* the column's label, else the field's name.
227+
*/
228+
groupFieldLabel?: (field: string) => string | undefined;
222229

223230
showColor?: boolean;
224231
rowColorConfig?: { field: string; colors?: Record<string, string> } | undefined;
@@ -553,6 +560,7 @@ export function ViewSettingsContent(props: ViewSettingsPopoverProps & { closeMen
553560
setGroupingConfig,
554561
groupOptions,
555562
groupOptionsLoading,
563+
groupFieldLabel,
556564
showColor,
557565
rowColorConfig,
558566
setRowColorConfig,
@@ -582,6 +590,7 @@ export function ViewSettingsContent(props: ViewSettingsPopoverProps & { closeMen
582590
const hasFooter = !!onSave || !!onReset || hasExport;
583591

584592
const fieldLabel = (name: string) => allFields.find((f) => f.name === name)?.label || name;
593+
const groupLevelLabel = (name: string) => groupFieldLabel?.(name) || fieldLabel(name);
585594
const none = t('list.none', { defaultValue: 'None' });
586595
const groupFields: string[] = Array.isArray(groupingConfig?.fields)
587596
? groupingConfig.fields.map((f: { field?: string }) => f?.field).filter((f: unknown): f is string => typeof f === 'string' && !!f)
@@ -654,7 +663,7 @@ export function ViewSettingsContent(props: ViewSettingsPopoverProps & { closeMen
654663
{showGroup && setGroupingConfig && (
655664
<MenuRow
656665
label={titles.group}
657-
value={groupFields.length > 0 ? groupFields.map(fieldLabel).join(' › ') : none}
666+
value={groupFields.length > 0 ? groupFields.map(groupLevelLabel).join(' › ') : none}
658667
onOpen={() => setPage('group')}
659668
testId="options-row-group"
660669
/>
@@ -750,7 +759,7 @@ export function ViewSettingsContent(props: ViewSettingsPopoverProps & { closeMen
750759
fieldOptions={groupOptions ?? groupFieldOptions(allFields, fieldOrder)}
751760
askFieldOnAdd
752761
fieldOptionsLoading={groupOptionsLoading}
753-
fieldLabel={fieldLabel}
762+
fieldLabel={groupLevelLabel}
754763
maxLevels={3}
755764
labels={{
756765
addGroup: t('list.addGroup', 'Add group field'),

0 commit comments

Comments
 (0)