refactor(ConsoleView): hoist Select options into useMemo, name shutdown sentinels, localise close label (P2-25, P2-26, P3-51)

Replace options IIFE with memoised runSelectOptions; extract magic-string
run-summary filters to SHUTDOWN_SUMMARY/WORKER_CRASH_SUMMARY constants;
localise Close console aria-label via console.close key.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 23:00:48 -04:00
1 parent 7df0d564e5
commit b58e64b555
3 files changed
+17 -7

No files matched your search

+1
View File
@@ -275,6 +275,7 @@ export const en: Record<string, string> = {
// ── Console panel ──
"console.title": "Console",
"console.noRuns": "No runs",
"console.close": "Close console",
// ── Entity labels (command palette sections) ──
"entity.sections": "Sections",
+1
View File
@@ -275,6 +275,7 @@ export const zh: Record<string, string> = {
// ── 控制台面板 ──
"console.title": "控制台",
"console.noRuns": "暂无运行",
"console.close": "关闭控制台",
// ── 实体标签(命令面板分类) ──
"entity.sections": "版块",
+15 -7
View File
@@ -6,6 +6,11 @@ import { ActionButton, Select, StatusPill } from "../components/ui";
import { formatMoney, formatTime } from "../lib/formatters";
import { useAppStore } from "../state/store";
// Run summaries that indicate the run is no longer active; these entries
// should not appear in the console run selector.
const SHUTDOWN_SUMMARY = "Application shut down.";
const WORKER_CRASH_SUMMARY = "Worker process crashed.";
interface ConsoleViewProps {
consoleOpen: boolean;
setConsoleOpen: (value: boolean) => void;
@@ -37,6 +42,14 @@ export function ConsoleView({
// the ref contents on re-render.
[selectedRun, logRevision, logBufferRef],
);
const runSelectOptions = useMemo(() => {
const activeRuns = runs.filter(
(run) => run.summary !== SHUTDOWN_SUMMARY && run.summary !== WORKER_CRASH_SUMMARY,
);
return activeRuns.length > 0
? activeRuns.map((run) => ({ value: run.id, label: run.summary || `Run ${run.id.slice(0, 8)}` }))
: [{ value: "", label: t("console.noRuns") }];
}, [runs, t]);
return (
<AnimatePresence>
{consoleOpen ? (
@@ -57,18 +70,13 @@ export function ConsoleView({
compact
value={selectedRun?.id ?? ""}
onChange={setSelectedRunId}
options={(() => {
const activeRuns = runs.filter((r) => r.summary !== "Application shut down." && r.summary !== "Worker process crashed.");
return activeRuns.length > 0
? activeRuns.map((run) => ({ value: run.id, label: run.summary || `Run ${run.id.slice(0, 8)}` }))
: [{ value: "", label: t("console.noRuns") }];
})()}
options={runSelectOptions}
/>
<button
type="button"
className="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 rounded-lg p-1 text-muted-foreground transition hover:text-foreground"
onClick={() => setConsoleOpen(false)}
aria-label="Close console"
aria-label={t("console.close")}
>
<X size={14} />
</button>