From 90ed3338c3f803591b8ce407701127507da8c799 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 22:03:26 +0000 Subject: [PATCH 1/4] feat(studio): design an object's public forms in Studio's Form tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Studio → Data → an object → Form switches between the record form and the object's public forms. The designer lists them (published and drafted), creates and deletes one, picks fillable fields only, reorders them, marks them required and groups them into named sections, and sets the title, description, after-submit message and address, with a live preview. A field the object requires cannot be removed, and an address another form uses is refused. Saves follow draft and publish; an installed app's form is saved as a declared override in its customization package. The designer's list, like Setup → Public forms, never shows On for a form its app ships switched off; an unknown row in Setup offers no switch; the withdrawal rule's docblock names its real callers, and the checklist item points at its new source. Claude-Session: https://claude.ai/code/session_01JQwxbWoxCrkYwcqxxENvmn Co-authored-by: Claude --- .../36444-studio-public-form-designer.md | 43 + .../areas/access-security.json | 4 +- packages/spec/src/ui/anonymous-form-intake.ts | 27 +- .../views/setup/PublicFormsSetupPage.test.tsx | 2 + .../src/views/setup/PublicFormsSetupPage.tsx | 2 +- .../app-shell/src/views/setup/publicForms.ts | 32 +- .../studio-design/StudioDesignSurface.tsx | 56 +- .../publicForm/PublicFormsDesigner.test.tsx | 332 +++++++ .../publicForm/PublicFormsDesigner.tsx | 850 ++++++++++++++++++ .../publicForm/publicFormDesign.test.ts | 261 ++++++ .../publicForm/publicFormDesign.ts | 452 ++++++++++ ui/packages/i18n/src/namespaces/studio/en.ts | 62 ++ ui/packages/i18n/src/namespaces/studio/zh.ts | 62 ++ 13 files changed, 2142 insertions(+), 43 deletions(-) create mode 100644 .changeset/36444-studio-public-form-designer.md create mode 100644 ui/packages/app-shell/src/views/studio-design/publicForm/PublicFormsDesigner.test.tsx create mode 100644 ui/packages/app-shell/src/views/studio-design/publicForm/PublicFormsDesigner.tsx create mode 100644 ui/packages/app-shell/src/views/studio-design/publicForm/publicFormDesign.test.ts create mode 100644 ui/packages/app-shell/src/views/studio-design/publicForm/publicFormDesign.ts diff --git a/.changeset/36444-studio-public-form-designer.md b/.changeset/36444-studio-public-form-designer.md new file mode 100644 index 00000000000..d7f206149c7 --- /dev/null +++ b/.changeset/36444-studio-public-form-designer.md @@ -0,0 +1,43 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +'@objectstack/spec': patch +--- + +feat(studio): design an object's public forms under the object, in Studio's Form tab + +Clause-②: yes (widening) — new Studio language-pack keys (`engine.studio.data.form.surface*` and the `engine.studio.publicForms.*` block) in en and zh +Metadata-protocol: none + +Studio → Data → an object → Form now switches between the **Record form** (the New and Edit dialogs' layout, as before) and the object's **Public forms**, the forms anyone can fill in without signing in, each submission a record of the object. No new tab: the Data pillar keeps its seven. + +The designer lists the object's public forms (published ones, and ones only drafted) and: + +- creates one (a title and an address; it starts with the fields the object requires) and deletes one; +- picks its fields from the object's fillable ones only: never a hidden, read-only, system, formula, roll-up or auto-number field; +- reorders fields by dragging (or the move buttons), marks them required, and groups them into named sections; +- sets the title, the description, the after-submit heading and message (`submitBehavior: { kind: 'thank-you' }`) and the address; +- shows the form live as it is edited. + +Two refusals, each with its reason on screen: + +- **A field the object requires** cannot be removed and is always required on the form. "Requires" means required with no default value and no default choice: a field the write path fills in, such as a status with `defaultValue`, is not held. +- **An address another form already uses** is refused, switched-off forms included, and nothing is saved. + +Saves follow Studio's draft → publish path: Save draft writes the form's draft, and Publish puts it live. + +- A form of a writable package is saved in that package. +- On an installed app, a form the app ships is saved as a declared override in the app's customization package (ADR-0146), never in the app. A new form goes into the customization package. +- A form the app ships cannot be deleted; the designer says to switch it off in Setup → Public forms instead. + +Switching a form on or off stays Setup's. The stored shape is the form view item it always was (`viewKind: 'form'`, `config.sharing`); no key is added. Access restrictions (password, expiry, domains) are not offered. + +Setup → Public forms names a form by the same rule: its label, else its title, else its first section's label, else its key. + +New locale keys: `engine.studio.data.form.surface*` and `engine.studio.publicForms.*` in the studio catalogue (en, zh). + +Alongside, from the review of the Setup page (#36697): + +- The designer's list reads an installed app's forms the way Setup → Public forms does: a form its app ships switched off (withdrawn by the app's own document, which no customization re-opens) is listed as "Off (its app ships it off)", never On, and a form whose app document cannot be read as "Unknown". +- On Setup → Public forms, a row whose status is unknown offers no switch; Refresh reads it again. +- `anonymousFormIntakeWithdrawnIn`'s docblock (`@objectstack/spec/ui`) names its callers as they are: the anonymous form doors, the v18 organization-ownership migration and the console's Setup → Public forms page. It no longer names an organization-scoped write door that does not call it. Prose only; the function is unchanged. diff --git a/docs/qa/platform-checklist/areas/access-security.json b/docs/qa/platform-checklist/areas/access-security.json index e897e686f43..eaa7458f561 100644 --- a/docs/qa/platform-checklist/areas/access-security.json +++ b/docs/qa/platform-checklist/areas/access-security.json @@ -1873,8 +1873,8 @@ "ref": "packages/qa/dogfood/test/showcase-public-form-withdrawal-layers.dogfood.test.ts ('showcase: a public form withdrawal at any metadata layer holds', 4 cases on a showcase boot with an organization active: the precondition, acceptance[0] and negative[1] through the save — 200, a message naming the env-wide scope and never the active organization's id, both doors 404 FORM_NOT_FOUND, 0 landed rows — then the no-organization read: set-active null, GET /meta/view/showcase_inquiry.contact serves config.sharing.allowAnonymous false with the link kept, set-active the organization again; and acceptance[1], both doors open with the row landing in the organization) + packages/rest/src/public-form-withdrawal.test.ts (the doors: '[#21331] public form withdrawal reaches every intake door', including '[ADR-0131 C7] no view read names an organization, whatever the tenancy answers: one environment read per door', and 'a public form withdrawal is a kill switch: one package's withdrawal of a view name closes its form') + packages/metadata-protocol/src/protocol.org-scoped-write-refused.test.ts ('[ADR-0131 D6] no organization-scoped metadata write is accepted', 'two packages shipping a view name' and 'each package's copy of a view container expands into its own package's slot', blocks (a) to (f)) + packages/metadata-core/src/anonymous-form-intake.test.ts (the anonymousFormIntakeWithdrawnIn cases). acceptance[0], acceptance[1], negative[0] and negative[1] score from the dogfood pin. acceptance[2] to acceptance[5] have no stock fixture (knownGaps); their pins are a unit (the rest file drives RestServer over a mocked protocol) and an in-process protocol over a stub registry (the metadata-protocol file), which is the layer their test oracle asks for. negative[2] is the dogfood pin's save at 200; negative[3] to negative[5] are procedural" }, "source": [ - "packages/metadata-core/src/anonymous-form-intake.ts#anonymousFormIntakeWithdrawnIn (the one judgement the doors make over the environment's list: a body of the same view name withdraws a candidate matched by slot or by slug; the package is not compared)", - "packages/metadata-core/src/anonymous-form-intake.ts#anonymousFormExplicitWithdrawals (explicit only: a sharing that keeps its publicLink and sets enabled or allowAnonymous to false; a schema-parsed artifact carries the default enabled false, which counts)", + "packages/spec/src/ui/anonymous-form-intake.ts#anonymousFormIntakeWithdrawnIn (the one judgement the doors make over the environment's list: a body of the same view name withdraws a candidate matched by slot or by slug; the package is not compared)", + "packages/spec/src/ui/anonymous-form-intake.ts#anonymousFormExplicitWithdrawals (explicit only: a sharing that keeps its publicLink and sets enabled or allowAnonymous to false; a schema-parsed artifact carries the default enabled false, which counts)", "packages/rest/src/form-routes.ts#registerFormEndpoints (resolveFormBySlug: the environment's view list alone, judged against itself as the layer beneath each candidate; the Default Organization's legacy read was deleted with ADR-0131 C7, and the tenancy service is still read for the posture; a withdrawn form answers 404 FORM_NOT_FOUND on both doors)", "packages/metadata-protocol/src/protocol.ts#getMetaItems (the environment's view list the doors read: one item per package that ships a view name, ADR-0048; a package-less copy stands in for every package with no copy of its own, packages/metadata-protocol/src/protocol.ts#servedViewExpansion)", "packages/metadata-protocol/src/protocol.ts#organizationScopedWriteRefusal (every organization-scoped write refused 403 NOT_OVERRIDABLE, ADR-0131 D6; PR #22515 deleted the intake-specific organization refusals and the row anchor revision 1 cited, and since PR #22447 the /meta doors hand the protocol no organization, so an organization-active administrator's save is environment-wide)", diff --git a/packages/spec/src/ui/anonymous-form-intake.ts b/packages/spec/src/ui/anonymous-form-intake.ts index 64898008b49..2fdb985a582 100644 --- a/packages/spec/src/ui/anonymous-form-intake.ts +++ b/packages/spec/src/ui/anonymous-form-intake.ts @@ -178,18 +178,22 @@ function anonymousFormExplicitWithdrawals(view: unknown): Array<{ slot: string; * Does one metadata layer withdraw an open form candidate? A WITHDRAWAL IS A * KILL SWITCH: layering may only narrow anonymous intake, never re-open it, so * the anonymous form doors serve a candidate only when no layer beneath it - * withdraws it, and the organization-scoped write door refuses a save that - * would leave one open. + * withdraws it. + * + * Three callers judge by it. The anonymous form doors (`registerFormEndpoints` + * in `@objectstack/rest`) pass the environment's view list as the layer. The + * v18 organization-ownership migration (`os migrate organization-ownership + * --apply`, `@objectstack/cli`) passes the organization rows it carries onto + * the environment. The console's Setup → Public forms page passes an installed + * app's own document, so it never shows on, or switches on, a form the app + * ships withdrawn (objectstack#36444). * * Identity is the `name`: the layer withdraws the candidate only through a - * body of the same `name` as the candidate's `view`. What that name is depends - * on the caller. The organization-scoped write door passes the env-wide body - * of the stored row the overlay is keyed by, so a key rename, a `form.name`, - * a slot move or an expansion rename is still judged against the form it was. - * The anonymous doors pass the env-wide view list and the item they serve, so - * they judge by the served item name (a known limit: an overlay stored before - * the withdrawal, or restored by rollback or revert, that moves its form to - * another key or slot is not matched there). The layer withdraws the + * body of the same `name` as the candidate's `view`. The anonymous doors pass + * the env-wide view list and the item they serve, so they judge by the served + * item name (a known limit: an overlay stored before the withdrawal, or + * restored by rollback or revert, that moves its form to another key or slot + * is not matched there). The layer withdraws the * candidate when its body of that name EXPLICITLY * withdraws a form ({@link anonymousFormExplicitWithdrawals}) that matches the * candidate by slot (the same `form`, `formViews` key or `config`) OR by slug @@ -205,8 +209,7 @@ function anonymousFormExplicitWithdrawals(view: unknown): Array<{ slot: string; * limit that fails closed: it may over-close another package's form of the * same name). It judges only the bodies the layer holds, so a caller closes a * name in every package only when its layer holds every package's body of the - * name. The organization-scoped write door anchors one body per package. The - * env-wide view list the anonymous doors read holds one item per package of a + * name. The env-wide view list the anonymous doors read holds one item per package of a * name: a package's saved env-wide copy of a view container serves that * package's item of each form it expands, and a package-less copy stands in * for every package with no copy of its own. A layer diff --git a/ui/packages/app-shell/src/views/setup/PublicFormsSetupPage.test.tsx b/ui/packages/app-shell/src/views/setup/PublicFormsSetupPage.test.tsx index e6bcc341241..8290cd3e355 100644 --- a/ui/packages/app-shell/src/views/setup/PublicFormsSetupPage.test.tsx +++ b/ui/packages/app-shell/src/views/setup/PublicFormsSetupPage.test.tsx @@ -170,6 +170,8 @@ describe('PublicFormsSetupPage', () => { await waitFor(() => expect(row).toHaveAttribute('data-unknown', 'true')); expect(row).toHaveAttribute('data-on', 'false'); expect(screen.getByTestId('public-form-unknown-web_to_lead')).toHaveTextContent('«publicFormsSetup.statusUnknown»'); + // Not knowing whether it is live, the page offers no switch: Refresh reads it again. + expect(screen.getByTestId('public-form-switch-web_to_lead')).toBeDisabled(); }); it('a switch over a pending draft says so and does not read as done', async () => { diff --git a/ui/packages/app-shell/src/views/setup/PublicFormsSetupPage.tsx b/ui/packages/app-shell/src/views/setup/PublicFormsSetupPage.tsx index 169a0eda27c..08dd38fd551 100644 --- a/ui/packages/app-shell/src/views/setup/PublicFormsSetupPage.tsx +++ b/ui/packages/app-shell/src/views/setup/PublicFormsSetupPage.tsx @@ -277,7 +277,7 @@ function PublicFormsSetupBody() {
void flip(row, next)} aria-label={t(row.on ? 'publicFormsSetup.switchOffLabel' : 'publicFormsSetup.switchOnLabel', { name: row.title, diff --git a/ui/packages/app-shell/src/views/setup/publicForms.ts b/ui/packages/app-shell/src/views/setup/publicForms.ts index a2052ff28f7..c8e1ea1e7be 100644 --- a/ui/packages/app-shell/src/views/setup/publicForms.ts +++ b/ui/packages/app-shell/src/views/setup/publicForms.ts @@ -77,6 +77,7 @@ import { } from '../runtime-metadata-persistence.js'; import { declaredOverrideOf, overrideDraftBody } from '../studio-design/StudioCustomizeControls.js'; import { fetchListedPackageManifests } from '../studio-design/packages-io.js'; +import { publicFormShownName } from '../studio-design/publicForm/publicFormDesign.js'; type FormDoc = Record; @@ -86,7 +87,7 @@ const isDoc = (v: unknown): v is FormDoc => !!v && typeof v === 'object' && !Arr export interface PublicFormRow { /** The form view item's name: the metadata address every write names. */ name: string; - /** What the page shows as its name ({@link shownName}). */ + /** What the page shows as its name (`publicFormShownName`, Studio's designer names it the same way). */ title: string; /** The object a submission creates a record of. */ object?: string; @@ -114,27 +115,6 @@ function withSwitch(form: FormDoc, on: boolean): FormDoc { return { ...form, sharing: { ...(isDoc(form.sharing) ? form.sharing : {}), enabled: on } }; } -const text = (v: unknown): string | undefined => (typeof v === 'string' && v.trim() ? v : undefined); - -/** - * The name a form is shown by, in the words its author gave it: the served - * (translated) label, else the form's title or label, else the label of its - * first section (what the form's own page heads it with), else its name - * without the object prefix (`crm_lead.web_to_lead` → `web_to_lead`). - */ -function shownName(item: FormDoc): string { - const config: FormDoc = isDoc(item.config) ? item.config : {}; - const first = Array.isArray(config.sections) ? config.sections.find(isDoc) : undefined; - const dot = item.name.lastIndexOf('.'); - return ( - text(item.label) ?? - text(config.title) ?? - text(config.label) ?? - text(first?.label) ?? - (dot >= 0 && dot < item.name.length - 1 ? item.name.slice(dot + 1) : item.name) - ); -} - /** * The public form a served view item carries, or `null` (module header): a * `viewKind: 'form'` item whose `config` the rule opens once its switch is on. @@ -149,7 +129,7 @@ export function publicFormRowOf(item: unknown): PublicFormRow | null { const packageId = typeof item._packageId === 'string' && item._packageId ? item._packageId : null; return { name: item.name, - title: shownName(item), + title: publicFormShownName(item), object: anonymousFormObjectName(item, item.config), slug: listed.slug, on, @@ -280,11 +260,11 @@ async function readFormLayers(name: string, target: ResolvedTarget, client: Pick * app's form; a row whose layers cannot be read is marked `unknown` and is not * shown as on. */ -export async function markShippedOff( - rows: readonly PublicFormRow[], +export async function markShippedOff>( + rows: readonly R[], client: Pick, doors?: Pick, -): Promise { +): Promise { if (!rows.some((r) => r.packageId)) return [...rows]; const listPackages = doors?.listPackages ?? fetchListedPackageManifests; let listing: ReturnType | undefined; 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 9a0c91440ce..66e8485d8cf 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx @@ -16,7 +16,7 @@ import * as React from 'react'; import { createPortal } from 'react-dom'; -import { useParams, useNavigate, useSearchParams, useLocation, Link, Navigate } from 'react-router-dom'; +import { useParams, useNavigate, useSearchParams, useLocation, useHref, Link, Navigate } from 'react-router-dom'; import { useAdapter, SchemaRendererProvider, useMetadata } from '@object-ui/react'; import { leadWithNameField } from '@object-ui/core'; // The ONE draft-envelope reader (objectui#8181): unwrap AND strip the @@ -453,6 +453,7 @@ import { StudioGridAddFieldButton, StudioGridAddFieldProvider, type StudioGridAd import { useDraftAutoSave, type DraftSend } from './useDraftAutoSave.js'; import { FLOW_PRESETS, flowPresetTrigger, type FlowPreset } from './flowPresets.js'; import { FormToolbar, ObjectFormDesigner } from './ObjectFormDesigner.js'; +import { PublicFormsDesigner } from './publicForm/PublicFormsDesigner.js'; import { isStudioHiddenSystemField } from './studioHiddenSystemField.js'; import { ObjectGroupInspector } from './ObjectGroupInspector.js'; import { ObjectValidationsPanel } from './ObjectValidationsPanel.js'; @@ -5993,6 +5994,12 @@ export function DataPillar({ // Within the Form view: Layout (WYSIWYG drag/section designer) ⇄ Preview // (live form). const [formMode, setFormMode] = React.useState<'layout' | 'preview'>('layout'); + // objectstack#36444 — which of the object's forms the Form tab designs: the + // record form (the New / Edit dialogs' layout) or its public forms (forms + // anyone fills in without signing in), designed under the object they + // submit into, with no tab of their own (objectui#12450's seven tabs). + const [formSurface, setFormSurface] = React.useState<'record' | 'public'>('record'); + const publicFormRoute = useHref('/f'); // objectui#12515 — which definition Preview renders when the object has a // published version AND a pending change: the draft (the default) or the // published one. Without a published version only the draft exists. @@ -7347,6 +7354,33 @@ export function DataPillar({ 'h-6 rounded px-2.5 text-xs transition-colors', active ? 'bg-background font-medium text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground', ); + const formSurfaceControl = ( +
+ + +
+ ); const formModeControl = (
) : (
+ {formSurfaceControl} {formModeControl} {formLayoutSource}
@@ -8025,7 +8061,23 @@ export function DataPillar({ left of the Form tab's one toolbar row (the designer's in Layout, `FormToolbar` in Preview), and the caption that used to trail it is each item's title. */} - {formMode === 'layout' ? ( + {formSurface === 'public' ? ( + + ) : formMode === 'layout' ? ( <> ({ + ObjectForm: ({ schema }: { schema: { sections: Array<{ label?: string; fields: Array<{ field: string; required?: boolean }> }> } }) => ( +
+ {schema.sections.map((s, i) => ( +
+ {s.label &&

{s.label}

} + {s.fields.map((f) => ( + + {f.field} + + ))} +
+ ))} +
+ ), +})); +vi.mock('../../../assistant/assistantBus.js', () => ({ emitMetadataRefresh: vi.fn() })); +vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } })); +// The package list the designer's list reads once (`markShippedOff`): the CRM app installed read-only, a writable own package. +vi.mock('../packages-io.js', async (importOriginal) => ({ + ...(await importOriginal>()), + fetchListedPackageManifests: async () => + new Map([ + ['com.example.crm', { writable: false, manifest: { id: 'com.example.crm', version: '4.0.0' } }], + ['com.acme.sales', { writable: true, manifest: { id: 'com.acme.sales', version: '1.0.0' } }], + ]), +})); + +import { PublicFormsDesigner } from './PublicFormsDesigner'; + +afterEach(cleanup); + +const BASE = 'com.example.crm'; +const PAIR = 'com.example.crm.custom'; + +const lead = { + name: 'crm_lead', + fields: { + name: { type: 'text', label: 'Lead Name', required: true }, + company: { type: 'text', label: 'Company' }, + email: { type: 'email', label: 'Email', required: true }, + phone: { type: 'phone', label: 'Phone' }, + title: { type: 'text', label: 'Title' }, + score: { type: 'formula', label: 'Score' }, + }, +}; + +const contactUs = () => ({ + name: 'crm_lead.web_to_lead', + object: 'crm_lead', + viewKind: 'form', + config: { + type: 'simple', + data: { provider: 'object', object: 'crm_lead' }, + sections: [ + { + name: 'contact_us', + label: 'Contact us', + columns: 1, + fields: [{ field: 'name', required: true }, { field: 'company' }, { field: 'email', required: true }, { field: 'phone' }, { field: 'title' }], + }, + ], + sharing: { enabled: true, publicLink: '/forms/contact-us', allowAnonymous: true }, + }, +}); + +const drafted = { + name: 'crm_lead.event_rsvp', + object: 'crm_lead', + viewKind: 'form', + label: 'Event RSVP', + config: { + data: { provider: 'object', object: 'crm_lead' }, + sections: [{ name: 'main', fields: [{ field: 'name', required: true }, { field: 'email', required: true }] }], + sharing: { enabled: true, publicLink: '/forms/event-rsvp', allowAnonymous: true }, + }, +}; + +function clientDouble(opts: { owner?: string; appDoc?: Record } = {}) { + const owner = opts.owner ?? BASE; + const appDoc = opts.appDoc ?? contactUs(); + return { + list: vi.fn(async () => [ + { ...contactUs(), _packageId: owner }, + { name: 'crm_lead.form', object: 'crm_lead', viewKind: 'form', config: { sections: [] }, _packageId: owner }, + { name: 'crm_lead.all', object: 'crm_lead', viewKind: 'list', config: {}, _packageId: owner }, + { ...contactUs(), name: 'crm_account.signup', object: 'crm_account', config: { ...contactUs().config, data: { provider: 'object', object: 'crm_account' }, sharing: { enabled: false, allowAnonymous: true, publicLink: '/forms/signup' } }, _packageId: owner }, + ]), + listDrafts: vi.fn(async () => [{ type: 'view', name: 'crm_lead.event_rsvp', packageId: owner }]), + getDraft: vi.fn(async () => drafted), + layered: vi.fn(async (_t: string, name: string) => + name === 'crm_lead.web_to_lead' ? { code: appDoc, effective: { ...contactUs(), _packageId: owner }, draft: null } : { code: null, effective: null, draft: drafted }, + ), + save: vi.fn(async () => ({})), + publish: vi.fn(async () => ({})), + reset: vi.fn(async () => ({})), + }; +} + +const customization = () => ({ + base: BASE, + baseLabel: 'CRM', + basedOn: '4.0.0', + walled: false, + pairId: null, + ensure: vi.fn(async () => PAIR), + ensurePackage: vi.fn(), + marks: { state: 'loaded' } as never, +}); + +function renderDesigner(client: ReturnType, extra: Partial> = {}) { + const onDraftSaved = vi.fn(); + render( + Form surface} + formRoute="/f" + {...extra} + />, + ); + return { onDraftSaved }; +} + +describe('Studio public form designer (objectstack#36444)', () => { + it('lists the object\'s public forms: published ones and ones only drafted, not internal forms or another object\'s', async () => { + renderDesigner(clientDouble()); + const list = await screen.findByTestId('public-forms-list'); + await within(list).findByTestId('public-form-item-crm_lead.web_to_lead'); + expect(within(list).getByTestId('public-form-item-crm_lead.event_rsvp')).toHaveTextContent('Draft'); + expect(within(list).queryByTestId('public-form-item-crm_lead.form')).toBeNull(); + expect(within(list).queryByTestId('public-form-item-crm_account.signup')).toBeNull(); + }); + + it('lists a form its installed app ships switched off as off, even when this environment\'s customization switches it on', async () => { + const shippedOff = { ...contactUs(), config: { ...contactUs().config, sharing: { enabled: false, publicLink: '/forms/contact-us', allowAnonymous: true } } }; + renderDesigner(clientDouble({ appDoc: shippedOff })); + const row = await screen.findByTestId('public-form-item-crm_lead.web_to_lead'); + await waitFor(() => expect(row).toHaveTextContent('Off (its app ships it off)')); + expect(row).not.toHaveTextContent(/\bOn\b/); + }); + + it('edits an installed app\'s form as a customization: Phone required, Title removed, a new title; then publishes it there', async () => { + const user = userEvent.setup(); + const client = clientDouble(); + const custom = customization(); + const { onDraftSaved } = (() => { + const onDraftSaved = vi.fn(); + render( + , + ); + return { onDraftSaved }; + })(); + await user.click(await screen.findByTestId('public-form-item-crm_lead.web_to_lead')); + await screen.findByTestId('public-form-title'); + + await user.click(screen.getByTestId('public-form-required-phone')); + await user.click(screen.getByTestId('public-form-remove-title')); + const title = screen.getByTestId('public-form-title'); + await user.clear(title); + await user.type(title, 'Talk to sales'); + + // The live preview follows the edit. + expect(screen.getByTestId('public-form-preview-title')).toHaveTextContent('Talk to sales'); + expect(screen.getByTestId('preview-field-phone')).toHaveAttribute('data-required', 'true'); + expect(screen.queryByTestId('preview-field-title')).toBeNull(); + + await user.click(screen.getByTestId('public-form-save')); + await waitFor(() => expect(client.save).toHaveBeenCalledTimes(1)); + expect(custom.ensure).toHaveBeenCalled(); + const [type, name, body, options] = client.save.mock.calls[0] as unknown as [string, string, any, any]; + expect([type, name]).toEqual(['view', 'crm_lead.web_to_lead']); + expect(options).toMatchObject({ mode: 'draft', packageId: PAIR, surface: 'studio', ifNoneMatch: '*' }); + expect(body.overrides).toEqual({ package: BASE, basedOn: '4.0.0' }); + expect(body._packageId).toBeUndefined(); + expect(body.label).toBe('Talk to sales'); + expect(body.config.title).toBe('Talk to sales'); + expect(body.config.sections[0].fields).toEqual([ + { field: 'name', required: true }, + { field: 'company' }, + { field: 'email', required: true }, + { field: 'phone', required: true }, + ]); + expect(body.config.sharing).toEqual({ enabled: true, publicLink: '/forms/contact-us', allowAnonymous: true }); + expect(onDraftSaved).toHaveBeenCalledWith({ type: 'view', name: 'crm_lead.web_to_lead' }); + + await user.click(await screen.findByTestId('public-form-publish')); + await waitFor(() => expect(client.publish).toHaveBeenCalledWith('view', 'crm_lead.web_to_lead', { packageId: PAIR })); + // Nothing is ever written to the app's own package. + for (const call of [...client.save.mock.calls, ...client.publish.mock.calls] as unknown as unknown[][]) { + expect(JSON.stringify(call)).not.toContain(`"packageId":"${BASE}"`); + } + }); + + it('refuses to remove a field the object requires, and says why', async () => { + const user = userEvent.setup(); + renderDesigner(clientDouble()); + await user.click(await screen.findByTestId('public-form-item-crm_lead.web_to_lead')); + await user.click(await screen.findByTestId('public-form-remove-email')); + expect(screen.getByTestId('public-form-notice')).toHaveTextContent('“Email” cannot be removed: the object requires it'); + expect(screen.getByTestId('public-form-field-email')).toBeInTheDocument(); + // And it stays required: its box is checked and cannot be cleared. + expect(screen.getByTestId('public-form-required-email')).toBeChecked(); + expect(screen.getByTestId('public-form-required-email')).toBeDisabled(); + }); + + it('creates a new form with four fields, drafted where the object is edited', async () => { + const user = userEvent.setup(); + const client = clientDouble({ owner: 'com.acme.sales' }); + renderDesigner(client, { readOnly: false, customization: null, packageId: 'com.acme.sales' }); + await screen.findByTestId('public-form-item-crm_lead.web_to_lead'); + await user.click(screen.getByTestId('public-form-new')); + await user.type(screen.getByTestId('public-form-create-title'), 'Demo signup'); + expect(screen.getByTestId('public-form-create-address')).toHaveValue('demo-signup'); + await user.click(screen.getByTestId('public-form-create-confirm')); + + // Starts with the fields the object requires; two more are added. + expect(screen.getByTestId('public-form-field-name')).toBeInTheDocument(); + expect(screen.getByTestId('public-form-field-email')).toBeInTheDocument(); + await user.selectOptions(screen.getByTestId('public-form-add-field-main'), 'company'); + await user.selectOptions(screen.getByTestId('public-form-add-field-main'), 'phone'); + // A formula is never offered. + expect(within(screen.getByTestId('public-form-add-field-main')).queryByText('Score')).toBeNull(); + + await user.click(screen.getByTestId('public-form-save')); + await waitFor(() => expect(client.save).toHaveBeenCalledTimes(1)); + const [, name, body, options] = client.save.mock.calls[0] as unknown as [string, string, any, any]; + expect(name).toBe('crm_lead.demo_signup'); + expect(options).toMatchObject({ mode: 'draft', packageId: 'com.acme.sales', ifNoneMatch: '*' }); + expect(body).toMatchObject({ name: 'crm_lead.demo_signup', object: 'crm_lead', viewKind: 'form', label: 'Demo signup' }); + expect(body.config.sections[0].fields.map((f: { field: string }) => f.field)).toEqual(['name', 'email', 'company', 'phone']); + expect(body.config.sharing).toEqual({ enabled: true, allowAnonymous: true, publicLink: '/forms/demo-signup' }); + expect(body.overrides).toBeUndefined(); + }); + + it('refuses an address another form uses, switched off or not, and saves nothing', async () => { + const user = userEvent.setup(); + const client = clientDouble(); + renderDesigner(client); + await screen.findByTestId('public-form-item-crm_lead.web_to_lead'); + await user.click(screen.getByTestId('public-form-new')); + await user.type(screen.getByTestId('public-form-create-title'), 'Contact us'); + expect(screen.getByTestId('public-form-create-address-problem')).toHaveTextContent('Another form already uses this address'); + expect(screen.getByTestId('public-form-create-confirm')).toBeDisabled(); + // The address of a switched-off form of another object is taken too. + await user.clear(screen.getByTestId('public-form-create-address')); + await user.type(screen.getByTestId('public-form-create-address'), 'signup'); + expect(screen.getByTestId('public-form-create-confirm')).toBeDisabled(); + + // An existing form moved onto another's address cannot be saved. + await user.click(screen.getByTestId('public-form-item-crm_lead.web_to_lead')); + const address = await screen.findByTestId('public-form-address'); + await user.clear(address); + await user.type(address, 'event-rsvp'); + expect(screen.getByTestId('public-form-address-problem')).toHaveTextContent('crm_lead.event_rsvp'); + expect(screen.getByTestId('public-form-save')).toBeDisabled(); + expect(client.save).not.toHaveBeenCalled(); + }); + + it('groups fields into a named section', async () => { + const user = userEvent.setup(); + renderDesigner(clientDouble()); + await user.click(await screen.findByTestId('public-form-item-crm_lead.web_to_lead')); + await user.click(await screen.findByTestId('public-form-add-section')); + const sections = within(screen.getByTestId('public-form-sections')).getAllByTestId(/^public-form-section-label-/); + expect(sections).toHaveLength(2); + await user.clear(sections[1]); + await user.type(sections[1], 'About you'); + expect(screen.getAllByTestId('preview-section')).toHaveLength(2); + expect(screen.getByText('About you', { selector: 'h4' })).toBeInTheDocument(); + }); + + it('does not delete a form the app ships; deletes one of a writable package', async () => { + const user = userEvent.setup(); + renderDesigner(clientDouble()); + await user.click(await screen.findByTestId('public-form-item-crm_lead.web_to_lead')); + expect(await screen.findByTestId('public-form-delete-shipped')).toHaveTextContent('switch it off in Setup'); + cleanup(); + + const own = clientDouble({ owner: 'com.acme.sales' }); + renderDesigner(own, { readOnly: false, customization: null, packageId: 'com.acme.sales' }); + await user.click(await screen.findByTestId('public-form-item-crm_lead.web_to_lead')); + await user.click(await screen.findByTestId('public-form-delete')); + await user.click(screen.getByTestId('public-form-delete-yes')); + await waitFor(() => expect(own.reset).toHaveBeenCalledWith('view', 'crm_lead.web_to_lead', { packageId: 'com.acme.sales' })); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/publicForm/PublicFormsDesigner.tsx b/ui/packages/app-shell/src/views/studio-design/publicForm/PublicFormsDesigner.tsx new file mode 100644 index 00000000000..68d7dd8e7da --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/publicForm/PublicFormsDesigner.tsx @@ -0,0 +1,850 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * Studio → Data → an object → Form → Public forms (objectstack#36444): the + * designer of the object's public forms (forms anyone can fill in without + * signing in, each submission a record of the object). Create and delete a + * form; pick its fields (fillable ones only), drag them into order, mark them + * required and group them into named sections; set its title, description, + * after-submit message and address; see it live as it is edited. + * + * Saves go through Studio's draft → publish path: Save draft writes the + * form's draft where the open object is edited (its package, or on an + * installed app its customization package, as a declared override of a form + * the app ships), and Publish puts it live. Switching a form on or off is + * Setup's (Setup → Public forms), not the designer's. + * + * The rules (fillable fields, object-required fields, the address) are + * `publicFormDesign.ts`'s. + */ + +import * as React from 'react'; +import { toast } from 'sonner'; +import { ArrowDown, ArrowUp, GripVertical, Loader2, Plus, Trash2, X } from 'lucide-react'; +import type { MetadataClient } from '@object-ui/data-objectstack'; +import { ObjectForm } from '@object-ui/plugin-form'; +import { SchemaRendererProvider } from '@object-ui/react'; +import { emitMetadataRefresh } from '../../../assistant/assistantBus.js'; +import { t, tFormat } from '../../metadata-admin/i18n.js'; +import { declaredOverrideOf, overrideDraftBody } from '../StudioCustomizeControls.js'; +import { markShippedOff } from '../../setup/publicForms.js'; +import type { StudioBaseCustomization, StudioSavedDraft } from '../StudioPillarKit.js'; +import { + addressProblem, + fieldsOnForm, + fillableFields, + isPublicFormItem, + missingRequiredFields, + newPublicFormModel, + newPublicFormName, + previewSectionsOf, + publicFormItemOf, + publicFormModelOf, + publicFormObjectOf, + publicFormShownName, + removeFieldRefusal, + slugFromTitle, + takenAddresses, + withField, + withFieldMoved, + withoutField, + withoutSection, + withRequired, + withSection, + withSectionLabel, + withSectionMoved, + type PublicFormModel, +} from './publicFormDesign.js'; + +type FormDoc = Record; + +const isDoc = (v: unknown): v is FormDoc => !!v && typeof v === 'object' && !Array.isArray(v); + +/** One public form of the object, as the list shows it. */ +interface ListedForm { + name: string; + title: string; + slug: string; + /** Live (served) and taking submissions. */ + on: boolean; + /** Published at all (a form only drafted is not). */ + published: boolean; + /** The package that serves it, when published. */ + packageId: string | null; + /** Its installed app ships it switched off, so it stays closed whatever is published here (`markShippedOff`). */ + shippedOff?: boolean; + /** Its app's own document could not be read, so whether it is live is not known. */ + unknown?: boolean; +} + +/** The open form: what was read, and the buffer being edited. */ +interface OpenForm { + name: string; + /** The stored document the buffer started from (`null`: a new form). */ + base: FormDoc | null; + /** The package whose row serves the form, or `null` for a new or draft-only one. */ + owner: string | null; + /** A draft of it is pending where it is saved. */ + hasDraft: boolean; + /** Where its draft is read and written: a package id, or `null` before the ensure door names the pair. */ + at: string | null; + model: PublicFormModel; + dirty: boolean; +} + +export interface PublicFormsDesignerProps { + objectName: string; + /** The object's definition as Studio edits it (its fields). */ + objectDef: Record; + client: MetadataClient; + /** The package the open object is read and saved at. */ + packageId: string; + /** The open object's package is read-only (an installed app). */ + readOnly: boolean; + /** On a read-only base, its customization package. */ + customization: StudioBaseCustomization | null; + publishNonce: number; + onDraftSaved?: (saved?: StudioSavedDraft) => void; + locale: string; + /** The data source the live preview renders with (it never writes). */ + previewDataSource: unknown; + /** The Form tab's leading controls (the record form / public forms switch). */ + leading: React.ReactNode; + /** The address of the anonymous form route (`useHref('/f')`), for the address preview. */ + formRoute?: string; +} + +/** The address prefix shown before the slug. */ +function addressPrefix(formRoute: string | undefined): string { + const origin = typeof window !== 'undefined' ? window.location.origin : ''; + return `${origin}${formRoute ?? '/f'}/`; +} + +export function PublicFormsDesigner(props: PublicFormsDesignerProps): React.ReactElement { + const { objectName, objectDef, client, packageId, readOnly, customization, publishNonce, onDraftSaved, locale } = props; + const [listed, setListed] = React.useState(null); + const [taken, setTaken] = React.useState>(new Map()); + const [listError, setListError] = React.useState(null); + const [listNonce, setListNonce] = React.useState(0); + const [open, setOpen] = React.useState(null); + const [busy, setBusy] = React.useState(null); + const [notice, setNotice] = React.useState(null); + const [creating, setCreating] = React.useState<{ title: string; slug: string; slugTouched: boolean } | null>(null); + const [confirmDelete, setConfirmDelete] = React.useState(false); + const [dragging, setDragging] = React.useState(null); + + const canWrite = !readOnly || (customization !== null && !customization.walled); + const fields = React.useMemo(() => fillableFields(objectDef), [objectDef]); + const fieldLabel = React.useMemo(() => new Map(fields.map((f) => [f.name, f.label])), [fields]); + const requiredByObject = React.useMemo( + () => new Set(fields.filter((f) => f.objectRequired).map((f) => f.name)), + [fields], + ); + + // The object's public forms: the published list, plus the forms only drafted. + React.useEffect(() => { + let live = true; + setListError(null); + (async () => { + try { + const [published, drafts] = await Promise.all([ + client.list('view'), + client.listDrafts({ type: 'view' }).catch(() => []), + ]); + const items = (published ?? []).filter(isDoc); + const rows: ListedForm[] = []; + const seen = new Set(); + for (const item of items) { + if (!isPublicFormItem(item) || publicFormObjectOf(item) !== objectName) continue; + const model = publicFormModelOf(item); + seen.add(model.name); + rows.push({ + name: model.name, + title: publicFormShownName(item), + slug: model.slug, + on: model.enabled, + published: true, + packageId: typeof item._packageId === 'string' ? item._packageId : null, + }); + } + const draftItems: FormDoc[] = []; + for (const d of drafts ?? []) { + if (!d?.name || seen.has(d.name) || !d.name.startsWith(`${objectName}.`)) continue; + const body = await client.getDraft('view', d.name, d.packageId ? { packageId: d.packageId } : {}).catch(() => null); + const doc = isDoc(body) && isDoc((body as FormDoc).item) ? (body as FormDoc).item : body; + if (!isPublicFormItem(doc)) continue; + draftItems.push(doc); + const model = publicFormModelOf(doc); + rows.push({ name: model.name, title: publicFormShownName(doc), slug: model.slug, on: false, published: false, packageId: null }); + } + // A form its installed app ships switched off is never listed as on (Setup → Public forms reads it the same way). + const marked = await markShippedOff(rows, client as never); + if (!live) return; + marked.sort((a, b) => a.title.localeCompare(b.title)); + setListed(marked); + setTaken(takenAddresses([...items, ...draftItems])); + } catch (err) { + if (live) setListError(err instanceof Error ? err.message : String(err)); + } + })(); + return () => { + live = false; + }; + }, [client, objectName, listNonce, publishNonce]); + + /** Where an existing form's draft is read and saved. */ + const addressOf = React.useCallback( + (owner: string | null): string | null => { + if (!readOnly) return owner && owner !== packageId ? owner : packageId; + // An installed app: the customization package, once it exists. + return customization?.pairId ?? null; + }, + [readOnly, packageId, customization], + ); + + const openForm = React.useCallback( + async (row: ListedForm) => { + setNotice(null); + setCreating(null); + setConfirmDelete(false); + setBusy('load'); + try { + const at = addressOf(row.packageId); + let layers = await client.layered('view', row.name, at ? { packageId: at } : row.packageId ? { packageId: row.packageId } : {}); + if (!isDoc(layers.effective) && !isDoc(layers.code) && !isDoc((layers as FormDoc).draft) && row.packageId) { + layers = await client.layered('view', row.name, { packageId: row.packageId }); + } + const draft = isDoc((layers as FormDoc).draft) ? ((layers as FormDoc).draft as FormDoc) : null; + const stored = draft ?? (isDoc(layers.effective) ? layers.effective : isDoc(layers.code) ? layers.code : null); + if (!stored) throw new Error(tFormat('engine.studio.publicForms.unreadable', locale, { name: row.title })); + setOpen({ + name: row.name, + base: stored, + owner: row.packageId, + hasDraft: !!draft, + at, + model: publicFormModelOf({ ...stored, name: row.name }), + dirty: false, + }); + } catch (err) { + toast.error(err instanceof Error ? err.message : String(err)); + } finally { + setBusy(null); + } + }, + [client, addressOf, locale], + ); + + const edit = (next: PublicFormModel) => setOpen((o) => (o ? { ...o, model: next, dirty: true } : o)); + + const problem = open ? addressProblem(open.model.slug, open.model.name, taken) : null; + const missing = open ? missingRequiredFields(open.model, requiredByObject) : []; + const isNew = open !== null && open.base === null; + const shippedByApp = open !== null && readOnly && open.owner !== null && open.owner === customization?.base; + + /** Where a save lands, and the body it writes. */ + const writeTarget = async (model: PublicFormModel): Promise<{ packageId: string; body: FormDoc }> => { + const body = publicFormItemOf(model, open?.base ?? null); + if (!readOnly) return { packageId: open?.at ?? packageId, body }; + if (!customization || customization.walled) throw new Error(t('engine.studio.publicForms.readOnly', locale)); + const pair = await customization.ensure(); + if (!shippedByApp) return { packageId: pair, body }; + // A form the app ships is customized as a declared override, never edited in the app. + const declared = declaredOverrideOf(open?.base, customization.base) ? body : overrideDraftBody(body, customization.base, customization.basedOn); + if (!declared) throw new Error(t('engine.studio.publicForms.noVersion', locale)); + return { packageId: pair, body: declared }; + }; + + const save = async () => { + if (!open || problem || missing.length > 0) return; + setBusy('save'); + setNotice(null); + try { + const target = await writeTarget(open.model); + await client.save('view', open.model.name, target.body, { + mode: 'draft', + packageId: target.packageId, + surface: 'studio', + // A form nobody has drafted yet: a draft written meanwhile is never overwritten. + ...(open.hasDraft ? {} : { ifNoneMatch: '*' }), + } as never); + setOpen({ ...open, at: target.packageId, hasDraft: true, dirty: false, base: { ...(open.base ?? {}), ...target.body } }); + onDraftSaved?.({ type: 'view', name: open.model.name }); + toast.success(tFormat('engine.studio.publicForms.saved', locale, { name: open.model.title || open.model.name })); + setListNonce((n) => n + 1); + } catch (err) { + const status = (err as { status?: unknown })?.status; + setNotice(status === 409 ? t('engine.studio.publicForms.draftConflict', locale) : err instanceof Error ? err.message : String(err)); + } finally { + setBusy(null); + } + }; + + const publish = async () => { + if (!open?.hasDraft || open.dirty || !open.at) return; + setBusy('publish'); + setNotice(null); + try { + await client.publish('view', open.model.name, { packageId: open.at }); + toast.success(tFormat('engine.studio.publicForms.published', locale, { name: open.model.title || open.model.name })); + setOpen({ ...open, hasDraft: false, owner: open.owner ?? open.at }); + emitMetadataRefresh(); + setListNonce((n) => n + 1); + } catch (err) { + setNotice(err instanceof Error ? err.message : String(err)); + } finally { + setBusy(null); + } + }; + + const discard = async () => { + if (!open) return; + if (!open.hasDraft) { + // Nothing saved: the buffer goes back to what was read. + if (open.base) setOpen({ ...open, model: publicFormModelOf({ ...open.base, name: open.name }), dirty: false }); + else setOpen(null); + return; + } + if (!open.at) return; + setBusy('discard'); + try { + await client.reset('view', open.model.name, { state: 'draft', packageId: open.at }); + onDraftSaved?.(); + setListNonce((n) => n + 1); + const row = listed?.find((r) => r.name === open.model.name && r.published); + setOpen(null); + if (row) await openForm(row); + } catch (err) { + setNotice(err instanceof Error ? err.message : String(err)); + } finally { + setBusy(null); + } + }; + + const remove = async () => { + if (!open || shippedByApp) return; + setBusy('delete'); + setNotice(null); + try { + const at = open.at ?? open.owner; + if (open.hasDraft && at) await client.reset('view', open.model.name, { state: 'draft', packageId: at }); + const row = listed?.find((r) => r.name === open.model.name && r.published); + if (row) await client.reset('view', open.model.name, { packageId: row.packageId ?? at ?? undefined }); + toast.success(tFormat('engine.studio.publicForms.deleted', locale, { name: open.model.title || open.model.name })); + onDraftSaved?.(); + emitMetadataRefresh(); + setOpen(null); + setConfirmDelete(false); + setListNonce((n) => n + 1); + } catch (err) { + setNotice(err instanceof Error ? err.message : String(err)); + } finally { + setBusy(null); + } + }; + + const startCreate = () => { + setOpen(null); + setNotice(null); + setConfirmDelete(false); + setCreating({ title: '', slug: '', slugTouched: false }); + }; + + const createProblem = creating ? addressProblem(creating.slug, newPublicFormName(objectName, creating.slug), taken) : null; + const nameTaken = + creating !== null && + !!creating.slug && + (listed ?? []).some((r) => r.name === newPublicFormName(objectName, creating.slug)); + + const create = () => { + if (!creating || !creating.title.trim() || createProblem || nameTaken) return; + const model = newPublicFormModel(objectName, creating.title.trim(), creating.slug, objectDef); + setCreating(null); + setOpen({ name: model.name, base: null, owner: null, hasDraft: false, at: readOnly ? null : packageId, model, dirty: true }); + }; + + /** Ask to remove a field: refused, with the reason, for one the object requires. */ + const askRemoveField = (field: string) => { + if (!open) return; + if (removeFieldRefusal(field, requiredByObject)) { + setNotice(tFormat('engine.studio.publicForms.requiredByObject', locale, { field: fieldLabel.get(field) ?? field })); + return; + } + setNotice(null); + edit(withoutField(open.model, field, requiredByObject)); + }; + + const prefix = addressPrefix(props.formRoute); + const problemText = (p: string | null) => + p === 'empty' + ? t('engine.studio.publicForms.addressEmpty', locale) + : p === 'shape' + ? t('engine.studio.publicForms.addressShape', locale) + : p === 'taken' + ? t('engine.studio.publicForms.addressTaken', locale) + : null; + + const input = + 'h-8 w-full rounded-md border border-input bg-background px-2 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60'; + const smallBtn = + 'inline-flex h-7 items-center gap-1 rounded-md px-2 text-xs font-medium hover:bg-muted disabled:pointer-events-none disabled:opacity-50'; + const primaryBtn = + 'inline-flex h-7 items-center gap-1.5 rounded-md bg-primary px-2.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50'; + + const editable = canWrite && !!open; + + return ( +
+ {/* The Form tab's one toolbar row. */} +
+ {props.leading} +
+ {open && ( + <> + {open.hasDraft && !open.dirty && ( + + {t('engine.studio.publicForms.draftChip', locale)} + + )} + {canWrite && ( + <> + + + + + )} + + )} +
+
+ +
+ {/* The object's public forms. */} + + + {/* The editor. */} +
+ {creating ? ( +
+

{t('engine.studio.publicForms.newTitle', locale)}

+ + +

{t('engine.studio.publicForms.newHint', locale)}

+
+ + +
+
+ ) : !open ? ( +
+ {busy === 'load' ? : t('engine.studio.publicForms.pick', locale)} +
+ ) : ( +
+ {!canWrite &&

{t('engine.studio.publicForms.readOnly', locale)}

} + {notice && ( +
+ {notice} + +
+ )} + {missing.length > 0 && ( +

+ {tFormat('engine.studio.publicForms.missingRequired', locale, { + fields: missing.map((f) => fieldLabel.get(f) ?? f).join(', '), + })} +

+ )} + +
+ +