diff --git a/.changeset/39003-app-shell-studio-leftovers.md b/.changeset/39003-app-shell-studio-leftovers.md new file mode 100644 index 00000000000..ea3d7092154 --- /dev/null +++ b/.changeset/39003-app-shell-studio-leftovers.md @@ -0,0 +1,17 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/layout': patch +'@object-ui/i18n': patch +'@objectstack/spec': patch +--- + +fix(console): clean up the Studio view editor's form-view leftovers, the retired package-less scope's references, and the sidebar's icon and colour resolvers + +Clause-②: no +Metadata-protocol: none + +- The Studio view editor and the runtime view-config panel edit list views only, as a `view` holds since protocol 19 (ADR-0159 D7). The view inspector's form branch (the form-layout type picker, the form-variant schema and the required-field-in-a-gated-section Save gate, which only a form held in a view could reach) is removed, with `toInlineFormType` and the unused studio string `engine.viewPreview.formFailed` and the `engine.inspector.view.gatedRequired.*` strings. A form is edited as a `form` item. +- A record create or edit's chrome (`resolveRecordFormChrome`) no longer goes through the named-form-view reader that nothing called with a form; it gives the host's own buttons, labels and layout as before. +- The metadata list drops the `emptyListHint` host member that nothing set since the package-less Studio scope retired; two changes-panel comments that described that scope now say who narrows the list today. +- The sidebar's icon and colour resolvers (`useNavTargetIcon`, `useNavTargetColor`) answer as of the render that made them, as the label resolver does: an object's tile drawn before its read lands takes the object's colour once it lands, instead of staying gray. `NavTargetLabelResolver`, `NavTargetIconResolver` and `NavTargetColorResolver` (`@object-ui/layout`) now state that a resolver's answers are fixed for its identity and that it may keep them for its own lifetime only. +- `@objectstack/spec`: the protocol-19 semantic entry `internal-record-forms-not-loaded` no longer names the lint rule retired in that protocol in its acceptance text, and the `form` liveness note for `buttons` names the console form page's `readFormButton` as the reader, no longer the removed named-form chrome reader. diff --git a/docs/adr/0113-required-write-contract-vs-column-constraint.md b/docs/adr/0113-required-write-contract-vs-column-constraint.md index ecd005af678..791aaf12be9 100644 --- a/docs/adr/0113-required-write-contract-vs-column-constraint.md +++ b/docs/adr/0113-required-write-contract-vs-column-constraint.md @@ -407,7 +407,8 @@ older `required` field; for those fields this amendment changes nothing on creat **Not in scope.** Only the object field's own `visibleWhen`. A field group's `visibleWhen`, a form view's field or section predicate, a hidden tab and static `hidden` are not read: the validator does not consume view metadata (ruled on -#13252; Studio's gated-section fence covers the section case at authoring). +#13252; Studio fences no section case at authoring, so a required field in a gated +section is answered by this contract at the record save). **Which server answer is canonical.** Three server sites answer "required, but hidden". For the **record write contract** this rule is canonical; it is the diff --git a/docs/adr/0159-forms-are-their-own-metadata-type-public-forms-are-form-items-view-is-lists-only.md b/docs/adr/0159-forms-are-their-own-metadata-type-public-forms-are-form-items-view-is-lists-only.md index 2c48e42dc89..1444cb4cddb 100644 --- a/docs/adr/0159-forms-are-their-own-metadata-type-public-forms-are-form-items-view-is-lists-only.md +++ b/docs/adr/0159-forms-are-their-own-metadata-type-public-forms-are-form-items-view-is-lists-only.md @@ -80,7 +80,7 @@ So a form reaches the platform in **three shapes**: the container's `form`, a `f ### No record form reads a form view -Since #36425 the console's create dialog, full-page create, action-opened create and edit lay out by the object's `fieldGroups` and the rules on its fields. The docblock of `ui/packages/app-shell/src/utils/recordFormNavigation.ts#FormViewDefinition` says it in these words: "No record create or edit reads one". `addRecord.formView` is a tombstone in `packages/spec/src/ui/view.zod.ts`. The lint rule `form-view-internal-not-loaded` (`packages/lint/src/validate-internal-form-views.ts`) reports an internal create or edit form as steering nothing. No per-role or per-position form assignment exists. +Since #36425 the console's create dialog, full-page create, action-opened create and edit lay out by the object's `fieldGroups` and the rules on its fields. The docblock of `ui/packages/app-shell/src/utils/recordFormNavigation.ts#RecordFormModalLayout` says it in these words: "An internal form view steers nothing". `addRecord.formView` is a tombstone in `packages/spec/src/ui/view.zod.ts`. The lint rule `form-view-internal-not-loaded` (`packages/lint/src/validate-internal-form-views.ts`) reports an internal create or edit form as steering nothing. No per-role or per-position form assignment exists. ### Named forms have three consumers diff --git a/packages/spec/liveness/form.json b/packages/spec/liveness/form.json index 1fd92e16d3c..f0793415cee 100644 --- a/packages/spec/liveness/form.json +++ b/packages/spec/liveness/form.json @@ -127,7 +127,7 @@ }, "buttons": { "status": "live", - "note": "Inherited verdict (2026-11-26, ADR-0159 card ②): a `form` item's body keys ARE `FormViewSchema`'s shape, taken by reference (packages/spec/src/ui/view.zod.ts#FormSchema), and the anonymous doors serve the item's body to the public form renderer an old-shape form reached until protocol 19 (packages/rest/src/form-routes.ts#resolveFormBySlug), so this row was seeded with view.json `form.`'s verdict; that row left view.json with the container's tombstone (2026-12-01, ADR-0159 D7), and this row is the one classification of the key. Until card ③ (#37087) the console opens no `form` item from an action; re-verify this row with that card. objectui: ObjectForm.tsx foldFormButtons() reads schema.buttons and folds submit/cancel {show,label} onto the flat showSubmit/submitText/showCancel/cancelText props (framework#1894 / #2998); ObjectView forwards it, and every console form entry point resolves submit/cancel through resolveFormViewChrome / readFormButton (#26843). Flat keys kept as deprecated back-compat (explicit flat key wins). SUB-KEY buttons.reset REMOVED 2026-10-28 (#27153, ADR-0049 enforce-or-remove, ruled retire): measured at origin/main fbe344b3, six button bars (components form.tsx, console FormPage, ModalForm, DrawerForm, WizardForm, MasterDetailForm) drew submit/cancel and none drew reset; reset.label had no reader; the one fold of reset.show landed on ObjectForm showReset, which means clear-after-save (resetOnSubmit), not a button. Tombstoned inside the buttons block (retiredKey carries the prescription) and stripped from stored rows and sources by the protocol-18 form-view-buttons-reset-removed conversion; the fold was removed in the same change. Sub-keys cannot be drilled (one level only), so the removal is recorded here; submit and cancel keep this row live." + "note": "Inherited verdict (2026-11-26, ADR-0159 card ②): a `form` item's body keys ARE `FormViewSchema`'s shape, taken by reference (packages/spec/src/ui/view.zod.ts#FormSchema), and the anonymous doors serve the item's body to the public form renderer an old-shape form reached until protocol 19 (packages/rest/src/form-routes.ts#resolveFormBySlug), so this row was seeded with view.json `form.`'s verdict; that row left view.json with the container's tombstone (2026-12-01, ADR-0159 D7), and this row is the one classification of the key. Until card ③ (#37087) the console opens no `form` item from an action; re-verify this row with that card. objectui: ObjectForm.tsx foldFormButtons() reads schema.buttons and folds submit/cancel {show,label} onto the flat showSubmit/submitText/showCancel/cancelText props (framework#1894 / #2998); ObjectView forwards it, and the console form page that opens a named form (FormPage) resolves submit/cancel through readFormButton (#26843). Flat keys kept as deprecated back-compat (explicit flat key wins). SUB-KEY buttons.reset REMOVED 2026-10-28 (#27153, ADR-0049 enforce-or-remove, ruled retire): measured at origin/main fbe344b3, six button bars (components form.tsx, console FormPage, ModalForm, DrawerForm, WizardForm, MasterDetailForm) drew submit/cancel and none drew reset; reset.label had no reader; the one fold of reset.show landed on ObjectForm showReset, which means clear-after-save (resetOnSubmit), not a button. Tombstoned inside the buttons block (retiredKey carries the prescription) and stripped from stored rows and sources by the protocol-18 form-view-buttons-reset-removed conversion; the fold was removed in the same change. Sub-keys cannot be drilled (one level only), so the removal is recorded here; submit and cancel keep this row live." }, "defaults": { "status": "live", diff --git a/packages/spec/src/migrations/entries/semantic/19.internal-record-forms-not-loaded.ts b/packages/spec/src/migrations/entries/semantic/19.internal-record-forms-not-loaded.ts index 206498aa48e..9229553689f 100644 --- a/packages/spec/src/migrations/entries/semantic/19.internal-record-forms-not-loaded.ts +++ b/packages/spec/src/migrations/entries/semantic/19.internal-record-forms-not-loaded.ts @@ -5,7 +5,7 @@ import type { SemanticMigration } from '../../types.js'; // objectstack-ai/objectstack#36425 — the Console's record create and edit // surfaces stop loading an object's internal form view. No key is retired and // no stored row is rewritten: an internal form still parses and installs, and -// steers nothing. The lint rule `form-view-internal-not-loaded` names each one. +// steers nothing. export const entry: SemanticMigration = { id: 'internal-record-forms-not-loaded', surface: @@ -24,8 +24,7 @@ export const entry: SemanticMigration = { + '`required` written on a form field entry is no longer asked for. Nothing converts it, because the ' + 'right field groups and field rules are a judgment about the object, not a rewrite of the form.', acceptanceCriteria: - '`os validate` reports no `form-view-internal-not-loaded` warning, or each one is a form you keep on ' - + 'purpose as inert. Opening New and Edit on each object that had an internal form shows the sections, ' - + 'required fields and create defaults you want, from the field groups and the field rules.', + 'Opening New and Edit on each object that had an internal form shows the sections, required fields and ' + + 'create defaults you want, from the field groups and the field rules.', relevantWhen: { kind: 'stack-declares', keys: ['views', 'viewItems', 'forms'] }, }; diff --git a/ui/packages/app-shell/src/hooks/useNavTargetIcon.answersAsOfItsRender-38859.test.tsx b/ui/packages/app-shell/src/hooks/useNavTargetIcon.answersAsOfItsRender-38859.test.tsx new file mode 100644 index 00000000000..6de86bd9930 --- /dev/null +++ b/ui/packages/app-shell/src/hooks/useNavTargetIcon.answersAsOfItsRender-38859.test.tsx @@ -0,0 +1,172 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#38859 — the icon and colour resolvers answer as of the render + * that made them, as the label resolver does (objectstack#38835). + * + * The sidebar's rows are memoised (`@object-ui/layout`'s `sameRowAnswers`, + * objectstack#37575) and compare the previous resolver with the new one by + * what each answers when the comparison runs. `MetadataProvider`'s object + * scopes are refs, so a resolver that read them live answered the landed + * colour for BOTH resolvers, the row was skipped, and the tile first drawn + * while the object's by-name read was on the wire stayed gray. + * + * The context is hand-rolled the way the provider behaves: one live scope + * store every published value reads (`readObjectScope`), and a NEW value on + * each landing over the same store. + * + * - a tile drawn while the read is on the wire takes the object's colour once + * it lands; + * - one icon or colour resolver answers what it first answered; a new + * resolver answers anew; + * - CONTROL: an object the scope never answers keeps the neutral tile. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { afterEach, describe, expect, it } from 'vitest'; +import { act, cleanup, render, screen } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import '@object-ui/components'; +import { SidebarProvider } from '@object-ui/components'; +import { MetadataCtx } from '@object-ui/react'; +import { NavigationRenderer, type NavTargetColorResolver, type NavTargetIconResolver } from '@object-ui/layout'; +import { useNavTargetColor, useNavTargetIcon } from './useNavTargetIcon'; + +/** Labelled entries, so only the tile depends on the object read. */ +const NAVIGATION = [ + { id: 'nav_ticket', type: 'object', objectName: 'repairs_repair_ticket', label: 'Tickets' }, + { id: 'nav_gone', type: 'object', objectName: 'repairs_never_served', label: 'Never served' }, +]; + +const TICKET = { name: 'repairs_repair_ticket', label: 'Repair Ticket', icon: 'wrench', color: 'orange' }; + +/** The provider's live scope store: the by-name answers landed so far. */ +function liveScope() { + const store = { items: [] as Array> }; + /** One published context value, as `MetadataProvider` builds one per version. */ + const value = () => ({ + apps: [], + get objects() { + return []; + }, + dashboards: [], + reports: [], + pages: [], + loading: false, + error: null, + refresh: async () => {}, + invalidate: () => {}, + ensureType: async () => [], + getItem: async () => null, + getItemsByType: () => [], + // Nothing has loaded the whole registry: the sidebar reads by name. + getTypeStatus: () => 'idle' as const, + readObjectScope: (scope: { names?: readonly string[] }) => { + const objects = store.items.filter((it) => scope.names?.includes(it.name as string)); + return { objects, served: objects, missing: [], settled: true }; + }, + }); + return { store, value }; +} + +/** The sidebar, wired as `UnifiedSidebar` wires the two resolvers. */ +function Sidebar() { + const resolveTargetIcon = useNavTargetIcon(); + const resolveTargetColor = useNavTargetColor(); + return ( + + + + ); +} + +function tree(value: unknown) { + return ( + + + + + + ); +} + +function tileOf(label: string): string | null | undefined { + return screen + .getByText(label) + .closest('[data-sidebar="menu-button"]') + ?.querySelector('[data-object-icon-tile]') + ?.getAttribute('data-object-icon-tile'); +} + +afterEach(() => { + cleanup(); +}); + +describe('objectstack#38859 — a sidebar tile takes its object colour once the read lands', () => { + it('a tile first drawn while the by-name read is on the wire takes the colour after it lands', () => { + const { store, value } = liveScope(); + const utils = render(tree(value())); + // Drawn before the read lands: the neutral gray tile. + expect(tileOf('Tickets')).toBe('gray'); + + // The read lands in the live store, and the provider publishes a new value. + store.items = [TICKET]; + act(() => utils.rerender(tree(value()))); + + expect(tileOf('Tickets')).toBe('orange'); + }); + + it('CONTROL: an object the scope never answers keeps the gray tile', () => { + const { store, value } = liveScope(); + const utils = render(tree(value())); + store.items = [TICKET]; + act(() => utils.rerender(tree(value()))); + expect(tileOf('Never served')).toBe('gray'); + }); +}); + +describe('objectstack#38859 — one icon or colour resolver answers as of the render that made it', () => { + it('each resolver keeps its first answer over the live store; the next resolver answers anew', () => { + const { store, value } = liveScope(); + const icons: NavTargetIconResolver[] = []; + const colors: NavTargetColorResolver[] = []; + function Probe() { + icons.push(useNavTargetIcon()); + colors.push(useNavTargetColor()); + return null; + } + const probe = (v: unknown) => ( + + + + ); + const target = { kind: 'object', objectName: 'repairs_repair_ticket' } as const; + + const utils = render(probe(value())); + const firstIcon = icons[icons.length - 1]; + const firstColor = colors[colors.length - 1]; + expect(firstIcon(target)).toBeUndefined(); + expect(firstColor(target)).toBeUndefined(); + + store.items = [TICKET]; + utils.rerender(probe(value())); + const nextIcon = icons[icons.length - 1]; + const nextColor = colors[colors.length - 1]; + + expect(nextIcon).not.toBe(firstIcon); + expect(nextColor).not.toBe(firstColor); + // What the memoised row compares: the previous resolver answers what it drew. + expect(firstIcon(target)).toBeUndefined(); + expect(firstColor(target)).toBeUndefined(); + expect(nextIcon(target)).toBe('wrench'); + expect(nextColor(target)).toBe('orange'); + }); +}); diff --git a/ui/packages/app-shell/src/hooks/useNavTargetIcon.ts b/ui/packages/app-shell/src/hooks/useNavTargetIcon.ts index 63392df6e12..dc3cf9e4413 100644 --- a/ui/packages/app-shell/src/hooks/useNavTargetIcon.ts +++ b/ui/packages/app-shell/src/hooks/useNavTargetIcon.ts @@ -13,28 +13,40 @@ * * It reads the object by name from the metadata cache the shell already holds * (`readObjectsByName`, the same read `useNavTargetLabel({ byName: true })` - * makes for the entry's text), so the sidebar loads no extra list for it. - * Nothing is stored: a changed object icon shows on the next render. An object - * with no `icon`, or one not loaded yet, answers `undefined` and the row keeps - * the renderer's generic icon. + * makes for the entry's text), so the sidebar loads no extra list for it. An + * object with no `icon`, or one not loaded yet, answers `undefined` and the + * row keeps the renderer's generic icon. + * + * That read is live (the provider's object scopes are refs), and the sidebar's + * memoised rows compare the previous resolver with the new one by what each + * answers when the comparison runs. So, like `useNavTargetLabel` + * (objectstack#38835), each resolver keeps the first answer it gives for an + * object and gives it again: the previous resolver answers what its render + * drew, and a landing, which makes a new resolver, is a change the row sees. + * A changed object icon shows once the metadata changes. The same holds for + * {@link useNavTargetColor}. */ import { useMemo } from 'react'; import type { NavIconTarget, NavTargetColorResolver, NavTargetIconResolver } from '@object-ui/layout'; import { useMetadata } from '../providers/MetadataProvider.js'; import { readObjectsByName } from './useObjectPresence.js'; +import { answeringOnce } from './useNavTargetLabel.js'; + +/** One key per object a resolver is asked about. */ +const objectKey = (target: NavIconTarget): string => `${target.kind}/${target.objectName}`; export function useNavTargetIcon(): NavTargetIconResolver { const metadata = useMetadata(); return useMemo( - () => (target: NavIconTarget) => { + () => answeringOnce(objectKey, (target: NavIconTarget) => { if (target.kind !== 'object') return undefined; const def = readObjectsByName(metadata, [target.objectName]).find( (item): item is { name: string; icon?: unknown } => !!item && typeof item === 'object' && (item as { name?: unknown }).name === target.objectName, ); return typeof def?.icon === 'string' && def.icon.trim() !== '' ? def.icon : undefined; - }, + }), [metadata], ); } @@ -43,19 +55,20 @@ export function useNavTargetIcon(): NavTargetIconResolver { * useNavTargetColor — the same read for the object's palette `color` * (objectstack#35985), as a {@link NavTargetColorResolver}: the colour of the * tile an `object` entry is drawn on. An object with no `color`, or one not - * loaded yet, answers `undefined` and the tile is the neutral gray. + * loaded yet, answers `undefined` and the tile is the neutral gray. Each + * resolver keeps its first answer per object, as {@link useNavTargetIcon} does. */ export function useNavTargetColor(): NavTargetColorResolver { const metadata = useMetadata(); return useMemo( - () => (target: NavIconTarget) => { + () => answeringOnce(objectKey, (target: NavIconTarget) => { if (target.kind !== 'object') return undefined; const def = readObjectsByName(metadata, [target.objectName]).find( (item): item is { name: string; color?: unknown } => !!item && typeof item === 'object' && (item as { name?: unknown }).name === target.objectName, ); return typeof def?.color === 'string' && def.color !== '' ? def.color : undefined; - }, + }), [metadata], ); } diff --git a/ui/packages/app-shell/src/hooks/useNavTargetLabel.ts b/ui/packages/app-shell/src/hooks/useNavTargetLabel.ts index 0a85364533a..1c33ebe742f 100644 --- a/ui/packages/app-shell/src/hooks/useNavTargetLabel.ts +++ b/ui/packages/app-shell/src/hooks/useNavTargetLabel.ts @@ -232,7 +232,7 @@ export function useNavTargetLabel(options?: NavTargetLabelOptions): NavTargetLab const { language, t } = useObjectTranslation(); const drafts = useContext(DraftTargetLabels); - return useMemo(() => answeringOnce((target: NavLabelTarget): string | undefined => { + return useMemo(() => answeringOnce(targetKey, (target: NavLabelTarget): string | undefined => { switch (target.kind) { case 'object': { const objects = byName ? readObjectsByName(metadata, [target.objectName]) : metadata.objects; @@ -308,16 +308,21 @@ export function useNavTargetLabel(options?: NavTargetLabelOptions): NavTargetLab } /** - * `answer`, keeping the first answer it gives for each target and giving it - * again (objectstack#38835): see the module comment. + * `answer`, keeping the first answer it gives for each target (keyed by `key`) + * and giving it again (objectstack#38835): see the module comment. The + * contract every nav target resolver keeps (`NavTargetLabelResolver` in + * `@object-ui/layout`); `useNavTargetIcon` / `useNavTargetColor` use it too. */ -function answeringOnce(answer: NavTargetLabelResolver): NavTargetLabelResolver { +export function answeringOnce( + key: (target: T) => string, + answer: (target: T) => string | undefined, +): (target: T) => string | undefined { const answered = new Map(); return (target) => { - const key = targetKey(target); - if (answered.has(key)) return answered.get(key); + const k = key(target); + if (answered.has(k)) return answered.get(k); const text = answer(target); - answered.set(key, text); + answered.set(k, text); return text; }; } diff --git a/ui/packages/app-shell/src/preview/DraftChangesPanel.tsx b/ui/packages/app-shell/src/preview/DraftChangesPanel.tsx index 6ff0376b7b3..1351b539abe 100644 --- a/ui/packages/app-shell/src/preview/DraftChangesPanel.tsx +++ b/ui/packages/app-shell/src/preview/DraftChangesPanel.tsx @@ -1457,10 +1457,10 @@ export interface DraftChangesPanelProps { packageId?: string | null; /** * Narrows the listed drafts further, for a host whose scope the `_drafts` - * query cannot express on its own. Studio's package-less scope passes its - * own predicate (package-less FLOW drafts, objectui#11553) so the sheet - * reviews exactly what that scope's Publish ships. Applied to the folded - * entries, before anything is classified or linted. + * query cannot express on its own. The preview bar (`DraftPreviewBar`) + * passes the app's package and its customization pair, so the sheet lists + * the drafts the previewed app reads. Applied to the folded entries, before + * anything is classified or linted. */ include?: (entry: DraftChangeEntry) => boolean; /** @@ -1824,7 +1824,7 @@ export function DraftChangesPanel({ }); // objectui#12929 — offered only where the footer publishes one package as a - // batch: the package-less scope publishes by reference, a door with no + // batch: without a package each draft publishes by itself, a door with no // `backfill`, and a read-only host has no Publish to carry the choice. const backfillControl: EntryBackfillControl | undefined = onPublish && packageId diff --git a/ui/packages/app-shell/src/utils/__tests__/formViewChrome-26843.test.ts b/ui/packages/app-shell/src/utils/__tests__/formViewChrome-26843.test.ts index 6b65eec71fe..5c9db4d0019 100644 --- a/ui/packages/app-shell/src/utils/__tests__/formViewChrome-26843.test.ts +++ b/ui/packages/app-shell/src/utils/__tests__/formViewChrome-26843.test.ts @@ -7,99 +7,15 @@ */ /** - * objectstack-ai/objectstack#26843 — the form view's `buttons`, `layout`, - * `defaults`, `defaultTab` and `tabPosition` reach the console's form hosts. - * - * `resolveFormViewChrome` reads them for a NAMED form view (the Setup preview - * of a form view). A record create or edit reads no form view - * (objectstack-ai/objectstack#36425): `resolveRecordFormChrome` gives the - * host's own chrome. Each block has a CONTROL with the key absent, which keeps - * the host's own answer. + * The chrome a console record create or edit draws. A record create or edit + * reads no form view (objectstack-ai/objectstack#36425): `resolveRecordFormChrome` + * gives the host's own chrome. A named form is a `form` item since + * `@objectstack/spec` 19 (ADR-0159), never a view, so no form view's + * `buttons`, `layout` or `defaults` reaches these hosts. */ import { describe, it, expect } from 'vitest'; -import { resolveFormViewChrome, resolveRecordFormChrome } from '../recordFormNavigation'; - -const HOST = { language: 'en', submitText: 'Save', cancelText: 'Cancel' } as const; - -describe('resolveFormViewChrome — buttons', () => { - it('an authored label and show win over the host defaults', () => { - const chrome = resolveFormViewChrome( - { buttons: { submit: { label: 'Send request' }, cancel: { show: false, label: 'Back' } } }, - { ...HOST, flow: 'create' }, - ); - expect(chrome).toMatchObject({ - showSubmit: true, - submitText: 'Send request', - showCancel: false, - cancelText: 'Back', - }); - }); - - it('an authored per-locale label resolves against the UI language', () => { - const buttons = { submit: { label: { en: 'Send', 'zh-CN': '发送' } } }; - expect(resolveFormViewChrome({ buttons }, { ...HOST, flow: 'edit' }).submitText).toBe('Send'); - expect(resolveFormViewChrome({ buttons }, { ...HOST, language: 'zh-CN', flow: 'edit' }).submitText).toBe('发送'); - }); - - it('`show: false` on submit hides it', () => { - expect(resolveFormViewChrome({ buttons: { submit: { show: false } } }, { ...HOST, flow: 'edit' }).showSubmit).toBe(false); - }); - - it('CONTROL: no form view, or no `buttons` — the host labels, both shown', () => { - for (const formView of [undefined, {}, { buttons: {} }]) { - expect(resolveFormViewChrome(formView, { ...HOST, flow: 'create' })).toStrictEqual({ - showSubmit: true, - submitText: 'Save', - showCancel: true, - cancelText: 'Cancel', - layout: 'vertical', - }); - } - }); -}); - -describe('resolveFormViewChrome — layout', () => { - it('an authored horizontal reaches the form', () => { - expect(resolveFormViewChrome({ layout: 'horizontal' }, { ...HOST, flow: 'edit' }).layout).toBe('horizontal'); - }); - - it('a value the spec enum refuses (the retired `grid`) is not copied', () => { - expect(resolveFormViewChrome({ layout: 'grid' as any }, { ...HOST, flow: 'edit' }).layout).toBe('vertical'); - }); -}); - -describe('resolveFormViewChrome — defaults', () => { - const defaults = { status: 'new', priority: 'high' }; - - it('seed a create', () => { - expect(resolveFormViewChrome({ defaults }, { ...HOST, flow: 'create' }).initialValues).toBe(defaults); - }); - - it('the host values (a URL prefill) win per field over the defaults', () => { - const chrome = resolveFormViewChrome({ defaults }, { ...HOST, flow: 'create', createValues: { priority: 'low', account: 'a1' } }); - expect(chrome.initialValues).toStrictEqual({ status: 'new', priority: 'low', account: 'a1' }); - }); - - it('the merged seed keeps its identity across calls with equal inputs — the forms re-seed on a new object', () => { - const first = resolveFormViewChrome({ defaults }, { ...HOST, flow: 'create', createValues: { priority: 'low' } }); - const second = resolveFormViewChrome({ defaults }, { ...HOST, flow: 'create', createValues: { priority: 'low' } }); - expect(second.initialValues).toBe(first.initialValues); - const changed = resolveFormViewChrome({ defaults }, { ...HOST, flow: 'create', createValues: { priority: 'urgent' } }); - expect(changed.initialValues).not.toBe(first.initialValues); - expect(changed.initialValues).toMatchObject({ priority: 'urgent' }); - }); - - it('an edit never reads them', () => { - expect(resolveFormViewChrome({ defaults }, { ...HOST, flow: 'edit' }).initialValues).toBeUndefined(); - }); - - it('CONTROL: no defaults — the host values pass through as the object they are', () => { - const createValues = { due_date: '2026-10-20' }; - expect(resolveFormViewChrome({}, { ...HOST, flow: 'create', createValues }).initialValues).toBe(createValues); - expect('initialValues' in resolveFormViewChrome({}, { ...HOST, flow: 'create' })).toBe(false); - }); -}); +import { resolveRecordFormChrome } from '../recordFormNavigation'; describe('resolveRecordFormChrome — a record create or edit (objectstack-ai/objectstack#36425)', () => { it('the host\'s own buttons and labels, the vertical layout, and only the host\'s create values', () => { diff --git a/ui/packages/app-shell/src/utils/index.ts b/ui/packages/app-shell/src/utils/index.ts index 4a5fabf5e10..81ee0652857 100644 --- a/ui/packages/app-shell/src/utils/index.ts +++ b/ui/packages/app-shell/src/utils/index.ts @@ -24,7 +24,6 @@ export type { ObjectDefinitionForNavigation, RecordFormTarget, ObjectDefinitionForRecordForm, - FormViewDefinition, RecordFormModalLayout, } from './recordFormNavigation.js'; diff --git a/ui/packages/app-shell/src/utils/recordFormNavigation.ts b/ui/packages/app-shell/src/utils/recordFormNavigation.ts index 54fc64c7fc2..92ceaca15f6 100644 --- a/ui/packages/app-shell/src/utils/recordFormNavigation.ts +++ b/ui/packages/app-shell/src/utils/recordFormNavigation.ts @@ -8,9 +8,7 @@ * @module utils/recordFormNavigation */ -import { FormViewSchema, type FormView } from '@objectstack/spec/ui'; import type { RecordFlowSurface } from '@objectstack/spec/data'; -import { pickLocalized } from '@object-ui/i18n'; /** * Subset of the object metadata shape consumed by the resolver. Mirrors the @@ -138,31 +136,6 @@ export function resolveRecordFormTarget(opts: { return { kind: 'page', url: `${baseUrl}/${objectDef.name}/new?${prefill.toString()}` }; } -/** - * The form body a NAMED form carries (a `form` item's body, at the top level: - * ADR-0159): what {@link resolveFormViewChrome} reads for a form that is opened - * by its own name — a public form, a form an action of type `form` opens. - * - * ⛔ No record create or edit reads one (objectstack-ai/objectstack#36425): the - * console's create dialog, full-page create, action-opened create and edit - * load no form. Those lay out by the object's `fieldGroups` and follow the - * rules on its fields. - */ -export interface FormViewDefinition { - /** The served `form` item's name (`OBJECT.KEY`). */ - name?: string; - /** Layout family declared by the form view (`simple` | `tabbed` | `wizard` | `split`). */ - type?: string; - /** Curated field sections. */ - sections?: any[]; - /** Field layout direction — see {@link resolveFormViewChrome}. */ - layout?: FormView['layout']; - /** Per-button visibility and label — see {@link resolveFormViewChrome}. */ - buttons?: FormView['buttons']; - /** Create-mode initial values — see {@link resolveFormViewChrome}. */ - defaults?: FormView['defaults']; -} - /** * The slice of a served object (`useMetadata().objects`) the record create * and edit forms read for their layout: its name, and the child collections @@ -240,9 +213,8 @@ export function resolveRecordFormModalLayout( * The form chrome a console form host draws (objectstack-ai/objectstack#26843), * ready to spread into an `` or `` schema: the action * buttons' visibility and labels, the field layout, and a create's opening - * values. A named form takes it from its own definition - * ({@link resolveFormViewChrome}); a record create or edit from the console's - * defaults ({@link resolveRecordFormChrome}). + * values. A record create or edit takes it from the console's defaults + * ({@link resolveRecordFormChrome}). */ export interface FormViewChrome { showSubmit: boolean; @@ -254,90 +226,6 @@ export interface FormViewChrome { initialValues?: Record; } -/** - * The opening values of a create that carries both a form view's `defaults` - * and the host's own values, per `defaults` payload. The forms re-seed whenever - * `initialValues` is a new object, so a merge rebuilt per render would wipe - * what the user typed. The cache keys on the metadata payload and on the - * host's values by CONTENT, never on a memoised identity (ui/AGENTS.md #10). - */ -const mergedCreateValues = new WeakMap }>(); - -function createSeed( - defaults: Record | undefined, - createValues: Record | undefined, -): Record | undefined { - if (!defaults || Object.keys(defaults).length === 0) return createValues; - if (!createValues) return defaults; - let key: string; - try { - key = JSON.stringify(createValues); - } catch { - return { ...defaults, ...createValues }; - } - const hit = mergedCreateValues.get(defaults); - if (hit && hit.key === key) return hit.values; - const values = { ...defaults, ...createValues }; - mergedCreateValues.set(defaults, { key, values }); - return values; -} - -/** - * Resolve the {@link FormViewChrome} of a named form. - * - * Every console form host used to hard-set these props — `showSubmit: true`, - * its own submit label, `layout: 'vertical'` — over the keys the form view - * declares, so an authored `buttons`, `layout` or `defaults` saved, published - * and never rendered. No flat `showSubmit` / `submitText` key is an author's - * (the spec's form view refuses them), so the host's values are console - * defaults and the author's keys win: - * - * - `buttons.submit` / `buttons.cancel`: an authored `show` over the host's - * `true`; an authored `label`, an `I18nLabel` resolved against `language`, - * over the host's label. A form has no reset button: the spec refuses - * `buttons.reset` (objectstack-ai/objectstack#27153). - * - `layout`: the authored value when the spec's enum allows it, else - * `'vertical'`, the renderer default. - * - `defaults`, on a create only: the opening values under the ones the host - * already carries (`createValues`: a URL prefill, a parent pre-link, a - * seeded day), which win per field. - */ -export function resolveFormViewChrome( - formView: FormViewDefinition | null | undefined, - opts: { - flow: RecordFormFlow; - /** The UI language an authored `I18nLabel` resolves against. */ - language: string; - /** The host's submit label when the form view authors none. */ - submitText: string; - /** The host's cancel label when the form view authors none. */ - cancelText: string; - /** The values the host opens a create with, if any. */ - createValues?: Record; - }, -): FormViewChrome { - const { submit, cancel } = formView?.buttons ?? {}; - const layout = formView?.layout !== undefined - && FormViewSchema.shape.layout.safeParse(formView.layout).success - ? formView.layout - : undefined; - const chrome: FormViewChrome = { - showSubmit: submit?.show ?? true, - submitText: pickLocalized(submit?.label, opts.language) || opts.submitText, - showCancel: cancel?.show ?? true, - cancelText: pickLocalized(cancel?.label, opts.language) || opts.cancelText, - layout: layout ?? 'vertical', - }; - const defaults = formView?.defaults && typeof formView.defaults === 'object' && !Array.isArray(formView.defaults) - ? formView.defaults - : undefined; - const initialValues = opts.flow === 'create' - ? createSeed(defaults, opts.createValues) - : opts.createValues; - if (initialValues) chrome.initialValues = initialValues; - return chrome; -} - /** * The {@link FormViewChrome} of a record create or edit * (objectstack-ai/objectstack#36425): the host's own buttons and labels, the @@ -352,7 +240,15 @@ export function resolveRecordFormChrome(opts: { cancelText: string; createValues?: Record; }): FormViewChrome { - return resolveFormViewChrome(null, { ...opts, language: '' }); + const chrome: FormViewChrome = { + showSubmit: true, + submitText: opts.submitText, + showCancel: true, + cancelText: opts.cancelText, + layout: 'vertical', + }; + if (opts.createValues) chrome.initialValues = opts.createValues; + return chrome; } /** diff --git a/ui/packages/app-shell/src/views/ViewConfigPanel.tsx b/ui/packages/app-shell/src/views/ViewConfigPanel.tsx index c579f164591..d065104dea8 100644 --- a/ui/packages/app-shell/src/views/ViewConfigPanel.tsx +++ b/ui/packages/app-shell/src/views/ViewConfigPanel.tsx @@ -37,7 +37,6 @@ import { Button } from '@object-ui/components'; import { useObjectTranslation } from '@object-ui/i18n'; import { ViewVariantInspector } from './metadata-admin/inspectors/ViewVariantInspector.js'; import { RuntimeDraftBar } from './RuntimeDraftBar.js'; -import { isFormFamilyKey } from './metadata-admin/view-variant-model.js'; import { useMetadataLocale, t as tStudio, tFormat } from './metadata-admin/i18n.js'; import { authoredBuffer, formatMetadataError, type AuthoredLayers } from '@object-ui/data-objectstack'; import { unwrapDraftBody } from './runtime-metadata-persistence.js'; @@ -416,8 +415,6 @@ export function ViewConfigPanel({ open, onClose, mode = 'edit', activeView, obje // already holds. const objectFields = useMemo(() => mapObjectFields(objectDef), [objectDef.fields]); // eslint-disable-line react-hooks/exhaustive-deps - const familyKey = isFormFamilyKey(draft.viewKind) ? 'form' : 'list'; - // Shallow-merge an inspector patch into the draft, then mirror the // flattened runtime view back to the host field-by-field (matching the // legacy onViewUpdate(field, value) contract ObjectView expects). @@ -574,7 +571,6 @@ export function ViewConfigPanel({ open, onClose, mode = 'edit', activeView, obje name={draft.name} draft={draft as unknown as Record} variantKey="config" - familyKey={familyKey} isHome readOnly={readOnly} locale={locale} diff --git a/ui/packages/app-shell/src/views/metadata-admin/ConditionalFormattingEditor.listEquality-36459.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/ConditionalFormattingEditor.listEquality-36459.test.tsx index a2e7270da15..6e68f956b37 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/ConditionalFormattingEditor.listEquality-36459.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/ConditionalFormattingEditor.listEquality-36459.test.tsx @@ -158,7 +158,6 @@ describe('the mount site hands the editor the object’s field definitions (#364 readOnly={false} locale={'en-US'} variantKey="list" - familyKey="list" isHome={false} objectFieldsOverride={mapObjectFields(TICKET as never)} /> diff --git a/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.requiredInGatedSection-6900.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.requiredInGatedSection-6900.test.tsx deleted file mode 100644 index d9cfa5273a6..00000000000 --- a/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.requiredInGatedSection-6900.test.tsx +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. - -/** - * Save refuses a form view that puts an OBJECT-required field inside a - * predicate-gated section — on BOTH hosts of the view inspector - * (objectui#6900, landed by ruling 5749269225, letter c). - * - * ## The hazard - * - * The server validates a record against the object's field definitions and - * never reads a form view (ruled objectstack#13252, option C rejected). So a - * form whose section is shown only when `'sales_manager' in - * current_user.positions` and which holds the object-required `salary` saves - * fine as metadata, and then cannot be completed by anyone the predicate hides - * the section from: the record save is refused naming a field they cannot see. - * - * ## Why the refusal rides the inspector's blocking channel - * - * The ruling puts it in the channel ALREADY licensed to gate Save — the - * inspector's blocking issues — and keeps the live Zod pass - * (`validateMetadataDraft`) advisory. `ResourceEditPage.schemaAdvisory.test.tsx` - * (objectui#6980) pins that asymmetry and is untouched by this card. - * - * ## Both hosts - * - * `ResourceEditPage` mounts the view inspector two ways: the DEFAULT inspector - * when nothing is selected (`ViewDefaultInspector`) and the SCOPED one when the - * canvas emits a variant selection (`ViewInspector`). Each is pinned here, so - * the refusal cannot be wired on one of the two paths an author reaches the - * same editor by. - * - * Only the canvas is stubbed (so a preview exists, and so the scoped leg can - * emit its selection). The object catalog arrives through the real - * `useObjectFields` read of `client.get('object', …)`, and the predicate's - * roots are read by the real `@objectstack/formula` parser. - */ - -import '@testing-library/jest-dom/vitest'; -// The source loads these lazily; pay that load at collection, not inside a -// case's clocked window. -import '@objectstack/lint'; -import * as React from 'react'; -import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'; -// Module scope as well as where a test awaits it below: the cold transform is paid -// during collection, which no test or hook timeout clocks (AGENTS.md, flaky-test discipline). -import '@objectstack/formula'; -import { render, screen, fireEvent, cleanup, waitFor, act } from '@testing-library/react'; -import { MemoryRouter } from 'react-router-dom'; - -/** Canonical wire shape — the same spelling as the objectui#6237 fixtures. */ -const cel = (source: string) => ({ dialect: 'cel', source }); -const IDENTITY_GATE = cel("'sales_manager' in current_user.positions"); -const RECORD_GATE = cel("record.status == 'sent'"); - -const state = vi.hoisted(() => ({ - salaryRequired: true, - gate: null as unknown, -})); - -function employeeObject(): Record { - return { - name: 'employee', - label: 'Employee', - fields: { - subject: { type: 'text', label: 'Subject' }, - salary: { type: 'number', label: 'Salary', ...(state.salaryRequired ? { required: true } : {}) }, - }, - }; -} - -function formView(): Record { - return { - name: 'employee_form', - label: 'Employee form', - object: 'employee', - viewKind: 'form', - config: { - type: 'simple', - sections: [ - { name: 'basics', label: 'Basics', fields: ['subject'] }, - { name: 'pay', label: 'Compensation', visibleWhen: state.gate, fields: ['salary'] }, - ], - }, - }; -} - -const mockClient = { - list: vi.fn(async () => []), - listDrafts: vi.fn(async () => []), - layered: vi.fn(async () => { - const view = formView(); - return { effective: view, code: view, editable: true }; - }), - getDraft: vi.fn(async () => null), - get: vi.fn(async (type: string, name: string) => - type === 'object' && name === 'employee' ? employeeObject() : null, - ), - saveDraft: vi.fn(async () => ({})), - withPreviewDrafts() { return this; }, -}; - -vi.mock('./useMetadata', async (importOriginal) => { - const mod = await importOriginal(); - return { - ...mod, - useMetadataClient: () => mockClient, - useMetadataTypes: () => ({ - entries: [{ type: 'view', name: 'view', label: 'View', allowEnvironmentOverlay: true }], - }), - }; -}); - -import { MetadataResourceEditPage } from './ResourceEditPage'; -import { registerBuiltinInspectors } from './inspectors'; -import { registerMetadataPreview, getMetadataPreview, type MetadataSelection } from './preview-registry'; - -registerBuiltinInspectors(); - -/** - * Canvas stand-in. It exists so the host takes its split-editor branch; its one - * button emits the variant selection the real tab strip emits, which is what - * swaps the DEFAULT inspector for the SCOPED one. - */ -function StubViewCanvas({ - onSelectionChange, -}: { - onSelectionChange?: (next: MetadataSelection | null) => void; -}) { - return ( - - ); -} - -const realViewPreview = getMetadataPreview('view'); - -beforeEach(() => { - state.salaryRequired = true; - state.gate = IDENTITY_GATE; - registerMetadataPreview('view', StubViewCanvas as never); -}); - -afterEach(() => { - cleanup(); - if (realViewPreview) registerMetadataPreview('view', realViewPreview); -}); - -/** The Save icon button, identified by its title in either state. */ -// Title flipped to the neutral inspector copy by ruling 5831744213 (objectui#6900). -const saveButton = () => screen.getByTestId('resource-save'); - -/** - * What Save says: a withheld Save's reason, which is its accessible description - * (objectstack#32105: it keeps its name "Save"), else an enabled Save's title. - */ -const saveSays = () => { - const btn = saveButton(); - const id = btn.getAttribute('aria-describedby'); - return (id ? document.getElementById(id)?.textContent : null) ?? btn.getAttribute('title') ?? ''; -}; - -/** - * Let the lazily imported CEL parser and the object-catalog read settle, so a - * negative leg's green is observed AFTER the verdict it would have flipped. - */ -async function settle() { - await act(async () => { - await import('@objectstack/formula'); - await new Promise((r) => setTimeout(r, 0)); - }); -} - -async function openEditor(host: 'default' | 'scoped') { - render( - - - , - ); - const select = await screen.findByRole('button', { name: 'select the form variant' }); - if (host === 'scoped') fireEvent.click(select); - // Wait for the inspector (either host) to mount its curated Label field — - // found by its placeholder, since the variant's spec form below it carries - // "Label" inputs of its own (one per section). - return screen.findByPlaceholderText('e.g. All Leads'); -} - -/** Dirty the draft, so Save is live at all and only the gate can hold it. */ -function dirty(label: HTMLElement) { - fireEvent.change(label, { target: { value: 'Employee form (edited)' } }); -} - -describe.each([['default'], ['scoped']] as const)( - 'MetadataResourceEditPage — the %s view inspector refuses a required field in a gated section (objectui#6900)', - (host) => { - it('Save stays disabled on an identity-gated section holding an object-required field', async () => { - const label = await openEditor(host); - // Dirty FIRST: an unedited draft keeps Save disabled on its own, so only - // an edited one can show that the refusal is what holds it shut. - dirty(label); - await settle(); - await waitFor(() => expect(saveButton()).toBeDisabled(), { timeout: 4000 }); - // And the refusal the author reads is on screen beside it. - expect(await screen.findByTestId('view-gated-required-issues')).toHaveTextContent('Salary'); - }); - - it('the Save title held by this refusal is the neutral inspector copy, not the CEL one (ruling 5831744213)', async () => { - const label = await openEditor(host); - dirty(label); - await settle(); - await waitFor(() => expect(saveButton()).toBeDisabled(), { timeout: 4000 }); - expect(saveSays()).toBe('Fix the issues shown in the inspector before saving.'); - }); - - it('control: the same form with the field NOT required on the object saves', async () => { - state.salaryRequired = false; - const label = await openEditor(host); - dirty(label); - await settle(); - await waitFor(() => expect(saveButton()).toBeEnabled(), { timeout: 4000 }); - expect(screen.queryByTestId('view-gated-required-issues')).toBeNull(); - }); - - it('control: the same section gated on a RECORD predicate saves', async () => { - state.gate = RECORD_GATE; - const label = await openEditor(host); - dirty(label); - await settle(); - await waitFor(() => expect(saveButton()).toBeEnabled(), { timeout: 4000 }); - expect(screen.queryByTestId('view-gated-required-issues')).toBeNull(); - }); - }, -); diff --git a/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx b/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx index 44431796416..44cd26c701e 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx @@ -3151,8 +3151,9 @@ function MetadataResourceEditPageImpl({ const saveTitle = saving ? t('engine.edit.saving', locale) : inspectorBlocking > 0 - // Neutral: the inspector channel carries CEL faults AND the - // objectui#6900 required-field refusal (ruling 5831744213). + // Neutral: the inspector channel carries more than CEL faults (a + // dataset dimension with no field, for one), so the title names no one + // kind (objectui#6900, ruling 5831744213). ? t('perm.inspector.saveBlocked', locale) : refusalBlocking > 0 ? tFormat('engine.validation.serverRefused', locale, { diff --git a/ui/packages/app-shell/src/views/metadata-admin/ResourceListPage.tsx b/ui/packages/app-shell/src/views/metadata-admin/ResourceListPage.tsx index bcb8cf66453..635fe865fe8 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/ResourceListPage.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/ResourceListPage.tsx @@ -855,9 +855,6 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string