Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ export default function App() {
usage={latestUsage}
work={vmWork}
selected={selected}
draftName={null}
query={query}
onQuery={setQuery}
ref={filterRef}
Expand All @@ -325,13 +324,11 @@ export default function App() {
<VmDetail
key={current.name}
vm={current}
isDraft={false}
status={status}
work={current ? vmWork[current.name] ?? null : null}
host={host}
usage={usage[current.name] ?? []}
onSave={onSave}
onCancelDraft={() => undefined}
onDelete={onDelete}
onDirtyChange={setUnsaved}
toast={toasts.push}
Expand Down
25 changes: 10 additions & 15 deletions src/renderer/src/components/Hardware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface Props {
locked: boolean
/** why the form is locked */
lockNotice: string
isDraft: boolean
dirty: boolean
nameError: string | null
diskError: string | null
Expand All @@ -30,7 +29,7 @@ interface Props {
}

export default function Hardware(props: Props) {
const { form, setForm, host, locked, lockNotice, isDraft, dirty, nameError, diskError, forwardsInvalid, onSave, onRevert, onDelete } = props
const { form, setForm, host, locked, lockNotice, dirty, nameError, diskError, forwardsInvalid, onSave, onRevert, onDelete } = props
const set = <K extends keyof VmConfig>(k: K, v: VmConfig[K]) => setForm((f) => ({ ...f, [k]: v }))
const maxRam = host ? Math.max(1024, Math.floor((host.totalRamMB - 2048) / 512) * 512) : 32768
const maxCpu = host?.cpuCount ?? 16
Expand Down Expand Up @@ -68,7 +67,7 @@ export default function Hardware(props: Props) {
</Group>

<Group title="Storage">
<Row label="Disk size" error={diskError} hint={isDraft ? 'grows as the guest writes, up to this size' : 'only used when the disk file is created. Grow an existing disk below'}>
<Row label="Disk size" error={diskError} hint="only used when the disk file is created. Grow an existing disk below">
<div className="with-unit">
<input
type="number"
Expand All @@ -88,11 +87,9 @@ export default function Hardware(props: Props) {
<option value="ide">IDE</option>
</select>
</Row>
{!isDraft && (
<Row label="Disk file">
<DiskTools vm={props.vm} status={props.status} dirty={dirty} toast={props.toast} onChanged={props.onDiskChanged} />
</Row>
)}
<Row label="Disk file">
<DiskTools vm={props.vm} status={props.status} dirty={dirty} toast={props.toast} onChanged={props.onDiskChanged} />
</Row>
<Row label="CD/DVD">
<select value={form.iso} onChange={(e) => set('iso', e.target.value)}>
<option value="">Empty</option>
Expand Down Expand Up @@ -197,17 +194,15 @@ export default function Hardware(props: Props) {
</fieldset>

<div className="form-actions">
{!isDraft && (
<button className="btn danger-ghost" disabled={locked} onClick={onDelete}>
Remove from library
</button>
)}
<button className="btn danger-ghost" disabled={locked} onClick={onDelete}>
Remove from library
</button>
<span className="spacer" />
<button className="btn" disabled={!dirty || locked} onClick={onRevert}>
{isDraft ? 'Cancel' : 'Revert'}
Revert
</button>
<button className="btn primary" disabled={!dirty || Boolean(nameError) || Boolean(diskError) || forwardsInvalid || locked} onClick={onSave} title="Save (Ctrl+S)" aria-keyshortcuts="Control+S">
{isDraft ? 'Create' : 'Save'}
Save
</button>
</div>
</div>
Expand Down
12 changes: 1 addition & 11 deletions src/renderer/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ interface Props {
/** profile operations and disk work by VM name, shown instead of the status */
work: Record<string, VmWork>
selected: string | null
draftName: string | null
/** the filter text. Kept in App, since the arrow keys move through what it shows */
query: string
onQuery: (q: string) => void
onSelect: (name: string) => void
}

// the ref is the filter box, for Ctrl+F
const Sidebar = forwardRef<HTMLInputElement, Props>(function Sidebar({ vms, states, usage, work, selected, draftName, query, onQuery, onSelect }, filterRef) {
const Sidebar = forwardRef<HTMLInputElement, Props>(function Sidebar({ vms, states, usage, work, selected, query, onQuery, onSelect }, filterRef) {
const q = query.trim()
const shown = filterVms(vms, query)

Expand Down Expand Up @@ -50,15 +49,6 @@ const Sidebar = forwardRef<HTMLInputElement, Props>(function Sidebar({ vms, stat
/>
</div>
<ul className="tree" role="listbox" aria-label="Virtual machines">
{draftName && (
<li>
<div className="row active draft" role="option" aria-selected>
<OsMark os="other" />
<span className="row-name">{draftName}</span>
<span className="row-state">new</span>
</div>
</li>
)}
{shown.map((v) => {
const s = states[v.name] ?? 'off'
const u = s === 'running' ? usage[v.name] : undefined
Expand Down
20 changes: 8 additions & 12 deletions src/renderer/src/components/VmDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import { errText, fileName, gb, statusLabel, workLabel } from '../util'

interface Props {
vm: VmConfig
isDraft: boolean
status: VmStatus
host: HostInfo | null
/** CPU and memory samples of this VM, oldest first, empty while it's off */
usage: VmUsage[]
onSave: (cfg: VmConfig, previousName?: string) => void
onCancelDraft: () => void
onDelete: (name: string) => void
/** a profile operation or disk work running on this VM, shown instead of the status */
work: VmWork | null
Expand All @@ -39,13 +37,13 @@ const TABS: { id: Tab; label: string }[] = [
]

export default function VmDetail(props: Props) {
const { vm, isDraft, status, host, onSave, onCancelDraft, onDelete, onDirtyChange } = props
const { vm, status, host, onSave, onDelete, onDirtyChange } = props
const work = props.work ? workLabel[props.work] : null
const [tab, setTab] = useState<Tab>(isDraft ? 'hardware' : 'summary')
const [tab, setTab] = useState<Tab>('summary')
const [form, setForm] = useState<VmConfig>(vm)
useEffect(() => setForm(vm), [vm])

const dirty = isDraft || JSON.stringify(form) !== JSON.stringify(vm)
const dirty = JSON.stringify(form) !== JSON.stringify(vm)
const nameError = validateVmName(form.name)
const diskError =
!Number.isInteger(form.diskSizeGB) || form.diskSizeGB < 5 || form.diskSizeGB > 16384 ? 'Pick a whole number from 5 to 16384 GB' : null
Expand All @@ -70,9 +68,9 @@ export default function VmDetail(props: Props) {

// the toolbar lives in App, it needs to know when Power on would ignore unsaved edits
useEffect(() => {
onDirtyChange(!isDraft && dirty)
onDirtyChange(dirty)
return () => onDirtyChange(false) // switching VMs throws the edits away
}, [dirty, isDraft, onDirtyChange])
}, [dirty, onDirtyChange])

return (
<main className="detail">
Expand All @@ -81,7 +79,7 @@ export default function VmDetail(props: Props) {
<div className="detail-title">
<h1>{form.name || 'Untitled'}</h1>
<span className={`state-text ${status}`} role="status">
{isDraft ? 'Not created yet' : work ?? statusLabel[status]}
{work ?? statusLabel[status]}
</span>
</div>
</div>
Expand All @@ -93,11 +91,10 @@ export default function VmDetail(props: Props) {
role="tab"
aria-selected={tab === t.id}
className={tab === t.id ? 'tab active' : 'tab'}
disabled={isDraft && t.id !== 'hardware'}
onClick={() => setTab(t.id)}
>
{t.label}
{t.id === 'hardware' && dirty && !isDraft && <span className="tab-dot" aria-label="unsaved changes" />}
{t.id === 'hardware' && dirty && <span className="tab-dot" aria-label="unsaved changes" />}
</button>
))}
</nav>
Expand All @@ -111,13 +108,12 @@ export default function VmDetail(props: Props) {
host={host}
locked={locked}
lockNotice={work ? `${work}. Wait for it to finish.` : 'Power off the VM to change its hardware.'}
isDraft={isDraft}
dirty={dirty}
nameError={nameError}
diskError={diskError}
forwardsInvalid={forwardsInvalid}
onSave={() => onSave(form, vm.name)}
onRevert={() => (isDraft ? onCancelDraft() : setForm(vm))}
onRevert={() => setForm(vm)}
onDelete={() => onDelete(vm.name)}
vm={vm}
status={status}
Expand Down
1 change: 0 additions & 1 deletion src/renderer/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ button:disabled { cursor: default; }
.row:hover { background: var(--surface-2); }
.row.active { background: var(--accent-bg); }
.row.active::before { content: ''; width: 3px; height: 14px; margin-left: -6px; margin-right: -3px; border-radius: 2px; background: var(--accent); }
.row.draft { font-style: italic; color: var(--text-2); }
.row-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-state { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.row-state.running { color: var(--run); }
Expand Down
Loading