From f56a311849af805801f359f6f7bb29003b3261be Mon Sep 17 00:00:00 2001 From: xxt Date: Tue, 24 Sep 2024 09:37:58 +0800 Subject: [PATCH] [Fix-16567] Unable to delete copied nodes in unsaved workflow (#16576) 1. Fix the handling logic for when the backend API returns an empty array 2. If the dependent Lineage Task List is empty, no further query is required --- .../impl/WorkflowLineageServiceImpl.java | 5 +- .../dependencies/use-dependencies.ts | 114 +++++++++++------- 2 files changed, 73 insertions(+), 46 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowLineageServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowLineageServiceImpl.java index c32be6a061..4f4f6b4c05 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowLineageServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowLineageServiceImpl.java @@ -260,16 +260,19 @@ public class WorkflowLineageServiceImpl extends BaseServiceImpl implements Workf if (project == null) { throw new ServiceException(Status.PROJECT_NOT_FOUND, projectCode); } + List dependentLineageTaskList = new ArrayList<>(); List workflowTaskLineageList = workflowTaskLineageDao.queryWorkFlowLineageByDept(projectCode, workflowDefinitionCode, taskCode == null ? 0 : taskCode); + if (workflowTaskLineageList.isEmpty()) { + return dependentLineageTaskList; + } List workflowDefinitionList = workflowDefinitionMapper.queryByCodes(workflowTaskLineageList.stream() .map(WorkflowTaskLineage::getWorkflowDefinitionCode).distinct().collect(Collectors.toList())); List taskDefinitionList = taskDefinitionMapper.queryByCodeList(workflowTaskLineageList.stream() .map(WorkflowTaskLineage::getTaskDefinitionCode).filter(code -> code != 0).distinct() .collect(Collectors.toList())); - List dependentLineageTaskList = new ArrayList<>(); for (WorkflowTaskLineage workflowTaskLineage : workflowTaskLineageList) { DependentLineageTask dependentLineageTask = new DependentLineageTask(); taskDefinitionList.stream() diff --git a/dolphinscheduler-ui/src/views/projects/components/dependencies/use-dependencies.ts b/dolphinscheduler-ui/src/views/projects/components/dependencies/use-dependencies.ts index a16a3c00f3..4db5136bda 100644 --- a/dolphinscheduler-ui/src/views/projects/components/dependencies/use-dependencies.ts +++ b/dolphinscheduler-ui/src/views/projects/components/dependencies/use-dependencies.ts @@ -30,14 +30,21 @@ export function useDependencies() { workFlowCode: workflowCode, taskCode: taskCode } as DependentTaskReq - const res = await queryDependentTasks(projectCode, dependentTaskReq) - res - .filter((item: any) => item.workflowDefinitionCode !== workflowCode) - .forEach((item: any) => { - tasks.push( - item.workflowDefinitionName + '->' + item.taskDefinitionName - ) - }) + await queryDependentTasks(projectCode, dependentTaskReq).then( + (res: any) => { + if (res?.data?.length > 0) { + res.data + .filter( + (item: any) => item.workflowDefinitionCode !== workflowCode + ) + .forEach((item: any) => { + tasks.push( + item.workflowDefinitionName + '->' + item.taskDefinitionName + ) + }) + } + } + ) } return tasks } @@ -51,14 +58,21 @@ export function useDependencies() { const dependentTaskReq = { workFlowCode: workflowCode } as DependentTaskReq - const res = await queryDependentTasks(projectCode, dependentTaskReq) - res - .filter((item: any) => item.workflowDefinitionCode !== workflowCode) - .forEach((item: any) => { - tasks.push( - item.workflowDefinitionName + '->' + item.taskDefinitionName - ) - }) + await queryDependentTasks(projectCode, dependentTaskReq).then( + (res: any) => { + if (res?.data?.length > 0) { + res.data + .filter( + (item: any) => item.workflowDefinitionCode !== workflowCode + ) + .forEach((item: any) => { + tasks.push( + item.workflowDefinitionName + '->' + item.taskDefinitionName + ) + }) + } + } + ) } return tasks } @@ -110,25 +124,29 @@ export function useDependencies() { if (workflowCode && projectCode) { await queryDependentTasks(projectCode, dependentTaskReq).then( (res: any) => { - res.data - .filter((item: any) => { - if (item.workflowDefinitionCode) { - return item.workflowDefinitionCode !== workflowCode - } else { - return false - } - }) - .forEach((item: any) => { - dependentTaskLinks.push({ - text: - item.workflowDefinitionName + '->' + item.taskDefinitionName, - show: true, - action: () => { - const url = `/projects/${item.projectCode}/workflow/definitions/${item.workflowDefinitionCode}` - window.open(url, '_blank') + if (res?.data?.length > 0) { + res.data + .filter((item: any) => { + if (item.workflowDefinitionCode) { + return item.workflowDefinitionCode !== workflowCode + } else { + return false } }) - }) + .forEach((item: any) => { + dependentTaskLinks.push({ + text: + item.workflowDefinitionName + + '->' + + item.taskDefinitionName, + show: true, + action: () => { + const url = `/projects/${item.projectCode}/workflow/definitions/${item.workflowDefinitionCode}` + window.open(url, '_blank') + } + }) + }) + } } ) } @@ -148,19 +166,25 @@ export function useDependencies() { if (workflowCode && projectCode) { await queryDependentTasks(projectCode, dependentTaskReq).then( (res: any) => { - res - .filter((item: any) => item.workflowDefinitionCode !== workflowCode) - .forEach((item: any) => { - dependentTaskLinks.push({ - text: - item.workflowDefinitionName + '->' + item.taskDefinitionName, - show: true, - action: () => { - const url = `/projects/${item.projectCode}/workflow/definitions/${item.workflowDefinitionCode}` - window.open(url, '_blank') - } + if (res?.data?.length > 0) { + res.data + .filter( + (item: any) => item.workflowDefinitionCode !== workflowCode + ) + .forEach((item: any) => { + dependentTaskLinks.push({ + text: + item.workflowDefinitionName + + '->' + + item.taskDefinitionName, + show: true, + action: () => { + const url = `/projects/${item.projectCode}/workflow/definitions/${item.workflowDefinitionCode}` + window.open(url, '_blank') + } + }) }) - }) + } } ) }