Skip to content

Commit e68e2a6

Browse files
marko-kriskovicivicac
authored andcommitted
2867 - created getAllTasksRecursively because the initial implementation didn't account for tasks in cluster elements, rag and tools
1 parent 4a46916 commit e68e2a6

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {TASK_DISPATCHER_NAMES} from '@/shared/constants';
2+
import {WorkflowTask} from '@/shared/middleware/platform/configuration';
3+
4+
import {TASK_DISPATCHER_CONFIG} from './taskDispatcherConfig';
5+
6+
/**
7+
* Recursively gets all tasks from a workflow, including tasks nested inside task dispatchers
8+
*/
9+
export default function getAllTasksRecursively(tasks: Array<WorkflowTask>): Array<WorkflowTask> {
10+
const allTasks: Array<WorkflowTask> = [];
11+
12+
const extractTasks = (taskList: Array<WorkflowTask>) => {
13+
taskList.forEach((task) => {
14+
allTasks.push(task);
15+
16+
// Check if this is a task dispatcher
17+
const componentName = task.type?.split('/')[0];
18+
19+
if (componentName && TASK_DISPATCHER_NAMES.includes(componentName)) {
20+
const config = TASK_DISPATCHER_CONFIG[componentName as keyof typeof TASK_DISPATCHER_CONFIG];
21+
22+
if (config) {
23+
const subtasks = config.getSubtasks({getAllSubtasks: true, task});
24+
25+
if (subtasks && subtasks.length > 0) {
26+
extractTasks(subtasks);
27+
}
28+
}
29+
}
30+
});
31+
};
32+
33+
extractTasks(tasks);
34+
35+
return allTasks;
36+
}

client/src/pages/platform/workflow-editor/utils/getFormattedName.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {ClusterElementsType, NodeDataType} from '@/shared/types';
33

44
import {isPlainObject} from '../../cluster-element-editor/utils/clusterElementsUtils';
55
import useWorkflowDataStore from '../stores/useWorkflowDataStore';
6+
import getAllTasksRecursively from './getAllTasksRecursively';
67

78
export default function getFormattedName(itemName: string): string {
89
const {nodes, workflow} = useWorkflowDataStore.getState();
@@ -13,7 +14,9 @@ export default function getFormattedName(itemName: string): string {
1314

1415
const workflowDefinition = JSON.parse(workflow.definition!);
1516

16-
const clusterElementNames = workflowDefinition.tasks.map((task: WorkflowTask) => {
17+
const allTasks = getAllTasksRecursively(workflowDefinition.tasks);
18+
19+
const clusterElementNames = allTasks.map((task: WorkflowTask) => {
1720
const elementNames: string[] = [];
1821

1922
const {clusterElements} = task;

0 commit comments

Comments
 (0)