-
Notifications
You must be signed in to change notification settings - Fork 937
feat: Redesign the workspace page #1620
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e70fce6
Refactor workspace page
BrunoQuaresma 90a2c6c
Add missing stories
BrunoQuaresma 56516ef
Fix tests
BrunoQuaresma 81eb20e
Remove unused CSS role
BrunoQuaresma 6df8903
Add status role
BrunoQuaresma 550a92e
Merge branch 'main' of github.com:coder/coder into bq/1581-refactor-w…
BrunoQuaresma 4821acc
Update site/src/components/Workspace/Workspace.tsx
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"coderd", | ||
"coderdtest", | ||
"codersdk", | ||
"cronstrue", | ||
"devel", | ||
"drpc", | ||
"drpcconn", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import React from "react" | ||
|
||
export interface StackProps { | ||
spacing?: number | ||
type Direction = "column" | "row" | ||
|
||
interface StyleProps { | ||
spacing: number | ||
direction: Direction | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
stack: { | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: ({ spacing }: { spacing: number }) => theme.spacing(spacing), | ||
flexDirection: ({ direction }: StyleProps) => direction, | ||
gap: ({ spacing }: StyleProps) => theme.spacing(spacing), | ||
}, | ||
})) | ||
|
||
export const Stack: React.FC<StackProps> = ({ children, spacing = 2 }) => { | ||
const styles = useStyles({ spacing }) | ||
export interface StackProps { | ||
spacing?: number | ||
direction?: Direction | ||
} | ||
|
||
export const Stack: React.FC<StackProps> = ({ children, spacing = 2, direction = "column" }) => { | ||
const styles = useStyles({ spacing, direction }) | ||
return <div className={styles.stack}>{children}</div> | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
site/src/components/WorkspaceActionButton/WorkspaceActionButton.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import PlayArrowRoundedIcon from "@material-ui/icons/PlayArrowRounded" | ||
import { ComponentMeta, Story } from "@storybook/react" | ||
import React from "react" | ||
import { WorkspaceActionButton, WorkspaceActionButtonProps } from "./WorkspaceActionButton" | ||
|
||
export default { | ||
title: "components/WorkspaceActionButton", | ||
component: WorkspaceActionButton, | ||
} as ComponentMeta<typeof WorkspaceActionButton> | ||
|
||
const Template: Story<WorkspaceActionButtonProps> = (args) => <WorkspaceActionButton {...args} /> | ||
|
||
export const Example = Template.bind({}) | ||
Example.args = { | ||
icon: <PlayArrowRoundedIcon />, | ||
label: "Start workspace", | ||
loadingLabel: "Starting workspace", | ||
isLoading: false, | ||
} | ||
|
||
export const Loading = Template.bind({}) | ||
Loading.args = { | ||
icon: <PlayArrowRoundedIcon />, | ||
label: "Start workspace", | ||
loadingLabel: "Starting workspace", | ||
isLoading: true, | ||
} |
42 changes: 42 additions & 0 deletions
42
site/src/components/WorkspaceActionButton/WorkspaceActionButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Button from "@material-ui/core/Button" | ||
import CircularProgress from "@material-ui/core/CircularProgress" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import React from "react" | ||
|
||
export interface WorkspaceActionButtonProps { | ||
label: string | ||
loadingLabel: string | ||
isLoading: boolean | ||
icon: JSX.Element | ||
onClick: () => void | ||
className?: string | ||
} | ||
|
||
export const WorkspaceActionButton: React.FC<WorkspaceActionButtonProps> = ({ | ||
label, | ||
loadingLabel, | ||
isLoading, | ||
icon, | ||
onClick, | ||
className, | ||
}) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<Button | ||
className={className} | ||
startIcon={isLoading ? <CircularProgress size={12} className={styles.spinner} /> : icon} | ||
onClick={onClick} | ||
disabled={isLoading} | ||
> | ||
{isLoading ? loadingLabel : label} | ||
</Button> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
spinner: { | ||
color: theme.palette.text.disabled, | ||
marginRight: theme.spacing(1), | ||
}, | ||
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import Button from "@material-ui/core/Button" | ||
import Link from "@material-ui/core/Link" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
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 React from "react" | ||
import { Link as RouterLink } from "react-router-dom" | ||
import { Workspace } from "../../api/typesGenerated" | ||
import { WorkspaceStatus } from "../../util/workspace" | ||
import { Stack } from "../Stack/Stack" | ||
import { WorkspaceActionButton } from "../WorkspaceActionButton/WorkspaceActionButton" | ||
|
||
export const Language = { | ||
stop: "Stop workspace", | ||
stopping: "Stopping workspace", | ||
start: "Start workspace", | ||
starting: "Starting workspace", | ||
retry: "Retry", | ||
update: "Update workspace", | ||
} | ||
|
||
/** | ||
* Jobs submitted while another job is in progress will be discarded, | ||
* so check whether workspace job status has reached completion (whether successful or not). | ||
*/ | ||
const canAcceptJobs = (workspaceStatus: WorkspaceStatus) => | ||
["started", "stopped", "deleted", "error", "canceled"].includes(workspaceStatus) | ||
|
||
export interface WorkspaceActionsProps { | ||
workspace: Workspace | ||
workspaceStatus: WorkspaceStatus | ||
handleStart: () => void | ||
handleStop: () => void | ||
handleRetry: () => void | ||
handleUpdate: () => void | ||
} | ||
|
||
export const WorkspaceActions: React.FC<WorkspaceActionsProps> = ({ | ||
workspace, | ||
workspaceStatus, | ||
handleStart, | ||
handleStop, | ||
handleRetry, | ||
handleUpdate, | ||
}) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<Stack direction="row" spacing={1}> | ||
<Link underline="none" component={RouterLink} to="edit"> | ||
<Button variant="outlined">Settings</Button> | ||
</Link> | ||
{(workspaceStatus === "started" || workspaceStatus === "stopping") && ( | ||
<WorkspaceActionButton | ||
className={styles.actionButton} | ||
icon={<StopIcon />} | ||
onClick={handleStop} | ||
label={Language.stop} | ||
loadingLabel={Language.stopping} | ||
isLoading={workspaceStatus === "stopping"} | ||
/> | ||
)} | ||
{(workspaceStatus === "stopped" || workspaceStatus === "starting") && ( | ||
<WorkspaceActionButton | ||
className={styles.actionButton} | ||
icon={<PlayArrowRoundedIcon />} | ||
onClick={handleStart} | ||
label={Language.start} | ||
loadingLabel={Language.starting} | ||
isLoading={workspaceStatus === "starting"} | ||
/> | ||
)} | ||
{workspaceStatus === "error" && ( | ||
<Button className={styles.actionButton} startIcon={<ReplayIcon />} onClick={handleRetry}> | ||
{Language.retry} | ||
</Button> | ||
)} | ||
{workspace.outdated && canAcceptJobs(workspaceStatus) && ( | ||
<Button className={styles.actionButton} startIcon={<CloudDownloadIcon />} onClick={handleUpdate}> | ||
{Language.update} | ||
</Button> | ||
)} | ||
</Stack> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
actionButton: { | ||
// Set fixed width for the action buttons so they will not change the size | ||
// during the transitions | ||
width: theme.spacing(30), | ||
}, | ||
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.