feat: add managed database capture and operator restore
PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
171
web/src/components/hud/VaultSearch.tsx
Normal file
171
web/src/components/hud/VaultSearch.tsx
Normal file
@@ -0,0 +1,171 @@
|
||||
import { useId, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
||||
import { animate, motion, useMotionValue, useTransform } from "motion/react";
|
||||
import type { Orbit, Snapshot } from "../../api";
|
||||
import { gentleSpring, uiSpring } from "../../lib/motion";
|
||||
import { createVaultSearch, type SearchResult } from "../../lib/vaultSearch";
|
||||
import { hudItems } from "./HUDRail";
|
||||
|
||||
const resultKey = ({ kind, id }: SearchResult) => `${kind}-${id}`;
|
||||
|
||||
export function SearchIcon() {
|
||||
return (
|
||||
<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor"
|
||||
strokeWidth="1.5" strokeLinecap="round" aria-hidden="true">
|
||||
<circle cx="10.5" cy="10.5" r="5.5" /><path d="m15 15 4 4" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export function VaultSearch({ open, reducedMotion, orbits, snapshots, orbitStatus, snapshotStatus, onClose, onSelect }: {
|
||||
open: boolean;
|
||||
reducedMotion: boolean;
|
||||
orbits?: Orbit[];
|
||||
snapshots?: Snapshot[];
|
||||
orbitStatus?: string;
|
||||
snapshotStatus?: string;
|
||||
onClose: () => void;
|
||||
onSelect: (result: SearchResult) => void;
|
||||
}) {
|
||||
const id = useId();
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
const close = useRef<HTMLButtonElement>(null);
|
||||
const overlay = useRef<HTMLDivElement>(null);
|
||||
const body = useRef<HTMLDivElement>(null);
|
||||
const progress = useMotionValue(0);
|
||||
const y = useTransform(progress, [0, 1], [-12, 0]);
|
||||
const height = useMotionValue(0);
|
||||
const [query, setQuery] = useState("");
|
||||
const [activeId, setActiveId] = useState<string>();
|
||||
const search = useMemo(() => createVaultSearch(hudItems, orbits, snapshots), [orbits, snapshots]);
|
||||
const groups = useMemo(() => search(query), [query, search]);
|
||||
const results = useMemo(() => groups.flatMap(group => group.results), [groups]);
|
||||
const active = results.find(result => resultKey(result) === activeId) ?? results[0];
|
||||
const activeKey = active && resultKey(active);
|
||||
const activeOption = activeKey && `${id}-${encodeURIComponent(activeKey)}`;
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!open) return;
|
||||
setQuery("");
|
||||
setActiveId(undefined);
|
||||
input.current?.focus({ preventScroll: true });
|
||||
const viewport = window.visualViewport;
|
||||
if (!viewport) return;
|
||||
const style = overlay.current!.style;
|
||||
const updateViewport = () => {
|
||||
style.setProperty("--search-viewport", `${viewport.height}px`);
|
||||
style.setProperty("--search-viewport-top", `${viewport.offsetTop}px`);
|
||||
};
|
||||
updateViewport();
|
||||
viewport.addEventListener("resize", updateViewport);
|
||||
viewport.addEventListener("scroll", updateViewport);
|
||||
return () => {
|
||||
viewport.removeEventListener("resize", updateViewport);
|
||||
viewport.removeEventListener("scroll", updateViewport);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (reducedMotion) progress.jump(Number(open));
|
||||
else animate(progress, Number(open), uiSpring);
|
||||
}, [open, reducedMotion, progress]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const element = body.current!;
|
||||
let target = element.offsetHeight;
|
||||
height.jump(target);
|
||||
const observer = new ResizeObserver(() => {
|
||||
const next = element.offsetHeight;
|
||||
if (next === target) return;
|
||||
target = next;
|
||||
if (reducedMotion) height.jump(next);
|
||||
else animate(height, next, gentleSpring);
|
||||
});
|
||||
observer.observe(element);
|
||||
return () => observer.disconnect();
|
||||
}, [height, reducedMotion]);
|
||||
|
||||
useLayoutEffect(() => () => {
|
||||
progress.stop();
|
||||
height.stop();
|
||||
}, [progress, height]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!open) return;
|
||||
if (activeKey !== activeId) setActiveId(activeKey);
|
||||
if (activeOption) document.getElementById(activeOption)?.scrollIntoView({ block: "nearest" });
|
||||
}, [open, activeId, activeKey, activeOption, results]);
|
||||
|
||||
function handleKeys(event: KeyboardEvent) {
|
||||
if (event.key === "Tab") {
|
||||
event.preventDefault();
|
||||
(event.target === input.current ? close.current : input.current)?.focus();
|
||||
return;
|
||||
}
|
||||
if (event.target !== input.current || event.nativeEvent.isComposing || event.keyCode === 229) return;
|
||||
if (event.key === "Enter" && active && !event.repeat) {
|
||||
event.preventDefault();
|
||||
onSelect(active);
|
||||
} else if ((event.key === "ArrowDown" || event.key === "ArrowUp") && results.length) {
|
||||
event.preventDefault();
|
||||
const offset = event.key === "ArrowDown" ? 1 : -1;
|
||||
const next = results[(results.indexOf(active) + offset + results.length) % results.length];
|
||||
setActiveId(resultKey(next));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<motion.div ref={overlay} className="search-overlay" inert={!open} style={{ opacity: progress }} onClick={event => {
|
||||
if (event.target === event.currentTarget) onClose();
|
||||
}}>
|
||||
<motion.section className="search-panel" style={{ y }} role="dialog" aria-modal="true" aria-label="Vault search" onKeyDown={handleKeys}>
|
||||
<div className="search-field">
|
||||
<SearchIcon />
|
||||
<input ref={input} type="text" role="combobox" aria-label="Search vault"
|
||||
aria-autocomplete="list" aria-expanded={!!results.length} aria-controls={`${id}-results`}
|
||||
aria-activedescendant={activeOption}
|
||||
autoComplete="off" autoCapitalize="none" spellCheck={false} placeholder="Search the vault…"
|
||||
value={query} onChange={event => {
|
||||
setQuery(event.currentTarget.value);
|
||||
setActiveId(undefined);
|
||||
}} />
|
||||
<button ref={close} className="console-control search-close" type="button" aria-label="Close search" onClick={onClose}>
|
||||
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor"
|
||||
strokeWidth="1.5" strokeLinecap="round" aria-hidden="true"><path d="m7 7 10 10M17 7 7 17" /></svg>
|
||||
</button>
|
||||
</div>
|
||||
<motion.div className="search-list-frame" style={{ height }}>
|
||||
<div ref={body} className="search-body">
|
||||
<div role="listbox" id={`${id}-results`} aria-label="Search results" hidden={!results.length}>
|
||||
{groups.map(group => (
|
||||
<div key={group.label} role="group" aria-label={group.label}>
|
||||
<p className="instrument-label search-group" aria-hidden="true">{group.label}</p>
|
||||
{group.results.map(result => {
|
||||
const key = resultKey(result);
|
||||
const icon = result.kind === "navigation" ? result.icon
|
||||
: result.kind === "orbit" ? hudItems[1].icon : "M12 3l8 9-8 9-8-9z M12 9v6";
|
||||
return (
|
||||
<div key={key} id={`${id}-${encodeURIComponent(key)}`} role="option" className="search-result"
|
||||
aria-selected={activeKey === key} onMouseDown={event => event.preventDefault()} onClick={() => onSelect(result)}>
|
||||
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor"
|
||||
strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={icon} /></svg>
|
||||
<span className="search-result-text">
|
||||
<span>{result.label}</span>
|
||||
{result.detail && <small>{result.detail}</small>}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<p className="search-status" role="status">
|
||||
<span>{results.length ? `${results.length} ${query.trim() ? "results shown" : "destinations"}` : "No matching results."}</span>
|
||||
{orbitStatus && <span>{orbitStatus}</span>}
|
||||
{snapshotStatus && <span>{snapshotStatus}</span>}
|
||||
</p>
|
||||
</div>
|
||||
</motion.div>
|
||||
</motion.section>
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user