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.

Add command palette keyboard selection

rcourtman7618d466975e
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 07e58af4df..b8312d35d1 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -2327,11 +2327,21 @@ remaining authenticated utility tabs.
The shared command palette now follows that same owner split.
`frontend-modern/src/components/shared/CommandPaletteModal.tsx` stays the
render shell, `frontend-modern/src/components/shared/useCommandPaletteState.ts`
-owns query state, open-reset/focus lifecycle, route-path wiring, and Enter-key
-selection, and `frontend-modern/src/components/shared/commandPaletteModel.ts`
+owns query state, selected-row keyboard state, open-reset/focus lifecycle,
+route-path wiring, and command selection, and
+`frontend-modern/src/components/shared/commandPaletteModel.ts`
owns canonical command construction plus query normalization and filtering
policy. Future command-palette work should extend those owners instead of
pushing route construction or search policy back into the shared shell.
+The OpenCode reference for this interaction is
+`packages/opencode/src/cli/cmd/run/footer.command.tsx` at `origin/dev`
+`e82542b8023a8374f29c23b70ec019c8f256354e`, where `RunCommandMenuBody`
+builds and filters command rows, holds selected menu state via
+`createFooterMenuState`, resets selection as the query changes, and routes
+keyboard movement and selection through `handleKey`. Pulse adapts that contract
+by keeping command construction in the shared palette model and command
+execution in the shared palette state / Assistant store instead of moving
+editor-specific command routing into the render shell.
Assistant command-palette actions are shell requests, not duplicated chat
logic. New session, session picker, model picker, Undo, and Redo commands must
flow through the shared `frontend-modern/src/stores/aiChat.ts` command request
diff --git a/frontend-modern/src/components/shared/CommandPaletteModal.tsx b/frontend-modern/src/components/shared/CommandPaletteModal.tsx
index 19cc71b1ed..60a5b7e552 100644
--- a/frontend-modern/src/components/shared/CommandPaletteModal.tsx
+++ b/frontend-modern/src/components/shared/CommandPaletteModal.tsx
@@ -42,27 +42,37 @@ export function CommandPaletteModal(props: CommandPaletteModalProps) {
when={commandPalette.filteredCommands().length > 0}
fallback={<div class="px-3 py-8 text-center text-sm text-muted">No matches found.</div>}
>
- <For each={commandPalette.filteredCommands()}>
- {(command) => (
- <button
- type="button"
- class="flex w-full items-center justify-between rounded-md px-3 py-2 text-left text-sm text-base-content hover:bg-surface-hover"
- onClick={() => handleSelect(command)}
- >
- <div>
- <div class="font-medium">{command.label}</div>
- <Show when={command.description}>
- <div class="text-xs text-muted">{command.description}</div>
- </Show>
- </div>
- <Show when={command.shortcut}>
- <span class="rounded border border-border-subtle bg-base px-2 py-1 text-[10px] font-medium text-base-content">
- {command.shortcut}
- </span>
- </Show>
- </button>
- )}
- </For>
+ <div role="listbox" aria-label="Command palette results">
+ <For each={commandPalette.filteredCommands()}>
+ {(command, index) => {
+ const selected = () => commandPalette.selectedIndex() === index();
+ return (
+ <button
+ type="button"
+ role="option"
+ aria-selected={selected()}
+ class={`flex w-full items-center justify-between rounded-md px-3 py-2 text-left text-sm text-base-content outline-none transition-colors hover:bg-surface-hover focus:bg-surface-hover ${
+ selected() ? 'bg-surface-hover' : ''
+ }`}
+ onClick={() => handleSelect(command)}
+ onMouseEnter={() => commandPalette.setSelectedIndex(index())}
+ >
+ <div>
+ <div class="font-medium">{command.label}</div>
+ <Show when={command.description}>
+ <div class="text-xs text-muted">{command.description}</div>
+ </Show>
+ </div>
+ <Show when={command.shortcut}>
+ <span class="rounded border border-border-subtle bg-base px-2 py-1 text-[10px] font-medium text-base-content">
+ {command.shortcut}
+ </span>
+ </Show>
+ </button>
+ );
+ }}
+ </For>
+ </div>
</Show>
</div>
</Dialog>
diff --git a/frontend-modern/src/components/shared/__tests__/CommandPaletteModal.test.tsx b/frontend-modern/src/components/shared/__tests__/CommandPaletteModal.test.tsx
index 7da1017484..d22ad719ba 100644
--- a/frontend-modern/src/components/shared/__tests__/CommandPaletteModal.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/CommandPaletteModal.test.tsx
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
-import type { JSX } from 'solid-js';
+import { createSignal, type JSX } from 'solid-js';
import type { Resource } from '@/types/resource';
import commandPaletteModalSource from '@/components/shared/CommandPaletteModal.tsx?raw';
import commandPaletteModelSource from '@/components/shared/commandPaletteModel.ts?raw';
@@ -130,13 +130,123 @@ describe('CommandPaletteModal', () => {
expect(screen.getByText('Go to vSphere Networks')).toBeInTheDocument();
expect(screen.getByText('/vmware/networks')).toBeInTheDocument();
- const commandLabels = screen.getAllByRole('button').map((button) => button.textContent ?? '');
+ const commandLabels = screen.getAllByRole('option').map((button) => button.textContent ?? '');
expect(commandLabels.findIndex((label) => label.includes('Open Pulse Assistant'))).toBe(0);
expect(commandLabels.findIndex((label) => label.includes('Go to Proxmox'))).toBeLessThan(
commandLabels.findIndex((label) => label.includes('Go to Machines')),
);
});
+ it('moves the selected command before Enter selection', async () => {
+ const onClose = vi.fn();
+ const openAssistant = vi.spyOn(aiChatStore, 'open').mockImplementation(() => {});
+ const requestCommand = vi.spyOn(aiChatStore, 'requestCommand').mockImplementation(() => {});
+ render(() => (
+ <CommandPaletteModal
+ isOpen={true}
+ onClose={onClose}
+ platformVisibility={platformVisibility}
+ />
+ ));
+
+ const input = screen.getByPlaceholderText('Type a command or search...');
+ expect(screen.getByRole('option', { name: /Open Pulse Assistant/ })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+
+ await fireEvent.keyDown(input, { key: 'ArrowDown' });
+
+ expect(screen.getByRole('option', { name: /Show Assistant commands/ })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+
+ await fireEvent.keyDown(input, { key: 'Enter' });
+
+ expect(onClose).toHaveBeenCalledTimes(1);
+ await waitFor(() => {
+ expect(requestCommand).toHaveBeenCalledWith('help');
+ });
+ expect(openAssistant).not.toHaveBeenCalled();
+ });
+
+ it('keeps the selected command across command-list recomputes before Enter selection', async () => {
+ const onClose = vi.fn();
+ const openAssistant = vi.spyOn(aiChatStore, 'open').mockImplementation(() => {});
+ const requestCommand = vi.spyOn(aiChatStore, 'requestCommand').mockImplementation(() => {});
+ const [visibilityVersion, setVisibilityVersion] = createSignal(0);
+ const dynamicPlatformVisibility = () => {
+ visibilityVersion();
+ return platformVisibility();
+ };
+ render(() => (
+ <CommandPaletteModal
+ isOpen={true}
+ onClose={onClose}
+ platformVisibility={dynamicPlatformVisibility}
+ />
+ ));
+
+ const input = screen.getByPlaceholderText('Type a command or search...');
+ await fireEvent.keyDown(input, { key: 'ArrowDown' });
+
+ expect(screen.getByRole('option', { name: /Show Assistant commands/ })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+
+ setVisibilityVersion(1);
+
+ await waitFor(() => {
+ expect(screen.getByRole('option', { name: /Show Assistant commands/ })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+ });
+
+ await fireEvent.keyDown(input, { key: 'Enter' });
+
+ expect(onClose).toHaveBeenCalledTimes(1);
+ await waitFor(() => {
+ expect(requestCommand).toHaveBeenCalledWith('help');
+ });
+ expect(openAssistant).not.toHaveBeenCalled();
+ });
+
+ it('wraps command palette keyboard movement', async () => {
+ render(() => (
+ <CommandPaletteModal
+ isOpen={true}
+ onClose={vi.fn()}
+ platformVisibility={platformVisibility}
+ />
+ ));
+
+ const input = screen.getByPlaceholderText('Type a command or search...');
+
+ await fireEvent.keyDown(input, { key: 'ArrowUp' });
+
+ expect(screen.getByRole('option', { name: /Go to Settings/ })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+
+ await fireEvent.keyDown(input, { key: 'Home' });
+
+ expect(screen.getByRole('option', { name: /Open Pulse Assistant/ })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+
+ await fireEvent.keyDown(input, { key: 'End' });
+
+ expect(screen.getByRole('option', { name: /Go to Settings/ })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+ });
+
it('routes Assistant model workflow commands through the Assistant store', async () => {
const onClose = vi.fn();
const requestCommand = vi.spyOn(aiChatStore, 'requestCommand').mockImplementation(() => {});
diff --git a/frontend-modern/src/components/shared/useCommandPaletteState.ts b/frontend-modern/src/components/shared/useCommandPaletteState.ts
index 5f09531246..ecf48e875b 100644
--- a/frontend-modern/src/components/shared/useCommandPaletteState.ts
+++ b/frontend-modern/src/components/shared/useCommandPaletteState.ts
@@ -26,6 +26,7 @@ export function useCommandPaletteState(props: CommandPaletteModalProps) {
const navigate = useNavigate();
const [query, setQuery] = createSignal('');
const [inputRef, setInputRef] = createSignal<HTMLInputElement>();
+ const [selectedIndex, setSelectedIndex] = createSignal(0);
const requestAssistantCommand = (action: AIChatCommandRequestAction) => {
runAfterPaletteSelection(() => aiChatStore.requestCommand(action));
@@ -66,22 +67,69 @@ export function useCommandPaletteState(props: CommandPaletteModalProps) {
props.onClose();
};
+ const moveSelection = (offset: number) => {
+ const total = filteredCommands().length;
+ if (total <= 0) return;
+ setSelectedIndex((index) => (((index + offset) % total) + total) % total);
+ };
+
const handleInputKeyDown = (event: KeyboardEvent) => {
- if (event.key !== 'Enter') return;
- const first = filteredCommands()[0];
- if (!first) return;
- event.preventDefault();
- handleSelect(first);
+ const total = filteredCommands().length;
+ switch (event.key) {
+ case 'ArrowDown':
+ event.preventDefault();
+ moveSelection(1);
+ return;
+ case 'ArrowUp':
+ event.preventDefault();
+ moveSelection(-1);
+ return;
+ case 'PageDown':
+ event.preventDefault();
+ moveSelection(5);
+ return;
+ case 'PageUp':
+ event.preventDefault();
+ moveSelection(-5);
+ return;
+ case 'Home':
+ event.preventDefault();
+ setSelectedIndex(0);
+ return;
+ case 'End':
+ event.preventDefault();
+ setSelectedIndex(Math.max(0, total - 1));
+ return;
+ case 'Enter': {
+ const selected = filteredCommands()[selectedIndex()] ?? filteredCommands()[0];
+ if (!selected) return;
+ event.preventDefault();
+ handleSelect(selected);
+ return;
+ }
+ }
};
+ createEffect(() => {
+ query();
+ setSelectedIndex(0);
+ });
+
+ createEffect(() => {
+ const total = filteredCommands().length;
+ setSelectedIndex((index) => (total > 0 ? Math.min(index, total - 1) : 0));
+ });
+
createEffect(() => {
if (props.isOpen) {
setQuery('');
+ setSelectedIndex(0);
queueMicrotask(() => inputRef()?.focus());
return;
}
setQuery('');
+ setSelectedIndex(0);
});
return {
@@ -89,6 +137,8 @@ export function useCommandPaletteState(props: CommandPaletteModalProps) {
handleInputKeyDown,
handleSelect,
query,
+ selectedIndex,
+ setSelectedIndex,
setInputRef,
setQuery,
};