avoid using store in implementations
This commit is contained in:
@@ -10,8 +10,19 @@ export interface UmbDataStore {
|
||||
}
|
||||
|
||||
export interface UmbTreeStore<T> extends UmbDataStore {
|
||||
|
||||
getTreeRoot(): Observable<Array<T>>;
|
||||
|
||||
getTreeItemChildren(key: string): Observable<Array<T>>;
|
||||
|
||||
// Notice: this might not be right to put here as only some content items has ability to be trashed.
|
||||
/**
|
||||
* @description - Trash data.
|
||||
* @param {object} data
|
||||
* @return {*} {(Promise<void>)}
|
||||
* @memberof UmbContentStore
|
||||
*/
|
||||
trash(keys: string[]): Promise<void>;
|
||||
}
|
||||
|
||||
export interface UmbContentStore<T> extends UmbDataStore {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { DocumentResource, DocumentTreeItem } from '@umbraco-cms/backend-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/resources';
|
||||
import { UmbContextToken } from '@umbraco-cms/context-api';
|
||||
import { createObservablePart, ArrayState } from '@umbraco-cms/observable-api';
|
||||
import { UmbStoreBase } from '@umbraco-cms/store';
|
||||
import { UmbStoreBase, UmbTreeStore } from '@umbraco-cms/store';
|
||||
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export const UMB_DOCUMENT_TREE_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbDocu
|
||||
* @extends {UmbStoreBase}
|
||||
* @description - Data Store for Documents
|
||||
*/
|
||||
export class UmbDocumentTreeStore extends UmbStoreBase {
|
||||
export class UmbDocumentTreeStore extends UmbStoreBase implements UmbTreeStore<DocumentTreeItem> {
|
||||
|
||||
|
||||
private _data = new ArrayState<DocumentTreeItem>([], (x) => x.key);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { MediaResource, ContentTreeItem } from '@umbraco-cms/backend-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/resources';
|
||||
import { UmbContextToken } from '@umbraco-cms/context-api';
|
||||
import { createObservablePart, ArrayState } from '@umbraco-cms/observable-api';
|
||||
import { UmbStoreBase } from '@umbraco-cms/store';
|
||||
import { UmbStoreBase, UmbTreeStore } from '@umbraco-cms/store';
|
||||
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
|
||||
export const UMB_MEDIA_TREE_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbMediaTreeStore>('UmbMediaTreeStore');
|
||||
@@ -17,7 +17,8 @@ export type MediaTreeItem = ContentTreeItem;
|
||||
* @extends {UmbStoreBase}
|
||||
* @description - Data Store for Media
|
||||
*/
|
||||
export class UmbMediaTreeStore extends UmbStoreBase {
|
||||
export class UmbMediaTreeStore extends UmbStoreBase implements UmbTreeStore<MediaTreeItem> {
|
||||
|
||||
#data = new ArrayState<MediaTreeItem>([], (x) => x.key);
|
||||
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
|
||||
@@ -20,7 +20,6 @@ export class UmbCollectionBulkActionDeleteElement extends UmbLitElement {
|
||||
public manifest?: ManifestCollectionBulkAction;
|
||||
|
||||
#modalService?: UmbModalService;
|
||||
#mediaStore?: UmbMediaTreeStore;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -32,10 +31,6 @@ export class UmbCollectionBulkActionDeleteElement extends UmbLitElement {
|
||||
this.consumeContext(UMB_MODAL_SERVICE_CONTEXT_TOKEN, (instance) => {
|
||||
this.#modalService = instance;
|
||||
});
|
||||
|
||||
this.consumeContext(UMB_MEDIA_TREE_STORE_CONTEXT_TOKEN, (instance) => {
|
||||
this.#mediaStore = instance;
|
||||
});
|
||||
}
|
||||
|
||||
#handleClick(event: Event) {
|
||||
@@ -63,7 +58,7 @@ export class UmbCollectionBulkActionDeleteElement extends UmbLitElement {
|
||||
dataSubscription?.unsubscribe();
|
||||
|
||||
if (confirmed) {
|
||||
this.#mediaStore?.trash(selection);
|
||||
this.#collectionContext?.trash(selection);
|
||||
this.#collectionContext?.clearSelection();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -92,6 +92,11 @@ export class UmbCollectionContext<
|
||||
this.#selection.next(value);
|
||||
}
|
||||
|
||||
// TODO: Not all can trash, so maybe we need to differentiate on collection contexts or fix it with another architecture.
|
||||
public trash(keys:string[]) {
|
||||
this._store?.trash(keys);
|
||||
}
|
||||
|
||||
public clearSelection() {
|
||||
this.#selection.next([]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user