Skip to content
Merged
17 changes: 17 additions & 0 deletions .changeset/33864-labels-over-machine-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@object-ui/app-shell': patch
'@object-ui/console': patch
'@object-ui/plugin-grid': patch
---

fix(console): four Console surfaces name things by their label, not their machine name

Clause-②: yes (widening)
Metadata-protocol: none

Anything shown to a person uses the label; the machine name appears at most as secondary text.

- Studio → Access: the suggested-binding banner, its Grant and Dismiss toasts and the state line a resolved suggestion keeps name the permission set by the label the rail shows for it, not by its machine name. A set with no label is still named by its machine name.
- Studio → Access → Record sharing: a "Controlled by parent" row reads `By parent → ` and the master object's label: this package's own object as the table reads it, else the served object's label, else its machine name.
- Setup → Audit Log: the Record column names the audited record by its display name, through the same batched resolver a list grid's `referenceVia` pointer column uses. The raw id is the tooltip; a record no read answers reads as `OBJECT · record unavailable` (its object's label). `@object-ui/plugin-grid` now exports that resolver's face, `RecordPointerCell`.
- Studio flow editor → Entry condition: the subject list offers each field by its label, with its path (`status`, `previous.status`) beside it.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,19 @@ const { ADAPTER, METADATA, SERVED_OBJECTS } = vi.hoisted(() => {
{ name: 'sys_audit_log', label: '审计日志' },
]) as readonly unknown[];
return {
// objectstack#33864 — `crm_account` is readable through the adapter, so
// its record can be named; every other object answers no definition and
// no rows (the actor lookup's `sys_user` included).
ADAPTER: {
find: async () => ({ data: [], total: 0 }),
find: async (objectName: string) =>
objectName === 'crm_account'
? { data: [{ id: 'acc_1', name: 'Acme Corp' }], total: 1 }
: { data: [], total: 0 },
findOne: async () => null,
getObjectSchema: async () => undefined,
getObjectSchema: async (objectName: string) =>
objectName === 'crm_account'
? { name: 'crm_account', label: '客户', nameField: 'name', fields: { name: { type: 'text', label: 'Name' } } }
: undefined,
},
SERVED_OBJECTS,
// Mutable per test: the served objects.
Expand Down Expand Up @@ -167,3 +176,32 @@ describe('AuditLogPage — the Object column and drawer show the served object l
expect(options).toContain('crm_blank');
});
});

/** The Record cell's text, by row. */
function recordCells(): string[] {
return bodyRows().map((row) => row.querySelectorAll('td')[3]?.textContent ?? '');
}

/**
* objectstack#33864 — the Record column names the audited record by its
* display name (`ux-conventions.labels-over-machine-names`), read through the
* grid's batched `referenceVia` pointer resolver (`record_id` is the id half
* of the pair `object_name` types). The raw id stays the cell's tooltip.
*/
describe('AuditLogPage — the Record column names the audited record (objectstack#33864)', () => {
it("shows a readable record's display name, the raw id as its tooltip", async () => {
renderPage();
await waitFor(() => expect(recordCells()[0]).toBe('Acme Corp'));
const cell = bodyRows()[0]!.querySelectorAll('td')[3]!;
expect(cell.querySelector('[data-record-pointer="readable"]')).toHaveAttribute('title', 'acc_1');
expect(recordCells()[0]).not.toContain('acc_1');
});

it('CONTROL: a record no read answers reads as unavailable, never as a bare id; a row with no record shows the dash', async () => {
renderPage();
await waitFor(() => expect(recordCells()[1]).toBe('nightly_widget · record unavailable'));
const cell = bodyRows()[1]!.querySelectorAll('td')[3]!;
expect(cell.querySelector('[data-record-pointer="unreadable"]')).toHaveAttribute('title', 'wid_1');
expect(recordCells()[3]).toBe('—');
});
});
16 changes: 15 additions & 1 deletion ui/apps/console/src/pages/system/AuditLogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
type ComboboxOption,
} from '@object-ui/components';
import { LookupField, getLazyFieldWidget, objectRefOptionLabel } from '@object-ui/fields';
import { RecordPointerCell } from '@object-ui/plugin-grid';
import { ConsolePageHeader, useAdapter, useMetadata } from '@object-ui/app-shell';
import { Search, X, AlertCircle, ScrollText, ExternalLink } from 'lucide-react';
import { actionBadgeVariant, actionFilterOptionsOf, actionLabelOf } from './auditLogActions';
Expand Down Expand Up @@ -719,7 +720,20 @@ export function AuditLogPage() {
<TableCell className="font-mono text-xs">{formatDate(r.created_at, displayLocale)}</TableCell>
<TableCell><Badge variant={variant}>{actionLabelOf(actionOptions, r.action) ?? '—'}</Badge></TableCell>
<TableCell>{objectLabelOf(objects, r.object_name) ?? '—'}</TableCell>
<TableCell className="font-mono text-xs">{truncate(r.record_id, 18)}</TableCell>
<TableCell className="max-w-[16rem] text-xs">
{/* The record by its display name, through the batched
pointer resolver the grid's `referenceVia` columns
use (`sys_audit_log.record_id` is the id half of the
pair `object_name` types). */}
{r.object_name && r.record_id ? (
<RecordPointerCell
pointer={{ objectName: r.object_name, recordId: r.record_id }}
dataSource={adapter}
/>
) : (
<span className="font-mono">{truncate(r.record_id, 18)}</span>
)}
</TableCell>
<TableCell><ActorCell face={actorOf(r)} /></TableCell>
<TableCell className="font-mono text-xs">{r.ip_address || '—'}</TableCell>
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ const OBJECTS_READERS: Record<string, { kind: Kind; why: string }> = {
kind: 'off',
why: "Studio: the Data pillar's Form tab asks selectRecordFormView which form view the app opens, over the served objects (objectstack#30057)",
},
'packages/app-shell/src/views/studio-design/PackageOwdOverviewPanel.tsx': {
kind: 'byName',
why: "Studio's record-sharing table: a controlled-by-parent row's master outside the package, its label by name (objectstack#33864)",
},
'packages/app-shell/src/views/studio-design/relatedListVocabulary.ts': {
kind: 'off',
why: "Studio: an object's inbound relationships, read while its Settings relatedLists editor or a field group's related-table picker is mounted",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import * as React from 'react';
import { describe, it, expect, afterEach, beforeAll, vi } from 'vitest';
import { render, cleanup, screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
// The source under test reaches a dynamic `import('@objectstack/lint')`; pay
// that load during collection, never inside a case's clocked window.
import '@objectstack/lint';

/**
* The trigger object's field catalog. Stubbed at the hook rather than at the
Expand Down Expand Up @@ -76,6 +79,7 @@ const FIELD_NAMES_IN_SCOPE = FIELDS.filter((f) => !f.hidden).map((f) => f.name);
import { FlowNodeConfigField } from './FlowNodeConfigField';
import { fieldsForNodeType, type FlowConfigField } from './flow-node-config';
import { resolveFlowScope, type TriggerScope } from './flow-scope';
import { tFormat } from '../i18n';

afterEach(cleanup);

Expand Down Expand Up @@ -277,12 +281,29 @@ describe('#6226 probe instrument — positive controls', () => {

/* ── the subject vocabulary AT THIS SITE ─────────────────────────────────── */

/** Open the row's SUBJECT dropdown and read back every subject offered. */
/**
* An option's CEL spelling. A field subject reads by its label with the
* spelling beside it (objectstack#33864), so the spelling is that hint; an
* unlabelled subject (`previous`) reads as its spelling alone.
*/
function spellingOf(option: HTMLElement): string {
const hint = option.querySelector('.font-mono');
return (hint ?? option).textContent ?? '';
}

/** Open the row's SUBJECT dropdown and read back the spelling of every subject offered. */
async function subjectOptions(container: HTMLElement): Promise<string[]> {
const trigger = container.querySelectorAll('[role="combobox"]')[0] as HTMLElement;
await userEvent.click(trigger);
const opts = await screen.findAllByRole('option');
return opts.map((o) => o.textContent ?? '');
return opts.map(spellingOf);
}

/** The open dropdown's option that offers `spelling`. */
function optionBySpelling(spelling: string): HTMLElement {
const option = screen.getAllByRole('option').find((o) => spellingOf(o) === spelling);
if (!option) throw new Error(`no option offers ${spelling}`);
return option;
}

/** The field holding exactly one row, ready to have its subject read. The
Expand Down Expand Up @@ -348,14 +369,14 @@ describe('#6226 the flow entry field offers the FLATTENED trigger vocabulary', (
const { container, onCommit } = mountOneRow();
const opts = await subjectOptions(container);
expect(opts).toContain('amount');
await userEvent.click(screen.getByRole('option', { name: 'amount' }));
await userEvent.click(optionBySpelling('amount'));
expect(onCommit).toHaveBeenCalledWith("amount == 'x'");
});

it('authors the create-path idiom `previous == null` end to end', async () => {
const { container, onCommit } = mountOneRow();
await userEvent.click(container.querySelectorAll('[role="combobox"]')[0] as HTMLElement);
await userEvent.click(screen.getByRole('option', { name: 'previous' }));
await userEvent.click(optionBySpelling('previous'));
const valueBox = container.querySelector('input') as HTMLInputElement;
fireEvent.change(valueBox, { target: { value: 'null' } });
expect(onCommit).toHaveBeenLastCalledWith('previous == null');
Expand All @@ -372,6 +393,42 @@ describe('#6226 the flow entry field offers the FLATTENED trigger vocabulary', (

/* ── the escape hatch ────────────────────────────────────────────────────── */

/**
* objectstack#33864 — the subject list names a field by its label, its CEL
* spelling beside it as secondary text (`ux-conventions.labels-over-machine-names`).
*/
describe('objectstack#33864 the flow entry field names each subject by its field label', () => {
/** Open the dropdown; each option as [its main text, its secondary spelling or null]. */
async function labelledOptions(container: HTMLElement): Promise<Array<[string, string | null]>> {
await userEvent.click(container.querySelectorAll('[role="combobox"]')[0] as HTMLElement);
const opts = await screen.findAllByRole('option');
return opts.map((o) => {
const hint = o.querySelector('.font-mono')?.textContent ?? null;
const text = o.textContent ?? '';
return [hint === null ? text : text.slice(0, text.length - hint.length), hint];
});
}

it('a field reads by its label, with its spelling as the hint', async () => {
const opts = await labelledOptions(mountOneRow().container);
expect(opts).toContainEqual(['Status', 'status']);
expect(opts).toContainEqual(['Contract term (months)', 'contract_term_months']);
});

it("a `previous.FIELD` reads by the field's label, before the change", async () => {
const opts = await labelledOptions(mountOneRow().container);
expect(opts).toContainEqual([
tFormat('engine.inspector.condition.previousField', 'en', { field: 'Status' }),
'previous.status',
]);
});

it('CONTROL: the whole-record `previous` has no label, so it reads as its spelling', async () => {
const opts = await labelledOptions(mountOneRow().container);
expect(opts).toContainEqual(['previous', null]);
});
});

describe('#6226 raw CEL remains reachable — the ruling\'s escape hatch', () => {
it('a row-mode field can be switched to the raw expression editor', async () => {
const container = mountField({ value: 'status == "done"' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ export function FlowNodeConfigField({ field, value, onCommit, disabled, locale,
// objectui#11789 — one verdict: the scope note this field renders
// below replaces the raw editor's "Valid CEL", never sits under it.
scopeIssue={unknownRefs.length > 0}
// A subject reads by its field label, its CEL spelling beside it
// (`ux-conventions.labels-over-machine-names`).
labelSubjects
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
// The source under test reaches a dynamic `import('@objectstack/lint')`; pay
// that load during collection, never inside a case's clocked window.
import '@objectstack/lint';

// The engine config-schema hook is stubbed empty so the inspector uses its
// hardcoded field groups (fieldsForNodeType); the trigger field catalog is
Expand Down Expand Up @@ -120,7 +123,11 @@ describe('#6226 the flow inspector hands the entry condition its trigger vocabul
.parentElement!;
const subject = row.querySelector('[role="combobox"]') as HTMLElement;
await userEvent.click(subject);
const opts = (await screen.findAllByRole('option')).map((o) => o.textContent ?? '');
// A field subject reads by its label with its spelling beside it
// (objectstack#33864): read the spelling, the hint where there is one.
const opts = (await screen.findAllByRole('option')).map(
(o) => (o.querySelector('.font-mono') ?? o).textContent ?? '',
);
expect(opts).toContain('status');
expect(opts).toContain('previous.status');
// One subject per value: the bare spelling, never `record.FIELD` beside it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ vi.mock('../useMetadata', async (importOriginal) => ({
useMetadataClient: () => h.client,
}));

// The source under test reaches a dynamic `import('@objectstack/lint')`; pay
// that load during collection, never inside a case's clocked window.
import '@objectstack/lint';
import { useObjectFields } from './useObjectFields';
import { t, useMetadataLocale } from '../i18n';
import { FlowNodeConfigField } from '../inspectors/FlowNodeConfigField';
Expand Down Expand Up @@ -190,8 +193,18 @@ function startNodeScope(objectName: string): TriggerScope | undefined {
return resolveFlowScope(draft, 'start').trigger;
}

/** Open the entry condition's SUBJECT dropdown and read every subject it offers. */
async function entrySubjects(objectName: string, expectField: string): Promise<string[]> {
/**
* The CEL spelling an option offers. The entry-condition builder names a field
* subject by its label with its spelling beside it (`labelSubjects`,
* objectstack#33864); a subject with no label (`previous`) is its spelling.
*/
function spellingOf(option: HTMLElement): string {
const hint = option.querySelector('.font-mono');
return (hint ?? option).textContent ?? '';
}

/** Open the entry condition's SUBJECT dropdown and read the spelling of every subject it offers. */
async function entrySubjects(objectName: string, expectOption: string): Promise<string[]> {
const { container } = render(
<FlowNodeConfigField
field={ENTRY_CONDITION}
Expand All @@ -203,22 +216,22 @@ async function entrySubjects(objectName: string, expectField: string): Promise<s
const trigger = container.querySelectorAll('[role="combobox"]')[0] as HTMLElement;
await userEvent.click(trigger);
// Waits for the catalog: the options follow the field read when it lands.
await screen.findByRole('option', { name: expectField });
return screen.getAllByRole('option').map((o) => o.textContent ?? '');
await screen.findByRole('option', { name: expectOption });
return screen.getAllByRole('option').map(spellingOf);
}

describe('the flow entry-condition builder offers a draft-only object\'s fields (objectui#11895)', () => {
it('offers the draft object\'s fields, not only `previous`', async () => {
installServer(WORLD);
const opts = await entrySubjects('repair_ticket', 'issue_summary');
const opts = await entrySubjects('repair_ticket', 'Issue summary issue_summary');
expect(opts).toContain('issue_summary');
expect(opts).toContain('severity');
expect(opts).toContain('previous.issue_summary');
});

it('CONTROL — a published object\'s fields are offered as before', async () => {
installServer(WORLD);
const opts = await entrySubjects('account', 'industry');
const opts = await entrySubjects('account', 'Industry industry');
expect(opts).toContain('name');
expect(opts).toContain('industry');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import React from 'react';

vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));

import { t } from '../metadata-admin/i18n';
import { MetadataCtx, type MetadataContextValue } from '@object-ui/react';
import { t, tFormat } from '../metadata-admin/i18n';
import { PackageOwdOverviewPanel } from './PackageOwdOverviewPanel';

const en = (key: string) => t(key, 'en-US');
Expand Down Expand Up @@ -156,7 +157,56 @@ describe('PackageOwdOverviewPanel — controlled_by_parent', () => {
renderPanel(freshServer());
await screen.findByTestId('owd-row-crm_case');
const master = screen.getByTestId('owd-master-crm_case');
expect(master.textContent).toMatch(/crm_account/);
// objectstack#33864 — the master is named by its label, not its name.
expect(master.textContent).toBe(tFormat('engine.studio.owd.byParent', 'en-US', { master: 'Account' }));
});
});

/**
* objectstack#33864 — "By parent → …" names the master object by its label
* (`ux-conventions.labels-over-machine-names`): this package's own object as
* the table reads it, else the served object's label, else the machine name.
*/
describe('PackageOwdOverviewPanel — the master is named by its label (objectstack#33864)', () => {
function servedObjects(objects: unknown[]): MetadataContextValue {
return {
apps: [],
objects,
dashboards: [],
reports: [],
pages: [],
loading: false,
error: null,
refresh: async () => {},
invalidate: () => {},
ensureType: async () => [],
getItem: async () => null,
getItemsByType: () => [],
getTypeStatus: () => 'ready',
};
}
const byParent = (master: string) => tFormat('engine.studio.owd.byParent', 'en-US', { master });

/** A package that holds only the detail: its master lives in another package. */
function detailOnly(): Server {
const server = freshServer();
delete server.objects.crm_account;
return server;
}

// This package's own master is pinned by 'shows the master link' above.
it("a master outside this package reads as the served object's label", async () => {
render(
<MetadataCtx.Provider value={servedObjects([{ name: 'crm_account', label: 'Customer Account' }])}>
<PackageOwdOverviewPanel client={makeClient(detailOnly())} packageId="com.example.showcase" locale="en-US" />
</MetadataCtx.Provider>,
);
expect(await screen.findByTestId('owd-master-crm_case')).toHaveTextContent(byParent('Customer Account'));
});

it('CONTROL: a master no read can label is named by its machine name', async () => {
renderPanel(detailOnly());
expect(await screen.findByTestId('owd-master-crm_case')).toHaveTextContent(byParent('crm_account'));
});
});

Expand Down
Loading
Loading