Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Replace add-filter menu with direct selector

rcourtmana1b862ba9f58
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index e052438266..d01a4959a9 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -249,9 +249,13 @@ domain-specific visible copy, scope filters, status labels, and searchable
field coverage. Platform pages must not surface generic "rows/resources"
search affordances when the visible table is actually pods, VMs, datastores,
apps, mail gateways, storage pools, backup jobs, or another product-owned
-object model. Platform-owned filter menus must also exclude facet options from
-other platform scopes, even when the underlying shared surface is mounted from
-the same Workloads or Storage component.
+object model. Add-filter controls that sit beside a page-level search box must
+prefer direct selectable filter values over a second nested search affordance;
+a page that needs filter-value search must keep that search inside the active
+filter chip or an explicit page-owned advanced selector. Platform-owned filter
+selectors must also exclude facet options from other platform scopes, even when
+the underlying shared surface is mounted from the same Workloads or Storage
+component.
Patrol's primary assessment strip is descriptive only; it must not render a
Patrol-authored recommended next step, suggested prompt chips, or a secondary
action band inside the assessment shell. If the same assessment opens
diff --git a/frontend-modern/src/components/Recovery/__tests__/Recovery.test.tsx b/frontend-modern/src/components/Recovery/__tests__/Recovery.test.tsx
index 001805ddf8..b897ff482c 100644
--- a/frontend-modern/src/components/Recovery/__tests__/Recovery.test.tsx
+++ b/frontend-modern/src/components/Recovery/__tests__/Recovery.test.tsx
@@ -130,6 +130,45 @@ type RecoveryPointsResponse = {
meta: { page: number; limit: number; total: number; totalPages: number };
};
+const getAddFilterSelect = (container?: HTMLElement): HTMLSelectElement =>
+ (container ? within(container) : screen).getByRole('combobox', {
+ name: 'Filter',
+ }) as HTMLSelectElement;
+
+const getAddFilterOption = (
+ filterLabel: string,
+ optionLabel: string,
+ container?: HTMLElement,
+): HTMLOptionElement =>
+ within(getAddFilterSelect(container)).getByRole('option', {
+ name: `${filterLabel}: ${optionLabel}`,
+ }) as HTMLOptionElement;
+
+const findAddFilterOption = async (
+ filterLabel: string,
+ optionLabel: string,
+ container?: HTMLElement,
+): Promise<HTMLOptionElement> => {
+ let option: HTMLOptionElement | undefined;
+ await waitFor(() => {
+ option = getAddFilterOption(filterLabel, optionLabel, container);
+ expect(option).toBeInTheDocument();
+ });
+ return option!;
+};
+
+const selectAddFilterOption = async (
+ filterLabel: string,
+ optionLabel: string,
+ container?: HTMLElement,
+) => {
+ const option = await findAddFilterOption(filterLabel, optionLabel, container);
+ const select = getAddFilterSelect(container);
+ fireEvent.change(select, {
+ target: { value: option.value },
+ });
+};
+
const requestParam = (url: URL, key: string) => String(url.searchParams.get(key) || '').trim();
const matchesTextQuery = (haystackParts: unknown[], query: string): boolean => {
@@ -446,7 +485,7 @@ describe('Recovery', () => {
expect(historySearch.closest('div.relative')?.className).toContain('w-full');
expect(screen.getByText(/Showing 1 - 2 of 2 recovery points/i)).toBeInTheDocument();
expect(within(historyControls).queryByText(/day group/i)).not.toBeInTheDocument();
- expect(within(historyControls).getByRole('button', { name: 'Filter' })).toBeInTheDocument();
+ expect(within(historyControls).getByRole('combobox', { name: 'Filter' })).toBeInTheDocument();
const rangeControls = screen.getByRole('group', { name: 'Recovery activity range' });
expect(within(rangeControls).getByRole('button', { name: '7d' })).toBeInTheDocument();
expect(within(rangeControls).getByRole('button', { name: '30d' })).toBeInTheDocument();
@@ -719,14 +758,8 @@ describe('Recovery', () => {
fireEvent.click(screen.getByText('tank/legacy'));
// The legacy `providers: ['truenas']` payload should normalize into the
// canonical "TrueNAS" platform label on whichever surface renders it
- // (events table badge, "+ Filter > Platform" menu, or active chip).
- const eventsControls = await screen.findByRole('group', {
- name: /recovery events controls/i,
- });
- fireEvent.click(within(eventsControls).getByRole('button', { name: 'Filter' }));
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Platform' }));
- const platformMenu = await screen.findByRole('menu');
- expect(within(platformMenu).getByRole('button', { name: 'TrueNAS' })).toBeInTheDocument();
+ // (events table badge, direct Filter selector, or active chip).
+ expect(screen.getAllByText('TrueNAS').length).toBeGreaterThan(0);
} finally {
rollupsPayload.pop();
delete pointsByRollupId['ext:legacy-provider-rollup'];
@@ -808,14 +841,11 @@ describe('Recovery', () => {
expect(
within(inventoryTable).queryByText('Cluster', { exact: true }),
).not.toBeInTheDocument();
- // Open the inventory FilterBar's "+ Filter > Item Type" submenu and
- // assert the canonical K8s Cluster wording without the generic alias.
- fireEvent.click(screen.getByRole('button', { name: 'Filter' }));
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Item Type' }));
- const itemTypeMenu = await screen.findByRole('menu');
- expect(within(itemTypeMenu).getByRole('button', { name: 'K8s Cluster' })).toBeInTheDocument();
+ // Assert the inventory FilterBar's direct item-type vocabulary without
+ // the generic alias.
+ expect(await findAddFilterOption('Item Type', 'K8s Cluster')).toBeInTheDocument();
expect(
- within(itemTypeMenu).queryByRole('button', { name: 'Cluster' }),
+ within(getAddFilterSelect()).queryByRole('option', { name: 'Item Type: Cluster' }),
).not.toBeInTheDocument();
} finally {
rollupsPayload.pop();
@@ -1135,10 +1165,7 @@ describe('Recovery', () => {
fireEvent.click(await screen.findByRole('button', { name: 'Protection coverage' }));
expect(await screen.findByText('VM 123')).toBeInTheDocument();
- fireEvent.click(screen.getByRole('button', { name: 'Filter' }));
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Platform' }));
- const platformMenu = await screen.findByRole('menu');
- fireEvent.click(within(platformMenu).getByRole('button', { name: 'TrueNAS' }));
+ await selectAddFilterOption('Platform', 'TrueNAS');
await waitFor(() => {
expect(navigateSpy).toHaveBeenCalledWith(
@@ -1211,10 +1238,7 @@ describe('Recovery', () => {
expect(await screen.findByText('VM 123')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Clear all' })).not.toBeInTheDocument();
- fireEvent.click(screen.getByRole('button', { name: 'Filter' }));
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Platform' }));
- const platformMenu = await screen.findByRole('menu');
- fireEvent.click(within(platformMenu).getByRole('button', { name: 'TrueNAS' }));
+ await selectAddFilterOption('Platform', 'TrueNAS');
const clearAllButton = await screen.findByRole('button', { name: 'Clear all' });
fireEvent.click(clearAllButton);
@@ -1290,15 +1314,15 @@ describe('Recovery', () => {
render(() => <Recovery />);
const controls = await screen.findByRole('group', { name: /recovery events controls/i });
- // Both the "+ Filter" trigger and the Columns picker live inside the
+ // Both the direct Filter selector and the Columns picker live inside the
// events controls group; the item filter trigger is also grouped here.
- expect(within(controls).getByRole('button', { name: 'Filter' })).toBeInTheDocument();
+ expect(within(controls).getByRole('combobox', { name: 'Filter' })).toBeInTheDocument();
expect(within(controls).getByRole('button', { name: /columns/i })).toBeInTheDocument();
expect(
within(controls).getByTestId('recovery-history-item-filter-trigger'),
).toBeInTheDocument();
// Recovery events opted into shared saved views — the bookmark menu
- // sits next to "+ Filter" and persists named filter combos under the
+ // sits next to Filter and persists named filter combos under the
// canonical localStorage key.
expect(within(controls).getByRole('button', { name: 'Saved views' })).toBeInTheDocument();
});
@@ -1339,17 +1363,16 @@ describe('Recovery', () => {
it('keeps recovery filter surfaces on canonical platform vocabulary', async () => {
render(() => <Recovery />);
+ expect(await screen.findByText('VM 123')).toBeInTheDocument();
- // Events FilterBar surfaces "Platform" via the "+ Filter" menu rather
- // than as a labelled select, so assert the menu vocabulary instead.
- fireEvent.click(await screen.findByRole('button', { name: 'Filter' }));
- expect(await screen.findByRole('menuitem', { name: 'Platform' })).toBeInTheDocument();
+ // Events FilterBar surfaces "Platform" via the direct Filter selector, so
+ // assert the selector vocabulary instead.
+ expect(await findAddFilterOption('Platform', 'PVE')).toBeInTheDocument();
expect(screen.queryByText('All Providers')).not.toBeInTheDocument();
- fireEvent.keyDown(document, { key: 'Escape' });
fireEvent.click(await screen.findByRole('button', { name: 'Protection coverage' }));
- fireEvent.click(await screen.findByRole('button', { name: 'Filter' }));
- expect(await screen.findByRole('menuitem', { name: 'Platform' })).toBeInTheDocument();
+ expect(await screen.findByText('tank/apps')).toBeInTheDocument();
+ expect(await findAddFilterOption('Platform', 'PVE')).toBeInTheDocument();
expect(screen.queryByText('All Providers')).not.toBeInTheDocument();
});
@@ -1358,10 +1381,7 @@ describe('Recovery', () => {
expect(await screen.findByText('VM 123')).toBeInTheDocument();
- fireEvent.click(screen.getByRole('button', { name: 'Filter' }));
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Item Type' }));
- const itemTypeMenu = await screen.findByRole('menu');
- fireEvent.click(within(itemTypeMenu).getByRole('button', { name: 'Dataset' }));
+ await selectAddFilterOption('Item Type', 'Dataset');
await waitFor(() => {
expect(navigateSpy).toHaveBeenCalledWith(
@@ -1470,10 +1490,7 @@ describe('Recovery', () => {
render(() => <Recovery />);
fireEvent.click(await screen.findByRole('button', { name: 'Protection coverage' }));
- fireEvent.click(await screen.findByRole('button', { name: 'Filter' }));
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Protection state' }));
- const stateMenu = await screen.findByRole('menu');
- fireEvent.click(within(stateMenu).getByRole('button', { name: 'Never succeeded' }));
+ await selectAddFilterOption('Protection state', 'Never succeeded');
await waitFor(() => {
expect(navigateSpy).toHaveBeenCalledWith(
@@ -1634,11 +1651,7 @@ describe('Recovery', () => {
render(() => <Recovery />);
- fireEvent.click(await screen.findByRole('button', { name: /^filter$/i }));
-
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Cluster / Site' }));
- const clusterMenu = await screen.findByRole('menu');
- fireEvent.click(within(clusterMenu).getByRole('button', { name: 'dev-cluster' }));
+ await selectAddFilterOption('Cluster / Site', 'dev-cluster');
await waitFor(() => {
expect(navigateSpy).toHaveBeenCalledWith(
@@ -1716,16 +1729,8 @@ describe('Recovery', () => {
render(() => <Recovery />);
- fireEvent.click(await screen.findByRole('button', { name: /^filter$/i }));
-
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Host / Agent' }));
- const hostMenu = await screen.findByRole('menu');
- fireEvent.click(within(hostMenu).getByRole('button', { name: 'node-agent-1' }));
-
- fireEvent.click(await screen.findByRole('button', { name: /^filter$/i }));
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Namespace / Group' }));
- const namespaceMenu = await screen.findByRole('menu');
- fireEvent.click(within(namespaceMenu).getByRole('button', { name: 'tenant-a' }));
+ await selectAddFilterOption('Host / Agent', 'node-agent-1');
+ await selectAddFilterOption('Namespace / Group', 'tenant-a');
await waitFor(() => {
expect(navigateSpy).toHaveBeenCalledWith(
@@ -1813,10 +1818,7 @@ describe('Recovery', () => {
await screen.findByText(/Showing 1 - 1 of 1 recovery points/i);
- fireEvent.click(screen.getByRole('button', { name: /^filter$/i }));
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Cluster / Site' }));
- const clusterMenu = await screen.findByRole('menu');
- fireEvent.click(within(clusterMenu).getByRole('button', { name: 'dev-cluster' }));
+ await selectAddFilterOption('Cluster / Site', 'dev-cluster');
await waitFor(() => {
const urls = apiFetchMock.mock.calls.map((call) => String(call[0] || ''));
diff --git a/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx b/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx
index 754651eca6..797f225ce4 100644
--- a/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx
+++ b/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx
@@ -90,10 +90,11 @@ const setStorageFilter = (filterLabel: string, optionLabel: string) => {
fireEvent.click(within(inlineGroup).getByRole('button', { name: optionLabel }));
return;
}
- fireEvent.click(screen.getByRole('button', { name: 'Filter' }));
- fireEvent.click(screen.getByRole('menuitem', { name: filterLabel }));
- const menu = screen.getByRole('menu');
- fireEvent.click(within(menu).getByRole('button', { name: optionLabel }));
+ const addFilter = screen.getByRole('combobox', { name: 'Filter' });
+ const option = within(addFilter).getByRole('option', {
+ name: `${filterLabel}: ${optionLabel}`,
+ }) as HTMLOptionElement;
+ fireEvent.change(addFilter, { target: { value: option.value } });
};
const queryStorageChip = (label: string): HTMLButtonElement | null => {
@@ -1789,14 +1790,13 @@ describe('Storage', () => {
fireEvent.click(screen.getAllByRole('tab', { name: 'Physical Disks' })[0]!);
- // The "+ Filter > Node" submenu lists nodes that have disk resources.
+ // The direct Filter selector lists nodes that have disk resources.
// Hosts without disk resources (e.g. 'mini') are filtered out.
- fireEvent.click(screen.getByRole('button', { name: 'Filter' }));
- fireEvent.click(screen.getByRole('menuitem', { name: 'Node' }));
- const nodeMenu = screen.getByRole('menu');
- const optionLabels = Array.from(nodeMenu.querySelectorAll<HTMLButtonElement>('button'))
- .map((button) => (button.textContent || '').trim())
- .filter((text) => text.length > 0 && !text.startsWith('Node'));
+ const addFilter = screen.getByRole('combobox', { name: 'Filter' });
+ const optionLabels = Array.from(addFilter.querySelectorAll<HTMLOptionElement>('option'))
+ .map((option) => (option.textContent || '').trim())
+ .filter((text) => text.startsWith('Node: '))
+ .map((text) => text.replace(/^Node: /, ''));
expect(optionLabels).toContain('pve1');
expect(optionLabels).not.toContain('mini');
});
diff --git a/frontend-modern/src/components/Workloads/__tests__/WorkloadsFilter.test.tsx b/frontend-modern/src/components/Workloads/__tests__/WorkloadsFilter.test.tsx
index 8981d5a5c6..eba765945f 100644
--- a/frontend-modern/src/components/Workloads/__tests__/WorkloadsFilter.test.tsx
+++ b/frontend-modern/src/components/Workloads/__tests__/WorkloadsFilter.test.tsx
@@ -63,12 +63,15 @@ function makeProps(overrides: Partial<WorkloadsFilterProps> = {}): WorkloadsFilt
};
}
-const openAddFilterMenu = () => {
- fireEvent.click(screen.getByRole('button', { name: 'Filter' }));
-};
-
const inlineFilterGroup = (label: string) => screen.getByRole('group', { name: label });
+const addFilterSelect = () => screen.getByRole('combobox', { name: 'Filter' });
+
+const addFilterOption = (filterLabel: string, optionLabel: string) =>
+ within(addFilterSelect()).getByRole('option', {
+ name: `${filterLabel}: ${optionLabel}`,
+ }) as HTMLOptionElement;
+
const pickInlineFilter = (filterLabel: string, optionLabel: string) => {
fireEvent.click(
within(inlineFilterGroup(filterLabel)).getByRole('button', { name: optionLabel }),
@@ -76,10 +79,9 @@ const pickInlineFilter = (filterLabel: string, optionLabel: string) => {
};
const pickFromMenu = (menuItem: string, optionLabel: string) => {
- openAddFilterMenu();
- fireEvent.click(screen.getByRole('menuitem', { name: menuItem }));
- const menu = screen.getByRole('menu');
- fireEvent.click(within(menu).getByRole('button', { name: optionLabel }));
+ fireEvent.change(addFilterSelect(), {
+ target: { value: addFilterOption(menuItem, optionLabel).value },
+ });
};
describe('WorkloadsFilter', () => {
@@ -126,7 +128,7 @@ describe('WorkloadsFilter', () => {
render(() => <WorkloadsFilter {...makeProps()} />);
expect(inlineFilterGroup('Type')).toBeInTheDocument();
expect(inlineFilterGroup('Status')).toBeInTheDocument();
- expect(screen.queryByRole('button', { name: 'Filter' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('combobox', { name: 'Filter' })).not.toBeInTheDocument();
});
it('renders Grouped and List view-option buttons', () => {
@@ -376,7 +378,7 @@ describe('WorkloadsFilter', () => {
});
describe('host filter', () => {
- it('appears in the "+ Filter" menu when hostFilter prop is provided', () => {
+ it('appears in the direct Filter selector when hostFilter prop is provided', () => {
render(() => (
<WorkloadsFilter
{...makeProps({
@@ -391,16 +393,15 @@ describe('WorkloadsFilter', () => {
})}
/>
));
- openAddFilterMenu();
- expect(screen.getByRole('menuitem', { name: 'Agent' })).toBeInTheDocument();
+ expect(addFilterOption('Agent', 'pve1')).toBeInTheDocument();
});
it('does not appear when hostFilter prop is absent', () => {
render(() => <WorkloadsFilter {...makeProps()} />);
- expect(screen.queryByRole('button', { name: 'Filter' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('combobox', { name: 'Filter' })).not.toBeInTheDocument();
});
- it('calls onChange when host selection changes via chip popover', () => {
+ it('calls onChange when host selection changes through the direct selector', () => {
const onChange = vi.fn();
render(() => (
<WorkloadsFilter
@@ -427,19 +428,21 @@ describe('WorkloadsFilter', () => {
hostFilter: {
label: 'K8s cluster',
value: '',
- options: [{ value: '', label: 'All clusters' }],
+ options: [
+ { value: '', label: 'All clusters' },
+ { value: 'prod', label: 'prod' },
+ ],
onChange: vi.fn(),
},
})}
/>
));
- openAddFilterMenu();
- expect(screen.getByRole('menuitem', { name: 'K8s cluster' })).toBeInTheDocument();
+ expect(addFilterOption('K8s cluster', 'prod')).toBeInTheDocument();
});
});
describe('platform filter', () => {
- it('appears in the menu when platformFilter prop is provided', () => {
+ it('appears in the direct Filter selector when platformFilter prop is provided', () => {
render(() => (
<WorkloadsFilter
{...makeProps({
@@ -454,11 +457,10 @@ describe('WorkloadsFilter', () => {
})}
/>
));
- openAddFilterMenu();
- expect(screen.getByRole('menuitem', { name: 'Platform' })).toBeInTheDocument();
+ expect(addFilterOption('Platform', 'Proxmox')).toBeInTheDocument();
});
- it('calls onChange when platform selection changes via chip popover', () => {
+ it('calls onChange when platform selection changes through the direct selector', () => {
const onChange = vi.fn();
render(() => (
<WorkloadsFilter
@@ -480,7 +482,7 @@ describe('WorkloadsFilter', () => {
});
describe('namespace filter', () => {
- it('appears in the menu when namespaceFilter prop is provided', () => {
+ it('appears in the direct Filter selector when namespaceFilter prop is provided', () => {
render(() => (
<WorkloadsFilter
{...makeProps({
@@ -495,11 +497,10 @@ describe('WorkloadsFilter', () => {
})}
/>
));
- openAddFilterMenu();
- expect(screen.getByRole('menuitem', { name: 'Namespace' })).toBeInTheDocument();
+ expect(addFilterOption('Namespace', 'default')).toBeInTheDocument();
});
- it('calls onChange when namespace selection changes via chip popover', () => {
+ it('calls onChange when namespace selection changes through the direct selector', () => {
const onChange = vi.fn();
render(() => (
<WorkloadsFilter
@@ -521,7 +522,7 @@ describe('WorkloadsFilter', () => {
});
describe('container runtime filter', () => {
- it('appears in the menu only when viewMode is a container variant and containerRuntimeFilter is provided', () => {
+ it('appears in the direct selector only when viewMode is a container variant and containerRuntimeFilter is provided', () => {
const props = makeProps({
viewMode: vi.fn(() => 'container' as const),
containerRuntimeFilter: {
@@ -534,8 +535,7 @@ describe('WorkloadsFilter', () => {
},
});
render(() => <WorkloadsFilter {...props} />);
- openAddFilterMenu();
- expect(screen.getByRole('menuitem', { name: 'Runtime' })).toBeInTheDocument();
+ expect(addFilterOption('Runtime', 'docker')).toBeInTheDocument();
});
it('does not appear when viewMode is not a container variant', () => {
@@ -551,10 +551,10 @@ describe('WorkloadsFilter', () => {
},
});
render(() => <WorkloadsFilter {...props} />);
- expect(screen.queryByRole('button', { name: 'Filter' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('combobox', { name: 'Filter' })).not.toBeInTheDocument();
});
- it('calls onChange when runtime selection changes via chip popover', () => {
+ it('calls onChange when runtime selection changes through the direct selector', () => {
const onChange = vi.fn();
render(() => (
<WorkloadsFilter
diff --git a/frontend-modern/src/components/shared/FilterBar/AddFilterMenu.tsx b/frontend-modern/src/components/shared/FilterBar/AddFilterMenu.tsx
index c0c417efa3..bc098ef4c5 100644
--- a/frontend-modern/src/components/shared/FilterBar/AddFilterMenu.tsx
+++ b/frontend-modern/src/components/shared/FilterBar/AddFilterMenu.tsx
@@ -1,17 +1,9 @@
+import { Component, For, createMemo, createUniqueId } from 'solid-js';
import {
- Component,
- For,
- Show,
- createEffect,
- createMemo,
- createSignal,
- on,
- onCleanup,
-} from 'solid-js';
-import PlusIcon from 'lucide-solid/icons/plus';
-import ArrowLeftIcon from 'lucide-solid/icons/arrow-left';
-import SearchIcon from 'lucide-solid/icons/search';
-import { filterActionButtonClass } from '@/components/shared/FilterToolbar';
+ filterGroupClass,
+ filterLabelClass,
+ filterSelectClass,
+} from '@/components/shared/FilterToolbar';
import {
isFilterSet,
type FilterDef,
@@ -23,6 +15,22 @@ interface AddFilterMenuProps {
filters: FilterDef[];
}
+interface SelectableFilterOption {
+ token: string;
+ filter: FilterDef;
+ option: FilterSelectOption;
+}
+
+interface SelectableFilter {
+ filter: FilterDef;
+ options: SelectableFilterOption[];
+}
+
+interface SelectableFilterGroup {
+ key: FilterGroupKey;
+ filters: SelectableFilter[];
+}
+
const GROUP_LABELS: Record<FilterGroupKey, string> = {
scope: 'Scope',
status: 'Status',
@@ -31,317 +39,102 @@ const GROUP_LABELS: Record<FilterGroupKey, string> = {
const GROUP_ORDER: FilterGroupKey[] = ['scope', 'status', 'properties'];
-const matchesQuery = (label: string, query: string): boolean =>
- label.toLowerCase().includes(query);
+const FILTER_VALUE_SEPARATOR = '\u001f';
-export const AddFilterMenu: Component<AddFilterMenuProps> = (props) => {
- const [open, setOpen] = createSignal(false);
- const [activeFilterId, setActiveFilterId] = createSignal<string | null>(null);
- const [query, setQuery] = createSignal('');
- const [activeIndex, setActiveIndex] = createSignal(0);
- let containerRef: HTMLDivElement | undefined;
- let searchInputRef: HTMLInputElement | undefined;
-
- const close = () => {
- setOpen(false);
- setActiveFilterId(null);
- setQuery('');
- setActiveIndex(0);
- };
-
- const handleClickOutside = (event: MouseEvent) => {
- if (containerRef && !containerRef.contains(event.target as Node)) {
- close();
- }
- };
+const optionToken = (filter: FilterDef, option: FilterSelectOption): string =>
+ `${filter.id}${FILTER_VALUE_SEPARATOR}${option.value}`;
- const handleEscape = (event: KeyboardEvent) => {
- if (event.key !== 'Escape') return;
- if (activeFilterId()) {
- setActiveFilterId(null);
- setQuery('');
- setActiveIndex(0);
- return;
- }
- close();
- };
+export const AddFilterMenu: Component<AddFilterMenuProps> = (props) => {
+ const selectId = createUniqueId();
+ const availableFilters = createMemo(() => props.filters.filter((filter) => !isFilterSet(filter)));
- createEffect(() => {
- if (!open()) return;
- document.addEventListener('mousedown', handleClickOutside);
- document.addEventListener('keydown', handleEscape);
- onCleanup(() => {
- document.removeEventListener('mousedown', handleClickOutside);
- document.removeEventListener('keydown', handleEscape);
- });
- });
+ const selectableGroups = createMemo<SelectableFilterGroup[]>(() => {
+ const groups = new Map<FilterGroupKey, SelectableFilter[]>();
- // Reset query + active index whenever the menu opens or its phase changes
- // (filter list ↔ value sub-menu). Auto-focus the search input after the
- // phase change so typing is captured immediately.
- createEffect(
- on([open, activeFilterId], () => {
- setQuery('');
- setActiveIndex(0);
- if (open()) {
- queueMicrotask(() => searchInputRef?.focus());
- }
- }),
- );
+ for (const filter of availableFilters()) {
+ const options = filter
+ .options()
+ .filter((option) => option.value !== filter.defaultValue)
+ .map((option) => ({
+ token: optionToken(filter, option),
+ filter,
+ option,
+ }));
- const availableFilters = createMemo(() => props.filters.filter((f) => !isFilterSet(f)));
+ if (options.length === 0) continue;
- const groupedAvailable = createMemo(() => {
- const groups = new Map<FilterGroupKey, FilterDef[]>();
- for (const filter of availableFilters()) {
const key: FilterGroupKey = filter.group ?? 'properties';
const bucket = groups.get(key);
+ const selectable = { filter, options };
if (bucket) {
- bucket.push(filter);
+ bucket.push(selectable);
} else {
- groups.set(key, [filter]);
+ groups.set(key, [selectable]);
}
}
+
return GROUP_ORDER.filter((key) => groups.has(key)).map((key) => ({
key,
filters: groups.get(key)!,
}));
});
- const activeFilter = createMemo(() => {
- const id = activeFilterId();
- if (!id) return null;
- return props.filters.find((filter) => filter.id === id) ?? null;
- });
-
- const activeFilterPickableOptions = createMemo(() => {
- const filter = activeFilter();
- if (!filter) return [];
- return filter.options().filter((option) => option.value !== filter.defaultValue);
- });
-
- const filteredGroupedAvailable = createMemo(() => {
- const q = query().trim().toLowerCase();
- if (!q) return groupedAvailable();
- return groupedAvailable()
- .map((group) => ({
- key: group.key,
- filters: group.filters.filter((filter) => matchesQuery(filter.label, q)),
- }))
- .filter((group) => group.filters.length > 0);
- });
-
- const flatVisibleFilters = createMemo<FilterDef[]>(() =>
- filteredGroupedAvailable().flatMap((group) => group.filters),
- );
-
- const filteredOptions = createMemo<FilterSelectOption[]>(() => {
- const q = query().trim().toLowerCase();
- const options = activeFilterPickableOptions();
- if (!q) return options;
- return options.filter((option) => matchesQuery(option.label, q));
- });
-
- const isDisabled = () => availableFilters().length === 0;
-
- const navigableLength = () =>
- activeFilter() ? filteredOptions().length : flatVisibleFilters().length;
-
- // Clamp active index whenever the navigable list shrinks (e.g. typing
- // narrows the result set).
- createEffect(() => {
- const length = navigableLength();
- if (length === 0) {
- if (activeIndex() !== 0) setActiveIndex(0);
- return;
+ const selectableByToken = createMemo(() => {
+ const entries = new Map<string, SelectableFilterOption>();
+ for (const group of selectableGroups()) {
+ for (const filter of group.filters) {
+ for (const option of filter.options) {
+ entries.set(option.token, option);
+ }
+ }
}
- if (activeIndex() >= length) setActiveIndex(length - 1);
+ return entries;
});
- const commitActive = () => {
- const length = navigableLength();
- if (length === 0) return;
- const index = Math.max(0, Math.min(activeIndex(), length - 1));
- const filter = activeFilter();
- if (filter) {
- const option = filteredOptions()[index];
- if (option) {
- filter.setValue(option.value);
- close();
- }
- return;
- }
- const next = flatVisibleFilters()[index];
- if (next) {
- setActiveFilterId(next.id);
- }
- };
+ const isDisabled = () => selectableByToken().size === 0;
- const handleSearchKeyDown = (event: KeyboardEvent) => {
- const length = navigableLength();
- if (event.key === 'ArrowDown') {
- event.preventDefault();
- if (length === 0) return;
- setActiveIndex((index) => (index + 1) % length);
- } else if (event.key === 'ArrowUp') {
- event.preventDefault();
- if (length === 0) return;
- setActiveIndex((index) => (index - 1 + length) % length);
- } else if (event.key === 'Enter') {
- event.preventDefault();
- commitActive();
- } else if (event.key === 'Backspace' && query() === '' && activeFilterId()) {
- event.preventDefault();
- setActiveFilterId(null);
- }
+ const handleChange = (event: Event) => {
+ const select = event.currentTarget as HTMLSelectElement;
+ const selected = selectableByToken().get(select.value);
+ if (!selected) return;
+ selected.filter.setValue(selected.option.value);
+ select.value = '';
};
- const isActiveFilterIndex = (index: number) =>
- !activeFilter() && activeIndex() === index;
- const isActiveOptionIndex = (index: number) =>
- Boolean(activeFilter()) && activeIndex() === index;
-
return (
- <div ref={containerRef} class="relative inline-flex">
- <button
- type="button"
- onClick={() => {
- if (isDisabled()) return;
- setOpen((value) => !value);
- }}
+ <div class={`${filterGroupClass} flex-shrink-0`}>
+ <label for={selectId} class={filterLabelClass}>
+ Filter
+ </label>
+ <select
+ id={selectId}
+ value=""
+ onChange={handleChange}
disabled={isDisabled()}
- aria-haspopup="menu"
- aria-expanded={open()}
- class={`${filterActionButtonClass} disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent disabled:hover:text-muted`}
+ aria-label="Filter"
+ class={`${filterSelectClass} min-w-[9rem] disabled:cursor-not-allowed disabled:opacity-50`}
>
- <PlusIcon class="h-3 w-3" />
- Filter
- </button>
-
- <Show when={open()}>
- <div
- role="menu"
- class="absolute left-0 top-[calc(100%+0.25rem)] z-50 w-64 max-w-[calc(100vw-2rem)] rounded-md border border-border bg-surface shadow-lg"
- >
- <Show when={activeFilter()}>
- {(filter) => (
- <button
- type="button"
- onClick={() => {
- setActiveFilterId(null);
- setQuery('');
- }}
- class="flex w-full items-center gap-1.5 border-b border-border-subtle px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wide text-muted hover:bg-surface-hover"
- >
- <ArrowLeftIcon class="h-3 w-3" />
- {filter().label}
- </button>
- )}
- </Show>
-
- <div class="relative border-b border-border-subtle">
- <SearchIcon class="pointer-events-none absolute left-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-muted" />
- <input
- ref={searchInputRef}
- type="text"
- value={query()}
- onInput={(event) => setQuery(event.currentTarget.value)}
- onKeyDown={handleSearchKeyDown}
- placeholder={activeFilter() ? 'Search values...' : 'Search filters...'}
- aria-label={activeFilter() ? 'Search values' : 'Search filters'}
- class="w-full bg-transparent py-1.5 pl-7 pr-2 text-xs text-base-content placeholder-muted outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:rounded"
- />
- </div>
-
- <Show
- when={activeFilter()}
- fallback={
- <div class="max-h-64 overflow-y-auto py-1">
- <Show
- when={flatVisibleFilters().length > 0}
- fallback={
- <div class="px-3 py-2 text-xs text-muted">No filters match.</div>
- }
- >
- {(() => {
- let cursor = 0;
- return (
- <For each={filteredGroupedAvailable()}>
- {(group) => {
- const groupItems = group.filters.map((filter) => ({
- filter,
- index: cursor++,
- }));
- return (
- <div>
- <div class="px-3 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-wide text-muted">
- {GROUP_LABELS[group.key]}
- </div>
- <For each={groupItems}>
- {(item) => (
- <button
- type="button"
- role="menuitem"
- onMouseEnter={() => setActiveIndex(item.index)}
- onClick={() => setActiveFilterId(item.filter.id)}
- class={`flex w-full items-center justify-between px-3 py-1.5 text-left text-xs text-base-content hover:bg-surface-hover ${
- isActiveFilterIndex(item.index)
- ? 'bg-surface-hover'
- : ''
- }`}
- >
- <span>{item.filter.label}</span>
- <span class="text-muted" aria-hidden="true">
- {item.filter.options().length}
- </span>
- </button>
- )}
- </For>
- </div>
- );
- }}
- </For>
- );
- })()}
- </Show>
- </div>
- }
- >
- {(filter) => (
- <div class="max-h-64 overflow-y-auto py-1">
- <Show
- when={filteredOptions().length > 0}
- fallback={
- <div class="px-3 py-2 text-xs text-muted">
- {activeFilterPickableOptions().length === 0
- ? 'No options available.'
- : 'No options match.'}
- </div>
- }
- >
- <For each={filteredOptions()}>
- {(option, index) => (
- <button
- type="button"
- onMouseEnter={() => setActiveIndex(index())}
- onClick={() => {
- filter().setValue(option.value);
- close();
- }}
- class={`flex w-full items-center px-3 py-1.5 text-left text-xs text-base-content hover:bg-surface-hover ${
- isActiveOptionIndex(index()) ? 'bg-surface-hover' : ''
- }`}
- >
- {option.label}
- </button>
+ <option value="" disabled>
+ {isDisabled() ? 'No filters' : 'Add filter'}
+ </option>
+ <For each={selectableGroups()}>
+ {(group) => (
+ <optgroup label={GROUP_LABELS[group.key]}>
+ <For each={group.filters}>
+ {(filter) => (
+ <For each={filter.options}>
+ {(option) => (
+ <option value={option.token}>
+ {filter.filter.label}: {option.option.label}
+ </option>
)}
</For>
- </Show>
- </div>
- )}
- </Show>
- </div>
- </Show>
+ )}
+ </For>
+ </optgroup>
+ )}
+ </For>
+ </select>
</div>
);
};
diff --git a/frontend-modern/src/components/shared/FilterBar/FilterBar.test.tsx b/frontend-modern/src/components/shared/FilterBar/FilterBar.test.tsx
index 7203b17390..fd31ee990d 100644
--- a/frontend-modern/src/components/shared/FilterBar/FilterBar.test.tsx
+++ b/frontend-modern/src/components/shared/FilterBar/FilterBar.test.tsx
@@ -56,9 +56,11 @@ describe('FilterBar', () => {
fireEvent.click(within(typeGroup).getByRole('button', { name: 'VMs' }));
expect(setType).toHaveBeenCalledWith('vm');
- fireEvent.click(screen.getByRole('button', { name: 'Filter' }));
- expect(screen.queryByRole('menuitem', { name: 'Type' })).not.toBeInTheDocument();
- expect(screen.getByRole('menuitem', { name: 'Node' })).toBeInTheDocument();
+ const filterSelect = screen.getByRole('combobox', { name: 'Filter' });
+ expect(
+ within(filterSelect).queryByRole('option', { name: 'Type: VMs' }),
+ ).not.toBeInTheDocument();
+ expect(within(filterSelect).getByRole('option', { name: 'Node: pve1' })).toBeInTheDocument();
});
it('hides the add-filter trigger when every filter is inline', () => {
@@ -67,7 +69,7 @@ describe('FilterBar', () => {
));
expect(screen.getByRole('group', { name: 'Type' })).toBeInTheDocument();
- expect(screen.queryByRole('button', { name: 'Filter' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('combobox', { name: 'Filter' })).not.toBeInTheDocument();
});
it('shows clear-all beside inline controls when only inline filters are active', () => {
diff --git a/frontend-modern/src/components/shared/FilterBar/filterCatalog.ts b/frontend-modern/src/components/shared/FilterBar/filterCatalog.ts
index 7f2d7a486c..1f54c217ac 100644
--- a/frontend-modern/src/components/shared/FilterBar/filterCatalog.ts
+++ b/frontend-modern/src/components/shared/FilterBar/filterCatalog.ts
@@ -53,7 +53,7 @@ export interface FilterBarProps {
onClearAll?: () => void;
showClearAll?: Accessor<boolean>;
/**
- * When set, render a "Saved views" menu next to "+ Filter" that persists
+ * When set, render a "Saved views" menu next to the Filter selector that persists
* named filter combinations (URL query strings) to localStorage under
* `pulse:filterbar:saved-views:<savedViewsKey>`. Pages opt in per surface
* because the saved-view storage scope follows the page's URL state model.
diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
index 007e606ed6..8883a3031a 100644
--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
@@ -1500,9 +1500,9 @@ describe('shared primitive guardrails', () => {
expect(filterChipSource).toContain('onClick={() => clearFilter(props.filter)}');
expect(filterChipSource).toContain("event.key === 'Escape'");
expect(filterChipSource).not.toContain('MutationObserver');
- // Type-ahead parity with AddFilterMenu: chip popover has its own search
- // input + arrow nav + Enter-to-commit, with activeIndex seeded on the
- // currently-selected value so Enter without typing is a no-op.
+ // Chip popovers keep their own value search for already-active filters,
+ // with activeIndex seeded on the currently-selected value so Enter without
+ // typing is a no-op.
expect(filterChipSource).toContain('aria-label={`Filter ${props.filter.label} values`}');
expect(filterChipSource).toContain('filteredOptions');
expect(filterChipSource).toContain('handleSearchKeyDown');
@@ -1514,27 +1514,26 @@ describe('shared primitive guardrails', () => {
expect(addFilterMenuSource).toContain('isFilterSet,');
expect(addFilterMenuSource).toContain('type FilterDef,');
+ expect(addFilterMenuSource).toContain('type FilterSelectOption,');
expect(addFilterMenuSource).toContain("from './filterCatalog';");
expect(addFilterMenuSource).toContain('availableFilters');
expect(addFilterMenuSource).toContain('option.value !== filter.defaultValue');
expect(addFilterMenuSource).toContain('GROUP_ORDER');
- expect(addFilterMenuSource).toContain('aria-haspopup="menu"');
+ expect(addFilterMenuSource).toContain('filterGroupClass');
+ expect(addFilterMenuSource).toContain('filterSelectClass');
+ expect(addFilterMenuSource).toContain('aria-label="Filter"');
expect(addFilterMenuSource).not.toContain('LabeledFilterSelect');
- // Type-ahead: a search input narrows the visible filter (or value) list
- // and Enter commits the active item, so power users can pick a filter
- // with one click + a few keystrokes instead of three clicks.
- expect(addFilterMenuSource).toContain(
- "aria-label={activeFilter() ? 'Search values' : 'Search filters'}",
- );
- expect(addFilterMenuSource).toContain('filteredGroupedAvailable');
- expect(addFilterMenuSource).toContain('flatVisibleFilters');
- expect(addFilterMenuSource).toContain('filteredOptions');
- expect(addFilterMenuSource).toContain('handleSearchKeyDown');
- expect(addFilterMenuSource).toContain("event.key === 'ArrowDown'");
- expect(addFilterMenuSource).toContain("event.key === 'ArrowUp'");
- expect(addFilterMenuSource).toContain("event.key === 'Enter'");
- expect(addFilterMenuSource).toContain('commitActive');
- expect(addFilterMenuSource).toContain('queueMicrotask(() => searchInputRef?.focus())');
+ // Add-filter selection is intentionally direct: the shared primitive
+ // exposes a single native select grouped by filter category instead of a
+ // nested searchable filter picker, while active chips still own value
+ // refinement after a filter has been applied.
+ expect(addFilterMenuSource).toContain('selectableGroups');
+ expect(addFilterMenuSource).toContain('selectableByToken');
+ expect(addFilterMenuSource).toContain('<optgroup label={GROUP_LABELS[group.key]}>');
+ expect(addFilterMenuSource).toContain('{filter.filter.label}: {option.option.label}');
+ expect(addFilterMenuSource).toContain('selected.filter.setValue(selected.option.value)');
+ expect(addFilterMenuSource).not.toContain('Search filters');
+ expect(addFilterMenuSource).not.toContain('Search values');
// Saved views: per-page named filter combos persist to
// localStorage under `pulse:filterbar:saved-views:<key>`. The hook owns
@@ -1616,13 +1615,13 @@ describe('shared primitive guardrails', () => {
// WorkloadsFilter — Type/Status stay in the shared FilterBar catalog but
// render as inline primary controls; Node/Platform/Namespace/Runtime
- // remain menu-backed catalog filters. The xl-breakpoint
+ // remain selector-backed catalog filters. The xl-breakpoint
// segmented↔select swap retires here.
expect(workloadsFilterSource).toContain(
"import { FilterBar, type FilterDef, type FilterSelectOption } from '@/components/shared/FilterBar';",
);
expect(workloadsFilterSource).toContain('<FilterBar');
- expect(workloadsFilterSource).toContain('ariaLabel="Workloads filters"');
+ expect(workloadsFilterSource).toContain("ariaLabel={props.ariaLabel ?? 'Workloads filters'}");
expect(workloadsFilterSource).toContain("id: 'workloads-type'");
expect(workloadsFilterSource).toContain("id: 'workloads-status'");
expect(workloadsFilterSource).toContain('inline: true');
@@ -1649,7 +1648,9 @@ describe('shared primitive guardrails', () => {
);
expect(storagePageControlsSource).toContain('<FilterBar');
expect(storagePageControlsSource).toContain('<Subtabs');
- expect(storagePageControlsSource).toContain('ariaLabel="Storage filters"');
+ expect(storagePageControlsSource).toContain(
+ "ariaLabel={props.filterAriaLabel ?? 'Storage filters'}",
+ );
expect(storagePageControlsSource).toContain("id: 'storage-node'");
expect(storagePageControlsSource).toContain("id: 'storage-group-by'");
expect(storagePageControlsSource).toContain("id: 'storage-source'");