feat(ui): display names for VMs and a side-by-side summary on wide windows
- The VM note now acts as its display name: shown as the page title and in the sidebar, renamed in place by clicking the title (or More → Change Display Name…). The VM name stays the identifier for folders, CLI and reims-ctl; it shows in the title's tooltip and in Technical details. Clearing the field or typing the VM name removes the display name. - When the content column is at least 760 px wide (container query), the screen and actions sit on the left and the summary becomes one labelled column on the right, so long GPU names are no longer cut off. Narrower windows keep the stacked layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ab49d79a71
commit
704f68cdce
5 files changed
+148
-70
No files matched your search
@@ -177,6 +177,21 @@ export const App: React.FC = () => {
|
||||
api.GetVMDetail(selectedVM.name).then(setDetail).catch(() => setDetail(null))
|
||||
}, [selectedVM?.name, state])
|
||||
|
||||
// Display names (the VM's note, .reims-go-note): shown in place of the VM's
|
||||
// name in the sidebar and page title; the name itself stays the identifier.
|
||||
const [displayNames, setDisplayNames] = useState<Record<string, string>>({})
|
||||
const vmNamesKey = vms.map((v) => v.name).join('|')
|
||||
useEffect(() => {
|
||||
let live = true
|
||||
for (const vm of vms) {
|
||||
api.GetVMNote(vm.name)
|
||||
.then((n) => { if (live) setDisplayNames((m) => ({ ...m, [vm.name]: (n ?? '').trim() })) })
|
||||
.catch(() => {})
|
||||
}
|
||||
return () => { live = false }
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [vmNamesKey])
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedVM) { setVmStats(null); return }
|
||||
let live = true
|
||||
@@ -647,6 +662,7 @@ export const App: React.FC = () => {
|
||||
selected={selected}
|
||||
hostReady={hostReady}
|
||||
onSelect={setSelected}
|
||||
displayNames={displayNames}
|
||||
onActivate={primaryAction}
|
||||
onNew={openWizard}
|
||||
onVMContextAction={onSidebarContextAction}
|
||||
@@ -672,6 +688,8 @@ export const App: React.FC = () => {
|
||||
<VMPage
|
||||
locale={locale}
|
||||
name={selectedVM.name}
|
||||
displayName={displayNames[selectedVM.name] ?? ''}
|
||||
onDisplayNameSaved={(n) => setDisplayNames((m) => ({ ...m, [selectedVM.name]: n }))}
|
||||
state={effectiveState}
|
||||
detail={detail}
|
||||
stats={vmStats}
|
||||
|
||||
@@ -18,6 +18,8 @@ interface Props {
|
||||
selected: string
|
||||
hostReady: boolean
|
||||
onSelect: (id: string) => void
|
||||
/** VM name → display name (its note); empty or missing shows the name. */
|
||||
displayNames?: Record<string, string>
|
||||
/** Double-click on a VM: its main action (start, or show its window). */
|
||||
onActivate?: (name: string) => void
|
||||
onNew: () => void
|
||||
@@ -47,7 +49,7 @@ function useVMIcons(vms: VMListItem[], transitions: Record<string, string>) {
|
||||
}
|
||||
|
||||
export const Sidebar: React.FC<Props> = ({
|
||||
locale, vms, transitions, selected, hostReady, onSelect, onActivate, onNew, onVMContextAction, downloading,
|
||||
locale, vms, transitions, selected, hostReady, onSelect, displayNames = {}, onActivate, onNew, onVMContextAction, downloading,
|
||||
}) => {
|
||||
const tr = (k: I18nKey) => t(locale, k)
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
@@ -116,7 +118,7 @@ export const Sidebar: React.FC<Props> = ({
|
||||
const src = icons[vm.name]
|
||||
const trigger = navBtn(
|
||||
vm.name,
|
||||
vm.name,
|
||||
displayNames[vm.name] || vm.name,
|
||||
src ? <img src={src} alt="" draggable={false} /> : <Monitor size={13} />,
|
||||
src ? 'nav-icon-thumb' : 'nav-icon-vm',
|
||||
t(locale, `state_${st}` as I18nKey),
|
||||
|
||||
@@ -79,7 +79,11 @@ export const PRIMARY_SHORTCUT = 'Ctrl+Enter'
|
||||
|
||||
interface Props {
|
||||
locale: Locale
|
||||
/** The VM's identifier (folder, CLI, reims-ctl). */
|
||||
name: string
|
||||
/** What the user calls it (its note); empty shows `name`. */
|
||||
displayName: string
|
||||
onDisplayNameSaved: (displayName: string) => void
|
||||
state: string
|
||||
detail: VMDetail | null
|
||||
stats: VMStats | null
|
||||
@@ -107,6 +111,8 @@ const clampPct = (v: number) => Math.min(100, Math.max(0, v))
|
||||
|
||||
interface Spec {
|
||||
key: string
|
||||
/** Shown only in the wide, single-column layout. */
|
||||
label: string
|
||||
icon: React.ReactNode
|
||||
value: string
|
||||
tip: string
|
||||
@@ -115,7 +121,7 @@ interface Spec {
|
||||
}
|
||||
|
||||
export const VMPage: React.FC<Props> = ({
|
||||
locale, name, state, detail, stats, host, pending, busyAction, onAction, onSettings, onOpenAffinity, onDelete, onViewLogs, onCopy, onTypeText, onTogglePreventSleep, onDeliverFile, onToast, onError, dropping,
|
||||
locale, name, displayName, onDisplayNameSaved, state, detail, stats, host, pending, busyAction, onAction, onSettings, onOpenAffinity, onDelete, onViewLogs, onCopy, onTypeText, onTogglePreventSleep, onDeliverFile, onToast, onError, dropping,
|
||||
}) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const busy = busyAction !== undefined
|
||||
@@ -138,23 +144,25 @@ export const VMPage: React.FC<Props> = ({
|
||||
return () => { live = false; if (timer) window.clearInterval(timer) }
|
||||
}, [name, running])
|
||||
|
||||
// Optional single-line VM note (.reims-go-note)
|
||||
const [note, setNote] = useState('')
|
||||
const [editingNote, setEditingNote] = useState(false)
|
||||
const [noteDraft, setNoteDraft] = useState('')
|
||||
useEffect(() => {
|
||||
let live = true
|
||||
setEditingNote(false)
|
||||
api.GetVMNote(name).then((n) => { if (live) setNote(n ?? '') }).catch(() => { if (live) setNote('') })
|
||||
return () => { live = false }
|
||||
}, [name])
|
||||
const saveNote = async () => {
|
||||
const cleaned = noteDraft.trim()
|
||||
setEditingNote(false)
|
||||
if (cleaned === note) return
|
||||
// Display name, stored as the VM's note (.reims-go-note). Clicking the title
|
||||
// edits it in place; clearing it (or typing the name) falls back to the name.
|
||||
const shownName = displayName || name
|
||||
const [editingName, setEditingName] = useState(false)
|
||||
const [nameDraft, setNameDraft] = useState('')
|
||||
useEffect(() => { setEditingName(false) }, [name])
|
||||
const startRename = () => { setNameDraft(shownName); setEditingName(true) }
|
||||
// From the More menu: keep the menu from pulling focus back to its button,
|
||||
// which would blur (and so save) the name field the moment it appears.
|
||||
const renameFromMenu = useRef(false)
|
||||
const nameInputRef = useRef<HTMLInputElement>(null)
|
||||
const saveName = async () => {
|
||||
setEditingName(false)
|
||||
let next = nameDraft.trim()
|
||||
if (next === name) next = ''
|
||||
if (next === displayName) return
|
||||
try {
|
||||
await api.SetVMNote(name, cleaned)
|
||||
setNote(cleaned)
|
||||
await api.SetVMNote(name, next)
|
||||
onDisplayNameSaved(next)
|
||||
} catch (e) {
|
||||
onError(tr('failGeneric'), e)
|
||||
}
|
||||
@@ -326,7 +334,18 @@ export const VMPage: React.FC<Props> = ({
|
||||
</Menu.Trigger>
|
||||
</Tip>
|
||||
<Menu.Portal>
|
||||
<Menu.Content className="menu" align="end" sideOffset={4} collisionPadding={8}>
|
||||
<Menu.Content
|
||||
className="menu"
|
||||
align="end"
|
||||
sideOffset={4}
|
||||
collisionPadding={8}
|
||||
onCloseAutoFocus={(e) => {
|
||||
if (!renameFromMenu.current) return
|
||||
renameFromMenu.current = false
|
||||
e.preventDefault()
|
||||
nameInputRef.current?.focus()
|
||||
}}
|
||||
>
|
||||
{running && (
|
||||
<>
|
||||
<Menu.Item className="menu-item" disabled={busy} onSelect={() => onAction('restart')}>
|
||||
@@ -363,6 +382,9 @@ export const VMPage: React.FC<Props> = ({
|
||||
<Menu.Item className="menu-item" onSelect={onOpenAffinity}>
|
||||
<Cpu size={14} /> {tr('affinityMenu')}
|
||||
</Menu.Item>
|
||||
<Menu.Item className="menu-item" onSelect={() => { renameFromMenu.current = true; startRename() }}>
|
||||
<Pencil size={14} /> {tr('displayNameEditEllipsis')}
|
||||
</Menu.Item>
|
||||
<Menu.Separator className="menu-sep" />
|
||||
</>
|
||||
)}
|
||||
@@ -404,17 +426,17 @@ export const VMPage: React.FC<Props> = ({
|
||||
|
||||
specs.push(
|
||||
{
|
||||
key: 'cpu', icon: <Cpu size={15} aria-hidden="true" />, value: tr('cores', { n: detail.cpus }),
|
||||
key: 'cpu', label: tr('factCPU'), icon: <Cpu size={15} aria-hidden="true" />, value: tr('cores', { n: detail.cpus }),
|
||||
tip: live ? tr('specCPULiveTip', { n: detail.cpus, pct: Math.round(cpuPct) }) : tr('specCPUTip', { n: detail.cpus }),
|
||||
meter: { pct: cpuPct, tone: meterTone(cpuPct), idle: !live },
|
||||
},
|
||||
{
|
||||
key: 'mem', icon: <MemoryStick size={15} aria-hidden="true" />, value: mem,
|
||||
key: 'mem', label: tr('factMemory'), icon: <MemoryStick size={15} aria-hidden="true" />, value: mem,
|
||||
tip: live && rss > 0 ? tr('specMemLiveTip', { mem, used: formatBytes(rss) }) : tr('specMemTip', { mem }),
|
||||
meter: { pct: memPct, tone: '', idle: !live },
|
||||
},
|
||||
{
|
||||
key: 'disk', icon: <HardDrive size={15} aria-hidden="true" />,
|
||||
key: 'disk', label: tr('factDisk'), icon: <HardDrive size={15} aria-hidden="true" />,
|
||||
value: diskKnown ? formatDiskUsage(stats!.disk_actual_bytes, stats!.disk_virtual_bytes) : controllerLabel(detail.disk_controller),
|
||||
tip: diskKnown
|
||||
? tr('specDiskUsage', { ctl: controllerLabel(detail.disk_controller), used: formatBytes(stats!.disk_actual_bytes), max: formatBytes(stats!.disk_virtual_bytes) })
|
||||
@@ -422,12 +444,12 @@ export const VMPage: React.FC<Props> = ({
|
||||
meter: { pct: diskPct, tone: meterTone(diskPct, 85, 95), idle: !diskKnown },
|
||||
},
|
||||
{
|
||||
key: 'gfx', icon: <Monitor size={15} aria-hidden="true" />,
|
||||
key: 'gfx', label: tr('factGraphics'), icon: <Monitor size={15} aria-hidden="true" />,
|
||||
value: graphicsLabel(locale, detail, host),
|
||||
tip: `${tr('factGraphics')}:${graphicsLabel(locale, detail, host)}`,
|
||||
},
|
||||
{
|
||||
key: 'net', icon: <Network size={15} aria-hidden="true" />,
|
||||
key: 'net', label: tr('fieldNetwork'), icon: <Network size={15} aria-hidden="true" />,
|
||||
value: detail.network ? tr('netShared') : tr('netOff'),
|
||||
tip: !detail.network ? tr('specNetOffTip') : detail.ssh_port > 0 ? tr('specNetSSHTip', { port: detail.ssh_port }) : tr('specNetTip'),
|
||||
},
|
||||
@@ -435,7 +457,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
if (detail.guest_lang) {
|
||||
const lang = splitLangLabel('', guestLangLabel(locale, detail.guest_lang))
|
||||
specs.push({
|
||||
key: 'lang', icon: <Globe size={15} aria-hidden="true" />, value: lang.label,
|
||||
key: 'lang', label: tr('specLang'), icon: <Globe size={15} aria-hidden="true" />, value: lang.label,
|
||||
tip: `${tr('guestLang')}:${lang.detail ? `${lang.label}(${lang.detail})` : lang.label}`,
|
||||
})
|
||||
}
|
||||
@@ -472,6 +494,8 @@ export const VMPage: React.FC<Props> = ({
|
||||
<span>{tr('dropFilesHint')}</span>
|
||||
</div>
|
||||
)}
|
||||
{/* Screen + summary: stacked, or side by side when the column is wide (container query in app.css). */}
|
||||
<div className="vm-top">
|
||||
<section className="vm-hero" aria-labelledby="vm-name">
|
||||
<VMScreen
|
||||
thumb={thumb}
|
||||
@@ -483,34 +507,33 @@ export const VMPage: React.FC<Props> = ({
|
||||
onShow={running && !busy ? () => onAction('focus') : undefined}
|
||||
onScreenshot={running && !busy ? () => onAction('screenshot') : undefined}
|
||||
/>
|
||||
<h1 className="vm-hero-name" id="vm-name">{name}</h1>
|
||||
<div className="vm-note-row">
|
||||
{editingNote ? (
|
||||
<input
|
||||
className="vm-note-input"
|
||||
value={noteDraft}
|
||||
maxLength={120}
|
||||
placeholder={tr('vmNotePlaceholder')}
|
||||
aria-label={tr('vmNoteEdit')}
|
||||
autoFocus
|
||||
onChange={(e) => setNoteDraft(e.target.value)}
|
||||
onBlur={() => void saveNote()}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') { e.preventDefault(); void saveNote() }
|
||||
if (e.key === 'Escape') { e.preventDefault(); setEditingNote(false) }
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
className="vm-note-btn"
|
||||
onClick={() => { setNoteDraft(note); setEditingNote(true) }}
|
||||
>
|
||||
<Pencil size={11} aria-hidden="true" />
|
||||
<span>{note || tr('vmNotePlaceholder')}</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{editingName ? (
|
||||
<input
|
||||
ref={nameInputRef}
|
||||
className="vm-name-input"
|
||||
value={nameDraft}
|
||||
maxLength={60}
|
||||
placeholder={name}
|
||||
aria-label={tr('displayNameLabel')}
|
||||
autoFocus
|
||||
onFocus={(e) => e.currentTarget.select()}
|
||||
onChange={(e) => setNameDraft(e.target.value)}
|
||||
onBlur={() => void saveName()}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') { e.preventDefault(); void saveName() }
|
||||
if (e.key === 'Escape') { e.preventDefault(); setEditingName(false) }
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<h1 className="vm-hero-name" id="vm-name">
|
||||
<Tip label={displayName ? tr('displayNameTip', { name }) : tr('displayNameEdit')}>
|
||||
<button type="button" className="vm-name-btn" onClick={startRename}>
|
||||
<span>{shownName}</span>
|
||||
<Pencil size={15} className="vm-name-pencil" aria-hidden="true" />
|
||||
</button>
|
||||
</Tip>
|
||||
</h1>
|
||||
)}
|
||||
<div className={`vm-hero-pill${pillClass}`} role="status">
|
||||
<StatusShape kind={statusKind(state)} />
|
||||
<span>{tr(`state_${state}` as I18nKey)}</span>
|
||||
@@ -532,6 +555,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
<Tip key={s.key} label={s.tip}>
|
||||
<div className="vm-spec-cell" role="listitem" tabIndex={-1}>
|
||||
<span className="vm-spec-icon">{s.icon}</span>
|
||||
<span className="vm-spec-label">{s.label}</span>
|
||||
<span className="vm-spec-val">{s.value}</span>
|
||||
{s.meter && (
|
||||
<span className="vm-spec-meter" data-idle={s.meter.idle || undefined} aria-hidden="true">
|
||||
@@ -543,6 +567,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{state === 'broken' && (
|
||||
<div className="notice notice-error" role="alert">
|
||||
@@ -925,6 +950,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
<div className="tech-body">
|
||||
<IconButton small className="tech-copy" label={tr('copyTechInfo')} icon={<Copy size={14} />} onClick={copyTechSummary} />
|
||||
<dl className="kv-list">
|
||||
<dt>{tr('fieldVMName')}</dt><dd className="mono">{name}</dd>
|
||||
<dt>{tr('fieldKind')}</dt><dd>{detail.kind || '—'}</dd>
|
||||
<dt>{tr('fieldCPUModel')}</dt><dd className="mono">{detail.cpu_model || 'auto'}</dd>
|
||||
<dt>{tr('fieldGraphicsBackend')}</dt><dd>{detail.graphics}</dd>
|
||||
|
||||
+10
-4
@@ -100,8 +100,11 @@ const dict = {
|
||||
toastSnapshotRestored: '已回滚到 {name}',
|
||||
toastSnapshotDeleted: '已删除恢复点 {name}',
|
||||
failSnapshot: '恢复点操作失败',
|
||||
vmNotePlaceholder: '添加备注…',
|
||||
vmNoteEdit: '编辑备注',
|
||||
displayNameEdit: '点按以修改显示名称',
|
||||
displayNameLabel: '显示名称',
|
||||
displayNameEditEllipsis: '修改显示名称…',
|
||||
displayNameTip: '显示名称 · 虚拟机名称为 {name}(点按修改)',
|
||||
fieldVMName: '虚拟机名称',
|
||||
logSearchPlaceholder: '筛选日志…',
|
||||
logErrorsOnly: '仅错误/警告',
|
||||
logCopy: '复制日志',
|
||||
@@ -768,8 +771,11 @@ const dict = {
|
||||
toastSnapshotRestored: 'Restored to {name}',
|
||||
toastSnapshotDeleted: 'Deleted restore point {name}',
|
||||
failSnapshot: 'Restore point failed',
|
||||
vmNotePlaceholder: 'Add a note…',
|
||||
vmNoteEdit: 'Edit note',
|
||||
displayNameEdit: 'Click to change the display name',
|
||||
displayNameLabel: 'Display name',
|
||||
displayNameEditEllipsis: 'Change Display Name…',
|
||||
displayNameTip: 'Display name · VM name is {name} (click to change)',
|
||||
fieldVMName: 'VM name',
|
||||
logSearchPlaceholder: 'Filter logs…',
|
||||
logErrorsOnly: 'Errors & warnings',
|
||||
logCopy: 'Copy logs',
|
||||
|
||||
+38
-12
@@ -1314,19 +1314,45 @@ button.status-issue + .status-metric { margin-left: 6px; }
|
||||
.vm-screen-shot:hover { background: rgba(20, 22, 28, 0.88); }
|
||||
.vm-screen-shot:active { transform: scale(0.94); }
|
||||
|
||||
.vm-note-row { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 22px; max-width: 100%; }
|
||||
.vm-note-btn {
|
||||
display: inline-flex; align-items: center; gap: 5px; max-width: 420px;
|
||||
padding: 2px 8px; border: none; border-radius: 6px; background: transparent;
|
||||
font-size: var(--fs-12); color: var(--text-3); cursor: pointer;
|
||||
transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
|
||||
/* The title is the display name; click to rename in place. The pencil hangs
|
||||
outside the text so the name stays centred. */
|
||||
.vm-name-btn {
|
||||
position: relative; display: inline-flex; align-items: center; max-width: 100%;
|
||||
padding: 0 6px; border: none; border-radius: var(--r-md);
|
||||
background: transparent; color: inherit; font: inherit; letter-spacing: inherit; cursor: text;
|
||||
transition: background var(--dur-fast) var(--ease-out);
|
||||
}
|
||||
.vm-note-btn:hover { background: var(--surface-hover); color: var(--text-2); }
|
||||
.vm-note-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.vm-note-input {
|
||||
width: 280px; max-width: 100%; height: 26px; padding: 0 8px; text-align: center;
|
||||
border-radius: var(--r-sm); border: 1px solid var(--accent); background: var(--surface-input);
|
||||
color: var(--text); font: inherit; font-size: var(--fs-12); box-shadow: var(--focus-ring);
|
||||
.vm-name-btn > span { overflow-wrap: anywhere; }
|
||||
.vm-name-btn:hover { background: var(--surface-hover); }
|
||||
.vm-name-pencil {
|
||||
position: absolute; left: 100%; top: 50%; margin-left: 6px; transform: translateY(-50%);
|
||||
color: var(--text-3); opacity: 0; transition: opacity var(--dur-fast) var(--ease-out);
|
||||
}
|
||||
.vm-name-btn:hover .vm-name-pencil, .vm-name-btn:focus-visible .vm-name-pencil { opacity: 1; }
|
||||
.vm-name-input {
|
||||
width: min(100%, 380px); height: 36px; padding: 0 10px; text-align: center;
|
||||
border-radius: var(--r-md); border: 1px solid var(--accent); background: var(--surface-input);
|
||||
color: var(--text); font-family: inherit; font-size: 24px; font-weight: 700; letter-spacing: -0.025em;
|
||||
box-shadow: var(--focus-ring);
|
||||
}
|
||||
|
||||
/* Screen + summary. Stacked by default; once the content column is wide
|
||||
enough the summary becomes one labelled column beside the screen, like
|
||||
"About This Mac". */
|
||||
.scroll { container-type: inline-size; }
|
||||
.vm-top { display: flex; flex-direction: column; gap: 14px; }
|
||||
.vm-spec-label { display: none; }
|
||||
@container (min-width: 760px) {
|
||||
.page.vm-page { max-width: 880px; }
|
||||
.vm-top {
|
||||
display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
|
||||
align-items: center; gap: 28px; padding: 6px 0 4px;
|
||||
}
|
||||
.vm-spec-card { grid-template-columns: minmax(0, 1fr); row-gap: 14px; padding: 16px 18px; }
|
||||
.vm-spec-cell { grid-template-columns: auto 4.5em minmax(0, 1fr); }
|
||||
.vm-spec-label { display: block; font-size: var(--fs-13); color: var(--text-3); white-space: nowrap; }
|
||||
.vm-spec-meter { grid-column: 3; }
|
||||
.vm-screen { width: clamp(220px, 34vh, 300px); }
|
||||
}
|
||||
|
||||
.vm-page-drop { position: relative; }
|
||||
|
||||
Reference in new issue
Block a user