register member stores
This commit is contained in:
@@ -15,8 +15,6 @@ import {
|
||||
UmbBackofficeContext,
|
||||
UMB_BACKOFFICE_CONTEXT_TOKEN,
|
||||
} from './shared/components/backoffice-frame/backoffice.context';
|
||||
import { UmbMemberDetailStore } from './members/members/member.detail.store';
|
||||
import { UmbMemberTreeStore } from './members/members/repository/member.tree.store';
|
||||
import { UmbDictionaryDetailStore } from './translation/dictionary/repository/dictionary.detail.store';
|
||||
import { UmbDictionaryTreeStore } from './translation/dictionary/repository/dictionary.tree.store';
|
||||
import { UmbDocumentBlueprintDetailStore } from './documents/document-blueprints/document-blueprint.detail.store';
|
||||
@@ -81,8 +79,6 @@ export class UmbBackofficeElement extends UmbLitElement {
|
||||
new UmbDataTypeTreeStore(this);
|
||||
new UmbUserStore(this);
|
||||
new UmbUserGroupStore(this);
|
||||
new UmbMemberDetailStore(this);
|
||||
new UmbMemberTreeStore(this);
|
||||
new UmbDictionaryDetailStore(this);
|
||||
new UmbDictionaryTreeStore(this);
|
||||
new UmbDocumentBlueprintDetailStore(this);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { UmbMemberRepository } from './member.repository';
|
||||
import { UmbMemberStore } from './member.store';
|
||||
import { UmbMemberTreeStore } from './member.tree.store';
|
||||
import { ManifestRepository } from 'libs/extensions-registry/repository.models';
|
||||
import { ManifestStore, ManifestTreeStore } from '@umbraco-cms/extensions-registry';
|
||||
|
||||
export const MEMBER_REPOSITORY_ALIAS = 'Umb.Repository.Member';
|
||||
|
||||
@@ -10,4 +13,21 @@ const repository: ManifestRepository = {
|
||||
class: UmbMemberRepository,
|
||||
};
|
||||
|
||||
export const manifests = [repository];
|
||||
export const MEMBER_STORE_ALIAS = 'Umb.Store.Member';
|
||||
export const MEMBER_TREE_STORE_ALIAS = 'Umb.Store.MemberTree';
|
||||
|
||||
const store: ManifestStore = {
|
||||
type: 'store',
|
||||
alias: MEMBER_STORE_ALIAS,
|
||||
name: 'Member Store',
|
||||
class: UmbMemberStore,
|
||||
};
|
||||
|
||||
const treeStore: ManifestTreeStore = {
|
||||
type: 'treeStore',
|
||||
alias: MEMBER_TREE_STORE_ALIAS,
|
||||
name: 'Member Tree Store',
|
||||
class: UmbMemberTreeStore,
|
||||
};
|
||||
|
||||
export const manifests = [store, treeStore, repository];
|
||||
|
||||
@@ -73,7 +73,7 @@ export class UmbMemberRepository implements UmbTreeRepository {
|
||||
|
||||
async rootTreeItems() {
|
||||
await this.#init;
|
||||
return this.#treeStore!.rootItems();
|
||||
return this.#treeStore!.rootItems;
|
||||
}
|
||||
|
||||
async treeItemsOf(parentKey: string | null) {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { UmbContextToken } from '@umbraco-cms/context-api';
|
||||
import { UmbStoreBase } from '@umbraco-cms/store';
|
||||
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
import { ArrayState } from '@umbraco-cms/observable-api';
|
||||
import type { MemberDetails } from '@umbraco-cms/models';
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @class UmbMemberStore
|
||||
* @extends {UmbStoreBase}
|
||||
* @description - Data Store for Members
|
||||
*/
|
||||
export class UmbMemberStore extends UmbStoreBase {
|
||||
#data = new ArrayState<MemberDetails>([], (x) => x.key);
|
||||
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
super(host, UmbMemberStore.name);
|
||||
}
|
||||
|
||||
append(member: MemberDetails) {
|
||||
this.#data.append([member]);
|
||||
}
|
||||
|
||||
remove(uniques: string[]) {
|
||||
this.#data.remove(uniques);
|
||||
}
|
||||
}
|
||||
|
||||
export const UMB_MEMBER_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbMemberStore>(UmbMemberStore.name);
|
||||
@@ -1,18 +1,14 @@
|
||||
import type { EntityTreeItemModel } from '@umbraco-cms/backend-api';
|
||||
import { UmbContextToken } from '@umbraco-cms/context-api';
|
||||
import { ArrayState } from '@umbraco-cms/observable-api';
|
||||
import { UmbStoreBase } from '@umbraco-cms/store';
|
||||
import { UmbTreeStoreBase } from '@umbraco-cms/store';
|
||||
import type { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @class UmbMemberTreeStore
|
||||
* @extends {UmbStoreBase}
|
||||
* @extends {UmbTreeStoreBase}
|
||||
* @description - Tree Data Store for Members
|
||||
*/
|
||||
export class UmbMemberTreeStore extends UmbStoreBase {
|
||||
#data = new ArrayState<EntityTreeItemModel>([], (x) => x.key);
|
||||
|
||||
export class UmbMemberTreeStore extends UmbTreeStoreBase {
|
||||
/**
|
||||
* Creates an instance of UmbTemplateTreeStore.
|
||||
* @param {UmbControllerHostInterface} host
|
||||
@@ -21,73 +17,6 @@ export class UmbMemberTreeStore extends UmbStoreBase {
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
super(host, UMB_MEMBER_TREE_STORE_CONTEXT_TOKEN.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends items to the store
|
||||
* @param {Array<EntityTreeItem>} items
|
||||
* @memberof UmbTemplateTreeStore
|
||||
*/
|
||||
appendItems(items: Array<EntityTreeItemModel>) {
|
||||
this.#data.append(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an item in the store
|
||||
* @param {string} key
|
||||
* @param {Partial<EntityTreeItem>} data
|
||||
* @memberof UmbMemberGroupTreeStore
|
||||
*/
|
||||
updateItem(key: string, data: Partial<EntityTreeItemModel>) {
|
||||
const entries = this.#data.getValue();
|
||||
const entry = entries.find((entry) => entry.key === key);
|
||||
|
||||
if (entry) {
|
||||
this.#data.appendOne({ ...entry, ...data });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an item from the store
|
||||
* @param {string} key
|
||||
* @memberof UmbMemberGroupTreeStore
|
||||
*/
|
||||
removeItem(key: string) {
|
||||
const entries = this.#data.getValue();
|
||||
const entry = entries.find((entry) => entry.key === key);
|
||||
|
||||
if (entry) {
|
||||
this.#data.remove([key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an observable to observe the root items
|
||||
* @return {*}
|
||||
* @memberof UmbMemberGroupTreeStore
|
||||
*/
|
||||
rootItems() {
|
||||
return this.#data.getObservablePart((items) => items.filter((item) => item.parentKey === null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an observable to observe the children of a given parent
|
||||
* @param {(string | null)} parentKey
|
||||
* @return {*}
|
||||
* @memberof UmbMemberGroupTreeStore
|
||||
*/
|
||||
childrenOf(parentKey: string | null) {
|
||||
return this.#data.getObservablePart((items) => items.filter((item) => item.parentKey === parentKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an observable to observe the items with the given keys
|
||||
* @param {Array<string>} keys
|
||||
* @return {*}
|
||||
* @memberof UmbMemberGroupTreeStore
|
||||
*/
|
||||
items(keys: Array<string>) {
|
||||
return this.#data.getObservablePart((items) => items.filter((item) => keys.includes(item.key ?? '')));
|
||||
}
|
||||
}
|
||||
|
||||
export const UMB_MEMBER_TREE_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbMemberTreeStore>(UmbMemberTreeStore.name);
|
||||
|
||||
Reference in New Issue
Block a user