- Notifications
You must be signed in to change notification settings - Fork1k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
e70fce6
Refactor workspace page
BrunoQuaresma90a2c6c
Add missing stories
BrunoQuaresma56516ef
Fix tests
BrunoQuaresma81eb20e
Remove unused CSS role
BrunoQuaresma6df8903
Add status role
BrunoQuaresma550a92e
Merge branch 'main' of github.com:coder/coder into bq/1581-refactor-w…
BrunoQuaresma4821acc
Update site/src/components/Workspace/Workspace.tsx
BrunoQuaresmaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions.vscode/settings.json
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" | ||
type Direction = "column" | "row" | ||
interface StyleProps { | ||
spacing: number | ||
direction: Direction | ||
} | ||
const useStyles = makeStyles((theme) => ({ | ||
stack: { | ||
display: "flex", | ||
flexDirection:({ direction }: StyleProps) => direction, | ||
gap: ({ spacing }:StyleProps) => theme.spacing(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,11 +2,13 @@ import { makeStyles } from "@material-ui/core/styles" | ||
import Typography from "@material-ui/core/Typography" | ||
import React from "react" | ||
import * as TypesGen from "../../api/typesGenerated" | ||
import { MONOSPACE_FONT_FAMILY } from "../../theme/constants" | ||
import { WorkspaceStatus } from "../../util/workspace" | ||
import { BuildsTable } from "../BuildsTable/BuildsTable" | ||
import { Stack } from "../Stack/Stack" | ||
import { WorkspaceActions } from "../WorkspaceActions/WorkspaceActions" | ||
import { WorkspaceSection } from "../WorkspaceSection/WorkspaceSection" | ||
import {WorkspaceStats } from "../WorkspaceStats/WorkspaceStats" | ||
export interface WorkspaceProps { | ||
handleStart: () => void | ||
@@ -34,76 +36,62 @@ export const Workspace: React.FC<WorkspaceProps> = ({ | ||
return ( | ||
<div className={styles.root}> | ||
<div className={styles.header}> | ||
<div> | ||
<Typography variant="h4" className={styles.title}> | ||
{workspace.name} | ||
</Typography> | ||
<Typography color="textSecondary" className={styles.subtitle}> | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
{workspace.owner_name} | ||
</Typography> | ||
</div> | ||
<div className={styles.headerActions}> | ||
<WorkspaceActions | ||
workspace={workspace} | ||
handleStart={handleStart} | ||
handleStop={handleStop} | ||
handleRetry={handleRetry} | ||
handleUpdate={handleUpdate} | ||
workspaceStatus={workspaceStatus} | ||
/> | ||
</div> | ||
</div> | ||
<Stack spacing={3}> | ||
<WorkspaceStats workspace={workspace} /> | ||
<WorkspaceSection title="Timeline" contentsProps={{ className: styles.timelineContents }}> | ||
<BuildsTable builds={builds} className={styles.timelineTable} /> | ||
</WorkspaceSection> | ||
</Stack> | ||
</div> | ||
) | ||
} | ||
export const useStyles = makeStyles((theme) => { | ||
return { | ||
root: { | ||
display: "flex", | ||
flexDirection: "column", | ||
}, | ||
header: { | ||
paddingTop: theme.spacing(5), | ||
paddingBottom: theme.spacing(5), | ||
fontFamily: MONOSPACE_FONT_FAMILY, | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
headerActions: { | ||
marginLeft: "auto", | ||
}, | ||
title: { | ||
fontWeight: 600, | ||
fontFamily: "inherit", | ||
}, | ||
subtitle: { | ||
fontFamily: "inherit", | ||
marginTop: theme.spacing(0.5), | ||
}, | ||
timelineContents: { | ||
margin: 0, | ||
27 changes: 27 additions & 0 deletionssite/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 deletionssite/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), | ||
}, | ||
})) |
16 changes: 10 additions & 6 deletionssite/src/components/WorkspaceBuildStats/WorkspaceBuildStats.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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.