-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[UI v2] feat: Adds FlowRunStateBadge component #17139
Closed
Closed
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions
18
ui-v2/src/components/ui/flow-run-state-badge/flow-run-state-badge.stories.tsx
This file contains 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,18 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { FlowRunStateBadge } from "./flow-run-state-badge"; | ||
import { FLOW_RUN_STATES } from "./flow-run-states"; | ||
|
||
export const story: StoryObj = { name: "FlowRunStateBadge" }; | ||
|
||
export default { | ||
title: "UI/FlowRunStateBadge", | ||
render: () => { | ||
return ( | ||
<div className="flex flex-col gap-4 items-start"> | ||
{FLOW_RUN_STATES.map((state) => ( | ||
<FlowRunStateBadge key={state} state={state} /> | ||
))} | ||
</div> | ||
); | ||
}, | ||
} satisfies Meta; |
62 changes: 62 additions & 0 deletions
62
ui-v2/src/components/ui/flow-run-state-badge/flow-run-state-badge.tsx
This file contains 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,62 @@ | ||
import { Badge } from "@/components/ui/badge"; | ||
import { ICONS as COMPONENT_ICONS } from "@/components/ui/icons"; | ||
import { cva } from "class-variance-authority"; | ||
import type { FlowRunStates } from "./flow-run-states"; | ||
|
||
const ICONS = { | ||
Scheduled: COMPONENT_ICONS.Clock, | ||
Late: COMPONENT_ICONS.Clock, | ||
Resuming: COMPONENT_ICONS.Clock, | ||
AwaitingRetry: COMPONENT_ICONS.Clock, | ||
AwaitingConcurrencySlot: COMPONENT_ICONS.Clock, | ||
Pending: COMPONENT_ICONS.Clock, | ||
Paused: COMPONENT_ICONS.Pause, | ||
Suspended: COMPONENT_ICONS.Pause, | ||
Running: COMPONENT_ICONS.Play, | ||
Retrying: COMPONENT_ICONS.Play, | ||
Completed: COMPONENT_ICONS.Check, | ||
Cached: COMPONENT_ICONS.Check, | ||
Cancelled: COMPONENT_ICONS.Ban, | ||
Cancelling: COMPONENT_ICONS.Ban, | ||
Crashed: COMPONENT_ICONS.ServerCrash, | ||
Failed: COMPONENT_ICONS.X, | ||
TimedOut: COMPONENT_ICONS.X, | ||
} as const satisfies Record<FlowRunStates, React.ElementType>; | ||
|
||
const flowRunStateVariants = cva("gap-1", { | ||
variants: { | ||
state: { | ||
Scheduled: "bg-yellow-100 text-yellow-700 hover:bg-yellow-100", | ||
Late: "bg-yellow-100 text-yellow-700 hover:bg-yellow-100", | ||
Resuming: "bg-yellow-100 text-yellow-700 hover:bg-yellow-100", | ||
AwaitingRetry: "bg-yellow-100 text-yellow-700 hover:bg-yellow-100", | ||
AwaitingConcurrencySlot: | ||
"bg-yellow-100 text-yellow-700 hover:bg-yellow-100", | ||
Pending: "bg-gray-300 text-gray-800 hover:bg-gray-300", | ||
Paused: "bg-gray-300 text-gray-800 hover:bg-gray-300", | ||
Suspended: "bg-gray-300 text-gray-800 hover:bg-gray-300", | ||
Running: "bg-blue-100 text-blue-700 hover:bg-blue-100", | ||
Retrying: "bg-blue-100 text-blue-700 hover:bg-blue-100", | ||
Completed: "bg-green-50 text-green-600 hover:bg-green-50", | ||
Cancelled: "bg-gray-300 text-gray-800 hover:bg-gray-300", | ||
Cancelling: "bg-gray-300 text-gray-800 hover:bg-gray-300", | ||
Cached: "bg-green-50 text-green-600 hover:bg-green-50", | ||
Crashed: "bg-orange-50 text-orange-600 hover:bg-orange-50", | ||
Failed: "bg-red-50 text-red-600 hover:bg-red-50", | ||
TimedOut: "bg-red-50 text-red-600 hover:bg-red-50", | ||
} satisfies Record<FlowRunStates, string>, | ||
}, | ||
}); | ||
|
||
type FlowRunStateProps = { | ||
state: FlowRunStates; | ||
}; | ||
export const FlowRunStateBadge = ({ state }: FlowRunStateProps) => { | ||
const Icon = ICONS[state]; | ||
return ( | ||
<Badge className={flowRunStateVariants({ state })}> | ||
<Icon size={16} /> | ||
{state} | ||
</Badge> | ||
); | ||
}; | ||
20 changes: 20 additions & 0 deletions
20
ui-v2/src/components/ui/flow-run-state-badge/flow-run-states.ts
This file contains 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,20 @@ | ||
export const FLOW_RUN_STATES = [ | ||
"Scheduled", | ||
"Late", | ||
"Resuming", | ||
"AwaitingRetry", | ||
"AwaitingConcurrencySlot", | ||
"Pending", | ||
"Paused", | ||
"Suspended", | ||
"Running", | ||
"Retrying", | ||
"Completed", | ||
"Cached", | ||
"Cancelled", | ||
"Cancelling", | ||
"Crashed", | ||
"Failed", | ||
"TimedOut", | ||
] as const; | ||
export type FlowRunStates = (typeof FLOW_RUN_STATES)[number]; |
This file contains 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,2 @@ | ||
export { FLOW_RUN_STATES, type FlowRunStates } from "./flow-run-states"; | ||
export { FlowRunStateBadge } from "./flow-run-state-badge"; |
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.
We'll need to account for user defined state names. So its helpful to optionally accept a state type along with the state name. That way if we have a full state object (
{ state_type: string, state_name: string }
) we can determine the color and icon based on the state type even if we don't recognize the state name.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.
The state types are defined here. But you'll see here that a flow run's state_name is just a
string
. There's also the state object here where you can see the full state object (which we don't use very often).When displaying states from a run both the state type and state name can be used (because they're both present on the flow run and task run models). However when creating filters by state we generally just use the state name as the value we filter off of. For example the FlowRunFilterState model can have both type and name filters, but we would generally use a name because then we can filter for "Late" (a state name of the state type "SCHEDULED").