-
Notifications
You must be signed in to change notification settings - Fork 892
refactor: Make workspace status more visible #3130
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
13 commits
Select commit
Hold shift + click to select a range
f69a361
Create workspace status badge
BrunoQuaresma 17b0189
Add badges to the workspace page
BrunoQuaresma 0579d8f
Remove status from the stats
BrunoQuaresma d7c1892
Add badges to the table
BrunoQuaresma 5646929
Merge branch 'main' of github.com:coder/coder into bq/3025
BrunoQuaresma bcc7424
Update site/src/components/WorkspaceStatusBadge/WorkspaceStatusBadge.…
BrunoQuaresma 02c04be
Update site/src/components/WorkspacesTable/WorkspacesRow.tsx
BrunoQuaresma 7e66e4b
Update site/src/components/WorkspacesTable/WorkspacesRow.tsx
BrunoQuaresma 7f3ef76
Remove unused function
BrunoQuaresma d84aa6d
Merge branch 'bq/3025' of github.com:coder/coder into bq/3025
BrunoQuaresma e82a6d3
Fix user error
BrunoQuaresma 3eef9d9
Add missed status role
BrunoQuaresma a3f5483
Fix fmt
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
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
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
71 changes: 71 additions & 0 deletions
71
site/src/components/WorkspaceStatusBadge/WorkspaceStatusBadge.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,71 @@ | ||
import { Story } from "@storybook/react" | ||
import { | ||
MockCanceledWorkspace, | ||
MockCancelingWorkspace, | ||
MockDeletedWorkspace, | ||
MockDeletingWorkspace, | ||
MockFailedWorkspace, | ||
MockQueuedWorkspace, | ||
MockStartingWorkspace, | ||
MockStoppedWorkspace, | ||
MockStoppingWorkspace, | ||
MockWorkspace, | ||
} from "testHelpers/renderHelpers" | ||
import { WorkspaceStatusBadge, WorkspaceStatusBadgeProps } from "./WorkspaceStatusBadge" | ||
|
||
export default { | ||
title: "components/WorkspaceStatusBadge", | ||
component: WorkspaceStatusBadge, | ||
} | ||
|
||
const Template: Story<WorkspaceStatusBadgeProps> = (args) => <WorkspaceStatusBadge {...args} /> | ||
|
||
export const Running = Template.bind({}) | ||
Running.args = { | ||
build: MockWorkspace.latest_build, | ||
} | ||
|
||
export const Starting = Template.bind({}) | ||
Starting.args = { | ||
build: MockStartingWorkspace.latest_build, | ||
} | ||
|
||
export const Stopped = Template.bind({}) | ||
Stopped.args = { | ||
build: MockStoppedWorkspace.latest_build, | ||
} | ||
|
||
export const Stopping = Template.bind({}) | ||
Stopping.args = { | ||
build: MockStoppingWorkspace.latest_build, | ||
} | ||
|
||
export const Deleting = Template.bind({}) | ||
Deleting.args = { | ||
build: MockDeletingWorkspace.latest_build, | ||
} | ||
|
||
export const Deleted = Template.bind({}) | ||
Deleted.args = { | ||
build: MockDeletedWorkspace.latest_build, | ||
} | ||
|
||
export const Canceling = Template.bind({}) | ||
Canceling.args = { | ||
build: MockCancelingWorkspace.latest_build, | ||
} | ||
|
||
export const Canceled = Template.bind({}) | ||
Canceled.args = { | ||
build: MockCanceledWorkspace.latest_build, | ||
} | ||
|
||
export const Failed = Template.bind({}) | ||
Failed.args = { | ||
build: MockFailedWorkspace.latest_build, | ||
} | ||
|
||
export const Queued = Template.bind({}) | ||
Queued.args = { | ||
build: MockQueuedWorkspace.latest_build, | ||
} |
174 changes: 174 additions & 0 deletions
174
site/src/components/WorkspaceStatusBadge/WorkspaceStatusBadge.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,174 @@ | ||
import CircularProgress from "@material-ui/core/CircularProgress" | ||
import { makeStyles, Theme, useTheme } from "@material-ui/core/styles" | ||
import ErrorIcon from "@material-ui/icons/ErrorOutline" | ||
import PlayIcon from "@material-ui/icons/PlayArrowOutlined" | ||
import StopIcon from "@material-ui/icons/StopOutlined" | ||
import { WorkspaceBuild } from "api/typesGenerated" | ||
import React from "react" | ||
import { MONOSPACE_FONT_FAMILY } from "theme/constants" | ||
import { combineClasses } from "util/combineClasses" | ||
import { getWorkspaceStatus } from "util/workspace" | ||
|
||
const StatusLanguage = { | ||
loading: "Loading", | ||
started: "Running", | ||
starting: "Starting", | ||
stopping: "Stopping", | ||
stopped: "Stopped", | ||
deleting: "Deleting", | ||
deleted: "Deleted", | ||
canceling: "Canceling action", | ||
canceled: "Canceled action", | ||
failed: "Failed", | ||
queued: "Queued", | ||
} | ||
|
||
const LoadingIcon: React.FC = () => { | ||
return <CircularProgress size={10} style={{ color: "#FFF" }} /> | ||
} | ||
|
||
export const getStatus = ( | ||
theme: Theme, | ||
build: WorkspaceBuild, | ||
): { | ||
borderColor: string | ||
backgroundColor: string | ||
text: string | ||
icon: React.ReactNode | ||
} => { | ||
const status = getWorkspaceStatus(build) | ||
switch (status) { | ||
case undefined: | ||
return { | ||
borderColor: theme.palette.text.secondary, | ||
backgroundColor: theme.palette.text.secondary, | ||
text: StatusLanguage.loading, | ||
icon: <LoadingIcon />, | ||
} | ||
case "started": | ||
return { | ||
borderColor: theme.palette.success.main, | ||
backgroundColor: theme.palette.success.dark, | ||
text: StatusLanguage.started, | ||
icon: <PlayIcon />, | ||
} | ||
case "starting": | ||
return { | ||
borderColor: theme.palette.success.main, | ||
backgroundColor: theme.palette.success.dark, | ||
text: StatusLanguage.starting, | ||
icon: <LoadingIcon />, | ||
} | ||
case "stopping": | ||
return { | ||
borderColor: theme.palette.warning.main, | ||
backgroundColor: theme.palette.warning.dark, | ||
text: StatusLanguage.stopping, | ||
icon: <LoadingIcon />, | ||
} | ||
case "stopped": | ||
return { | ||
borderColor: theme.palette.warning.main, | ||
backgroundColor: theme.palette.warning.dark, | ||
text: StatusLanguage.stopped, | ||
icon: <StopIcon />, | ||
} | ||
case "deleting": | ||
return { | ||
borderColor: theme.palette.warning.main, | ||
backgroundColor: theme.palette.warning.dark, | ||
text: StatusLanguage.deleting, | ||
icon: <LoadingIcon />, | ||
} | ||
case "deleted": | ||
return { | ||
borderColor: theme.palette.error.main, | ||
backgroundColor: theme.palette.error.dark, | ||
text: StatusLanguage.deleted, | ||
icon: <ErrorIcon />, | ||
} | ||
case "canceling": | ||
return { | ||
borderColor: theme.palette.warning.main, | ||
backgroundColor: theme.palette.warning.dark, | ||
text: StatusLanguage.canceling, | ||
icon: <LoadingIcon />, | ||
} | ||
case "canceled": | ||
return { | ||
borderColor: theme.palette.warning.main, | ||
backgroundColor: theme.palette.warning.dark, | ||
text: StatusLanguage.canceled, | ||
icon: <ErrorIcon />, | ||
} | ||
case "error": | ||
return { | ||
borderColor: theme.palette.error.main, | ||
backgroundColor: theme.palette.error.dark, | ||
text: StatusLanguage.failed, | ||
icon: <ErrorIcon />, | ||
} | ||
case "queued": | ||
return { | ||
borderColor: theme.palette.info.main, | ||
backgroundColor: theme.palette.info.dark, | ||
text: StatusLanguage.queued, | ||
icon: <LoadingIcon />, | ||
} | ||
} | ||
throw new Error("unknown text " + status) | ||
} | ||
|
||
export type WorkspaceStatusBadgeProps = { | ||
build: WorkspaceBuild | ||
className?: string | ||
} | ||
|
||
export const WorkspaceStatusBadge: React.FC<WorkspaceStatusBadgeProps> = ({ build, className }) => { | ||
const styles = useStyles() | ||
const theme = useTheme() | ||
const { text, icon, ...colorStyles } = getStatus(theme, build) | ||
return ( | ||
<div | ||
className={combineClasses([styles.wrapper, className])} | ||
style={{ ...colorStyles }} | ||
role="status" | ||
> | ||
<div className={styles.iconWrapper}>{icon}</div> | ||
{text} | ||
</div> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
wrapper: { | ||
fontFamily: MONOSPACE_FONT_FAMILY, | ||
display: "inline-flex", | ||
alignItems: "center", | ||
borderWidth: 1, | ||
borderStyle: "solid", | ||
borderRadius: 99999, | ||
fontSize: 14, | ||
fontWeight: 500, | ||
color: "#FFF", | ||
height: theme.spacing(3), | ||
paddingLeft: theme.spacing(0.75), | ||
paddingRight: theme.spacing(1.5), | ||
whiteSpace: "nowrap", | ||
}, | ||
|
||
iconWrapper: { | ||
marginRight: theme.spacing(0.5), | ||
width: theme.spacing(2), | ||
height: theme.spacing(2), | ||
lineHeight: 0, | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
|
||
"& > svg": { | ||
width: theme.spacing(2), | ||
height: theme.spacing(2), | ||
}, | ||
}, | ||
})) |
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
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
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.