Skip to content

feat(site): add workspace health badge to workspace list #8387

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Story } from "@storybook/react"
import {
MockCanceledWorkspace,
MockCancelingWorkspace,
MockDeletedWorkspace,
MockDeletingWorkspace,
MockFailedWorkspace,
MockPendingWorkspace,
MockStartingWorkspace,
MockStoppedWorkspace,
MockStoppingWorkspace,
MockWorkspace,
MockBuildInfo,
MockEntitlementsWithScheduling,
MockExperiments,
MockAppearance,
} from "testHelpers/entities"
import {
WorkspaceHealthBadge,
WorkspaceHealthBadgeProps,
} from "./WorkspaceHealthBadge"
import { DashboardProviderContext } from "components/Dashboard/DashboardProvider"

export default {
title: "components/WorkspaceHealthBadge",
component: WorkspaceHealthBadge,
}

const MockedAppearance = {
config: MockAppearance,
preview: false,
setPreview: () => null,
save: () => null,
}

const Template: Story<WorkspaceHealthBadgeProps> = (args) => (
<DashboardProviderContext.Provider
value={{
buildInfo: MockBuildInfo,
entitlements: MockEntitlementsWithScheduling,
experiments: MockExperiments,
appearance: MockedAppearance,
}}
>
<WorkspaceHealthBadge {...args} />
</DashboardProviderContext.Provider>
)

export const Running = Template.bind({})
Running.args = {
workspace: MockWorkspace,
}

// TODO(mafredri): Healthyness mocks.

export const Starting = Template.bind({})
Starting.args = {
workspace: MockStartingWorkspace,
}

export const Stopped = Template.bind({})
Stopped.args = {
workspace: MockStoppedWorkspace,
}

export const Stopping = Template.bind({})
Stopping.args = {
workspace: MockStoppingWorkspace,
}

export const Deleting = Template.bind({})
Deleting.args = {
workspace: MockDeletingWorkspace,
}

export const Deleted = Template.bind({})
Deleted.args = {
workspace: MockDeletedWorkspace,
}

export const Canceling = Template.bind({})
Canceling.args = {
workspace: MockCancelingWorkspace,
}

export const Canceled = Template.bind({})
Canceled.args = {
workspace: MockCanceledWorkspace,
}

export const Failed = Template.bind({})
Failed.args = {
workspace: MockFailedWorkspace,
}

export const Pending = Template.bind({})
Pending.args = {
workspace: MockPendingWorkspace,
}
30 changes: 30 additions & 0 deletions site/src/components/WorkspaceHealthBadge/WorkspaceHealthBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Workspace } from "api/typesGenerated"
import { Pill } from "components/Pill/Pill"
import { FC, PropsWithChildren } from "react"
import { ErrorIcon } from "components/Icons/ErrorIcon"
import FavoriteIcon from "@mui/icons-material/Favorite"
import { Maybe } from "components/Conditionals/Maybe"

export type WorkspaceHealthBadgeProps = {
workspace: Workspace
className?: string
}

export const WorkspaceHealthBadge: FC<
PropsWithChildren<WorkspaceHealthBadgeProps>
> = ({ workspace, className }) => {
return (
<Maybe
condition={["starting", "running", "stopping"].includes(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Should we modify the API endpoint instead and do this on the API so that workspace.health = null when it's not possible to know (e.g. stopped workspace)?

workspace.latest_build.status,
)}
>
<Pill
className={className}
icon={workspace.health.healthy ? <FavoriteIcon /> : <ErrorIcon />}
text={workspace.health.healthy ? "Healthy" : "Unhealthy"}
type={workspace.health.healthy ? "success" : "warning"}
/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the popover component here when healthy = false?

</Maybe>
)
}
5 changes: 5 additions & 0 deletions site/src/components/WorkspacesTable/WorkspacesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { OutdatedHelpTooltip } from "components/Tooltips/OutdatedHelpTooltip"
import { Avatar } from "components/Avatar/Avatar"
import { Stack } from "components/Stack/Stack"
import { useClickableTableRow } from "hooks/useClickableTableRow"
import { WorkspaceHealthBadge } from "components/WorkspaceHealthBadge/WorkspaceHealthBadge"

export const WorkspacesRow: FC<{
workspace: Workspace
Expand Down Expand Up @@ -65,6 +66,10 @@ export const WorkspacesRow: FC<{
<WorkspaceStatusBadge workspace={workspace} />
</TableCell>

<TableCell>
<WorkspaceHealthBadge workspace={workspace} />
</TableCell>

<TableCell>
<div className={styles.arrowCell}>
<KeyboardArrowRight className={styles.arrowRight} />
Expand Down
2 changes: 2 additions & 0 deletions site/src/components/WorkspacesTable/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Language = {
template: "Template",
lastUsed: "Last Used",
status: "Status",
health: "Health",
}

export interface WorkspacesTableProps {
Expand All @@ -37,6 +38,7 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
<TableCell width="25%">{Language.template}</TableCell>
<TableCell width="20%">{Language.lastUsed}</TableCell>
<TableCell width="15%">{Language.status}</TableCell>
<TableCell width="15%">{Language.health}</TableCell>
<TableCell width="1%" />
</TableRow>
</TableHead>
Expand Down