mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-28 08:49:42 +02:00
feat: enable duplicate workflow feature
This commit is contained in:
parent
c61a3843a5
commit
93c45580e7
8 changed files with 396 additions and 2 deletions
|
|
@ -1,10 +1,12 @@
|
|||
"use client";
|
||||
|
||||
import { ReactFlowInstance } from "@xyflow/react";
|
||||
import { AlertCircle, ArrowLeft, ChevronDown, Download, History, LoaderCircle, MoreVertical, Phone } from "lucide-react";
|
||||
import { AlertCircle, ArrowLeft, ChevronDown, Copy, Download, History, LoaderCircle, MoreVertical, Phone } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { duplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePost } from "@/client/sdk.gen";
|
||||
import { WorkflowError } from "@/client/types.gen";
|
||||
import { FlowEdge, FlowNode } from "@/components/flow/types";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
|
@ -45,6 +47,7 @@ export const WorkflowEditorHeader = ({
|
|||
}: WorkflowEditorHeaderProps) => {
|
||||
const router = useRouter();
|
||||
const [savingWorkflow, setSavingWorkflow] = useState(false);
|
||||
const [duplicating, setDuplicating] = useState(false);
|
||||
|
||||
const hasValidationErrors = workflowValidationErrors.length > 0;
|
||||
const isCallDisabled = isDirty || hasValidationErrors;
|
||||
|
|
@ -59,6 +62,27 @@ export const WorkflowEditorHeader = ({
|
|||
router.push("/workflow");
|
||||
};
|
||||
|
||||
const handleDuplicate = async () => {
|
||||
if (duplicating) return;
|
||||
setDuplicating(true);
|
||||
const promise = duplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePost({
|
||||
path: { workflow_id: workflowId },
|
||||
});
|
||||
toast.promise(promise, {
|
||||
loading: "Duplicating workflow...",
|
||||
success: "Workflow duplicated successfully",
|
||||
error: "Failed to duplicate workflow",
|
||||
});
|
||||
try {
|
||||
const { data } = await promise;
|
||||
if (data?.id) {
|
||||
router.push(`/workflow/${data.id}`);
|
||||
}
|
||||
} finally {
|
||||
setDuplicating(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownloadWorkflow = () => {
|
||||
if (!rfInstance.current) return;
|
||||
|
||||
|
|
@ -224,6 +248,18 @@ export const WorkflowEditorHeader = ({
|
|||
<History className="w-4 h-4 mr-2" />
|
||||
View Runs
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={handleDuplicate}
|
||||
disabled={duplicating}
|
||||
className="text-white hover:bg-[#2a2a2a] cursor-pointer"
|
||||
>
|
||||
{duplicating ? (
|
||||
<LoaderCircle className="w-4 h-4 mr-2 animate-spin" />
|
||||
) : (
|
||||
<Copy className="w-4 h-4 mr-2" />
|
||||
)}
|
||||
{duplicating ? "Duplicating..." : "Duplicate Workflow"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={handleDownloadWorkflow}
|
||||
className="text-white hover:bg-[#2a2a2a] cursor-pointer"
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -2278,6 +2278,41 @@ export type UpdateWorkflowApiV1WorkflowWorkflowIdPutResponses = {
|
|||
|
||||
export type UpdateWorkflowApiV1WorkflowWorkflowIdPutResponse = UpdateWorkflowApiV1WorkflowWorkflowIdPutResponses[keyof UpdateWorkflowApiV1WorkflowWorkflowIdPutResponses];
|
||||
|
||||
export type DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostData = {
|
||||
body?: never;
|
||||
headers?: {
|
||||
authorization?: string | null;
|
||||
'X-API-Key'?: string | null;
|
||||
};
|
||||
path: {
|
||||
workflow_id: number;
|
||||
};
|
||||
query?: never;
|
||||
url: '/api/v1/workflow/{workflow_id}/duplicate';
|
||||
};
|
||||
|
||||
export type DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostErrors = {
|
||||
/**
|
||||
* Not found
|
||||
*/
|
||||
404: unknown;
|
||||
/**
|
||||
* Validation Error
|
||||
*/
|
||||
422: HttpValidationError;
|
||||
};
|
||||
|
||||
export type DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostError = DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostErrors[keyof DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostErrors];
|
||||
|
||||
export type DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostResponses = {
|
||||
/**
|
||||
* Successful Response
|
||||
*/
|
||||
200: WorkflowResponse;
|
||||
};
|
||||
|
||||
export type DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostResponse = DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostResponses[keyof DuplicateWorkflowEndpointApiV1WorkflowWorkflowIdDuplicatePostResponses];
|
||||
|
||||
export type GetWorkflowRunsApiV1WorkflowWorkflowIdRunsGetData = {
|
||||
body?: never;
|
||||
headers?: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue