mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
feat(workflows): add responsive library card actions (#6008)
**Category:** improvement **User Impact:** Users can scan what each workflow does and trigger, edit, duplicate, enable, disable, or delete it directly from the library. **Problem:** The workflow list buried common actions and did not expose each automation's trigger-to-action shape at a glance. **Solution:** Add a responsive workflow library with a persistent create tile, compact trigger/action diagrams, prominent workflow titles with supporting descriptions, and shared card actions while preserving existing detail, editor, and run-history entry points. Card toggles refresh both list and open-detail caches so status and definition stay consistent. <details> <summary>File changes</summary> **desktop/src/features/workflows/ui/WorkflowActionsMenu.tsx** Adds a shared card menu for trigger, edit, duplicate, enable/disable, and delete actions. **desktop/src/features/workflows/ui/WorkflowCard.tsx** Reworks cards around the prototype's visual hierarchy: color-coded trigger, action flow, sentence-case eyebrow, prominent title, supporting description, status, channel, and update date without a footer clock icon. **desktop/src/features/workflows/ui/WorkflowsView.tsx** Adds the responsive grid, create tile, mutation wiring, and list/detail cache invalidation. Container breakpoints keep cards two-across at medium widths and three-across in the 1280px desktop layout. **desktop/src/features/workflows/ui/workflowDefinition.ts** Adds immutable enabled-state updates plus narrow trigger and first-action readers used only to select card icons. **desktop/src/features/workflows/ui/workflowDefinition.test.mjs** Covers neutral icon selection, enabled-state immutability, and status presentation. **desktop/tests/e2e/workflows.spec.ts** Covers the create tile, title/description hierarchy, selected-card enable/disable consistency, and deterministic narrow/medium/wide captures while retaining existing action coverage. </details> ## Reproduction steps 1. Open **Workflows** and confirm the create tile stays first as cards flow from one to three columns with available width. 2. Confirm each card shows a sentence-case trigger eyebrow, prominent workflow title, supporting description when present, status, channel, and update date without a clock icon. 3. Open a card's overflow menu and trigger, edit, duplicate, enable/disable, or delete the workflow. 4. Leave the detail panel open while toggling and confirm its badge and JSON definition update with the card. ## Screenshots Real built E2E UI with representative workflow data at three viewport sizes. ### Narrow — 800 × 720  ### Medium — 1024 × 720  ### Wide — 1280 × 720  ### Card actions  --------- Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
@@ -185,12 +185,15 @@ export function useCreateWorkflowMutation(channelId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateWorkflowMutation(workflowId: string) {
|
||||
export function useUpdateWorkflowMutation(
|
||||
workflowId: string,
|
||||
workflowRevision: string,
|
||||
) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (yamlDefinition: string) =>
|
||||
updateWorkflow(workflowId, yamlDefinition),
|
||||
updateWorkflow(workflowId, yamlDefinition, workflowRevision),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: workflowQueryKey(workflowId),
|
||||
|
||||
105
desktop/src/features/workflows/ui/WorkflowActionsMenu.tsx
Normal file
105
desktop/src/features/workflows/ui/WorkflowActionsMenu.tsx
Normal file
@@ -0,0 +1,105 @@
|
||||
import {
|
||||
Copy,
|
||||
MoreHorizontal,
|
||||
Pencil,
|
||||
Play,
|
||||
Power,
|
||||
PowerOff,
|
||||
Trash2,
|
||||
} from "lucide-react";
|
||||
|
||||
import { Button } from "@/shared/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/shared/ui/dropdown-menu";
|
||||
|
||||
type WorkflowActionsMenuProps = {
|
||||
isEnabled: boolean;
|
||||
isTogglingEnabled?: boolean;
|
||||
onDelete: () => void;
|
||||
onDuplicate: () => void;
|
||||
onEdit: () => void;
|
||||
onToggleEnabled: () => void;
|
||||
onTrigger: () => void;
|
||||
};
|
||||
|
||||
export function WorkflowActionsMenu({
|
||||
isEnabled,
|
||||
isTogglingEnabled = false,
|
||||
onDelete,
|
||||
onDuplicate,
|
||||
onEdit,
|
||||
onToggleEnabled,
|
||||
onTrigger,
|
||||
}: WorkflowActionsMenuProps) {
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
aria-label="Workflow actions"
|
||||
className="h-8 w-8 text-muted-foreground hover:bg-background/80 hover:text-foreground data-[state=open]:bg-background/80 data-[state=open]:text-foreground"
|
||||
size="icon"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={onTrigger}>
|
||||
<Play className="mr-2 h-4 w-4" />
|
||||
Trigger
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={onEdit}>
|
||||
<Pencil className="mr-2 h-4 w-4" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={onDuplicate}>
|
||||
<Copy className="mr-2 h-4 w-4" />
|
||||
Duplicate
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuCheckboxItem
|
||||
checked={isEnabled}
|
||||
className="gap-2 pl-2 [&>span:first-child]:hidden"
|
||||
disabled={isTogglingEnabled}
|
||||
onCheckedChange={(checked) => {
|
||||
if (checked !== isEnabled) onToggleEnabled();
|
||||
}}
|
||||
onSelect={(event) => event.preventDefault()}
|
||||
>
|
||||
{isEnabled ? (
|
||||
<Power className="mr-2 h-4 w-4 shrink-0" />
|
||||
) : (
|
||||
<PowerOff className="mr-2 h-4 w-4 shrink-0" />
|
||||
)}
|
||||
<span>Enable</span>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={
|
||||
"ml-auto inline-flex h-5 w-9 shrink-0 items-center rounded-full border-2 border-transparent transition-colors " +
|
||||
(isEnabled ? "bg-primary" : "bg-input")
|
||||
}
|
||||
data-testid="workflow-enabled-switch-visual"
|
||||
>
|
||||
<span
|
||||
className={
|
||||
"block h-4 w-4 rounded-full bg-background transition-transform " +
|
||||
(isEnabled ? "translate-x-4" : "translate-x-0")
|
||||
}
|
||||
/>
|
||||
</span>
|
||||
</DropdownMenuCheckboxItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-destructive" onClick={onDelete}>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -1,138 +1,181 @@
|
||||
import {
|
||||
Clock,
|
||||
Copy,
|
||||
MoreHorizontal,
|
||||
Pencil,
|
||||
Play,
|
||||
Trash2,
|
||||
ArrowRight,
|
||||
CalendarClock,
|
||||
CircleCheckBig,
|
||||
GitPullRequest,
|
||||
Hash,
|
||||
MessageCircle,
|
||||
MessageSquare,
|
||||
Send,
|
||||
SmilePlus,
|
||||
Timer,
|
||||
Webhook,
|
||||
Zap,
|
||||
} from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
|
||||
import type { Workflow } from "@/shared/api/types";
|
||||
import { Badge } from "@/shared/ui/badge";
|
||||
import { Button } from "@/shared/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/shared/ui/dropdown-menu";
|
||||
import { cn } from "@/shared/lib/cn";
|
||||
import { WorkflowActionsMenu } from "./WorkflowActionsMenu";
|
||||
import {
|
||||
getWorkflowDescription,
|
||||
getWorkflowDisplayStatus,
|
||||
getWorkflowEnabled,
|
||||
getWorkflowPrimaryAction,
|
||||
getWorkflowTriggerSummary,
|
||||
getWorkflowTriggerType,
|
||||
} from "./workflowDefinition";
|
||||
|
||||
type WorkflowCardProps = {
|
||||
workflow: Workflow;
|
||||
channelName?: string;
|
||||
isActive?: boolean;
|
||||
isTogglingEnabled?: boolean;
|
||||
onSelect: (workflowId: string) => void;
|
||||
onTrigger: (workflowId: string) => void;
|
||||
onToggleEnabled: (workflow: Workflow) => void;
|
||||
onEdit: (workflow: Workflow) => void;
|
||||
onDuplicate: (workflow: Workflow) => void;
|
||||
onDelete: (workflow: Workflow) => void;
|
||||
};
|
||||
|
||||
function StatusBadge({ status }: { status: Workflow["status"] }) {
|
||||
const variants: Record<
|
||||
Workflow["status"],
|
||||
"success" | "secondary" | "warning"
|
||||
> = {
|
||||
active: "success",
|
||||
disabled: "secondary",
|
||||
archived: "warning",
|
||||
};
|
||||
const TRIGGER_ICONS: Record<string, LucideIcon> = {
|
||||
diff_posted: GitPullRequest,
|
||||
message_posted: MessageSquare,
|
||||
reaction_added: SmilePlus,
|
||||
schedule: CalendarClock,
|
||||
webhook: Webhook,
|
||||
};
|
||||
|
||||
return <Badge variant={variants[status]}>{status}</Badge>;
|
||||
const ACTION_ICONS: Record<string, LucideIcon> = {
|
||||
add_reaction: SmilePlus,
|
||||
call_webhook: Webhook,
|
||||
delay: Timer,
|
||||
request_approval: CircleCheckBig,
|
||||
send_dm: MessageCircle,
|
||||
send_message: Send,
|
||||
set_channel_topic: Hash,
|
||||
};
|
||||
|
||||
const TRIGGER_ACCENTS: Record<string, string> = {
|
||||
diff_posted: "border-violet-400/30 bg-violet-600 text-white",
|
||||
message_posted: "border-blue-400/30 bg-blue-600 text-white",
|
||||
reaction_added: "border-pink-400/30 bg-pink-600 text-white",
|
||||
schedule: "border-emerald-400/30 bg-emerald-600 text-white",
|
||||
webhook: "border-orange-300/30 bg-orange-500 text-white",
|
||||
};
|
||||
|
||||
function StatusBadge({ status }: { status: Workflow["status"] }) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"rounded-full border border-border/65 bg-background/80 px-2 py-1 text-2xs font-semibold uppercase tracking-wider shadow-xs",
|
||||
status === "active" ? "text-foreground" : "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{status}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function WorkflowCard({
|
||||
workflow,
|
||||
channelName,
|
||||
isActive = false,
|
||||
isTogglingEnabled = false,
|
||||
onSelect,
|
||||
onTrigger,
|
||||
onToggleEnabled,
|
||||
onEdit,
|
||||
onDuplicate,
|
||||
onDelete,
|
||||
}: WorkflowCardProps) {
|
||||
const displayStatus = getWorkflowDisplayStatus(workflow);
|
||||
const description = getWorkflowDescription(workflow.definition);
|
||||
const triggerSummary = getWorkflowTriggerSummary(workflow.definition);
|
||||
const description = getWorkflowDescription(workflow.definition);
|
||||
const triggerType = getWorkflowTriggerType(workflow.definition);
|
||||
const actionType = getWorkflowPrimaryAction(workflow.definition);
|
||||
const TriggerIcon = triggerType ? TRIGGER_ICONS[triggerType] : undefined;
|
||||
const ActionIcon = actionType ? ACTION_ICONS[actionType] : undefined;
|
||||
const triggerAccent = triggerType ? TRIGGER_ACCENTS[triggerType] : undefined;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`relative w-full rounded-lg border bg-card p-3 text-left transition-colors hover:bg-muted/50 ${
|
||||
isActive ? "border-primary/40 bg-primary/5 shadow-xs" : ""
|
||||
}`}
|
||||
className={cn(
|
||||
"group relative min-h-60 w-full overflow-hidden rounded-2xl border border-border/70 bg-muted/50 p-5 text-left text-foreground shadow-xs transition-all hover:-translate-y-0.5 hover:border-border hover:bg-muted/65 hover:shadow-md",
|
||||
isActive && "border-primary/50 bg-primary/5 ring-1 ring-primary/30",
|
||||
)}
|
||||
data-testid={`workflow-card-${workflow.id}`}
|
||||
>
|
||||
<button
|
||||
className="absolute inset-0 rounded-lg"
|
||||
className="absolute inset-0 z-0 rounded-2xl focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
|
||||
onClick={() => onSelect(workflow.id)}
|
||||
type="button"
|
||||
>
|
||||
<span className="sr-only">View {workflow.name}</span>
|
||||
</button>
|
||||
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<Zap className="h-4 w-4 shrink-0 text-amber-500" />
|
||||
<span className="truncate text-sm font-medium">
|
||||
{workflow.name}
|
||||
<div className="pointer-events-none relative z-10 flex h-full min-h-48 flex-col">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex items-center gap-2" aria-hidden="true">
|
||||
<span
|
||||
className={cn(
|
||||
"flex h-9 w-9 items-center justify-center rounded-xl border shadow-xs",
|
||||
triggerAccent ?? "border-slate-400/30 bg-slate-600 text-white",
|
||||
)}
|
||||
>
|
||||
{TriggerIcon ? (
|
||||
<TriggerIcon className="h-5 w-5" />
|
||||
) : (
|
||||
<Zap className="h-5 w-5" />
|
||||
)}
|
||||
</span>
|
||||
{ActionIcon ? (
|
||||
<>
|
||||
<ArrowRight className="h-4 w-4 text-muted-foreground/60" />
|
||||
<span className="flex h-9 w-9 items-center justify-center rounded-xl border border-border/65 bg-background/80 text-muted-foreground shadow-xs">
|
||||
<ActionIcon className="h-5 w-5" />
|
||||
</span>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="pointer-events-auto flex items-center gap-1.5">
|
||||
<StatusBadge status={displayStatus} />
|
||||
<WorkflowActionsMenu
|
||||
isEnabled={getWorkflowEnabled(workflow.definition)}
|
||||
isTogglingEnabled={isTogglingEnabled}
|
||||
onDelete={() => onDelete(workflow)}
|
||||
onDuplicate={() => onDuplicate(workflow)}
|
||||
onEdit={() => onEdit(workflow)}
|
||||
onToggleEnabled={() => onToggleEnabled(workflow)}
|
||||
onTrigger={() => onTrigger(workflow.id)}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-1.5 flex items-center gap-3 pl-6 text-2xs text-muted-foreground">
|
||||
{channelName ? <span>{channelName}</span> : null}
|
||||
{triggerSummary ? <span>{triggerSummary}</span> : null}
|
||||
<span className="flex items-center gap-1">
|
||||
<Clock className="h-4 w-4" />
|
||||
{new Date(workflow.updatedAt * 1000).toLocaleDateString()}
|
||||
</span>
|
||||
</div>
|
||||
{description ? (
|
||||
<p className="mt-2 pl-6 text-xs text-muted-foreground">
|
||||
{description}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
aria-label="Workflow actions"
|
||||
className="relative z-10 h-7 w-7 shrink-0"
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => onTrigger(workflow.id)}>
|
||||
<Play className="mr-2 h-4 w-4" />
|
||||
Trigger
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => onEdit(workflow)}>
|
||||
<Pencil className="mr-2 h-4 w-4" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => onDuplicate(workflow)}>
|
||||
<Copy className="mr-2 h-4 w-4" />
|
||||
Duplicate
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="text-destructive"
|
||||
onClick={() => onDelete(workflow)}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{triggerSummary ? (
|
||||
<p className="mt-4 line-clamp-1 text-xs font-semibold text-muted-foreground">
|
||||
{triggerSummary}
|
||||
</p>
|
||||
) : null}
|
||||
<h3 className="mt-1 line-clamp-2 text-xl font-bold leading-tight tracking-tight">
|
||||
{workflow.name}
|
||||
</h3>
|
||||
{description ? (
|
||||
<p className="mt-2 line-clamp-2 text-sm leading-relaxed text-muted-foreground">
|
||||
{description}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="mt-auto flex min-w-0 items-end justify-between gap-3 pt-5 text-muted-foreground">
|
||||
<p className="min-w-0 truncate text-2xs">
|
||||
{channelName ? `#${channelName}` : "Channel workflow"}
|
||||
</p>
|
||||
<span className="shrink-0 text-2xs">
|
||||
{new Date(workflow.updatedAt * 1000).toLocaleDateString()}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -83,7 +83,10 @@ export function WorkflowDialog({
|
||||
} | null>(null);
|
||||
|
||||
const createMutation = useCreateWorkflowMutation(selectedChannelId);
|
||||
const updateMutation = useUpdateWorkflowMutation(workflow?.id ?? "");
|
||||
const updateMutation = useUpdateWorkflowMutation(
|
||||
workflow?.id ?? "",
|
||||
workflow?.revision ?? "",
|
||||
);
|
||||
const mutation = mode === "edit" ? updateMutation : createMutation;
|
||||
|
||||
const selectedChannel =
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { Plus, RefreshCw, Zap } from "lucide-react";
|
||||
import { Plus, RefreshCw } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { stringify as yamlStringify } from "yaml";
|
||||
|
||||
import {
|
||||
allWorkflowsQueryKey,
|
||||
workflowListFocusRefetchPolicy,
|
||||
workflowQueryKey,
|
||||
} from "@/features/workflows/hooks";
|
||||
import { WorkflowCard } from "@/features/workflows/ui/WorkflowCard";
|
||||
import { WorkflowDeleteDialog } from "@/features/workflows/ui/WorkflowDeleteDialog";
|
||||
@@ -15,10 +18,12 @@ import {
|
||||
deleteWorkflow,
|
||||
getChannelsWorkflows,
|
||||
triggerWorkflow,
|
||||
updateWorkflow,
|
||||
} from "@/shared/api/tauriWorkflows";
|
||||
import { Button } from "@/shared/ui/button";
|
||||
import { Card } from "@/shared/ui/card";
|
||||
import { PageHeader } from "@/shared/ui/PageHeader";
|
||||
import { Skeleton } from "@/shared/ui/skeleton";
|
||||
import { getWorkflowEnabled, withWorkflowEnabled } from "./workflowDefinition";
|
||||
|
||||
type WorkflowsViewProps = {
|
||||
channels: Channel[];
|
||||
@@ -38,35 +43,45 @@ type DialogState =
|
||||
| { mode: "edit"; workflow: Workflow }
|
||||
| { mode: "duplicate"; workflow: Workflow };
|
||||
|
||||
const WORKFLOW_CARD_GRID_CLASS =
|
||||
"grid grid-cols-1 gap-3 [@container(min-width:38rem)]:grid-cols-2 [@container(min-width:54rem)]:grid-cols-3";
|
||||
|
||||
function WorkflowsListSkeleton() {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className={WORKFLOW_CARD_GRID_CLASS}>
|
||||
{["first", "second", "third", "fourth"].map((card) => (
|
||||
<Card className="p-4" key={card}>
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="min-w-0 flex-1 space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Skeleton className="h-5 w-44" />
|
||||
<Skeleton className="h-5 w-16 rounded-full" />
|
||||
</div>
|
||||
<Skeleton className="h-4 w-full max-w-2xl" />
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Skeleton className="h-5 w-20 rounded-full" />
|
||||
<Skeleton className="h-5 w-24 rounded-full" />
|
||||
<Skeleton className="h-5 w-16 rounded-full" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="hidden shrink-0 gap-2 sm:flex">
|
||||
<Skeleton className="h-8 w-8 rounded-lg" />
|
||||
<Skeleton className="h-8 w-8 rounded-lg" />
|
||||
</div>
|
||||
<div
|
||||
className="flex min-h-60 flex-col rounded-2xl border bg-card p-5"
|
||||
key={card}
|
||||
>
|
||||
<div className="flex items-start justify-between">
|
||||
<Skeleton className="h-9 w-9 rounded-xl" />
|
||||
<Skeleton className="h-6 w-16 rounded-full" />
|
||||
</div>
|
||||
</Card>
|
||||
<Skeleton className="mt-5 h-6 w-3/4" />
|
||||
<Skeleton className="mt-3 h-4 w-full" />
|
||||
<Skeleton className="mt-2 h-4 w-4/5" />
|
||||
<Skeleton className="mt-auto h-4 w-32" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CreateWorkflowCard({ onClick }: { onClick: () => void }) {
|
||||
return (
|
||||
<button
|
||||
aria-label="Create Workflow"
|
||||
className="group relative flex min-h-60 w-full min-w-0 items-center justify-center overflow-hidden rounded-2xl border border-dashed border-border/80 bg-transparent text-muted-foreground shadow-xs transition-colors hover:border-border hover:bg-muted/70 hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring"
|
||||
data-testid="new-workflow-card"
|
||||
onClick={onClick}
|
||||
type="button"
|
||||
>
|
||||
<Plus className="h-7 w-7 transition-colors" />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export function WorkflowsView({
|
||||
channels,
|
||||
onCloseWorkflow,
|
||||
@@ -132,6 +147,38 @@ export function WorkflowsView({
|
||||
},
|
||||
});
|
||||
|
||||
const toggleEnabledMutation = useMutation({
|
||||
mutationFn: (workflow: Workflow) =>
|
||||
updateWorkflow(
|
||||
workflow.id,
|
||||
yamlStringify(
|
||||
withWorkflowEnabled(
|
||||
workflow.definition,
|
||||
!getWorkflowEnabled(workflow.definition),
|
||||
),
|
||||
),
|
||||
workflow.revision,
|
||||
),
|
||||
onError: (error) => {
|
||||
toast.error("Couldn’t change workflow status", {
|
||||
description:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "The workflow was not changed. Try again.",
|
||||
});
|
||||
},
|
||||
onSuccess: (_data, workflow) => {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: workflowQueryKey(workflow.id),
|
||||
});
|
||||
void queryClient.invalidateQueries({
|
||||
predicate: (query) =>
|
||||
query.queryKey[0] === "workflows" ||
|
||||
query.queryKey[0] === "workflows-all",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const triggerOne = triggerMutation.mutate;
|
||||
const handleTrigger = React.useCallback(
|
||||
(workflowId: string) => triggerOne(workflowId),
|
||||
@@ -162,6 +209,12 @@ export function WorkflowsView({
|
||||
[],
|
||||
);
|
||||
|
||||
const toggleEnabled = toggleEnabledMutation.mutate;
|
||||
const handleToggleEnabled = React.useCallback(
|
||||
(workflow: Workflow) => toggleEnabled(workflow),
|
||||
[toggleEnabled],
|
||||
);
|
||||
|
||||
const handleDialogOpenChange = React.useCallback((open: boolean) => {
|
||||
if (!open) {
|
||||
setDialogState({ mode: "closed" });
|
||||
@@ -174,73 +227,67 @@ export function WorkflowsView({
|
||||
data-testid="workflows-view"
|
||||
>
|
||||
<div
|
||||
className="flex min-h-0 flex-1 flex-col overflow-y-auto px-4 pb-4 pt-4"
|
||||
className="flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden overscroll-contain px-4 py-7 sm:px-6 sm:py-8"
|
||||
data-scroll-restoration-id="workflows-list"
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<h2 className="text-lg font-semibold">Workflows</h2>
|
||||
<Button
|
||||
aria-label="Refresh workflows"
|
||||
disabled={allWorkflowsQuery.isFetching}
|
||||
onClick={() => void allWorkflowsQuery.refetch()}
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
>
|
||||
<RefreshCw
|
||||
className={`h-4 w-4 ${allWorkflowsQuery.isFetching ? "animate-spin" : ""}`}
|
||||
/>
|
||||
</Button>
|
||||
</div>
|
||||
<Button onClick={() => setDialogState({ mode: "create" })} size="sm">
|
||||
<Plus className="mr-1 h-4 w-4" />
|
||||
Create Workflow
|
||||
</Button>
|
||||
</div>
|
||||
<div className="mx-auto w-full max-w-6xl space-y-8 [container-type:inline-size]">
|
||||
<PageHeader
|
||||
action={
|
||||
<Button
|
||||
aria-label="Refresh workflows"
|
||||
disabled={allWorkflowsQuery.isFetching}
|
||||
onClick={() => void allWorkflowsQuery.refetch()}
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
>
|
||||
<RefreshCw
|
||||
className={`h-4 w-4 ${allWorkflowsQuery.isFetching ? "animate-spin" : ""}`}
|
||||
/>
|
||||
</Button>
|
||||
}
|
||||
description="Automations that keep your community moving."
|
||||
title="Workflows"
|
||||
/>
|
||||
|
||||
{allWorkflowsQuery.isLoading ? (
|
||||
<WorkflowsListSkeleton />
|
||||
) : allWorkflowsQuery.isError ? (
|
||||
<div className="flex flex-1 flex-col items-center justify-center gap-2 text-muted-foreground">
|
||||
<p className="text-sm text-red-400">Failed to load workflows</p>
|
||||
<Button
|
||||
onClick={() => void allWorkflowsQuery.refetch()}
|
||||
size="sm"
|
||||
variant="outline"
|
||||
>
|
||||
Retry
|
||||
</Button>
|
||||
</div>
|
||||
) : allWorkflows.length === 0 ? (
|
||||
<div className="flex flex-1 flex-col items-center justify-center gap-3 text-muted-foreground">
|
||||
<Zap className="h-10 w-10 opacity-30" />
|
||||
<p className="text-sm">No workflows yet</p>
|
||||
<Button
|
||||
onClick={() => setDialogState({ mode: "create" })}
|
||||
size="sm"
|
||||
variant="outline"
|
||||
>
|
||||
<Plus className="mr-1 h-4 w-4" />
|
||||
Create your first workflow
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{allWorkflows.map(({ workflow, channelName }) => (
|
||||
<WorkflowCard
|
||||
channelName={channelName}
|
||||
isActive={selectedWorkflowId === workflow.id}
|
||||
key={workflow.id}
|
||||
onDelete={handleDelete}
|
||||
onDuplicate={handleDuplicate}
|
||||
onEdit={handleEdit}
|
||||
onSelect={onSelectWorkflow}
|
||||
onTrigger={handleTrigger}
|
||||
workflow={workflow}
|
||||
{allWorkflowsQuery.isLoading ? (
|
||||
<WorkflowsListSkeleton />
|
||||
) : allWorkflowsQuery.isError ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 py-16 text-muted-foreground">
|
||||
<p className="text-sm text-red-400">Failed to load workflows</p>
|
||||
<Button
|
||||
onClick={() => void allWorkflowsQuery.refetch()}
|
||||
size="sm"
|
||||
variant="outline"
|
||||
>
|
||||
Retry
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className={WORKFLOW_CARD_GRID_CLASS}>
|
||||
<CreateWorkflowCard
|
||||
onClick={() => setDialogState({ mode: "create" })}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{allWorkflows.map(({ workflow, channelName }) => (
|
||||
<WorkflowCard
|
||||
channelName={channelName}
|
||||
isActive={selectedWorkflowId === workflow.id}
|
||||
isTogglingEnabled={
|
||||
toggleEnabledMutation.isPending &&
|
||||
toggleEnabledMutation.variables?.id === workflow.id
|
||||
}
|
||||
key={workflow.id}
|
||||
onDelete={handleDelete}
|
||||
onDuplicate={handleDuplicate}
|
||||
onEdit={handleEdit}
|
||||
onSelect={onSelectWorkflow}
|
||||
onToggleEnabled={handleToggleEnabled}
|
||||
onTrigger={handleTrigger}
|
||||
workflow={workflow}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{selectedWorkflowId ? (
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
getWorkflowDisplayStatus,
|
||||
getWorkflowPrimaryAction,
|
||||
getWorkflowTriggerType,
|
||||
withWorkflowEnabled,
|
||||
} from "./workflowDefinition.ts";
|
||||
|
||||
test("reads only direct trigger and first-action types for card icons", () => {
|
||||
assert.equal(
|
||||
getWorkflowTriggerType({ trigger: { on: "message_posted" } }),
|
||||
"message_posted",
|
||||
);
|
||||
assert.equal(
|
||||
getWorkflowPrimaryAction({
|
||||
steps: [{ action: "send_message" }, { action: "delay" }],
|
||||
}),
|
||||
"send_message",
|
||||
);
|
||||
assert.equal(getWorkflowTriggerType({ trigger: { on: "" } }), null);
|
||||
assert.equal(getWorkflowPrimaryAction({ steps: [null] }), null);
|
||||
});
|
||||
|
||||
test("updates enabled state without mutating the workflow definition", () => {
|
||||
const definition = {
|
||||
name: "deploy",
|
||||
trigger: { on: "message_posted" },
|
||||
};
|
||||
const disabled = withWorkflowEnabled(definition, false);
|
||||
|
||||
assert.deepEqual(disabled, { ...definition, enabled: false });
|
||||
assert.deepEqual(definition, {
|
||||
name: "deploy",
|
||||
trigger: { on: "message_posted" },
|
||||
});
|
||||
assert.deepEqual(withWorkflowEnabled(disabled, true), definition);
|
||||
});
|
||||
|
||||
test("shows a disabled definition as disabled while preserving other statuses", () => {
|
||||
const workflow = {
|
||||
id: "workflow-id",
|
||||
name: "deploy",
|
||||
channelId: "channel-id",
|
||||
definition: { enabled: false },
|
||||
status: "active",
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
};
|
||||
|
||||
assert.equal(getWorkflowDisplayStatus(workflow), "disabled");
|
||||
assert.equal(
|
||||
getWorkflowDisplayStatus({ ...workflow, status: "archived" }),
|
||||
"archived",
|
||||
);
|
||||
});
|
||||
@@ -9,12 +9,46 @@ function asRecord(value: unknown): Record<string, unknown> | null {
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
export function getWorkflowTriggerType(
|
||||
definition: Record<string, unknown>,
|
||||
): string | null {
|
||||
const trigger = asRecord(definition.trigger);
|
||||
return typeof trigger?.on === "string" && trigger.on.trim().length > 0
|
||||
? trigger.on
|
||||
: null;
|
||||
}
|
||||
|
||||
export function getWorkflowPrimaryAction(
|
||||
definition: Record<string, unknown>,
|
||||
): string | null {
|
||||
const firstStep = Array.isArray(definition.steps)
|
||||
? asRecord(definition.steps[0])
|
||||
: null;
|
||||
return typeof firstStep?.action === "string" &&
|
||||
firstStep.action.trim().length > 0
|
||||
? firstStep.action
|
||||
: null;
|
||||
}
|
||||
|
||||
export function getWorkflowEnabled(
|
||||
definition: Record<string, unknown>,
|
||||
): boolean {
|
||||
return definition.enabled !== false;
|
||||
}
|
||||
|
||||
export function withWorkflowEnabled(
|
||||
definition: Record<string, unknown>,
|
||||
enabled: boolean,
|
||||
): Record<string, unknown> {
|
||||
const updated = { ...definition };
|
||||
if (enabled) {
|
||||
delete updated.enabled;
|
||||
} else {
|
||||
updated.enabled = false;
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
export function getWorkflowDisplayStatus(
|
||||
workflow: Workflow,
|
||||
): Workflow["status"] | "disabled" {
|
||||
|
||||
Reference in New Issue
Block a user