-
Notifications
You must be signed in to change notification settings - Fork 894
refactor: replace badge by status indicator #17811
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
refactor: replace badge by status indicator
- Loading branch information
commit 4ba56bbf37b1efb01bb507099edb90bb2590f16f
There are no files selected for viewing
93 changes: 0 additions & 93 deletions
93
site/src/modules/workspaces/WorkspaceStatusBadge/WorkspaceStatusBadge.stories.tsx
This file was deleted.
Oops, something went wrong.
90 changes: 0 additions & 90 deletions
90
site/src/modules/workspaces/WorkspaceStatusBadge/WorkspaceStatusBadge.tsx
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
site/src/modules/workspaces/WorkspaceStatusIndicator/WorkspaceStatusIndicator.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,82 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import type { Workspace, WorkspaceStatus } from "api/typesGenerated"; | ||
import { MockWorkspace } from "testHelpers/entities"; | ||
import { WorkspaceStatusIndicator } from "./WorkspaceStatusIndicator"; | ||
|
||
const meta: Meta<typeof WorkspaceStatusIndicator> = { | ||
title: "modules/workspaces/WorkspaceStatusIndicator", | ||
component: WorkspaceStatusIndicator, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof WorkspaceStatusIndicator>; | ||
|
||
const createWorkspaceWithStatus = (status: WorkspaceStatus): Workspace => { | ||
return { | ||
...MockWorkspace, | ||
latest_build: { | ||
...MockWorkspace.latest_build, | ||
status, | ||
}, | ||
} as Workspace; | ||
}; | ||
|
||
export const Running: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("running"), | ||
}, | ||
}; | ||
|
||
export const Stopped: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("stopped"), | ||
}, | ||
}; | ||
|
||
export const Starting: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("starting"), | ||
}, | ||
}; | ||
|
||
export const Stopping: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("stopping"), | ||
}, | ||
}; | ||
|
||
export const Failed: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("failed"), | ||
}, | ||
}; | ||
|
||
export const Canceling: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("canceling"), | ||
}, | ||
}; | ||
|
||
export const Canceled: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("canceled"), | ||
}, | ||
}; | ||
|
||
export const Deleting: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("deleting"), | ||
}, | ||
}; | ||
|
||
export const Deleted: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("deleted"), | ||
}, | ||
}; | ||
|
||
export const Pending: Story = { | ||
args: { | ||
workspace: createWorkspaceWithStatus("pending"), | ||
}, | ||
}; |
47 changes: 47 additions & 0 deletions
47
site/src/modules/workspaces/WorkspaceStatusIndicator/WorkspaceStatusIndicator.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,47 @@ | ||
import type { Workspace } from "api/typesGenerated"; | ||
import { | ||
StatusIndicator, | ||
StatusIndicatorDot, | ||
type StatusIndicatorProps, | ||
} from "components/StatusIndicator/StatusIndicator"; | ||
import type { FC } from "react"; | ||
import type React from "react"; | ||
import { | ||
type DisplayWorkspaceStatusType, | ||
getDisplayWorkspaceStatus, | ||
} from "utils/workspace"; | ||
|
||
const variantByStatusType: Record< | ||
DisplayWorkspaceStatusType, | ||
StatusIndicatorProps["variant"] | ||
> = { | ||
active: "pending", | ||
inactive: "inactive", | ||
success: "success", | ||
error: "failed", | ||
danger: "warning", | ||
warning: "warning", | ||
}; | ||
|
||
type WorkspaceStatusIndicatorProps = { | ||
workspace: Workspace; | ||
children?: React.ReactNode; | ||
}; | ||
|
||
export const WorkspaceStatusIndicator: FC<WorkspaceStatusIndicatorProps> = ({ | ||
workspace, | ||
children, | ||
}) => { | ||
const { text, type } = getDisplayWorkspaceStatus( | ||
workspace.latest_build.status, | ||
workspace.latest_build.job, | ||
); | ||
|
||
return ( | ||
<StatusIndicator variant={variantByStatusType[type]}> | ||
<StatusIndicatorDot /> | ||
{text} | ||
{children} | ||
</StatusIndicator> | ||
); | ||
}; |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious: why is it better than
css
property?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we are moving away from MUI and emotion to use shadcn and TailwindCSS. So we want to be consistent and only use the new stack.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, TIL!