Skip to content
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
Remove retry code
  • Loading branch information
presleyp committed May 25, 2022
commit 53347ffd96dfd1ea484fed1509f458e10c89174c
1 change: 0 additions & 1 deletion site/src/components/Workspace/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Started.args = {
workspace: MockWorkspace,
handleStart: action("start"),
handleStop: action("stop"),
handleRetry: action("retry"),
resources: [MockWorkspaceResource, MockWorkspaceResource2],
builds: [MockWorkspaceBuild],
}
Expand Down
3 changes: 0 additions & 3 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { WorkspaceStats } from "../WorkspaceStats/WorkspaceStats"
export interface WorkspaceProps {
handleStart: () => void
handleStop: () => void
handleRetry: () => void
handleUpdate: () => void
handleCancel: () => void
workspace: TypesGen.Workspace
Expand All @@ -29,7 +28,6 @@ export interface WorkspaceProps {
export const Workspace: React.FC<WorkspaceProps> = ({
handleStart,
handleStop,
handleRetry,
handleUpdate,
handleCancel,
workspace,
Expand Down Expand Up @@ -57,7 +55,6 @@ export const Workspace: React.FC<WorkspaceProps> = ({
workspace={workspace}
handleStart={handleStart}
handleStop={handleStop}
handleRetry={handleRetry}
handleUpdate={handleUpdate}
handleCancel={handleCancel}
/>
Expand Down
18 changes: 6 additions & 12 deletions site/src/components/WorkspaceActions/WorkspaceActions.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Button from "@material-ui/core/Button"
import Link from "@material-ui/core/Link"
import { makeStyles } from "@material-ui/core/styles"
import CancelIcon from "@material-ui/icons/Cancel"
import CloudDownloadIcon from "@material-ui/icons/CloudDownload"
import PlayArrowRoundedIcon from "@material-ui/icons/PlayArrowRounded"
import ReplayIcon from "@material-ui/icons/Replay"
import StopIcon from "@material-ui/icons/Stop"
import CancelIcon from "@material-ui/icons/Cancel"
import React from "react"
import { Link as RouterLink } from "react-router-dom"
import { Workspace } from "../../api/typesGenerated"
Expand All @@ -18,7 +17,6 @@ export const Language = {
stopping: "Stopping workspace",
start: "Start workspace",
starting: "Starting workspace",
retry: "Retry",
cancel: "Cancel action",
update: "Update workspace",
}
Expand All @@ -38,17 +36,14 @@ const canAcceptJobs = (workspaceStatus: WorkspaceStatus) =>
const canCancelJobs = (workspaceStatus: WorkspaceStatus) =>
["starting", "stopping", "deleting"].includes(workspaceStatus)

const canStart = (workspaceStatus: WorkspaceStatus) =>
["stopped", "canceled", "error"].includes(workspaceStatus)
const canStart = (workspaceStatus: WorkspaceStatus) => ["stopped", "canceled", "error"].includes(workspaceStatus)

const canStop = (workspaceStatus: WorkspaceStatus) =>
["started", "canceled", "error"].includes(workspaceStatus)
const canStop = (workspaceStatus: WorkspaceStatus) => ["started", "canceled", "error"].includes(workspaceStatus)

export interface WorkspaceActionsProps {
workspace: Workspace
handleStart: () => void
handleStop: () => void
handleRetry: () => void
handleUpdate: () => void
handleCancel: () => void
}
Expand All @@ -57,9 +52,8 @@ export const WorkspaceActions: React.FC<WorkspaceActionsProps> = ({
workspace,
handleStart,
handleStop,
handleRetry,
handleUpdate,
handleCancel
handleCancel,
}) => {
const styles = useStyles()
const workspaceStatus = getWorkspaceStatus(workspace.latest_build)
Expand Down Expand Up @@ -89,14 +83,14 @@ export const WorkspaceActions: React.FC<WorkspaceActionsProps> = ({
isLoading={workspaceStatus === "stopping"}
/>
)}
{canCancelJobs(workspaceStatus) &&
{canCancelJobs(workspaceStatus) && (
<WorkspaceActionButton
className={styles.actionButton}
icon={<CancelIcon />}
onClick={handleCancel}
label={Language.cancel}
/>
}
)}
{workspace.outdated && canAcceptJobs(workspaceStatus) && (
<Button className={styles.actionButton} startIcon={<CloudDownloadIcon />} onClick={handleUpdate}>
{Language.update}
Expand Down
40 changes: 0 additions & 40 deletions site/src/pages/WorkspacePage/WorkspacePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,46 +86,6 @@ describe("Workspace Page", () => {
.mockImplementation(() => Promise.resolve(MockWorkspaceBuild))
await testButton(Language.start, startWorkspaceMock)
})
it("requests a start job when the user presses Retry after trying to start", async () => {
// Use a workspace that failed during start
server.use(
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
...MockFailedWorkspace,
latest_build: {
...MockFailedWorkspace.latest_build,
transition: "start",
},
}),
)
}),
)
const startWorkSpaceMock = jest.spyOn(api, "startWorkspace").mockResolvedValueOnce(MockWorkspaceBuild)
await testButton(Language.retry, startWorkSpaceMock)
})
it("requests a stop job when the user presses Retry after trying to stop", async () => {
// Use a workspace that failed during stop
server.use(
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
...MockFailedWorkspace,
latest_build: {
...MockFailedWorkspace.latest_build,
transition: "stop",
},
}),
)
}),
)
const stopWorkspaceMock = jest
.spyOn(api, "stopWorkspace")
.mockImplementation(() => Promise.resolve(MockWorkspaceBuild))
await testButton(Language.retry, stopWorkspaceMock)
})
it("requests a template when the user presses Update", async () => {
const getTemplateMock = jest.spyOn(api, "getTemplate").mockResolvedValueOnce(MockTemplate)
server.use(
Expand Down
1 change: 0 additions & 1 deletion site/src/pages/WorkspacePage/WorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const WorkspacePage: React.FC = () => {
workspace={workspace}
handleStart={() => workspaceSend("START")}
handleStop={() => workspaceSend("STOP")}
handleRetry={() => workspaceSend("RETRY")}
handleUpdate={() => workspaceSend("UPDATE")}
handleCancel={() => workspaceSend("CANCEL")}
resources={resources}
Expand Down
25 changes: 12 additions & 13 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export type WorkspaceEvent =
| { type: "GET_WORKSPACE"; workspaceId: string }
| { type: "START" }
| { type: "STOP" }
| { type: "RETRY" }
| { type: "UPDATE" }
| { type: "CANCEL" }
| { type: "LOAD_MORE_BUILDS" }
Expand Down Expand Up @@ -136,9 +135,8 @@ export const workspaceMachine = createMachine(
on: {
START: "requestingStart",
STOP: "requestingStop",
RETRY: [{ cond: "triedToStart", target: "requestingStart" }, { target: "requestingStop" }],
UPDATE: "refreshingTemplate",
CANCEL: "requestingCancel"
CANCEL: "requestingCancel",
},
},
requestingStart: {
Expand Down Expand Up @@ -182,9 +180,9 @@ export const workspaceMachine = createMachine(
},
onError: {
target: "idle",
actions: ["assignCancellationMessage", "displayCancellationError"]
}
}
actions: ["assignCancellationMessage", "displayCancellationError"],
},
},
},
refreshingTemplate: {
entry: "clearRefreshTemplateError",
Expand Down Expand Up @@ -314,12 +312,14 @@ export const workspaceMachine = createMachine(
assign({
buildError: undefined,
}),
assignCancellationMessage: (_, event) => assign({
cancellationMessage: event.data
}),
clearCancellationMessage: (_) => assign({
cancellationMessage: undefined
}),
assignCancellationMessage: (_, event) =>
assign({
cancellationMessage: event.data,
}),
clearCancellationMessage: (_) =>
assign({
cancellationMessage: undefined,
}),
displayCancellationError: (context) => {
displayError(context.cancellationMessage)
},
Expand Down Expand Up @@ -400,7 +400,6 @@ export const workspaceMachine = createMachine(
}),
},
guards: {
triedToStart: (context) => context.workspace?.latest_build.transition === "start",
hasMoreBuilds: (_) => false,
},
services: {
Expand Down