-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1721 - enable operation switching for condition subtasks
- Loading branch information
1 parent
f7a20e6
commit 79f3a62
Showing
4 changed files
with
165 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
client/src/pages/platform/workflow-editor/utils/updateRootConditionNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import {Workflow, WorkflowTask} from '@/shared/middleware/automation/configuration'; | ||
import {NodeType} from '@/shared/types'; | ||
import {Node} from 'reactflow'; | ||
|
||
import {WorkflowTaskDataType} from '../stores/useWorkflowDataStore'; | ||
import getParentConditionTask from './getParentConditionTask'; | ||
|
||
interface UpdateRootConditionNodeProps { | ||
conditionCase: string; | ||
conditionId: string; | ||
nodeIndex: number; | ||
tasks: Array<WorkflowTask>; | ||
updatedParentConditionNodeData: NodeType; | ||
updatedParentConditionTask: WorkflowTask; | ||
nodes: Array<Node>; | ||
workflow: Workflow & WorkflowTaskDataType; | ||
} | ||
|
||
export default function updateRootConditionNode({ | ||
nodeIndex, | ||
nodes, | ||
tasks, | ||
updatedParentConditionNodeData, | ||
updatedParentConditionTask, | ||
workflow, | ||
}: UpdateRootConditionNodeProps): NodeType { | ||
let currentTaskNode = updatedParentConditionNodeData; | ||
|
||
let currentTaskNodeConditionData = updatedParentConditionNodeData.conditionData; | ||
|
||
while (currentTaskNodeConditionData) { | ||
const parentConditionTask = getParentConditionTask(tasks, currentTaskNodeConditionData.conditionId); | ||
|
||
if (!parentConditionTask) { | ||
break; | ||
} | ||
|
||
const parentConditionTaskNode = nodes.find((node) => node.id === parentConditionTask.name); | ||
|
||
if (!parentConditionTaskNode) { | ||
break; | ||
} | ||
|
||
console.log('parentConditionTaskNode: ', parentConditionTaskNode); | ||
|
||
const currentConditionCase = currentTaskNodeConditionData.conditionCase; | ||
|
||
const parentConditionCaseTasks: Array<WorkflowTask> = | ||
parentConditionTaskNode.data.parameters[currentConditionCase] || []; | ||
|
||
const workflowTasks = workflow.tasks; | ||
|
||
let currentTask = workflowTasks?.find((task) => task.name === currentTaskNode.id); | ||
|
||
if (!currentTask) { | ||
currentTask = updatedParentConditionTask; | ||
} | ||
|
||
const currentTaskIndex = parentConditionCaseTasks.findIndex((task) => task.name === currentTask.name); | ||
|
||
if (currentTaskIndex > -1) { | ||
parentConditionCaseTasks[currentTaskIndex] = currentTask; | ||
} else { | ||
parentConditionCaseTasks[nodeIndex] = currentTask; | ||
} | ||
|
||
parentConditionTaskNode.data.parameters = { | ||
...parentConditionTaskNode.data.parameters, | ||
[currentConditionCase]: parentConditionCaseTasks, | ||
}; | ||
|
||
currentTaskNode = { | ||
...parentConditionTaskNode, | ||
name: parentConditionTaskNode.id, | ||
type: parentConditionTaskNode.type || 'workflow', | ||
version: parentConditionTaskNode.data.type.split('/v')[1], | ||
workflowNodeName: parentConditionTaskNode.id, | ||
}; | ||
|
||
currentTaskNodeConditionData = parentConditionTaskNode.data.conditionData; | ||
} | ||
|
||
return currentTaskNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters