Repository navigation
Toolbar: show a running profile save and disable what it would refuse #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ interface Props { | |
| onSave: (cfg: VmConfig, previousName?: string) => void | ||
| onCancelDraft: () => void | ||
| onDelete: (name: string) => void | ||
| /** a profile operation running on this VM, shown instead of the status */ | ||
| work: string | null | ||
| onDirtyChange: (dirty: boolean) => void | ||
| toast: PushToast | ||
| onNeedsSetup: (reason: string) => void | ||
|
|
@@ -37,7 +39,7 @@ const TABS: { id: Tab; label: string }[] = [ | |
| ] | ||
|
|
||
| export default function VmDetail(props: Props) { | ||
| const { vm, isDraft, status, host, onSave, onCancelDraft, onDelete, onDirtyChange } = props | ||
| const { vm, isDraft, status, work, host, onSave, onCancelDraft, onDelete, onDirtyChange } = props | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const [tab, setTab] = useState<Tab>(isDraft ? 'hardware' : 'summary') | ||
| const [form, setForm] = useState<VmConfig>(vm) | ||
| useEffect(() => setForm(vm), [vm]) | ||
|
|
@@ -47,8 +49,10 @@ export default function VmDetail(props: Props) { | |
| const diskError = | ||
| !Number.isInteger(form.diskSizeGB) || form.diskSizeGB < 5 || form.diskSizeGB > 16384 ? 'Pick a whole number from 5 to 16384 GB' : null | ||
| const forwardsInvalid = form.forwards.some((_f, i) => forwardError(form.forwards, i) !== null) | ||
| // a profile operation can run while the VM is off (a disk-only save, a launch rolling back), save and delete wait for it | ||
| const locked = status !== 'off' || work !== null | ||
| // same rule as the Save button on the Hardware tab | ||
| const canSave = dirty && !nameError && !diskError && !forwardsInvalid && status === 'off' | ||
| const canSave = dirty && !nameError && !diskError && !forwardsInvalid && !locked | ||
|
|
||
| // Ctrl+S saves the hardware form from any tab | ||
| const save = useRef(() => {}) | ||
|
|
@@ -75,7 +79,9 @@ export default function VmDetail(props: Props) { | |
| <OsMark os={form.os} large /> | ||
| <div className="detail-title"> | ||
| <h1>{form.name || 'Untitled'}</h1> | ||
| <span className={`state-text ${status}`}>{isDraft ? 'Not created yet' : statusLabel[status]}</span> | ||
| <span className={`state-text ${status}`} role="status"> | ||
| {isDraft ? 'Not created yet' : work ?? statusLabel[status]} | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
||
|
|
@@ -102,7 +108,8 @@ export default function VmDetail(props: Props) { | |
| form={form} | ||
| setForm={setForm} | ||
| host={host} | ||
| locked={status !== 'off'} | ||
| locked={locked} | ||
| lockNotice={work ? `${work}. Wait for it to finish.` : 'Power off the VM to change its hardware.'} | ||
| isDraft={isDraft} | ||
| dirty={dirty} | ||
| nameError={nameError} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, no change needed: if a
vm:profileWorkevent lands before this reply, the reply overwrites it. Same pattern asstates()above it. The worst case is the toolbar staying enabled until the next event, which is what we had before this PR.