Revert "remove unused"

This reverts commit 24831d07f9.
This commit is contained in:
Mads Rasmussen
2023-11-13 16:03:16 +01:00
parent 8ab930f237
commit 520bed5d66
2 changed files with 34 additions and 1 deletions

View File

@@ -35,8 +35,25 @@ export class UmbStylesheetTreeRepository
return { data };
}
async requestRootTreeItems() {
console.log('stylesheet root');
await this.#init;
const { data, error } = await this.#treeDataSource.getRootItems();
if (data) {
this.#treeStore?.appendItems(data.items);
}
return { data, error, asObservable: () => this.#treeStore!.rootItems };
}
async requestTreeItemsOf(path: string | null) {
if (path === undefined) throw new Error('Cannot request tree item with missing path');
if (path === null || path === '/' || path === '') {
return this.requestRootTreeItems();
}
await this.#init;
const { data, error } = await this.#treeDataSource.getChildrenOf(path);
@@ -48,6 +65,11 @@ export class UmbStylesheetTreeRepository
return { data, error, asObservable: () => this.#treeStore!.childrenOf(path) };
}
async rootTreeItems() {
await this.#init;
return this.#treeStore!.rootItems;
}
async treeItemsOf(parentPath: string | null) {
if (!parentPath) throw new Error('Parent Path is missing');
await this.#init;

View File

@@ -21,6 +21,15 @@ export class UmbStylesheetTreeServerDataSource implements UmbTreeDataSource<File
this.#host = host;
}
/**
* Fetches the stylesheet tree root items from the server
* @return {*}
* @memberof UmbStylesheetTreeServerDataSource
*/
async getRootItems() {
return tryExecuteAndNotify(this.#host, StylesheetResource.getTreeStylesheetRoot({}));
}
/**
* Fetches the children of a given stylesheet path from the server
* @param {(string | null)} path
@@ -30,8 +39,10 @@ export class UmbStylesheetTreeServerDataSource implements UmbTreeDataSource<File
async getChildrenOf(path: string | null) {
if (path === undefined) throw new Error('Path is missing');
/* TODO: should we make getRootItems() internal
so it only is a server concern that there are two endpoints? */
if (path === null) {
return tryExecuteAndNotify(this.#host, StylesheetResource.getTreeStylesheetRoot({}));
return this.getRootItems();
} else {
return tryExecuteAndNotify(
this.#host,