From 8bb6971c2f6a4c4e42ee1d06bd07ba7d75e6bc3d Mon Sep 17 00:00:00 2001 From: Amy0104 <97265214+Amy0104@users.noreply.github.com> Date: Mon, 21 Mar 2022 15:28:58 +0800 Subject: [PATCH] [Fix][UI Next][V1.0.0-Alpha] Fix the branch flow options not showing and back to show. (#9049) --- .../src/store/project/task-node.ts | 10 +++++ .../components/node/fields/use-conditions.ts | 16 +++++++ .../task/components/node/format-data.ts | 14 ++++++ .../projects/task/components/node/types.ts | 7 +++ .../components/dag/use-canvas-init.ts | 17 +++++++ .../components/dag/use-cell-update.ts | 20 +++++++-- .../workflow/components/dag/use-task-edit.ts | 44 +++++++++++++++++-- 7 files changed, 121 insertions(+), 7 deletions(-) diff --git a/dolphinscheduler-ui-next/src/store/project/task-node.ts b/dolphinscheduler-ui-next/src/store/project/task-node.ts index 9d8ec7e95e..977959494b 100644 --- a/dolphinscheduler-ui-next/src/store/project/task-node.ts +++ b/dolphinscheduler-ui-next/src/store/project/task-node.ts @@ -79,6 +79,16 @@ export const useTaskNodeStore = defineStore({ } if (relation.postTaskCode === code && relation.preTaskCode !== 0) { preTasks.push(relation.preTaskCode) + if ( + !this.preTaskOptions.find( + (item) => item.value === relation.preTaskCode + ) + ) { + this.preTaskOptions.push({ + value: relation.preTaskCode, + label: tasks[relation.preTaskCode] + }) + } } } ) diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-conditions.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-conditions.ts index 7b14fb3b85..356e6e0dd3 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-conditions.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-conditions.ts @@ -51,6 +51,14 @@ export function useConditions(model: { [field: string]: any }): IJsonItem[] { props: { clearable: true }, + validate: { + trigger: ['input', 'blur'], + validator: (unuse, value) => { + if (value && value === model.failedBranch) { + return new Error(t('project.node.branch_tips')) + } + } + }, options: taskStore.getPostTaskOptions }, { @@ -71,6 +79,14 @@ export function useConditions(model: { [field: string]: any }): IJsonItem[] { props: { clearable: true }, + validate: { + trigger: ['input', 'blur'], + validator: (unuse, value) => { + if (value && value === model.successBranch) { + return new Error(t('project.node.branch_tips')) + } + } + }, options: taskStore.getPostTaskOptions }, ...useTimeoutAlarm(model), diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts index 07ac7e9115..728a4ec2da 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts @@ -207,6 +207,13 @@ export function formatParams(data: INodeData): { relation: data.relation, dependTaskList: data.dependTaskList } + taskParams.conditionResult = {} + if (data.successBranch) { + taskParams.conditionResult.successNode = [data.successBranch] + } + if (data.failedBranch) { + taskParams.conditionResult.failedNode = [data.failedBranch] + } } if (data.taskType === 'DATAX') { @@ -464,6 +471,13 @@ export function formatModel(data: ITaskData) { params.processDefinitionCode = data.taskParams.processDefinitionCode } + if (data.taskParams?.conditionResult?.successNode?.length) { + params.successBranch = data.taskParams?.conditionResult.successNode[0] + } + if (data.taskParams?.conditionResult?.failedNode?.length) { + params.failedBranch = data.taskParams?.conditionResult.failedNode[0] + } + return params } diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts index bab4a2886d..f8bdf0ae74 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts @@ -276,6 +276,10 @@ interface ITaskParams { ruleInputParameter?: IRuleParameters jobFlowDefineJson?: string processDefinitionCode?: number + conditionResult?: { + successNode?: number[] + failedNode?: number[] + } } interface INodeData @@ -287,6 +291,7 @@ interface INodeData | 'sourceParams' | 'dependence' | 'sparkParameters' + | 'conditionResult' >, ISqoopTargetData, ISqoopSourceData, @@ -321,6 +326,8 @@ interface INodeData resourceFiles?: { id: number; fullName: string }[] | null relation?: RelationType definition?: object + successBranch?: number + failedBranch?: number } interface ITaskData diff --git a/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-canvas-init.ts b/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-canvas-init.ts index 6282acfaed..1c422ee38f 100644 --- a/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-canvas-init.ts +++ b/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-canvas-init.ts @@ -101,6 +101,23 @@ export function useCanvasInit(options: Options) { highlight: true, createEdge() { return graph.value?.createEdge({ shape: X6_EDGE_NAME }) + }, + validateConnection(data) { + const { sourceCell, targetCell } = data + + if ( + sourceCell && + targetCell && + sourceCell.isNode() && + targetCell.isNode() + ) { + const sourceData = sourceCell.getData() + if (!sourceData) return true + if (sourceData.taskType !== 'CONDITIONS') return true + return (graph.value?.getConnectedEdges(sourceCell).length || 0) <= 2 + } + + return true } }, highlighting: { diff --git a/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-cell-update.ts b/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-cell-update.ts index 1cfc1e2da5..f62c09a8e1 100644 --- a/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-cell-update.ts +++ b/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-cell-update.ts @@ -99,11 +99,24 @@ export function useCellUpdate(options: Options) { const getSources = (id: string): number[] => { const edges = getNodeEdge(id) if (!edges.length) return [] - const targets = [] as number[] + const sources = [] as number[] edges.forEach((edge) => { const sourceNode = edge.getSourceNode() if (sourceNode && sourceNode.id !== id) { - targets.push(Number(sourceNode.id)) + sources.push(Number(sourceNode.id)) + } + }) + return sources + } + + const getTargets = (id: string): number[] => { + const edges = getNodeEdge(id) + if (!edges.length) return [] + const targets = [] as number[] + edges.forEach((edge) => { + const targetNode = edge.getTargetNode() + if (targetNode && targetNode.id !== id) { + targets.push(Number(targetNode.id)) } }) return targets @@ -114,6 +127,7 @@ export function useCellUpdate(options: Options) { setNodeEdge, addNode, removeNode, - getSources + getSources, + getTargets } } diff --git a/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-task-edit.ts b/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-task-edit.ts index e15d23d80a..770f52a532 100644 --- a/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-task-edit.ts +++ b/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-task-edit.ts @@ -41,10 +41,16 @@ interface Options { */ export function useTaskEdit(options: Options) { const { graph, definition } = options - const { addNode, removeNode, getSources, setNodeName, setNodeEdge } = - useCellUpdate({ - graph - }) + const { + addNode, + removeNode, + getSources, + getTargets, + setNodeName, + setNodeEdge + } = useCellUpdate({ + graph + }) const processDefinition = ref( definition?.value || { processDefinition: {}, @@ -107,6 +113,13 @@ export function useTaskEdit(options: Options) { processDefinition.value.taskDefinitionList.filter( (task) => !codes.includes(task.code) ) + codes.forEach((code: number) => { + remove( + processDefinition.value.processTaskRelationList, + (process) => + process.postTaskCode === code || process.preTaskCode === code + ) + }) } function openTaskModal(task: NodeData) { @@ -126,6 +139,7 @@ export function useTaskEdit(options: Options) { currTask.value = definition } updatePreTasks(getSources(String(code)), code) + updatePostTasks(code) taskModalVisible.value = true } @@ -191,6 +205,28 @@ export function useTaskEdit(options: Options) { }) } + function updatePostTasks(code: number) { + const targets = getTargets(String(code)) + targets.forEach((target: number) => { + if ( + !processDefinition.value?.processTaskRelationList.find( + (relation) => + relation.postTaskCode === target && relation.preTaskCode === code + ) + ) { + processDefinition.value?.processTaskRelationList.push({ + postTaskCode: target, + preTaskCode: code, + name: '', + preTaskVersion: 1, + postTaskVersion: 1, + conditionType: 'NONE', + conditionParams: {} + }) + } + }) + } + onMounted(() => { if (graph.value) { graph.value.on('cell:dblclick', ({ cell }) => {