2a1f7c2edf
* feat: sync workflows from a configured github repo Per-workspace setting pointing at a GitHub repo directory of portable workflow export files. A background poller fetches it on an interval and creates, updates, or deletes the matching workflows; a force-sync endpoint bypasses the content-hash check. Synced workflows carry source/source_path provenance and coexist with manual ones; changes that cannot be applied safely (steps or workflows that still hold tasks, ambiguous step names, unparseable files) surface as warnings in the new settings section. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): fill workflow sync form from a pasted github link A new Repository link field parses plain repo URLs, SSH remotes, and tree/blob links (which also carry branch and directory) into the structured owner/repo/branch/path fields. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): simplify workflow sync form to link, branch, and interval The repository link is now the only repo input: owner, repo, and directory resolve from the pasted URL (echoed as a summary under the field), and a stored config renders back into a canonical tree link via buildGitHubRepoUrl. Branch and poll interval stay individually editable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): collapse workflow sync into a button, dialog, and status card The Workflows settings page now shows only a GitHub Sync button by default; the link/branch/interval form lives in a dialog that closes on successful save or removal. Once configured, a compact status card (mirroring the GitHub connection-status card) shows the synced repo, branch, directory, last result, warnings, and a Sync now action. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): move github sync button into the workflows page header The GitHub Sync trigger now stacks under the Workspace settings button on the top right, and the extra separator around the sync area is gone — unconfigured workspaces show no sync chrome at all, configured ones show just the status card above the workflow list. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): move github sync button next to the workflow actions GitHub Sync now sits in the Workflows section toolbar alongside Export All, Import, and Add Workflow; the status card renders inside the section above the workflow list. The toolbar moved to its own component to keep the page under the file-size limit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): separate sync status card from the workflow list Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(web): align sync status card with the workflow list gutter Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: repair local edits to synced workflows on periodic sync Periodic syncs previously skipped applying when the repo content hash was unchanged, so local UI edits to a synced workflow were only reverted by a manual Sync now. Every sync now reconciles against the repo; the applier compares each step against its definition and only writes (and broadcasts) actual differences, so a no-drift sync stays silent. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: make github-synced workflows read-only Workflows with source=github reject UI mutations: workflow rename, description, agent-profile, and delete return 409 from the task-domain handlers; step create/update/delete/reorder and template application are guarded in the workflow controller. The sync applier writes through the service/repo layer and stays exempt. The frontend disables the card's inputs, save/delete, and the step pipeline editor for synced workflows, with a tooltip pointing at the synced repository. Drift repair on sync remains as the backstop. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: optional workflow sync polling and repo-derived branch picker A per-workspace auto-sync toggle (poll_enabled, default on) controls the background polling loop; when off the workspace only syncs via Sync now. The dialog's branch field becomes a select fed by the repository's actual branches (same loader the task-create dialog uses), falling back to free text until branches load. Existing dev databases gain the new column via an idempotent ALTER. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: release synced workflows when the sync config is removed Deleting a workspace's workflow sync configuration converts its GitHub-sourced workflows back to manual ownership (source=manual), so they become editable instead of being stranded read-only. Release runs before the config row is deleted so a failure keeps the config for retry. The settings page reloads after removal (and after syncs that changed workflows) so cards unlock without a manual refresh. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): drop branch selector and compact the auto-sync row The pasted link already carries the branch (main by default), so the dialog no longer needs a branch field — the resolved summary echoes it. The auto-sync toggle is now one compact row with the interval inline and a single short helper line. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: address PR review feedback Backend: fail-open read-only guard on workflow lookup errors (fixes MCP step handler CI failures); poller Stop holds its mutex through drain; per-workspace lock serializes syncs against config delete/replace; rollback workflow creation when provenance stamping fails; idiomatic duplicate-column migration via db.IsDuplicateColumnError; branch-name validation and a 30-day interval cap; generic 500s with logged detail; WS read-only rejections use CONFLICT with the real reason; e2e reset aborts when sync-config cleanup fails; test hygiene (t.Cleanup, SetMaxOpenConns). Frontend: malformed percent escapes parse as invalid instead of throwing; save disabled during initial load and for invalid intervals; Remove disabled while saving; stale async config responses discarded; delete-dialog confirms re-check read-only; focusable Synced badge; explicit button types; failed polls labeled 'last attempt'; unique warning list keys; test cleanup via afterEach. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: guard workflow sync test fake against concurrent poller access The poller invokes the fake applier from its own goroutine while the synctest test asserts on call counts; -race caught the unguarded reads. Also documents that the per-workspace lock is deliberately held across the GitHub fetch. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
585 lines
18 KiB
TypeScript
585 lines
18 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useEffect } from "react";
|
|
import { IconDownload, IconTrash } from "@tabler/icons-react";
|
|
import { Card, CardContent } from "@kandev/ui/card";
|
|
import { Badge } from "@kandev/ui/badge";
|
|
import { Button } from "@kandev/ui/button";
|
|
import { Input } from "@kandev/ui/input";
|
|
import { Label } from "@kandev/ui/label";
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@kandev/ui/select";
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
|
|
import type { Workflow, WorkflowStep } from "@/lib/types/http";
|
|
import { useHealthyAgentProfiles } from "@/hooks/domains/settings/use-healthy-agent-profiles";
|
|
import { useRequest } from "@/lib/http/use-request";
|
|
import { useToast } from "@/components/toast-provider";
|
|
import { WorkflowExportDialog } from "@/components/settings/workflow-export-dialog";
|
|
import { UnsavedChangesBadge, UnsavedSaveButton } from "@/components/settings/unsaved-indicator";
|
|
import { WorkflowPipelineEditor } from "@/components/settings/workflow-pipeline-editor";
|
|
import { listWorkflowStepsAction } from "@/app/actions/workspaces";
|
|
import { HelpTip } from "./workflow-pipeline-editor-helpers";
|
|
import { WorkflowDeleteDialog, StepDeleteDialog } from "./workflow-card-dialogs";
|
|
import {
|
|
useWorkflowStepActions,
|
|
useWorkflowDeleteHandlers,
|
|
useStepDeleteHandlers,
|
|
useWorkflowSaveActions,
|
|
handleExportWorkflow,
|
|
} from "./workflow-card-actions";
|
|
|
|
type WorkflowCardProps = {
|
|
workflow: Workflow;
|
|
isWorkflowDirty: boolean;
|
|
initialWorkflowSteps?: WorkflowStep[];
|
|
templateStepCount?: number;
|
|
otherWorkflows?: Workflow[];
|
|
onUpdateWorkflow: (updates: {
|
|
name?: string;
|
|
description?: string;
|
|
agent_profile_id?: string;
|
|
}) => void;
|
|
onDeleteWorkflow: () => Promise<unknown>;
|
|
onSaveWorkflow: () => Promise<unknown>;
|
|
onWorkflowCreated?: (created: Workflow) => void;
|
|
};
|
|
|
|
function useWorkflowSteps(
|
|
workflowId: string,
|
|
initialSteps: WorkflowStep[] | undefined,
|
|
isNewWorkflow: boolean,
|
|
toast: ReturnType<typeof useToast>["toast"],
|
|
) {
|
|
const [workflowSteps, setWorkflowSteps] = useState<WorkflowStep[]>(initialSteps ?? []);
|
|
const [workflowLoading, setWorkflowLoading] = useState(false);
|
|
|
|
useEffect(() => {
|
|
if (isNewWorkflow) {
|
|
setWorkflowSteps(initialSteps ?? []);
|
|
setWorkflowLoading(false);
|
|
return;
|
|
}
|
|
let cancelled = false;
|
|
const load = async () => {
|
|
setWorkflowLoading(true);
|
|
try {
|
|
const res = await listWorkflowStepsAction(workflowId);
|
|
if (!cancelled) setWorkflowSteps(res.steps ?? []);
|
|
} catch {
|
|
if (!cancelled) toast({ title: "Failed to load workflow steps", variant: "error" });
|
|
} finally {
|
|
if (!cancelled) setWorkflowLoading(false);
|
|
}
|
|
};
|
|
load();
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [workflowId, initialSteps, isNewWorkflow, toast]);
|
|
|
|
const refreshWorkflowSteps = async () => {
|
|
try {
|
|
const res = await listWorkflowStepsAction(workflowId);
|
|
setWorkflowSteps(res.steps ?? []);
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
};
|
|
|
|
return { workflowSteps, setWorkflowSteps, workflowLoading, refreshWorkflowSteps };
|
|
}
|
|
|
|
type WorkflowDeleteState = {
|
|
deleteOpen: boolean;
|
|
setDeleteOpen: (v: boolean) => void;
|
|
workflowTaskCount: number | null;
|
|
setWorkflowTaskCount: (v: number | null) => void;
|
|
workflowDeleteLoading: boolean;
|
|
setWorkflowDeleteLoading: (v: boolean) => void;
|
|
targetWorkflowId: string;
|
|
setTargetWorkflowId: (v: string) => void;
|
|
targetWorkflowSteps: WorkflowStep[];
|
|
setTargetWorkflowSteps: (v: WorkflowStep[]) => void;
|
|
targetStepId: string;
|
|
setTargetStepId: (v: string) => void;
|
|
migrateLoading: boolean;
|
|
setMigrateLoading: (v: boolean) => void;
|
|
};
|
|
|
|
function useWorkflowDeleteState(): WorkflowDeleteState {
|
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
const [workflowTaskCount, setWorkflowTaskCount] = useState<number | null>(null);
|
|
const [workflowDeleteLoading, setWorkflowDeleteLoading] = useState(false);
|
|
const [targetWorkflowId, setTargetWorkflowId] = useState<string>("");
|
|
const [targetWorkflowSteps, setTargetWorkflowSteps] = useState<WorkflowStep[]>([]);
|
|
const [targetStepId, setTargetStepId] = useState<string>("");
|
|
const [migrateLoading, setMigrateLoading] = useState(false);
|
|
return {
|
|
deleteOpen,
|
|
setDeleteOpen,
|
|
workflowTaskCount,
|
|
setWorkflowTaskCount,
|
|
workflowDeleteLoading,
|
|
setWorkflowDeleteLoading,
|
|
targetWorkflowId,
|
|
setTargetWorkflowId,
|
|
targetWorkflowSteps,
|
|
setTargetWorkflowSteps,
|
|
targetStepId,
|
|
setTargetStepId,
|
|
migrateLoading,
|
|
setMigrateLoading,
|
|
};
|
|
}
|
|
|
|
type StepDeleteState = {
|
|
stepDeleteOpen: boolean;
|
|
setStepDeleteOpen: (v: boolean) => void;
|
|
stepToDelete: string | null;
|
|
setStepToDelete: (v: string | null) => void;
|
|
stepTaskCount: number | null;
|
|
setStepTaskCount: (v: number | null) => void;
|
|
targetStepForMigration: string;
|
|
setTargetStepForMigration: (v: string) => void;
|
|
stepMigrateLoading: boolean;
|
|
setStepMigrateLoading: (v: boolean) => void;
|
|
};
|
|
|
|
function useStepDeleteState(): StepDeleteState {
|
|
const [stepDeleteOpen, setStepDeleteOpen] = useState(false);
|
|
const [stepToDelete, setStepToDelete] = useState<string | null>(null);
|
|
const [stepTaskCount, setStepTaskCount] = useState<number | null>(null);
|
|
const [targetStepForMigration, setTargetStepForMigration] = useState<string>("");
|
|
const [stepMigrateLoading, setStepMigrateLoading] = useState(false);
|
|
return {
|
|
stepDeleteOpen,
|
|
setStepDeleteOpen,
|
|
stepToDelete,
|
|
setStepToDelete,
|
|
stepTaskCount,
|
|
setStepTaskCount,
|
|
targetStepForMigration,
|
|
setTargetStepForMigration,
|
|
stepMigrateLoading,
|
|
setStepMigrateLoading,
|
|
};
|
|
}
|
|
|
|
type WorkflowCardActionsProps = {
|
|
isNewWorkflow: boolean;
|
|
workflowId: string;
|
|
setExportYaml: (json: string) => void;
|
|
setExportOpen: (open: boolean) => void;
|
|
toast: ReturnType<typeof useToast>["toast"];
|
|
onDeleteClick: () => Promise<void>;
|
|
deleteDisabled: boolean;
|
|
readOnly: boolean;
|
|
};
|
|
|
|
const SYNCED_READ_ONLY_REASON =
|
|
"Managed by workflow sync — edit or remove it in the synced repository";
|
|
|
|
function DeleteWorkflowButton({
|
|
onDeleteClick,
|
|
deleteDisabled,
|
|
readOnly,
|
|
}: {
|
|
onDeleteClick: () => Promise<void>;
|
|
deleteDisabled: boolean;
|
|
readOnly: boolean;
|
|
}) {
|
|
const button = (
|
|
<Button
|
|
type="button"
|
|
variant="destructive"
|
|
onClick={onDeleteClick}
|
|
disabled={deleteDisabled}
|
|
className="cursor-pointer"
|
|
data-testid="delete-workflow-button"
|
|
>
|
|
<IconTrash className="h-4 w-4 mr-2" />
|
|
Delete Workflow
|
|
</Button>
|
|
);
|
|
|
|
if (!readOnly) return button;
|
|
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span tabIndex={0} className="inline-flex">
|
|
{button}
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{SYNCED_READ_ONLY_REASON}</TooltipContent>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
function WorkflowCardActions({
|
|
isNewWorkflow,
|
|
workflowId,
|
|
setExportYaml,
|
|
setExportOpen,
|
|
toast,
|
|
onDeleteClick,
|
|
deleteDisabled,
|
|
readOnly,
|
|
}: WorkflowCardActionsProps) {
|
|
return (
|
|
<div className="flex justify-end gap-2">
|
|
{!isNewWorkflow && (
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() => handleExportWorkflow({ workflowId, setExportYaml, setExportOpen, toast })}
|
|
className="cursor-pointer"
|
|
>
|
|
<IconDownload className="h-4 w-4 mr-2" />
|
|
Export
|
|
</Button>
|
|
)}
|
|
<DeleteWorkflowButton
|
|
onDeleteClick={onDeleteClick}
|
|
deleteDisabled={deleteDisabled}
|
|
readOnly={readOnly}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
type WorkflowCardDialogsProps = {
|
|
wfDel: WorkflowDeleteState;
|
|
otherWorkflows: Workflow[];
|
|
deleteWorkflowLoading: boolean;
|
|
wfDeleteHandlers: {
|
|
handleDeleteWorkflow: () => Promise<void>;
|
|
handleMigrateAndDeleteWorkflow: () => Promise<void>;
|
|
};
|
|
exportOpen: boolean;
|
|
setExportOpen: (open: boolean) => void;
|
|
exportYaml: string;
|
|
stepDel: StepDeleteState;
|
|
stepsForStepMigration: WorkflowStep[];
|
|
stepDeleteHandlers: {
|
|
handleMigrateAndDeleteStep: () => Promise<void>;
|
|
handleDeleteStepAndTasks: () => Promise<void>;
|
|
};
|
|
};
|
|
|
|
type WorkflowCardBodyProps = {
|
|
workflow: Workflow;
|
|
isWorkflowDirty: boolean;
|
|
onUpdateWorkflow: (updates: {
|
|
name?: string;
|
|
description?: string;
|
|
agent_profile_id?: string;
|
|
}) => void;
|
|
activeSaveRequest: { isLoading: boolean; status: "idle" | "loading" | "success" | "error" };
|
|
handleSaveWorkflow: () => Promise<void>;
|
|
workflowLoading: boolean;
|
|
workflowSteps: WorkflowStep[];
|
|
stepActions: {
|
|
handleUpdateWorkflowStep: (id: string, updates: Partial<WorkflowStep>) => Promise<void>;
|
|
handleAddWorkflowStep: () => Promise<void>;
|
|
handleRemoveWorkflowStep: (id: string) => Promise<void>;
|
|
handleReorderWorkflowSteps: (steps: WorkflowStep[]) => Promise<void>;
|
|
};
|
|
readOnly: boolean;
|
|
};
|
|
|
|
// SyncedBadge marks workflows managed by workflow sync (workflow.source ===
|
|
// "github"). Hovering / focusing shows which repo-relative file it came from
|
|
// so users don't accidentally edit a workflow that the next poll will
|
|
// overwrite.
|
|
function SyncedBadge({ sourcePath }: { sourcePath?: string }) {
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Badge
|
|
variant="outline"
|
|
tabIndex={0}
|
|
className="text-xs cursor-default"
|
|
data-testid="workflow-synced-badge"
|
|
>
|
|
Synced
|
|
</Badge>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
Read-only — managed by workflow sync from {sourcePath || "a configured repository"}. Edit or
|
|
remove it in the synced repository.
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
function WorkflowCardBody({
|
|
workflow,
|
|
isWorkflowDirty,
|
|
onUpdateWorkflow,
|
|
activeSaveRequest,
|
|
handleSaveWorkflow,
|
|
workflowLoading,
|
|
workflowSteps,
|
|
stepActions,
|
|
readOnly,
|
|
}: WorkflowCardBodyProps) {
|
|
const healthyProfiles = useHealthyAgentProfiles(workflow.agent_profile_id);
|
|
|
|
return (
|
|
<>
|
|
<div className="flex items-end gap-2">
|
|
<div className="flex-1 space-y-1.5">
|
|
<Label className="flex items-center gap-2">
|
|
<span>Workflow Name</span>
|
|
{isWorkflowDirty && <UnsavedChangesBadge />}
|
|
{readOnly && <SyncedBadge sourcePath={workflow.source_path} />}
|
|
{readOnly && (
|
|
<span className="text-xs text-muted-foreground">
|
|
Read-only — managed by workflow sync
|
|
</span>
|
|
)}
|
|
</Label>
|
|
<Input
|
|
value={workflow.name}
|
|
onChange={(e) => onUpdateWorkflow({ name: e.target.value })}
|
|
disabled={readOnly}
|
|
/>
|
|
</div>
|
|
<div className="w-[240px] shrink-0 space-y-1.5">
|
|
<Label className="flex items-center gap-1">
|
|
<span>Agent Profile</span>
|
|
<HelpTip text="Default agent profile for tasks in this workflow. When set, the agent selector is locked in the task creation dialog." />
|
|
</Label>
|
|
<Select
|
|
value={workflow.agent_profile_id || "none"}
|
|
onValueChange={(value) =>
|
|
onUpdateWorkflow({ agent_profile_id: value === "none" ? "" : value })
|
|
}
|
|
disabled={readOnly}
|
|
>
|
|
<SelectTrigger
|
|
className="w-full cursor-pointer"
|
|
data-testid="workflow-agent-profile-select"
|
|
>
|
|
<SelectValue placeholder="None (use task default)" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="none" className="cursor-pointer">
|
|
None (use task default)
|
|
</SelectItem>
|
|
{healthyProfiles.map((p) => (
|
|
<SelectItem key={p.id} value={p.id} className="cursor-pointer">
|
|
{p.label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
<UnsavedSaveButton
|
|
isDirty={isWorkflowDirty}
|
|
isLoading={activeSaveRequest.isLoading}
|
|
status={activeSaveRequest.status}
|
|
onClick={handleSaveWorkflow}
|
|
disabled={readOnly}
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label>Workflow Steps</Label>
|
|
{workflowLoading ? (
|
|
<div className="text-sm text-muted-foreground">Loading workflow steps...</div>
|
|
) : (
|
|
<WorkflowPipelineEditor
|
|
steps={workflowSteps}
|
|
onUpdateStep={stepActions.handleUpdateWorkflowStep}
|
|
onAddStep={stepActions.handleAddWorkflowStep}
|
|
onRemoveStep={stepActions.handleRemoveWorkflowStep}
|
|
onReorderSteps={stepActions.handleReorderWorkflowSteps}
|
|
readOnly={readOnly}
|
|
/>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function WorkflowCardDialogs({
|
|
wfDel,
|
|
otherWorkflows,
|
|
deleteWorkflowLoading,
|
|
wfDeleteHandlers,
|
|
exportOpen,
|
|
setExportOpen,
|
|
exportYaml,
|
|
stepDel,
|
|
stepsForStepMigration,
|
|
stepDeleteHandlers,
|
|
}: WorkflowCardDialogsProps) {
|
|
return (
|
|
<>
|
|
<WorkflowDeleteDialog
|
|
open={wfDel.deleteOpen}
|
|
onOpenChange={wfDel.setDeleteOpen}
|
|
workflowTaskCount={wfDel.workflowTaskCount}
|
|
otherWorkflows={otherWorkflows}
|
|
targetWorkflowId={wfDel.targetWorkflowId}
|
|
setTargetWorkflowId={wfDel.setTargetWorkflowId}
|
|
targetWorkflowSteps={wfDel.targetWorkflowSteps}
|
|
targetStepId={wfDel.targetStepId}
|
|
setTargetStepId={wfDel.setTargetStepId}
|
|
migrateLoading={wfDel.migrateLoading}
|
|
deleteLoading={deleteWorkflowLoading}
|
|
onDelete={wfDeleteHandlers.handleDeleteWorkflow}
|
|
onMigrateAndDelete={wfDeleteHandlers.handleMigrateAndDeleteWorkflow}
|
|
/>
|
|
<WorkflowExportDialog
|
|
open={exportOpen}
|
|
onOpenChange={setExportOpen}
|
|
title="Export Workflow"
|
|
content={exportYaml}
|
|
/>
|
|
<StepDeleteDialog
|
|
open={stepDel.stepDeleteOpen}
|
|
onOpenChange={stepDel.setStepDeleteOpen}
|
|
stepTaskCount={stepDel.stepTaskCount}
|
|
stepsForMigration={stepsForStepMigration}
|
|
targetStep={stepDel.targetStepForMigration}
|
|
setTargetStep={stepDel.setTargetStepForMigration}
|
|
loading={stepDel.stepMigrateLoading}
|
|
onMigrateAndDelete={stepDeleteHandlers.handleMigrateAndDeleteStep}
|
|
onDeleteAndTasks={stepDeleteHandlers.handleDeleteStepAndTasks}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function useWorkflowCardState(props: WorkflowCardProps) {
|
|
const { workflow, initialWorkflowSteps, templateStepCount = 0, otherWorkflows = [] } = props;
|
|
const { onDeleteWorkflow, onSaveWorkflow, onWorkflowCreated } = props;
|
|
const { toast } = useToast();
|
|
const [exportOpen, setExportOpen] = useState(false);
|
|
const [exportYaml, setExportYaml] = useState("");
|
|
const wfDel = useWorkflowDeleteState();
|
|
const stepDel = useStepDeleteState();
|
|
const isNewWorkflow = workflow.id.startsWith("temp-");
|
|
// Workflows synced from a configured GitHub repo are read-only: the
|
|
// backend rejects definition mutations with a 409, so the UI disables the
|
|
// matching affordances (name/agent-profile/steps/delete) up front.
|
|
const readOnly = workflow.source === "github";
|
|
const deleteWorkflowRequest = useRequest(onDeleteWorkflow);
|
|
const { workflowSteps, setWorkflowSteps, workflowLoading, refreshWorkflowSteps } =
|
|
useWorkflowSteps(workflow.id, initialWorkflowSteps, isNewWorkflow, toast);
|
|
const stepActions = useWorkflowStepActions({
|
|
workflow,
|
|
isNewWorkflow,
|
|
readOnly,
|
|
workflowSteps,
|
|
setWorkflowSteps,
|
|
refreshWorkflowSteps,
|
|
setStepToDelete: stepDel.setStepToDelete,
|
|
setStepTaskCount: stepDel.setStepTaskCount,
|
|
setTargetStepForMigration: stepDel.setTargetStepForMigration,
|
|
setStepDeleteOpen: stepDel.setStepDeleteOpen,
|
|
toast,
|
|
});
|
|
const { activeSaveRequest, handleSaveWorkflow } = useWorkflowSaveActions({
|
|
workflow,
|
|
isNewWorkflow,
|
|
readOnly,
|
|
workflowSteps,
|
|
templateStepCount,
|
|
onSaveWorkflow,
|
|
onWorkflowCreated,
|
|
toast,
|
|
});
|
|
const wfDeleteHandlers = useWorkflowDeleteHandlers({
|
|
workflow,
|
|
isNewWorkflow,
|
|
readOnly,
|
|
otherWorkflows,
|
|
wfDel,
|
|
deleteWorkflowRun: deleteWorkflowRequest.run,
|
|
toast,
|
|
});
|
|
const stepDeleteHandlers = useStepDeleteHandlers({
|
|
workflow,
|
|
stepDel,
|
|
refreshWorkflowSteps,
|
|
toast,
|
|
});
|
|
const stepsForStepMigration = stepDel.stepToDelete
|
|
? workflowSteps.filter((s) => s.id !== stepDel.stepToDelete)
|
|
: [];
|
|
return {
|
|
toast,
|
|
exportOpen,
|
|
setExportOpen,
|
|
exportYaml,
|
|
setExportYaml,
|
|
wfDel,
|
|
stepDel,
|
|
isNewWorkflow,
|
|
readOnly,
|
|
deleteWorkflowRequest,
|
|
workflowSteps,
|
|
workflowLoading,
|
|
stepActions,
|
|
activeSaveRequest,
|
|
handleSaveWorkflow,
|
|
wfDeleteHandlers,
|
|
stepDeleteHandlers,
|
|
stepsForStepMigration,
|
|
};
|
|
}
|
|
|
|
export function WorkflowCard(props: WorkflowCardProps) {
|
|
const { workflow, isWorkflowDirty, otherWorkflows = [], onUpdateWorkflow } = props;
|
|
const s = useWorkflowCardState(props);
|
|
|
|
return (
|
|
<Card
|
|
data-testid={`workflow-card-${workflow.id}`}
|
|
className={isWorkflowDirty ? "ring-yellow-500/50" : undefined}
|
|
>
|
|
<CardContent className="pt-6">
|
|
<div className="space-y-4">
|
|
<WorkflowCardBody
|
|
workflow={workflow}
|
|
isWorkflowDirty={isWorkflowDirty}
|
|
onUpdateWorkflow={onUpdateWorkflow}
|
|
activeSaveRequest={s.activeSaveRequest}
|
|
handleSaveWorkflow={s.handleSaveWorkflow}
|
|
workflowLoading={s.workflowLoading}
|
|
workflowSteps={s.workflowSteps}
|
|
stepActions={s.stepActions}
|
|
readOnly={s.readOnly}
|
|
/>
|
|
<WorkflowCardActions
|
|
isNewWorkflow={s.isNewWorkflow}
|
|
workflowId={workflow.id}
|
|
setExportYaml={s.setExportYaml}
|
|
setExportOpen={s.setExportOpen}
|
|
toast={s.toast}
|
|
onDeleteClick={s.wfDeleteHandlers.handleDeleteWorkflowClick}
|
|
deleteDisabled={
|
|
s.deleteWorkflowRequest.isLoading || s.wfDel.workflowDeleteLoading || s.readOnly
|
|
}
|
|
readOnly={s.readOnly}
|
|
/>
|
|
</div>
|
|
</CardContent>
|
|
<WorkflowCardDialogs
|
|
wfDel={s.wfDel}
|
|
otherWorkflows={otherWorkflows}
|
|
deleteWorkflowLoading={s.deleteWorkflowRequest.isLoading}
|
|
wfDeleteHandlers={s.wfDeleteHandlers}
|
|
exportOpen={s.exportOpen}
|
|
setExportOpen={s.setExportOpen}
|
|
exportYaml={s.exportYaml}
|
|
stepDel={s.stepDel}
|
|
stepsForStepMigration={s.stepsForStepMigration}
|
|
stepDeleteHandlers={s.stepDeleteHandlers}
|
|
/>
|
|
</Card>
|
|
);
|
|
}
|