Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/37087-console-reads-form-items.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
'@object-ui/console': patch
'@object-ui/i18n': patch
---

feat(console): the console reads and edits forms as `form` items (objectstack#37087, ADR-0159)

- **Setup → Public forms** lists and switches `form` items: the list is the `form` read, a switch saves the `form` item (its body with `sharing.enabled` set, without the `data` an old-shape form is served with), and "Restore package original" resets the `form` override. What the page shows is unchanged: every public form, on and off, its address and preview; a form its installed app ships switched off reads as off. A form whose app's own document cannot be read now offers no switch.
- **Studio's form editor**: the public form designer is the `form` type's editor (`EditPage` and `CreatePage`), with list columns for name, label, object, public address and status. It reads and writes the `form` item, whose body is at the top level, and has no switch: every save and publish writes `sharing.enabled` and `sharing.allowAnonymous` as they are stored at that moment, so a publish never opens a form Setup switched off. A form an installed app ships is saved as a declared override in the app's customization package. When the server refuses a save or publish because another form already uses the address, the editor says the address is taken, not that a draft is pending. The `form` type stays out of Studio's menu for now.
- **The console's own form page** (the signed-in one an action of type `form` opens) reads `GET /api/v1/meta/form/NAME`. The anonymous form route is unchanged.
- New `engine.studio.publicForms.*` and `engine.list.col.publicAddress` / `engine.list.col.publicState` strings in `./namespaces/studio` (en, zh).

Clause-②: yes
Metadata-protocol: none
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ const OBJECT_SCHEMA = {
},
};

const VIEW_ENVELOPE = {
const FORM_ITEM = {
name: 'showcase_task.intake',
object: 'showcase_task',
viewKind: 'form',
label: 'Task intake',
config: {
...{
type: 'simple',
sections: [{ label: 'Task', fields: ['title', 'freeform', 'agree', 'optin'] }],
},
Expand All @@ -89,7 +88,7 @@ async function renderForm() {
vi.stubGlobal(
'fetch',
stubFetch([
{ match: '/meta/view/', body: VIEW_ENVELOPE },
{ match: '/meta/form/', body: FORM_ITEM },
{ match: '/meta/object/', body: OBJECT_SCHEMA },
]),
);
Expand Down
5 changes: 2 additions & 3 deletions ui/apps/console/src/__tests__/internalFormShell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ import { App } from '../App';
const INTERNAL_VIEW = {
name: 'showcase_task.edit',
object: 'showcase_task',
viewKind: 'form',
label: 'Log Time',
config: { type: 'simple', sections: [{ fields: ['title'] }] },
...{ type: 'simple', sections: [{ fields: ['title'] }] },
};
const OBJECT_SCHEMA = { name: 'showcase_task', fields: { title: { type: 'text', label: 'Title' } } };
const PUBLIC_FORM = {
Expand All @@ -163,7 +162,7 @@ beforeEach(() => {
vi.stubGlobal(
'fetch',
vi.fn(async (url: string) => {
const body = String(url).includes('/meta/view/')
const body = String(url).includes('/meta/form/')
? INTERNAL_VIEW
: String(url).includes('/meta/object/')
? OBJECT_SCHEMA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ function withRules(rules: Record<string, Record<string, unknown>>) {
return { ...BASE_SCHEMA, fields };
}

/** Wrap sections in the `/meta/view/:name` envelope the internal route reads. */
function viewEnvelope(sections: unknown[]) {
/** Wrap sections in the `/meta/form/:name` item the internal route reads. */
function formItem(sections: unknown[]) {
return {
name: 'showcase_task.edit',
object: 'showcase_task',
viewKind: 'form',
label: 'Task',
config: { type: 'simple', sections },
...{ type: 'simple', sections },
};
}

Expand Down Expand Up @@ -134,7 +133,7 @@ function renderInternal(sections: unknown[], opts: RenderOpts = {}) {
vi.stubGlobal(
'fetch',
stubFetch([
{ match: '/meta/view/', body: viewEnvelope(sections) },
{ match: '/meta/form/', body: formItem(sections) },
{ match: '/meta/object/', body: opts.objectSchema ?? BASE_SCHEMA },
...(opts.extraRoutes ?? []),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ function stubInternal(refusal: { status: number; body: unknown }) {
const view = {
name: 'spare_parts.form',
object: 'spare_parts',
viewKind: 'form',
label: 'Spare part',
config: { type: 'simple', sections: [{ fields: ['name'] }] },
...{ type: 'simple', sections: [{ fields: ['name'] }] },
};
const object = { name: 'spare_parts', label: 'Spare part', fields: FIELDS };
vi.stubGlobal(
Expand All @@ -68,7 +67,7 @@ function stubInternal(refusal: { status: number; body: unknown }) {
posts += 1;
return answer(false, refusal.status, refusal.body);
}
if (String(url).includes('/meta/view/')) return answer(true, 200, view);
if (String(url).includes('/meta/form/')) return answer(true, 200, view);
if (String(url).includes('/meta/object/')) return answer(true, 200, object);
throw new Error(`unstubbed fetch: ${url}`);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ const OBJECT_SCHEMA = {
},
};

function viewEnvelope(fields: unknown[], columns: number) {
function formItem(fields: unknown[], columns: number) {
return {
name: 'showcase_task.intake',
object: 'showcase_task',
viewKind: 'form',
label: 'Task intake',
config: { type: 'simple', sections: [{ label: 'Task', columns, fields }] },
...{ type: 'simple', sections: [{ label: 'Task', columns, fields }] },
};
}

Expand All @@ -72,7 +71,7 @@ function renderForm(fields: unknown[], columns = 2) {
vi.stubGlobal(
'fetch',
stubFetch([
{ match: '/meta/view/', body: viewEnvelope(fields, columns) },
{ match: '/meta/form/', body: formItem(fields, columns) },
{ match: '/meta/object/', body: OBJECT_SCHEMA },
]),
);
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/console/src/components/FormPage.fieldSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* The measurement that chose the route: the console's copy was a strict subset
* — 9 of the shared type's 26 keys, every one of them identical, none of them
* console-only — sitting in a position that describes an **authored document**
* (`FormSectionSpec.fields`, read straight off `/meta/view/:name`), not a
* (`FormSectionSpec.fields`, read straight off `/meta/form/:name`), not a
* narrower thing this app authors. The narrow, renderer-honoured shape is a
* separate type that already exists here, `RenderableField`. So the two names
* were one contract, and the console's copy simply described it wrongly: legal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,24 @@ const OBJECT_SCHEMA = {
},
};

function viewBody(form: Record<string, unknown>) {
return {
name: 'showcase_inquiry.intake',
object: 'showcase_inquiry',
viewKind: 'form',
label: 'Intake',
config: { type: 'simple', sections: [{ fields: ['title', 'channel'] }], ...form },
};
function formBody(form: Record<string, unknown>) {
return { type: 'simple', sections: [{ fields: ['title', 'channel'] }], ...form };
}

/** The `form` item `/meta/form/:name` serves: identity and body at the top level. */
function formItem(form: Record<string, unknown>) {
return { name: 'showcase_inquiry.intake', object: 'showcase_inquiry', label: 'Intake', ...formBody(form) };
}

function stubFetch(form: Record<string, unknown>) {
return vi.fn(async (url: string) => {
const path = String(url);
const body = path.includes('/meta/view/')
? viewBody(form)
const body = path.includes('/meta/form/')
? formItem(form)
: path.includes('/meta/object/')
? OBJECT_SCHEMA
: path.includes('/forms/intake')
? { slug: 'intake', object: 'showcase_inquiry', form: viewBody(form).config, objectSchema: OBJECT_SCHEMA }
? { slug: 'intake', object: 'showcase_inquiry', form: formBody(form), objectSchema: OBJECT_SCHEMA }
: path.includes('/data/showcase_inquiry/r1')
? { record: { id: 'r1', title: 'Stored', channel: 'email' } }
: null;
Expand Down
22 changes: 10 additions & 12 deletions ui/apps/console/src/components/FormPage.inAppShell-13433.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ import { appRoutes } from '../AppContent';
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));

/** A container's default form: no view label, no form `title` — what Log Time opens. */
const UNLABELLED_VIEW = {
name: 'showcase_task.form',
object: 'showcase_task',
viewKind: 'form',
config: {
type: 'simple',
sections: [{ name: 'task', label: 'Task details', fields: ['title'] }],
},
const UNLABELLED_BODY = {
type: 'simple',
sections: [{ name: 'task', label: 'Task details', fields: ['title'] }],
};

/** A `form` item that names itself nowhere: no `label`, no `title`. */
const UNLABELLED_VIEW = { name: 'showcase_task.form', object: 'showcase_task', ...UNLABELLED_BODY };

const OBJECT_SCHEMA = {
name: 'showcase_task',
label: 'Task',
Expand All @@ -65,7 +63,7 @@ function stubFetch(view: unknown = UNLABELLED_VIEW) {
const method = (init?.method ?? 'GET').toUpperCase();
const u = String(url);
let body: unknown;
if (u.includes('/meta/view/')) body = view;
if (u.includes('/meta/form/')) body = view;
else if (u.includes('/meta/object/')) body = OBJECT_SCHEMA;
else if (method === 'GET' && u.includes('/data/showcase_task/task-42')) body = GET_RESPONSE;
else if (method === 'POST' && u.includes('/data/showcase_task')) body = POST_RESPONSE;
Expand Down Expand Up @@ -127,14 +125,14 @@ describe('the heading of an internal form (objectui#13433)', () => {
});

it('an authored form `title` heads the form', async () => {
vi.stubGlobal('fetch', stubFetch({ ...UNLABELLED_VIEW, config: { ...UNLABELLED_VIEW.config, title: 'Log time' } }));
vi.stubGlobal('fetch', stubFetch({ ...UNLABELLED_VIEW, title: 'Log time' }));
renderInternal({ url: '/forms/showcase_task.form' });

expect(await screen.findByRole('heading', { level: 1 })).toHaveTextContent(/^Log time$/);
});

it('control: the view’s own label still wins', async () => {
vi.stubGlobal('fetch', stubFetch({ ...UNLABELLED_VIEW, label: 'Quick edit', config: { ...UNLABELLED_VIEW.config, title: 'Log time' } }));
vi.stubGlobal('fetch', stubFetch({ ...UNLABELLED_VIEW, label: 'Quick edit', title: 'Log time' }));
renderInternal({ url: '/forms/showcase_task.form' });

expect(await screen.findByRole('heading', { level: 1 })).toHaveTextContent(/^Quick edit$/);
Expand Down Expand Up @@ -191,7 +189,7 @@ describe('Cancel on an internal form (objectui#13433)', () => {
ok: true,
status: 200,
statusText: 'OK',
json: async () => ({ object: 'showcase_task', form: UNLABELLED_VIEW.config, objectSchema: OBJECT_SCHEMA }),
json: async () => ({ object: 'showcase_task', form: UNLABELLED_BODY, objectSchema: OBJECT_SCHEMA }),
text: async () => '',
}) as unknown as Response),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ const FORM = {

const PUBLIC_PAYLOAD = { slug: 'support', object: API_NAME, form: FORM, objectSchema: CASE_SCHEMA };

const VIEW_ENVELOPE = {
const FORM_ITEM = {
name: 'support_case.intake',
object: API_NAME,
viewKind: 'form',
label: 'Support',
config: FORM,
...FORM,
};

// ─── Harness ──────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -136,7 +135,7 @@ function renderSurface(surface: Surface, lang: Lang) {
surface === 'public'
? [{ match: '/forms/support', body: PUBLIC_PAYLOAD }]
: [
{ match: '/meta/view/', body: VIEW_ENVELOPE },
{ match: '/meta/form/', body: FORM_ITEM },
{ match: '/meta/object/', body: CASE_SCHEMA },
// The signed-in visitor's bundle, answered empty: the authored copy
// is what renders.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
const VIEW = {
name: 'showcase_task.edit',
object: 'showcase_task',
viewKind: 'form',
label: 'Log Time',
config: { type: 'simple', sections: [{ fields: ['title', 'hours'] }] },
...{ type: 'simple', sections: [{ fields: ['title', 'hours'] }] },
};

const OBJECT = {
Expand Down Expand Up @@ -80,7 +79,7 @@ function openEdit(refusal: { status: number; body: unknown }) {
writes += 1;
return answer(true, 200, {});
}
if (String(url).includes('/meta/view/')) return answer(true, 200, VIEW);
if (String(url).includes('/meta/form/')) return answer(true, 200, VIEW);
if (String(url).includes('/meta/object/')) return answer(true, 200, OBJECT);
if (String(url).includes(`/data/showcase_task/${RECORD_ID}`)) {
return answer(false, refusal.status, refusal.body);
Expand Down
9 changes: 4 additions & 5 deletions ui/apps/console/src/components/FormPage.maxLength.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ const OBJECT_SCHEMA = {
},
};

/** Wrap a section's fields in the `/meta/view/:name` envelope this route reads. */
function viewEnvelope(fields: unknown[]) {
/** Wrap a section's fields in the `/meta/form/:name` item this route reads. */
function formItem(fields: unknown[]) {
return {
name: 'showcase_task.intake',
object: 'showcase_task',
viewKind: 'form',
label: 'Task intake',
config: { type: 'simple', sections: [{ label: 'Task', fields }] },
...{ type: 'simple', sections: [{ label: 'Task', fields }] },
};
}

Expand All @@ -96,7 +95,7 @@ function renderForm(fields: unknown[]) {
vi.stubGlobal(
'fetch',
stubFetch([
{ match: '/meta/view/', body: viewEnvelope(fields) },
{ match: '/meta/form/', body: formItem(fields) },
{ match: '/meta/object/', body: OBJECT_SCHEMA },
]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
/** Answers the `/meta/view` read with `status`; nothing else is reachable. */
function stubViewRead(status: number) {
return vi.fn(async (url: string) => {
if (!String(url).includes('/meta/view/no_such_form')) throw new Error(`unstubbed fetch: ${url}`);
if (!String(url).includes('/meta/form/no_such_form')) throw new Error(`unstubbed fetch: ${url}`);
const body = { error: { code: 'RESOURCE_NOT_FOUND', message: 'Metadata item not found or access denied.' } };
return {
ok: status >= 200 && status < 300,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ import { FormPage } from './FormPage';

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

const VIEW_ENVELOPE = {
const FORM_ITEM = {
name: 'showcase_task.form',
object: 'showcase_task',
viewKind: 'form',
label: 'Task',
config: {
...{
type: 'simple',
sections: [{ label: 'Task', fields: ['title', 'status', 'priority'] }],
},
Expand Down Expand Up @@ -106,7 +105,7 @@ function json(body: unknown): Response {
function stubServer(record: Record<string, unknown>) {
return vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input instanceof Request ? input.url : input);
if (url.includes('/meta/view/')) return json(VIEW_ENVELOPE);
if (url.includes('/meta/form/')) return json(FORM_ITEM);
if (url.includes('/meta/object/')) {
const lang = new Headers(init?.headers).get('Accept-Language');
seenLanguages.push(lang);
Expand Down
11 changes: 5 additions & 6 deletions ui/apps/console/src/components/FormPage.predicateScope.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,12 @@ function withRules(rules: Record<string, Record<string, unknown>>) {
return { ...BASE_SCHEMA, fields };
}

function viewEnvelope(sections: unknown[]) {
function formItem(sections: unknown[]) {
return {
name: 'showcase_task.edit',
object: 'showcase_task',
viewKind: 'form',
label: 'Task',
config: { type: 'simple', sections },
...{ type: 'simple', sections },
};
}

Expand Down Expand Up @@ -188,7 +187,7 @@ function renderInternalWithScope(
vi.stubGlobal(
'fetch',
stubFetch([
{ match: '/meta/view/', body: viewEnvelope(sections) },
{ match: '/meta/form/', body: formItem(sections) },
{ match: '/meta/object/', body: objectSchema },
]),
);
Expand Down Expand Up @@ -398,8 +397,8 @@ describe('#6110 hop 1 — `/forms/:name` publishes the SESSION principal', () =>
'fetch',
stubFetch([
{
match: '/meta/view/',
body: viewEnvelope([
match: '/meta/form/',
body: formItem([
{ label: 'Basics', fields: ['priority'] },
{ label: 'Compensation', visibleWhen: GATE, fields: ['notes'] },
]),
Expand Down
Loading
Loading