mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
refactor(ui): clean code
This commit is contained in:
parent
24b591ed62
commit
4b931f782e
@ -276,21 +276,21 @@ export const updateNode = (node: WorkflowNode, targetNode: WorkflowNode) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const addNode = (node: WorkflowNode, preId: string, targetNode: WorkflowNode) => {
|
||||
export const addNode = (node: WorkflowNode, previousNodeId: string, targetNode: WorkflowNode) => {
|
||||
return produce(node, (draft) => {
|
||||
let current = draft;
|
||||
while (current) {
|
||||
if (current.id === preId && targetNode.type !== WorkflowNodeType.Branch && targetNode.type !== WorkflowNodeType.ExecuteResultBranch) {
|
||||
if (current.id === previousNodeId && targetNode.type !== WorkflowNodeType.Branch && targetNode.type !== WorkflowNodeType.ExecuteResultBranch) {
|
||||
targetNode.next = current.next;
|
||||
current.next = targetNode;
|
||||
break;
|
||||
} else if (current.id === preId && (targetNode.type === WorkflowNodeType.Branch || targetNode.type === WorkflowNodeType.ExecuteResultBranch)) {
|
||||
} else if (current.id === previousNodeId && (targetNode.type === WorkflowNodeType.Branch || targetNode.type === WorkflowNodeType.ExecuteResultBranch)) {
|
||||
targetNode.branches![0].next = current.next;
|
||||
current.next = targetNode;
|
||||
break;
|
||||
}
|
||||
if (current.type === WorkflowNodeType.Branch || current.type === WorkflowNodeType.ExecuteResultBranch) {
|
||||
current.branches = current.branches!.map((branch) => addNode(branch, preId, targetNode));
|
||||
current.branches = current.branches!.map((branch) => addNode(branch, previousNodeId, targetNode));
|
||||
}
|
||||
current = current.next as WorkflowNode;
|
||||
}
|
||||
@ -382,15 +382,15 @@ export const removeBranch = (node: WorkflowNode, branchNodeId: string, branchInd
|
||||
});
|
||||
};
|
||||
|
||||
export const getWorkflowOutputBeforeId = (root: WorkflowNode, nodeId: string, type: string): WorkflowNode[] => {
|
||||
// 1 个分支的节点,不应该能获取到相邻分支上节点的输出
|
||||
export const getWorkflowOutputBeforeId = (node: WorkflowNode, id: string, type: string): WorkflowNode[] => {
|
||||
const output: WorkflowNode[] = [];
|
||||
|
||||
const traverse = (current: WorkflowNode, output: WorkflowNode[]) => {
|
||||
if (!current) {
|
||||
return false;
|
||||
}
|
||||
if (current.id === id) {
|
||||
if (current.id === nodeId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ export const getWorkflowOutputBeforeId = (node: WorkflowNode, id: string, type:
|
||||
return traverse(current.next as WorkflowNode, output);
|
||||
};
|
||||
|
||||
traverse(node, output);
|
||||
traverse(root, output);
|
||||
return output;
|
||||
};
|
||||
|
||||
@ -446,21 +446,3 @@ export const isAllNodesValidated = (node: WorkflowNode): boolean => {
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export const getExecuteMethod = (node: WorkflowNode): { trigger: string; triggerCron: string } => {
|
||||
if (node.type === WorkflowNodeType.Start) {
|
||||
const config = node.config as WorkflowNodeConfigForStart;
|
||||
return {
|
||||
trigger: config.trigger ?? "",
|
||||
triggerCron: config.triggerCron ?? "",
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
trigger: "",
|
||||
triggerCron: "",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -25,14 +25,14 @@ export type WorkflowState = {
|
||||
discard(): void;
|
||||
destroy(): void;
|
||||
|
||||
addNode: (node: WorkflowNode, preId: string) => void;
|
||||
addNode: (node: WorkflowNode, previousNodeId: string) => void;
|
||||
updateNode: (node: WorkflowNode) => void;
|
||||
removeNode: (nodeId: string) => void;
|
||||
|
||||
addBranch: (branchId: string) => void;
|
||||
removeBranch: (branchId: string, index: number) => void;
|
||||
|
||||
getWorkflowOuptutBeforeId: (id: string, type: string) => WorkflowNode[];
|
||||
getWorkflowOuptutBeforeId: (nodeId: string, type: string) => WorkflowNode[];
|
||||
};
|
||||
|
||||
export const useWorkflowStore = create<WorkflowState>((set, get) => ({
|
||||
@ -143,10 +143,10 @@ export const useWorkflowStore = create<WorkflowState>((set, get) => ({
|
||||
});
|
||||
},
|
||||
|
||||
addNode: async (node: WorkflowNode, preId: string) => {
|
||||
addNode: async (node: WorkflowNode, previousNodeId: string) => {
|
||||
if (!get().initialized) throw "Workflow not initialized yet";
|
||||
|
||||
const root = addNode(get().workflow.draft!, preId, node);
|
||||
const root = addNode(get().workflow.draft!, previousNodeId, node);
|
||||
const resp = await saveWorkflow({
|
||||
id: get().workflow.id!,
|
||||
draft: root,
|
||||
@ -243,7 +243,7 @@ export const useWorkflowStore = create<WorkflowState>((set, get) => ({
|
||||
});
|
||||
},
|
||||
|
||||
getWorkflowOuptutBeforeId: (id: string, type: string) => {
|
||||
return getWorkflowOutputBeforeId(get().workflow.draft as WorkflowNode, id, type);
|
||||
getWorkflowOuptutBeforeId: (nodeId: string, type: string) => {
|
||||
return getWorkflowOutputBeforeId(get().workflow.draft as WorkflowNode, nodeId, type);
|
||||
},
|
||||
}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user