mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-17 19:33:38 +00:00
fix: rendering of more complex pipelines tree view (#14595)
This commit is contained in:
parent
a789fc86d6
commit
83a1d4bb31
@ -78,7 +78,7 @@ const TreeViewTab = ({
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Row className="w-full">
|
<Row className="w-full">
|
||||||
<Col span={6}>
|
<Col span={12}>
|
||||||
<Tree
|
<Tree
|
||||||
defaultExpandAll
|
defaultExpandAll
|
||||||
showIcon
|
showIcon
|
||||||
@ -87,7 +87,7 @@ const TreeViewTab = ({
|
|||||||
treeData={treeLabelList}
|
treeData={treeLabelList}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={18}>
|
<Col span={12}>
|
||||||
<Tree
|
<Tree
|
||||||
defaultExpandAll
|
defaultExpandAll
|
||||||
showIcon
|
showIcon
|
||||||
|
|||||||
@ -123,13 +123,66 @@ const checkIsDownStreamTask = (currentTask: Task, tasks: Task[]) =>
|
|||||||
taskData.downstreamTasks?.includes(currentTask.name)
|
taskData.downstreamTasks?.includes(currentTask.name)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Function to build a tree for all nodes
|
||||||
|
export const buildCompleteTree = (
|
||||||
|
data: Task[],
|
||||||
|
viewElements: {
|
||||||
|
key: string;
|
||||||
|
value: any;
|
||||||
|
}[],
|
||||||
|
icon: any,
|
||||||
|
key: string,
|
||||||
|
parentKey: string
|
||||||
|
) => {
|
||||||
|
let node: DataNode;
|
||||||
|
|
||||||
|
const nodeKey: string = parentKey + '-' + key;
|
||||||
|
|
||||||
|
if (icon != null) {
|
||||||
|
node = {
|
||||||
|
key: nodeKey,
|
||||||
|
title: viewElements.find((item) => item.key === key)?.value ?? null,
|
||||||
|
children: [],
|
||||||
|
icon,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
node = {
|
||||||
|
key: nodeKey,
|
||||||
|
title: viewElements.find((item) => item.key === key)?.value ?? null,
|
||||||
|
children: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const entry = data.find((item) => item.name === key);
|
||||||
|
|
||||||
|
if (entry) {
|
||||||
|
const childrenKeys = entry.downstreamTasks ?? [];
|
||||||
|
|
||||||
|
for (const childKey of childrenKeys) {
|
||||||
|
const childNode = buildCompleteTree(
|
||||||
|
data,
|
||||||
|
viewElements,
|
||||||
|
icon,
|
||||||
|
childKey,
|
||||||
|
parentKey + '-' + entry.name
|
||||||
|
);
|
||||||
|
node.children?.push(childNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.children?.length === 0) {
|
||||||
|
delete node.children;
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
};
|
||||||
|
|
||||||
export const getTreeData = (
|
export const getTreeData = (
|
||||||
tasks: Task[],
|
tasks: Task[],
|
||||||
viewData: Record<string, ViewDataInterface[]>
|
viewData: Record<string, ViewDataInterface[]>
|
||||||
) => {
|
) => {
|
||||||
const icon = <div className="tree-view-dot" />;
|
const icon = <div className="tree-view-dot" />;
|
||||||
let treeDataList: DataNode[] = [];
|
const treeDataList: DataNode[] = [];
|
||||||
let treeLabelList: DataNode[] = [];
|
const treeLabelList: DataNode[] = [];
|
||||||
|
|
||||||
// map execution element to task name
|
// map execution element to task name
|
||||||
const viewElements = map(viewData, (value, key) => ({
|
const viewElements = map(viewData, (value, key) => ({
|
||||||
@ -161,96 +214,29 @@ export const getTreeData = (
|
|||||||
),
|
),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const labelElements: { key: string; value: string }[] = [];
|
||||||
|
|
||||||
|
viewElements.forEach((value) => {
|
||||||
|
const object = { key: value.key, value: value.key };
|
||||||
|
labelElements.push(object);
|
||||||
|
});
|
||||||
|
|
||||||
|
const roots: string[] = [];
|
||||||
|
|
||||||
for (const task of tasks) {
|
for (const task of tasks) {
|
||||||
const taskName = task.name;
|
if (!checkIsDownStreamTask(task, tasks)) {
|
||||||
|
roots.push(task.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// list of downstream tasks
|
roots.forEach((taskName) => {
|
||||||
const downstreamTasks = task.downstreamTasks ?? [];
|
treeDataList.push(
|
||||||
|
buildCompleteTree(tasks, viewElements, null, taskName, 'root')
|
||||||
// check has downstream tasks or not
|
);
|
||||||
const hasDownStream = Boolean(downstreamTasks.length);
|
treeLabelList.push(
|
||||||
|
buildCompleteTree(tasks, labelElements, icon, taskName, 'root')
|
||||||
// check if current task is downstream task
|
|
||||||
const isDownStreamTask = checkIsDownStreamTask(task, tasks);
|
|
||||||
|
|
||||||
// check if it's an existing tree data
|
|
||||||
const existingData = treeDataList.find((tData) => tData.key === taskName);
|
|
||||||
|
|
||||||
// check if it's an existing label data
|
|
||||||
const existingLabel = treeLabelList.find((lData) => lData.key === taskName);
|
|
||||||
|
|
||||||
// get the execution element for current task
|
|
||||||
const currentViewElement = getExecutionElementByKey(taskName, viewElements);
|
|
||||||
const currentTreeData = {
|
|
||||||
key: taskName,
|
|
||||||
title: currentViewElement?.value ?? null,
|
|
||||||
};
|
|
||||||
|
|
||||||
const currentLabelData = {
|
|
||||||
key: taskName,
|
|
||||||
title: taskName,
|
|
||||||
icon,
|
|
||||||
};
|
|
||||||
|
|
||||||
// skip the down stream node as it will be render by the parent task
|
|
||||||
if (isDownStreamTask) {
|
|
||||||
continue;
|
|
||||||
} else if (hasDownStream) {
|
|
||||||
const dataChildren: DataNode[] = [];
|
|
||||||
const labelChildren: DataNode[] = [];
|
|
||||||
// get execution list of downstream tasks
|
|
||||||
|
|
||||||
for (const downstreamTask of downstreamTasks) {
|
|
||||||
const taskElement = getExecutionElementByKey(
|
|
||||||
downstreamTask,
|
|
||||||
viewElements
|
|
||||||
);
|
);
|
||||||
|
|
||||||
dataChildren.push({
|
|
||||||
key: downstreamTask,
|
|
||||||
title: taskElement?.value ?? null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
labelChildren.push({
|
|
||||||
key: downstreamTask,
|
|
||||||
title: downstreamTask,
|
|
||||||
icon,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* if not existing data then push current tree data to tree data list
|
|
||||||
* else modified the existing data
|
|
||||||
*/
|
|
||||||
treeDataList = isUndefined(existingData)
|
|
||||||
? [...treeDataList, { ...currentTreeData, children: dataChildren }]
|
|
||||||
: treeDataList.map((currentData) => {
|
|
||||||
if (currentData.key === existingData.key) {
|
|
||||||
return { ...existingData, children: dataChildren };
|
|
||||||
} else {
|
|
||||||
return currentData;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
treeLabelList = isUndefined(existingLabel)
|
|
||||||
? [...treeLabelList, { ...currentLabelData, children: labelChildren }]
|
|
||||||
: treeLabelList.map((currentData) => {
|
|
||||||
if (currentData.key === existingLabel.key) {
|
|
||||||
return { ...existingLabel, children: labelChildren };
|
|
||||||
} else {
|
|
||||||
return currentData;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
treeDataList = isUndefined(existingData)
|
|
||||||
? [...treeDataList, currentTreeData]
|
|
||||||
: treeDataList;
|
|
||||||
|
|
||||||
treeLabelList = isUndefined(existingLabel)
|
|
||||||
? [...treeLabelList, currentLabelData]
|
|
||||||
: treeLabelList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { treeDataList, treeLabelList };
|
return { treeDataList, treeLabelList };
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user