From 851016217df16c2fd791f5279abfa55f4ae450aa Mon Sep 17 00:00:00 2001 From: Ingerid Gjeitnes Hellen <64828956+ingeridhellen@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:30:26 +0200 Subject: [PATCH] feat(tree): make one init for everything (#564) * feat(tree): make one init for everything * refactor: maybe fix test --------- Co-authored-by: Henrik Bossart --- packages/dm-core/src/domain/Tree.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/dm-core/src/domain/Tree.tsx b/packages/dm-core/src/domain/Tree.tsx index 78d4efc1b..678cad4d3 100644 --- a/packages/dm-core/src/domain/Tree.tsx +++ b/packages/dm-core/src/domain/Tree.tsx @@ -1,4 +1,5 @@ import { AxiosResponse } from 'axios' +import { splitAddress } from '../utils/addressUtilities' import { EBlueprint } from '../Enums' import { useDMSS } from '../context/DMSSContext' import { DmssAPI } from '../services' @@ -268,6 +269,18 @@ export class Tree { this.updateCallback = updateCallback } + async init(path?: string[]) { + if (!path) { + this.initFromDataSources() + return + } + path + .filter((x) => splitAddress(x).documentPath) + .forEach((x) => this.initFromPath(x)) + const dataSources = path.filter((x) => !splitAddress(x).documentPath) + if (dataSources.length) this.initFromDataSources(dataSources) + } + async initFromDataSources(dataSources?: string[]) { // Add the dataSources as the top-level nodes const allDataSources = await this.dmssApi