Skip to content

Commit a8bb5ba

Browse files
committed
feat(app-shell): show the disable refusal for a dependent validation rule whole on the Setup packages page
A 409 PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE from the disable door is drawn under a heading in the reader's language with the server's whole sentence (package · object · rule and the remedy), no longer cut to its first sentence. The disable confirm dialog says such a rule can still refuse the disable, since the served disableable verdict does not read dependent rules. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwxPsNfCDtuhas4VDr
1 parent 8ae0ab9 commit a8bb5ba

4 files changed

Lines changed: 139 additions & 8 deletions

File tree

‎ui/packages/app-shell/src/views/metadata-admin/PackagesPage.moduleDisable-28118.test.tsx‎

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ vi.mock('@object-ui/auth', async (importOriginal) => ({
3636
import { PackageDetailSheet, PackagesPage, type InstalledPackageRow } from './PackagesPage';
3737
import { t } from './i18n';
3838
import { initRuntimeConfig, resetRuntimeConfigForTesting } from '../../runtime-config';
39+
import { loadStudioCatalogue } from '@object-ui/i18n/namespaces/studio';
40+
41+
// The zh catalogue of the designer strings is fetched on first use; loaded here
42+
// so a zh render answers in zh from its first paint.
43+
const ZH = await loadStudioCatalogue('zh');
3944

4045
const label = (key: string) => t(`engine.packages.detail.${key}`, 'en');
4146

@@ -72,15 +77,20 @@ const reply = (status: number, body: unknown) =>
7277

7378
let calls: { path: string; method: string }[];
7479

75-
/** Serve the drafts read, the lifecycle doors and (for the page) the list door. */
76-
function stubWire(packages: unknown[] = []) {
80+
/**
81+
* Serve the drafts read, the lifecycle doors and (for the page) the list door.
82+
* `answer` serves a door's own reply first (a refusal), when it returns one.
83+
*/
84+
function stubWire(packages: unknown[] = [], answer?: (path: string, method: string) => Response | undefined) {
7785
calls = [];
7886
vi.stubGlobal(
7987
'fetch',
8088
vi.fn(async (input: unknown, init?: { method?: string }) => {
8189
const path = new URL(String(input), 'http://console.test').pathname;
8290
const method = (init?.method ?? 'GET').toUpperCase();
8391
calls.push({ path, method });
92+
const own = answer?.(path, method);
93+
if (own) return own;
8494
if (path.startsWith('/api/v1/meta/_drafts')) return reply(200, { success: true, data: { drafts: [] } });
8595
if (path === '/api/v1/packages' && method === 'GET') return reply(200, { success: true, data: { packages } });
8696
if (path === '/api/v1/cloud-connection/installed') return reply(404, {});
@@ -103,11 +113,16 @@ const settle = () =>
103113
await new Promise((r) => setTimeout(r, 0));
104114
});
105115

106-
async function renderSheet(pkg: InstalledPackageRow) {
107-
render(
116+
async function renderSheet(pkg: InstalledPackageRow, language?: 'zh') {
117+
const sheet = (
108118
<MemoryRouter>
109119
<PackageDetailSheet pkg={pkg} open onOpenChange={() => {}} onChanged={() => {}} />
110-
</MemoryRouter>,
120+
</MemoryRouter>
121+
);
122+
render(
123+
language
124+
? <I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }}>{sheet}</I18nProvider>
125+
: sheet,
111126
);
112127
await screen.findByTestId('pkg-scope');
113128
await settle();
@@ -220,3 +235,75 @@ describe('Installed Apps view — a marketplace suite\'s module row (objectstack
220235
expect(screen.queryByRole('button', { name: label('disable') })).toBeNull();
221236
});
222237
});
238+
239+
describe('PackageDetailSheet — a disable the server refuses for a dependent validation rule (objectstack#31003)', () => {
240+
const CODE = 'PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE';
241+
// The disable door's own sentence, as it spells it: the rule as
242+
// package · object · rule, then the remedy.
243+
const LISTING = 'com.acme.suite.custom · account · credit_cap (reads credit_limit)';
244+
const REMEDY = 'Switch off or change that rule first, or keep the package enabled.';
245+
const SENTENCE =
246+
`Package '${MODULE_ID}' cannot be disabled: an active validation rule reads a field it adds through ` +
247+
`objectExtensions, which the disable would withhold — ${LISTING}. ${REMEDY}`;
248+
const refuseDisable = (status: number, code: string, message: string) => (path: string, method: string) =>
249+
method === 'PATCH' && path.endsWith('/disable')
250+
? reply(status, { success: false, error: { code, message } })
251+
: undefined;
252+
253+
async function confirmDisable() {
254+
fireEvent.click(screen.getByRole('button', { name: label('disable') }));
255+
const dialog = await screen.findByTestId('pkg-detail-disable-dialog');
256+
fireEvent.click(within(dialog).getByTestId('pkg-detail-disable-confirm'));
257+
await vi.waitFor(() => expect(lifecycleCalls()).toEqual(['disable']));
258+
await settle();
259+
}
260+
261+
it('the confirm dialog says a dependent validation rule can still refuse the disable', async () => {
262+
stubWire();
263+
await renderSheet(moduleRow());
264+
fireEvent.click(screen.getByRole('button', { name: label('disable') }));
265+
const dialog = await screen.findByTestId('pkg-detail-disable-dialog');
266+
expect(within(dialog).getByTestId('pkg-detail-disable-may-refuse')).toHaveTextContent(label('disableMayBeRefused'));
267+
expect(within(dialog).getByText(label('disableDescription'))).toBeInTheDocument();
268+
});
269+
270+
it.each([
271+
['en', undefined, label('disableRestricted')],
272+
['zh', 'zh' as const, ZH['engine.packages.detail.disableRestricted']],
273+
])('(%s) a 409 draws the heading in the reader\'s language and the server\'s whole sentence', async (_name, language, heading) => {
274+
expect(heading, 'the catalogue carries the heading').toBeTruthy();
275+
stubWire([], refuseDisable(409, CODE, SENTENCE));
276+
await renderSheet(moduleRow(), language);
277+
if (language) expect(heading).not.toBe(label('disableRestricted'));
278+
await confirmDisable();
279+
280+
expect(await screen.findByTestId('pkg-detail-refusal-heading')).toHaveTextContent(heading!);
281+
const text = screen.getByTestId('pkg-detail-refusal-text');
282+
// Whole, never cut to its first sentence: the rule listing and the remedy
283+
// are both on screen, with no "More" in front of either.
284+
expect(text).toHaveTextContent(LISTING);
285+
expect(text).toHaveTextContent(REMEDY);
286+
expect(text.textContent).toContain(SENTENCE);
287+
expect(screen.queryByTestId('refusal-more')).toBeNull();
288+
// Still on offer: the package was not switched off.
289+
expect(screen.getByRole('button', { name: language ? ZH['engine.packages.detail.disable'] : label('disable') })).toBeInTheDocument();
290+
});
291+
292+
it('CONTROL: another refusal code keeps the first-sentence drawing, with no heading', async () => {
293+
stubWire([], refuseDisable(403, 'WRITABLE_PACKAGE_REQUIRED', 'Package is read-only. Disable it from its owner.'));
294+
await renderSheet(moduleRow());
295+
await confirmDisable();
296+
expect(await screen.findByTestId('refusal-lead')).toHaveTextContent('Package is read-only.');
297+
expect(screen.getByTestId('refusal-more')).toBeInTheDocument();
298+
expect(screen.queryByTestId('pkg-detail-refusal-heading')).toBeNull();
299+
});
300+
301+
it('CONTROL: a disable with no dependent rule lands in one confirm, with no refusal drawn', async () => {
302+
stubWire();
303+
await renderSheet(moduleRow());
304+
await confirmDisable();
305+
expect(await screen.findByText(label('disabled'))).toBeInTheDocument();
306+
expect(screen.queryByTestId('pkg-detail-refusal-heading')).toBeNull();
307+
expect(lifecycleCalls()).toEqual(['disable']);
308+
});
309+
});

‎ui/packages/app-shell/src/views/metadata-admin/PackagesPage.tsx‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ type UncheckedPackageRow = Omit<InstalledPackageRow, 'source' | 'writable'> & {
188188

189189
const API = '/api/v1/packages';
190190

191+
/**
192+
* The code `PATCH /packages/:id/disable` answers, with `409`, while a
193+
* validation rule of an enabled package reads a field the package adds through
194+
* `objectExtensions` (registered in the spec's error-code ledger). Its message
195+
* names every such rule and the remedy; the refusal carries no `details`.
196+
*/
197+
const DISABLE_RESTRICTED_BY_VALIDATION_RULE = 'PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE';
198+
191199
async function apiJson<T>(path: string, init?: RequestInit): Promise<T> {
192200
// objectstack#29119 — every write this page sends (publish, revert, discard,
193201
// delete, adopt, enable/disable, import) may change the package list, so the
@@ -518,11 +526,14 @@ export function PackageDetailSheet({
518526
const client = useMetadataClient();
519527
const [busy, setBusy] = React.useState<string | null>(null);
520528
// `details`: the lines a refusal carries under its sentence, in the server's
521-
// own words (objectui#13160).
529+
// own words (objectui#13160). `heading`: a console sentence, in the reader's
530+
// language, drawn above a refusal that is then shown whole rather than cut
531+
// to its first sentence (objectstack#31003).
522532
const [msg, setMsg] = React.useState<{
523533
kind: 'ok' | 'err';
524534
text: string;
525535
details?: readonly string[];
536+
heading?: string;
526537
} | null>(null);
527538
// ADR-0033 — pending DRAFT items bound to this package. AI-authored metadata
528539
// lands as drafts that the active-only browsers hide, so without this the
@@ -629,6 +640,14 @@ export function PackageDetailSheet({
629640
kind: 'err',
630641
text: e?.message ?? t('engine.packages.detail.actionFailed', locale),
631642
...(e instanceof PackagePublishRefusal ? { details: e.reasons } : {}),
643+
// objectstack#31003 — the disable door refuses while an enabled
644+
// validation rule reads a field the package adds. The server's sentence
645+
// names every such rule (package · object · rule) and then the remedy,
646+
// so it is drawn whole under a heading in the reader's language: cut to
647+
// its first sentence, the remedy sat behind "More".
648+
...(errorCodeIs(e, DISABLE_RESTRICTED_BY_VALIDATION_RULE)
649+
? { heading: t('engine.packages.detail.disableRestricted', locale) }
650+
: {}),
632651
});
633652
} finally {
634653
setBusy(null);
@@ -1174,8 +1193,22 @@ export function PackageDetailSheet({
11741193
}`}
11751194
>
11761195
{/* A refusal leads with its first sentence; the rest of the
1177-
server's text is behind "More" (objectui#13332). */}
1178-
{msg.kind === 'err' ? <RefusalMessage text={msg.text} /> : msg.text}
1196+
server's text is behind "More" (objectui#13332). One with a
1197+
heading is drawn whole under it (objectstack#31003). */}
1198+
{msg.kind === 'err' && msg.heading ? (
1199+
<>
1200+
<p className="font-medium" data-testid="pkg-detail-refusal-heading">
1201+
{msg.heading}
1202+
</p>
1203+
<p className="mt-1 whitespace-pre-wrap break-words select-text" data-testid="pkg-detail-refusal-text">
1204+
{msg.text}
1205+
</p>
1206+
</>
1207+
) : msg.kind === 'err' ? (
1208+
<RefusalMessage text={msg.text} />
1209+
) : (
1210+
msg.text
1211+
)}
11791212
{msg.details && msg.details.length > 0 && (
11801213
// Not capped: the sheet scrolls (`overflow-y-auto`), as it does
11811214
// for the pending-drafts list above. `break-words` keeps a long
@@ -1301,6 +1334,13 @@ export function PackageDetailSheet({
13011334
<AlertDialogDescription>
13021335
{t('engine.packages.detail.disableDescription', locale)}
13031336
</AlertDialogDescription>
1337+
{/* objectstack#31003 — the served `disableable` says what the
1338+
package allows, not whether a rule elsewhere still reads its
1339+
fields; the door answers that only when asked, so the dialog
1340+
says the disable can still be refused. */}
1341+
<p className="text-sm text-muted-foreground" data-testid="pkg-detail-disable-may-refuse">
1342+
{t('engine.packages.detail.disableMayBeRefused', locale)}
1343+
</p>
13041344
</AlertDialogHeader>
13051345
<AlertDialogFooter>
13061346
<AlertDialogCancel data-testid="pkg-detail-disable-cancel">

‎ui/packages/i18n/src/namespaces/studio/en.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,8 @@ const STUDIO_EN: Record<string, string> = {
19331933
'engine.packages.detail.disable': 'Disable',
19341934
'engine.packages.detail.disableTitle': 'Disable "{name}"?',
19351935
'engine.packages.detail.disableDescription': 'The package is taken out of service for every user until it is enabled again. No records are deleted, and you can enable it again at any time.',
1936+
'engine.packages.detail.disableMayBeRefused': 'The disable is refused while an active validation rule reads a field this package adds; the refusal names each such rule.',
1937+
'engine.packages.detail.disableRestricted': 'This package cannot be disabled while an active validation rule reads a field it adds. Switch off or change each rule named below first, or keep the package enabled.',
19361938
'engine.packages.detail.export': 'Export',
19371939
'engine.packages.detail.exporting': 'Exporting…',
19381940
'engine.packages.detail.deletePackage': 'Delete package',

‎ui/packages/i18n/src/namespaces/studio/zh.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,8 @@ const STUDIO_ZH: Record<string, string> = {
17451745
'engine.packages.detail.disable': '禁用',
17461746
'engine.packages.detail.disableTitle': '禁用「{name}」?',
17471747
'engine.packages.detail.disableDescription': '在重新启用之前,此软件包将对所有用户停止服务。不会删除任何记录,您可以随时重新启用。',
1748+
'engine.packages.detail.disableMayBeRefused': '如果有生效中的验证规则读取此软件包添加的字段,禁用会被拒绝,拒绝信息会逐条列出这些规则。',
1749+
'engine.packages.detail.disableRestricted': '有生效中的验证规则读取此软件包添加的字段,因此暂时无法禁用。请先停用或修改下方列出的每条规则,或保持此软件包启用。',
17481750
'engine.packages.detail.export': '导出',
17491751
'engine.packages.detail.exporting': '导出中…',
17501752
'engine.packages.detail.deletePackage': '删除软件包',

0 commit comments

Comments
 (0)