chore: remove unused code
This commit is contained in:
@@ -1,26 +1,21 @@
|
||||
import { run } from "@/api/workflow";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate, useSearchParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { message, notification, Switch } from "antd";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { ArrowLeft as ArrowLeftIcon } from "lucide-react";
|
||||
|
||||
import Show from "@/components/Show";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Toaster } from "@/components/ui/toaster";
|
||||
import { useToast } from "@/components/ui/use-toast";
|
||||
import End from "@/components/workflow/End";
|
||||
import NodeRender from "@/components/workflow/NodeRender";
|
||||
import WorkflowBaseInfoEditDialog from "@/components/workflow/WorkflowBaseInfoEditDialog";
|
||||
import WorkflowLog from "@/components/workflow/WorkflowLog";
|
||||
|
||||
import { cn } from "@/components/ui/utils";
|
||||
import WorkflowProvider from "@/components/workflow/WorkflowProvider";
|
||||
import { cn } from "@/components/ui/utils";
|
||||
import { allNodesValidated, WorkflowNode } from "@/domain/workflow";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { useWorkflowStore, WorkflowState } from "@/stores/workflow";
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useNavigate, useSearchParams } from "react-router-dom";
|
||||
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { run as runWorkflow } from "@/api/workflow";
|
||||
|
||||
const selectState = (state: WorkflowState) => ({
|
||||
workflow: state.workflow,
|
||||
@@ -30,11 +25,18 @@ const selectState = (state: WorkflowState) => ({
|
||||
});
|
||||
|
||||
const WorkflowDetail = () => {
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [messageApi, MessageContextHolder] = message.useMessage();
|
||||
const [_, NotificationContextHolder] = notification.useNotification();
|
||||
|
||||
// 3. 使用正确的选择器和 shallow 比较
|
||||
const { workflow, init, switchEnable, save } = useWorkflowStore(useShallow(selectState));
|
||||
|
||||
// 从 url 中获取 workflowId
|
||||
const [searchParams] = useSearchParams();
|
||||
const [locId, setLocId] = useState<string>("");
|
||||
const id = searchParams.get("id");
|
||||
|
||||
@@ -49,12 +51,6 @@ const WorkflowDetail = () => {
|
||||
}
|
||||
}, [id]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { toast } = useToast();
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
const elements = useMemo(() => {
|
||||
let current = workflow.draft as WorkflowNode;
|
||||
|
||||
@@ -78,11 +74,7 @@ const WorkflowDetail = () => {
|
||||
|
||||
const handleEnableChange = () => {
|
||||
if (!workflow.enabled && !allNodesValidated(workflow.draft as WorkflowNode)) {
|
||||
toast({
|
||||
title: t("workflow.detail.action.save.failed"),
|
||||
description: t("workflow.detail.action.save.failed.uncompleted"),
|
||||
variant: "destructive",
|
||||
});
|
||||
messageApi.warning(t("workflow.detail.action.save.failed.uncompleted"));
|
||||
return;
|
||||
}
|
||||
switchEnable();
|
||||
@@ -93,11 +85,7 @@ const WorkflowDetail = () => {
|
||||
|
||||
const handleWorkflowSaveClick = () => {
|
||||
if (!allNodesValidated(workflow.draft as WorkflowNode)) {
|
||||
toast({
|
||||
title: t("workflow.detail.action.save.failed"),
|
||||
description: t("workflow.detail.action.save.failed.uncompleted"),
|
||||
variant: "destructive",
|
||||
});
|
||||
messageApi.warning(t("workflow.detail.action.save.failed.uncompleted"));
|
||||
return;
|
||||
}
|
||||
save();
|
||||
@@ -119,95 +107,89 @@ const WorkflowDetail = () => {
|
||||
}
|
||||
setRunning(true);
|
||||
try {
|
||||
await run(workflow.id as string);
|
||||
toast({
|
||||
title: t("workflow.detail.action.run.success"),
|
||||
description: t("workflow.detail.action.run.success"),
|
||||
variant: "default",
|
||||
});
|
||||
await runWorkflow(workflow.id as string);
|
||||
messageApi.success(t("workflow.detail.action.run.success"));
|
||||
} catch (e) {
|
||||
toast({
|
||||
title: t("workflow.detail.action.run.failed"),
|
||||
description: getErrMsg(e),
|
||||
variant: "destructive",
|
||||
});
|
||||
messageApi.warning(t("workflow.detail.action.run.failed"));
|
||||
}
|
||||
setRunning(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
{MessageContextHolder}
|
||||
{NotificationContextHolder}
|
||||
|
||||
<WorkflowProvider>
|
||||
<Toaster />
|
||||
<ScrollArea className="h-[100vh] w-full relative bg-background">
|
||||
<div className="h-16 sticky top-0 left-0 z-20 shadow-md bg-muted/40 flex justify-between items-center">
|
||||
<div className="px-5 text-stone-700 dark:text-stone-200 flex items-center space-x-2">
|
||||
<ArrowLeft className="cursor-pointer" onClick={handleBackClick} />
|
||||
<WorkflowBaseInfoEditDialog
|
||||
trigger={
|
||||
<div className="flex flex-col space-y-1 cursor-pointer items-start">
|
||||
<div className="truncate max-w-[200px]">{workflow.name ? workflow.name : t("workflow.props.name.default")}</div>
|
||||
<div className="text-sm text-muted-foreground truncate max-w-[200px]">
|
||||
{workflow.description ? workflow.description : t("workflow.props.description.placeholder")}
|
||||
</div>
|
||||
<div className="h-16 sticky top-0 left-0 z-[1]` shadow-md bg-muted/40 flex justify-between items-center">
|
||||
<div className="px-5 text-stone-700 dark:text-stone-200 flex items-center space-x-2">
|
||||
<ArrowLeftIcon className="cursor-pointer" onClick={handleBackClick} />
|
||||
<WorkflowBaseInfoEditDialog
|
||||
trigger={
|
||||
<div className="flex flex-col space-y-1 cursor-pointer items-start">
|
||||
<div className="truncate max-w-[200px]">{workflow.name ? workflow.name : t("workflow.props.name.default")}</div>
|
||||
<div className="text-sm text-muted-foreground truncate max-w-[200px]">
|
||||
{workflow.description ? workflow.description : t("workflow.props.description.placeholder")}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between space-x-5 text-muted-foreground text-lg h-full">
|
||||
<div
|
||||
className={cn("h-full flex items-center cursor-pointer border-b-2", getTabCls("workflow"))}
|
||||
onClick={() => {
|
||||
setTab("workflow");
|
||||
}}
|
||||
>
|
||||
<div>{t("workflow.detail.title")}</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between space-x-5 text-muted-foreground text-lg h-full">
|
||||
<div
|
||||
className={cn("h-full flex items-center cursor-pointer border-b-2", getTabCls("workflow"))}
|
||||
onClick={() => {
|
||||
setTab("workflow");
|
||||
}}
|
||||
>
|
||||
<div>{t("workflow.detail.title")}</div>
|
||||
</div>
|
||||
<div
|
||||
className={cn("h-full flex items-center cursor-pointer border-b-2", getTabCls("history"))}
|
||||
onClick={() => {
|
||||
setTab("history");
|
||||
}}
|
||||
>
|
||||
<div>{t("workflow.detail.history")}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="px-5 flex items-center space-x-3">
|
||||
<Show when={!!workflow.enabled}>
|
||||
<Show
|
||||
when={!!workflow.hasDraft}
|
||||
fallback={
|
||||
<Button variant={"secondary"} onClick={handleRunClick}>
|
||||
{running ? t("workflow.detail.action.running") : t("workflow.detail.action.run")}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Button variant={"secondary"} onClick={handleWorkflowSaveClick}>
|
||||
{t("workflow.detail.action.save")}
|
||||
</Button>
|
||||
</Show>
|
||||
</Show>
|
||||
|
||||
<Switch className="dark:data-[state=unchecked]:bg-stone-400" checked={workflow.enabled ?? false} onCheckedChange={handleEnableChange} />
|
||||
<div
|
||||
className={cn("h-full flex items-center cursor-pointer border-b-2", getTabCls("history"))}
|
||||
onClick={() => {
|
||||
setTab("history");
|
||||
}}
|
||||
>
|
||||
<div>{t("workflow.detail.history")}</div>
|
||||
</div>
|
||||
</div>
|
||||
<Show when={tab === "workflow"}>
|
||||
<div className=" flex flex-col items-center mt-8">{elements}</div>
|
||||
</Show>
|
||||
|
||||
<Show when={!!locId && tab === "history"}>
|
||||
<div className=" flex flex-col items-center mt-8">
|
||||
<div className="px-5 flex items-center space-x-3">
|
||||
<Show when={!!workflow.enabled}>
|
||||
<Show
|
||||
when={!!workflow.hasDraft}
|
||||
fallback={
|
||||
<Button variant={"secondary"} onClick={handleRunClick}>
|
||||
{running ? t("workflow.detail.action.running") : t("workflow.detail.action.run")}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Button variant={"secondary"} onClick={handleWorkflowSaveClick}>
|
||||
{t("workflow.detail.action.save")}
|
||||
</Button>
|
||||
</Show>
|
||||
</Show>
|
||||
|
||||
<Switch checked={workflow.enabled ?? false} onChange={handleEnableChange} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Show when={tab === "workflow"}>
|
||||
<div className="p-4">
|
||||
<div className="flex flex-col items-center p-4 bg-background">{elements}</div>
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
<Show when={!!locId && tab === "history"}>
|
||||
<div className="p-4">
|
||||
<div className="flex flex-col items-center p-4 bg-background">
|
||||
<WorkflowLog />
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
<ScrollBar orientation="vertical" />
|
||||
<ScrollBar orientation="horizontal" />
|
||||
</ScrollArea>
|
||||
</div>
|
||||
</Show>
|
||||
</WorkflowProvider>
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user