fae7e920a9
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Routines are the recurring-work surface that lets a company keep operating without a human manually kicking off every task > - The base routine detail Variation C shell already landed in #7848, but the follow-up branch still had polish work for scheduling, section ergonomics, and the list layout > - Operators need routine edit screens to explain trigger behavior clearly, keep long detail pages usable on mobile/touch devices, and make grouped routine lists easier to scan > - This pull request rebases the remaining branch work onto current `master`, drops the duplicate commits already merged through #7848, and keeps only the new routine UI follow-ups > - The benefit is a cleaner routines workflow without reopening the already-merged shell work or carrying unrelated lockfile, workflow, or screenshot changes ## Linked Issues or Issue Description Refs #7848 Feature follow-up: polish the routines UI after the Variation C routine-detail shell landed. Problem / motivation: - Routine trigger configuration needs clearer previews for manual, schedule, API, and webhook execution modes. - Routine detail sections need better responsive spacing and touch ergonomics. - The routines list grouping should scan like grouped records instead of a table with heavy row dividers. - The routine tests need a React 19-compatible render helper so the focused routine suite can run in this workspace. Proposed solution: - Add cron-fire preview helpers and routine-run display helpers with focused tests. - Expand the routine editable and operate sections with richer trigger, variable, run, activity, and history presentation. - Adjust the routine detail shell and sub-sidebar spacing for mobile/touch layout. - Update grouped routine list presentation to use bordered group headers with borderless rows. - Switch affected routine tests to the repo's `flushSync` render-helper pattern. Alternatives considered: - Leaving the duplicate pre-#7848 commits in the branch would recreate conflicts and make the PR review much larger than the remaining change. - Keeping grouped routine rows inside one bordered table was simpler, but made the grouping hierarchy less legible. Roadmap alignment: - ROADMAP.md lists Scheduled Routines as a core shipped capability and Output/Enforced Outcomes as ongoing priorities. This is polish on that existing routines capability, not a new roadmap-level feature. ## What Changed - Added routine scheduling preview helpers and tests for cron/manual/API/webhook fire-policy display. - Added routine run display helpers and tests for deduped trigger labels and run-row subtitles. - Polished routine detail sections, including trigger summaries, operate views, and env/variable editing ergonomics. - Adjusted routine detail page and sub-sidebar spacing so the title/header area is less pinned and touch layouts center better. - Reworked the routines list grouped layout so group headers are bordered cards and routine rows are borderless inside each group. - Added Storybook coverage for the routines list grouped layout and updated the existing routine detail story. - Repaired routine tests to use `flushSync` helpers compatible with the installed React 19 runtime. ## Verification - `pnpm exec vitest run ui/src/lib/cron-fires.test.ts ui/src/lib/routine-run-display.test.ts ui/src/pages/Routines.test.tsx ui/src/components/RoutineSubSidebar.test.tsx ui/src/components/RoutineSaveBar.test.tsx` - Result: 5 test files passed, 37 tests passed. - Confirmed the rebased PR diff does not include `pnpm-lock.yaml`, `.github/workflows/*`, or committed screenshots. - Confirmed `origin/master` is an ancestor of the pushed branch head after rebase. ## Risks - Medium UI risk: this touches the routine detail and routine list surfaces, so visual regressions are possible in edge cases not covered by the focused tests. - Low data risk: no schema, migration, server API, or lockfile changes are included. - Review note: the branch intentionally force-pushed after rebasing because the original first three commits were already merged through #7848. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used OpenAI Codex, GPT-5-based coding agent runtime, with repository shell/tool access. Exact hosted runtime model identifier and context-window size were not exposed in the execution environment. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
202 lines
7.1 KiB
TypeScript
202 lines
7.1 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { MoreHorizontal, Play } from "lucide-react";
|
|
import { Link } from "@/lib/router";
|
|
import { AgentIcon } from "@/components/AgentIconPicker";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { ToggleSwitch } from "@/components/ui/toggle-switch";
|
|
|
|
export type RoutineListProjectSummary = {
|
|
name: string;
|
|
color?: string | null;
|
|
};
|
|
|
|
export type RoutineListAgentSummary = {
|
|
name: string;
|
|
icon?: string | null;
|
|
};
|
|
|
|
export type RoutineListRowItem = {
|
|
id: string;
|
|
title: string;
|
|
status: string;
|
|
projectId: string | null;
|
|
assigneeAgentId: string | null;
|
|
lastRun?: {
|
|
triggeredAt?: Date | string | null;
|
|
status?: string | null;
|
|
} | null;
|
|
};
|
|
|
|
export function formatLastRunTimestamp(value: Date | string | null | undefined) {
|
|
if (!value) return "Never";
|
|
return new Date(value).toLocaleString();
|
|
}
|
|
|
|
export function formatRoutineRunStatus(value: string | null | undefined) {
|
|
if (!value) return null;
|
|
return value.replaceAll("_", " ");
|
|
}
|
|
|
|
export function nextRoutineStatus(currentStatus: string, enabled: boolean) {
|
|
if (currentStatus === "archived" && enabled) return "active";
|
|
return enabled ? "active" : "paused";
|
|
}
|
|
|
|
export function RoutineListRow<TRoutine extends RoutineListRowItem>({
|
|
routine,
|
|
projectById,
|
|
agentById,
|
|
runningRoutineId,
|
|
statusMutationRoutineId,
|
|
href,
|
|
configureLabel = "Edit",
|
|
managedByLabel,
|
|
secondaryDetails,
|
|
runNowButton = false,
|
|
disableRunNow = false,
|
|
disableToggle = false,
|
|
hideArchiveAction = false,
|
|
divider = true,
|
|
onRunNow,
|
|
onToggleEnabled,
|
|
onToggleArchived,
|
|
}: {
|
|
routine: TRoutine;
|
|
projectById: Map<string, RoutineListProjectSummary>;
|
|
agentById: Map<string, RoutineListAgentSummary>;
|
|
runningRoutineId: string | null;
|
|
statusMutationRoutineId: string | null;
|
|
href: string;
|
|
configureLabel?: string;
|
|
managedByLabel?: string | null;
|
|
secondaryDetails?: ReactNode;
|
|
runNowButton?: boolean;
|
|
disableRunNow?: boolean;
|
|
disableToggle?: boolean;
|
|
hideArchiveAction?: boolean;
|
|
/** Render a bottom divider between consecutive rows. Off when the group is its own card. */
|
|
divider?: boolean;
|
|
onRunNow: (routine: TRoutine) => void;
|
|
onToggleEnabled: (routine: TRoutine, enabled: boolean) => void;
|
|
onToggleArchived?: (routine: TRoutine) => void;
|
|
}) {
|
|
const enabled = routine.status === "active";
|
|
const isArchived = routine.status === "archived";
|
|
const isStatusPending = statusMutationRoutineId === routine.id;
|
|
const project = routine.projectId ? projectById.get(routine.projectId) ?? null : null;
|
|
const agent = routine.assigneeAgentId ? agentById.get(routine.assigneeAgentId) ?? null : null;
|
|
const isDraft = !isArchived && !routine.assigneeAgentId;
|
|
const runDisabled = runningRoutineId === routine.id || isArchived || disableRunNow;
|
|
|
|
return (
|
|
<Link
|
|
to={href}
|
|
className={`group flex flex-col gap-3 px-3 py-3 transition-colors hover:bg-accent/50 sm:flex-row sm:items-center no-underline text-inherit${
|
|
divider ? " border-b border-border last:border-b-0" : ""
|
|
}`}
|
|
>
|
|
<div className="min-w-0 flex-1 space-y-1.5">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<span className="truncate text-sm font-medium">{routine.title}</span>
|
|
{(isArchived || routine.status === "paused" || isDraft) ? (
|
|
<span className="text-xs text-muted-foreground">
|
|
{isArchived ? "archived" : isDraft ? "draft" : "paused"}
|
|
</span>
|
|
) : null}
|
|
{managedByLabel ? (
|
|
<span className="text-xs text-muted-foreground">{managedByLabel}</span>
|
|
) : null}
|
|
</div>
|
|
<div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground">
|
|
<span className="flex items-center gap-2">
|
|
<span
|
|
className="h-2.5 w-2.5 shrink-0 rounded-sm"
|
|
style={{ backgroundColor: project?.color ?? "#64748b" }}
|
|
/>
|
|
<span>{routine.projectId ? (project?.name ?? "Unknown project") : "No project"}</span>
|
|
</span>
|
|
<span className="flex items-center gap-2">
|
|
{agent?.icon ? <AgentIcon icon={agent.icon} className="h-3.5 w-3.5 shrink-0" /> : null}
|
|
<span>{routine.assigneeAgentId ? (agent?.name ?? "Unknown agent") : "No default agent"}</span>
|
|
</span>
|
|
<span>
|
|
{formatLastRunTimestamp(routine.lastRun?.triggeredAt)}
|
|
{routine.lastRun ? ` · ${formatRoutineRunStatus(routine.lastRun.status)}` : ""}
|
|
</span>
|
|
</div>
|
|
{secondaryDetails ? (
|
|
<div className="text-xs text-muted-foreground">{secondaryDetails}</div>
|
|
) : null}
|
|
</div>
|
|
|
|
<div className="flex items-center gap-3" onClick={(event) => { event.preventDefault(); event.stopPropagation(); }}>
|
|
{runNowButton ? (
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
disabled={runDisabled}
|
|
onClick={() => onRunNow(routine)}
|
|
>
|
|
<Play className="h-3.5 w-3.5" />
|
|
{runningRoutineId === routine.id ? "Running..." : "Run now"}
|
|
</Button>
|
|
) : null}
|
|
|
|
<div className="flex items-center gap-3">
|
|
<ToggleSwitch
|
|
size="lg"
|
|
checked={enabled}
|
|
onCheckedChange={() => onToggleEnabled(routine, enabled)}
|
|
disabled={isStatusPending || isArchived || disableToggle}
|
|
aria-label={enabled ? `Disable ${routine.title}` : `Enable ${routine.title}`}
|
|
/>
|
|
<span className="w-12 text-xs text-muted-foreground">
|
|
{isArchived ? "Archived" : isDraft ? "Draft" : enabled ? "On" : "Off"}
|
|
</span>
|
|
</div>
|
|
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" size="icon-sm" aria-label={`More actions for ${routine.title}`}>
|
|
<MoreHorizontal className="h-4 w-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem asChild>
|
|
<Link to={href}>{configureLabel}</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
disabled={runDisabled}
|
|
onClick={() => onRunNow(routine)}
|
|
>
|
|
{runningRoutineId === routine.id ? "Running..." : "Run now"}
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
onClick={() => onToggleEnabled(routine, enabled)}
|
|
disabled={isStatusPending || isArchived || disableToggle}
|
|
>
|
|
{enabled ? "Pause" : "Enable"}
|
|
</DropdownMenuItem>
|
|
{!hideArchiveAction && onToggleArchived ? (
|
|
<DropdownMenuItem
|
|
onClick={() => onToggleArchived(routine)}
|
|
disabled={isStatusPending}
|
|
>
|
|
{routine.status === "archived" ? "Restore" : "Archive"}
|
|
</DropdownMenuItem>
|
|
) : null}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</Link>
|
|
);
|
|
}
|