-
Notifications
You must be signed in to change notification settings - Fork 113
π€ feat: add workflow visibility surfaces #3495
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
Open
ThomasK33
wants to merge
5
commits into
main
Choose a base branch
from
workflows-azg3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ffa59c2
π€ feat: add workflow visibility surfaces
ThomasK33 6f67de8
π€ fix: harden workflow visibility state
ThomasK33 ebe60db
π€ test: stabilize workflow indicator popover
ThomasK33 8400b63
π€ fix: stabilize workflow readiness checks
ThomasK33 2395a8c
π€ fix: preserve sidebar feature flags
ThomasK33 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
127 changes: 127 additions & 0 deletions
127
src/browser/components/WorkflowIndicator/WorkflowIndicator.test.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,127 @@ | ||
| import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | ||
| import { cleanup, fireEvent, render } from "@testing-library/react"; | ||
| import { installDom } from "../../../../tests/ui/dom"; | ||
|
|
||
| import type { WorkflowDefinitionDescriptor, WorkflowRunRecord } from "@/common/types/workflow"; | ||
| import { TooltipProvider } from "@/browser/components/Tooltip/Tooltip"; | ||
| import { WorkflowIndicatorPopoverContent, WorkflowIndicatorView } from "./WorkflowIndicator"; | ||
| import { | ||
| groupWorkflowDefinitionsByScope, | ||
| summarizeWorkflowRuns, | ||
| } from "@/browser/features/Workflows/workflowStatusPresentation"; | ||
|
|
||
| function definition( | ||
| name: string, | ||
| scope: WorkflowDefinitionDescriptor["scope"] | ||
| ): WorkflowDefinitionDescriptor { | ||
| return { name, scope, description: `${name} workflow`, executable: true }; | ||
| } | ||
|
|
||
| function run(overrides: Partial<WorkflowRunRecord>): WorkflowRunRecord { | ||
| return { | ||
| id: "wfr_test", | ||
| workspaceId: "workspace-1", | ||
| definition: definition("demo", "project"), | ||
| definitionSource: "/repo/.mux/workflows/demo.js", | ||
| definitionHash: "hash", | ||
| args: {}, | ||
| status: "running", | ||
| createdAt: "2026-01-01T00:00:00.000Z", | ||
| updatedAt: "2026-01-01T00:00:00.000Z", | ||
| events: [], | ||
| steps: [], | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe("WorkflowIndicatorView", () => { | ||
| let cleanupDom: (() => void) | null = null; | ||
|
|
||
| beforeEach(() => { | ||
| cleanupDom = installDom(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| cleanup(); | ||
| cleanupDom?.(); | ||
| cleanupDom = null; | ||
| }); | ||
|
|
||
| test("prioritizes problem runs over active counts", () => { | ||
| const definitions = [definition("project-flow", "project")]; | ||
| const runs = [ | ||
| run({ id: "wfr_failed", status: "failed", definition: definitions[0] }), | ||
| run({ id: "wfr_running", status: "running" }), | ||
| ]; | ||
| const view = render( | ||
| <TooltipProvider> | ||
| <WorkflowIndicatorView | ||
| workspaceId="workspace-1" | ||
| snapshot={{ | ||
| definitions, | ||
| definitionGroups: groupWorkflowDefinitionsByScope(definitions), | ||
| runs, | ||
| currentRuns: runs, | ||
| historyRuns: [], | ||
| summary: summarizeWorkflowRuns(runs), | ||
| isLoading: false, | ||
| error: null, | ||
| }} | ||
| /> | ||
| </TooltipProvider> | ||
| ); | ||
|
|
||
| const button = view.getByLabelText("1 workflow needs attention"); | ||
| expect(button.textContent).toContain("1"); | ||
| }); | ||
|
|
||
| test("uses plural grammar for multiple problem runs", () => { | ||
| const failed = run({ id: "wfr_failed", status: "failed" }); | ||
| const interrupted = run({ id: "wfr_interrupted", status: "interrupted" }); | ||
| const runs = [failed, interrupted]; | ||
| const view = render( | ||
| <TooltipProvider> | ||
| <WorkflowIndicatorView | ||
| workspaceId="workspace-1" | ||
| snapshot={{ | ||
| definitions: [], | ||
| definitionGroups: groupWorkflowDefinitionsByScope([]), | ||
| runs, | ||
| currentRuns: runs, | ||
| historyRuns: [], | ||
| summary: summarizeWorkflowRuns(runs), | ||
| isLoading: false, | ||
| error: null, | ||
| }} | ||
| /> | ||
| </TooltipProvider> | ||
| ); | ||
|
|
||
| expect(view.getByLabelText("2 workflows need attention")).toBeTruthy(); | ||
| }); | ||
|
|
||
| test("opens the workflows tab from the popover action", () => { | ||
| let opened = false; | ||
| const view = render( | ||
| <WorkflowIndicatorPopoverContent | ||
| onOpenWorkflowsTab={() => { | ||
| opened = true; | ||
| }} | ||
| snapshot={{ | ||
| definitions: [], | ||
| definitionGroups: groupWorkflowDefinitionsByScope([]), | ||
| runs: [], | ||
| currentRuns: [], | ||
| historyRuns: [], | ||
| summary: summarizeWorkflowRuns([]), | ||
| isLoading: false, | ||
| error: null, | ||
| }} | ||
| /> | ||
| ); | ||
|
|
||
| fireEvent.click(view.getByText("Open tab")); | ||
|
|
||
| expect(opened).toBe(true); | ||
| }); | ||
| }); |
151 changes: 151 additions & 0 deletions
151
src/browser/components/WorkflowIndicator/WorkflowIndicator.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,151 @@ | ||
| import React from "react"; | ||
| import { Workflow } from "lucide-react"; | ||
|
|
||
| import { Popover, PopoverContent, PopoverTrigger } from "@/browser/components/Popover/Popover"; | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from "@/browser/components/Tooltip/Tooltip"; | ||
| import { CUSTOM_EVENTS, createCustomEvent } from "@/common/constants/events"; | ||
| import { cn } from "@/common/lib/utils"; | ||
|
|
||
| import { | ||
| useWorkflowWorkspaceSnapshot, | ||
| type WorkflowWorkspaceSnapshot, | ||
| } from "@/browser/features/Workflows/WorkflowStore"; | ||
| import { getWorkflowStatusPresentation } from "@/browser/features/Workflows/workflowStatusPresentation"; | ||
|
|
||
| interface WorkflowIndicatorProps { | ||
| workspaceId: string; | ||
| } | ||
|
|
||
| interface WorkflowIndicatorViewProps { | ||
| workspaceId: string; | ||
| snapshot: WorkflowWorkspaceSnapshot; | ||
| onOpenWorkflowsTab?: () => void; | ||
| } | ||
|
|
||
| export function WorkflowIndicator(props: WorkflowIndicatorProps) { | ||
| const snapshot = useWorkflowWorkspaceSnapshot(props.workspaceId); | ||
| return <WorkflowIndicatorView workspaceId={props.workspaceId} snapshot={snapshot} />; | ||
| } | ||
|
|
||
| export function WorkflowIndicatorView(props: WorkflowIndicatorViewProps) { | ||
| const [open, setOpen] = React.useState(false); | ||
| const problemCount = props.snapshot.summary.problemCount; | ||
| const activeCount = props.snapshot.summary.activeCount; | ||
| const hasProblems = problemCount > 0; | ||
| const hasActive = activeCount > 0; | ||
| const badgeCount = hasProblems ? problemCount : activeCount; | ||
| const label = hasProblems | ||
| ? `${problemCount} workflow${problemCount === 1 ? "" : "s"} ${problemCount === 1 ? "needs" : "need"} attention` | ||
| : hasActive | ||
| ? `${activeCount} active workflow${activeCount === 1 ? "" : "s"}` | ||
| : "Workflows"; | ||
|
|
||
| const openWorkflowsTab = () => { | ||
| setOpen(false); | ||
| if (props.onOpenWorkflowsTab) { | ||
| props.onOpenWorkflowsTab(); | ||
| return; | ||
| } | ||
| window.dispatchEvent( | ||
| createCustomEvent(CUSTOM_EVENTS.OPEN_WORKFLOWS_TAB, { workspaceId: props.workspaceId }) | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <Popover open={open} onOpenChange={setOpen}> | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <PopoverTrigger asChild> | ||
| <button | ||
| type="button" | ||
| className={cn( | ||
| "relative flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted hover:bg-sidebar-hover hover:text-foreground max-[520px]:hidden", | ||
| hasProblems && "text-error", | ||
| !hasProblems && hasActive && "text-success" | ||
| )} | ||
| aria-label={label} | ||
| > | ||
| <Workflow className="h-3.5 w-3.5" /> | ||
| {(hasProblems || hasActive) && ( | ||
| <span className="bg-background counter-nums absolute -top-1 -right-1 min-w-3 rounded-full px-0.5 text-[9px] leading-3"> | ||
| {badgeCount} | ||
| </span> | ||
| )} | ||
| </button> | ||
| </PopoverTrigger> | ||
| </TooltipTrigger> | ||
| <TooltipContent side="bottom" align="end"> | ||
| {label} | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| <PopoverContent | ||
| side="bottom" | ||
| align="end" | ||
| className="bg-modal-bg border-separator-light w-72 overflow-visible rounded px-3 py-2 text-xs font-normal shadow-[0_2px_8px_rgba(0,0,0,0.4)]" | ||
| > | ||
| <WorkflowIndicatorPopoverContent | ||
| snapshot={props.snapshot} | ||
| onOpenWorkflowsTab={openWorkflowsTab} | ||
| /> | ||
| </PopoverContent> | ||
| </Popover> | ||
| ); | ||
| } | ||
|
|
||
| export function WorkflowIndicatorPopoverContent(props: { | ||
| snapshot: WorkflowWorkspaceSnapshot; | ||
| onOpenWorkflowsTab: () => void; | ||
| }) { | ||
| return ( | ||
| <div className="flex flex-col gap-3"> | ||
| <div className="flex items-center justify-between gap-2"> | ||
| <div className="text-foreground font-medium">Workflows</div> | ||
| <button | ||
| type="button" | ||
| className="text-accent hover:underline" | ||
| onClick={props.onOpenWorkflowsTab} | ||
| > | ||
| Open tab | ||
| </button> | ||
| </div> | ||
| <IndicatorSection title="Active and attention"> | ||
| {props.snapshot.currentRuns.length === 0 ? ( | ||
| <p className="text-muted">No active workflows</p> | ||
| ) : ( | ||
| props.snapshot.currentRuns.slice(0, 5).map((run) => { | ||
| const presentation = getWorkflowStatusPresentation(run.status); | ||
| return ( | ||
| <div key={run.id} className="flex items-center justify-between gap-2"> | ||
| <span className="truncate">{run.definition.name}</span> | ||
| <span className="text-muted shrink-0">{presentation.label}</span> | ||
| </div> | ||
| ); | ||
| }) | ||
| )} | ||
| </IndicatorSection> | ||
| <IndicatorSection title="Available definitions"> | ||
| {props.snapshot.definitions.length === 0 ? ( | ||
| <p className="text-muted">No definitions found</p> | ||
| ) : ( | ||
| <p className="text-muted"> | ||
| {props.snapshot.definitionGroups.project.length} project Β·{" "} | ||
| {props.snapshot.definitionGroups.global.length} global Β·{" "} | ||
| {props.snapshot.definitionGroups["built-in"].length} built-in Β·{" "} | ||
| {props.snapshot.definitionGroups.scratch.length} scratch | ||
| </p> | ||
| )} | ||
| </IndicatorSection> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function IndicatorSection(props: { title: string; children: React.ReactNode }) { | ||
| return ( | ||
| <section className="flex flex-col gap-1"> | ||
| <h3 className="text-muted text-[11px] font-semibold tracking-wide uppercase"> | ||
| {props.title} | ||
| </h3> | ||
| {props.children} | ||
| </section> | ||
| ); | ||
| } |
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.
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.