2021-04-03 11:13:25 -07:00
|
|
|
import { GetDatasetQuery } from '../../../graphql/dataset.generated';
|
|
|
|
import { Dataset } from '../../../types.generated';
|
|
|
|
import { Direction, FetchedEntities, NodeData } from '../types';
|
|
|
|
import constructFetchedNode from './constructFetchedNode';
|
|
|
|
import getChildren from './getChildren';
|
|
|
|
|
|
|
|
export default function constructTree(
|
|
|
|
dataset: GetDatasetQuery['dataset'],
|
|
|
|
fetchedEntities: FetchedEntities,
|
|
|
|
direction: Direction,
|
|
|
|
): NodeData {
|
|
|
|
if (!dataset) return { name: 'loading...', children: [] };
|
|
|
|
const constructedNodes = {};
|
|
|
|
|
|
|
|
const root: NodeData = {
|
|
|
|
name: dataset?.name,
|
|
|
|
urn: dataset?.urn,
|
|
|
|
type: dataset?.type,
|
2021-04-09 01:24:33 +08:00
|
|
|
icon: dataset?.platform?.info?.logoUrl || undefined,
|
2021-04-03 11:13:25 -07:00
|
|
|
unexploredChildren: 0,
|
|
|
|
};
|
|
|
|
root.children = getChildren(dataset as Dataset, direction)
|
|
|
|
.map((child) => {
|
|
|
|
return constructFetchedNode(child.dataset.urn, fetchedEntities, direction, constructedNodes);
|
|
|
|
})
|
|
|
|
?.filter(Boolean) as Array<NodeData>;
|
|
|
|
return root;
|
|
|
|
}
|