From 704f68cdcec3cb8838d2bb26ddad5a3e1acf6d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=B7=9D=E7=99=BD=E6=B5=AA?= <1679659@qq.com> Date: Sun, 29 Nov 2026 04:34:53 -0700 Subject: [PATCH] feat(ui): display names for VMs and a side-by-side summary on wide windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- frontend/src/App.tsx | 18 ++++ frontend/src/components/Sidebar.tsx | 6 +- frontend/src/components/VMPage.tsx | 130 +++++++++++++++++----------- frontend/src/i18n.ts | 14 ++- frontend/src/styles/app.css | 50 ++++++++--- 5 files changed, 148 insertions(+), 70 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 2a4a1a6..c50ec19 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -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>({}) + 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 = () => { setDisplayNames((m) => ({ ...m, [selectedVM.name]: n }))} state={effectiveState} detail={detail} stats={vmStats} diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx index d2e2d28..510e77c 100644 --- a/frontend/src/components/Sidebar.tsx +++ b/frontend/src/components/Sidebar.tsx @@ -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 /** 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) { } export const Sidebar: React.FC = ({ - 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(null) @@ -116,7 +118,7 @@ export const Sidebar: React.FC = ({ const src = icons[vm.name] const trigger = navBtn( vm.name, - vm.name, + displayNames[vm.name] || vm.name, src ? : , src ? 'nav-icon-thumb' : 'nav-icon-vm', t(locale, `state_${st}` as I18nKey), diff --git a/frontend/src/components/VMPage.tsx b/frontend/src/components/VMPage.tsx index f855818..5ce6869 100644 --- a/frontend/src/components/VMPage.tsx +++ b/frontend/src/components/VMPage.tsx @@ -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 = ({ - 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) => t(locale, k, v) const busy = busyAction !== undefined @@ -138,23 +144,25 @@ export const VMPage: React.FC = ({ 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(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 = ({ - + { + if (!renameFromMenu.current) return + renameFromMenu.current = false + e.preventDefault() + nameInputRef.current?.focus() + }} + > {running && ( <> onAction('restart')}> @@ -363,6 +382,9 @@ export const VMPage: React.FC = ({ {tr('affinityMenu')} + { renameFromMenu.current = true; startRename() }}> + {tr('displayNameEditEllipsis')} + )} @@ -404,17 +426,17 @@ export const VMPage: React.FC = ({ specs.push( { - key: 'cpu', icon: