-
Notifications
You must be signed in to change notification settings - Fork 889
feat: Delete workspace #1822
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
feat: Delete workspace #1822
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ComponentMeta, Story } from "@storybook/react" | ||
import React from "react" | ||
import { DeleteWorkspaceDialog, DeleteWorkspaceDialogProps } from "./DeleteWorkspaceDialog" | ||
|
||
export default { | ||
title: "Components/DeleteWorkspaceDialog", | ||
component: DeleteWorkspaceDialog, | ||
argTypes: { | ||
onClose: { | ||
action: "onClose", | ||
}, | ||
onConfirm: { | ||
action: "onConfirm", | ||
}, | ||
open: { | ||
control: "boolean", | ||
defaultValue: true, | ||
}, | ||
title: { | ||
defaultValue: "Confirm Dialog", | ||
}, | ||
}, | ||
} as ComponentMeta<typeof DeleteWorkspaceDialog> | ||
|
||
const Template: Story<DeleteWorkspaceDialogProps> = (args) => <DeleteWorkspaceDialog {...args} /> | ||
|
||
export const Example = Template.bind({}) | ||
Example.args = { | ||
isOpen: true, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react" | ||
import { ConfirmDialog } from "../ConfirmDialog/ConfirmDialog" | ||
|
||
const Language = { | ||
deleteDialogTitle: "Delete workspace?", | ||
deleteDialogMessage: "Deleting your workspace is irreversible. Are you sure?", | ||
} | ||
|
||
export interface DeleteWorkspaceDialogProps { | ||
isOpen: boolean | ||
handleConfirm: () => void | ||
handleCancel: () => void | ||
} | ||
|
||
export const DeleteWorkspaceDialog: React.FC<DeleteWorkspaceDialogProps> = ({ | ||
isOpen, | ||
handleCancel, | ||
handleConfirm, | ||
}) => ( | ||
<ConfirmDialog | ||
type="delete" | ||
hideCancel={false} | ||
open={isOpen} | ||
title={Language.deleteDialogTitle} | ||
onConfirm={handleConfirm} | ||
onClose={handleCancel} | ||
description={Language.deleteDialogMessage} | ||
/> | ||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||
import { useMachine } from "@xstate/react" | ||||||||||||||||||||||||||||
import React, { useEffect } from "react" | ||||||||||||||||||||||||||||
import { useParams } from "react-router-dom" | ||||||||||||||||||||||||||||
import { useNavigate, useParams } from "react-router-dom" | ||||||||||||||||||||||||||||
import { DeleteWorkspaceDialog } from "../../components/DeleteWorkspaceDialog/DeleteWorkspaceDialog" | ||||||||||||||||||||||||||||
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary" | ||||||||||||||||||||||||||||
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader" | ||||||||||||||||||||||||||||
import { Margins } from "../../components/Margins/Margins" | ||||||||||||||||||||||||||||
|
@@ -11,6 +12,7 @@ import { workspaceMachine } from "../../xServices/workspace/workspaceXService" | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export const WorkspacePage: React.FC = () => { | ||||||||||||||||||||||||||||
const { workspace: workspaceQueryParam } = useParams() | ||||||||||||||||||||||||||||
const navigate = useNavigate() | ||||||||||||||||||||||||||||
const workspaceId = firstOrItem(workspaceQueryParam, null) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const [workspaceState, workspaceSend] = useMachine(workspaceMachine) | ||||||||||||||||||||||||||||
|
@@ -32,16 +34,27 @@ export const WorkspacePage: React.FC = () => { | |||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||
<Margins> | ||||||||||||||||||||||||||||
<Stack spacing={4}> | ||||||||||||||||||||||||||||
<Workspace | ||||||||||||||||||||||||||||
workspace={workspace} | ||||||||||||||||||||||||||||
handleStart={() => workspaceSend("START")} | ||||||||||||||||||||||||||||
handleStop={() => workspaceSend("STOP")} | ||||||||||||||||||||||||||||
handleUpdate={() => workspaceSend("UPDATE")} | ||||||||||||||||||||||||||||
handleCancel={() => workspaceSend("CANCEL")} | ||||||||||||||||||||||||||||
resources={resources} | ||||||||||||||||||||||||||||
getResourcesError={getResourcesError instanceof Error ? getResourcesError : undefined} | ||||||||||||||||||||||||||||
builds={builds} | ||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||
<> | ||||||||||||||||||||||||||||
<Workspace | ||||||||||||||||||||||||||||
workspace={workspace} | ||||||||||||||||||||||||||||
handleStart={() => workspaceSend("START")} | ||||||||||||||||||||||||||||
handleStop={() => workspaceSend("STOP")} | ||||||||||||||||||||||||||||
handleDelete={() => workspaceSend("ASK_DELETE")} | ||||||||||||||||||||||||||||
handleUpdate={() => workspaceSend("UPDATE")} | ||||||||||||||||||||||||||||
handleCancel={() => workspaceSend("CANCEL")} | ||||||||||||||||||||||||||||
resources={resources} | ||||||||||||||||||||||||||||
getResourcesError={getResourcesError instanceof Error ? getResourcesError : undefined} | ||||||||||||||||||||||||||||
builds={builds} | ||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||
<DeleteWorkspaceDialog | ||||||||||||||||||||||||||||
isOpen={workspaceState.matches({ ready: { build: "askingDelete" } })} | ||||||||||||||||||||||||||||
handleCancel={() => workspaceSend("CANCEL_DELETE")} | ||||||||||||||||||||||||||||
handleConfirm={() => { | ||||||||||||||||||||||||||||
workspaceSend("DELETE") | ||||||||||||||||||||||||||||
navigate("/workspaces") | ||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||
Comment on lines
+52
to
+55
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. Question: What happens if we send I ran into this problem in #1701 and used a WDYT here? Edit: LoC for reference coder/site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx Lines 169 to 181 in ebaae75
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. You're right. I opened a decision ticket on this and we decided to stick with what I have for now, but change it in the future. #1837 |
||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||
</> | ||||||||||||||||||||||||||||
</Stack> | ||||||||||||||||||||||||||||
</Margins> | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,9 @@ export type WorkspaceEvent = | |
| { type: "GET_WORKSPACE"; workspaceId: string } | ||
| { type: "START" } | ||
| { type: "STOP" } | ||
| { type: "ASK_DELETE" } | ||
| { type: "DELETE" } | ||
| { type: "CANCEL_DELETE" } | ||
| { type: "UPDATE" } | ||
| { type: "CANCEL" } | ||
| { type: "LOAD_MORE_BUILDS" } | ||
|
@@ -136,10 +139,17 @@ export const workspaceMachine = createMachine( | |
on: { | ||
START: "requestingStart", | ||
STOP: "requestingStop", | ||
ASK_DELETE: "askingDelete", | ||
UPDATE: "refreshingTemplate", | ||
CANCEL: "requestingCancel", | ||
}, | ||
}, | ||
askingDelete: { | ||
on: { | ||
DELETE: "requestingDelete", | ||
CANCEL_DELETE: "idle", | ||
}, | ||
}, | ||
requestingStart: { | ||
entry: "clearBuildError", | ||
invoke: { | ||
|
@@ -170,6 +180,21 @@ export const workspaceMachine = createMachine( | |
}, | ||
}, | ||
}, | ||
requestingDelete: { | ||
entry: "clearBuildError", | ||
invoke: { | ||
id: "deleteWorkspace", | ||
src: "deleteWorkspace", | ||
onDone: { | ||
target: "idle", | ||
actions: ["assignBuild", "refreshTimeline"], | ||
}, | ||
onError: { | ||
target: "idle", | ||
actions: ["assignBuildError", "displayBuildError"], | ||
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. Do these show an error toast or something similar? 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. Yes, and now that you mention it I should test for it. The component is called Snackbar. Oh but I think redirecting will stop it from happening :/ |
||
}, | ||
}, | ||
}, | ||
requestingCancel: { | ||
entry: "clearCancellationMessage", | ||
invoke: { | ||
|
@@ -428,6 +453,13 @@ export const workspaceMachine = createMachine( | |
throw Error("Cannot stop workspace without workspace id") | ||
} | ||
}, | ||
deleteWorkspace: async (context) => { | ||
if (context.workspace) { | ||
return await API.deleteWorkspace(context.workspace.id) | ||
} else { | ||
throw Error("Cannot delete workspace without workspace id") | ||
} | ||
}, | ||
cancelWorkspace: async (context) => { | ||
if (context.workspace) { | ||
return await API.cancelWorkspaceBuild(context.workspace.latest_build.id) | ||
|
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.
Praise: Nice 😎