From 615da96b08140c5585c622e0b35d0a124af892ba Mon Sep 17 00:00:00 2001 From: Amy0104 <97265214+Amy0104@users.noreply.github.com> Date: Thu, 5 May 2022 11:48:02 +0800 Subject: [PATCH] [Fix][UI Next][V1.0.0-Beta] Fix edge deletion unhandled and remove the useless nextNodes. (#9875) --- .../task/components/node/fields/use-switch.ts | 37 ++++++++++++++++++- .../workflow/components/dag/dag-toolbar.tsx | 4 +- .../workflow/components/dag/use-task-edit.ts | 14 ++++++- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-switch.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-switch.ts index ae3f48dfc7..0405406192 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-switch.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-switch.ts @@ -14,10 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ref, watch } from 'vue' +import { ref, watch, onMounted, nextTick } from 'vue' import { useI18n } from 'vue-i18n' import { useTaskNodeStore } from '@/store/project/task-node' import { queryProcessDefinitionByCode } from '@/service/modules/process-definition' +import { findIndex } from 'lodash' import type { IJsonItem } from '../types' export function useSwitch( @@ -42,6 +43,35 @@ export function useSwitch( } }) loading.value = false + clearUselessNode(branchFlowOptions.value) + } + + const clearUselessNode = (options: { value: number }[]) => { + if (!options || !options.length) { + model.nextNode = null + model.dependTaskList?.forEach((task: { nextNode: number | null }) => { + task.nextNode = null + }) + return + } + if ( + findIndex( + branchFlowOptions.value, + (option: { value: number }) => option.value == model.nextNode + ) === -1 + ) { + model.nextNode = null + } + model.dependTaskList?.forEach((task: { nextNode: number | null }) => { + if ( + findIndex( + branchFlowOptions.value, + (option: { value: number }) => option.value == task.nextNode + ) === -1 + ) { + task.nextNode = null + } + }) } watch( @@ -53,6 +83,11 @@ export function useSwitch( } ) + onMounted(async () => { + await nextTick() + clearUselessNode(branchFlowOptions.value) + }) + return [ { type: 'multi-condition', diff --git a/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/dag-toolbar.tsx b/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/dag-toolbar.tsx index c1155efa48..72e5f7f1ed 100644 --- a/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/dag-toolbar.tsx +++ b/dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/dag-toolbar.tsx @@ -168,11 +168,11 @@ export default defineComponent({ if (graph.value) { const cells = graph.value.getSelectedCells() if (cells) { - graph.value?.removeCells(cells) const codes = cells .filter((cell) => cell.isNode()) .map((cell) => +cell.id) - context.emit('removeTasks', codes) + context.emit('removeTasks', codes, cells) + graph.value?.removeCells(cells) } } } 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 c90d03dced..87a22e9ea5 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 @@ -108,7 +108,7 @@ export function useTaskEdit(options: Options) { * Remove task * @param {number} codes */ - function removeTasks(codes: number[]) { + function removeTasks(codes: number[], cells: any[]) { processDefinition.value.taskDefinitionList = processDefinition.value.taskDefinitionList.filter( (task) => !codes.includes(task.code) @@ -120,6 +120,18 @@ export function useTaskEdit(options: Options) { process.postTaskCode === code || process.preTaskCode === code ) }) + cells.forEach((cell) => { + if (cell.isEdge()) { + const preTaskCode = cell.getSourceCellId() + const postTaskCode = cell.getTargetCellId() + remove( + processDefinition.value.processTaskRelationList, + (process) => + String(process.postTaskCode) === postTaskCode && + String(process.preTaskCode) === preTaskCode + ) + } + }) } function openTaskModal(task: NodeData) {