Skip to content

Commit c0416c9

Browse files
committed
observable for isTrashed
1 parent 1bfa5fd commit c0416c9

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/packages/core/tree/tree-item/tree-item-base/tree-item-context-base.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { UMB_SECTION_CONTEXT, UMB_SECTION_SIDEBAR_CONTEXT } from '@umbraco-cms/b
77
import type { UmbSectionContext, UmbSectionSidebarContext } from '@umbraco-cms/backoffice/section';
88
import type { ManifestTreeItem } from '@umbraco-cms/backoffice/extension-registry';
99
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
10-
import { UmbArrayState, UmbBooleanState, UmbDeepState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
10+
import { UmbArrayState, UmbBooleanState, UmbObjectState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
1111
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
1212
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
1313
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
@@ -31,37 +31,37 @@ export abstract class UmbTreeItemContextBase<TreeItemType extends UmbTreeItemMod
3131

3232
#manifest?: ManifestTreeItem;
3333

34-
#treeItem = new UmbDeepState<TreeItemType | undefined>(undefined);
35-
treeItem = this.#treeItem.asObservable();
34+
protected readonly _treeItem = new UmbObjectState<TreeItemType | undefined>(undefined);
35+
readonly treeItem = this._treeItem.asObservable();
3636

3737
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3838
// @ts-ignore
3939
#childItems = new UmbArrayState<TreeItemType>([], (x) => x.unique);
40-
childItems = this.#childItems.asObservable();
40+
readonly childItems = this.#childItems.asObservable();
4141

4242
#hasChildren = new UmbBooleanState(false);
43-
hasChildren = this.#hasChildren.asObservable();
43+
readonly hasChildren = this.#hasChildren.asObservable();
4444

4545
#isLoading = new UmbBooleanState(false);
46-
isLoading = this.#isLoading.asObservable();
46+
readonly isLoading = this.#isLoading.asObservable();
4747

4848
#isSelectable = new UmbBooleanState(false);
49-
isSelectable = this.#isSelectable.asObservable();
49+
readonly isSelectable = this.#isSelectable.asObservable();
5050

5151
#isSelectableContext = new UmbBooleanState(false);
52-
isSelectableContext = this.#isSelectableContext.asObservable();
52+
readonly isSelectableContext = this.#isSelectableContext.asObservable();
5353

5454
#isSelected = new UmbBooleanState(false);
55-
isSelected = this.#isSelected.asObservable();
55+
readonly isSelected = this.#isSelected.asObservable();
5656

5757
#isActive = new UmbBooleanState(false);
58-
isActive = this.#isActive.asObservable();
58+
readonly isActive = this.#isActive.asObservable();
5959

6060
#hasActions = new UmbBooleanState(false);
61-
hasActions = this.#hasActions.asObservable();
61+
readonly hasActions = this.#hasActions.asObservable();
6262

6363
#path = new UmbStringState('');
64-
path = this.#path.asObservable();
64+
readonly path = this.#path.asObservable();
6565

6666
treeContext?: UmbDefaultTreeContext<TreeItemType>;
6767
#sectionContext?: UmbSectionContext;
@@ -130,7 +130,7 @@ export abstract class UmbTreeItemContextBase<TreeItemType extends UmbTreeItemMod
130130

131131
public setTreeItem(treeItem: TreeItemType | undefined) {
132132
if (!treeItem) {
133-
this.#treeItem.setValue(undefined);
133+
this._treeItem.setValue(undefined);
134134
return;
135135
}
136136

@@ -143,7 +143,7 @@ export abstract class UmbTreeItemContextBase<TreeItemType extends UmbTreeItemMod
143143
this.entityType = treeItem.entityType;
144144

145145
this.#hasChildren.setValue(treeItem.hasChildren || false);
146-
this.#treeItem.setValue(treeItem);
146+
this._treeItem.setValue(treeItem);
147147

148148
// Update observers:
149149
this.#observeActions();
@@ -239,7 +239,7 @@ export abstract class UmbTreeItemContextBase<TreeItemType extends UmbTreeItemMod
239239
}
240240

241241
getTreeItem() {
242-
return this.#treeItem.getValue();
242+
return this._treeItem.getValue();
243243
}
244244

245245
#observeIsSelectable() {

src/packages/documents/documents/tree/tree-item/document-tree-item.context.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ export class UmbDocumentTreeItemContext extends UmbDefaultTreeItemContext<UmbDoc
77
// TODO: Provide this together with the EntityContext, ideally this takes part via a extension-type [NL]
88
#isTrashedContext = new UmbIsTrashedEntityContext(this);
99

10+
readonly isTrashed = this._treeItem.asObservablePart((item) => item?.isTrashed ?? false);
11+
1012
constructor(host: UmbControllerHost) {
1113
super(host);
1214

13-
this.observe(this.treeItem, (item) => {
14-
this.#isTrashedContext.setIsTrashed(item?.isTrashed || false);
15+
this.observe(this.isTrashed, (isTrashed) => {
16+
this.#isTrashedContext.setIsTrashed(isTrashed);
1517
});
1618
}
1719
}

0 commit comments

Comments
 (0)