Skip to content

Commit dc53d4a

Browse files
fix(app-shell): disabled Explain and Pick in Explain access say an object is missing (#35289)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg6v19uPsX6gX42G8tGcvvzb)_ Fixes #34865 Clause-②: no Metadata-protocol: none ## 维护者速读 改了什么:Studio「权限解释」(Explain access)面板里,未选对象时灰掉的「解释」按钮和记录「选择」按钮,现在鼠标悬停、键盘 Tab 聚焦、读屏软件三条路都能拿到原因「请先选择对象」。 为什么改:原来两个按钮是原生 disabled,悬停无提示、Tab 跳过、读屏读不到原因;「选择」唯一的 title 就是它自己的名字「Pick」。 风险与回滚:只改显示与可达性,复用已落地的共享包装 `DisabledControlReason`,不改解释请求逻辑;选了对象后两个按钮与原来一样。回滚 = revert 本 PR。 先看:`ui/packages/app-shell/src/views/metadata-admin/AccessExplainPanel.tsx`(两处按钮外包一层 `DisabledControlReason`)→ `AccessExplainPanel.test.tsx` 末尾新增的 describe → `ui/packages/i18n/src/namespaces/studio/en.ts` / `zh.ts` 各一行新文案。 两分钟验证:`pnpm --filter @object-ui/app-shell exec vitest run --maxWorkers=2 src/views/metadata-admin/AccessExplainPanel.test.tsx`,预期全部通过(含新增 2 条)。 需要你做的:无,席位落地。 ## What changes With no object chosen, "Explain access" draws Explain and the record Pick disabled, and both were bare disabled buttons: a natively disabled button takes neither hover nor focus, so no tooltip opened, Tab skipped it, and nothing reached the accessibility tree. Pick's only `title` was its own label, "Pick". Both now take the treatment the closed #32103, #32104 and #32105 gave the same class (`ux-conventions.disabled-control-reason`), by reusing the shared `DisabledControlReason` wrapper from `metadata-admin/inspectors/_shared.tsx` unchanged: a focusable wrapper opens a tooltip with the reason, and the wrapper and the button both point `aria-describedby` at an `sr-only` copy of it. Each button keeps its own name. - Reason: one new string, `engine.studio.access.explain.needObject` ("Choose an object first" / "请先选择对象"), in the Studio namespace catalogues of `@object-ui/i18n`. Both buttons wait on the same condition, so they share it. - Explain while a run is in flight gives no reason: its label already says "Explaining…". - Pick's redundant `title` (equal to its visible label) is dropped, so a native tooltip no longer competes with the reason. - The disabled predicates are unchanged (`!objectName.trim()`, and `busy ||` for Explain). - Root changeset: `patch` on `@object-ui/app-shell` and `@object-ui/i18n`, as the prior fix of this class shipped. ## Tests New top-level describe in the existing harness `AccessExplainPanel.test.tsx`: - No object: Pick and Explain are disabled and each is described by the reason; Pick carries no `title`; Tab from the record-id input lands on Pick's wrapper, then on Explain's wrapper, each described by the reason, and the tooltip shows it. - CONTROL: an object typed in, both are plain enabled buttons, with no `aria-describedby`, no `data-disabled-reason` and no `tabindex` on the wrapper. ## Acceptance notes - File surface: the dispatch fenced `AccessExplainPanel.tsx`, its tests and the root changeset. The reason string has to live in the Studio namespace catalogue, so `ui/packages/i18n/src/namespaces/studio/en.ts` and `zh.ts` each gain one line, the same place the prior fix of this class put its strings. The shared helper is reused, not edited. ## Verification Local runs at the head this PR was opened on: - `node scripts/pm/overlap-check.mjs`: `VERDICT clean exit 0` before each push. - Derived local gate subset, each exit 0: `check-adr-0087-registration --base origin/main`, `check-changeset-no-major --base origin/main`, `check-empty-changeset --base origin/main`, `check-sdui-manifest`, `check:nul-bytes`, `check:published-files`, `check:cross-package-test-inputs`, `check:test-source-alias`, `check:undeclared-dep-imports`, `check:closed-ceremony-text`, `check:type-check-coverage`. - NOT MEASURED locally: the app-shell vitest file and the UI type-check. Reason: the shared verify lock was held for the whole session by another run of the full app-shell suite, and five timed attempts did not acquire it. This is a declared narrowing; `Test UI` and `Type Check UI` on this PR are the evidence, and the dev report records the outcome. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CbSphdunq2aJq7ktuY)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CbSphdunq2aJq7ktuY <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbSphdunq2aJq7ktuY --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1b2cd80 commit dc53d4a

5 files changed

Lines changed: 98 additions & 16 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(app-shell): Studio's "Explain access" says why Explain and Pick are disabled, on hover, on keyboard focus and to assistive technology
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
With no object chosen, the Explain button and the record Pick button were bare disabled buttons: no tooltip on hover, skipped by Tab, and nothing in the accessibility tree (Pick's only title was its own label, "Pick"). Both now sit in the shared `DisabledControlReason` wrapper the Studio form designer, create dialog and metadata Save already use: a focusable wrapper that opens a tooltip with the reason "Choose an object first", and both the wrapper and the button point `aria-describedby` at it. Each button keeps its own name; once an object is chosen both are plain enabled buttons, and a running Explain gives no reason because its label already says "Explaining…". The new string is in the Studio namespace catalogues (`en`, `zh`) of `@object-ui/i18n`.

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import '@testing-library/jest-dom/vitest';
1414
import { afterEach, describe, expect, it, vi } from 'vitest';
1515
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
16+
import userEvent from '@testing-library/user-event';
1617

1718
const fetchSpy = vi.fn();
1819
// objectui#2600 B2 — package object list backing the object dropdown; a
@@ -38,6 +39,7 @@ vi.mock('@object-ui/fields', async (importOriginal) => ({
3839
}));
3940

4041
import { AccessExplainPanel, type ExplainDecision } from './AccessExplainPanel';
42+
import { t } from './i18n';
4143

4244
afterEach(() => {
4345
cleanup();
@@ -228,3 +230,51 @@ describe('AccessExplainPanel (ADR-0090 D6)', () => {
228230
expect(screen.getByLabelText('Object').tagName).toBe('INPUT');
229231
});
230232
});
233+
234+
/**
235+
* objectstack#34865 — with no object chosen, Explain and the record Pick are
236+
* disabled, and were bare disabled buttons: no reason on hover, Tab skipped
237+
* them, nothing in the accessibility tree (Pick's only title was "Pick").
238+
* Each now sits in a focusable wrapper described by the reason
239+
* (`DisabledControlReason`, ux-conventions.disabled-control-reason), keeping
240+
* its own name.
241+
*/
242+
describe('AccessExplainPanel — disabled Explain and Pick say an object is missing (objectstack#34865)', () => {
243+
const describedBy = (el: HTMLElement) =>
244+
document.getElementById(el.getAttribute('aria-describedby') ?? '') as HTMLElement | null;
245+
const NEED_OBJECT = t('engine.studio.access.explain.needObject', 'en-US');
246+
const explain = () => screen.getByRole('button', { name: /explain$/i });
247+
const pick = () => screen.getByRole('button', { name: t('engine.studio.access.explain.pickRecord', 'en-US') });
248+
249+
it('no object: Tab from the record id reaches Pick, then Explain, each giving the reason', async () => {
250+
const user = userEvent.setup();
251+
renderPanel();
252+
for (const button of [pick(), explain()]) {
253+
expect(button).toBeDisabled();
254+
expect(describedBy(button)).toHaveTextContent(NEED_OBJECT);
255+
}
256+
expect(pick()).not.toHaveAttribute('title');
257+
258+
screen.getByLabelText(/Record/i).focus();
259+
await user.tab();
260+
expect(pick().parentElement).toHaveFocus();
261+
expect(describedBy(pick().parentElement as HTMLElement)).toHaveTextContent(NEED_OBJECT);
262+
expect(await screen.findByRole('tooltip')).toHaveTextContent(NEED_OBJECT);
263+
264+
await user.tab();
265+
expect(explain().parentElement).toHaveFocus();
266+
expect(describedBy(explain().parentElement as HTMLElement)).toHaveTextContent(NEED_OBJECT);
267+
await waitFor(() => expect(screen.getByRole('tooltip')).toHaveTextContent(NEED_OBJECT));
268+
});
269+
270+
it('CONTROL — an object chosen: Explain and Pick are plain enabled buttons with no reason', () => {
271+
renderPanel();
272+
fireEvent.change(screen.getByLabelText('Object'), { target: { value: 'crm_lead' } });
273+
for (const button of [pick(), explain()]) {
274+
expect(button).toBeEnabled();
275+
expect(button).not.toHaveAttribute('aria-describedby');
276+
expect(button.parentElement).not.toHaveAttribute('data-disabled-reason');
277+
expect(button.parentElement).not.toHaveAttribute('tabindex');
278+
}
279+
});
280+
});

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

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
import { t, tFormat, useMetadataLocale } from './i18n.js';
5959
import { useMetadataClient } from './useMetadata.js';
6060
import { readEnvelopeFailureText } from '../../utils/apiErrorEnvelope.js';
61+
import { DisabledControlReason } from './inspectors/_shared.js';
6162

6263
/**
6364
* The explain-report vocabulary is OWNED by `@objectstack/spec/security` and
@@ -333,6 +334,10 @@ export function AccessExplainPanel({ open, onOpenChange, defaultObject, packageI
333334
const [busy, setBusy] = React.useState(false);
334335
const [error, setError] = React.useState<string | null>(null);
335336
const [decision, setDecision] = React.useState<ExplainDecision | null>(null);
337+
// Explain and Pick both wait for an object, and say so on hover, on focus
338+
// and to assistive tech (ux-conventions.disabled-control-reason). A run in
339+
// flight gives none: Explain's label already says so.
340+
const needObjectReason = objectName.trim() ? undefined : t('engine.studio.access.explain.needObject', locale);
336341
// objectui#11862 — the people this panel can name, by user id: the row the
337342
// user picker handed back, and the rows the same lookup answered for a
338343
// decision's principal. An id with no entry renders as the id.
@@ -604,18 +609,22 @@ export function AccessExplainPanel({ open, onOpenChange, defaultObject, packageI
604609
placeholder={t('engine.studio.access.explain.recordPlaceholder', locale)}
605610
className="h-8 min-w-0 flex-1 text-xs"
606611
/>
607-
<Button
608-
type="button"
609-
variant="outline"
610-
size="sm"
611-
className="h-8 shrink-0 gap-1 text-xs"
612-
disabled={!objectName.trim()}
613-
onClick={() => setRecordPickerOpen(true)}
614-
title={t('engine.studio.access.explain.pickRecord', locale)}
615-
>
616-
<ChevronsUpDown className="h-3 w-3" />
617-
{t('engine.studio.access.explain.pickRecord', locale)}
618-
</Button>
612+
<DisabledControlReason reason={needObjectReason} testId="explain-pick-record-reason" className="shrink-0">
613+
{(describedBy) => (
614+
<Button
615+
type="button"
616+
variant="outline"
617+
size="sm"
618+
className="h-8 shrink-0 gap-1 text-xs"
619+
disabled={!objectName.trim()}
620+
onClick={() => setRecordPickerOpen(true)}
621+
aria-describedby={describedBy}
622+
>
623+
<ChevronsUpDown className="h-3 w-3" />
624+
{t('engine.studio.access.explain.pickRecord', locale)}
625+
</Button>
626+
)}
627+
</DisabledControlReason>
619628
{recordId && (
620629
<Button
621630
variant="ghost"
@@ -631,10 +640,20 @@ export function AccessExplainPanel({ open, onOpenChange, defaultObject, packageI
631640
</div>
632641
</div>
633642

634-
<Button size="sm" className="h-8 gap-1.5 text-xs" disabled={busy || !objectName.trim()} onClick={() => void run()}>
635-
{busy ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <HelpCircle className="h-3.5 w-3.5" />}
636-
{busy ? t('engine.studio.access.explain.running', locale) : t('engine.studio.access.explain.run', locale)}
637-
</Button>
643+
<DisabledControlReason reason={busy ? undefined : needObjectReason} testId="explain-run-reason">
644+
{(describedBy) => (
645+
<Button
646+
size="sm"
647+
className="h-8 gap-1.5 text-xs"
648+
disabled={busy || !objectName.trim()}
649+
onClick={() => void run()}
650+
aria-describedby={describedBy}
651+
>
652+
{busy ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <HelpCircle className="h-3.5 w-3.5" />}
653+
{busy ? t('engine.studio.access.explain.running', locale) : t('engine.studio.access.explain.run', locale)}
654+
</Button>
655+
)}
656+
</DisabledControlReason>
638657
</div>
639658

640659
{/* ── result ── */}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,7 @@ const STUDIO_EN: Record<string, string> = {
27992799
'engine.studio.access.explain.operation': 'Operation',
28002800
'engine.studio.access.explain.run': 'Explain',
28012801
'engine.studio.access.explain.running': 'Explaining…',
2802+
'engine.studio.access.explain.needObject': 'Choose an object first',
28022803
'engine.studio.access.explain.allowedLine': '{operation} on “{object}” is ALLOWED for this principal.',
28032804
'engine.studio.access.explain.deniedLine': '{operation} on “{object}” is DENIED for this principal.',
28042805
'engine.studio.access.explain.principal': 'Principal',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,7 @@ const STUDIO_ZH: Record<string, string> = {
25032503
'engine.studio.access.explain.operation': '操作',
25042504
'engine.studio.access.explain.run': '解释',
25052505
'engine.studio.access.explain.running': '解释中…',
2506+
'engine.studio.access.explain.needObject': '请先选择对象',
25062507
'engine.studio.access.explain.allowedLine': '该主体对「{object}」执行 {operation} 将被【允许】。',
25072508
'engine.studio.access.explain.deniedLine': '该主体对「{object}」执行 {operation} 将被【拒绝】。',
25082509
'engine.studio.access.explain.principal': '主体',

0 commit comments

Comments
 (0)