handle folders only setting and pass to root end points

This commit is contained in:
Mads Rasmussen
2024-05-30 10:53:56 +02:00
parent b1872eeddf
commit 64a38e8032
2 changed files with 43 additions and 9 deletions

View File

@@ -49,6 +49,9 @@ export class UmbDefaultTreeContext<
#startNode = new UmbObjectState<UmbTreeStartNode | undefined>(undefined);
startNode = this.#startNode.asObservable();
#foldersOnly = new UmbBooleanState(false);
foldersOnly = this.#foldersOnly.asObservable();
#manifest?: ManifestTree;
#repository?: UmbTreeRepository<TreeItemType, TreeRootType>;
#actionEventContext?: UmbActionEventContext;
@@ -178,6 +181,7 @@ export class UmbDefaultTreeContext<
// If we have a start node get children of that instead of the root
const startNode = this.getStartNode();
const foldersOnly = this.#foldersOnly.getValue();
const additionalArgs = this.#additionalRequestArgs.getValue();
const { data } = startNode?.unique
@@ -187,11 +191,13 @@ export class UmbDefaultTreeContext<
unique: startNode.unique,
entityType: startNode.entityType,
},
foldersOnly,
skip,
take,
})
: await this.#repository!.requestTreeRootItems({
...additionalArgs,
foldersOnly,
skip,
take,
});
@@ -241,6 +247,36 @@ export class UmbDefaultTreeContext<
this.loadTree();
}
/**
* Gets the startNode config
* @return {UmbTreeStartNode}
* @memberof UmbDefaultTreeContext
*/
getStartNode() {
return this.#startNode.getValue();
}
/**
* Sets the foldersOnly config
* @param {boolean} foldersOnly
* @memberof UmbDefaultTreeContext
*/
setFoldersOnly(foldersOnly: boolean) {
this.#foldersOnly.setValue(foldersOnly);
// we need to reset the tree if this config changes
this.#resetTree();
this.loadTree();
}
/**
* Gets the foldersOnly config
* @return {boolean}
* @memberof UmbDefaultTreeContext
*/
getFoldersOnly() {
return this.#foldersOnly.getValue();
}
/**
* Updates the requestArgs config and reloads the tree.
*/
@@ -254,15 +290,6 @@ export class UmbDefaultTreeContext<
return this.#additionalRequestArgs.getValue();
}
/**
* Gets the startNode config
* @return {UmbTreeStartNode}
* @memberof UmbDefaultTreeContext
*/
getStartNode() {
return this.#startNode.getValue();
}
#resetTree() {
this.#treeRoot.setValue(undefined);
this.#rootItems.setValue([]);

View File

@@ -31,6 +31,9 @@ export class UmbDefaultTreeElement extends UmbLitElement {
@property({ type: Object, attribute: false })
startNode?: UmbTreeStartNode;
@property({ type: Boolean, attribute: false })
foldersOnly?: boolean = false;
@property({ attribute: false })
selectableFilter: (item: UmbTreeItemModelBase) => boolean = () => true;
@@ -87,6 +90,10 @@ export class UmbDefaultTreeElement extends UmbLitElement {
this.#treeContext!.setHideTreeRoot(this.hideTreeRoot);
}
if (_changedProperties.has('foldersOnly')) {
this.#treeContext!.setFoldersOnly(this.foldersOnly ?? false);
}
if (_changedProperties.has('selectableFilter')) {
this.#treeContext!.selectableFilter = this.selectableFilter;
}