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/33865-package-create-toast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

fix(console): creating a package answers with a toast naming the new package

Clause-②: no
Metadata-protocol: none

Creating a package (Studio's *New app*, the Studio package switcher's *New package*, and the Packages page) closed the dialog and moved on with nothing on screen saying the write landed. The create dialog now shows a success toast naming the new package by its display name: "Created package “NAME”." (zh: 已创建软件包「NAME」。). A refused create shows no toast and keeps its message in the dialog, as before; saving an edit is unchanged.

New locale key: `engine.packages.create.created` in the studio catalogue (en, zh). No props or exports change.

Revoke on a granted suggested binding in Studio Access already answers with its toast ("“SET” is no longer granted by default."); a new pin on the Studio mount holds it.
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import * as React from 'react';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { PackageFormDialog } from './PackageFormDialog';
import { t } from './i18n';
import { toast } from 'sonner';
import { t, tFormat } from './i18n';
// The designer rows this suite reads in zh live in `@object-ui/i18n`'s `studio`
// namespace, whose `zh` catalogue is fetched on demand (objectstack#25922).
// Resident before any case, so the zh rows below read synchronously.
import { loadStudioCatalogue } from '@object-ui/i18n/namespaces/studio';
// The source under test reaches dynamic `import('@objectstack/formula')` and
// `import('@objectstack/lint')` (the spec form's CEL fields); pay those loads
// during collection, never inside a case's clocked window.
import '@objectstack/formula';
import '@objectstack/lint';
await loadStudioCatalogue('zh');

// Which console language the dialog renders in. Only `useMetadataLocale` is
Expand Down Expand Up @@ -199,3 +205,77 @@ describe('PackageFormDialog — capability refusal (objectstack#8270)', () => {
expect(screen.queryByText(t('engine.packages.noCapability', 'en-US'))).toBeNull();
});
});

/**
* objectstack#33865 (`ux-conventions.write-feedback`) — a package create is a
* write, and it answers with a toast naming the new package by its display
* name (label first). The dialog closes on success and every caller then
* navigates or re-lists, so without the toast nothing on screen says the
* write landed.
*
* Pinned:
* - a create the server accepts toasts the created sentence once, naming the
* package by its display name, not its id;
* - zh: the same toast in the zh sentence;
* - CONTROL: a refused create (409) toasts nothing and keeps its banner;
* - CONTROL: an edit save does not answer with the created sentence.
*/
describe('PackageFormDialog — a create answers with a toast naming the package (objectstack#33865)', () => {
let success: MockInstance<typeof toast.success>;
beforeEach(() => {
success = vi.spyOn(toast, 'success').mockImplementation(() => 'toast');
});
afterEach(() => success.mockRestore());

it('toasts the created sentence once, naming the package by its display name', async () => {
const onSaved = vi.fn();
render(<PackageFormDialog mode="create" open onOpenChange={vi.fn()} onSaved={onSaved} />);
await submitCreate();

await waitFor(() => expect(onSaved).toHaveBeenCalledTimes(1));
expect(success).toHaveBeenCalledTimes(1);
expect(success).toHaveBeenCalledWith(tFormat('engine.packages.create.created', 'en-US', { name: 'New App' }));
expect(success.mock.calls[0][0]).not.toContain('com.acme.new');
});

it('zh: the toast reads the zh sentence', async () => {
localeFixture = 'zh-CN';
const onSaved = vi.fn();
render(<PackageFormDialog mode="create" open onOpenChange={vi.fn()} onSaved={onSaved} />);
await submitCreate('zh-CN');

await waitFor(() => expect(onSaved).toHaveBeenCalledTimes(1));
const zh = tFormat('engine.packages.create.created', 'zh-CN', { name: 'New App' });
expect(zh).not.toBe(tFormat('engine.packages.create.created', 'en-US', { name: 'New App' }));
expect(success).toHaveBeenCalledWith(zh);
});

it('CONTROL: a refused create toasts nothing and keeps its banner', async () => {
stubRefusal(409, "Package 'com.acme.new' already exists");
const onSaved = vi.fn();
render(<PackageFormDialog mode="create" open onOpenChange={vi.fn()} onSaved={onSaved} />);
await submitCreate();

expect(await screen.findByText(t('engine.packages.create.exists', 'en-US'))).toBeInTheDocument();
expect(onSaved).not.toHaveBeenCalled();
expect(success).not.toHaveBeenCalled();
});

it('CONTROL: an edit save does not answer with the created sentence', async () => {
const onSaved = vi.fn();
render(
<PackageFormDialog
mode="edit"
open
onOpenChange={vi.fn()}
manifest={{ id: 'com.acme.new', name: 'New App', version: '0.1.0', type: 'app', namespace: 'new' }}
onSaved={onSaved}
/>,
);
fireEvent.click(await screen.findByTestId('package-form-submit'));

await waitFor(() => expect(onSaved).toHaveBeenCalledTimes(1));
expect(calls[0].init.method).toBe('PATCH');
expect(success).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import * as React from 'react';
import { AlertTriangle, ChevronDown } from 'lucide-react';
import { toast } from 'sonner';
import { ManifestSchema, deriveNamespaceFromPackageId } from '@objectstack/spec/kernel';
import { useAuth } from '@object-ui/auth';
import { NAMESPACE_RE, isSpecPackageId } from '../studio-design/packages-io.js';
Expand Down Expand Up @@ -610,6 +611,15 @@ export function PackageFormDialog({
});
const id = String((created?.manifest?.id as string) ?? manifestBody.id);
result = { id, mode, package: created };
// `ux-conventions.write-feedback`: the create answers with a toast
// naming the new package by its display name — the dialog closes
// and the caller may navigate away, so nothing else on screen says
// the write landed. A refusal stays in the dialog's banner below.
toast.success(
tFormat('engine.packages.create.created', locale, {
name: String((created?.manifest?.name as string) ?? manifestBody.name),
}),
);
} else {
const id = String((manifest?.id as string) ?? draft.id ?? '');
// The REST PATCH persists name / description / version / dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,66 @@ describe('objectstack#33864 — the suggested-bindings strip names its set by la
);
});
});

/**
* objectstack#33865 (`ux-conventions.write-feedback`) — Revoke on a granted
* suggestion is a write, and it answers with a toast naming the set, as Grant
* and Dismiss do. The Studio mount hands the strip its own `revokedToast`
* sentence; this reads it through the REAL pillar: Grant, then Revoke on the
* row the Grant left.
*
* Pinned:
* - Grant → Revoke: the Revoke answers with the revoked sentence naming the
* set by its label, after the Grant's own toast, and the row then reads
* dismissed with Reconsider;
* - CONTROL: a Revoke the server refuses answers with the server's message
* and never the revoked sentence — the toast follows the write, not the
* press.
*/
describe('objectstack#33865 — Revoke on a granted suggestion answers with a toast', () => {
const fmt = (key: string, set: string, anchor?: string) =>
tFormat(key, 'en', anchor === undefined ? { set } : { set, anchor });
const GRANTED = { ...PENDING, status: 'confirmed' as const, deployment_decision: true };

async function grant() {
api.list.mockResolvedValue([PENDING]);
api.confirm.mockResolvedValue({ suggestion: GRANTED, bindingCreated: true });
renderAccess(false);
const row = await screen.findByTestId('suggested-binding-crm_user', undefined, { timeout: 8000 });
await waitFor(() => expect(row).toHaveTextContent('CRM user'));
within(row).getByTestId('suggested-binding-confirm-crm_user').click();
await waitFor(() =>
expect(toast.success).toHaveBeenCalledWith(
fmt('engine.studio.access.suggestConfirmedToast', 'CRM user', 'everyone'),
),
);
return screen.findByTestId('suggested-binding-revoke-crm_user');
}

it('Grant then Revoke: the Revoke toasts the revoked sentence naming the set, and the row reads dismissed', async () => {
api.dismiss.mockResolvedValue({ ...GRANTED, status: 'dismissed' });
const revoke = await grant();
expect(toast.success).toHaveBeenCalledTimes(1);

revoke.click();
await waitFor(() =>
expect(toast.success).toHaveBeenLastCalledWith(fmt('engine.studio.access.suggestRevokedToast', 'CRM user')),
);
expect(toast.success).toHaveBeenCalledTimes(2);
expect(api.dismiss).toHaveBeenCalledWith('sug_1');
const row = screen.getByTestId('suggested-binding-crm_user');
await waitFor(() => expect(row).toHaveAttribute('data-state', 'dismissed'));
expect(row).toHaveTextContent(fmt('engine.studio.access.suggestDismissedState', 'CRM user'));
expect(within(row).getByTestId('suggested-binding-reopen-crm_user')).toBeInTheDocument();
});

it('CONTROL: a refused Revoke toasts the server message, never the revoked sentence', async () => {
api.dismiss.mockRejectedValue(refused(409, 'CONFLICT', 'the suggestion changed under you'));
const revoke = await grant();

revoke.click();
await waitFor(() => expect(toast.error).toHaveBeenCalledWith('the suggestion changed under you'));
expect(toast.success).toHaveBeenCalledTimes(1);
expect(toast.success).not.toHaveBeenCalledWith(fmt('engine.studio.access.suggestRevokedToast', 'CRM user'));
});
});
1 change: 1 addition & 0 deletions ui/packages/i18n/src/namespaces/studio/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,7 @@ const STUDIO_EN: Record<string, string> = {
'engine.packages.create.submit': 'Create package',
'engine.packages.create.failed': 'Failed to create package',
'engine.packages.create.exists': 'A package with this id already exists.',
'engine.packages.create.created': 'Created package “{name}”.',
// objectstack#8270 — the server refuses package writes without the ADR-0066
// `manage_metadata` capability, and its refusal is an English sentence that
// reached a zh console verbatim. Deployments that withhold the capability do
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/namespaces/studio/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,7 @@ const STUDIO_ZH: Record<string, string> = {
'engine.packages.create.submit': '创建软件包',
'engine.packages.create.failed': '创建软件包失败',
'engine.packages.create.exists': '已存在相同 ID 的软件包。',
'engine.packages.create.created': '已创建软件包「{name}」。',
// objectstack#8270 — 这条正是在 zh 控制台里显示为英文原文的服务端拒绝信息。
'engine.packages.noCapability': '你没有在本系统管理软件包的权限 — 该操作需要「管理元数据」权限。',
'engine.packages.form.basics': '基本信息',
Expand Down
Loading