diff --git a/e2e/architecture.spec.ts b/e2e/architecture.spec.ts index c6f1988e..5c2f508f 100644 --- a/e2e/architecture.spec.ts +++ b/e2e/architecture.spec.ts @@ -527,7 +527,7 @@ test('new group validation refusal retains the dialog and its name without a suc }); await page.goto('/#/nodes?provider=inline'); await page.getByRole('button', {name: 'Add hk-01 to a group', exact: true}).click(); - await page.getByRole('menuitemradio', {name: 'New group…', exact: true}).click(); + await page.getByRole('menuitem', {name: 'New group…', exact: true}).click(); const dialog = page.getByRole('dialog', {name: 'New group…', exact: true}); await dialog.getByLabel('Name', {exact: true}).fill('retained-group'); const validating = page.waitForRequest('**/api/v1/config/validate'); diff --git a/e2e/builder.spec.ts b/e2e/builder.spec.ts index f2692900..d70f9e82 100644 --- a/e2e/builder.spec.ts +++ b/e2e/builder.spec.ts @@ -4,11 +4,11 @@ test('a node joins an existing group or a new one through the name filter', asyn await page.goto('/#/nodes?provider=inline'); await page.getByRole('button', {name: 'Add jp-01 to a group', exact: true}).click(); const menu = page.getByRole('menu'); - await expect(menu.getByRole('menuitemradio', {name: /^gaming/})).toHaveCount(0); - await menu.getByRole('menuitemradio', {name: /^resilient/}).click(); + await expect(menu.getByRole('menuitem', {name: /^gaming/})).toHaveCount(0); + await menu.getByRole('menuitem', {name: /^resilient/}).click(); await expect(page.locator('.rp-toast.positive')).toContainText('jp-01 added to resilient'); await page.getByRole('button', {name: 'Add sg-01 to a group', exact: true}).click(); - await page.getByRole('menuitemradio', {name: 'New group…', exact: true}).click(); + await page.getByRole('menuitem', {name: 'New group…', exact: true}).click(); const dialog = page.getByRole('dialog'); await dialog.getByLabel('Name').fill('backup'); await expect(dialog.getByRole('button', {name: /Selection policy/})).toContainText('Fastest on average'); diff --git a/src/features/connections/Connections.tsx b/src/features/connections/Connections.tsx index 465ab9e6..e75835d5 100644 --- a/src/features/connections/Connections.tsx +++ b/src/features/connections/Connections.tsx @@ -1,4 +1,3 @@ -import {Menu} from 'react-aria-components'; import { Badge, Button, @@ -8,8 +7,6 @@ import { LabeledSelect, Light, ChoiceMenu, - MenuButton, - MenuChoice, RuleRef, Segmented, TextField, @@ -51,24 +48,9 @@ export function Connections(props: PageProps) { {id: 'none', label: t('conn.ungrouped')} ]} /> - - {vm.columns.map(column => ( - - ))} - - } - > + {t('conn.columns')} - + {vm.filtered && ( )} - { - m.place( - String(group), - chosen.map(row => row.item) - ); - setSelected(new Set()); - }} - > - {targets.map(group => ( - - ))} - - } + items={targets.map(group => ({id: group.name, label: group.name}))} + onAction={group => { + m.place( + group, + chosen.map(row => row.item) + ); + setSelected(new Set()); + }} > {t('arrange.addSelected')} - + ); diff --git a/src/ui/Select.tsx b/src/ui/Select.tsx index 493bfa64..0a74d6e5 100644 --- a/src/ui/Select.tsx +++ b/src/ui/Select.tsx @@ -271,11 +271,49 @@ function SubmenuMenu({label, submenus}: {label: string; submenus: ChoiceSubmenu[ ); } +// The flat menu's items, read only once it opens: a table row's choices can cost a pass over the whole table. +type Items = Item[] | (() => Item[]); +function FlatMenu({ + label, + items, + selectionMode, + value, + onChange, + onAction +}: { + label: string; + items: Items; + selectionMode: 'none' | 'single' | 'multiple'; + value?: string | string[]; + onChange?: (key: string) => void; + onAction?: (key: string) => void; +}) { + return ( + onAction(String(key)))} + > + {(typeof items === 'function' ? items() : items).map(item => ( + + ))} + + ); +} + +type NotFlat = {items?: never; selectionMode?: never; value?: never; onChange?: never}; // A menu of choices: flat, in titled sections each with its own selection, or as rows that each open a submenu of -// sections. `onAction` hears every pick, including one of the already chosen item, for menus where picking it again +// sections. A flat menu marks one choice (`selectionMode` single, the default) or several (`multiple`, each pick +// toggling one through `onAction`); with neither `value` nor `selectionMode` it is an action menu that only runs +// `onAction`. `onAction` hears every pick, including one of the already chosen item, for menus where picking it again // clears it. export function ChoiceMenu({ items, + selectionMode, value, onChange, sections, @@ -284,12 +322,20 @@ export function ChoiceMenu({ ...props }: Omit & ( - | {items: Item[]; value: string; onChange: (key: string) => void; sections?: never; submenus?: never} - | {sections: ChoiceSection[]; items?: never; value?: never; onChange?: never; submenus?: never} - | {submenus: ChoiceSubmenu[]; items?: never; value?: never; onChange?: never; sections?: never} - ) & { - onAction?: (key: string) => void; - }) { + | { + items: Items; + selectionMode?: 'single'; + value: string; + onChange: (key: string) => void; + onAction?: (key: string) => void; + sections?: never; + submenus?: never; + } + | {items: Items; selectionMode: 'multiple'; value: string[]; onAction: (key: string) => void; onChange?: never; sections?: never; submenus?: never} + | {items: Items; onAction: (key: string) => void; selectionMode?: never; value?: never; onChange?: never; sections?: never; submenus?: never} + | (NotFlat & {sections: ChoiceSection[]; onAction?: (key: string) => void; submenus?: never}) + | (NotFlat & {submenus: ChoiceSubmenu[]; onAction?: never; sections?: never}) + )) { return ( ) : ( - onAction(String(key)))} - > - {items.map(item => ( - - ))} - + ) } />