Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions apps/dashboard/src/components/run-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export function RunList({
</div>
)}
<Card className="bg-card border-border p-8 text-center">
<p className="text-muted-foreground">
No workflow runs have been created yet.
</p>
<p className="text-muted-foreground">No workflow runs found.</p>
</Card>
</div>
);
Expand Down
12 changes: 8 additions & 4 deletions apps/dashboard/src/components/workflow-stats.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Card } from "@/components/ui/card";
import {
getRunStatusConfig,
getStatusStatCardClass,
getStatusStatIconClass,
} from "@/lib/status";
import { cn } from "@/lib/utils";
import { Link, useSearch } from "@tanstack/react-router";
import type { WorkflowRunCounts } from "openworkflow/internal";

export interface WorkflowStatsProps {
Expand All @@ -20,6 +20,7 @@ const STATS_STATUS_ORDER = [
] as const satisfies readonly (keyof WorkflowRunCounts)[];

export function WorkflowStats({ workflowRunCounts }: WorkflowStatsProps) {
const { limit, workflowName, status: active } = useSearch({ from: "/" });
const stats = STATS_STATUS_ORDER.map((status) => {
const config = getRunStatusConfig(status);

Expand All @@ -37,11 +38,14 @@ export function WorkflowStats({ workflowRunCounts }: WorkflowStatsProps) {
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:gap-4 xl:grid-cols-5">
{stats.map((stat) => {
const Icon = stat.icon;
const status = active === stat.status ? undefined : stat.status;
return (
<Card
<Link
key={stat.label}
to="/"
search={{ limit, workflowName, status }}
className={cn(
"bg-card p-3 transition-colors sm:p-5",
"p-3 text-xs ring-1 transition-colors data-[status=active]:ring-2 sm:p-5",
stat.cardClass,
)}
>
Expand All @@ -56,7 +60,7 @@ export function WorkflowStats({ workflowRunCounts }: WorkflowStatsProps) {
</div>
<Icon className={cn("size-4 sm:size-5", stat.iconClass)} />
</div>
</Card>
</Link>
);
})}
</div>
Expand Down
15 changes: 12 additions & 3 deletions apps/dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getBackend } from "./backend";
import { parseWorkflowInput } from "./input";
import { saveWorkflowSchedule, scheduleInputSchema } from "./schedules.server";
import { isRunStatus } from "./status";
import { createServerFn } from "@tanstack/react-start";
import { rerunWorkflowRun } from "openworkflow/internal";
import type {
Expand Down Expand Up @@ -49,15 +50,23 @@ function parseOptionalDate(
return parsedDate;
}

export const runFilters = z.object({
status: z.string().refine(isRunStatus).optional(),
workflowName: z.string().optional(),
});

/**
* List workflow runs from the backend with optional pagination.
*/
export const listWorkflowRunsServerFn = createServerFn({ method: "GET" })
.validator(z.object(paginationInputFields))
.validator(runFilters.extend(paginationInputFields))
.handler(async ({ data }): Promise<PaginatedResponse<WorkflowRun>> => {
const backend = await getBackend();
const result = await backend.listWorkflowRuns(getPaginationOptions(data));
return result;
return backend.listWorkflowRuns({
...getPaginationOptions(data),
...(data.status && { status: data.status }),
...(data.workflowName && { workflowName: data.workflowName }),
});
});

/**
Expand Down
11 changes: 5 additions & 6 deletions apps/dashboard/src/lib/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,12 @@ const CANCELABLE_RUN_STATUSES: ReadonlySet<string> = new Set<WorkflowRunStatus>(

const fallbackStatusConfig = STATUS_CONFIG.pending;

export function getRunStatusConfig(status: string): StatusConfig {
if (!Object.hasOwn(STATUS_CONFIG, status)) {
return fallbackStatusConfig;
}
export function isRunStatus(status: string): status is WorkflowRunStatus {
return Object.hasOwn(STATUS_CONFIG, status);
}

// safety: the membership check above confirms a configured workflow status.
return STATUS_CONFIG[status as WorkflowRunStatus];
export function getRunStatusConfig(status: string): StatusConfig {
return isRunStatus(status) ? STATUS_CONFIG[status] : fallbackStatusConfig;
}

export function getStatusColor(status: string): string {
Expand Down
32 changes: 23 additions & 9 deletions apps/dashboard/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { WorkflowStats } from "@/components/workflow-stats";
import {
getStepAttemptServerFn,
getWorkflowRunCountsServerFn,
getWorkflowRunServerFn,
listWorkflowRunsServerFn,
runFilters,
} from "@/lib/api";
import {
resolveRunsPageSize,
Expand All @@ -28,20 +30,17 @@ import type { StepAttempt, WorkflowRun } from "openworkflow/internal";
import { useState } from "react";

export const Route = createFileRoute("/")({
validateSearch: validateRunsPaginationSearch,
validateSearch: (search) => ({
...validateRunsPaginationSearch(search),
...runFilters.safeParse(search).data,
}),
loaderDeps: ({ search }) => search,
component: HomePage,
loader: async ({ deps }) => {
const limit = resolveRunsPageSize(deps.limit);

const [runsResponse, workflowRunCounts] = await Promise.all([
listWorkflowRunsServerFn({
data: {
limit,
after: deps.after,
before: deps.before,
},
}),
listWorkflowRunsServerFn({ data: { ...deps, limit } }),
getWorkflowRunCountsServerFn(),
]);
const runs = runsResponse.data;
Expand Down Expand Up @@ -104,8 +103,13 @@ function HomePage() {
Route.useLoaderData();
const { data, pagination } = runsResponse;
const search = Route.useSearch();
const { limit, status, workflowName } = search;
const navigate = Route.useNavigate();

function applyName(form: FormData) {
return navigate({ search: { limit, status, ...Object.fromEntries(form) } });
}

const [isCreateRunOpen, setIsCreateRunOpen] = useState(false);
const runs = data;

Expand Down Expand Up @@ -135,6 +139,16 @@ function HomePage() {

<WorkflowStats workflowRunCounts={workflowRunCounts} />
<div className="space-y-4">
<form className="flex max-w-md gap-2" action={applyName}>
<Input
key={workflowName}
name="workflowName"
aria-label="Exact workflow name"
placeholder="Exact workflow name"
defaultValue={workflowName}
/>
<Button type="submit">Apply</Button>
</form>
<RunList
runs={runs}
childRunRelationsByRunId={childRunRelationsByRunId}
Expand All @@ -147,7 +161,7 @@ function HomePage() {
itemCount={runs.length}
itemName="run"
onChange={(next) => {
void navigate({ search: next });
void navigate({ search: { status, workflowName, ...next } });
}}
/>
</div>
Expand Down
Loading