From 06d9654dda057541894507d240d67899db8ab9fa Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 06:01:06 +0000 Subject: [PATCH 1/3] fix(ui): name a lookup's group headers and filter options by the target nameField; localize the empty group Claude-Session: https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi Co-authored-by: Claude --- ...er-builder-lookup-namefield-35053.test.tsx | 100 ++++++++ .../components/src/custom/filter-builder.tsx | 62 +++-- .../src/utils/__tests__/record-title.test.ts | 27 ++ ui/packages/core/src/utils/record-title.ts | 51 +++- .../__tests__/groupDateHeading-13234.test.tsx | 10 +- .../groupSelectOptionOrder-11809.test.tsx | 10 +- .../lookupGroupNameField-35053.test.tsx | 232 ++++++++++++++++++ .../serverGroupingFieldSwitch-11574.test.tsx | 2 +- .../plugin-grid/src/lookupGroupTargets.ts | 63 +++++ .../plugin-grid/src/objectGridGrouping.ts | 43 +++- ui/packages/plugin-grid/src/useGroupedData.ts | 54 ++-- .../plugin-grid/src/useServerGrouping.ts | 22 +- 12 files changed, 604 insertions(+), 72 deletions(-) create mode 100644 ui/packages/components/src/__tests__/filter-builder-lookup-namefield-35053.test.tsx create mode 100644 ui/packages/plugin-grid/src/__tests__/lookupGroupNameField-35053.test.tsx create mode 100644 ui/packages/plugin-grid/src/lookupGroupTargets.ts diff --git a/ui/packages/components/src/__tests__/filter-builder-lookup-namefield-35053.test.tsx b/ui/packages/components/src/__tests__/filter-builder-lookup-namefield-35053.test.tsx new file mode 100644 index 00000000000..f9b59bdf5c2 --- /dev/null +++ b/ui/packages/components/src/__tests__/filter-builder-lookup-namefield-35053.test.tsx @@ -0,0 +1,100 @@ +/** + * 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. + */ + +/** + * objectstack#35053 — the filter value picker names a lookup's candidate + * records by the TARGET object's declared `nameField` when the lookup declares + * no `displayField`, the default the spec's `FieldSchema.displayField` states. + * The target here is titled by an autonumber `deal_number` and has no `name`, + * `label` or `title`, so the old `displayField || "name"` read printed every + * option, and the chosen value's chip, as the raw record id. + * + * The control: an explicit `displayField` on the lookup still wins. The value + * the picker writes stays the record's id. + */ +import { describe, it, expect, vi } from 'vitest'; +import React from 'react'; +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { SchemaRendererContext } from '@object-ui/react'; +import { FilterBuilder } from '../custom/filter-builder'; + +const TARGET = 'crm_deal_confirmation'; + +const TARGET_DEF = { + name: TARGET, + nameField: 'deal_number', + fields: { + deal_number: { type: 'autonumber', label: 'Deal Number' }, + code: { type: 'text', label: 'Code' }, + }, +}; + +const DEALS = [ + { id: 'KC3TKTKQPLwGVqsJ', deal_number: 'DEAL-2026-0002', code: 'C-2' }, + { id: 'T1lF9T1kq45KAN06', deal_number: 'DEAL-2026-0001', code: 'C-1' }, +]; + +function fakeDataSource() { + return { + find: vi.fn(async (_object: string, params: Record) => { + const ids: string[] | undefined = params.$filter?.id?.$in; + return { data: ids ? DEALS.filter((d) => ids.includes(d.id)) : DEALS }; + }), + getObjectSchema: vi.fn(async (name: string) => (name === TARGET ? TARGET_DEF : undefined)), + }; +} + +function renderRow(lookupExtra: Record, value: unknown, dataSource: unknown) { + const onChange = vi.fn(); + const fields = [ + { value: 'deal_confirmation', label: 'Deal', type: 'lookup', referenceTo: TARGET, ...lookupExtra }, + ]; + const tree = { + id: 'root', + logic: 'and', + conditions: [{ id: 'c1', field: 'deal_confirmation', operator: 'equals', value }], + }; + render( + + + , + ); + return onChange; +} + +describe('filter value picker names lookup options by the target nameField (objectstack#35053)', () => { + it('lists the deal numbers, not the record ids, and writes the id it picks', async () => { + const dataSource = fakeDataSource(); + const onChange = renderRow({}, '', dataSource); + fireEvent.click(screen.getByTestId('lookup-picker-deal_confirmation')); + const option = await screen.findByText('DEAL-2026-0001'); + expect(screen.getByText('DEAL-2026-0002')).toBeInTheDocument(); + expect(screen.queryByText(DEALS[1].id)).not.toBeInTheDocument(); + expect(dataSource.getObjectSchema).toHaveBeenCalledWith(TARGET); + + fireEvent.click(option); + const calls = onChange.mock.calls; + expect(calls[calls.length - 1][0].conditions[0]).toMatchObject({ value: DEALS[1].id }); + }); + + it('the chosen value\'s chip reads the deal number', async () => { + renderRow({}, DEALS[1].id, fakeDataSource()); + await waitFor(() => + expect(screen.getByTestId('lookup-picker-deal_confirmation')).toHaveTextContent('DEAL-2026-0001'), + ); + }); + + it('CONTROL — an explicit `displayField` on the lookup still wins over the nameField', async () => { + renderRow({ displayField: 'code' }, '', fakeDataSource()); + fireEvent.click(screen.getByTestId('lookup-picker-deal_confirmation')); + expect(await screen.findByText('C-1')).toBeInTheDocument(); + expect(screen.getByText('C-2')).toBeInTheDocument(); + expect(screen.queryByText('DEAL-2026-0001')).not.toBeInTheDocument(); + }); +}); diff --git a/ui/packages/components/src/custom/filter-builder.tsx b/ui/packages/components/src/custom/filter-builder.tsx index ec954c64bd5..b48b717e0e1 100644 --- a/ui/packages/components/src/custom/filter-builder.tsx +++ b/ui/packages/components/src/custom/filter-builder.tsx @@ -17,7 +17,7 @@ import { type ViewFilterRule, } from "@objectstack/spec/ui" import { DATE_RANGE_PRESETS, expandEmptyOperator, type DateRangePreset } from "@objectstack/spec/data" -import { SchemaRendererContext } from "@object-ui/react" +import { SchemaRendererContext, useSettledSchema } from "@object-ui/react" import { FILTER_DATE_LIKE_TYPES, FILTER_LOOKUP_LIKE_TYPES, @@ -36,6 +36,7 @@ import { ComponentRegistry, isRealCalendarDate, isRetiredFieldType, + referencedRecordTitle, reportRetiredFieldType, toDateTimeInputValue, } from "@object-ui/core" @@ -2712,17 +2713,27 @@ function LookupValuePicker({ field, value, multiple, onChange }: LookupValuePick // list that disagrees with the gate about what is live. const referenceTo = field.referenceTo || (field.type === "user" ? "users" : undefined) - const displayField = field.displayField || "name" + // The lookup's own `displayField` when it declares one; otherwise the target + // object's declared `nameField` names each option (objectstack#35053), read + // from the target's definition: one schema read per picker, which the + // ObjectStack adapter serves from its metadata cache after the first. + const displayField = field.displayField || undefined const idField = field.idField || "id" + const { def: targetDef } = useSettledSchema( + referenceTo ?? "", + referenceTo && dataSource && typeof dataSource.find === "function" ? dataSource : undefined, + ) const [open, setOpen] = React.useState(false) const [searchQuery, setSearchQuery] = React.useState("") - const [options, setOptions] = React.useState([]) + // The records the search answered; their labels are derived at render, so + // a target definition that lands after them still names them. + const [optionRecords, setOptionRecords] = React.useState([]) const [loading, setLoading] = React.useState(false) const [error, setError] = React.useState(null) - // Resolved labels for currently selected ids (so we can render chips even - // when the selection isn't part of the latest fetched page). - const [resolved, setResolved] = React.useState>({}) + // The records of the currently selected ids, by id (so we can render chips + // even when the selection isn't part of the latest fetched page). + const [resolvedRecords, setResolvedRecords] = React.useState>({}) const debounceRef = React.useRef | null>(null) const selectedIds: string[] = React.useMemo(() => { @@ -2736,14 +2747,21 @@ function LookupValuePicker({ field, value, multiple, onChange }: LookupValuePick const hasDataSource = dataSource != null && typeof dataSource.find === "function" && !!referenceTo + // Grouped and filtered by id: two records with one title stay two options. const recordToOption = React.useCallback( (r: any): LookupOption => { const id = r?.[idField] ?? r?.id ?? r?._id - const label = r?.[displayField] ?? r?.label ?? r?.name ?? String(id) - return { value: id, label: String(label) } + const label = referencedRecordTitle(targetDef, r, displayField) ?? String(id) + return { value: id, label } }, - [displayField, idField], + [targetDef, displayField, idField], ) + const options = React.useMemo(() => optionRecords.map(recordToOption), [optionRecords, recordToOption]) + const resolved = React.useMemo(() => { + const labels: Record = {} + for (const [id, r] of Object.entries(resolvedRecords)) labels[id] = recordToOption(r).label + return labels + }, [resolvedRecords, recordToOption]) const fetchData = React.useCallback( async (search?: string) => { @@ -2755,30 +2773,29 @@ function LookupValuePicker({ field, value, multiple, onChange }: LookupValuePick if (search && search.trim()) params.$search = search.trim() const result = await dataSource.find(referenceTo, params) const records: any[] = result?.data ?? result ?? [] - const mapped = records.map(recordToOption) - setOptions(mapped) - // Cache resolved labels for any matching selected ids - if (mapped.length > 0) { - setResolved((prev) => { + setOptionRecords(records) + // Keep the records of any matching selected ids + if (records.length > 0) { + setResolvedRecords((prev) => { const next = { ...prev } - for (const opt of mapped) next[String(opt.value)] = opt.label + for (const r of records) next[String(r?.[idField] ?? r?.id ?? r?._id)] = r return next }) } } catch (err) { setError(err instanceof Error ? err.message : String(err)) - setOptions([]) + setOptionRecords([]) } finally { setLoading(false) } }, - [dataSource, referenceTo, hasDataSource, recordToOption], + [dataSource, referenceTo, hasDataSource, idField], ) // Resolve labels for already-selected ids that we haven't seen yet React.useEffect(() => { if (!hasDataSource || selectedIds.length === 0) return - const missing = selectedIds.filter((id) => !(id in resolved)) + const missing = selectedIds.filter((id) => !(id in resolvedRecords)) if (missing.length === 0) return let cancelled = false ;(async () => { @@ -2789,12 +2806,9 @@ function LookupValuePicker({ field, value, multiple, onChange }: LookupValuePick }) const records: any[] = result?.data ?? result ?? [] if (cancelled) return - setResolved((prev) => { + setResolvedRecords((prev) => { const next = { ...prev } - for (const r of records) { - const opt = recordToOption(r) - next[String(opt.value)] = opt.label - } + for (const r of records) next[String(r?.[idField] ?? r?.id ?? r?._id)] = r return next }) } catch { @@ -2804,7 +2818,7 @@ function LookupValuePicker({ field, value, multiple, onChange }: LookupValuePick return () => { cancelled = true } - }, [selectedIds, hasDataSource, dataSource, referenceTo, idField, recordToOption, resolved]) + }, [selectedIds, hasDataSource, dataSource, referenceTo, idField, resolvedRecords]) // Fetch initial data when popover opens React.useEffect(() => { diff --git a/ui/packages/core/src/utils/__tests__/record-title.test.ts b/ui/packages/core/src/utils/__tests__/record-title.test.ts index 4840ac81ef5..725d6a5f57e 100644 --- a/ui/packages/core/src/utils/__tests__/record-title.test.ts +++ b/ui/packages/core/src/utils/__tests__/record-title.test.ts @@ -12,6 +12,7 @@ import { deriveTitleField, isTitleEligibleField, formatTitleTemplate, + referencedRecordTitle, } from '../record-title'; describe('getRecordDisplayName — ADR-0079 repro', () => { @@ -519,3 +520,29 @@ describe('formatTitleTemplate — the empty-placeholder sentinel', () => { expect(isPrintable(out)).toBe(true); }); }); + +describe('referencedRecordTitle — a lookup target named by its nameField (objectstack#35053)', () => { + const target = { + nameField: 'deal_number', + fields: { deal_number: { type: 'autonumber' }, code: { type: 'text' } }, + }; + const deal = { id: 'T1lF9T1kq45KAN06', deal_number: 'DEAL-2026-0001', code: 'C-1' }; + + it('reads the target nameField when the lookup declares no displayField', () => { + expect(referencedRecordTitle(target, deal)).toBe('DEAL-2026-0001'); + }); + + it('an explicit displayField wins over the nameField', () => { + expect(referencedRecordTitle(target, deal, 'code')).toBe('C-1'); + }); + + it('answers undefined where getRecordDisplayName would fall to its floor', () => { + expect(referencedRecordTitle(target, { id: 'x1' })).toBeUndefined(); + expect(getRecordDisplayName(target, { id: 'x1' })).toBe('Record #x1'); + expect(referencedRecordTitle(target, 'x1')).toBeUndefined(); + }); + + it('with no target definition, reads the record alone', () => { + expect(referencedRecordTitle(undefined, { id: 'a', name: 'Acme' })).toBe('Acme'); + }); +}); diff --git a/ui/packages/core/src/utils/record-title.ts b/ui/packages/core/src/utils/record-title.ts index d7e714385e9..7e11cc48fc6 100644 --- a/ui/packages/core/src/utils/record-title.ts +++ b/ui/packages/core/src/utils/record-title.ts @@ -560,6 +560,50 @@ export function getRecordDisplayName( record: any, options?: RecordDisplayNameOptions, ): string { + const named = recordTitleAboveFloor(objectDef, record, options); + if (named !== undefined) return named; + + // 5. Record-#id floor; only a truly id-less record hits the bare fallback. + const id = record?.id ?? record?._id; + if (id !== null && id !== undefined && String(id).trim() !== '') { + return `Record #${id}`; + } + return options?.fallback ?? 'Untitled'; +} + +/** + * The title of a record that a LOOKUP points at — a group header keyed by a + * lookup, a filter value option, any surface that names the referenced record + * from the record it read: the lookup field's own `displayField` (the + * caller's declared pointer, {@link RecordDisplayNameOptions.titleField}), + * then the target object's ladder from {@link getRecordDisplayName}, with its + * declared `nameField` above every heuristic. That is the default the spec + * states for a lookup with no `displayField` ("the referenced object's + * name/title"). + * + * Stops short of the `Record #` / `Untitled` floor and answers + * `undefined` instead, so each caller keeps its own face for a record nothing + * names (a raw key, an id chip). `targetDef` may be absent while the target's + * schema is unknown; the ladder then reads the record alone. + */ +export function referencedRecordTitle( + targetDef: any, + record: any, + displayField?: string, +): string | undefined { + if (!record || typeof record !== 'object') return undefined; + return recordTitleAboveFloor(targetDef, record, { titleField: displayField }); +} + +/** + * Every rung of {@link getRecordDisplayName} above its floor: the title, or + * `undefined` when no rung names the record. + */ +function recordTitleAboveFloor( + objectDef: any, + record: any, + options?: RecordDisplayNameOptions, +): string | undefined { // 0. Explicit title field — the caller's option, if it actually resolves on // the record. This is a DECLARED key: every view config that offers a // title pointer (`ui/CalendarConfig`, `ui/GalleryConfig`, `ui/GanttConfig`, @@ -632,10 +676,5 @@ export function getRecordDisplayName( } } - // 5. Record-#id floor; only a truly id-less record hits the bare fallback. - const id = record?.id ?? record?._id; - if (id !== null && id !== undefined && String(id).trim() !== '') { - return `Record #${id}`; - } - return options?.fallback ?? 'Untitled'; + return undefined; } diff --git a/ui/packages/plugin-grid/src/__tests__/groupDateHeading-13234.test.tsx b/ui/packages/plugin-grid/src/__tests__/groupDateHeading-13234.test.tsx index 37cc9edc3c9..93cd580abcc 100644 --- a/ui/packages/plugin-grid/src/__tests__/groupDateHeading-13234.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/groupDateHeading-13234.test.tsx @@ -27,7 +27,7 @@ * * CONTROLS, which hold before and after the change: the groups keep the order * and counts of their stored keys (the headings are drawn, not sorted), the - * empty group keeps its "(empty)" heading, and a text key reads as itself. + * empty group keeps its "Empty" heading, and a text key reads as itself. */ import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest'; import { render, cleanup } from '@testing-library/react'; @@ -269,7 +269,7 @@ describe.each(['server', 'client'])('a %s-grouped grid heads a date grou it('each heading reads the Period Start cell under it, never the stored key', async () => { const ds = renderGrouped(source, [{ field: 'period_start', order: 'desc' }], { date: format }); const bands = await settledBands(ds, 'Period Start', 5); - for (const band of bands.filter((b) => b.heading !== '(empty)')) { + for (const band of bands.filter((b) => b.heading !== 'Empty')) { expect(band.heading).toBe(band.cell); expect(DAY_KEYS_DESC).not.toContain(band.heading); } @@ -280,7 +280,7 @@ describe.each(['server', 'client'])('a %s-grouped grid heads a date grou it('each heading reads the Closed At cell under it, never the stored instant', async () => { const ds = renderGrouped(source, [{ field: 'closed_at', order: 'desc' }], { datetime: format }); const bands = await settledBands(ds, 'Closed At', 5); - for (const band of bands.filter((b) => b.heading !== '(empty)')) { + for (const band of bands.filter((b) => b.heading !== 'Empty')) { expect(band.heading).toBe(band.cell); expect(band.heading).not.toMatch(/^\d{4}-\d{2}-\d{2}T/); } @@ -297,7 +297,7 @@ describe.each(['server', 'client'])('a %s-grouped grid heads a date grou ['0:2026-08-01', '1'], ['0:', '1'], ]); - expect(bands[4].heading).toBe('(empty)'); + expect(bands[4].heading).toBe('Empty'); }); it('CONTROL — ascending order is the stored keys\' order too', async () => { @@ -334,7 +334,7 @@ describe('two-level grouping, date first (objectui#13234)', () => { '0:2026-08-01', '0:', ]); - for (const band of bands.filter((b) => b.heading !== '(empty)')) { + for (const band of bands.filter((b) => b.heading !== 'Empty')) { expect(band.heading).toBe(band.cell); expect(DAY_KEYS_DESC).not.toContain(band.heading); } diff --git a/ui/packages/plugin-grid/src/__tests__/groupSelectOptionOrder-11809.test.tsx b/ui/packages/plugin-grid/src/__tests__/groupSelectOptionOrder-11809.test.tsx index 10e8e6132b6..6dc573cdbf9 100644 --- a/ui/packages/plugin-grid/src/__tests__/groupSelectOptionOrder-11809.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/groupSelectOptionOrder-11809.test.tsx @@ -204,7 +204,7 @@ describe('grid groups follow a select field\'s declared option order (objectui#1 const ds = renderServerGrouped([{ field: 'status' }]); await settled(ds, 7); await vi.waitFor(() => - expect(groupLabels()).toEqual([...DECLARED_STATUS, 'legacy', '(empty)']), + expect(groupLabels()).toEqual([...DECLARED_STATUS, 'legacy', 'Empty']), ); }); @@ -218,7 +218,7 @@ describe('grid groups follow a select field\'s declared option order (objectui#1 const ds = renderServerGrouped([{ field: 'status', order: 'desc' }]); await settled(ds, 7); await vi.waitFor(() => - expect(groupLabels()).toEqual([...DECLARED_STATUS].reverse().concat(['legacy', '(empty)'])), + expect(groupLabels()).toEqual([...DECLARED_STATUS].reverse().concat(['legacy', 'Empty'])), ); }); @@ -234,7 +234,7 @@ describe('grid groups follow a select field\'s declared option order (objectui#1 const ds = renderClientGrouped([{ field: 'status' }]); await settled(ds, 7); await vi.waitFor(() => - expect(groupLabels()).toEqual([...DECLARED_STATUS, 'legacy', '(empty)']), + expect(groupLabels()).toEqual([...DECLARED_STATUS, 'legacy', 'Empty']), ); }); @@ -242,7 +242,7 @@ describe('grid groups follow a select field\'s declared option order (objectui#1 const ds = renderClientGrouped([{ field: 'status', order: 'desc' }]); await settled(ds, 7); await vi.waitFor(() => - expect(groupLabels()).toEqual([...DECLARED_STATUS].reverse().concat(['legacy', '(empty)'])), + expect(groupLabels()).toEqual([...DECLARED_STATUS].reverse().concat(['legacy', 'Empty'])), ); }); @@ -289,7 +289,7 @@ describe('the hook\'s option order, below the grid (objectui#11809)', () => { const statusRows = ROWS.map((r) => ({ ...r })); const { result } = renderHook(() => useGroupedData({ fields: [{ field: 'status' }] }, statusRows)); expect(result.current.groups.map((g) => g.label)).toEqual([ - '(empty)', + 'Empty', 'backlog', 'done', 'in_progress', diff --git a/ui/packages/plugin-grid/src/__tests__/lookupGroupNameField-35053.test.tsx b/ui/packages/plugin-grid/src/__tests__/lookupGroupNameField-35053.test.tsx new file mode 100644 index 00000000000..fab145e3ca5 --- /dev/null +++ b/ui/packages/plugin-grid/src/__tests__/lookupGroupNameField-35053.test.tsx @@ -0,0 +1,232 @@ +/** + * 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. + */ + +/** + * objectstack#35053 — a grid grouped by a lookup names each group by the + * TARGET object's declared `nameField` when the lookup declares no + * `displayField`, as the lookup's own cell already does; the spec's + * `FieldSchema.displayField` states that default ("defaults to the referenced + * object's name/title"). The target here is titled by an autonumber + * `deal_number` and has no `name` / `label` / `title` field, so the old + * `name ?? label ?? title` guess printed every group as its raw record id. + * + * Both producers are pinned: the server-grouped headers (labels read in the + * header load) and the client grouping (an expanded record per row). Each has + * a control that an explicit `displayField` still wins, and the groups stay + * keyed by id, so two records with one title stay two groups. The empty group + * reads the grid's own empty-value string in the reader's language. + */ +import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest'; +import { render, cleanup } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import React from 'react'; + +import { ObjectGrid } from '../ObjectGrid'; +import { ActionProvider } from '@object-ui/react'; +import { I18nProvider } from '@object-ui/i18n'; +import { registerAllFields } from '@object-ui/fields'; +import type { DataSource, ObjectGridSchema } from '@object-ui/types'; + +beforeAll(() => { + registerAllFields(); +}); + +const OBJECT = 'crm_cb_order'; +const TARGET = 'crm_deal_confirmation'; + +/** The target: titled by an autonumber, with no name-ish field at all. */ +const TARGET_DEF = { + name: TARGET, + nameField: 'deal_number', + fields: { + deal_number: { type: 'autonumber', label: 'Deal Number' }, + code: { type: 'text', label: 'Code' }, + amount: { type: 'number', label: 'Amount' }, + }, +}; + +const DEALS = [ + { id: 'T1lF9T1kq45KAN06', deal_number: 'DEAL-2026-0001', code: 'C-1', amount: 10 }, + { id: 'mhHko1m3h9-1aahG', deal_number: 'DEAL-2026-0002', code: 'C-2', amount: 20 }, +]; + +const orderFields = (lookupExtra: Record = {}) => ({ + id: { type: 'text', label: 'Id' }, + subject: { type: 'text', label: 'Subject' }, + deal_confirmation: { type: 'lookup', label: 'Deal', reference: TARGET, ...lookupExtra }, +}); + +const ORDER_ROWS: Array> = [ + { id: 'o1', subject: 'First', deal_confirmation: DEALS[0].id }, + { id: 'o2', subject: 'Second', deal_confirmation: DEALS[1].id }, + { id: 'o3', subject: 'Third', deal_confirmation: DEALS[0].id }, + { id: 'o4', subject: 'Unlinked', deal_confirmation: null }, +]; + +function matches(row: Record, cond: unknown): boolean { + if (cond === undefined || cond === null) return true; + return Object.entries(cond as Record).every(([key, value]) => { + if (key === '$and') return (value as unknown[]).every((c) => matches(row, c)); + if (value && typeof value === 'object' && !Array.isArray(value)) { + const op = value as Record; + if ('$eq' in op) return row[key] === op.$eq; + if ('$in' in op) return (op.$in as unknown[]).includes(row[key]); + if ('$null' in op) return op.$null ? row[key] == null : row[key] != null; + throw new Error(`double: unsupported operator ${JSON.stringify(op)}`); + } + return row[key] === value; + }); +} + +const schemaOf = (lookupExtra: Record) => vi.fn(async (name: string) => + name === TARGET ? TARGET_DEF : { name: OBJECT, fields: orderFields(lookupExtra) }); + +/** Serves the header query and the row pages of the order, and the deal reads. */ +const makeServerSource = (lookupExtra: Record = {}) => ({ + queryGroupHeaders: vi.fn(async (_object: string, query: { where?: unknown; groupBy?: string[] }) => { + const groupBy = query.groupBy ?? []; + const buckets = new Map(); + for (const row of ORDER_ROWS.filter((r) => matches(r, query.where))) { + const key = JSON.stringify(groupBy.map((f) => row[f] ?? null)); + buckets.set(key, (buckets.get(key) ?? 0) + 1); + } + return [...buckets.entries()].map(([key, count]) => { + const values = JSON.parse(key) as unknown[]; + return { ...Object.fromEntries(groupBy.map((f, i) => [f, values[i]])), count }; + }); + }), + find: vi.fn(async (object: string, params: Record) => { + const source = object === TARGET ? DEALS : ORDER_ROWS; + const matching = source.filter((r) => matches(r, params.$filter)); + const skip = (params.$skip as number | undefined) ?? 0; + const top = (params.$top as number | undefined) ?? matching.length; + return { data: matching.slice(skip, skip + top), total: matching.length }; + }), + findOne: vi.fn(), + create: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + getObjectSchema: schemaOf(lookupExtra), +}); + +/** The client path: rows handed in with each deal expanded, as `$expand` serves it. */ +const CLIENT_ROWS: Array> = [ + { id: 'o1', subject: 'First', deal_confirmation: DEALS[0] }, + { id: 'o2', subject: 'Second', deal_confirmation: DEALS[1] }, + { id: 'o3', subject: 'Third', deal_confirmation: DEALS[0] }, + { id: 'o4', subject: 'Unlinked', deal_confirmation: null }, +]; + +const makeSchemaOnlySource = (lookupExtra: Record = {}) => ({ + find: vi.fn(), + findOne: vi.fn(), + create: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + getObjectSchema: schemaOf(lookupExtra), +}); + +function renderGrid( + ds: unknown, + extra: Record = {}, + language?: string, +) { + const grid = ( + + + + ); + return render( + language + ? ( + + {grid} + + ) + : grid, + ); +} + +const groupLabels = () => + Array.from(document.querySelectorAll('.group-label')).map((el) => el.textContent); + +afterEach(() => cleanup()); + +describe('server-grouped headers name a lookup by its target nameField (objectstack#35053)', () => { + it('a target titled by `deal_number` heads its groups with the deal number, not the record id', async () => { + const ds = makeServerSource(); + renderGrid(ds); + await vi.waitFor(() => + expect(groupLabels()).toEqual(['Empty', 'DEAL-2026-0001', 'DEAL-2026-0002']), + ); + expect(ds.getObjectSchema).toHaveBeenCalledWith(TARGET); + }); + + it('CONTROL — an explicit `displayField` on the lookup still wins over the nameField', async () => { + const ds = makeServerSource({ displayField: 'code' }); + renderGrid(ds); + await vi.waitFor(() => expect(groupLabels()).toEqual(['Empty', 'C-1', 'C-2'])); + }); + + it('zh-CN: the empty group reads the grid\'s empty-value string in Chinese, and keeps its place', async () => { + const ds = makeServerSource(); + renderGrid(ds, {}, 'zh-CN'); + await vi.waitFor(() => + expect(groupLabels()).toEqual(['空', 'DEAL-2026-0001', 'DEAL-2026-0002']), + ); + }); +}); + +describe('client grouping names an expanded lookup by its target nameField (objectstack#35053)', () => { + it('heads each group with the deal number, counting by id', async () => { + const ds = makeSchemaOnlySource(); + renderGrid(ds, { data: { provider: 'value', items: CLIENT_ROWS } }); + await vi.waitFor(() => + expect(groupLabels()).toEqual(['Empty', 'DEAL-2026-0001', 'DEAL-2026-0002']), + ); + expect(ds.getObjectSchema).toHaveBeenCalledWith(TARGET); + }); + + it('CONTROL — an explicit `displayField` on the lookup still wins over the nameField', async () => { + const ds = makeSchemaOnlySource({ displayField: 'code' }); + renderGrid(ds, { data: { provider: 'value', items: CLIENT_ROWS } }); + await vi.waitFor(() => expect(groupLabels()).toEqual(['Empty', 'C-1', 'C-2'])); + }); + + it('two records sharing one title stay two groups', async () => { + const twin = { ...DEALS[1], deal_number: DEALS[0].deal_number }; + const ds = makeSchemaOnlySource(); + renderGrid(ds, { + data: { + provider: 'value', + items: [ + { id: 'o1', subject: 'First', deal_confirmation: DEALS[0] }, + { id: 'o2', subject: 'Second', deal_confirmation: twin }, + ], + }, + }); + await vi.waitFor(() => expect(groupLabels()).toEqual(['DEAL-2026-0001', 'DEAL-2026-0001'])); + }); + + it('zh-CN: the empty group reads the grid\'s empty-value string in Chinese', async () => { + const ds = makeSchemaOnlySource(); + renderGrid(ds, { data: { provider: 'value', items: CLIENT_ROWS } }, 'zh-CN'); + await vi.waitFor(() => + expect(groupLabels()).toEqual(['空', 'DEAL-2026-0001', 'DEAL-2026-0002']), + ); + }); +}); diff --git a/ui/packages/plugin-grid/src/__tests__/serverGroupingFieldSwitch-11574.test.tsx b/ui/packages/plugin-grid/src/__tests__/serverGroupingFieldSwitch-11574.test.tsx index 57d73987240..60f2bfad236 100644 --- a/ui/packages/plugin-grid/src/__tests__/serverGroupingFieldSwitch-11574.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/serverGroupingFieldSwitch-11574.test.tsx @@ -192,7 +192,7 @@ async function expectServerGroups(field: string, expected: number) { await vi.waitFor(() => expect(headerLabels()).toEqual(expect.arrayContaining(answer))); // Exactly the server's groups: none left over from the previous field. expect([...headerLabels()].sort()).toEqual(answer); - expect(headerLabels()).not.toContain('(empty)'); + expect(headerLabels()).not.toContain('Empty'); // …and no group is left on "Loading grid…". await vi.waitFor(() => expect(stuckLoading()).toHaveLength(0)); } diff --git a/ui/packages/plugin-grid/src/lookupGroupTargets.ts b/ui/packages/plugin-grid/src/lookupGroupTargets.ts new file mode 100644 index 00000000000..f88a05c48a7 --- /dev/null +++ b/ui/packages/plugin-grid/src/lookupGroupTargets.ts @@ -0,0 +1,63 @@ +/** + * The object a grouping lookup points at, read so its group headers are named + * by that object's declared `nameField` (through `@object-ui/core`'s + * `referencedRecordTitle`) rather than by a guessed `name` / `label` / `title` + * key. Shared by the server-grouped headers (`useServerGrouping.ts`) and the + * client grouping formatter (`objectGridGrouping.ts`). + */ + +import { useEffect, useState } from 'react'; +import type { DataSource } from '@object-ui/types'; + +/** + * The definition of `objectName`, or `undefined` when the data source cannot + * serve one or the read fails. Never rejects: a group header with no target + * definition is still labelled, by the record alone. + * + * One read per call; the ObjectStack adapter serves repeat reads of an object + * from its metadata cache, so each target is fetched at most once per session. + */ +export async function readLookupTargetDef( + dataSource: Pick | null | undefined, + objectName: string, +): Promise { + if (!dataSource || typeof dataSource.getObjectSchema !== 'function') return undefined; + try { + const def = await dataSource.getObjectSchema(objectName); + return def && typeof def === 'object' ? def : undefined; + } catch { + return undefined; + } +} + +/** + * The definitions of `targets` (object names), keyed by name, read once per + * target per change of the list. A target still in flight, or one that could + * not be read, is absent from the map. + * + * Keyed on the list's CONTENT, never on the identity of the array a host may + * rebuild every render (`ui/AGENTS.md` #10). + */ +export function useLookupTargetDefs( + dataSource: Pick | null | undefined, + targets: readonly string[], +): ReadonlyMap | undefined { + const targetsKey = JSON.stringify([...new Set(targets)].sort()); + const [held, setHeld] = useState<{ key: string; defs: ReadonlyMap } | null>(null); + + useEffect(() => { + const names = JSON.parse(targetsKey) as string[]; + if (names.length === 0 || !dataSource) return; + let cancelled = false; + void Promise.all(names.map(async (name) => [name, await readLookupTargetDef(dataSource, name)] as const)) + .then((answers) => { + if (cancelled) return; + const defs = new Map(); + for (const [name, def] of answers) if (def !== undefined) defs.set(name, def); + setHeld({ key: targetsKey, defs }); + }); + return () => { cancelled = true; }; + }, [dataSource, targetsKey]); + + return held?.key === targetsKey ? held.defs : undefined; +} diff --git a/ui/packages/plugin-grid/src/objectGridGrouping.ts b/ui/packages/plugin-grid/src/objectGridGrouping.ts index cf161b7cc04..caefb01b9e6 100644 --- a/ui/packages/plugin-grid/src/objectGridGrouping.ts +++ b/ui/packages/plugin-grid/src/objectGridGrouping.ts @@ -10,7 +10,7 @@ import React, { useEffect } from 'react'; import type { ObjectGridSchema, DataSource, ListColumn } from '@object-ui/types'; import { parseFilterAST, type FilterCondition } from '@objectstack/spec/data'; import type { useSafeFieldLabel } from '@object-ui/react'; -import { buildCategoryOrder, buildCategoryRank } from '@object-ui/core'; +import { buildCategoryOrder, buildCategoryRank, isExpandableFieldType, referencedRecordTitle } from '@object-ui/core'; import { useDisplayLocale } from '@object-ui/i18n'; import type { GridCellFieldLike } from './cellRendererResolution'; import { temporalCellFaceOf, type TemporalCellFace } from './temporalCellFace'; @@ -19,6 +19,7 @@ import { type GroupAggregationConfig, type GroupOptionRanks, type ServerGroupSource, type TemporalAggregateFaces, } from './useGroupedData'; import { groupSearchOf, useServerGroupHeaders, useServerGroupRows, type ServerGroupLeaf } from './useServerGrouping'; +import { useLookupTargetDefs } from './lookupGroupTargets'; import { normalizeColumns } from './objectGridColumns'; import { honestGroupAggregations } from './recordCurrencyAggregates'; import type { useGridTranslation } from './objectGridTranslations'; @@ -33,8 +34,17 @@ type RowLoad = ReturnType; type GroupingFieldDef = GridCellFieldLike & { type?: string; options?: Parameters['translateOptions']>[2]; + reference?: unknown; + displayField?: unknown; }; +/** The object a grouping field points at, when it is a lookup that names one. */ +function lookupTargetOf(def: GroupingFieldDef | undefined): string | undefined { + return isExpandableFieldType(def) && typeof def?.reference === 'string' && def.reference !== '' + ? def.reference + : undefined; +} + /** * The date-family face the cell of `field` paints in this grid: the authored * column's `type` over the object field's, with the object field's `format` @@ -105,6 +115,19 @@ export function useObjectGridGrouping({ // readable label for select/boolean fields rather than the raw value // (e.g. "In Progress" instead of "in_progress", "Yes" instead of "true"). // A select value's label is the OBJECT FIELD's option label (objectui#11544). + // [objectstack#35053] The objects the client-grouped lookup fields point at: + // an expanded record is named by its target's declared `nameField` when the + // lookup declares no `displayField`, as the lookup's own cell names it. A + // server-grouped grid names its keys in the header read instead. + const lookupTargetDefs = useLookupTargetDefs( + dataSource, + serverGroupedFetch + ? [] + : usableGroupingFields(schema.grouping?.fields).flatMap((gf) => { + const target = lookupTargetOf(objectFields?.[gf.field]); + return target ? [target] : []; + }), + ); const groupValueFormatter = React.useMemo(() => { // [objectui#7217] ONE normalized entry list, shared with the // `useGroupedDataInOptionOrder` call below. Reading `grouping.fields` raw here threw @@ -118,7 +141,12 @@ export function useObjectGridGrouping({ // Per-field { value -> label } lookup, plus a per-field type so we can // handle booleans / dates / users without dedicated option lists. - const lookup = new Map }>(); + const lookup = new Map; + target?: string; + displayField?: string; + }>(); for (const gf of groupingFields) { const fieldName = gf.field; @@ -151,15 +179,24 @@ export function useObjectGridGrouping({ } } + const target = lookupTargetOf(objectDefField); + const displayField = objectDefField?.displayField; lookup.set(fieldName, { type: type || undefined, options: optionsMap.size > 0 ? optionsMap : undefined, + ...(target ? { target } : {}), + ...(target && typeof displayField === 'string' && displayField !== '' ? { displayField } : {}), }); } return (field: string, value: any): string | undefined => { const meta = lookup.get(field); if (!meta) return undefined; + // A lookup's expanded record: its `displayField`, then the target's + // declared `nameField`, then the shared ladder. Grouped by its id still. + if (meta.target && value && typeof value === 'object' && !Array.isArray(value)) { + return referencedRecordTitle(lookupTargetDefs?.get(meta.target), value, meta.displayField); + } // Select / multi-select: resolve from options map first. if (meta.options) { const label = meta.options.get(String(value)); @@ -176,7 +213,7 @@ export function useObjectGridGrouping({ } return undefined; }; - }, [schema.grouping, schema.columns, schema.objectName, objectFields, translateOptions, t]); + }, [schema.grouping, schema.columns, schema.objectName, objectFields, translateOptions, t, lookupTargetDefs]); // [objectui#13234] Per grouping field whose cell paints a date-family face, // that face; `temporalCellText` draws the field's group headings through diff --git a/ui/packages/plugin-grid/src/useGroupedData.ts b/ui/packages/plugin-grid/src/useGroupedData.ts index 7ebb8de3d4a..b3589d5c778 100644 --- a/ui/packages/plugin-grid/src/useGroupedData.ts +++ b/ui/packages/plugin-grid/src/useGroupedData.ts @@ -8,9 +8,10 @@ import { useState, useMemo, useCallback } from 'react'; import type { GroupingConfig } from '@object-ui/types'; -import { compareSortValues, getSortValue, type SortValue } from '@object-ui/core'; +import { compareSortValues, getSortValue, referencedRecordTitle, type SortValue } from '@object-ui/core'; import { deriveColumnSummary, listViewGroupOrderColumn, type ListViewGroupHeaderRow } from '@objectstack/spec/ui'; import { temporalCellText, temporalExtreme, temporalInstant, type TemporalCellFace } from './temporalCellFace'; +import { useGridTranslation } from './objectGridTranslations'; /** Supported aggregation function types. */ export type AggregationType = 'sum' | 'count' | 'avg' | 'min' | 'max' | 'count_distinct'; @@ -152,13 +153,15 @@ export type GroupValueFormatter = (field: string, value: any) => string | undefi * * When a `formatValue` resolver is supplied, it is consulted first so callers * can map raw values (e.g. select option codes, booleans) to display labels. + * `emptyLabel` is the empty group's heading, in the reader's language. */ function buildSegmentLabel( value: any, field: string, - formatValue?: GroupValueFormatter, + formatValue: GroupValueFormatter | undefined, + emptyLabel: string, ): string { - if (value === undefined || value === null || value === '') return '(empty)'; + if (value === undefined || value === null || value === '') return emptyLabel; if (formatValue) { const formatted = formatValue(field, value); if (formatted !== undefined && formatted !== '') return formatted; @@ -170,27 +173,22 @@ function buildSegmentLabel( const f2 = formatValue(field, v); if (f2 !== undefined && f2 !== '') return f2; } - return buildSegmentLabel(v, field); + return buildSegmentLabel(v, field, undefined, emptyLabel); }) .join(', '); - return joined || '(empty)'; + return joined || emptyLabel; } // Lookup / master_detail fields: the cell is an expanded object such as // `{ id, name, ... }`. Stringifying directly produces "[object Object]", - // so prefer common display fields, falling back to the id. + // so it is named by the shared referenced-record ladder, falling back to + // the id. With no target definition in hand the ladder reads the record + // alone; a host that holds one names it through `formatValue` above. if (typeof value === 'object') { - const label = - (value as any).name ?? - (value as any).label ?? - (value as any).title ?? - (value as any).display_name ?? - (value as any).displayName ?? - (value as any).fullName ?? - (value as any).full_name; - if (label !== undefined && label !== null && label !== '') return String(label); + const label = referencedRecordTitle(undefined, value); + if (label !== undefined) return label; const id = (value as any).id ?? (value as any)._id ?? (value as any).pk; if (id !== undefined && id !== null && id !== '') return String(id); - return '(empty)'; + return emptyLabel; } return String(value); } @@ -408,7 +406,7 @@ function compareGroupEntries( if (cmp !== 0) return order === 'desc' ? -cmp : cmp; } } - if (!ranks) return compareGroups(a.label, b.label, order); + if (!ranks) return compareGroupLabels(a, b, order); const aEmpty = a.segment === ''; const bEmpty = b.segment === ''; if (aEmpty || bEmpty) return aEmpty === bEmpty ? 0 : aEmpty ? 1 : -1; @@ -422,6 +420,19 @@ function compareGroupEntries( return order === 'desc' ? -cmp : cmp; } if (aRank || bRank) return aRank ? -1 : 1; + return compareGroupLabels(a, b, order); +} + +/** + * Label order, with the empty group placed by its KEY rather than by its + * heading: ahead of every label ascending and after every one descending, + * where the untranslated `(empty)` heading always sorted, whatever the + * heading reads in the reader's language. + */ +function compareGroupLabels(a: SortableGroup, b: SortableGroup, order: 'asc' | 'desc'): number { + const aEmpty = a.segment === ''; + const bEmpty = b.segment === ''; + if (aEmpty !== bEmpty) return (aEmpty ? -1 : 1) * (order === 'desc' ? -1 : 1); return compareGroups(a.label, b.label, order); } @@ -644,6 +655,9 @@ export function useGroupedDataInOptionOrder( const rawFields = config?.fields; const fields = useMemo(() => usableGroupingFields(rawFields), [rawFields]); const isGrouped = fields.length > 0; + // The empty group's heading: the grid's own empty-value string. + const { t } = useGridTranslation(); + const emptyLabel = t('grid.empty'); // Track which group keys have been explicitly toggled by the user. const [toggledKeys, setToggledKeys] = useState>({}); @@ -682,7 +696,7 @@ export function useGroupedDataInOptionOrder( row, raw, segment: extractValueKey(raw), - label: resolved ?? buildSegmentLabel(raw, f.field, formatValue), + label: resolved ?? buildSegmentLabel(raw, f.field, formatValue, emptyLabel), ...(orderColumn !== undefined ? { orderValue: orderValueOf(row[orderColumn]) } : {}), }; }); @@ -737,7 +751,7 @@ export function useGroupedDataInOptionOrder( const segment = buildSegmentKey(row, f.field); if (!map.has(segment)) { map.set(segment, { - label: buildSegmentLabel(row[f.field], f.field, formatValue), + label: buildSegmentLabel(row[f.field], f.field, formatValue, emptyLabel), rows: [], }); keyOrder.push(segment); @@ -791,7 +805,7 @@ export function useGroupedDataInOptionOrder( }; return buildLevel(data, 0, '', {}); - }, [data, fields, isGrouped, toggledKeys, aggregations, formatValue, server, optionRanks, temporalAggregates]); + }, [data, fields, isGrouped, toggledKeys, aggregations, formatValue, server, optionRanks, temporalAggregates, emptyLabel]); const toggleGroup = useCallback((key: string) => { setToggledKeys((prev) => { diff --git a/ui/packages/plugin-grid/src/useServerGrouping.ts b/ui/packages/plugin-grid/src/useServerGrouping.ts index 3e774b508eb..c7b633a990c 100644 --- a/ui/packages/plugin-grid/src/useServerGrouping.ts +++ b/ui/packages/plugin-grid/src/useServerGrouping.ts @@ -89,7 +89,8 @@ import { type ListViewGroupHeaderRow, type ListViewGroupQuerySource, } from '@objectstack/spec/ui'; -import { isExpandableFieldType } from '@object-ui/core'; +import { isExpandableFieldType, referencedRecordTitle } from '@object-ui/core'; +import { readLookupTargetDef } from './lookupGroupTargets'; import { groupOrderByOf, serverSummaryOf, type GroupAggregationConfig, type UsableGroupingField } from './useGroupedData'; /** @@ -281,17 +282,22 @@ export function useServerGroupHeaders(input: ServerGroupHeadersInput): ServerGro const ids = [...new Set(deepest.map((row) => row[field]).filter((v) => v !== null && v !== undefined && v !== ''))]; if (ids.length === 0) return; try { - const result = await dataSource.find(reference, { - $filter: { id: { $in: ids } }, - $top: ids.length, - }); + // The target's definition rides beside the record read: with no + // `displayField` on the lookup, its declared `nameField` names + // the record, as the lookup's own cell names it. + const [result, targetDef] = await Promise.all([ + dataSource.find(reference, { + $filter: { id: { $in: ids } }, + $top: ids.length, + }), + readLookupTargetDef(dataSource, reference), + ]); const byId: Record = {}; for (const rec of (result?.data ?? []) as Array>) { const id = rec?.id; if (id === undefined || id === null) continue; - const label = (displayField ? rec[displayField] : undefined) - ?? rec.name ?? rec.label ?? rec.title; - if (label !== undefined && label !== null && label !== '') byId[String(id)] = String(label); + const label = referencedRecordTitle(targetDef, rec, displayField ?? undefined); + if (label !== undefined) byId[String(id)] = label; } keyLabels[field] = byId; } catch (err) { From 2e944beb4b64582b92b2cfe642ca60cceb49e937 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 06:20:52 +0000 Subject: [PATCH 2/3] chore: changeset for the lookup label fix Claude-Session: https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi Co-authored-by: Claude --- .changeset/35053-lookup-label-namefield.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .changeset/35053-lookup-label-namefield.md diff --git a/.changeset/35053-lookup-label-namefield.md b/.changeset/35053-lookup-label-namefield.md new file mode 100644 index 00000000000..7ef91748b39 --- /dev/null +++ b/.changeset/35053-lookup-label-namefield.md @@ -0,0 +1,21 @@ +--- +'@object-ui/core': patch +'@object-ui/plugin-grid': patch +'@object-ui/components': patch +--- + +fix(ui): grouping headers and the filter value picker name a lookup by its target's `nameField`, and the empty group is translated + +Clause-②: no +Metadata-protocol: none + +A lookup with no `displayField` is now named by the target object's declared `nameField`, the default the spec states for `displayField` ("the referenced object's name/title"). This is the same title the lookup's grid cell and the record header already show. Before, three places guessed a `name`, `label` or `title` key, and showed the raw record id when the target had none, for example a target titled by an autonumber such as `DEAL-2026-0001`: + +- **Group headers of a list grouped by the lookup**, both server-grouped and client-grouped. +- **Filter builder value picker options** for the lookup, and the chip of the chosen value. + +An explicit `displayField` on the lookup still wins. Grouping and filtering stay keyed by record id, so two records with the same title stay separate groups and separate options. The picker reads the target object's definition once per picker. The ObjectStack adapter serves later reads of it from its metadata cache. + +The group of rows with no value now reads the grid's own empty-value string (`grid.empty`, for example "Empty" in English and "空" in Chinese) instead of the untranslated `(empty)`. It keeps its place in the group order: first when ascending and last when descending. + +`@object-ui/core` adds `referencedRecordTitle(targetDef, record, displayField?)`. It gives the title of a referenced record using the lookup's `displayField`, then the record-title ladder of `getRecordDisplayName`, and returns `undefined` instead of the `Record #` floor. From 861bdd2e4bfbd70774a19a1cf03902e3d511d469 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 07:35:29 +0000 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20declare=20the=20new=20referencedRe?= =?UTF-8?q?cordTitle=20export=20as=20Clause-=E2=91=A1=20widening?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi Co-authored-by: Claude --- .changeset/35053-lookup-label-namefield.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/35053-lookup-label-namefield.md b/.changeset/35053-lookup-label-namefield.md index 7ef91748b39..4f687d7c13c 100644 --- a/.changeset/35053-lookup-label-namefield.md +++ b/.changeset/35053-lookup-label-namefield.md @@ -6,7 +6,7 @@ fix(ui): grouping headers and the filter value picker name a lookup by its target's `nameField`, and the empty group is translated -Clause-②: no +Clause-②: yes (widening) Metadata-protocol: none A lookup with no `displayField` is now named by the target object's declared `nameField`, the default the spec states for `displayField` ("the referenced object's name/title"). This is the same title the lookup's grid cell and the record header already show. Before, three places guessed a `name`, `label` or `title` key, and showed the raw record id when the target had none, for example a target titled by an autonumber such as `DEAL-2026-0001`: @@ -18,4 +18,4 @@ An explicit `displayField` on the lookup still wins. Grouping and filtering stay The group of rows with no value now reads the grid's own empty-value string (`grid.empty`, for example "Empty" in English and "空" in Chinese) instead of the untranslated `(empty)`. It keeps its place in the group order: first when ascending and last when descending. -`@object-ui/core` adds `referencedRecordTitle(targetDef, record, displayField?)`. It gives the title of a referenced record using the lookup's `displayField`, then the record-title ladder of `getRecordDisplayName`, and returns `undefined` instead of the `Record #` floor. +`@object-ui/core` adds `referencedRecordTitle(targetDef, record, displayField?)` to its public entry, a new export. It gives the title of a referenced record using the lookup's `displayField`, then the record-title ladder of `getRecordDisplayName`, and returns `undefined` instead of the `Record #` floor.