Files
Reims-Go/frontend/src/components/Sidebar.tsx
T
千川白浪andClaude Opus 5.5 4bea654736 feat: add Wails desktop GUI and stage-0 UI redesign
Wails shell over the existing Go core (app.go, main.go, wails.json,
build/), with a React frontend for the VM list, VM detail, host page,
create wizard and settings, plus process helpers for the driver and
runtime packages.

UI redesign stage 0 (docs/ui-redesign.md):
- VM actions live in the page header: one primary action per state,
  icon-only secondary actions with tooltips, the rest in a "..." menu
- install guide is a single card with the only "eject installer" button
- summary is an icon + value row; paths, ICD, CPU model and runtime hash
  moved to a collapsed "technical details" section
- logs no longer auto-open; a status bar shows merged download progress
  and an error count; the log view sticks to the bottom
- busy states on actions, toasts for results, custom delete dialog with
  "keep disk files"
- design tokens, Windows font stack, integer type scale, no inline styles
- keyboard: sidebar listbox navigation, focus rings, Ctrl+N / Ctrl+, / Ctrl+L
- copy rewritten per the restraint rules in §4.5
- Radix primitives and lucide icons replace hand-rolled widgets

Backend: OpenVMFolder binding to show a VM's directory in Explorer.
Docs: shell-design.md revised for decisions D1 and D4.
Vite dev server pinned to 127.0.0.1 so `wails dev` can reach it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 03:09:39 -07:00

81 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Cpu, Monitor, Plus } from 'lucide-react'
import React, { useRef } from 'react'
import { I18nKey, t } from '../i18n'
import { Locale, VMListItem } from '../types'
import { IconButton, StatusShape, Tip, statusKind } from '../ui/controls'
export const HOST_ID = '__host__'
interface Props {
locale: Locale
vms: VMListItem[]
transitions: Record<string, string>
selected: string
hostReady: boolean
onSelect: (id: string) => void
onNew: () => void
}
export const Sidebar: React.FC<Props> = ({ locale, vms, transitions, selected, hostReady, onSelect, onNew }) => {
const listRef = useRef<HTMLDivElement>(null)
const ids = [...vms.map((v) => v.name), HOST_ID]
// Listbox keyboard model: ↑/↓/Home/End move selection and focus together.
const onKeyDown = (e: React.KeyboardEvent) => {
const idx = ids.indexOf(selected)
let next = -1
if (e.key === 'ArrowDown') next = Math.min(ids.length - 1, idx + 1)
else if (e.key === 'ArrowUp') next = Math.max(0, idx - 1)
else if (e.key === 'Home') next = 0
else if (e.key === 'End') next = ids.length - 1
if (next < 0) return
e.preventDefault()
onSelect(ids[next])
listRef.current?.querySelector<HTMLElement>(`[data-id="${CSS.escape(ids[next])}"]`)?.focus()
}
const item = (id: string, label: string, icon: React.ReactNode, stateLabel: string, kind: ReturnType<typeof statusKind>) => (
<button
key={id}
type="button"
role="option"
data-id={id}
className="nav-item"
aria-selected={selected === id}
aria-label={`${label},${stateLabel}`}
tabIndex={selected === id ? 0 : -1}
onClick={() => onSelect(id)}
>
{icon}
<span className="nav-label">{label}</span>
<Tip label={stateLabel} side="right">
<span className="hstack"><StatusShape kind={kind} /></span>
</Tip>
</button>
)
return (
<aside className="sidebar">
<div className="sidebar-head">
<span>{t(locale, 'sidebarVMs')}</span>
<IconButton small label={t(locale, 'newVM')} shortcut="Ctrl+N" icon={<Plus size={16} />} onClick={onNew} tipSide="right" />
</div>
<div className="nav" role="listbox" aria-label={t(locale, 'sidebarVMs')} ref={listRef} onKeyDown={onKeyDown}>
{vms.length === 0 && <div className="nav-empty">{t(locale, 'emptyVMs')}</div>}
{vms.map((vm) => {
const st = transitions[vm.name] ?? vm.state
return item(vm.name, vm.name, <Monitor size={16} />, t(locale, `state_${st}` as I18nKey), statusKind(st))
})}
<div className="sidebar-sep" role="presentation" />
{item(
HOST_ID,
t(locale, 'sidebarHost'),
<Cpu size={16} />,
t(locale, hostReady ? 'hostReady' : 'hostNeedsAction'),
hostReady ? 'running' : 'warn',
)}
</div>
</aside>
)
}