-
Notifications
You must be signed in to change notification settings - Fork 12
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
Prototype: Stop instance disk modal #2747
Draft
benjaminleonard
wants to merge
6
commits into
attach-disk-modal
Choose a base branch
from
stop-instance-disk-modal
base: attach-disk-modal
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
61438c6
Experimental stop instance in modal
benjaminleonard b1dc605
Cleanup
benjaminleonard 7581cf4
merge modalform thing into this one
david-crespo 2f72238
simplify some of the instance state business
david-crespo dbdf80b
Merge branch 'attach-disk-modal' into stop-instance-disk-modal
benjaminleonard 5ba0578
Update test
benjaminleonard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
import { type ReactNode } from 'react' | ||
|
||
import { apiQueryClient, useApiMutation, type Instance } from '@oxide/api' | ||
|
||
import { HL } from '~/components/HL' | ||
import { addToast } from '~/stores/toast' | ||
import { Button } from '~/ui/lib/Button' | ||
import { Message } from '~/ui/lib/Message' | ||
|
||
type StopInstancePromptProps = { | ||
instance: Instance | ||
children: ReactNode | ||
} | ||
|
||
export function StopInstancePrompt({ instance, children }: StopInstancePromptProps) { | ||
const isStoppingInstance = instance.runState === 'stopping' | ||
|
||
const stopInstance = useApiMutation('instanceStop', { | ||
onSuccess: () => { | ||
// trigger polling by the top level InstancePage one | ||
apiQueryClient.invalidateQueries('instanceView') | ||
addToast(<>Stopping instance <HL>{instance.name}</HL></>) // prettier-ignore | ||
}, | ||
onError: (error) => { | ||
addToast({ | ||
variant: 'error', | ||
title: `Error stopping instance '${instance.name}'`, | ||
content: error.message, | ||
}) | ||
}, | ||
}) | ||
|
||
return ( | ||
<Message | ||
variant="notice" | ||
content={ | ||
<> | ||
{children}{' '} | ||
<Button | ||
size="xs" | ||
className="mt-3" | ||
variant="notice" | ||
onClick={() => | ||
stopInstance.mutateAsync({ | ||
path: { instance: instance.name }, | ||
query: { project: instance.projectId }, | ||
}) | ||
} | ||
loading={isStoppingInstance} | ||
> | ||
Stop instance | ||
</Button> | ||
</> | ||
} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,10 @@ | |
@apply hidden; | ||
} | ||
|
||
.btn-notice.ox-button:after { | ||
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. I want to clean up button styles for these mini coloured ghost icons |
||
@apply opacity-40; | ||
} | ||
|
||
/** | ||
* A class to make it very visually obvious that a button style is missing | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ | |
animation: rotate 5s linear infinite; | ||
} | ||
|
||
.spinner .path, | ||
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. This is borrowed from #2742 |
||
.spinner .bg { | ||
stroke: currentColor; | ||
} | ||
|
||
.spinner.spinner-md { | ||
--radius: 8; | ||
--circumference: calc(var(--PI) * var(--radius) * 2px); | ||
|
@@ -27,7 +32,6 @@ | |
stroke-dasharray: var(--circumference); | ||
transform-origin: center; | ||
animation: dash 8s ease-in-out infinite; | ||
stroke: var(--content-accent-tertiary); | ||
} | ||
|
||
@media (prefers-reduced-motion) { | ||
|
@@ -50,24 +54,6 @@ | |
} | ||
} | ||
|
||
.spinner-ghost .bg, | ||
.spinner-secondary .bg { | ||
stroke: var(--content-default); | ||
} | ||
|
||
.spinner-secondary .path { | ||
stroke: var(--content-secondary); | ||
} | ||
|
||
.spinner-primary .bg { | ||
stroke: var(--content-accent); | ||
} | ||
|
||
.spinner-danger .bg, | ||
.spinner-danger .path { | ||
stroke: var(--content-destructive-tertiary); | ||
} | ||
|
||
@keyframes rotate { | ||
100% { | ||
transform: rotate(360deg); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Oh this is very clever
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.
The only downside is that you have a delay in the loading state because it doesn't change to loading while the initial stop request goes through. I tried this
and it does respond immediately, but it flashes back to off briefly in between the stop request completing and the invalidation running and flipping the instance to 'stopping'. I can't think of a fix other than adding back in the explicit state thing you had. Those things make me nervous because the logic has to be bulletproof to avoid accidentally getting stuck in a loading state, but I'm sure we can do it.