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
10 changes: 10 additions & 0 deletions .changeset/flow-edge-inspector-readonly-reason.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): a read-only flow edge inspector says why its controls are disabled, on hover, on keyboard focus and to assistive tech

Clause-②: no
Metadata-protocol: none

On a read-only package, Studio's flow connection inspector disabled every control (From, To, the branch pickers, Label, Condition, Default branch, Type, Remove connection) and gave no reason anywhere: no tooltip, no accessible description, and Tab skipped the whole panel. The reason Studio's Automations pillar hands every flow inspector reached it and was dropped. The connection inspector now carries the treatment the node inspector carries: the panel is a tab stop described by the reason, and hovering any disabled control in it shows the reason in a tooltip. Both inspectors draw it through one shared wrapper. A host that passes no reason renders exactly as before.
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#29077 — a read-only flow edge inspector says why its controls are
* disabled, on hover, on keyboard focus and to assistive tech, when its host
* hands it the reason (`readOnlyReason`), as the node inspector does since
* objectstack#28985.
*
* Measured on the card: on a read-only package every control of the connection
* inspector (From, To, the branch pickers, Label, Condition, Default branch,
* Type, Remove connection) was disabled with no `aria-describedby` and no tab
* stop, and the reason Studio's Automations pillar hands every flow inspector
* was dropped. Both panels now draw it through one `InspectorReadOnlyReason`.
*
* The reason is the host's: a host that passes none gets the panel it always
* had. Studio's pillar passing it to a selected connection is pinned in
* `StudioDesignSurface.automationsReadOnly-11124.test.tsx`.
*/

import '@testing-library/jest-dom/vitest';
import * as React from 'react';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

vi.mock('../previews/useObjectFields', () => ({
useObjectFields: () => ({ fields: [], loading: false, error: null }),
}));

import { FlowEdgeInspector } from './FlowEdgeInspector';
import { flowEdgeDisplayName } from '../previews/flow-canvas-parts';
import { t } from '../i18n';

afterEach(cleanup);

const REASON = 'Read-only package: switch to or create a writable package to edit.';

const NODES = [
{ id: 'start', type: 'start', label: 'Start' },
{ id: 'review', type: 'approval', label: 'Review' },
{ id: 'end', type: 'end', label: 'End' },
];
// An approval's out-edge, so the panel also draws its "Approval branch" picker.
const DRAFT = {
name: 'f',
label: 'F',
nodes: NODES,
edges: [
{ id: 'e1', source: 'start', target: 'review' },
{ id: 'e2', source: 'review', target: 'end', label: 'approve' },
],
};

function mount({ readOnly, readOnlyReason }: { readOnly: boolean; readOnlyReason?: string }) {
return render(
<FlowEdgeInspector
type="flow"
name="f"
draft={DRAFT}
selection={{ kind: 'edge', id: 'e2' }}
onPatch={() => {}}
onClearSelection={() => {}}
readOnly={readOnly}
readOnlyReason={readOnlyReason}
locale="en-US"
/>,
);
}

const removeButton = () => screen.getByRole('button', { name: t('engine.inspector.flowEdge.remove', 'en-US') });

/** The panel's form controls, Remove connection included — the ones the reason is about. */
const controls = (root: HTMLElement) => [
...root.querySelectorAll<HTMLElement>('input, select, textarea, button[role="combobox"]'),
removeButton(),
];

describe('Flow edge inspector, read-only with a reason from its host (objectstack#29077)', () => {
it('the panel is a tab stop described by the reason, named by the connection, and holds the disabled controls', () => {
const { container } = mount({ readOnly: true, readOnlyReason: REASON });
const body = container.querySelector('[data-disabled-reason]') as HTMLElement;
expect(body).not.toBeNull();
expect(body).toHaveAttribute('tabindex', '0');
expect(body).toHaveAccessibleDescription(REASON);
// The same name the panel's title shows: each end by its node's name.
expect(body).toHaveAccessibleName(flowEdgeDisplayName({ source: 'review', target: 'end' }, NODES, 'en-US'));
expect(body).not.toHaveAccessibleName(/review|end\b/);

const all = controls(body);
// From, To, Approval branch, Label, Condition, Default branch, Type and
// Remove connection; at least six, so a vacuous pass is not one.
expect(all.length).toBeGreaterThanOrEqual(6);
for (const el of all) {
expect(body).toContainElement(el);
expect(el).toBeDisabled();
}
});

it('hovering the disabled "Remove connection" opens a tooltip with the reason', async () => {
const user = userEvent.setup();
mount({ readOnly: true, readOnlyReason: REASON });
expect(removeButton()).toBeDisabled();
await user.hover(removeButton());
expect(await screen.findByRole('tooltip')).toHaveTextContent(REASON);
});

it('a keyboard user reaches the reason: Tab lands on the described panel, which opens the tooltip', async () => {
const user = userEvent.setup();
const { container } = mount({ readOnly: true, readOnlyReason: REASON });
const body = container.querySelector('[data-disabled-reason]') as HTMLElement;
await user.tab();
expect(body).toHaveFocus();
expect(await screen.findByRole('tooltip')).toHaveTextContent(REASON);
});
});

describe('Flow edge inspector — the controls (objectstack#29077)', () => {
it('a host that passes no reason gets the panel it always had: no tab stop, no description', () => {
const { container } = mount({ readOnly: true });
expect(container.querySelector('[data-disabled-reason]')).toBeNull();
expect(container.querySelector('[tabindex="0"]')).toBeNull();
for (const el of controls(container)) expect(el).toBeDisabled();
});

it('a blank reason counts as none', () => {
const { container } = mount({ readOnly: true, readOnlyReason: ' ' });
expect(container.querySelector('[data-disabled-reason]')).toBeNull();
});

it('a writable inspector ignores a reason: the controls are live and nothing is described', () => {
const { container } = mount({ readOnly: false, readOnlyReason: REASON });
expect(container.querySelector('[data-disabled-reason]')).toBeNull();
expect(screen.queryByText(REASON)).toBeNull();
const all = controls(container);
expect(all.length).toBeGreaterThanOrEqual(6);
for (const el of all) expect(el).toBeEnabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
InspectorCheckboxField,
InspectorRemoveButton,
InspectorEmptyState,
InspectorReadOnlyReason,
spliceArray,
} from './_shared.js';
import { Label } from '@object-ui/components';
Expand Down Expand Up @@ -73,6 +74,7 @@ export function FlowEdgeInspector({
onSelectionChange,
locale,
readOnly,
readOnlyReason,
}: MetadataInspectorProps) {
const edges = Array.isArray((draft as any).edges) ? ((draft as any).edges as FlowDesignerEdge[]) : [];
const index = edges.findIndex((e, i) => edgeKey(e, i) === selection.id);
Expand Down Expand Up @@ -204,7 +206,7 @@ export function FlowEdgeInspector({

const edgeType = (typeof edge.type === 'string' && edge.type) || 'default';

return (
const shell = (
<InspectorShell
kindLabel={t('engine.inspector.flowEdge.kind', locale)}
// Read off the edge itself, each end by its node's name (objectui#13143):
Expand Down Expand Up @@ -376,4 +378,17 @@ export function FlowEdgeInspector({
)}
</InspectorShell>
);

// Read-only with a reason from the host: every control above is disabled for
// that one reason, so the panel carries it, as the node inspector's does.
return (
<InspectorReadOnlyReason
readOnly={readOnly}
reason={readOnlyReason}
label={flowEdgeDisplayName(edge, nodes, locale)}
testId="flow-edge-readonly-reason"
>
{shell}
</InspectorReadOnlyReason>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import * as React from 'react';
import { Plus } from 'lucide-react';
import { resolveFlowTriggerKind } from '@objectstack/spec/automation';
import { Input, Label, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@object-ui/components';
import { Input, Label } from '@object-ui/components';
import type { MetadataInspectorProps } from '../inspector-registry.js';
import { t, tFormat } from '../i18n.js';
import {
Expand All @@ -31,6 +31,7 @@ import {
InspectorSelectField,
InspectorRemoveButton,
InspectorEmptyState,
InspectorReadOnlyReason,
} from './_shared.js';
import {
mergeServerFlowFields,
Expand Down Expand Up @@ -294,7 +295,6 @@ export function FlowNodeInspector({
readOnly,
readOnlyReason,
}: MetadataInspectorProps) {
const readOnlyReasonId = React.useId();
// Resolve the selection to a node + how to write it back — a top-level draft
// node, or a node nested inside a container region (#2670). Every edit goes
// through loc.write, so the inspector never branches on where the node lives.
Expand Down Expand Up @@ -895,34 +895,16 @@ export function FlowNodeInspector({
</InspectorShell>
);

const reason = readOnly ? readOnlyReason?.trim() : undefined;
if (!reason) return shell;
// Read-only with a reason from the host: every control above is disabled for
// that one reason, and a disabled control takes neither hover nor focus. The
// inspector body is the tooltip trigger, so hovering any of them shows it, and
// a tab stop described by an `sr-only` copy, so a keyboard or screen-reader
// user reaches it too. One trigger for the panel, not one per control: the
// reason is the same for all of them. Same treatment as Studio's field rail
// and validation-rule editor.
// that one reason, so the panel carries it (`InspectorReadOnlyReason`).
return (
<TooltipProvider delayDuration={200}>
<Tooltip>
<TooltipTrigger asChild>
<div
role="group"
aria-label={flowNodeDisplayName(node, locale)}
tabIndex={0}
aria-describedby={readOnlyReasonId}
data-disabled-reason=""
data-testid="flow-node-readonly-reason"
className="flex h-full min-h-0 flex-col focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
>
{shell}
<span id={readOnlyReasonId} className="sr-only">{reason}</span>
</div>
</TooltipTrigger>
<TooltipContent side="left" align="start">{reason}</TooltipContent>
</Tooltip>
</TooltipProvider>
<InspectorReadOnlyReason
readOnly={readOnly}
reason={readOnlyReason}
label={flowNodeDisplayName(node, locale)}
testId="flow-node-readonly-reason"
>
{shell}
</InspectorReadOnlyReason>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@
import * as React from 'react';
import { ArrowDown, ArrowUp, Trash2, X } from 'lucide-react';
import { cn } from '@object-ui/components';
import { Badge, Button, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@object-ui/components';
import {
Badge,
Button,
Input,
Label,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@object-ui/components';
import { type LoadState } from '../loadState.js';
import { t, tFormat, useMetadataLocale, type SupportedLocale } from '../i18n.js';

Expand Down Expand Up @@ -704,6 +718,53 @@ export function InspectorEmptyState({ message }: { message: string }) {
return <div className="text-xs italic text-muted-foreground p-4 text-center">{message}</div>;
}

export interface InspectorReadOnlyReasonProps {
/** The inspector's `readOnly`: with it false, `children` render bare. */
readOnly?: boolean;
/** The host's `readOnlyReason`. Missing or blank, `children` render bare. */
reason?: string;
/** The group's accessible name: the element the panel edits. */
label: string;
testId?: string;
children: React.ReactNode;
}

/**
* The reason a read-only inspector's controls are disabled, given on hover, on
* keyboard focus and to assistive tech. A disabled control takes neither hover
* nor focus, so the panel itself is the tooltip trigger and a tab stop
* described by an `sr-only` copy of the reason. One trigger for the panel, not
* one per control: the host's reason is the same for all of them. Draws
* nothing of its own unless `readOnly` and the reason is non-blank, so a host
* that passes no reason renders exactly as before.
*/
export function InspectorReadOnlyReason({ readOnly, reason: reasonProp, label, testId, children }: InspectorReadOnlyReasonProps) {
const reasonId = React.useId();
const reason = readOnly ? reasonProp?.trim() : undefined;
if (!reason) return <>{children}</>;
return (
<TooltipProvider delayDuration={200}>
<Tooltip>
<TooltipTrigger asChild>
<div
role="group"
aria-label={label}
tabIndex={0}
aria-describedby={reasonId}
data-disabled-reason=""
data-testid={testId}
className="flex h-full min-h-0 flex-col focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
>
{children}
<span id={reasonId} className="sr-only">{reason}</span>
</div>
</TooltipTrigger>
<TooltipContent side="left" align="start">{reason}</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}

/**
* Helper to immutably splice an item in an array on a draft.
* Returns a new array; never mutates input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@ describe('Automations pillar on a read-only package (objectui#11124)', () => {
expect(body).toHaveAccessibleDescription(READ_ONLY_REASON);
});

it('a selected connection opens read-only, and its inspector carries the package reason (objectstack#29077)', async () => {
renderPillar(true);
await openFlow();

const hit = [...document.querySelectorAll('path > title')].find((el) => el.textContent === 'Start → End');
expect(hit, 'the canvas must render the start → end connection').toBeTruthy();
fireEvent.click(hit!.parentElement!);
const rail = screen.getByRole('complementary');
const remove = await within(rail).findByRole(
'button',
{ name: t('engine.inspector.flowEdge.remove', 'en') },
{ timeout: 8000 },
);
expect(remove).toBeDisabled();
const body = screen.getByTestId('flow-edge-readonly-reason');
expect(body).toContainElement(remove);
expect(body).toHaveAttribute('tabindex', '0');
expect(body).toHaveAccessibleDescription(READ_ONLY_REASON);
});

it('offers no canvas edit: no "add connected node" or "insert node" handle', async () => {
renderPillar(true);
await openFlow();
Expand Down
Loading