mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-06 16:01:00 +00:00
feat(ui): move connection detail actions behind a More menu
Each panel shows one primary action. The connection detail keeps Add rule and moves show rule, edit rule, view flow, trace, only this client and close connection into a trailing More menu, close last. MoreMenu is the shared wrapper; a disabled item carries its reason as its description.
This commit is contained in:
1 parent
4dde228def
commit
d3970eb987
11 files changed
+197
-87
No files matched your search
@@ -2,7 +2,7 @@ import {test as httpTest, type Locator, type Page} from '@playwright/test';
|
||||
import {createMockApi} from '../src/api/mock';
|
||||
import {sha256} from '../src/api/hash';
|
||||
import {ApiError} from '../src/api/error';
|
||||
import {expect, test} from './fixtures';
|
||||
import {expect, test, moreAction} from './fixtures';
|
||||
|
||||
async function backend(page: Page) {
|
||||
const api = createMockApi();
|
||||
@@ -153,7 +153,7 @@ for (const all of [false, true]) {
|
||||
if (all) {
|
||||
await page.getByRole('button', {name: 'Close all', exact: true}).click();
|
||||
await page.getByRole('alertdialog').getByRole('button', {name: 'Close all', exact: true}).click();
|
||||
} else await page.getByRole('button', {name: 'Close connection', exact: true}).click();
|
||||
} else await moreAction(page.locator('.rp-panel, .rp-drawer'), 'Close connection');
|
||||
await request;
|
||||
await expect(page).toHaveURL(/connections\?id=1$/);
|
||||
// A pending confirmation covers the page; its Cancel abandons the bulk close.
|
||||
|
||||
+28
-32
@@ -1,4 +1,4 @@
|
||||
import {detail, expect, expectLoadFailures, mockBackend, test} from './fixtures';
|
||||
import {detail, expect, expectLoadFailures, mockBackend, test, moreAction} from './fixtures';
|
||||
import {createMockApi} from '../src/api/mock';
|
||||
import {ApiError} from '../src/api/error';
|
||||
import {sha256} from '../src/api/hash';
|
||||
@@ -68,7 +68,7 @@ test('a refused write shows its diagnostics in the dialog and writes nothing', a
|
||||
test('show matched rule opens the rule list on that rule', async ({page}) => {
|
||||
await mockBackend(page);
|
||||
await page.goto('/#/connections?id=1');
|
||||
await detail(page).getByRole('button', {name: 'Show matched rule', exact: true}).click();
|
||||
await moreAction(detail(page), 'Show matched rule');
|
||||
await expect(page).toHaveURL(/#\/rules\?tab=list&rule=r5$/);
|
||||
const selected = page.getByRole('tabpanel', {name: 'Routing rules'}).locator('[role=row][aria-selected=true]');
|
||||
await expect(selected).toHaveCount(1);
|
||||
@@ -83,7 +83,9 @@ test('a connection with no recorded rule adds before the fallback and says earli
|
||||
};
|
||||
await page.goto('/#/connections?id=1');
|
||||
await expect(detail(page).getByRole('heading', {name: 'api.telegram.org'})).toBeVisible();
|
||||
await expect(detail(page).getByRole('button', {name: 'Show matched rule', exact: true})).toHaveCount(0);
|
||||
await detail(page).getByRole('button', {name: 'More actions', exact: true}).click();
|
||||
await expect(page.getByRole('menuitem', {name: 'Show matched rule', exact: true})).toHaveCount(0);
|
||||
await page.keyboard.press('Escape');
|
||||
await detail(page).getByRole('button', {name: 'Add rule', exact: true}).click();
|
||||
const dialog = page.getByRole('dialog', {name: 'Add rule'});
|
||||
await expect(dialog.getByRole('button', {name: /Insert$/})).toContainText('Last, before the fallback');
|
||||
@@ -100,41 +102,35 @@ test('without a writable configuration showing the matched rule only reads', asy
|
||||
await page.goto('/#/connections?id=1');
|
||||
await expect(detail(page).getByRole('heading', {name: 'api.telegram.org'})).toBeVisible();
|
||||
await expect(detail(page).getByRole('link', {name: /in the rule list$/})).toBeVisible();
|
||||
await detail(page).getByRole('button', {name: 'Show matched rule', exact: true}).click();
|
||||
await moreAction(detail(page), 'Show matched rule');
|
||||
await expect(page).toHaveURL(/#\/rules\?tab=list&rule=r5$/);
|
||||
});
|
||||
|
||||
for (const width of [360, 768, 1440])
|
||||
test(`the panel actions share one size, line up and keep even gaps at ${width}px`, async ({page}) => {
|
||||
test(`the panel shows one primary action beside a More menu of the same size at ${width}px`, async ({page}) => {
|
||||
await mockBackend(page);
|
||||
await page.setViewportSize({width, height: 900});
|
||||
await page.goto('/#/connections?id=1');
|
||||
const close = detail(page).getByRole('button', {name: 'Close connection', exact: true});
|
||||
await expect(close).toBeVisible();
|
||||
const boxes = await detail(page)
|
||||
.getByRole('button', {
|
||||
name: /^(Add rule|Show matched rule|Edit matched rule's outbound settings|View flow|Trace this connection|Only this device|Close connection)$/
|
||||
})
|
||||
.evaluateAll(buttons => buttons.map(button => button.getBoundingClientRect().toJSON() as DOMRect));
|
||||
expect(boxes).toHaveLength(7);
|
||||
// One button style: a quiet button beside a filled one reads as a misaligned label.
|
||||
const fills = await detail(page)
|
||||
.getByRole('button', {name: /^(Add rule|Show matched rule|Edit matched rule's outbound settings|View flow|Trace this connection|Only this device)$/})
|
||||
.evaluateAll(buttons => buttons.map(button => getComputedStyle(button).backgroundColor));
|
||||
expect(new Set(fills).size).toBe(1);
|
||||
expect(new Set(boxes.map(box => box.height)).size).toBe(1);
|
||||
const lines: DOMRect[][] = [];
|
||||
for (const box of boxes) {
|
||||
const line = lines.find(line => Math.abs(line[0].top - box.top) <= 1);
|
||||
if (line) line.push(box);
|
||||
else lines.push([box]);
|
||||
}
|
||||
const gaps = lines.flatMap(line => line.slice(1).map((box, i) => box.left - line[i].right));
|
||||
const leading = lines.slice(1).map((line, i) => line[0].top - lines[i][0].bottom);
|
||||
for (const gap of [...gaps, ...leading]) expect(Math.abs(gap - gaps[0])).toBeLessThanOrEqual(1);
|
||||
expect(lines.every(line => Math.abs(line[0].left - boxes[0].left) <= 1)).toBe(true);
|
||||
// The destructive action ends the group on a line of its own.
|
||||
expect(lines.at(-1)).toEqual([boxes[6]]);
|
||||
const add = detail(page).getByRole('button', {name: 'Add rule', exact: true});
|
||||
const more = detail(page).getByRole('button', {name: 'More actions', exact: true});
|
||||
await expect(add).toBeVisible();
|
||||
await expect(more).toBeVisible();
|
||||
await expect(
|
||||
detail(page).getByRole('button', {name: /^(Show matched rule|View flow|Trace this connection|Only this device|Close connection)$/})
|
||||
).toHaveCount(0);
|
||||
const [primary, trigger] = [(await add.boundingBox())!, (await more.boundingBox())!];
|
||||
expect(trigger.height).toBe(primary.height);
|
||||
expect(Math.abs(trigger.y - primary.y)).toBeLessThanOrEqual(1);
|
||||
await more.click();
|
||||
// The destructive action ends the menu.
|
||||
await expect(page.getByRole('menu', {name: 'More actions'}).getByRole('menuitem')).toHaveText([
|
||||
'Show matched rule',
|
||||
"Edit matched rule's outbound settings",
|
||||
'View flow',
|
||||
'Trace this connection',
|
||||
'Only this device',
|
||||
'Close connection'
|
||||
]);
|
||||
});
|
||||
|
||||
const top = (page: import('@playwright/test').Page) => page.locator('.rp-top');
|
||||
@@ -628,7 +624,7 @@ test('the matched rule is edited from a connection: only its outbound changes, o
|
||||
const {api, requests} = await mockBackend(page);
|
||||
const before = (await api.config()).sources.find(source => source.id === 'src-main')!.content!;
|
||||
await page.goto('/#/connections?id=1');
|
||||
await detail(page).getByRole('button', {name: "Edit matched rule's outbound settings", exact: true}).click();
|
||||
await moreAction(detail(page), "Edit matched rule's outbound settings");
|
||||
await expect(page).toHaveURL(/#\/rules\?.*edit=/);
|
||||
const dialog = page.getByRole('dialog', {name: 'Edit outbound settings'});
|
||||
await expect(dialog.locator('.rp-code')).toContainText('domain(geosite: telegram)');
|
||||
|
||||
+25
-8
@@ -1,5 +1,5 @@
|
||||
import type {Locator} from '@playwright/test';
|
||||
import {expect, expectLoadFailures, mockBackend, test} from './fixtures';
|
||||
import {expect, expectLoadFailures, mockBackend, test, moreAction, moreItem} from './fixtures';
|
||||
import {createMockApi} from '../src/api/mock';
|
||||
|
||||
// The flat list exercises the virtualizer; grouping (the default) gets its own test below.
|
||||
@@ -381,7 +381,7 @@ test.describe('default view', () => {
|
||||
await page.setViewportSize({width: 1440, height: 900});
|
||||
await grid.locator('[role=row][aria-level="2"]').first().click();
|
||||
await expect(page.locator('.rp-panel').getByRole('heading')).toBeVisible();
|
||||
await page.locator('.rp-panel').getByRole('button', {name: 'Only this device', exact: true}).click();
|
||||
await moreAction(page.locator('.rp-panel'), 'Only this device');
|
||||
await expect(page).toHaveURL(/src=10\.0\.0\.\d+/);
|
||||
await expect(groups).toHaveCount(1);
|
||||
});
|
||||
@@ -391,7 +391,7 @@ test('closing a connection removes it from the list and clears the selection', a
|
||||
await page.goto('/#/connections?id=c-0001');
|
||||
const panel = page.locator('.rp-panel');
|
||||
await expect(panel.getByRole('heading', {name: 'api.telegram.org'})).toBeVisible();
|
||||
await panel.getByRole('button', {name: 'Close connection', exact: true}).click();
|
||||
await moreAction(panel, 'Close connection');
|
||||
await expect(page.locator('.rp-toast.positive')).toContainText('Closed api.telegram.org');
|
||||
await expect(page).toHaveURL(/#\/connections\?tab=list$/);
|
||||
await expect(page.locator('.rp-table [data-key="c-0001"]')).toHaveCount(0);
|
||||
@@ -399,10 +399,9 @@ test('closing a connection removes it from the list and clears the selection', a
|
||||
await page.goto('/#/connections?id=c-0002');
|
||||
const reason =
|
||||
'The backend has no userspace transfer to interrupt, so this connection cannot be closed. Connections the kernel forwards directly are of this kind.';
|
||||
const close = panel.getByRole('button', {name: 'Close connection', exact: true});
|
||||
const close = await moreItem(panel, 'Close connection');
|
||||
await expect(close).toBeDisabled();
|
||||
await expect(close).toHaveAccessibleDescription(reason);
|
||||
await expect(panel.getByText(reason)).toBeVisible();
|
||||
await expect(close).toContainText(reason);
|
||||
await expect(page.locator('.rp-table [data-key="c-0002"]')).toHaveCount(1);
|
||||
});
|
||||
|
||||
@@ -419,7 +418,7 @@ test('a connection opened while another closes stays selected', async ({page}) =
|
||||
await page.goto(`/#/connections?id=${encodeURIComponent(closed.id)}`);
|
||||
const panel = page.locator('.rp-panel');
|
||||
await expect(panel.getByRole('heading')).toBeVisible();
|
||||
await panel.getByRole('button', {name: 'Close connection', exact: true}).click();
|
||||
await moreAction(panel, 'Close connection');
|
||||
await page.locator(`.rp-table [data-key="${opened.id}"]`).click();
|
||||
await expect(page).toHaveURL(new RegExp(`[?&]id=${encodeURIComponent(opened.id)}(&|$)`));
|
||||
release();
|
||||
@@ -442,7 +441,25 @@ test('phone details retain routing diagnostics and omit unsupported flow actions
|
||||
'href',
|
||||
'#/rules?tab=list&rule=' + encodeURIComponent(row.rule_id!)
|
||||
);
|
||||
await expect(drawer.getByRole('button', {name: 'View flow', exact: true})).toHaveCount(0);
|
||||
await drawer.getByRole('button', {name: 'More actions', exact: true}).click();
|
||||
const menu = page.getByRole('menu', {name: 'More actions'});
|
||||
await expect(menu.getByRole('menuitem', {name: 'Trace this connection', exact: true})).toBeVisible();
|
||||
await expect(menu.getByRole('menuitem', {name: 'View flow', exact: true})).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('the connection More menu opens with Enter and gives focus back on Escape', async ({page}) => {
|
||||
await page.setViewportSize({width: 1440, height: 900});
|
||||
await page.goto('/#/connections?id=c-0001');
|
||||
const panel = page.locator('.rp-panel');
|
||||
const more = panel.getByRole('button', {name: 'More actions', exact: true});
|
||||
await more.focus();
|
||||
await page.keyboard.press('Enter');
|
||||
const menu = page.getByRole('menu', {name: 'More actions'});
|
||||
await expect(menu).toBeVisible();
|
||||
await expect(menu.getByRole('menuitem').first()).toBeFocused();
|
||||
await page.keyboard.press('Escape');
|
||||
await expect(menu).toHaveCount(0);
|
||||
await expect(more).toBeFocused();
|
||||
});
|
||||
|
||||
test('the connection list exports the filtered rows as CSV', async ({page}) => {
|
||||
|
||||
@@ -110,6 +110,17 @@ export async function scrollTableToEnd(grid: Locator) {
|
||||
}
|
||||
|
||||
export const detail = (page: Page) => page.locator('.rp-panel, .rp-drawer');
|
||||
// A panel's secondary actions sit in its trailing More menu. Opens it and returns the item; the menu itself is
|
||||
// portalled out of the panel.
|
||||
export async function moreItem(scope: Locator, name: string | RegExp, menu = 'More actions') {
|
||||
await scope.getByRole('button', {name: menu, exact: true}).click();
|
||||
return scope
|
||||
.page()
|
||||
.getByRole('menu', {name: menu})
|
||||
.getByRole('menuitem', {name, exact: typeof name === 'string'});
|
||||
}
|
||||
// Opens a panel's More menu and chooses an item.
|
||||
export const moreAction = async (scope: Locator, name: string | RegExp, menu?: string) => (await moreItem(scope, name, menu)).click();
|
||||
// The language and scheme the page takes from its next load.
|
||||
export const setAppearance = (page: Page, lang: string, scheme: string) =>
|
||||
page.evaluate(
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import {expect, faults, mockBackend, setAppearance, test} from './fixtures';
|
||||
import {expect, faults, mockBackend, setAppearance, test, moreAction} from './fixtures';
|
||||
|
||||
test.use({viewport: {width: 1440, height: 900}});
|
||||
|
||||
@@ -22,7 +22,7 @@ test.describe(() => {
|
||||
await panel.getByRole('link', {name: 'View connection', exact: true}).click();
|
||||
await expect(page).toHaveURL(/#\/connections\?id=1$/);
|
||||
await expect(page.locator('.rp-panel').getByRole('heading', {name: 'api.telegram.org'})).toBeVisible();
|
||||
await page.locator('.rp-panel').getByRole('button', {name: 'View flow', exact: true}).click();
|
||||
await moreAction(page.locator('.rp-panel'), 'View flow');
|
||||
await expect(page).toHaveURL(/#\/flows\?tab=records&id=flow-1$/);
|
||||
await page.locator('.rp-panel').getByRole('button', {name: 'Close', exact: true}).click();
|
||||
await expect(page).toHaveURL(/#\/flows\?tab=records$/);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {detail, expect, test} from './fixtures';
|
||||
import {detail, expect, test, moreAction} from './fixtures';
|
||||
|
||||
test.use({viewport: {width: 1440, height: 900}});
|
||||
|
||||
@@ -18,7 +18,7 @@ test('a trace link fills in the form without running it', async ({page}) => {
|
||||
|
||||
test('a connection opens the trace of its target and source', async ({page}) => {
|
||||
await page.goto('/#/connections?tab=list&id=1');
|
||||
await detail(page).getByRole('button', {name: 'Trace this connection', exact: true}).click();
|
||||
await moreAction(detail(page), 'Trace this connection');
|
||||
await expect(page).toHaveURL(/#\/rules\?tab=trace&network=tcp&domain=api\.telegram\.org&dst_ip=149\.154\.167\.220&dst_port=443&src_ip=10\.0\.0\.12$/);
|
||||
await expect(page.getByLabel('Domain', {exact: true})).toHaveValue('api.telegram.org');
|
||||
await expect(page.getByLabel('Destination IP', {exact: true})).toHaveValue('149.154.167.220');
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
ActionHelp,
|
||||
Badge,
|
||||
Button,
|
||||
ConfirmButton,
|
||||
@@ -14,7 +13,8 @@ import {
|
||||
TextField,
|
||||
ErrorMessage,
|
||||
Tabs,
|
||||
TextTooltip
|
||||
TextTooltip,
|
||||
MoreMenu
|
||||
} from '../../ui/ui';
|
||||
import Download from '../../ui/icons/Download';
|
||||
import {Traffic} from './Traffic';
|
||||
@@ -111,23 +111,31 @@ export function Connections(props: PageProps) {
|
||||
{cur.status}
|
||||
</Light>
|
||||
</HelpRow>
|
||||
{/* One button style for the actions; Close connection, the destructive one, always takes the last line. */}
|
||||
{/* One primary action; the rest go into the trailing More menu, Close connection, the destructive one, last. */}
|
||||
<div className="rp-cluster">
|
||||
<div className="rp-cluster">
|
||||
{vm.ruleAction.canAdd && <Button onPress={vm.ruleAction.openAdd}>{t('rule.add')}</Button>}
|
||||
{vm.ruleAction.canShow && <Button onPress={() => vm.showRule()}>{t('conn.showRule')}</Button>}
|
||||
{vm.ruleAction.canEdit && <Button onPress={() => vm.showRule(true)}>{t('conn.editRule')}</Button>}
|
||||
{vm.canViewFlow && <Button onPress={vm.showFlow}>{t('conn.viewFlow')}</Button>}
|
||||
{vm.canTrace && <Button onPress={vm.traceConnection}>{t('conn.trace')}</Button>}
|
||||
{cur.source && <Button onPress={vm.onlyClient}>{t('conn.onlyThisClient')}</Button>}
|
||||
</div>
|
||||
{vm.canClose && cur.closable && (
|
||||
<ActionHelp reason={cur.closeReason}>
|
||||
<Button negative quiet isPending={vm.close.pending} isDisabled={vm.close.disabled || !!cur.closeReason} onPress={vm.close.run}>
|
||||
{t('conn.close')}
|
||||
</Button>
|
||||
</ActionHelp>
|
||||
)}
|
||||
{vm.ruleAction.canAdd && <Button onPress={vm.ruleAction.openAdd}>{t('rule.add')}</Button>}
|
||||
<MoreMenu
|
||||
actions={[
|
||||
...(vm.ruleAction.canShow ? [{id: 'show-rule', label: t('conn.showRule'), onAction: () => vm.showRule()}] : []),
|
||||
...(vm.ruleAction.canEdit ? [{id: 'edit-rule', label: t('conn.editRule'), onAction: () => vm.showRule(true)}] : []),
|
||||
...(vm.canViewFlow ? [{id: 'view-flow', label: t('conn.viewFlow'), onAction: vm.showFlow}] : []),
|
||||
...(vm.canTrace ? [{id: 'trace', label: t('conn.trace'), onAction: vm.traceConnection}] : []),
|
||||
...(cur.source ? [{id: 'only-client', label: t('conn.onlyThisClient'), onAction: vm.onlyClient}] : []),
|
||||
...(vm.canClose && cur.closable
|
||||
? [
|
||||
{
|
||||
id: 'close',
|
||||
label: t('conn.close'),
|
||||
negative: true,
|
||||
isPending: vm.close.pending,
|
||||
isDisabled: vm.close.disabled || !!cur.closeReason,
|
||||
reason: cur.closeReason ?? undefined,
|
||||
onAction: vm.close.run
|
||||
}
|
||||
]
|
||||
: [])
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<Kv items={cur.fields} />
|
||||
<Kv
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import {expect, it} from 'vitest';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {MoreActionsList} from './ActionGroup';
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
it('lists the actions in order with the destructive one marked', () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MoreActionsList
|
||||
label="More actions"
|
||||
actions={[
|
||||
{id: 'trace', label: 'Trace', onAction: noop},
|
||||
{id: 'close', label: 'Close', negative: true, onAction: noop}
|
||||
]}
|
||||
/>
|
||||
);
|
||||
expect(markup).toContain('aria-label="More actions"');
|
||||
expect(markup.indexOf('Trace')).toBeLessThan(markup.indexOf('Close'));
|
||||
expect(markup).toMatch(/class="rp-item plain negative"[^>]*>.*Close/);
|
||||
expect(markup).not.toContain('aria-disabled');
|
||||
});
|
||||
|
||||
it('describes a disabled item with its reason, and an enabled one with none', () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MoreActionsList
|
||||
label="More actions"
|
||||
actions={[
|
||||
{id: 'edit', label: 'Edit', isDisabled: true, reason: 'The file is read-only', onAction: noop},
|
||||
{id: 'probe', label: 'Probe', reason: 'unused while enabled', onAction: noop}
|
||||
]}
|
||||
/>
|
||||
);
|
||||
// The item names every slot it may describe itself with; the reason's is among them.
|
||||
const reason = markup.match(/id="([^"]+)" slot="description">The file is read-only</);
|
||||
expect(reason).not.toBeNull();
|
||||
expect(markup).toMatch(new RegExp(`data-key="edit"`));
|
||||
expect(markup).toMatch(new RegExp(`aria-describedby="[^"]*\\b${reason![1]}\\b[^"]*"[^>]*data-key="edit"`));
|
||||
expect(markup).toContain('aria-disabled="true"');
|
||||
expect(markup).not.toContain('unused while enabled');
|
||||
});
|
||||
+53
-22
@@ -1,11 +1,23 @@
|
||||
import type {ReactNode} from 'react';
|
||||
import {Menu, MenuItem} from 'react-aria-components';
|
||||
import {Menu, MenuItem, Text} from 'react-aria-components';
|
||||
import MoreVertical from './icons/MoreVertical';
|
||||
import {useT} from '../i18n';
|
||||
import {Button} from './Button';
|
||||
import {MenuButton} from './Select';
|
||||
import {cx} from './cx';
|
||||
|
||||
export type Action = {id: string; label: string; icon?: ReactNode; onAction: () => void; isDisabled?: boolean; isPending?: boolean};
|
||||
export type Action = {
|
||||
id: string;
|
||||
label: string;
|
||||
icon?: ReactNode;
|
||||
onAction: () => void;
|
||||
isDisabled?: boolean;
|
||||
isPending?: boolean;
|
||||
// Why a disabled action cannot run. In a menu it is the item's description, in view under its name.
|
||||
reason?: string;
|
||||
// A destructive action, which the caller puts last.
|
||||
negative?: boolean;
|
||||
};
|
||||
|
||||
const ActionButton = ({action}: {action: Action}) => (
|
||||
<Button isDisabled={action.isDisabled} isPending={action.isPending} onPress={action.onAction}>
|
||||
@@ -19,7 +31,6 @@ const ActionButton = ({action}: {action: Action}) => (
|
||||
// phone. At the breakpoint and above they are plain buttons in the parent's flow. With overflowMode="wrap" they stay
|
||||
// buttons at every width and the parent wraps them, for a card whose actions are its content.
|
||||
export function ActionGroup({actions, overflowMode = 'collapse'}: {actions: Action[]; overflowMode?: 'collapse' | 'wrap'}) {
|
||||
const t = useT();
|
||||
if (overflowMode === 'wrap')
|
||||
return (
|
||||
<>
|
||||
@@ -41,28 +52,48 @@ export function ActionGroup({actions, overflowMode = 'collapse'}: {actions: Acti
|
||||
))}
|
||||
</span>
|
||||
<span className="rp-narrow-only">
|
||||
<MenuButton
|
||||
chevron={false}
|
||||
label={t('ui.moreActions')}
|
||||
content={
|
||||
<Menu
|
||||
aria-label={t('ui.moreActions')}
|
||||
disabledKeys={rest.filter(action => action.isDisabled || action.isPending).map(action => action.id)}
|
||||
onAction={key => rest.find(action => action.id === key)?.onAction()}
|
||||
>
|
||||
{rest.map(action => (
|
||||
<MenuItem key={action.id} id={action.id} className="rp-item plain" textValue={action.label}>
|
||||
{action.label}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
<MoreVertical />
|
||||
</MenuButton>
|
||||
<MoreMenu actions={rest} />
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// The menu a MoreMenu opens. A disabled item keeps its reason as its description, the way a disabled button names its
|
||||
// ActionHelp line.
|
||||
export function MoreActionsList({actions, label}: {actions: Action[]; label: string}) {
|
||||
return (
|
||||
<Menu
|
||||
aria-label={label}
|
||||
disabledKeys={actions.filter(action => action.isDisabled || action.isPending).map(action => action.id)}
|
||||
onAction={key => actions.find(action => action.id === key)?.onAction()}
|
||||
>
|
||||
{actions.map(action => (
|
||||
<MenuItem key={action.id} id={action.id} className={cx('rp-item plain', action.negative && 'negative')} textValue={action.label}>
|
||||
<span className="rp-item-text">
|
||||
<Text slot="label">{action.label}</Text>
|
||||
{action.isDisabled && action.reason && (
|
||||
<Text slot="description" className="desc reason">
|
||||
{action.reason}
|
||||
</Text>
|
||||
)}
|
||||
</span>
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
// A panel's secondary actions, in a trailing menu after its one primary button, as S2's ActionMenu. The caller puts a
|
||||
// destructive action last. A row of a table passes a label naming the row.
|
||||
export function MoreMenu({actions, label}: {actions: Action[]; label?: string}) {
|
||||
const t = useT();
|
||||
const name = label ?? t('ui.moreActions');
|
||||
if (actions.length === 0) return null;
|
||||
return (
|
||||
<MenuButton chevron={false} label={name} content={<MoreActionsList actions={actions} label={name} />}>
|
||||
<MoreVertical />
|
||||
</MenuButton>
|
||||
);
|
||||
}
|
||||
@@ -215,6 +215,13 @@
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
/* Why a disabled action cannot run takes its own line under the name. */
|
||||
.rp-item-text > .desc.reason {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
.rp-item.negative {
|
||||
color: var(--rp-negative-text);
|
||||
}
|
||||
.rp-item .desc {
|
||||
color: var(--rp-subtle);
|
||||
font-size: var(--rp-text-xs);
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ export {ContextualHelp, HelpRow, type Help} from './ContextualHelp';
|
||||
export {NodeTile, type NodeStatus, latencyTone, CardLink, RuleRef} from './Tile';
|
||||
export {Tag, Tags} from './Tag';
|
||||
export {ActionBar} from './ActionBar';
|
||||
export {ActionGroup, type Action} from './ActionGroup';
|
||||
export {ActionGroup, MoreMenu, type Action} from './ActionGroup';
|
||||
export {Card, cardClass} from './Card';
|
||||
export {Divider} from './Divider';
|
||||
export {VisuallyHidden} from 'react-aria';
|
||||
Reference in new issue
Block a user