Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ export class UmbTreeItemChildrenManager<
* @memberof UmbTreeItemChildrenManager
*/
public async loadChildren(): Promise<void> {
const target = this.targetPagination.getBaseTarget();
/* If a new target is set we only want to reload children if the new target isn’t among the already loaded items. */
if (target && this.isChildLoaded(target)) {
return;
}

return this.#loadChildren();
}

Expand Down Expand Up @@ -244,7 +250,7 @@ export class UmbTreeItemChildrenManager<
? this.targetPagination.getNumberOfCurrentItemsBeforeBaseTarget()
: this.#takeBeforeTarget !== undefined
? this.#takeBeforeTarget
: 5,
: this.targetPagination.getTakeSize(),
takeAfter: reload
? this.targetPagination.getNumberOfCurrentItemsAfterBaseTarget()
: this.#takeAfterTarget !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,7 @@
if (currentBaseTarget && !target) {
return;
}

Check notice on line 96 in src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-expansion.manager.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (release/17.0)

✅ Getting better: Complex Method

UmbTreeItemTargetExpansionManager.observeExpansionForTreeItem decreases in cyclomatic complexity from 14 to 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
/* If a new target is set we only want to reload children if the new target isn’t among the already loaded items. */
const targetIsLoaded = this.#childrenManager.isChildLoaded(target);
if (target && targetIsLoaded) {
return;
}

// If we already have children and the target didn't change then we don't have to load new children
const isNewTarget = target !== currentBaseTarget;
if (isExpanded && this.#childrenManager.hasLoadedChildren() && !isNewTarget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class UmbDocumentTreeItemContext extends UmbDefaultTreeItemContext<
this.hasCollection,
(hasCollection) => {
if (hasCollection) {
this._treeItemChildrenManager.setTargetTakeSize(2, 2);
this._treeItemChildrenManager.setTargetTakeSize(1, 1);

this.observe(
this.hasActiveDescendant,
Expand Down
Loading