2021-04-09 11:55:25 -07:00
|
|
|
import EntityRegistry from '../../entity/EntityRegistry';
|
|
|
|
import { Direction, EntityAndType, FetchedEntities, NodeData } from '../types';
|
2022-04-28 13:27:21 -04:00
|
|
|
import constructFetchedNode, { shouldIncludeChildEntity } from './constructFetchedNode';
|
2021-04-03 11:13:25 -07:00
|
|
|
|
|
|
|
export default function constructTree(
|
2021-04-09 11:55:25 -07:00
|
|
|
entityAndType: EntityAndType | null | undefined,
|
2021-04-03 11:13:25 -07:00
|
|
|
fetchedEntities: FetchedEntities,
|
|
|
|
direction: Direction,
|
2021-04-09 11:55:25 -07:00
|
|
|
entityRegistry: EntityRegistry,
|
2021-04-03 11:13:25 -07:00
|
|
|
): NodeData {
|
2021-04-09 11:55:25 -07:00
|
|
|
if (!entityAndType?.entity) return { name: 'loading...', children: [] };
|
2021-04-03 11:13:25 -07:00
|
|
|
const constructedNodes = {};
|
|
|
|
|
2021-04-09 11:55:25 -07:00
|
|
|
const fetchedEntity = entityRegistry.getLineageVizConfig(entityAndType.type, entityAndType.entity);
|
|
|
|
|
2021-04-03 11:13:25 -07:00
|
|
|
const root: NodeData = {
|
2021-04-09 11:55:25 -07:00
|
|
|
name: fetchedEntity?.name || '',
|
2022-04-01 10:37:51 -07:00
|
|
|
expandedName: fetchedEntity?.expandedName || '',
|
2021-04-09 11:55:25 -07:00
|
|
|
urn: fetchedEntity?.urn,
|
|
|
|
type: fetchedEntity?.type,
|
2021-10-06 23:39:52 -07:00
|
|
|
subtype: fetchedEntity?.subtype,
|
2021-04-09 11:55:25 -07:00
|
|
|
icon: fetchedEntity?.icon,
|
2021-04-23 00:18:39 -07:00
|
|
|
platform: fetchedEntity?.platform,
|
2021-04-03 11:13:25 -07:00
|
|
|
unexploredChildren: 0,
|
|
|
|
};
|
2021-10-22 15:46:46 -07:00
|
|
|
const lineageConfig = entityRegistry.getLineageVizConfig(entityAndType.type, entityAndType.entity);
|
|
|
|
let children: EntityAndType[] = [];
|
|
|
|
if (direction === Direction.Upstream) {
|
|
|
|
children = lineageConfig?.upstreamChildren || [];
|
|
|
|
}
|
|
|
|
if (direction === Direction.Downstream) {
|
|
|
|
children = lineageConfig?.downstreamChildren || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
root.children = children
|
2021-04-03 11:13:25 -07:00
|
|
|
.map((child) => {
|
2021-04-16 17:53:01 -07:00
|
|
|
if (child.entity.urn === root.urn) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return constructFetchedNode(child.entity.urn, fetchedEntities, direction, constructedNodes, [
|
|
|
|
root.urn || '',
|
|
|
|
]);
|
2021-04-03 11:13:25 -07:00
|
|
|
})
|
2022-04-28 13:27:21 -04:00
|
|
|
?.filter((child) => {
|
|
|
|
const childEntity = fetchedEntities[child?.urn || ''];
|
|
|
|
return shouldIncludeChildEntity(direction, children, childEntity, fetchedEntity);
|
|
|
|
})
|
2021-04-03 11:13:25 -07:00
|
|
|
?.filter(Boolean) as Array<NodeData>;
|
|
|
|
return root;
|
|
|
|
}
|