diff --git a/.changeset/35650-action-designer-served-rows.md b/.changeset/35650-action-designer-served-rows.md new file mode 100644 index 00000000000..af2b41c1749 --- /dev/null +++ b/.changeset/35650-action-designer-served-rows.md @@ -0,0 +1,14 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(studio): the action designer draws a script action's refusal catalogue and declared texts with their served rows + +Clause-②: no +Metadata-protocol: none + +The served `action` form gives `refusals` and `texts` the key-only record control (an entry is drawn under its code or key, with its message, status, reasons and params rows) and help text, but only the Related drawer editor read that form. The action's full-page editor and the Studio object's Actions view mount the action designer, whose "More fields" section was handed the bare schema, so both keys read as the raw JSON editor. + +The designer now takes the served form from its host (`serverForm` on the default-inspector props) and draws the two rows from it in its Behavior section, beside the script body; the row's own visibility rule shows them on a script action only. A host with no served form keeps both keys in "More fields", as before. Nothing about what an action stores or what the server accepts changes. + +The console's zh-CN overlay gains the labels for the action's `refusals` and `texts` rows and the hook's `texts` rows. diff --git a/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.actionServedRows-35650.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.actionServedRows-35650.test.tsx new file mode 100644 index 00000000000..103553085d4 --- /dev/null +++ b/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.actionServedRows-35650.test.tsx @@ -0,0 +1,170 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#35650 — the action's full-page editor draws a script action's + * refusal catalogue (`refusals`) and declared texts (`texts`) with their + * served rows: the key-only record control and the row's help text, not the + * raw JSON editor the bare schema gives a record. + * + * The REAL page with the production registrations: `action` registers a + * preview and a default inspector, so the page takes its designer branch and + * the no-selection panel is `ActionDefaultInspector`. The type row is built + * from the spec the way the server builds it: `actionForm` as the form, and + * `ActionSchema` converted with `z.toJSONSchema(…, { io: 'input' })` as the + * schema. The only stand-ins are the metadata client and the network. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import { z } from 'zod'; +import { ActionSchema, actionForm } from '@objectstack/spec/ui'; + +// Module-scope imports of the engines the page reaches through dynamic +// `import()` (the CEL authoring and the save-time lint): a cold first load +// stays out of every `waitFor` (`check:test-source-alias`). +import '@objectstack/formula'; +import '@objectstack/lint'; + +/** The `action` row's `schema`, converted from the spec the way the server does. */ +const ACTION_JSON_SCHEMA = z.toJSONSchema(ActionSchema as unknown as z.ZodType, { + io: 'input', + unrepresentable: 'any', +}) as Record; + +/** The served row of `key`, read off the form the server serves. */ +function servedHelpText(key: string): string { + for (const section of actionForm.sections ?? []) { + for (const row of section.fields ?? []) { + if (typeof row !== 'string' && row.field === key) return String(row.helpText); + } + } + throw new Error(`actionForm declares no ${key} row`); +} + +const STORED = { + name: 'sign_contract', + label: 'Sign contract', + objectName: 'contract', + type: 'script', + locations: ['record_header'], + body: { language: 'js', source: "throw { code: 'SIGN_IN_REQUIRED' };" }, + refusals: { SIGN_IN_REQUIRED: { message: 'Sign in first.', status: 401 } }, + texts: { email_subject: { message: 'Contract signed' } }, +}; + +let stored: Record = STORED; + +const mockClient = { + list: vi.fn(async () => []), + listDrafts: vi.fn(async () => []), + layered: vi.fn(async () => ({ effective: stored, code: null, editable: true, deletable: true })), + getDraft: vi.fn(async () => null), + get: vi.fn(async () => stored), + save: vi.fn(async (_type: string, _name: string, item: unknown) => { + stored = item as Record; + return {}; + }), + saveDraft: vi.fn(async () => ({})), + publish: vi.fn(async () => ({ success: true })), + references: vi.fn(async () => []), + history: vi.fn(async () => []), + // The object-scoped field pickers read the bound object through the draft-preview client. + withPreviewDrafts: vi.fn(), +}; +mockClient.withPreviewDrafts.mockImplementation(() => mockClient); + +vi.mock('./useMetadata', async (importOriginal) => ({ + ...(await importOriginal()), + useMetadataClient: () => mockClient, + useMetadataTypes: () => ({ + loading: false, + error: null, + entries: [ + { + type: 'action', + name: 'action', + label: 'Action', + domain: 'ui', + allowEnvironmentOverlay: true, + allowRuntimeCreate: true, + schema: ACTION_JSON_SCHEMA, + form: actionForm, + }, + ], + }), +})); +vi.mock('@monaco-editor/react', () => { + const Editor = () => null; + return { Editor, default: Editor, loader: { init: () => Promise.reject(new Error('offline')) } }; +}); +vi.mock('@object-ui/plugin-editor', () => ({ configureBundledMonaco: () => Promise.resolve() })); +vi.stubGlobal( + 'fetch', + vi.fn(async () => new Response('null', { status: 404, headers: { 'content-type': 'application/json' } })), +); + +import { MetadataResourceEditPage } from './ResourceEditPage'; +import { t } from './i18n'; +// The load-time registrations, exactly as the package entry runs them, so the +// branch this file takes is the branch production takes. +import './register-builtins'; +import { registerBuiltinDesigners } from './register-builtin-designers'; +registerBuiltinDesigners(); + +beforeEach(() => { + stored = STORED; + for (const fn of Object.values(mockClient)) (fn as unknown as { mockClear: () => void }).mockClear(); + mockClient.withPreviewDrafts.mockImplementation(() => mockClient); + window.localStorage.setItem('metadata-admin:autosave', '0'); +}); +afterEach(() => { + cleanup(); + window.localStorage.removeItem('metadata-admin:autosave'); +}); + +async function openAction(): Promise { + render( + + + , + ); + // The designer branch opens editable: its panel is the inspector itself. + await screen.findByText(t('engine.inspector.moreFields', 'en'), {}, { timeout: 8000 }); + +} + +describe('the action full-page editor draws refusals and texts from their served rows (objectstack#35650)', () => { + it('draws each as the key-only record control with the served help text, and no raw JSON', async () => { + await openAction(); + // No editor on the panel holds either record as JSON text (the raw JSON face). + const jsonHolders = Array.from(document.querySelectorAll('textarea')).filter( + (el) => el.value.includes('"SIGN_IN_REQUIRED"') || el.value.includes('"email_subject"'), + ); + expect(jsonHolders).toEqual([]); + // The served rows' help text, and the key-only control drawing each entry under its key. + expect(screen.getByText(servedHelpText('refusals'))).toBeInTheDocument(); + expect(screen.getByText(servedHelpText('texts'))).toBeInTheDocument(); + const rows = screen.getByTestId('action-served-rows'); + expect(within(rows).getByText('SIGN_IN_REQUIRED', { selector: 'span' })).toBeInTheDocument(); + expect(within(rows).getByText('email_subject', { selector: 'span' })).toBeInTheDocument(); + }); + + it('an entry edited through the served row saves as a spec-valid action', async () => { + await openAction(); + const rows = screen.getByTestId('action-served-rows'); + fireEvent.click(within(rows).getByText('email_subject', { selector: 'span' })); + const entry = within(rows).getByText('email_subject', { selector: 'span' }).closest('.rounded-md') as HTMLElement; + fireEvent.change(within(entry).getByDisplayValue('Contract signed'), { target: { value: 'Your contract is signed' } }); + await waitFor(() => expect(screen.getByTestId('resource-save')).toBeEnabled(), { timeout: 4000 }); + fireEvent.click(screen.getByTestId('resource-save')); + await waitFor(() => expect(mockClient.save).toHaveBeenCalledTimes(1), { timeout: 6000 }); + const body = JSON.parse(JSON.stringify(mockClient.save.mock.calls[0]![2])) as Record; + expect(body.texts).toEqual({ email_subject: { message: 'Your contract is signed' } }); + expect(body.refusals).toEqual(STORED.refusals); + const parsed = ActionSchema.safeParse(body); + expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true); + }); +}); 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 b8e640e13de..3cdd83b37a7 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx @@ -3812,6 +3812,7 @@ function MetadataResourceEditPageImpl({ readOnly={formReadOnly} locale={locale} serverSchema={entry?.schema as Record | undefined} + serverForm={entry?.form} issues={displayIssues} revealIssues={revealIssues} onInlineIssueFieldsChange={setInlineIssueFields} diff --git a/ui/packages/app-shell/src/views/metadata-admin/default-inspector-registry.ts b/ui/packages/app-shell/src/views/metadata-admin/default-inspector-registry.ts index a63b2f88904..fb0917d7acf 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/default-inspector-registry.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/default-inspector-registry.ts @@ -24,6 +24,7 @@ import type { ComponentType, ReactNode } from 'react'; import type { SupportedLocale } from './i18n.js'; import { createObservableTypeRegistry, type MetadataSelection } from './preview-registry.js'; import type { SchemaFormIssue } from './SchemaForm.js'; +import type { FormViewSpec } from './form-spec.js'; export interface MetadataDefaultInspectorProps { /** Metadata type, e.g. 'view'. */ @@ -73,6 +74,16 @@ export interface MetadataDefaultInspectorProps { * server schema is available (offline / older server). */ serverSchema?: Record; + /** + * The served FormView layout for this type (`RichMetadataTypeEntry.form`, + * from `/meta/types`), the form a generic host hands `SchemaForm` beside + * {@link serverSchema}. A curated inspector reads the rows it names from it, + * so a row the server declares a face for (a widget, help text, a + * visibility predicate) is drawn with that face rather than the one the + * bare schema implies (objectstack#35650). Undefined when the host has no + * served form: such an inspector draws those keys as it did without one. + */ + serverForm?: FormViewSpec; /** * The host's issues on the draft (a refused save, the live pass), paths * relative to the draft — what the host's fallback form is handed. An diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ActionDefaultInspector.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ActionDefaultInspector.tsx index 35f6bbcb8c5..16b68477d23 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ActionDefaultInspector.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ActionDefaultInspector.tsx @@ -41,6 +41,12 @@ * control, shared (`ScriptCapabilitiesField`), because both bodies are the * spec's one `HookBodySchema`. An expression body shows none, and a switch to * it drops the grant with the other L2-only keys ({@link writeScriptBody}). + * + * A script action's refusal catalogue (`refusals`) and declared texts (`texts`) + * are drawn from their SERVED form rows (objectstack#35650), handed in as + * `serverForm`: the key-only record control, the entry rows and the help text + * the server declares. Fed the bare schema in "More fields" they read as the + * raw JSON editor. A host with no served form keeps them in "More fields". */ import * as React from 'react'; @@ -59,6 +65,9 @@ import { usePermissions } from '@object-ui/permissions'; import type { MetadataDefaultInspectorProps } from '../default-inspector-registry.js'; import { SchemaForm } from '../SchemaForm.js'; import { fallbackFormPatch } from './fallbackFormPatch.js'; +import { servedFormRows } from './servedFormRows.js'; +import { useIssuePrefixRegister } from '../issuePath.js'; +import type { FormViewSpec } from '../form-spec.js'; import { t, tFormat, type SupportedLocale } from '../i18n.js'; import { InspectorShell, @@ -479,6 +488,19 @@ const CURATED_FIELDS = [ */ const RETIRED_FIELDS = ['bulkEnabled', 'shortcut']; +/** + * Keys this inspector draws from their SERVED form row (objectstack#35650), + * beside the script body in the Behavior section: the action's refusal + * catalogue and its declared texts. Each is a record keyed by the code or key + * the body uses, and its served row declares the key-only record control, the + * entry's own rows and the help text; the bare schema the fallback form reads + * says only "a record", which is the raw JSON editor. The row's own + * `visibleWhen` (a `script` action) decides when it shows. + * + * A key the served form has no row for stays in the fallback form, as before. + */ +const SERVED_ROW_FIELDS = ['refusals', 'texts'] as const; + /* ─────────────── small helpers ─────────────── */ function SectionHeader({ title, hint }: { title: string; hint?: string }) { @@ -639,6 +661,23 @@ function ParamOptionsEditor({ options, onCommit, disabled, locale }: { /* ─────────────── inspector ─────────────── */ +/** + * The setter a whole-draft `SchemaForm` reports its inline rows through + * (`onInlineIssueFieldsChange`): each row key is registered, unprefixed, for as + * long as the form reports it, so two such forms on one draft are heard as one + * union rather than the later report replacing the earlier one. + */ +function useWholeDraftFormIssueRows( + register: (prefix: string) => () => void, +): (rows: ReadonlySet) => void { + const [rows, setRows] = React.useState>(() => new Set()); + React.useEffect(() => { + const offs = [...rows].map((row) => register(row)); + return () => offs.forEach((off) => off()); + }, [rows, register]); + return setRows; +} + /** * The CEL editors this inspector mounts, as aggregation keys. Errors are * counted PER SITE rather than into one running total: the two predicate @@ -659,8 +698,15 @@ export function ActionDefaultInspector({ issues, revealIssues, onInlineIssueFieldsChange, + serverForm, }: MetadataDefaultInspectorProps) { const tr = React.useCallback((key: string) => t(key, locale), [locale]); + // Two forms draw rows of this draft (the served rows below and the "More + // fields" fallback), so each registers the rows it draws and the host hears + // the union (objectstack#35628's inline register). + const registerIssuePrefix = useIssuePrefixRegister(onInlineIssueFieldsChange); + const setServedIssueRows = useWholeDraftFormIssueRows(registerIssuePrefix); + const setFallbackIssueRows = useWholeDraftFormIssueRows(registerIssuePrefix); // objectui#12510 — the Icon label names the icon picker (the shape objectui#12531 // gave the object and app-nav icon fields): the picker is a combobox, which // takes no name from its content. @@ -899,6 +945,14 @@ export function ActionDefaultInspector({ }; const fallbackSchema = serverSchema as Record | undefined; + // objectstack#35650 — the served rows of SERVED_ROW_FIELDS, for the keys the + // served schema declares, as a one-section form over the same schema. + const servedProps = (fallbackSchema?.properties ?? {}) as Record; + const servedRows = servedFormRows(serverForm, SERVED_ROW_FIELDS).filter((row) => row.field in servedProps); + const servedRowsForm: FormViewSpec | undefined = + serverForm && servedRows.length > 0 + ? { ...serverForm, type: 'simple', sections: [{ fields: servedRows }], groups: undefined } + : undefined; return ( {tr('engine.inspector.action.bodyShapeHint')} )} + {fallbackSchema && servedRowsForm && ( +
+ onPatch(fallbackFormPatch(draft, next))} + /> +
+ )} {/* 3 ─ Inputs (params) */} @@ -1272,11 +1340,11 @@ export function ActionDefaultInspector({ row.field) : [])]} readOnly={readOnly} issues={issues} revealIssues={revealIssues} - onInlineIssueFieldsChange={onInlineIssueFieldsChange} + onInlineIssueFieldsChange={setFallbackIssueRows} onChange={(next) => onPatch(fallbackFormPatch(draft, next))} /> diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/servedFormRows.ts b/ui/packages/app-shell/src/views/metadata-admin/inspectors/servedFormRows.ts new file mode 100644 index 00000000000..a77da9d31b4 --- /dev/null +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/servedFormRows.ts @@ -0,0 +1,37 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { FormFieldSpec, FormViewSpec } from '../form-spec.js'; + +/** + * The rows the served form declares for `keys`, in the form's own order + * (objectstack#35650). + * + * A curated inspector edits most keys with its own controls and hands the rest + * to a "More fields" `SchemaForm` fed the bare served schema. A key whose + * served row declares its face — a `widget`, help text, nested row + * descriptors, a visibility predicate — loses all of it there: the schema + * alone says only "a record", and a record with no row reads as the raw JSON + * editor. Drawing such a key from its served row is how the inspector reads + * the contract the server already serves, instead of hand-building a second + * face for it. + * + * A key the form declares no row for is not returned, so the caller keeps + * drawing it in its fallback form, as before: nothing is lost when the host + * has no served form, or the server's form predates the row. A `{ group }` + * section names no row by key, so it contributes none here (`SchemaForm` + * resolves such a section when it renders a whole form; this is a lookup). + */ +export function servedFormRows( + form: FormViewSpec | undefined, + keys: readonly string[], +): FormFieldSpec[] { + const rows: FormFieldSpec[] = []; + for (const section of form?.sections ?? form?.groups ?? []) { + if (!Array.isArray(section.fields)) continue; + for (const row of section.fields) { + const spec: FormFieldSpec = typeof row === 'string' ? { field: row } : row; + if (keys.includes(spec.field) && !rows.some((r) => r.field === spec.field)) rows.push(spec); + } + } + return rows; +} diff --git a/ui/packages/app-shell/src/views/metadata-admin/metadata-form-zh-cn.ts b/ui/packages/app-shell/src/views/metadata-admin/metadata-form-zh-cn.ts index 6a54461b561..b7421f45679 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/metadata-form-zh-cn.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/metadata-form-zh-cn.ts @@ -286,6 +286,9 @@ export const ZH_CN_SPEC_FORMS: NonNullable = { 'refusals.reasons': { label: '原因' }, 'refusals.reasons.message': { label: '提示语' }, 'refusals.params': { label: '参数' }, + texts: { label: '文本' }, + 'texts.message': { label: '句子' }, + 'texts.params': { label: '参数' }, handler: { label: '处理器' }, async: { label: '异步' }, onError: { label: '错误处理' }, @@ -531,6 +534,15 @@ export const ZH_CN_SPEC_FORMS: NonNullable = { 'body.capabilities': { label: '能力' }, 'body.timeoutMs': { label: '超时(毫秒)' }, 'body.memoryMb': { label: '内存(MB)' }, + refusals: { label: '拒绝目录' }, + 'refusals.message': { label: '提示语' }, + 'refusals.status': { label: '状态码' }, + 'refusals.reasons': { label: '原因' }, + 'refusals.reasons.message': { label: '提示语' }, + 'refusals.params': { label: '参数' }, + texts: { label: '文本' }, + 'texts.message': { label: '句子' }, + 'texts.params': { label: '参数' }, params: { label: '参数' }, 'params.name': { label: '名称' }, 'params.field': { label: '字段' }, diff --git a/ui/packages/app-shell/src/views/studio-design/DataPillar.actionServedRows-35650.test.tsx b/ui/packages/app-shell/src/views/studio-design/DataPillar.actionServedRows-35650.test.tsx new file mode 100644 index 00000000000..c8df36e43d0 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/DataPillar.actionServedRows-35650.test.tsx @@ -0,0 +1,152 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#35650 — on the Studio design surface, an object's Actions view + * draws a script action's refusal catalogue (`refusals`) and declared texts + * (`texts`) with their served rows: the key-only record control and the row's + * help text, not the raw JSON editor the bare schema gives a record. + * + * The real pillar with the real action inspector: the surface reads the + * `action` type row from `/meta/types` and hands its schema and its form to the + * Actions view. The type row is built from the spec the way the server builds + * it (`actionForm`, `ActionSchema` through `z.toJSONSchema(…, { io: 'input' })`). + * The only stand-ins are the metadata client's transport and the data source. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { afterEach, describe, expect, it, vi } from 'vitest'; +import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import { z } from 'zod'; +import { MetadataClient } from '@object-ui/data-objectstack'; +import { ActionSchema, actionForm } from '@objectstack/spec/ui'; + +const ACTION_JSON_SCHEMA = z.toJSONSchema(ActionSchema as unknown as z.ZodType, { + io: 'input', + unrepresentable: 'any', +}) as Record; + +/** The served row's help text for `key`, read off the form the server serves. */ +function servedHelpText(key: string): string { + for (const section of actionForm.sections ?? []) { + for (const row of section.fields ?? []) { + if (typeof row !== 'string' && row.field === key) return String(row.helpText); + } + } + throw new Error(`actionForm declares no ${key} row`); +} + +const SIGN = { + name: 'showcase_task_sign', + label: 'Sign', + objectName: 'showcase_task', + locations: ['record_more'], + type: 'script', + body: { language: 'js', source: "throw { code: 'SIGN_IN_REQUIRED' };" }, + refusals: { SIGN_IN_REQUIRED: { message: 'Sign in first.', status: 401 } }, + texts: { email_subject: { message: 'Task signed' } }, +}; + +let objectDef: Record = {}; + +const fetchImpl = vi.fn(async () => new Response('null', { status: 404, headers: { 'content-type': 'application/json' } })); +const client = new MetadataClient({ baseUrl: 'http://test.local', fetch: fetchImpl as unknown as typeof fetch }); +Object.assign(client, { + list: vi.fn(async () => [{ name: 'showcase_task', label: 'Task' }]), + listDrafts: vi.fn(async () => []), + layered: vi.fn(async () => ({ effective: objectDef, code: objectDef })), + getDraft: vi.fn(async () => null), +}); + +const ACTION_TYPE_ROW = { + type: 'action', + name: 'action', + label: 'Action', + domain: 'ui', + allowEnvironmentOverlay: true, + allowRuntimeCreate: true, + schema: ACTION_JSON_SCHEMA, + form: actionForm, +}; + +vi.mock('../metadata-admin/useMetadata', async (importOriginal) => { + const mod = await importOriginal(); + return { ...mod, useMetadataClient: () => client, useMetadataTypes: () => ({ entries: [ACTION_TYPE_ROW] }) }; +}); + +vi.mock('./packages-io', async (importOriginal) => { + const mod = await importOriginal(); + return { ...mod, fetchPackages: vi.fn(async () => []) }; +}); + +// The Advanced views live in a Radix DropdownMenu; rendered as passthroughs, +// as in DataPillar.actionRefusal-26736.test.tsx. +type PassthroughProps = { children?: React.ReactNode; onSelect?: () => void }; +vi.mock('@object-ui/components', async (importOriginal) => { + const mod = await importOriginal(); + return { + ...mod, + DropdownMenu: (p: PassthroughProps) =>
{p.children}
, + DropdownMenuTrigger: (p: PassthroughProps) =>
{p.children}
, + DropdownMenuContent: (p: PassthroughProps) =>
{p.children}
, + DropdownMenuItem: (p: PassthroughProps) => ( + + ), + DropdownMenuRadioGroup: (p: PassthroughProps) =>
{p.children}
, + DropdownMenuRadioItem: (p: PassthroughProps) => ( + + ), + }; +}); + +vi.mock('@object-ui/react', async (importOriginal) => { + const mod = await importOriginal(); + return { ...mod, useAdapter: () => dataSource }; +}); + +// The source reaches a dynamic import of it: its first load is paid at collection (`check:test-source-alias`). +import '@objectstack/lint'; +import { DataPillar } from './StudioDesignSurface'; +import { StudioSaveHarness } from './__tests__/studioSaveHarness'; +import { createEmptyDataSource } from './__tests__/emptyDataSource'; +import { registerBuiltinInspectors } from '../metadata-admin/inspectors'; +import { t } from '../metadata-admin/i18n'; + +const dataSource = createEmptyDataSource(); +registerBuiltinInspectors(); + +afterEach(() => { + cleanup(); + fetchImpl.mockClear(); +}); + +async function openActionsView(): Promise { + objectDef = { name: 'showcase_task', label: 'Task', fields: [{ name: 'title', label: 'Title', type: 'text' }], actions: [SIGN] }; + render( + + + , + ); + // The first match is the flat tab (the passthrough menu draws a second). + fireEvent.click((await screen.findAllByRole('button', { name: t('engine.studio.data.tab.actions', 'en') }))[0]); + await screen.findByText(t('engine.inspector.moreFields', 'en'), {}, { timeout: 8000 }); + +} + +describe('Studio Actions view — refusals and texts take their served rows (objectstack#35650)', () => { + it('draws each as the key-only record control with the served help text, and no raw JSON', async () => { + await openActionsView(); + // No editor on the panel holds either record as JSON text (the raw JSON face). + const jsonHolders = Array.from(document.querySelectorAll('textarea')).filter( + (el) => el.value.includes('"SIGN_IN_REQUIRED"') || el.value.includes('"email_subject"'), + ); + expect(jsonHolders).toEqual([]); + // The served rows' help text, and the key-only control drawing each entry under its key. + expect(screen.getByText(servedHelpText('refusals'))).toBeInTheDocument(); + expect(screen.getByText(servedHelpText('texts'))).toBeInTheDocument(); + const rows = screen.getByTestId('action-served-rows'); + expect(within(rows).getByText('SIGN_IN_REQUIRED', { selector: 'span' })).toBeInTheDocument(); + expect(within(rows).getByText('email_subject', { selector: 'span' })).toBeInTheDocument(); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectActionsPanel.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectActionsPanel.tsx index e25bb6ff4cd..874de3ffca3 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectActionsPanel.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectActionsPanel.tsx @@ -80,6 +80,7 @@ import { Ban, Zap, Plus, Trash2, ChevronDown, ChevronRight, Loader2, Power } fro import { Popover, PopoverTrigger, PopoverContent } from '@object-ui/components'; import { getIcon } from '../../utils/getIcon.js'; import { useRegisteredMetadataDefaultInspector } from '../metadata-admin/default-inspector-registry.js'; +import type { FormViewSpec } from '../metadata-admin/form-spec.js'; import type { I18nLabel } from '@objectstack/spec/ui'; import { t, tFormat, useMetadataLocale } from '../metadata-admin/i18n.js'; import { readFields } from '../metadata-admin/previews/object-fields-io.js'; @@ -167,6 +168,7 @@ export function ObjectActionsPanel({ onPatch, disabled, actionSchema, + actionForm, onBlockingIssuesChange, onCelVerdictsChange, focus, @@ -202,6 +204,13 @@ export function ObjectActionsPanel({ * forward-compatible config panel for the action metadata. */ actionSchema?: Record; + /** + * The served FormView layout for the `action` type (`/meta/types`), handed + * to ActionDefaultInspector as `serverForm` so the rows it draws from the + * served form (the refusal catalogue and declared texts) take their served + * face, not the raw JSON editor (objectstack#35650). + */ + actionForm?: FormViewSpec; /** * objectstack#30088 — on a read-only base's object, its pair: New saves the * action as an `action` item there (see the header). Absent, every action is @@ -820,6 +829,7 @@ export function ObjectActionsPanel({ readOnly={!editable(sel.name)} locale={locale} serverSchema={actionSchema} + serverForm={actionForm} onBlockingIssuesChange={(count) => reportCel(String(sel.name ?? ''), count)} /> diff --git a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx index 4ae98f6017a..cadcf2c861c 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx @@ -290,6 +290,7 @@ import { useRegisteredMetadataInspectorTypes, } from '../metadata-admin/inspector-registry.js'; import { useRegisteredMetadataDefaultInspector } from '../metadata-admin/default-inspector-registry.js'; +import type { FormViewSpec } from '../metadata-admin/form-spec.js'; import { getMetadataResource } from '../metadata-admin/registry.js'; import { useMetadataClient, useMetadataTypes } from '../metadata-admin/useMetadata.js'; // objectui#11773 — every draft save of an existing item sends the version its buffer was built on. @@ -5627,6 +5628,13 @@ export function DataPillar({ for (const e of metaTypes) idx[e.type] = e.schema; return idx; }, [metaTypes]); + // objectstack#35650 — the served form layouts beside them, so a panel's + // curated inspector draws a row the server declares a face for with it. + const typeForms = React.useMemo(() => { + const idx: Record = {}; + for (const e of metaTypes) idx[e.type] = e.form; + return idx; + }, [metaTypes]); // Below the mobile breakpoint the Objects rail overlays the canvas instead // of a permanent 208px column (which otherwise squeezed the grid/form // canvas down to almost nothing on phones) — closed by default, toggled by @@ -7821,6 +7829,7 @@ export function DataPillar({ disabled={readOnly} focus={actionFocus} actionSchema={typeSchemas.action} + actionForm={typeForms.action} onCelVerdictsChange={reportPanelVerdicts} // objectstack#30088 — a base object's new actions are items of the pair. pair={pairDoor}