Skip to content

feat: Workspace StatusBar #1362

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 52 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b1cc9d6
Move component and prep
presleyp May 5, 2022
0da5e7e
Make WorkspaceSection more reusable
presleyp May 5, 2022
580e801
Lay out elements
presleyp May 5, 2022
b995f4a
Layout tweaks
presleyp May 6, 2022
e7dc082
Add outdated to Workspace type
presleyp May 6, 2022
7f6bbda
Fill out status bar component
presleyp May 6, 2022
08b01c0
Merge branch 'main' into statusbar/presleyp/1032
presleyp May 6, 2022
1bc3e35
Format
presleyp May 6, 2022
ccbf527
Add transition to types
presleyp May 6, 2022
f6bcbaa
Add api handlers for build toggle
presleyp May 9, 2022
db348a6
Format
presleyp May 9, 2022
8d5fcfd
Parallelize machine
presleyp May 9, 2022
62c40f4
Lay out basics of build submachine
presleyp May 9, 2022
eaa353d
Pipe start and stop events through - needs status
presleyp May 9, 2022
399390e
Attempt at a machine
presleyp May 10, 2022
c100ec5
Update mock
presleyp May 10, 2022
903e8ee
Render status and buttons
presleyp May 10, 2022
e8e81ce
Fix type error on template page
presleyp May 10, 2022
2226fea
Move Settings
presleyp May 10, 2022
df0bc5b
Format
presleyp May 10, 2022
14bd598
Keep refreshed workspace
presleyp May 10, 2022
c93dde3
Merge branch 'main' into statusbar/presleyp/1032
presleyp May 10, 2022
1093103
Make it switch workspaces
presleyp May 10, 2022
478db51
Lint
presleyp May 10, 2022
40a62a8
Fix relative api path
presleyp May 10, 2022
bd3a026
Test
presleyp May 10, 2022
9786f6c
Fix polling
presleyp May 10, 2022
7727a1b
Add loading workspace state
presleyp May 10, 2022
4a57152
Format
presleyp May 10, 2022
e3ae1b8
Add stub settings page
presleyp May 11, 2022
2695a29
Format
presleyp May 11, 2022
44e4552
Merge branch 'main' into statusbar/presleyp/1032
presleyp May 11, 2022
d83e5ac
Lint
presleyp May 11, 2022
f909a86
Get rid of let
presleyp May 11, 2022
5dcec61
Merge branch 'main' into statusbar/presleyp/1032
presleyp May 11, 2022
be86750
Add update
presleyp May 12, 2022
992ee0c
Make start use version id
presleyp May 12, 2022
9903c96
Merge branch 'main' into statusbar/presleyp/1032
presleyp May 12, 2022
91d5811
Merge branch 'main' into statusbar/presleyp/1032
presleyp May 12, 2022
9cd386e
Fix imports
presleyp May 12, 2022
1a09166
Add polling for outdated
presleyp May 12, 2022
aee54a0
Merge branch 'main' into statusbar/presleyp/1032
presleyp May 12, 2022
e9758c7
Rely on context instead of finite state for status
presleyp May 12, 2022
87fee06
Handle canceling
presleyp May 13, 2022
b3f6b8c
Fix tests
presleyp May 13, 2022
39e84d9
Format
presleyp May 13, 2022
06abf62
Display errors so users know when button presses didn't work
presleyp May 13, 2022
8552ea2
Fix api typo, remove logging
presleyp May 13, 2022
72c856e
Lint
presleyp May 13, 2022
259d517
Merge branch 'main' into statusbar/presleyp/1032
presleyp May 13, 2022
24829be
Simplify type
presleyp May 16, 2022
542d865
Add type, extract helper
presleyp May 16, 2022
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
Add update
  • Loading branch information
presleyp committed May 12, 2022
commit be867500bcc2000fe85b2a51aaf4f488670a1501
5 changes: 4 additions & 1 deletion site/src/components/Workspace/Workspace.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { action } from "@storybook/addon-actions"
import { Story } from "@storybook/react"
import React from "react"
import { MockOrganization, MockTemplate, MockWorkspace } from "../../testHelpers"
import { MockOrganization, MockOutdatedWorkspace, MockTemplate, MockWorkspace } from "../../testHelpers"
import { Workspace, WorkspaceProps } from "./Workspace"

export default {
Expand Down Expand Up @@ -37,3 +37,6 @@ Error.args = { ...Started.args, workspaceStatus: "error" }

export const NoBreadcrumb = Template.bind({})
NoBreadcrumb.args = { ...Started.args, template: undefined }

export const Outdated = Template.bind({})
Outdated.args = { ...Started.args, workspace: MockOutdatedWorkspace }
3 changes: 3 additions & 0 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface WorkspaceProps {
handleStart: () => void
handleStop: () => void
handleRetry: () => void
handleUpdate: () => void
workspaceStatus: WorkspaceStatus
}

Expand All @@ -27,6 +28,7 @@ export const Workspace: React.FC<WorkspaceProps> = ({
handleStart,
handleStop,
handleRetry,
handleUpdate,
workspaceStatus,
}) => {
const styles = useStyles()
Expand All @@ -41,6 +43,7 @@ export const Workspace: React.FC<WorkspaceProps> = ({
handleStart={handleStart}
handleStop={handleStop}
handleRetry={handleRetry}
handleUpdate={handleUpdate}
workspaceStatus={workspaceStatus}
/>
<div className={styles.horizontal}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface WorkspaceStatusBarProps {
handleStart: () => void
handleStop: () => void
handleRetry: () => void
handleUpdate: () => void
workspaceStatus: WorkspaceStatus
}

Expand All @@ -45,6 +46,7 @@ export const WorkspaceStatusBar: React.FC<WorkspaceStatusBarProps> = ({
handleStart,
handleStop,
handleRetry,
handleUpdate,
workspaceStatus,
}) => {
const styles = useStyles()
Expand Down Expand Up @@ -102,7 +104,12 @@ export const WorkspaceStatusBar: React.FC<WorkspaceStatusBarProps> = ({
</Button>
)}

{workspace.outdated && <Button color="primary">{Language.update}</Button>}
{/* Workspace will not update while another job is in progress so hide the button until it's usable */}
{workspace.outdated && ["started", "stopped", "error"].includes(workspaceStatus) && (
<Button onClick={handleUpdate} color="primary">
{Language.update}
</Button>
)}
</div>
</div>
</Stack>
Expand Down
13 changes: 13 additions & 0 deletions site/src/pages/WorkspacePage/WorkspacePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { rest } from "msw"
import React from "react"
import {
MockFailedWorkspace,
MockOutdatedWorkspace,
MockStoppedWorkspace,
MockTemplate,
MockWorkspace,
Expand Down Expand Up @@ -62,4 +63,16 @@ describe("Workspace Page", () => {
const laterStatus = await screen.findByText("Building")
expect(laterStatus).toBeDefined()
})
it("restarts the workspace when the user presses Update", async () => {
renderWithAuth(<WorkspacePage />, { route: `/workspaces/${MockWorkspace.id}`, path: "/workspaces/:workspace" })
server.use(
rest.get(`/api/v2/workspaces/${MockWorkspace.id}`, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(MockOutdatedWorkspace))
}),
)
const updateButton = await screen.findByText("Update")
updateButton.click()
const status = await screen.findByText("Building")
expect(status).toBeDefined()
})
})
1 change: 1 addition & 0 deletions site/src/pages/WorkspacePage/WorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const WorkspacePage: React.FC = () => {
handleStart={() => workspaceSend("START")}
handleStop={() => workspaceSend("STOP")}
handleRetry={() => workspaceSend("RETRY")}
handleUpdate={() => workspaceSend("UPDATE")}
workspaceStatus={workspaceStatus}
/>
</Stack>
Expand Down
28 changes: 4 additions & 24 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,11 @@ export const MockWorkspace: Workspace = {
latest_build: MockWorkspaceBuild,
}

export const MockStoppedWorkspace: Workspace = {
id: "test-workspace",
name: "Test-Workspace",
created_at: "",
updated_at: "",
template_id: MockTemplate.id,
outdated: false,
owner_id: MockUser.id,
autostart_schedule: MockWorkspaceAutostartEnabled.schedule,
autostop_schedule: MockWorkspaceAutostopEnabled.schedule,
latest_build: MockWorkspaceBuildStop,
}
export const MockStoppedWorkspace: Workspace = { ...MockWorkspace, latest_build: MockWorkspaceBuildStop }

export const MockFailedWorkspace: Workspace = {
id: "test-workspace",
name: "Test-Workspace",
created_at: "",
updated_at: "",
template_id: MockTemplate.id,
outdated: false,
owner_id: MockUser.id,
autostart_schedule: MockWorkspaceAutostartEnabled.schedule,
autostop_schedule: MockWorkspaceAutostopEnabled.schedule,
latest_build: MockFailedWorkspaceBuild,
}
export const MockFailedWorkspace: Workspace = { ...MockWorkspace, latest_build: MockFailedWorkspaceBuild }

export const MockOutdatedWorkspace: Workspace = { ...MockWorkspace, outdated: true }

export const MockWorkspaceAgent: WorkspaceAgent = {
id: "test-workspace-agent",
Expand Down
44 changes: 41 additions & 3 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ interface WorkspaceContext {
workspace?: Types.Workspace
template?: Types.Template
organization?: Types.Organization
build?: TypesGen.WorkspaceBuild
getWorkspaceError?: Error | unknown
getTemplateError?: Error | unknown
getOrganizationError?: Error | unknown
// error enqueuing a ProvisionerJob to create a new WorkspaceBuild
jobError?: Error | unknown
// error creating a new WorkspaceBuild
buildError?: Error | unknown
// these are separate from get X errors because they don't make the page unusable
refreshWorkspaceError: Error | unknown
refreshTemplateError: Error | unknown
}

type WorkspaceEvent =
| { type: "GET_WORKSPACE"; workspaceId: string }
| { type: "START" }
| { type: "STOP" }
| { type: "RETRY" }
| { type: "UPDATE" }
| { type: "REFRESH_WORKSPACE" }

export const workspaceMachine = createMachine(
Expand Down Expand Up @@ -60,12 +65,13 @@ export const workspaceMachine = createMachine(
tags: "loading",
},
gettingWorkspace: {
entry: ["clearGetWorkspaceError", "clearContext"],
invoke: {
src: "getWorkspace",
id: "getWorkspace",
onDone: {
target: "ready",
actions: ["assignWorkspace", "clearGetWorkspaceError"],
actions: ["assignWorkspace"],
},
onError: {
target: "error",
Expand Down Expand Up @@ -116,6 +122,9 @@ export const workspaceMachine = createMachine(
},
build: {
initial: "dispatch",
on: {
UPDATE: "#workspaceState.ready.build.refreshingTemplate",
},
states: {
dispatch: {
always: [
Expand Down Expand Up @@ -156,7 +165,7 @@ export const workspaceMachine = createMachine(
src: "startWorkspace",
onDone: {
target: "buildingStart",
actions: "clearJobError",
actions: ["assignBuild", "clearJobError"],
},
onError: {
target: "error",
Expand All @@ -169,7 +178,7 @@ export const workspaceMachine = createMachine(
invoke: {
id: "stopWorkspace",
src: "stopWorkspace",
onDone: { target: "buildingStop", actions: "clearJobError" },
onDone: { target: "buildingStop", actions: ["assignBuild", "clearJobError"] },
onError: {
target: "error",
actions: "assignJobError",
Expand Down Expand Up @@ -239,6 +248,15 @@ export const workspaceMachine = createMachine(
},
tags: ["buildLoading", "stopping"],
},
refreshingTemplate: {
entry: "clearRefreshTemplateError",
invoke: {
id: "refreshTemplate",
src: "getTemplate",
onDone: { target: "#workspaceState.ready.build.requestingStart", actions: "assignTemplate" },
onError: { target: "error", actions: "assignRefreshTemplateError" },
},
},
error: {
on: {
RETRY: [
Expand Down Expand Up @@ -266,6 +284,14 @@ export const workspaceMachine = createMachine(
},
{
actions: {
// Clear data about an old workspace when looking at a new one
clearContext: () =>
assign({
workspace: undefined,
template: undefined,
organization: undefined,
build: undefined,
}),
assignWorkspace: assign({
workspace: (_, event) => event.data,
}),
Expand All @@ -287,6 +313,10 @@ export const workspaceMachine = createMachine(
getOrganizationError: (_, event) => event.data,
}),
clearGetOrganizationError: (context) => assign({ ...context, getOrganizationError: undefined }),
assignBuild: (_, event) =>
assign({
build: event.data,
}),
assignJobError: (_, event) =>
assign({
jobError: event.data,
Expand All @@ -311,6 +341,14 @@ export const workspaceMachine = createMachine(
assign({
refreshWorkspaceError: undefined,
}),
assignRefreshTemplateError: (_, event) =>
assign({
refreshTemplateError: event.data,
}),
clearRefreshTemplateError: (_) =>
assign({
refreshTemplateError: undefined,
}),
},
guards: {
workspaceIsStarted: (context) =>
Expand Down