8000 feat: show deleted workspace after delete action by Kira-Pilot · Pull Request #2208 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: show deleted workspace after delete action #2208

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

Merged
merged 8 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
x state pass
  • Loading branch information
Kira-Pilot committed Jun 8, 2022
commit 2931b60bf0625907e25df8fa94790d9f579b3cd1
7 changes: 5 additions & 2 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ export const getTemplateVersionResources = async (versionId: string): Promise<Ty
return response.data
}

export const getWorkspace = async (workspaceId: string, params?: any): Promise<TypesGen.Workspace> => {
console.log("in here", params)
export const getWorkspace = async (
workspaceId: string,
params?: TypesGen.WorkspaceOptions,
): Promise<TypesGen.Workspace> => {
console.log("in get Workspace API method", params)
const response = await axios.get<TypesGen.Workspace>(`/api/v2/workspaces/${workspaceId}`, { params })
return response.data
}
Expand Down
2 changes: 0 additions & 2 deletions site/src/components/Workspace/Workspace.tsx
10000
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export const Workspace: FC<WorkspaceProps> = ({
builds,
}) => {
const styles = useStyles()
console.log("workspace", workspace)
const isDeleted = getWorkspaceStatus(workspace.latest_build) === succeededToStatus["delete"]
console.log("isDeleted", isDeleted)
return (
<Margins>
<PageHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const shouldDisplay = (workspace: TypesGen.Workspace): boolean => {
if (!isWorkspaceOn(workspace)) {
return false
} else {
// a mannual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
// SEE: #1834
const deadline = dayjs(workspace.latest_build.deadline).utc()
const hasDeadline = deadline.year() > 1
Expand Down
4 changes: 1 addition & 3 deletions site/src/pages/WorkspacePage/WorkspacePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMachine } from "@xstate/react"
import React, { useEffect } from "react"
import { Helmet } from "react-helmet"
import { useNavigate, useParams } from "react-router-dom"
import { useParams } from "react-router-dom"
import { DeleteWorkspaceDialog } from "../../components/DeleteWorkspaceDialog/DeleteWorkspaceDialog"
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary"
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"
Expand All @@ -13,7 +13,6 @@ import { workspaceScheduleBannerMachine } from "../../xServices/workspaceSchedul

export const WorkspacePage: React.FC = () => {
const { username: usernameQueryParam, workspace: workspaceQueryParam } = useParams()
const navigate = useNavigate()
const username = firstOrItem(usernameQueryParam, null)
const workspaceName = firstOrItem(workspaceQueryParam, null)

Expand Down Expand Up @@ -63,7 +62,6 @@ export const WorkspacePage: React.FC = () => {
handleCancel={() => workspaceSend("CANCEL_DELETE")}
handleConfirm={() => {
workspaceSend("DELETE")
navigate("/workspaces")
}}
/>
</>
Expand Down
32 changes: 30 additions & 2 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export const workspaceMachine = createMachine(
getWorkspace: {
data: TypesGen.Workspace
}
getDeletedWorkspace: {
data: TypesGen.Workspace
}
getTemplate: {
data: TypesGen.Template
}
Expand Down Expand Up @@ -93,6 +96,9 @@ export const workspaceMachine = createMachine(
idle: {
tags: "loading",
},
deleted: {
tags: "deleted",
},
gettingWorkspace: {
entry: ["clearGetWorkspaceError", "clearContext"],
invoke: {
Expand Down Expand Up @@ -183,10 +189,10 @@ export const workspaceMachine = createMachine(
requestingDelete: {
entry: "clearBuildError",
invoke: {
id: "deleteWorkspace",
id: "deleteWorkspace", // delete the workspace
src: "deleteWorkspace",
onDone: {
target: "idle",
target: "gettingDeletedWorkspace",
actions: ["assignBuild", "refreshTimeline"],
},
onError: {
Expand All @@ -195,6 +201,21 @@ export const workspaceMachine = createMachine(
},
},
},
gettingDeletedWorkspace: {
entry: ["clearGetWorkspaceError", "clearContext"],
invoke: {
id: "getDeletedWorkspace", // request deleted workspace
src: "getDeletedWorkspace",
onDone: {
target: "idle",
actions: ["assignBuild", "refreshTimeline"],
},
onError: {
target: "idle", // error
actions: ["assignBuildError", "displayBuildError"],
},
},
},
requestingCancel: {
entry: "clearCancellationMessage",
invoke: {
Expand Down Expand Up @@ -433,6 +454,13 @@ export const workspaceMachine = createMachine(
getWorkspace: async (_, event) => {
return await API.getWorkspaceByOwnerAndName(event.username, event.workspaceName)
},
getDeletedWorkspace: async (context) => {
if (context.workspace) {
return await API.getWorkspace(context.workspace.id, { deleted: true })
} else {
throw Error("Cannot get workspace without id")
}
},
getTemplate: async (context) => {
if (context.workspace) {
return await API.getTemplate(context.workspace.template_id)
Expand Down
0