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 all commits
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
27 changes: 19 additions & 8 deletions site/src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TemplatesPage } from "./pages/TemplatesPages/TemplatesPage"
import { CreateUserPage } from "./pages/UsersPage/CreateUserPage/CreateUserPage"
import { UsersPage } from "./pages/UsersPage/UsersPage"
import { WorkspacePage } from "./pages/WorkspacePage/WorkspacePage"
import { WorkspaceSettingsPage } from "./pages/WorkspaceSettingsPage/WorkspaceSettingsPage"

const TerminalPage = React.lazy(() => import("./pages/TerminalPage/TerminalPage"))

Expand Down Expand Up @@ -75,14 +76,24 @@ export const AppRouter: React.FC = () => (
</Route>

<Route path="workspaces">
<Route
path=":workspace"
element={
<AuthAndFrame>
<WorkspacePage />
</AuthAndFrame>
}
/>
<Route path=":workspace">
<Route
index
element={
<AuthAndFrame>
<WorkspacePage />
</AuthAndFrame>
}
/>
<Route
path="edit"
element={
<AuthAndFrame>
<WorkspaceSettingsPage />
</AuthAndFrame>
}
/>
</Route>
</Route>

<Route path="users">
Expand Down
16 changes: 16 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios, { AxiosRequestHeaders } from "axios"
import { mutate } from "swr"
import { WorkspaceBuildTransition } from "./types"
import * as TypesGen from "./typesGenerated"

const CONTENT_TYPE_JSON: AxiosRequestHeaders = {
Expand Down Expand Up @@ -132,6 +133,21 @@ export const getWorkspaceResources = async (workspaceBuildID: string): Promise<T
return response.data
}

const postWorkspaceBuild =
(transition: WorkspaceBuildTransition) =>
async (workspaceId: string, template_version_id?: string): Promise<TypesGen.WorkspaceBuild> => {
const payload = {
transition,
template_version_id,
}
const response = await axios.post(`/api/v2/workspaces/${workspaceId}/builds`, payload)
return response.data
}

export const startWorkspace = postWorkspaceBuild("start")
export const stopWorkspace = postWorkspaceBuild("stop")
export const deleteWorkspace = postWorkspaceBuild("delete")

export const createUser = async (user: TypesGen.CreateUserRequest): Promise<TypesGen.User> => {
const response = await axios.post<TypesGen.User>("/api/v2/users", user)
return response.data
Expand Down
2 changes: 2 additions & 0 deletions site/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export interface ReconnectingPTYRequest {
readonly height?: number
readonly width?: number
}

export type WorkspaceBuildTransition = "start" | "stop" | "delete"
41 changes: 38 additions & 3 deletions site/src/components/Workspace/Workspace.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { action } from "@storybook/addon-actions"
import { Story } from "@storybook/react"
import React from "react"
import { MockOrganization, MockTemplate, MockWorkspace } from "../../testHelpers/renderHelpers"
import { MockOrganization, MockOutdatedWorkspace, MockTemplate, MockWorkspace } from "../../testHelpers/renderHelpers"
import { Workspace, WorkspaceProps } from "./Workspace"

export default {
Expand All @@ -11,9 +12,43 @@ export default {

const Template: Story<WorkspaceProps> = (args) => <Workspace {...args} />

export const Example = Template.bind({})
Example.args = {
export const Started = Template.bind({})
Started.args = {
organization: MockOrganization,
template: MockTemplate,
workspace: MockWorkspace,
handleStart: action("start"),
handleStop: action("stop"),
handleRetry: action("retry"),
workspaceStatus: "started",
}

export const Starting = Template.bind({})
Starting.args = { ...Started.args, workspaceStatus: "starting" }

export const Stopped = Template.bind({})
Stopped.args = { ...Started.args, workspaceStatus: "stopped" }

export const Stopping = Template.bind({})
Stopping.args = { ...Started.args, workspaceStatus: "stopping" }

export const Error = Template.bind({})
Error.args = { ...Started.args, workspaceStatus: "error" }

export const BuildLoading = Template.bind({})
BuildLoading.args = { ...Started.args, workspaceStatus: "loading" }

export const Deleting = Template.bind({})
Deleting.args = { ...Started.args, workspaceStatus: "deleting" }

export const Deleted = Template.bind({})
Deleted.args = { ...Started.args, workspaceStatus: "deleted" }

export const Canceling = Template.bind({})
Canceling.args = { ...Started.args, workspaceStatus: "canceling" }

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

export const Outdated = Template.bind({})
Outdated.args = { ...Started.args, workspace: MockOutdatedWorkspace }
15 changes: 0 additions & 15 deletions site/src/components/Workspace/Workspace.test.tsx

This file was deleted.

84 changes: 30 additions & 54 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
import Box from "@material-ui/core/Box"
import Paper from "@material-ui/core/Paper"
import { makeStyles } from "@material-ui/core/styles"
import Typography from "@material-ui/core/Typography"
import CloudCircleIcon from "@material-ui/icons/CloudCircle"
import React from "react"
import { Link } from "react-router-dom"
import * as TypesGen from "../../api/typesGenerated"
import { WorkspaceStatus } from "../../pages/WorkspacePage/WorkspacePage"
import { WorkspaceSchedule } from "../WorkspaceSchedule/WorkspaceSchedule"
import { WorkspaceSection } from "../WorkspaceSection/WorkspaceSection"
import * as Constants from "./constants"
import { WorkspaceStatusBar } from "../WorkspaceStatusBar/WorkspaceStatusBar"

export interface WorkspaceProps {
organization: TypesGen.Organization
organization?: TypesGen.Organization
workspace: TypesGen.Workspace
template: TypesGen.Template
template?: TypesGen.Template
handleStart: () => void
handleStop: () => void
handleRetry: () => void
handleUpdate: () => void
workspaceStatus: WorkspaceStatus
}

/**
* Workspace is the top-level component for viewing an individual workspace
*/
export const Workspace: React.FC<WorkspaceProps> = ({ organization, template, workspace }) => {
export const Workspace: React.FC<WorkspaceProps> = ({
organization,
template,
workspace,
handleStart,
handleStop,
handleRetry,
handleUpdate,
workspaceStatus,
}) => {
const styles = useStyles()

return (
<div className={styles.root}>
<div className={styles.vertical}>
<WorkspaceHeader organization={organization} template={template} workspace={workspace} />
<WorkspaceStatusBar
organization={organization}
template={template}
workspace={workspace}
handleStart={handleStart}
handleStop={handleStop}
handleRetry={handleRetry}
handleUpdate={handleUpdate}
workspaceStatus={workspaceStatus}
/>
<div className={styles.horizontal}>
<div className={styles.sidebarContainer}>
<WorkspaceSection title="Applications">
Expand Down Expand Up @@ -55,40 +75,6 @@ export const Workspace: React.FC<WorkspaceProps> = ({ organization, template, wo
)
}

/**
* Component for the header at the top of the workspace page
*/
export const WorkspaceHeader: React.FC<WorkspaceProps> = ({ organization, template, workspace }) => {
const styles = useStyles()

const templateLink = `/templates/${organization.name}/${template.name}`

return (
<Paper elevation={0} className={styles.section}>
<div className={styles.horizontal}>
<WorkspaceHeroIcon />
<div className={styles.vertical}>
<Typography variant="h4">{workspace.name}</Typography>
<Typography variant="body2" color="textSecondary">
<Link to={templateLink}>{template.name}</Link>
</Typography>
</div>
</div>
</Paper>
)
}

/**
* Component to render the 'Hero Icon' in the header of a workspace
*/
export const WorkspaceHeroIcon: React.FC = () => {
return (
<Box mr="1em">
<CloudCircleIcon width={Constants.TitleIconSize} height={Constants.TitleIconSize} />
</Box>
)
}

/**
* Temporary placeholder component until we have the sections implemented
* Can be removed once the Workspace page has all the necessary sections
Expand All @@ -101,7 +87,7 @@ const Placeholder: React.FC = () => {
)
}

export const useStyles = makeStyles((theme) => {
export const useStyles = makeStyles(() => {
return {
root: {
display: "flex",
Expand All @@ -115,12 +101,6 @@ export const useStyles = makeStyles((theme) => {
display: "flex",
flexDirection: "column",
},
section: {
border: `1px solid ${theme.palette.divider}`,
borderRadius: Constants.CardRadius,
padding: Constants.CardPadding,
margin: theme.spacing(1),
},
sidebarContainer: {
display: "flex",
flexDirection: "column",
Expand All @@ -129,9 +109,5 @@ export const useStyles = makeStyles((theme) => {
timelineContainer: {
flex: 1,
},
icon: {
width: Constants.TitleIconSize,
height: Constants.TitleIconSize,
},
}
})
3 changes: 0 additions & 3 deletions site/src/components/Workspace/constants.ts

This file was deleted.

14 changes: 8 additions & 6 deletions site/src/components/WorkspaceSection/WorkspaceSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import Paper from "@material-ui/core/Paper"
import { makeStyles } from "@material-ui/core/styles"
import Typography from "@material-ui/core/Typography"
import React from "react"
import { CardPadding, CardRadius } from "../Workspace/constants"
import { CardPadding, CardRadius } from "../../theme/constants"

export interface WorkspaceSectionProps {
title: string
title?: string
}

export const WorkspaceSection: React.FC<WorkspaceSectionProps> = ({ title, children }) => {
const styles = useStyles()

return (
<Paper elevation={0} className={styles.root}>
<div className={styles.headerContainer}>
<div className={styles.header}>
<Typography variant="h6">{title}</Typography>
{title && (
<div className={styles.headerContainer}>
<div className={styles.header}>
<Typography variant="h6">{title}</Typography>
</div>
</div>
</div>
)}

<div className={styles.contents}>{children}</div>
</Paper>
Expand Down
Loading