Skip to content
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

Display errors on instance actions #1806

Merged
merged 1 commit into from
Oct 31, 2023
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
37 changes: 29 additions & 8 deletions app/pages/project/instances/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { useNavigate } from 'react-router-dom'
import { type Instance, instanceCan, useApiMutation } from '@oxide/api'
import type { MakeActions } from '@oxide/table'

import { useToast } from 'app/hooks'
import { confirmDelete } from 'app/stores/confirm-delete'
import { addToast } from 'app/stores/toast'
import { pb } from 'app/util/path-builder'

import { fancifyStates } from './instance/tabs/common'
Expand All @@ -31,7 +31,6 @@ export const useMakeInstanceActions = (
options: Options = {}
): MakeActions<Instance> => {
const navigate = useNavigate()
const addToast = useToast()

// if you also pass onSuccess to mutate(), this one is not overridden — this
// one runs first, then the one passed to mutate()
Expand All @@ -43,15 +42,20 @@ export const useMakeInstanceActions = (

return useCallback(
(instance) => {
const successToast = (title: string) => addToast({ title })
const instanceSelector = { ...projectSelector, instance: instance.name }
const instanceParams = { path: { instance: instance.name }, query: projectSelector }
return [
{
label: 'Start',
onActivate() {
startInstance.mutate(instanceParams, {
onSuccess: () => successToast(`Starting instance '${instance.name}'`),
onSuccess: () => addToast({ title: `Starting instance '${instance.name}'` }),
onError: (error) =>
addToast({
variant: 'error',
title: `Error starting instance '${instance.name}'`,
content: error.message,
}),
})
},
disabled: !instanceCan.start(instance) && (
Expand All @@ -62,7 +66,13 @@ export const useMakeInstanceActions = (
label: 'Stop',
onActivate() {
stopInstance.mutate(instanceParams, {
onSuccess: () => successToast(`Stopping instance '${instance.name}'`),
onSuccess: () => addToast({ title: `Stopping instance '${instance.name}'` }),
onError: (error) =>
addToast({
variant: 'error',
title: `Error stopping instance '${instance.name}'`,
content: error.message,
}),
})
},
disabled: !instanceCan.stop(instance) && (
Expand All @@ -73,7 +83,13 @@ export const useMakeInstanceActions = (
label: 'Reboot',
onActivate() {
rebootInstance.mutate(instanceParams, {
onSuccess: () => successToast(`Rebooting instance '${instance.name}'`),
onSuccess: () => addToast({ title: `Rebooting instance '${instance.name}'` }),
onError: (error) =>
addToast({
variant: 'error',
title: `Error rebooting instance '${instance.name}'`,
content: error.message,
}),
})
},
disabled: !instanceCan.reboot(instance) && (
Expand All @@ -93,8 +109,14 @@ export const useMakeInstanceActions = (
deleteInstance.mutateAsync(instanceParams, {
onSuccess: () => {
options.onDelete?.()
successToast(`Deleting instance '${instance.name}'`)
addToast({ title: `Deleting instance '${instance.name}'` })
},
onError: (error) =>
addToast({
variant: 'error',
title: `Error deleting instance '${instance.name}'`,
content: error.message,
}),
}),
label: instance.name,
}),
Expand All @@ -113,7 +135,6 @@ export const useMakeInstanceActions = (
rebootInstance,
startInstance,
stopInstance,
addToast,
]
)
}
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ if (!apiModeResult.success) {
*/
const apiMode = apiModeResult.data

const DOGFOOD_HOST = 'oxide.sys.rack2.eng.oxide.computer'
// if you want a different host you can override it with EXT_HOST
const DOGFOOD_HOST = process.env.EXT_HOST || 'oxide.sys.rack2.eng.oxide.computer'

const mapObj = <V0, V>(
obj: Record<string, V0>,
Expand Down
Loading