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/36511-studio-save-cancel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(studio): the object page saves with Cancel and Save in the top bar, and a Save is live at once

Clause-②: no
Metadata-protocol: none

Studio's object page (fields, validation rules, actions, settings and field groups) no longer autosaves a draft 1.5 s after each edit. Edits stay on the page until the author presses Save, which sits at the right of the Studio top bar where Publish was; Cancel beside it puts the page back as the server holds it. Save writes the object's draft and then publishes that one object at the package it was written to, so the change is live at once. An installed app's object takes its edits into the paired `.custom` package and publishes them there.

Changes and Publish are drawn only while drafts are pending (a copilot's, or another editor's), and a publish waits while the page holds edits Save has not sent. A Save refused by the server keeps the edits on the page with the reason, and its toast names each refused item with its reason and lists the items that were saved. Removing or retyping a published field asks first. Save waits out the expression checks of the last keystroke, so a formula or rule guard that does not parse is never sent. Leaving the page, or opening another object, with unsaved edits asks, as every departure does.

Other Studio editors (flows, hooks, list and form views, navigation, permissions) keep their draft autosave for now.
41 changes: 34 additions & 7 deletions ui/e2e/live/studio-customize-journey.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test as base, expect, type APIRequestContext, type Page, type Response } from '@playwright/test';
import { test as base, expect, type APIRequestContext, type Page, type Request, type Response } from '@playwright/test';

/**
* Live e2e for the ADR-0146 customization journey, walked through the Studio
Expand All @@ -12,9 +12,10 @@ import { test as base, expect, type APIRequestContext, type Page, type Response
* type's list) — not what the canvas draws.
* 2. Restore package original: the pair's draft and row are deleted at the
* pair, and the three reads serve the shipped column set again.
* 3. Add `region__c`: Add field on the base object's Form writes an
* `object_extension` into the pair; once published, the base object is
* served with the field and the pair's own read and export carry it.
* 3. Add `region__c`: Add field on the base object's Form, then the top
* bar's Save (objectstack#36511), writes an `object_extension` into the
* pair and publishes that one item there, so the base object is served
* with the field at once and the pair's own read and export carry it.
* 4. Uninstall the base: the uninstall door refuses the read-only showcase
* with 422 `WRITABLE_PACKAGE_REQUIRED` and removes nothing. This is the
* refusal `main` answers here, and the one asserted: `DELETE
Expand Down Expand Up @@ -230,19 +231,45 @@ test('a read-only base is customized, restored and extended through Studio, and
await page.getByTestId('add-field-label-input').fill(FIELD.label);
await expect(page.getByTestId('add-field-api-name-preview')).toContainText(FIELD.name);

// objectstack#36511 — the add stays on the page until the top bar's
// Save: no write of the extension leaves before it is pressed.
const extensionWrites: string[] = [];
const onRequest = (r: Request) => {
if (r.method() !== 'GET' && r.url().includes(`/api/v1/meta/object_extension/${OBJECT}`)) {
extensionWrites.push(`${r.method()} ${r.url()}`);
}
};
page.on('request', onRequest);
await page.getByTestId('add-field-create').click();
await expect(page.getByTestId('studio-save')).toBeVisible();
expect(extensionWrites).toEqual([]);

// Save writes the extension's draft into the pair, then publishes that
// one item there: live at once, with no package publish.
const drafted = page.waitForResponse(
(r) => r.request().method() === 'PUT' && r.url().includes(`/api/v1/meta/object_extension/${OBJECT}?`),
);
await page.getByTestId('add-field-create').click();
const published = page.waitForResponse(
(r) => r.request().method() === 'POST' && r.url().includes(`/api/v1/meta/object_extension/${OBJECT}/publish`),
);
await page.getByTestId('studio-save').click();
const draft = await drafted;
expect(draft.ok(), await draft.text()).toBeTruthy();
expect(new URL(draft.url()).searchParams.get('package')).toBe(PAIR);
expect(new URL(draft.url()).searchParams.get('mode')).toBe('draft');
expect(draft.request().postDataJSON()).toEqual({
extend: OBJECT,
fields: { [FIELD.name]: { type: 'text', label: FIELD.label } },
});

await publishPair(page);
const publish = await published;
expect(publish.ok(), await publish.text()).toBeTruthy();
expect(new URL(publish.url()).searchParams.get('package')).toBe(PAIR);
// The Save left nothing to save, and no draft for the package publish.
await expect(page.getByTestId('studio-save')).toHaveCount(0);
page.off('request', onRequest);
expect(extensionWrites.map((w) => w.split(' ')[0])).toEqual(['PUT', 'POST']);
const pending = await request.get(`${API}/api/v1/meta/object_extension/${OBJECT}?state=draft&package=${PAIR}`);
expect(pending.status(), await pending.text()).toBe(404);
const object = await request.get(`${API}/api/v1/meta/object/${OBJECT}`);
expect(object.ok(), await object.text()).toBeTruthy();
const objectBody = await object.json();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import { useServerHoldAt, type ServerDiagnosticEntry } from './draftVerdict.js';
// fields as lists (`celAuthoring.ts` stays free of any import at load).
import { multiValueFieldsOf, type CelFieldDef } from './clientValidation.js';

const LINT_DEBOUNCE_MS = 250;
import { LINT_DEBOUNCE_MS } from './celLintDebounce.js';

const KIND_TAG: Record<CelSuggestionKind, string> = {
field: 'field',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/** The CEL editors lint this long after the last keystroke; Studio's Save waits it out (objectstack#36511). */
export const LINT_DEBOUNCE_MS = 250;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import '@testing-library/jest-dom/vitest';
import * as React from 'react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { render, screen, fireEvent, cleanup, act, waitFor, within } from '@testing-library/react';
import { render, screen, fireEvent, cleanup, waitFor, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { MetadataClient } from '@object-ui/data-objectstack';
import { ActionSchema } from '@objectstack/spec/ui';
Expand Down Expand Up @@ -63,6 +63,8 @@ function serverIssues(body: Record<string, unknown>): Array<{ path: string; mess
}

const fetchImpl = vi.fn(async (_url: string, init?: RequestInit) => {
// objectstack#36511 — the Save's own publish of the item, and a refused one's discard.
if (init?.method === 'POST' || init?.method === 'DELETE') return new Response('{"success":true}', { status: 200 });
if (init?.method === 'PUT') {
const body = JSON.parse(String(init.body)) as Record<string, unknown>;
puts.push(body);
Expand Down Expand Up @@ -128,7 +130,10 @@ vi.mock('@object-ui/react', async (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, pressStudioSave } from './__tests__/studioSaveHarness';
import { createEmptyDataSource } from './__tests__/emptyDataSource';
import { registerBuiltinInspectors } from '../metadata-admin/inspectors';
import { t, tFormat } from '../metadata-admin/i18n';
Expand All @@ -144,19 +149,12 @@ afterEach(() => {

const L = (key: string) => t(key, 'en');

/** Past the autosave's 1.5 s debounce. */
async function outlastDebounce(): Promise<void> {
await act(async () => {
await new Promise((r) => setTimeout(r, 2300));
});
}

async function mountOnView(def: Record<string, unknown>, tabKey: string): Promise<void> {
objectDef = def;
render(
<MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
<StudioSaveHarness><MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
<DataPillar packageId="com.example.showcase" />
</MemoryRouter>,
</MemoryRouter></StudioSaveHarness>,
);
// The first match is the flat tab (the passthrough menu draws a second).
fireEvent.click((await screen.findAllByRole('button', { name: L(tabKey) }))[0]);
Expand All @@ -179,7 +177,7 @@ describe('Studio data page — a refused action save is shown at the action, and
// Any edit: the label of the first action, which the list selects.
const labelInput = (await screen.findByText(L('engine.inspector.action.label'), { selector: 'label' })).parentElement!.querySelector('input')!;
fireEvent.change(labelInput, { target: { value: 'Archive now' } });
await outlastDebounce();
await pressStudioSave();
expect(puts).toHaveLength(1);

// The refusal names the action, not "the server refused this draft".
Expand All @@ -198,7 +196,7 @@ describe('Studio data page — a refused action save is shown at the action, and
// and clear the flat key; the next autosave is accepted, the strip goes.
fireEvent.click(expose);
fireEvent.click(expose);
await outlastDebounce();
await pressStudioSave();
expect(puts).toHaveLength(2);
expect(lastSentAction('showcase_task_send')).not.toHaveProperty('aiExposed');
expect(serverIssues(puts[1])).toEqual([]);
Expand All @@ -211,11 +209,11 @@ describe('Studio data page — a Type switch is held until its input is filled (
await mountOnView({ name: 'showcase_task', label: 'Task', fields: [{ name: 'title', label: 'Title', type: 'text' }], actions: [SEND] }, 'engine.studio.data.tab.actions');

await pick(L('engine.inspector.action.type'), L('engine.inspector.action.type.api'));
await outlastDebounce();
await pressStudioSave();
expect(puts, 'an api action with no endpoint is held, not sent').toEqual([]);
expect(screen.queryByTestId('studio-refusal')).toBeNull();
expect(within(await screen.findByTestId('studio-held')).getByTestId('studio-held-message')).toHaveTextContent(
tFormat('engine.studio.held.line', 'en', {
tFormat('engine.studio.held.lineExplicit', 'en', {
clause: tFormat('engine.studio.held.actionNeedsInput', 'en', {
input: L('engine.inspector.action.target.api.label'),
action: 'Send',
Expand All @@ -225,7 +223,7 @@ describe('Studio data page — a Type switch is held until its input is filled (

const endpoint = screen.getByText(`${L('engine.inspector.action.target.api.label')} *`, { selector: 'label' }).parentElement!.querySelector('input')!;
fireEvent.change(endpoint, { target: { value: '/api/v1/send' } });
await outlastDebounce();
await pressStudioSave();
expect(puts).toHaveLength(1);
// The body the script had is gone with the switch, so the server accepts it.
expect(lastSentAction('showcase_task_send')).not.toHaveProperty('body');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const mockClient = {
listDrafts: vi.fn(async () => []),
layered: vi.fn(async () => ({ effective: servedObject, code: servedObject })),
getDraft: vi.fn(async () => null),
publish: vi.fn(async () => ({})), reset: vi.fn(async () => ({})),
save: vi.fn(async () => ({ ok: true })),
};

Expand Down Expand Up @@ -68,7 +69,10 @@ vi.mock('@object-ui/plugin-view', async (importOriginal) => {
return { ...mod, ObjectView: GridDouble };
});

// 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, pressStudioSave } from './__tests__/studioSaveHarness';
import { t } from '../metadata-admin/i18n';
import { readFields } from '../metadata-admin/previews/object-fields-io';
import { addFieldFromFormToolbar, addFieldFromGrid } from './__tests__/dataPillarAddField';
Expand Down Expand Up @@ -98,9 +102,9 @@ afterEach(() => {

async function renderPillar(props: { readOnly?: boolean } = {}) {
render(
<MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
<StudioSaveHarness><MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
<DataPillar packageId="com.example.showcase" readOnly={props.readOnly} />
</MemoryRouter>,
</MemoryRouter></StudioSaveHarness>,
);
await waitFor(() => expect(screen.getByTestId('records-panel')).toBeInTheDocument(), { timeout: 8000 });
}
Expand All @@ -115,6 +119,7 @@ const toolbarAddField = () => within(screen.getByTestId('form-toolbar')).getByRo

/** The fields of the latest object draft the pillar saved. */
async function savedFields(): Promise<Record<string, Record<string, unknown>>> {
await pressStudioSave();
await waitFor(() => expect(mockClient.save).toHaveBeenCalled(), { timeout: 8000 });
const calls = mockClient.save.mock.calls as unknown as Array<[string, string, Record<string, unknown>]>;
const body = calls[calls.length - 1][2];
Expand Down Expand Up @@ -205,11 +210,8 @@ describe('Data pillar — Add field asks for the label and type first (objectui#
expect(within(inspector).getByText('full_name')).toBeInTheDocument();
await addFieldFromFormToolbar(undefined, { label: 'ヘルススコア', apiName: 'health_score' });
await waitFor(() => expect(within(screen.getByTestId('data-field-inspector')).getByText('health_score')).toBeInTheDocument());
const fields = await waitFor(async () => {
const f = await savedFields();
expect(Object.keys(f)).toEqual(['name', 'full_name', 'health_score']);
return f;
}, { timeout: 8000 });
const fields = await savedFields();
expect(Object.keys(fields)).toEqual(['name', 'full_name', 'health_score']);
expect(fields.full_name).toMatchObject({ type: 'text', label: 'Name' });
expect(fields.health_score).toMatchObject({ type: 'text', label: 'ヘルススコア' });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import '@testing-library/jest-dom/vitest';
import * as React from 'react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { render, screen, fireEvent, cleanup, act, within } from '@testing-library/react';
import { render, screen, fireEvent, cleanup, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter } from 'react-router-dom';
import { MetadataClient } from '@object-ui/data-objectstack';
Expand All @@ -41,6 +41,8 @@ const objectDef = {
const puts: unknown[] = [];

const fetchImpl = vi.fn(async (_url: string, init?: RequestInit) => {
// objectstack#36511 — the Save's own publish of the item, and a refused one's discard.
if (init?.method === 'POST' || init?.method === 'DELETE') return new Response('{"success":true}', { status: 200 });
if (init?.method === 'PUT') {
puts.push(JSON.parse(String(init.body)));
return new Response(JSON.stringify({ success: true }), {
Expand Down Expand Up @@ -74,7 +76,10 @@ vi.mock('@object-ui/react', async (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, pressStudioSave } from './__tests__/studioSaveHarness';
import { addFieldFromFormToolbar } from './__tests__/dataPillarAddField';
import { createEmptyDataSource } from './__tests__/emptyDataSource';
import { registerBuiltinInspectors } from '../metadata-admin/inspectors';
Expand All @@ -98,9 +103,9 @@ function controlUnder(label: string): HTMLElement {
describe('Studio data page — a held Picklist reads as a sentence (objectui#11785, held since objectui#11786)', () => {
it('names the field by its label and shows no developer text', async () => {
render(
<MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
<StudioSaveHarness><MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
<DataPillar packageId="com.example.showcase" />
</MemoryRouter>,
</MemoryRouter></StudioSaveHarness>,
);
fireEvent.click(await screen.findByRole('button', { name: 'Form' }));
await addFieldFromFormToolbar();
Expand All @@ -112,17 +117,15 @@ describe('Studio data page — a held Picklist reads as a sentence (objectui#117
await userEvent.click(controlUnder('Type'));
await userEvent.click(await screen.findByRole('option', { name: /^Picklist$/ }));

// Past the autosave's 1.5 s debounce: the guard holds the save.
await act(async () => {
await new Promise((r) => setTimeout(r, 2300));
});
// Save pressed (objectstack#36511): the guard holds it.
await pressStudioSave();
expect(puts, 'the guard must hold this save').toEqual([]);

expect(screen.queryByTestId('studio-refusal'), 'held, not refused (objectui#11786)').toBeNull();
const held = await screen.findByTestId('studio-held');
const message = within(held).getByTestId('studio-held-message');
expect(message).toHaveTextContent(
tFormat('engine.studio.held.line', 'en', {
tFormat('engine.studio.held.lineExplicit', 'en', {
clause: tFormat('engine.studio.held.needsOptions', 'en', { field: label }),
}),
);
Expand All @@ -134,19 +137,17 @@ describe('Studio data page — a held Picklist reads as a sentence (objectui#117

it('"Show me" opens the named field\'s inspector after it was closed', async () => {
render(
<MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
<StudioSaveHarness><MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
<DataPillar packageId="com.example.showcase" />
</MemoryRouter>,
</MemoryRouter></StudioSaveHarness>,
);
fireEvent.click(await screen.findByRole('button', { name: 'Form' }));
await addFieldFromFormToolbar();
await screen.findByText('Type', { selector: 'label' }, { timeout: 4000 });
const apiName = (controlUnder('API name') as HTMLInputElement).value;
await userEvent.click(controlUnder('Type'));
await userEvent.click(await screen.findByRole('option', { name: /^Picklist$/ }));
await act(async () => {
await new Promise((r) => setTimeout(r, 2300));
});
await pressStudioSave();
const strip = await screen.findByTestId('studio-held');

// The rail's own header close (the field inspector inside carries another).
Expand Down
Loading
Loading