Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/36204-group-add-default-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@object-ui/components': patch
'@object-ui/plugin-list': patch
'@object-ui/i18n': patch
---

fix(list): "Add group field" asks which field, and offers only fields that can group

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
Metadata-protocol: none

On a list, 「添加分组字段」 / "Add group field" used to group at once by the list's first column, usually the record's name, so every record became a group of its own. Now, in the toolbar's Group panel and in the view settings menu's Group level alike:

- It adds no field by itself and does not group. The field dropdown opens, and the list is grouped once a field is picked there. Closing the dropdown without a pick leaves the list as it was.
- The dropdown lists only the fields that can group: single select or radio (a status is one), tick (boolean or toggle), person, and linked record (lookup, master-detail, tree), each single-valued. Text, number, date and multi-select fields are not offered. The list's columns come first in the reader's column order, then the object's other groupable fields the reader may read, business fields before system ones such as the record owner. Created by and updated by are offered only when the view shows them as a column.
- With no field that can group, the button is drawn disabled and says why: 「没有可以用来分组的字段」 / "No field here can group the list".
- Until the object's field types are read, the button is disabled without a reason. When no definition can be read at all, every column is offered, as before.
- A view already grouped by another kind of field keeps showing that grouping, and its level can still be changed or removed.
- A second level follows the same rule among the fields no level uses yet.
- The grouping is still a part of the list's draft: **Discard** and **Save** appear, and nothing is written.

`@object-ui/components`: with `askFieldOnAdd`, `GroupingEditor`'s "Add group field" opens a row whose field dropdown is already open and writes the level only on a pick. With no `fieldOptions` it draws the button disabled, explained by `labels.noFields`, or without a reason while `fieldOptionsLoading`. `fieldLabel(field)` labels a level whose field `fieldOptions` does not carry. Without these props the editor behaves as before.
10 changes: 8 additions & 2 deletions docs/qa/platform-checklist/areas/records-forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -3610,7 +3610,7 @@
"title": "Grid personalization persists across reload: column resize/reorder/pin, row-height, group-by (with API-true totals), row-color",
"since": "v16",
"status": "active",
"revision": 10,
"revision": 11,
"priority": "P2",
"surface": "browser",
"personas": [
Expand All @@ -3637,7 +3637,7 @@
"open showcase_task grid; screenshot",
"resize a column (reorder two columns only on a grid that sets reorderableColumns; there is no runtime pin control — acceptance[0]), and set a row height on the Row height level of the list's options menu (the toolbar's options trigger, then 行高 / Row height: three choices, 紧凑 / 标准 / 宽松 — Compact / Standard / Spacious, ui/packages/plugin-list/src/components/ViewSettingsPopover.tsx; a gallery's Row height level picks its card size the same way) — three modes, stored as rowHeight compact / medium / tall (the spec's five row heights compact/short/medium/tall/extra_tall narrow onto these three: objectui core normalize-list-view.ts DENSITY_MODE_TO_ROW_HEIGHT / ROW_HEIGHT_TO_DENSITY_MODE)",
"reload; confirm the column widths and row-height restored — they are kept in this browser for the signed-in user, localStorage list-layout:<userId>:showcase_task (perView.<view>.widths / rowHeight, objectstack#35955; before it the user's sys_user_preference ui.list.showcase_task row, objectui#12418). A column ORDER is not: since objectstack#35955 it is the list's unsaved draft, so a reload reopens on the view's own order unless it was saved into a view, with localStorage grid-columns-showcase_task[-<viewId>] as the component's cache; the old per-view override through dataSource.updateViewConfig is retired (objectui#12504). Also open the list in a FRESH browser context as the same user: the layout does NOT follow the user there — it opens on the view's own widths and row height, by design (objectstack#35955)",
"group-by status ('Add group field' pre-selects the first field, Title, and groups at once, so switch it to Status). A runtime grouping lives in the list's URL (uf__group, ui/packages/app-shell/src/views/objectViewListUrlState.ts), not in sys_user_preference: reloading that URL keeps it, a reload of the bare list URL reopens on the view's own grouping by design, and steps[6] reads it that way (QA run #33861). Confirm per-group headers appear and each group shows its record count — summarizeField (estimate_hours) is declared on the KANBAN config of task.view.ts, not on the grid, so grid groups carry counts; clear grouping and confirm the headers are removed cleanly",
"group-by status ('Add group field' adds no field and does not group: the field dropdown opens listing only the fields that can group, single select or radio, tick, person and linked record, so no Title, number or date, objectstack#36204; pick Status there. Closing it without a pick leaves the grid ungrouped, and a grid with no such field draws the button disabled with its reason). A runtime grouping lives in the list's URL (uf__group, ui/packages/app-shell/src/views/objectViewListUrlState.ts), not in sys_user_preference: reloading that URL keeps it, a reload of the bare list URL reopens on the view's own grouping by design, and steps[6] reads it that way (QA run #33861). Confirm per-group headers appear and each group shows its record count — summarizeField (estimate_hours) is declared on the KANBAN config of task.view.ts, not on the grid, so grid groups carry counts; clear grouping and confirm the headers are removed cleanly",
"cross-check each group's count against a direct per-group server count (GET /api/v1/data/showcase_task filtered to that status, read its total)",
"read the row-color rule the stock Grid view declares — rowColor on priority with the colors map low slate / medium blue / high amber / urgent red (examples/app-showcase/src/ui/views/task.view.ts); there is no runtime row-color authoring control — and confirm rows paint by it (useRowColor, the -100 tint of each name)",
"reload once more; confirm every personalization this item stores survives (column widths, row height); capture a screenshot per variant"
Expand Down Expand Up @@ -3749,6 +3749,12 @@
"date": "2026-11-21",
"change": "steps[2], acceptance[1] (verify), acceptance[4] (clause, verify, evidence) and source[2] re-pointed (objectstack#35955 PR3, Sales ruling D1 on #35955): column widths and row height are kept in this browser only, localStorage list-layout:<user id>:<object>, and the ui.list.<object> row is retired. Changed on purpose: they no longer follow the user to a fresh browser. Not loosened: they still survive a reload in the same browser and never reach another account",
"ref": "#35955"
},
{
"revision": 11,
"date": "2026-11-22",
"change": "steps[3] re-pointed (objectstack#36204): 'Add group field' no longer pre-selects the first column; it opens the field dropdown without grouping, the dropdown lists only fields that can group (single select or radio, tick, person, linked record), the grouping happens on the pick of Status, and with no such field the button is disabled with its reason. No clause changed.",
"ref": "#36204"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,19 @@ async function openGroupPanel() {
await settle();
}

/**
* "Add group field", then the field. This harness's data source answers no
* `getObjectSchema`, so the list knows no field's type and the button opens
* the field dropdown instead of adding a level (objectstack#36204): the level
* is written once a field is picked there.
*/
async function addGroupLevel(name: string) {
fireEvent.click(screen.getByTestId('grouping-add'));
const listbox = await screen.findByRole('listbox');
// No definition either for the labels: the options are the field names.
fireEvent.click(within(listbox).getByRole('option', { name }));
}

/** The Group level's own Clear, inside the Display menu. */
function clearGrouping() {
const panel = screen.getByTestId('view-settings-content');
Expand Down Expand Up @@ -787,7 +800,7 @@ describe('the toolbar grouping is in the URL too (objectui#11860)', () => {
const host = await mountHost(['/elsewhere', `${VIEW}/all`]);
expect(groupedBy()).toBeUndefined();
await openGroupPanel();
fireEvent.click(screen.getByTestId('grouping-add'));
await addGroupLevel('priority');
await settle();
const written = groupParamOf(host);
expect(written?.fields).toHaveLength(1);
Expand All @@ -808,7 +821,7 @@ describe('the toolbar grouping is in the URL too (objectui#11860)', () => {
it('the grouping a user set on a link survives a reload of that link', async () => {
const host = await mountHost([`${VIEW}/all`]);
await openGroupPanel();
fireEvent.click(screen.getByTestId('grouping-add'));
await addGroupLevel('priority');
await settle();
const url = `${host.pathname()}${host.search()}`;
const field = groupParamOf(host).fields[0].field;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* "Add group field" adds no field by itself (objectstack#36204).
*
* It used to add the first field no level used, at once: in a list the first
* column, a name as a rule, so the first click grouped the records one per
* group. With `askFieldOnAdd` the click writes nothing and opens a row whose
* field dropdown is already open; the level is written only once a field is
* picked there, and closing the dropdown without a pick writes nothing.
* With no field to offer the button stays, disabled, and `labels.noFields`
* says why; while `fieldOptionsLoading` it is disabled without a reason.
*
* DIRECTION: every pin but the CONTROLs fails on the old editor (the button
* wrote the first field at once, no pending row existed, and with no option
* the button was simply not drawn). The CONTROLs are the old behaviour, kept
* for a host that passes none of the new props.
*/
import { describe, it, expect, vi } from 'vitest';
import React from 'react';
import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';
import '@testing-library/jest-dom';
import { GroupingEditor, type GroupingConfigValue, type GroupingEditorProps } from '../custom/grouping-editor';

const FIELD_OPTIONS = [
{ value: 'status', label: 'Status' },
{ value: 'owner', label: 'Owner' },
{ value: 'vip', label: 'VIP' },
];

function renderEditor(value: GroupingConfigValue | undefined, extra: Partial<GroupingEditorProps> = {}) {
const onChange = vi.fn();
const props: GroupingEditorProps = { value, onChange, fieldOptions: FIELD_OPTIONS, askFieldOnAdd: true, ...extra };
const utils = render(<GroupingEditor {...props} />);
return { ...utils, onChange, props };
}

const labels = (options: HTMLElement[]) => options.map((o) => o.textContent ?? '');

describe('"Add group field" opens the field dropdown and writes nothing until a pick', () => {
it('opens a row with its dropdown open, writes nothing, and hides the add button', async () => {
const { onChange } = renderEditor(undefined);
fireEvent.click(screen.getByTestId('grouping-add'));
expect(onChange).not.toHaveBeenCalled();
expect(screen.getByTestId('grouping-field-pending')).toBeInTheDocument();
expect(screen.queryByTestId('grouping-add')).toBeNull();
// No level yet: the list is not grouped.
expect(screen.queryByTestId('grouping-field-0')).toBeNull();
const listbox = await screen.findByRole('listbox');
expect(labels(within(listbox).getAllByRole('option'))).toEqual(['Status', 'Owner', 'VIP']);
});

it('a pick writes the level and the row becomes that level', async () => {
const { onChange, rerender, props } = renderEditor(undefined);
fireEvent.click(screen.getByTestId('grouping-add'));
const listbox = await screen.findByRole('listbox');
fireEvent.click(within(listbox).getAllByRole('option').find((o) => o.textContent === 'Owner')!);
expect(onChange).toHaveBeenCalledTimes(1);
const written = onChange.mock.calls[0][0];
expect(written).toStrictEqual({ fields: [{ field: 'owner', order: 'asc', collapsed: false }] });
rerender(<GroupingEditor {...props} value={written} />);
await waitFor(() => expect(screen.queryByTestId('grouping-field-pending')).toBeNull());
expect(screen.getByTestId('grouping-field-0')).toHaveTextContent('Owner');
expect(screen.getByTestId('grouping-add')).toBeInTheDocument();
});

it('a second level offers only the fields no level uses and appends', async () => {
const { onChange } = renderEditor({ fields: [{ field: 'status', order: 'desc', collapsed: true }] });
fireEvent.click(screen.getByTestId('grouping-add'));
const listbox = await screen.findByRole('listbox');
expect(labels(within(listbox).getAllByRole('option'))).toEqual(['Owner', 'VIP']);
fireEvent.click(within(listbox).getAllByRole('option').find((o) => o.textContent === 'VIP')!);
expect(onChange.mock.calls[0][0]).toStrictEqual({
fields: [
{ field: 'status', order: 'desc', collapsed: true },
{ field: 'vip', order: 'asc', collapsed: false },
],
});
});

it('closing the dropdown without a pick drops the row and writes nothing', async () => {
const { onChange } = renderEditor(undefined);
fireEvent.click(screen.getByTestId('grouping-add'));
const listbox = await screen.findByRole('listbox');
fireEvent.keyDown(listbox, { key: 'Escape' });
await waitFor(() => expect(screen.queryByTestId('grouping-field-pending')).toBeNull());
expect(onChange).not.toHaveBeenCalled();
expect(screen.getByTestId('grouping-add')).toBeInTheDocument();
});

it('CONTROL: without `askFieldOnAdd` the first unused field is added at once, as before', () => {
const { onChange } = renderEditor(undefined, { askFieldOnAdd: undefined });
fireEvent.click(screen.getByTestId('grouping-add'));
expect(onChange.mock.calls[0][0]).toStrictEqual({
fields: [{ field: 'status', order: 'asc', collapsed: false }],
});
});
});

describe('no field to offer: the button stays, disabled, and says why', () => {
it('with `labels.noFields` the button is disabled and described by the reason', () => {
const { onChange } = renderEditor(undefined, { fieldOptions: [], labels: { noFields: 'Nothing can group this' } });
const button = screen.getByTestId('grouping-add');
expect(button).toBeDisabled();
const reason = screen.getByTestId('grouping-no-fields');
expect(reason).toHaveTextContent('Nothing can group this');
expect(button).toHaveAttribute('aria-describedby', reason.id);
fireEvent.click(button);
expect(onChange).not.toHaveBeenCalled();
expect(screen.queryByTestId('grouping-field-pending')).toBeNull();
});

it('while the options load the button is disabled without a reason', () => {
renderEditor(undefined, { fieldOptions: [], fieldOptionsLoading: true, labels: { noFields: 'Nothing can group this' } });
const button = screen.getByTestId('grouping-add');
expect(button).toBeDisabled();
expect(button).not.toHaveAttribute('aria-describedby');
expect(screen.queryByTestId('grouping-no-fields')).toBeNull();
});

it('once the options arrive the button is enabled', async () => {
const { rerender, props } = renderEditor(undefined, { fieldOptions: [], fieldOptionsLoading: true });
expect(screen.getByTestId('grouping-add')).toBeDisabled();
rerender(<GroupingEditor {...props} fieldOptions={FIELD_OPTIONS} fieldOptionsLoading={false} />);
expect(screen.getByTestId('grouping-add')).toBeEnabled();
fireEvent.click(screen.getByTestId('grouping-add'));
expect(await screen.findByRole('listbox')).toBeInTheDocument();
});

it('CONTROL: with no option and no `noFields`, no add button is drawn, as before', () => {
renderEditor(undefined, { fieldOptions: [], askFieldOnAdd: undefined });
expect(screen.queryByTestId('grouping-add')).toBeNull();
expect(screen.queryByTestId('grouping-no-fields')).toBeNull();
});
});

describe('a level grouped by a field the host does not offer', () => {
it('shows the label `fieldLabel` gives', () => {
renderEditor({ fields: [{ field: 'customer_name', order: 'asc', collapsed: false }] }, {
fieldLabel: (f) => (f === 'customer_name' ? 'Customer name' : undefined),
});
expect(screen.getByTestId('grouping-field-0')).toHaveTextContent('Customer name');
});

it('CONTROL: without `fieldLabel` it shows the field name', () => {
renderEditor({ fields: [{ field: 'customer_name', order: 'asc', collapsed: false }] });
expect(screen.getByTestId('grouping-field-0')).toHaveTextContent('customer_name');
});
});
Loading
Loading