Skip to content

Commit 5827ebc

Browse files
Change WorkflowStats component to use new workflow run counts
1 parent 8b61a72 commit 5827ebc

3 files changed

Lines changed: 35 additions & 31 deletions

File tree

packages/dashboard/src/components/workflow-stats.tsx

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,19 @@ import {
55
ClockIcon,
66
HourglassIcon,
77
ProhibitIcon,
8-
PulseIcon,
98
XCircleIcon,
109
} from "@phosphor-icons/react";
11-
import type { WorkflowRun } from "openworkflow/internal";
10+
import type { WorkflowRunCounts } from "openworkflow/internal";
1211

1312
export interface WorkflowStatsProps {
14-
runs: WorkflowRun[];
13+
workflowRunCounts: WorkflowRunCounts;
1514
}
1615

17-
export function WorkflowStats({ runs }: WorkflowStatsProps) {
18-
// this computes stats from real run data as a placeholder until the backend
19-
// is updated to provide aggregated stats
20-
const completed = runs.filter(
21-
(r) => r.status === "completed" || r.status === "succeeded",
22-
).length;
23-
const running = runs.filter((r) => r.status === "running").length;
24-
const failed = runs.filter((r) => r.status === "failed").length;
25-
const pending = runs.filter((r) => r.status === "pending").length;
26-
const sleeping = runs.filter((r) => r.status === "sleeping").length;
27-
const canceled = runs.filter((r) => r.status === "canceled").length;
16+
export function WorkflowStats({ workflowRunCounts }: WorkflowStatsProps) {
17+
const { pending, running, sleeping, completed, failed, canceled } =
18+
workflowRunCounts;
2819

2920
const stats = [
30-
{
31-
label: "Total Runs",
32-
value: runs.length.toLocaleString(),
33-
icon: PulseIcon,
34-
},
3521
{ label: "Pending", value: pending.toLocaleString(), icon: ClockIcon },
3622
{
3723
label: "Running",
@@ -61,17 +47,13 @@ export function WorkflowStats({ runs }: WorkflowStatsProps) {
6147
];
6248

6349
return (
64-
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:gap-4 lg:grid-cols-4 xl:grid-cols-7">
65-
{stats.map((stat, index) => {
50+
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:gap-4 xl:grid-cols-6">
51+
{stats.map((stat) => {
6652
const Icon = stat.icon;
6753
return (
6854
<Card
6955
key={stat.label}
70-
className={`bg-card border-border hover:border-primary/50 p-3 transition-colors sm:p-5 ${
71-
index === 0
72-
? "col-span-2 sm:col-span-3 lg:col-span-2 xl:col-span-1"
73-
: ""
74-
}`}
56+
className="bg-card border-border hover:border-primary/50 p-3 transition-colors sm:p-5"
7557
>
7658
<div className="flex items-start justify-between">
7759
<div className="space-y-1">

packages/dashboard/src/lib/api.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
PaginatedResponse,
55
PaginationOptions,
66
StepAttempt,
7+
WorkflowRunCounts,
78
WorkflowRun,
89
} from "openworkflow/internal";
910
import * as z from "zod";
@@ -56,6 +57,16 @@ export const listWorkflowRunsServerFn = createServerFn({ method: "GET" })
5657
return result;
5758
});
5859

60+
/**
61+
* Read workflow run counts from the backend.
62+
*/
63+
export const getWorkflowRunCountsServerFn = createServerFn({
64+
method: "GET",
65+
}).handler(async (): Promise<WorkflowRunCounts> => {
66+
const backend = await getBackend();
67+
return await backend.countWorkflowRuns();
68+
});
69+
5970
/**
6071
* Get a single workflow run by ID.
6172
*/

packages/dashboard/src/routes/index.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
DialogTitle,
1111
} from "@/components/ui/dialog";
1212
import { WorkflowStats } from "@/components/workflow-stats";
13-
import { listWorkflowRunsServerFn } from "@/lib/api";
13+
import {
14+
getWorkflowRunCountsServerFn,
15+
listWorkflowRunsServerFn,
16+
} from "@/lib/api";
1417
import { usePolling } from "@/lib/use-polling";
1518
import { PlusIcon } from "@phosphor-icons/react";
1619
import { createFileRoute } from "@tanstack/react-router";
@@ -19,13 +22,21 @@ import { useState } from "react";
1922
export const Route = createFileRoute("/")({
2023
component: HomePage,
2124
loader: async () => {
22-
const result = await listWorkflowRunsServerFn({ data: { limit: 100 } });
23-
return result;
25+
const [runsResponse, workflowRunCounts] = await Promise.all([
26+
listWorkflowRunsServerFn({ data: { limit: 100 } }),
27+
getWorkflowRunCountsServerFn(),
28+
]);
29+
30+
return {
31+
runsResponse,
32+
workflowRunCounts,
33+
};
2434
},
2535
});
2636

2737
function HomePage() {
28-
const { data: runs } = Route.useLoaderData();
38+
const { runsResponse, workflowRunCounts } = Route.useLoaderData();
39+
const { data: runs } = runsResponse;
2940
const [isCreateRunOpen, setIsCreateRunOpen] = useState(false);
3041
usePolling();
3142

@@ -51,7 +62,7 @@ function HomePage() {
5162
</Button>
5263
</div>
5364

54-
<WorkflowStats runs={runs} />
65+
<WorkflowStats workflowRunCounts={workflowRunCounts} />
5566
<RunList runs={runs} showHeader={false} />
5667
</div>
5768

0 commit comments

Comments
 (0)