Skip to content

Commit 13435cb

Browse files
committed
setTargetTakeSize to low when Collection parent
1 parent d4f4835 commit 13435cb

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-base/tree-item-context-base.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ export abstract class UmbTreeItemContextBase<
4747
#path = new UmbStringState('');
4848
readonly path = this.#path.asObservable();
4949

50-
#treeItemChildrenManager = new UmbTreeItemChildrenManager<TreeItemType, TreeRootType>(this);
51-
public readonly childItems = this.#treeItemChildrenManager.children;
52-
public readonly hasChildren = this.#treeItemChildrenManager.hasChildren;
53-
public readonly foldersOnly = this.#treeItemChildrenManager.foldersOnly;
54-
public readonly pagination = this.#treeItemChildrenManager.offsetPagination;
55-
public readonly targetPagination = this.#treeItemChildrenManager.targetPagination;
56-
public readonly isLoading = this.#treeItemChildrenManager.isLoading;
57-
public readonly isLoadingPrevChildren = this.#treeItemChildrenManager.isLoadingPrevChildren;
58-
public readonly isLoadingNextChildren = this.#treeItemChildrenManager.isLoadingNextChildren;
50+
protected readonly _treeItemChildrenManager = new UmbTreeItemChildrenManager<TreeItemType, TreeRootType>(this);
51+
public readonly childItems = this._treeItemChildrenManager.children;
52+
public readonly hasChildren = this._treeItemChildrenManager.hasChildren;
53+
public readonly foldersOnly = this._treeItemChildrenManager.foldersOnly;
54+
public readonly pagination = this._treeItemChildrenManager.offsetPagination;
55+
public readonly targetPagination = this._treeItemChildrenManager.targetPagination;
56+
public readonly isLoading = this._treeItemChildrenManager.isLoading;
57+
public readonly isLoadingPrevChildren = this._treeItemChildrenManager.isLoadingPrevChildren;
58+
public readonly isLoadingNextChildren = this._treeItemChildrenManager.isLoadingNextChildren;
5959

6060
#treeItemExpansionManager = new UmbTreeItemTargetExpansionManager<TreeItemType, TreeRootType>(this, {
61-
childrenManager: this.#treeItemChildrenManager,
61+
childrenManager: this._treeItemChildrenManager,
6262
targetPaginationManager: this.targetPagination,
6363
});
6464
isOpen = this.#treeItemExpansionManager.isExpanded;
@@ -76,7 +76,7 @@ export abstract class UmbTreeItemContextBase<
7676
constructor(host: UmbControllerHost) {
7777
super(host, UMB_TREE_ITEM_CONTEXT);
7878
// TODO: Get take size from Tree context
79-
this.#treeItemChildrenManager.setTakeSize(50);
79+
this._treeItemChildrenManager.setTakeSize(50);
8080
this.#consumeContexts();
8181
window.addEventListener('navigationend', this.#debouncedCheckIsActive);
8282
}
@@ -131,7 +131,7 @@ export abstract class UmbTreeItemContextBase<
131131
if (!treeItem.entityType) throw new Error('Could not create tree item context, tree item type is missing');
132132
this.entityType = treeItem.entityType;
133133

134-
this.#treeItemChildrenManager.setTreeItem(treeItem);
134+
this._treeItemChildrenManager.setTreeItem(treeItem);
135135
this.#treeItemExpansionManager.setTreeItem(treeItem);
136136
this.#treeItemEntityActionManager.setTreeItem(treeItem);
137137

@@ -155,31 +155,31 @@ export abstract class UmbTreeItemContextBase<
155155
* @memberof UmbTreeItemContextBase
156156
* @returns {Promise<void>}
157157
*/
158-
public loadChildren = (): Promise<void> => this.#treeItemChildrenManager.loadChildren();
158+
public loadChildren = (): Promise<void> => this._treeItemChildrenManager.loadChildren();
159159

160-
public reloadChildren = (): Promise<void> => this.#treeItemChildrenManager.reloadChildren();
160+
public reloadChildren = (): Promise<void> => this._treeItemChildrenManager.reloadChildren();
161161

162162
/**
163163
* Load more children of the tree item
164164
* @deprecated Use `loadNextItems` instead. Will be removed in v18.0.0.
165165
* @memberof UmbTreeItemContextBase
166166
* @returns {Promise<void>}
167167
*/
168-
public loadMore = (): Promise<void> => this.#treeItemChildrenManager.loadNextChildren();
168+
public loadMore = (): Promise<void> => this._treeItemChildrenManager.loadNextChildren();
169169

170170
/**
171171
* Load previous items of the tree item
172172
* @memberof UmbTreeItemContextBase
173173
* @returns {Promise<void>}
174174
*/
175-
public loadPrevItems = (): Promise<void> => this.#treeItemChildrenManager.loadPrevChildren();
175+
public loadPrevItems = (): Promise<void> => this._treeItemChildrenManager.loadPrevChildren();
176176

177177
/**
178178
* Load next items of the tree item
179179
* @memberof UmbTreeItemContextBase
180180
* @returns {Promise<void>}
181181
*/
182-
public loadNextItems = (): Promise<void> => this.#treeItemChildrenManager.loadNextChildren();
182+
public loadNextItems = (): Promise<void> => this._treeItemChildrenManager.loadNextChildren();
183183

184184
public toggleContextMenu() {
185185
if (!this.getTreeItem() || !this.entityType || this.unique === undefined) {
@@ -302,7 +302,7 @@ export abstract class UmbTreeItemContextBase<
302302
this.observe(
303303
this.treeContext?.foldersOnly,
304304
(foldersOnly) => {
305-
this.#treeItemChildrenManager.setFoldersOnly(foldersOnly ?? false);
305+
this._treeItemChildrenManager.setFoldersOnly(foldersOnly ?? false);
306306
},
307307
'observeFoldersOnly',
308308
);

src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-children.manager.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export class UmbTreeItemChildrenManager<
6060
public readonly isLoadingNextChildren = this.#isLoadingNextChildren.asObservable();
6161

6262
#takeSize: number = 50;
63+
#takeBeforeTarget?: number;
64+
#takeAfterTarget?: number;
65+
6366
#actionEventContext?: typeof UMB_ACTION_EVENT_CONTEXT.TYPE;
6467

6568
#treeContext?: typeof UMB_TREE_CONTEXT.TYPE;
@@ -88,6 +91,11 @@ export class UmbTreeItemChildrenManager<
8891
this.targetPagination.setTakeSize(size);
8992
}
9093

94+
public setTargetTakeSize(before: number | undefined, after: number | undefined): void {
95+
this.#takeBeforeTarget = before;
96+
this.#takeAfterTarget = after;
97+
}
98+
9199
public getTakeSize(): number {
92100
return this.#takeSize;
93101
}
@@ -232,10 +240,16 @@ export class UmbTreeItemChildrenManager<
232240
Currently we use 5, but this could be anything that feels "right".
233241
When reloading from target when want to retrieve the same number of items that a currently loaded
234242
*/
235-
takeBefore: reload ? this.targetPagination.getNumberOfCurrentItemsBeforeBaseTarget() : 5,
243+
takeBefore: reload
244+
? this.targetPagination.getNumberOfCurrentItemsBeforeBaseTarget()
245+
: this.#takeBeforeTarget !== undefined
246+
? this.#takeBeforeTarget
247+
: 5,
236248
takeAfter: reload
237249
? this.targetPagination.getNumberOfCurrentItemsAfterBaseTarget()
238-
: this.targetPagination.getTakeSize(),
250+
: this.#takeAfterTarget !== undefined
251+
? this.#takeAfterTarget
252+
: this.targetPagination.getTakeSize(),
239253
}
240254
: undefined;
241255

@@ -277,8 +291,8 @@ export class UmbTreeItemChildrenManager<
277291
this.targetPagination.setBaseTarget(newBaseTarget);
278292
this.#loadChildren();
279293
} else {
280-
/*
281-
If we can't find a new base target we reload the children from the top.
294+
/*
295+
If we can't find a new base target we reload the children from the top.
282296
We cancel the base target and load using skip/take pagination instead.
283297
This can happen if deep linked to a non existing item or all retries have failed.
284298
*/
@@ -354,8 +368,8 @@ export class UmbTreeItemChildrenManager<
354368
if (newStartTarget) {
355369
this.#loadPrevItemsFromTarget();
356370
} else {
357-
/*
358-
If we can't find a new end target we reload the children from the top.
371+
/*
372+
If we can't find a new end target we reload the children from the top.
359373
We cancel the base target and load using skip/take pagination instead.
360374
*/
361375
this.#resetChildren();
@@ -443,8 +457,8 @@ export class UmbTreeItemChildrenManager<
443457
if (newEndTarget) {
444458
this.#loadNextItemsFromTarget();
445459
} else {
446-
/*
447-
If we can't find a new end target we reload the children from the top.
460+
/*
461+
If we can't find a new end target we reload the children from the top.
448462
We cancel the base target and load using skip/take pagination instead.
449463
*/
450464
this.#resetChildren();

src/Umbraco.Web.UI.Client/src/packages/documents/documents/tree/tree-item/document-tree-item.context.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ export class UmbDocumentTreeItemContext extends UmbDefaultTreeItemContext<
3232
#asMenu = false;
3333
setAsMenu(value: boolean) {
3434
this.#asMenu = value;
35+
if (this.#asMenu) {
36+
this.observe(
37+
this.hasCollection,
38+
(hasCollection) => {
39+
if (hasCollection) {
40+
this._treeItemChildrenManager.setTargetTakeSize(2, 2);
41+
}
42+
},
43+
'_whenMenuObserveHasCollection',
44+
);
45+
}
3546
}
3647
getAsMenu(): boolean {
3748
return this.#asMenu;

0 commit comments

Comments
 (0)