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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
import { useNavigate } from '@solidjs/router';
import { createEffect, createMemo, createSignal } from 'solid-js';
import {
buildDockerPath,
buildKubernetesPath,
buildProxmoxPath,
buildStandalonePath,
buildTrueNASPath,
buildVmwarePath,
} from '@/routing/resourceLinks';
import { aiAvailabilityStore } from '@/stores/aiAvailability';
import {
buildCommandPaletteCommands,
filterCommandPaletteCommands,
type CommandPaletteModalCommand,
type CommandPaletteModalProps,
} from './commandPaletteModel';
export type { CommandPaletteModalCommand, CommandPaletteModalProps } from './commandPaletteModel';
export function useCommandPaletteState(props: CommandPaletteModalProps) {
const navigate = useNavigate();
const [query, setQuery] = createSignal('');
const [inputRef, setInputRef] = createSignal<HTMLInputElement>();
const [listboxRef, setListboxRef] = createSignal<HTMLDivElement>();
const [selectedIndex, setSelectedIndex] = createSignal(0);
// Same session capability that gates the Patrol tab: with AI off, the
// palette does not offer Patrol.
const aiAvailable = () => aiAvailabilityStore.enabled === true;
const commands = createMemo(() =>
buildCommandPaletteCommands({
paths: {
standalonePath: buildStandalonePath(),
proxmoxPath: buildProxmoxPath(),
dockerPath: buildDockerPath(),
kubernetesPath: buildKubernetesPath(),
kubernetesWorkloadsPath: buildKubernetesPath('workloads'),
trueNasPath: buildTrueNASPath(),
vmwarePath: buildVmwarePath(),
vmwareNetworksPath: buildVmwarePath('networks'),
},
platformVisibility: props.platformVisibility(),
patrolVisible: aiAvailable(),
navigate,
}),
);
const filteredCommands = createMemo(() => filterCommandPaletteCommands(commands(), query()));
const handleSelect = (command: CommandPaletteModalCommand) => {
command.action();
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) => {
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(() => {
selectedIndex();
filteredCommands();
queueMicrotask(() => {
listboxRef()
?.querySelector<HTMLElement>('[role="option"][aria-selected="true"]')
?.scrollIntoView?.({ block: 'nearest' });
});
});
createEffect(() => {
if (props.isOpen) {
setQuery('');
setSelectedIndex(0);
queueMicrotask(() => inputRef()?.focus());
return;
}
setQuery('');
setSelectedIndex(0);
});
return {
filteredCommands,
handleInputKeyDown,
handleSelect,
query,
selectedIndex,
setSelectedIndex,
setInputRef,
setListboxRef,
setQuery,
};
}