-
Notifications
You must be signed in to change notification settings - Fork 17
chore: workflow run ui #894
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
3 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
Some comments aren't visible on the classic Files Changed page.
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
230 changes: 230 additions & 0 deletions
230
apps/web/app/routes/ws/workflows/page.$workflowId.runs.$runId.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,230 @@ | ||
| import type { RouterOutputs } from "@ctrlplane/trpc"; | ||
| import { Fragment } from "react"; | ||
| import { formatDistanceToNowStrict } from "date-fns"; | ||
| import { ExternalLink } from "lucide-react"; | ||
| import { Link, useParams } from "react-router"; | ||
|
|
||
| import { trpc } from "~/api/trpc"; | ||
| import { | ||
| Breadcrumb, | ||
| BreadcrumbItem, | ||
| BreadcrumbLink, | ||
| BreadcrumbList, | ||
| BreadcrumbPage, | ||
| BreadcrumbSeparator, | ||
| } from "~/components/ui/breadcrumb"; | ||
| import { buttonVariants } from "~/components/ui/button"; | ||
| import { Separator } from "~/components/ui/separator"; | ||
| import { SidebarTrigger } from "~/components/ui/sidebar"; | ||
| import { Spinner } from "~/components/ui/spinner"; | ||
| import { | ||
| Table, | ||
| TableBody, | ||
| TableCell, | ||
| TableHead, | ||
| TableHeader, | ||
| TableRow, | ||
| } from "~/components/ui/table"; | ||
| import { useWorkspace } from "~/components/WorkspaceProvider"; | ||
| import { cn } from "~/lib/utils"; | ||
| import { JobStatusBadge } from "../_components/JobStatusBadge"; | ||
|
|
||
| type WorkflowRunJob = RouterOutputs["workflows"]["runs"]["get"]["jobs"][number]; | ||
|
|
||
| function timeAgo(date: Date | string | null) { | ||
| if (date == null) return "-"; | ||
| const d = typeof date === "string" ? new Date(date) : date; | ||
| return formatDistanceToNowStrict(d, { addSuffix: true }); | ||
| } | ||
|
|
||
| function RunPageHeader({ | ||
| workflowName, | ||
| runId, | ||
| }: { | ||
| workflowName: string; | ||
| runId: string; | ||
| }) { | ||
| const { workspace } = useWorkspace(); | ||
| const { workflowId } = useParams<{ workflowId: string }>(); | ||
| return ( | ||
| <header className="flex h-16 shrink-0 items-center gap-2 border-b"> | ||
| <div className="flex w-full items-center gap-2 px-4"> | ||
| <SidebarTrigger className="-ml-1" /> | ||
| <Separator | ||
| orientation="vertical" | ||
| className="mr-2 data-[orientation=vertical]:h-4" | ||
| /> | ||
| <Breadcrumb> | ||
| <BreadcrumbList> | ||
| <BreadcrumbItem> | ||
| <BreadcrumbLink asChild> | ||
| <Link to={`/${workspace.slug}/workflows`}>Workflows</Link> | ||
| </BreadcrumbLink> | ||
| </BreadcrumbItem> | ||
| <BreadcrumbSeparator /> | ||
| <BreadcrumbItem> | ||
| <BreadcrumbLink asChild> | ||
| <Link to={`/${workspace.slug}/workflows/${workflowId}`}> | ||
| {workflowName} | ||
| </Link> | ||
| </BreadcrumbLink> | ||
| </BreadcrumbItem> | ||
| <BreadcrumbSeparator /> | ||
| <BreadcrumbItem> | ||
| <BreadcrumbPage>{runId.slice(0, 8)}</BreadcrumbPage> | ||
| </BreadcrumbItem> | ||
| </BreadcrumbList> | ||
| </Breadcrumb> | ||
| </div> | ||
| </header> | ||
| ); | ||
| } | ||
|
|
||
| function InputsSection({ inputs }: { inputs: unknown }) { | ||
| const entries = Object.entries((inputs as Record<string, unknown>) ?? {}); | ||
| if (entries.length === 0) | ||
| return <p className="text-sm text-muted-foreground">No inputs.</p>; | ||
|
|
||
| return ( | ||
| <div className="grid grid-cols-[120px_1fr] gap-y-1 text-sm"> | ||
| {entries.map(([key, value]) => ( | ||
| <Fragment key={key}> | ||
| <span className="text-muted-foreground">{key}</span> | ||
| <span className="font-mono text-xs">{JSON.stringify(value)}</span> | ||
| </Fragment> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function extractLinks(metadata: Record<string, string>) { | ||
| try { | ||
| const linksMetadata = metadata["ctrlplane/links"]; | ||
| if (linksMetadata == null) return {}; | ||
| return JSON.parse(linksMetadata) as Record<string, string>; | ||
| } catch { | ||
| return {}; | ||
| } | ||
| } | ||
|
|
||
| function LinksCell({ metadata }: { metadata: Record<string, string> }) { | ||
| const links = extractLinks(metadata); | ||
|
|
||
| return ( | ||
| <TableCell> | ||
| <div className="flex gap-1"> | ||
| {Object.entries(links).map(([label, url]) => ( | ||
| <a | ||
| key={label} | ||
| href={url} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className={cn( | ||
| buttonVariants({ variant: "secondary", size: "sm" }), | ||
| "max-w-30 flex h-6 items-center gap-1.5 px-2 py-0", | ||
| )} | ||
| > | ||
| <span className="truncate">{label}</span> | ||
| <ExternalLink className="size-3 shrink-0" /> | ||
| </a> | ||
| ))} | ||
| </div> | ||
| </TableCell> | ||
| ); | ||
| } | ||
|
|
||
| function JobRow({ job }: { job: WorkflowRunJob }) { | ||
| return ( | ||
| <TableRow> | ||
| <TableCell className="font-mono text-xs text-muted-foreground"> | ||
| {job.id.slice(0, 8)} | ||
| </TableCell> | ||
| <TableCell>{job.jobAgentName ?? "-"}</TableCell> | ||
| <TableCell className="text-muted-foreground"> | ||
| {job.jobAgentType ?? "-"} | ||
| </TableCell> | ||
| <TableCell> | ||
| <JobStatusBadge status={job.status} message={job.message} /> | ||
| </TableCell> | ||
| <LinksCell metadata={job.metadata} /> | ||
| <TableCell className="text-muted-foreground"> | ||
| {timeAgo(job.createdAt)} | ||
| </TableCell> | ||
| </TableRow> | ||
| ); | ||
| } | ||
|
|
||
| export default function WorkflowRunDetailPage() { | ||
| const { workspace } = useWorkspace(); | ||
| const { workflowId, runId } = useParams<{ | ||
| workflowId: string; | ||
| runId: string; | ||
| }>(); | ||
|
|
||
| const { data: workflow } = trpc.workflows.get.useQuery( | ||
| { workspaceId: workspace.id, workflowId: workflowId! }, | ||
| { enabled: workflowId != null }, | ||
| ); | ||
|
|
||
| const { data: run, isLoading } = trpc.workflows.runs.get.useQuery( | ||
| { workflowRunId: runId!, workspaceId: workspace.id }, | ||
| { enabled: runId != null }, | ||
| ); | ||
|
|
||
| const workflowName = workflow?.name ?? "..."; | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <> | ||
| <RunPageHeader workflowName={workflowName} runId={runId ?? ""} /> | ||
| <div className="flex h-64 items-center justify-center"> | ||
| <Spinner className="size-6" /> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| if (run == null) throw new Error("Workflow run not found"); | ||
|
|
||
| return ( | ||
| <> | ||
| <RunPageHeader workflowName={workflowName} runId={run.id} /> | ||
|
|
||
| <main className="flex-1 space-y-8 overflow-auto p-6"> | ||
| <section className="space-y-2"> | ||
| <h2 className="text-lg font-semibold">Inputs</h2> | ||
| <InputsSection inputs={run.inputs} /> | ||
| </section> | ||
|
|
||
| <section className="space-y-2"> | ||
| <h2 className="text-lg font-semibold">Jobs</h2> | ||
| {run.jobs.length === 0 ? ( | ||
| <p className="text-sm text-muted-foreground"> | ||
| No jobs were dispatched for this run. | ||
| </p> | ||
| ) : ( | ||
| <div className="rounded-md border"> | ||
| <Table> | ||
| <TableHeader> | ||
| <TableRow> | ||
| <TableHead>Job</TableHead> | ||
| <TableHead>Agent</TableHead> | ||
| <TableHead>Type</TableHead> | ||
| <TableHead>Status</TableHead> | ||
| <TableHead>Links</TableHead> | ||
| <TableHead>Created</TableHead> | ||
| </TableRow> | ||
| </TableHeader> | ||
| <TableBody> | ||
| {run.jobs.map((job) => ( | ||
| <JobRow key={job.id} job={job} /> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| </div> | ||
| )} | ||
| </section> | ||
| </main> | ||
| </> | ||
| ); | ||
| } |
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.
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.
Make row navigation keyboard-accessible.
The row is clickable with a mouse, but it is not focusable/operable via keyboard. Please add keyboard semantics (or render a real
<Link>target in-cell).♿ Suggested fix
<TableRow className="cursor-pointer" + role="link" + tabIndex={0} onClick={() => navigate( `/${workspace.slug}/workflows/${workflowId}/runs/${run.id}`, ) } + onKeyDown={(e) => { + if (e.key === "Enter" || e.key === " ") { + e.preventDefault(); + navigate(`/${workspace.slug}/workflows/${workflowId}/runs/${run.id}`); + } + }} >📝 Committable suggestion
🤖 Prompt for AI Agents