Skip to content

Commit cfb690a

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/area-E1-33949-ceiling
2 parents c5b21e4 + 27c2f1e commit cfb690a

9 files changed

Lines changed: 244 additions & 13 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
fix(components): record page header-action predicates wait for the record instead of reporting "No such key" for fields the object has
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
A record page binds its record id at once and its row only when the read answers. Until then the `page:header` actions evaluated their `visible`, `hidden`, `disabled` and `pressed` predicates against an empty record, so every `record.<field>` predicate faulted, and the console said "A conditional predicate failed to evaluate … No such key: status … Check the field names and CEL" once per action on every page load, for a field the object has. Nothing was wrong with the metadata.
12+
13+
A record that is bound but not loaded is now its own state. Each predicate answers its key's safe default (hidden, not hidden, disabled, not pressed) and reports nothing; a `disabled` action does not claim it is "not available for this record" while there is no record yet. Once the record arrives the predicates run as before, and the warning still fires when a key is really missing from the loaded record. A header with no record bound at all evaluates as before.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
fix(console): a list page with no declared primary action keeps its header actions as buttons, whatever the length of the object's description
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
On a list page the header folds its actions when they do not fit beside the title and the object's description: the primary action stays a labelled button and the others move into the `⋯` menu. The primary is declared: the page's New, else the list-toolbar action authored `variant: 'primary'`. A list with neither had nothing to keep labelled, so the folded header was the `⋯` alone, and a long description by itself moved the page's one action (for example a reader without create rights and a single `Launch Contract` toolbar action) into the menu at desktop width. Such a list is now offered no folded header: its actions stay buttons at every width and the description is truncated instead. The `/data` page follows the same rule: with no New to keep, Save as view stays a button. A list that declares a primary folds exactly as before. To keep a toolbar action labelled on a narrow header as well, author it `variant: 'primary'`.

‎ui/packages/app-shell/src/layout/PageHeader.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export interface ConsolePageHeaderProps {
135135
* The header measures its own width, not the viewport's. The page declares
136136
* which action is primary by being the one that names it here; the header
137137
* never guesses it from `actions`. A page that passes no `foldedActions`
138-
* keeps `actions` at every width.
138+
* keeps `actions` at every width, and a page with no primary to keep
139+
* labelled passes none (objectstack#33988): a face of only the `⋯` would
140+
* trade the page's actions for its description.
139141
*/
140142
foldedActions?: React.ReactNode;
141143
/**

‎ui/packages/app-shell/src/views/ObjectDataPage.createAffordances.test.tsx‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ import { MemoryRouter, Routes, Route } from 'react-router-dom';
6161
let principal: Record<string, boolean> = {};
6262
/** Controllable server-resolved effective API operations (#3391); `undefined` = unrestricted. */
6363
let apiOperations: string[] | undefined;
64+
/** Whether the reader is a workspace admin (draws "Save as view"); off by default. */
65+
let workspaceAdmin = false;
6466

6567
vi.mock('@object-ui/permissions', async (importOriginal) => {
6668
const actual = await importOriginal<typeof import('@object-ui/permissions')>();
@@ -85,7 +87,7 @@ vi.mock('@object-ui/permissions', async (importOriginal) => {
8587
vi.mock('@object-ui/auth', async (importOriginal) => ({
8688
...(await importOriginal<Record<string, unknown>>()),
8789
useAuth: () => ({ user: { id: 'u1', name: 'Ada' }, activeOrganization: null }),
88-
useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }),
90+
useWorkspaceAdminStatus: () => ({ isAdmin: workspaceAdmin, isResolved: true }),
8991
createAuthenticatedFetch: () => vi.fn(),
9092
}));
9193

@@ -182,6 +184,7 @@ function expectCreateEntry(expected: { rendered: boolean; disabled?: boolean })
182184
beforeEach(() => {
183185
principal = {};
184186
apiOperations = undefined;
187+
workspaceAdmin = false;
185188
cleanup();
186189
vi.stubGlobal(
187190
'fetch',
@@ -373,3 +376,31 @@ describe('#5164 — /data and the object-list page agree on one declaration', ()
373376
expect(newButton()).toBeTruthy();
374377
});
375378
});
379+
380+
/**
381+
* objectstack#33988 — the header's folded face (objectui#12705) keeps New
382+
* labelled and puts Save as view in a `⋯`. With no New there is nothing to keep
383+
* labelled, so the page offers no folded face: a long description must never
384+
* send the page's one action into the `⋯`. The header marks a page that offers
385+
* the fold with `data-folded`; one that does not keeps `actions` at every
386+
* width, so the attribute is absent.
387+
*/
388+
describe('objectstack#33988 — /data offers the fold only with a New to keep labelled', () => {
389+
const cluster = () => document.querySelector('[data-testid="page-header-actions"]') as HTMLElement | null;
390+
391+
it('an admin who cannot create keeps "Save as view" as a button: no folded face is offered', () => {
392+
workspaceAdmin = true;
393+
principal = { create: false };
394+
renderDataPage(objects());
395+
expect(newButton()).toBeNull();
396+
expect(cluster()?.querySelector('[data-testid="object-data-save-as-view"]')).toBeTruthy();
397+
expect(cluster()?.hasAttribute('data-folded')).toBe(false);
398+
});
399+
400+
it('CONTROL: with New drawn, the folded face is still offered', () => {
401+
workspaceAdmin = true;
402+
renderDataPage(objects());
403+
expect(newButton()).toBeTruthy();
404+
expect(cluster()?.getAttribute('data-folded')).toBe('false');
405+
});
406+
});

‎ui/packages/app-shell/src/views/ObjectDataPage.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,11 @@ export function ObjectDataPage({ dataSource, objects }: any) {
629629
</>
630630
}
631631
// objectui#12705 — too narrow for both actions and the description:
632-
// New stays labelled and Save as view goes into a `⋯`.
632+
// New stays labelled and Save as view goes into a `⋯`. With no New
633+
// to keep labelled there is no folded face (objectstack#33988): it
634+
// would send the page's one action into the `⋯` for the description.
633635
foldedActions={
634-
<>
636+
newButton && <>
635637
{newButton}
636638
{isAdmin && (
637639
<DropdownMenu>

‎ui/packages/app-shell/src/views/ObjectView.headerFold-12705.test.tsx‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ vi.mock('@object-ui/plugin-grid', async (importOriginal) => ({
9999
ImportWizard: ({ open }: { open: boolean }) => (open ? <div data-testid="import-wizard" /> : null),
100100
}));
101101

102+
// `ObjectView` reaches a dynamic `import('@objectstack/lint')`: pay its load at
103+
// collection, never inside a case's clocked window (`check:test-source-alias`).
104+
import '@objectstack/lint';
102105
import { ObjectView, declaredPrimaryToolbarAction } from './ObjectView';
103106
import { ExpressionProvider } from '../providers/ExpressionProvider';
104107

@@ -282,6 +285,47 @@ describe('the object list’s header folds its actions (objectui#12705)', () =>
282285
});
283286
});
284287

288+
/**
289+
* objectstack#33988 — a list that declares no primary (no New, no toolbar
290+
* action authored `variant: 'primary'`) is offered no folded face: that face
291+
* would keep no labelled action, so a long description alone sent the page's
292+
* one action into the `⋯` at desktop width (hotclm's 「Launch Contract」). The
293+
* header keeps `actions` at every width and the description truncates instead.
294+
*/
295+
describe('a list with no declared primary keeps its actions labelled (objectstack#33988)', () => {
296+
const LAUNCH = { name: 'launch_contract', label: 'Launch Contract', type: 'script', locations: ['list_toolbar'] };
297+
/** The card's object: no New for the reader, one undeclared toolbar action, its English description. */
298+
const CONTRACTS = {
299+
name: 'demo_contract',
300+
label: 'Contract',
301+
pluralLabel: 'Contracts',
302+
description:
303+
'A contract from intake to archive: parties, commercial and legal terms, lifecycle status and the stamps each stage leaves.',
304+
fields: { id: { type: 'text', label: 'Id' }, name: { type: 'text', label: 'Name' } },
305+
actions: [LAUNCH],
306+
};
307+
308+
// A 1366 px laptop and a 1440 px desktop, each less the 256 px sidebar, and
309+
// a tablet-wide header between the phone header and the desktop.
310+
it.each([1110, 1184, 700])('at a %i px header the action stays a button and the header does not fold', (width) => {
311+
headerWidth = width;
312+
principal = { create: false };
313+
const { cluster, labelled, openMenu } = renderList(CONTRACTS);
314+
expect(labelled()).toEqual(['Launch Contract']);
315+
expect(openMenu()).toEqual(['Add to favorites']);
316+
expect(cluster.hasAttribute('data-folded')).toBe(false);
317+
});
318+
319+
it('CONTROL: authored `variant: primary`, the same list still folds at a 600 px header, keeping it labelled', () => {
320+
headerWidth = 600;
321+
principal = { create: false };
322+
const { cluster, labelled, openMenu } = renderList({ ...CONTRACTS, actions: [{ ...LAUNCH, variant: 'primary' }] });
323+
expect(cluster.getAttribute('data-folded')).toBe('true');
324+
expect(labelled()).toEqual(['Launch Contract']);
325+
expect(openMenu()).toEqual(['Add to favorites']);
326+
});
327+
});
328+
285329
describe('declaredPrimaryToolbarAction (objectui#12705)', () => {
286330
it('is the `variant: primary` list-toolbar action with the lowest order, never the first by position', () => {
287331
const late = { ...INVITE, name: 'late', order: 5 };

‎ui/packages/app-shell/src/views/objectViewHeaderChrome.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export function useObjectViewHeaderChrome({
9797
// it before the header can fold, so no action in the folded face carries
9898
// `autoTrigger`. Not offered on the environment list, whose toolbar is
9999
// `EnvironmentListToolbar`, not this bar.
100+
//
101+
// objectstack#33988 — not offered either when the list declares no
102+
// primary (no New, no toolbar action authored `variant: 'primary'`): that
103+
// face would keep no labelled action, so a long description alone would
104+
// send the page's one action into the `⋯`. Without a folded face the
105+
// header keeps `actions` at every width and the description truncates.
100106
const toolbarRowActions: UIActionSchema[] = listActions?.some((a: { locations?: readonly string[] }) => a.locations?.includes('list_toolbar'))
101107
? toolbarActionsWithDeepLink
102108
: [];
@@ -133,7 +139,7 @@ export function useObjectViewHeaderChrome({
133139
maxVisible: 0,
134140
mobileMaxVisible: 0,
135141
};
136-
const foldedHeaderActions = !isEnvironmentList ? (
142+
const foldedHeaderActions = !isEnvironmentList && (showCreate || primaryToolbarAction) ? (
137143
<>
138144
{createButton}
139145
{/* One inline slot at every width: `toolbarBar` keeps none below

‎ui/packages/components/src/__tests__/page-header-predicate-dialect.test.tsx‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,103 @@ describe('page:header — fail-closed stays fail-closed, and says so once (#3521
361361
}
362362
});
363363
});
364+
365+
describe('page:header — a record still loading is its own state, not an empty record (objectstack#33987)', () => {
366+
// The record page binds its record id at once and hands `data: null` until
367+
// the read answers. Evaluating then meant evaluating against an empty
368+
// record: every `record.<field>` predicate faulted with "No such key", and
369+
// the warn-once report told the author to check the field names of a field
370+
// the object HAS — on every load, before the record arrived.
371+
const faultsFor = (warn: ReturnType<typeof vi.spyOn>, name: string) =>
372+
warn.mock.calls.filter(
373+
(c: unknown[]) => String(c[0]).includes('failed to evaluate') && String(c[0]).includes(`"${name}"`),
374+
);
375+
376+
function headerTree(action: Record<string, unknown>, recordId: string | null, data: any) {
377+
return (
378+
<PredicateScopeProvider scope={SCOPE}>
379+
<ActionProvider>
380+
<RecordContextProvider
381+
objectName="showcase_field_zoo"
382+
recordId={recordId}
383+
data={data}
384+
objectSchema={OBJECT_SCHEMA}
385+
>
386+
<PageHeader
387+
schema={{
388+
type: 'page:header',
389+
title: 'Specimen',
390+
actions: [{ locations: ['record_header'], label: 'Zoo Action', type: 'api', ...action }],
391+
}}
392+
/>
393+
</RecordContextProvider>
394+
</ActionProvider>
395+
</PredicateScopeProvider>
396+
);
397+
}
398+
399+
let warn: ReturnType<typeof vi.spyOn>;
400+
beforeEach(() => {
401+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
402+
return () => warn.mockRestore();
403+
});
404+
405+
it('pending: no fault report; once the record arrives the predicate is honoured, still with no report', () => {
406+
const action = { name: 'zoo_pending_visible_33987', visible: 'record.f_status == "open"' };
407+
const { rerender } = render(headerTree(action, 'r1', null));
408+
// Pending answers the key's own fallback (hidden), and says nothing.
409+
expect(shown()).toBe(false);
410+
expect(faultsFor(warn, 'zoo_pending_visible_33987')).toHaveLength(0);
411+
412+
rerender(headerTree(action, 'r1', RECORD));
413+
expect(shown()).toBe(true);
414+
expect(faultsFor(warn, 'zoo_pending_visible_33987')).toHaveLength(0);
415+
});
416+
417+
it('the loaded verdict is the predicate’s own in the negative direction too', () => {
418+
const action = { name: 'zoo_pending_negative_33987', visible: 'record.f_status == "open"' };
419+
const { rerender } = render(headerTree(action, 'r1', undefined));
420+
rerender(headerTree(action, 'r1', { ...RECORD, f_status: 'closed' }));
421+
expect(shown()).toBe(false);
422+
expect(faultsFor(warn, 'zoo_pending_negative_33987')).toHaveLength(0);
423+
});
424+
425+
it('pending: `hidden`, `disabled` and `pressed` report nothing either, and `disabled` claims no reason about the record', () => {
426+
const action = {
427+
name: 'zoo_pending_legs_33987',
428+
hidden: 'record.f_status == "closed"',
429+
disabled: 'record.f_status == "closed"',
430+
pressed: 'record.f_status == "open"',
431+
};
432+
const { rerender } = render(headerTree(action, 'r1', null));
433+
// Each leg answers its own fallback: rendered, disabled, not pressed.
434+
expect(shown()).toBe(true);
435+
expect(button()).toBeDisabled();
436+
expect(button()).toHaveAttribute('aria-pressed', 'false');
437+
expect(button()).not.toHaveAttribute('aria-describedby');
438+
expect(faultsFor(warn, 'zoo_pending_legs_33987')).toHaveLength(0);
439+
440+
rerender(headerTree(action, 'r1', RECORD));
441+
expect(shown()).toBe(true);
442+
expect(button()).not.toBeDisabled();
443+
expect(button()).toHaveAttribute('aria-pressed', 'true');
444+
expect(faultsFor(warn, 'zoo_pending_legs_33987')).toHaveLength(0);
445+
});
446+
447+
it('CONTROL: a LOADED record really missing the key still faults, fails closed and says so once', () => {
448+
const { f_status: _omitted, ...withoutStatus } = RECORD;
449+
const action = { name: 'zoo_loaded_missing_33987', visible: 'record.f_status == "open"' };
450+
render(headerTree(action, 'r1', withoutStatus));
451+
expect(shown()).toBe(false);
452+
const faults = faultsFor(warn, 'zoo_loaded_missing_33987');
453+
expect(faults).toHaveLength(1);
454+
expect(String(faults[0][0])).toContain('f_status');
455+
});
456+
457+
it('CONTROL: a header with no record bound (no id) still evaluates, so a `record.*` predicate there faults and says so', () => {
458+
const action = { name: 'zoo_unbound_33987', visible: 'record.f_status == "open"' };
459+
render(headerTree(action, null, undefined));
460+
expect(shown()).toBe(false);
461+
expect(faultsFor(warn, 'zoo_unbound_33987')).toHaveLength(1);
462+
});
463+
});

‎ui/packages/components/src/renderers/layout/containers.tsx‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,15 @@ export const PageHeaderActions: React.FC<PageHeaderActionsProps> = ({
20532053
// `warnOnError: true`), so a broken predicate hides its button here exactly
20542054
// as it does on the other surfaces, and says so once.
20552055
const headerPredicateFields = headerObjectSchema?.fields;
2056+
// The record this header is ABOUT has not arrived yet: a record is bound (the
2057+
// host named its id) and its row is still absent — `RecordContextValue.data`
2058+
// is "undefined while loading", and the record page hands `null` until its
2059+
// read answers. That is its own state, not an empty record: an empty record
2060+
// makes every `record.<field>` predicate fault, which is an authoring error
2061+
// only when the key is missing from a record that DID load. A header with no
2062+
// record bound at all (no context, or no id) keeps evaluating as before, so a
2063+
// `record.*` predicate there still faults and says so.
2064+
const headerRecordPending = ctx != null && ctx.recordId != null && ctx.data == null;
20562065
const headerPredicateScope = React.useMemo(() => {
20572066
const scopeUser = (predicateScope as any)?.user;
20582067
// Relation fields bind as the FOREIGN KEY the server stores, not as the
@@ -2104,17 +2113,27 @@ export const PageHeaderActions: React.FC<PageHeaderActionsProps> = ({
21042113
* share `visible`'s `false`, which on this key means ENABLED — so
21052114
* `disabled: !current_user.can(…)` left the action pressable until the
21062115
* payload arrived, the one leg of this surface that failed open.
2116+
*
2117+
* While the record is PENDING (see `headerRecordPending`) nothing is
2118+
* evaluated: every predicate answers its `fallback` and reports nothing.
2119+
* Evaluating then meant evaluating against an empty record, where every
2120+
* `record.<field>` faults with "No such key" — and the fault report, which
2121+
* is warn-once per (label, predicate), told the author to "check the field
2122+
* names" of a field the object has, on every load, before the record it
2123+
* names had arrived. The predicate runs, and reports, once the record does.
21072124
*/
21082125
const evalHeaderPredicate = React.useCallback(
21092126
(pred: unknown, label: string, fallback: boolean): boolean =>
2110-
evalRowPredicate(pred as never, ctx?.data ?? {}, {
2111-
fallback,
2112-
scope: headerPredicateScope,
2113-
fields: headerPredicateFields,
2114-
warnOnError: true,
2115-
label,
2116-
}),
2117-
[ctx?.data, headerPredicateScope, headerPredicateFields],
2127+
headerRecordPending
2128+
? fallback
2129+
: evalRowPredicate(pred as never, ctx?.data ?? {}, {
2130+
fallback,
2131+
scope: headerPredicateScope,
2132+
fields: headerPredicateFields,
2133+
warnOnError: true,
2134+
label,
2135+
}),
2136+
[ctx?.data, headerRecordPending, headerPredicateScope, headerPredicateFields],
21182137
);
21192138

21202139
const headerActionPlan = React.useMemo<{ actions: any[]; authoredKeys: ReadonlySet<string> }>(() => {
@@ -2557,6 +2576,9 @@ export const PageHeaderActions: React.FC<PageHeaderActionsProps> = ({
25572576
const disabledReasonFor = (action: any): string | undefined => {
25582577
const key = (action?.name || action?.id || '') as string;
25592578
if (key === '' || !authoredHeaderActionKeys.has(key)) return undefined;
2579+
// A pending record answers `disabled`'s fallback (closed), which is not
2580+
// a fact about the record — so it is not explained as one.
2581+
if (headerRecordPending) return undefined;
25602582
if (!resolveDisabled(action?.disabled, action?.name ?? action?.id)) return undefined;
25612583
const declared = typeof action?.disabledReason === 'string' ? action.disabledReason : '';
25622584
return declared.trim() !== ''

0 commit comments

Comments
 (0)