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:
@@ -1,34 +1,62 @@
|
||||
import { AnimatePresence, motion } from "motion/react";
|
||||
import type { KeyboardEvent, ReactNode } from "react";
|
||||
import { AnimatePresence, motion, useMotionValue, useSpring, useTransform, type MotionValue } from "motion/react";
|
||||
import { useLayoutEffect, useRef, type KeyboardEvent, type ReactNode } from "react";
|
||||
import type { Orbit, Snapshot } from "../../api";
|
||||
import { useScreenTransition } from "../../hooks/useScreenTransition";
|
||||
import { gentleSpring } from "../../lib/motion";
|
||||
import { useReducedMotion } from "../../hooks/useReducedMotion";
|
||||
import { formatBytes, formatWhen, orbitStatus, schedulePhrase } from "../../lib/format";
|
||||
import { SpringPane } from "../ui/SpringPane";
|
||||
|
||||
function TelemetryValue({ value, bytes = false }: { value?: number; bytes?: boolean }) {
|
||||
const reducedMotion = useReducedMotion();
|
||||
const target = useMotionValue(value ?? 0);
|
||||
const count = useSpring(target, gentleSpring);
|
||||
const text = useTransform(count, number => bytes ? formatBytes(Math.max(0, number)) : String(Math.round(number)));
|
||||
useLayoutEffect(() => {
|
||||
if (reducedMotion || value === undefined) count.jump(value ?? 0);
|
||||
target.set(value ?? 0);
|
||||
}, [value, reducedMotion, target, count]);
|
||||
|
||||
if (value === undefined) return "—";
|
||||
return (
|
||||
<>
|
||||
<span className="sr-only">{bytes ? formatBytes(value) : value}</span>
|
||||
<motion.span aria-hidden="true">{text}</motion.span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function TelemetryStrip({
|
||||
orbitCount, failedCount, snapCount, totalBytes,
|
||||
orbitCount, failedCount, snapCount, totalBytes, bigScreen, reducedMotion,
|
||||
}: {
|
||||
orbitCount?: number;
|
||||
failedCount: number;
|
||||
snapCount?: number;
|
||||
totalBytes: number;
|
||||
bigScreen: boolean;
|
||||
reducedMotion: boolean;
|
||||
}) {
|
||||
const strip = useRef<HTMLDListElement>(null);
|
||||
useScreenTransition(strip, bigScreen, reducedMotion, undefined, true);
|
||||
return (
|
||||
<dl className="vault-telemetry">
|
||||
<div><dt>Orbits</dt><dd>{orbitCount ?? "—"}</dd></div>
|
||||
<div><dt>Failed</dt><dd className={failedCount ? "telemetry-alert" : ""}>{orbitCount === undefined ? "—" : failedCount}</dd></div>
|
||||
<div><dt>Snapshots</dt><dd>{snapCount ?? "—"}</dd></div>
|
||||
<div><dt>Payload</dt><dd>{snapCount === undefined ? "—" : formatBytes(totalBytes)}</dd></div>
|
||||
<dl ref={strip} className="vault-telemetry">
|
||||
<div><dt>Orbits</dt><dd><TelemetryValue value={orbitCount} /></dd></div>
|
||||
<div><dt>Failed</dt><dd className={failedCount ? "telemetry-alert" : ""}>
|
||||
<TelemetryValue value={orbitCount === undefined ? undefined : failedCount} />
|
||||
</dd></div>
|
||||
<div><dt>Snapshots</dt><dd><TelemetryValue value={snapCount} /></dd></div>
|
||||
<div><dt>Payload</dt><dd><TelemetryValue value={snapCount === undefined ? undefined : totalBytes} bytes /></dd></div>
|
||||
</dl>
|
||||
);
|
||||
}
|
||||
|
||||
export function OrbitRegister({
|
||||
orbits, selected, message, onSelect, onManage,
|
||||
orbits, selected, message, bigScreen, onSelect, onManage,
|
||||
}: {
|
||||
orbits: Orbit[];
|
||||
selected?: string;
|
||||
message?: string;
|
||||
bigScreen: boolean;
|
||||
onSelect: (id: string) => void;
|
||||
onManage: () => void;
|
||||
}) {
|
||||
@@ -45,7 +73,8 @@ export function OrbitRegister({
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="vault-console orbit-register" aria-labelledby="register-title">
|
||||
<motion.section className="vault-console orbit-register" aria-labelledby="register-title" inert={bigScreen}
|
||||
initial={false} animate={{ opacity: bigScreen ? 0 : 1 }}>
|
||||
<header className="console-heading">
|
||||
<p className="instrument-label">Flight register</p>
|
||||
<h2 id="register-title">Orbits</h2>
|
||||
@@ -56,13 +85,14 @@ export function OrbitRegister({
|
||||
const status = orbitStatus(orbit.last_status);
|
||||
return (
|
||||
<motion.li key={orbit.id} layout={reducedMotion ? false : "position"}>
|
||||
<button
|
||||
<motion.button
|
||||
type="button"
|
||||
id={`register-${orbit.id}`}
|
||||
className="register-row"
|
||||
aria-pressed={selected === orbit.id}
|
||||
tabIndex={active === orbit.id ? 0 : -1}
|
||||
onClick={() => onSelect(orbit.id)}
|
||||
whileHover={{ backgroundColor: selected === orbit.id ? "#28252b" : "#1b1e23" }}
|
||||
onKeyDown={(event) => moveFocus(event, index)}
|
||||
>
|
||||
<span className={`register-signal signal-${status.tone}`} aria-hidden="true" />
|
||||
@@ -71,7 +101,7 @@ export function OrbitRegister({
|
||||
<small>{orbit.provider}</small>
|
||||
</span>
|
||||
<span className={`register-state tone-${status.tone}`}>{status.label}</span>
|
||||
</button>
|
||||
</motion.button>
|
||||
</motion.li>
|
||||
);
|
||||
})}
|
||||
@@ -81,22 +111,26 @@ export function OrbitRegister({
|
||||
{orbits.length ? "Manage orbits" : "Set up an orbit"} <span aria-hidden="true">↗</span>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</motion.section>
|
||||
);
|
||||
}
|
||||
|
||||
export function OrbitInspector({
|
||||
orbit, snapshots, snapshotMessage, capture, onSelectSnapshot,
|
||||
orbit, snapshots, snapshotMessage, capture, highlightedId, captureGlow, bigScreen, onSelectSnapshot,
|
||||
}: {
|
||||
orbit?: Orbit;
|
||||
snapshots: Snapshot[];
|
||||
snapshotMessage?: string;
|
||||
capture?: ReactNode;
|
||||
highlightedId?: string;
|
||||
captureGlow: MotionValue<number>;
|
||||
bigScreen: boolean;
|
||||
onSelectSnapshot: (id: string) => void;
|
||||
}) {
|
||||
const status = orbitStatus(orbit?.last_status ?? "idle");
|
||||
return (
|
||||
<section className="vault-console orbit-inspector" aria-labelledby="inspector-title">
|
||||
<motion.section className="vault-console orbit-inspector" aria-labelledby="inspector-title" inert={bigScreen}
|
||||
initial={false} animate={{ opacity: bigScreen ? 0 : 1 }}>
|
||||
<header className="console-heading">
|
||||
<p className="instrument-label">Orbit detail</p>
|
||||
<h2 id="inspector-title">{orbit?.name ?? "Select an orbit"}</h2>
|
||||
@@ -106,7 +140,7 @@ export function OrbitInspector({
|
||||
<AnimatePresence initial={false}>
|
||||
{orbit ? (
|
||||
<SpringPane key={orbit.id}>
|
||||
<p className="inspector-schedule">{schedulePhrase(orbit.schedule, orbit.dry_run)}</p>
|
||||
<p className="inspector-schedule">{schedulePhrase(orbit)}</p>
|
||||
<div className="inspector-capture">{capture}</div>
|
||||
<section className="inspector-history" aria-label="Snapshot history">
|
||||
<header>
|
||||
@@ -118,6 +152,9 @@ export function OrbitInspector({
|
||||
{snapshots.map((snapshot, index) => (
|
||||
<li key={snapshot.id}>
|
||||
<button id={`snapshot-${snapshot.id}`} type="button" className="snapshot-row" onClick={() => onSelectSnapshot(snapshot.id)}>
|
||||
{snapshot.id === highlightedId && (
|
||||
<motion.span className="snapshot-row-flash" aria-hidden="true" style={{ opacity: captureGlow }} />
|
||||
)}
|
||||
<span className="snapshot-glyph" aria-hidden="true">◇</span>
|
||||
<span>
|
||||
<strong>{formatWhen(snapshot.taken_at)}</strong>
|
||||
@@ -137,6 +174,6 @@ export function OrbitInspector({
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
</section>
|
||||
</motion.section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ import { motion } from "motion/react";
|
||||
import { useEffect, useId, useLayoutEffect, useRef, type ReactNode } from "react";
|
||||
|
||||
export function HUDPanel({
|
||||
open, title, subtitle, onClose, children,
|
||||
open, title, subtitle, onClose, children, inert,
|
||||
}: {
|
||||
open: boolean;
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
onClose: () => void;
|
||||
children: ReactNode;
|
||||
inert?: boolean;
|
||||
}) {
|
||||
const panel = useRef<HTMLElement>(null);
|
||||
const heading = useRef<HTMLHeadingElement>(null);
|
||||
@@ -61,7 +62,7 @@ export function HUDPanel({
|
||||
aria-labelledby={labelId}
|
||||
aria-describedby={display.subtitle ? descriptionId : undefined}
|
||||
aria-hidden={!open}
|
||||
inert={!open}
|
||||
inert={!open || inert}
|
||||
initial={false}
|
||||
animate={{ x: open ? "0%" : "100%" }}
|
||||
>
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { animate, motion, useMotionValue, useTransform, useVelocity } from "motion/react";
|
||||
import { useCallback, useId, useLayoutEffect, useRef, type PointerEvent } from "react";
|
||||
import { useScreenTransition } from "../../hooks/useScreenTransition";
|
||||
import { uiSpring } from "../../lib/motion";
|
||||
|
||||
export type HUDMode = "scene" | "orbits" | "wormhole" | "decay" | "reconstitute" | "snapshot";
|
||||
export type HUDMode = "scene" | "orbits" | "wormhole" | "reconstitute" | "snapshot";
|
||||
|
||||
const items = [
|
||||
export const hudItems = [
|
||||
{ id: "scene", label: "Vault", icon: "M4 9l8-4 8 4v6l-8 4-8-4z M4 9l8 4 8-4 M12 13v6" },
|
||||
{ id: "orbits", label: "Orbits", icon: "M21 12a9 5 0 1 1-18 0 9 5 0 1 1 18 0z M12 10.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 1 1 0-3z M18 5h.01" },
|
||||
{ id: "wormhole", label: "Outposts", icon: "M12 3v3 M4.2 7.5l2.6 1.5 M4.2 16.5 6.8 15 M12 18v3 M17.2 15l2.6 1.5 M17.2 9l2.6-1.5 M15.5 12a3.5 3.5 0 1 1-7 0 3.5 3.5 0 1 1 7 0z" },
|
||||
{ id: "decay", label: "Retention", icon: "M6 4h12 M6 20h12 M8 4v3l4 5-4 5v3 M16 4v3l-4 5 4 5v3" },
|
||||
{ id: "reconstitute", label: "Restore", icon: "M4 12a8 8 0 1 1 2.3 5.7 M4 6v6h6 M12 8v4l3 2" },
|
||||
] as const;
|
||||
|
||||
@@ -25,6 +25,7 @@ export function HUDRail({
|
||||
onSelect: (mode: HUDMode) => void;
|
||||
}) {
|
||||
const nav = useRef<HTMLElement>(null);
|
||||
useScreenTransition(nav, floating, reducedMotion);
|
||||
const slots = useRef<Slot[]>([]);
|
||||
const gesture = useRef<Gesture>(undefined);
|
||||
const suppressClick = useRef(false);
|
||||
@@ -33,7 +34,7 @@ export function HUDRail({
|
||||
const velocity = useVelocity(center);
|
||||
const tail = useTransform(() => center.get() - Math.max(-22, Math.min(22, velocity.get() * 0.032)));
|
||||
const id = useId();
|
||||
const activeIndex = Math.max(0, items.findIndex(item => item.id === active));
|
||||
const activeIndex = Math.max(0, hudItems.findIndex(item => item.id === active));
|
||||
|
||||
const snap = useCallback((index: number, immediate = false) => {
|
||||
const slot = slots.current[index];
|
||||
@@ -56,11 +57,10 @@ export function HUDRail({
|
||||
const element = nav.current!;
|
||||
const buttons = Array.from(element.querySelectorAll("button"));
|
||||
const measure = () => {
|
||||
const left = element.getBoundingClientRect().left + element.clientLeft;
|
||||
const next = buttons.map(button => {
|
||||
const rect = button.getBoundingClientRect();
|
||||
return { center: rect.left + rect.width / 2 - left, width: rect.width - 10 };
|
||||
});
|
||||
const next = buttons.map(button => ({
|
||||
center: button.offsetLeft + button.offsetWidth / 2,
|
||||
width: button.offsetWidth - 10,
|
||||
}));
|
||||
const changed = next.some((slot, index) =>
|
||||
slot.center !== slots.current[index]?.center || slot.width !== slots.current[index]?.width,
|
||||
);
|
||||
@@ -115,7 +115,7 @@ export function HUDRail({
|
||||
Math.abs(slot.center - projected) < Math.abs(slots.current[nearest].center - projected) ? index : nearest,
|
||||
0);
|
||||
if (next === activeIndex) snap(activeIndex);
|
||||
else onSelect(items[next].id);
|
||||
else onSelect(hudItems[next].id);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -144,44 +144,43 @@ export function HUDRail({
|
||||
}
|
||||
}}
|
||||
>
|
||||
{floating ? (
|
||||
<svg className="nav-liquid" aria-hidden="true">
|
||||
<defs>
|
||||
<filter id={`${id}-goo`} x="-25%" y="-50%" width="150%" height="200%">
|
||||
<feGaussianBlur in="SourceGraphic" stdDeviation="3.5" result="blur" />
|
||||
<feColorMatrix in="blur" type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -8" result="goo" />
|
||||
<feComposite in="SourceGraphic" in2="goo" operator="atop" />
|
||||
</filter>
|
||||
<linearGradient id={`${id}-fill`} x2="0%" y2="100%">
|
||||
<stop stopColor="#724a34" />
|
||||
<stop offset="100%" stopColor="#38251e" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g filter={`url(#${id}-goo)`} fill={`url(#${id}-fill)`}>
|
||||
<motion.ellipse cx={reducedMotion ? center : tail} cy="50%" rx="17" ry="13" />
|
||||
<motion.ellipse cx={center} cy="50%" rx="21" ry="17" />
|
||||
</g>
|
||||
</svg>
|
||||
) : (
|
||||
<>
|
||||
<span aria-hidden="true" className="nav-text-dock" />
|
||||
<motion.span aria-hidden="true" className="nav-underline" style={{ x: center, width }} />
|
||||
</>
|
||||
)}
|
||||
{items.map(({ id, label, icon }) => (
|
||||
<motion.svg className="nav-liquid" aria-hidden="true" initial={false} animate={{ opacity: floating ? 1 : 0 }}>
|
||||
<defs>
|
||||
<filter id={`${id}-goo`} x="-25%" y="-50%" width="150%" height="200%">
|
||||
<feGaussianBlur in="SourceGraphic" stdDeviation="3.5" result="blur" />
|
||||
<feColorMatrix in="blur" type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -8" result="goo" />
|
||||
<feComposite in="SourceGraphic" in2="goo" operator="atop" />
|
||||
</filter>
|
||||
<linearGradient id={`${id}-fill`} x2="0%" y2="100%">
|
||||
<stop stopColor="#724a34" />
|
||||
<stop offset="100%" stopColor="#38251e" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g filter={`url(#${id}-goo)`} fill={`url(#${id}-fill)`}>
|
||||
<motion.ellipse cx={reducedMotion ? center : tail} cy="50%" rx="17" ry="13" />
|
||||
<motion.ellipse cx={center} cy="50%" rx="21" ry="17" />
|
||||
</g>
|
||||
</motion.svg>
|
||||
<span aria-hidden="true" className="nav-text-dock" />
|
||||
<motion.span aria-hidden="true" className="nav-underline" style={{ x: center, width }}
|
||||
initial={false} animate={{ opacity: floating ? 0 : 1 }} />
|
||||
{hudItems.map(({ id, label, icon }) => (
|
||||
<button
|
||||
key={id}
|
||||
type="button"
|
||||
aria-label={floating ? label : undefined}
|
||||
aria-label={label}
|
||||
title={floating ? label : undefined}
|
||||
onClick={() => onSelect(id)}
|
||||
aria-current={active === id ? "page" : undefined}
|
||||
>
|
||||
{floating ? (
|
||||
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
|
||||
<path d={icon} />
|
||||
</svg>
|
||||
) : label}
|
||||
<motion.svg className="nav-icon" viewBox="0 0 24 24" width="22" height="22" fill="none"
|
||||
stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"
|
||||
initial={false} animate={{ opacity: floating ? 1 : 0 }}>
|
||||
<path d={icon} />
|
||||
</motion.svg>
|
||||
<motion.span className="nav-label" aria-hidden="true" initial={false} animate={{ opacity: floating ? 0 : 1 }}>
|
||||
{label}
|
||||
</motion.span>
|
||||
</button>
|
||||
))}
|
||||
</motion.nav>
|
||||
|
||||
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