Merge pull request #878 from umbraco/feature/delete-doc-type
This commit is contained in:
@@ -18,7 +18,7 @@ const entityActions: Array<ManifestEntityAction> = [
|
||||
weight: 900,
|
||||
meta: {
|
||||
icon: 'umb:trash',
|
||||
label: 'Delete (TBD)',
|
||||
label: 'Delete',
|
||||
repositoryAlias: DOCUMENT_TYPE_REPOSITORY_ALIAS,
|
||||
api: UmbDeleteEntityAction,
|
||||
entityTypes: [entityType],
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { DocumentTypeItemResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbItemStore, UmbStoreBase } from '@umbraco-cms/backoffice/store';
|
||||
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @class UmbDocumentTypeItemStore
|
||||
* @extends {UmbStoreBase}
|
||||
* @description - Data Store for Document Type items
|
||||
*/
|
||||
|
||||
export class UmbDocumentTypeItemStore
|
||||
extends UmbStoreBase<DocumentTypeItemResponseModel>
|
||||
implements UmbItemStore<DocumentTypeItemResponseModel>
|
||||
{
|
||||
/**
|
||||
* Creates an instance of UmbDocumentTypeItemStore.
|
||||
* @param {UmbControllerHostElement} host
|
||||
* @memberof UmbDocumentTypeItemStore
|
||||
*/
|
||||
constructor(host: UmbControllerHostElement) {
|
||||
super(
|
||||
host,
|
||||
UMB_DOCUMENT_TYPE_ITEM_STORE_CONTEXT_TOKEN.toString(),
|
||||
new UmbArrayState<DocumentTypeItemResponseModel>([], (x) => x.id),
|
||||
);
|
||||
}
|
||||
|
||||
items(ids: Array<string>) {
|
||||
return this._data.asObservablePart((items) => items.filter((item) => ids.includes(item.id ?? '')));
|
||||
}
|
||||
}
|
||||
|
||||
export const UMB_DOCUMENT_TYPE_ITEM_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbDocumentTypeItemStore>(
|
||||
'UmbDocumentTypeItemStore',
|
||||
);
|
||||
@@ -2,6 +2,8 @@ import { UmbDocumentTypeTreeServerDataSource } from './sources/document-type.tre
|
||||
import { UmbDocumentTypeServerDataSource } from './sources/document-type.server.data.js';
|
||||
import { UmbDocumentTypeTreeStore, UMB_DOCUMENT_TYPE_TREE_STORE_CONTEXT_TOKEN } from './document-type.tree.store.js';
|
||||
import { UmbDocumentTypeStore, UMB_DOCUMENT_TYPE_STORE_CONTEXT_TOKEN } from './document-type.store.js';
|
||||
import { UMB_DOCUMENT_TYPE_ITEM_STORE_CONTEXT_TOKEN, UmbDocumentTypeItemStore } from './document-type-item.store.js';
|
||||
import { UmbDocumentTypeItemServerDataSource } from './sources/document-type-item.server.data.js';
|
||||
import type { UmbTreeDataSource, UmbTreeRepository, UmbDetailRepository } from '@umbraco-cms/backoffice/repository';
|
||||
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
|
||||
@@ -31,6 +33,9 @@ export class UmbDocumentTypeRepository
|
||||
#detailDataSource: UmbDocumentTypeServerDataSource;
|
||||
#detailStore?: UmbDocumentTypeStore;
|
||||
|
||||
#itemSource: UmbDocumentTypeItemServerDataSource;
|
||||
#itemStore?: UmbDocumentTypeItemStore;
|
||||
|
||||
#notificationContext?: UmbNotificationContext;
|
||||
|
||||
constructor(host: UmbControllerHostElement) {
|
||||
@@ -39,6 +44,7 @@ export class UmbDocumentTypeRepository
|
||||
// TODO: figure out how spin up get the correct data source
|
||||
this.#treeSource = new UmbDocumentTypeTreeServerDataSource(this.#host);
|
||||
this.#detailDataSource = new UmbDocumentTypeServerDataSource(this.#host);
|
||||
this.#itemSource = new UmbDocumentTypeItemServerDataSource(this.#host);
|
||||
|
||||
this.#init = Promise.all([
|
||||
new UmbContextConsumerController(this.#host, UMB_DOCUMENT_TYPE_TREE_STORE_CONTEXT_TOKEN, (instance) => {
|
||||
@@ -49,15 +55,17 @@ export class UmbDocumentTypeRepository
|
||||
this.#detailStore = instance;
|
||||
}),
|
||||
|
||||
new UmbContextConsumerController(this.#host, UMB_DOCUMENT_TYPE_ITEM_STORE_CONTEXT_TOKEN, (instance) => {
|
||||
this.#itemStore = instance;
|
||||
}),
|
||||
|
||||
new UmbContextConsumerController(this.#host, UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
||||
this.#notificationContext = instance;
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
// TODO: Trash
|
||||
// TODO: Move
|
||||
|
||||
async requestTreeRoot() {
|
||||
await this.#init;
|
||||
|
||||
@@ -97,6 +105,19 @@ export class UmbDocumentTypeRepository
|
||||
return { data, error, asObservable: () => this.#treeStore!.childrenOf(parentId) };
|
||||
}
|
||||
|
||||
async requestItems(ids: Array<string>) {
|
||||
if (!ids) throw new Error('Document Type Ids are missing');
|
||||
await this.#init;
|
||||
|
||||
const { data, error } = await this.#itemSource.getItems(ids);
|
||||
|
||||
if (data) {
|
||||
this.#itemStore?.appendItems(data);
|
||||
}
|
||||
|
||||
return { data, error, asObservable: () => this.#itemStore!.items(ids) };
|
||||
}
|
||||
|
||||
async requestItemsLegacy(ids: Array<string>) {
|
||||
await this.#init;
|
||||
|
||||
@@ -226,7 +247,6 @@ export class UmbDocumentTypeRepository
|
||||
}
|
||||
|
||||
// General:
|
||||
|
||||
async delete(id: string) {
|
||||
if (!id) throw new Error('Document Type id is missing');
|
||||
await this.#init;
|
||||
@@ -240,9 +260,10 @@ export class UmbDocumentTypeRepository
|
||||
// TODO: we currently don't use the detail store for anything.
|
||||
// Consider to look up the data before fetching from the server.
|
||||
// Consider notify a workspace if a template is deleted from the store while someone is editing it.
|
||||
// TODO: would be nice to align the stores on methods/methodNames.
|
||||
this.#detailStore?.remove([id]);
|
||||
this.#treeStore?.removeItem(id);
|
||||
// TODO: would be nice to align the stores on methods/methodNames.
|
||||
this.#itemStore?.removeItem(id);
|
||||
}
|
||||
|
||||
return { error };
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './document-type.repository.js'
|
||||
export * from './document-type.store.js'
|
||||
export * from './document-type.tree.store.js'
|
||||
export * from './document-type.repository.js';
|
||||
export * from './document-type.store.js';
|
||||
export * from './document-type.tree.store.js';
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { UmbDocumentTypeItemStore } from './document-type-item.store.js';
|
||||
import { UmbDocumentTypeRepository } from './document-type.repository.js';
|
||||
import { UmbDocumentTypeStore } from './document-type.store.js';
|
||||
import { UmbDocumentTypeTreeStore } from './document-type.tree.store.js';
|
||||
import { ManifestRepository, ManifestStore, ManifestTreeStore } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import {
|
||||
ManifestItemStore,
|
||||
ManifestRepository,
|
||||
ManifestStore,
|
||||
ManifestTreeStore,
|
||||
} from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const DOCUMENT_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.DocumentType';
|
||||
|
||||
@@ -14,6 +20,7 @@ const repository: ManifestRepository = {
|
||||
|
||||
export const DOCUMENT_TYPE_STORE_ALIAS = 'Umb.Store.DocumentType';
|
||||
export const DOCUMENT_TYPE_TREE_STORE_ALIAS = 'Umb.Store.DocumentTypeTree';
|
||||
export const DOCUMENT_TYPE_ITEM_STORE_ALIAS = 'Umb.Store.DocumentTypeItem';
|
||||
|
||||
const store: ManifestStore = {
|
||||
type: 'store',
|
||||
@@ -29,4 +36,11 @@ const treeStore: ManifestTreeStore = {
|
||||
class: UmbDocumentTypeTreeStore,
|
||||
};
|
||||
|
||||
export const manifests = [repository, store, treeStore];
|
||||
const itemStore: ManifestItemStore = {
|
||||
type: 'itemStore',
|
||||
alias: DOCUMENT_TYPE_ITEM_STORE_ALIAS,
|
||||
name: 'Document Type Item Store',
|
||||
class: UmbDocumentTypeItemStore,
|
||||
};
|
||||
|
||||
export const manifests = [repository, store, treeStore, itemStore];
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { UmbItemDataSource } from '@umbraco-cms/backoffice/repository';
|
||||
import { DocumentTypeItemResponseModel, DocumentTypeResource } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
|
||||
/**
|
||||
* A data source for Document Type items that fetches data from the server
|
||||
* @export
|
||||
* @class UmbDocumentTypeItemServerDataSource
|
||||
* @implements {UmbItemDataSource}
|
||||
*/
|
||||
export class UmbDocumentTypeItemServerDataSource implements UmbItemDataSource<DocumentTypeItemResponseModel> {
|
||||
#host: UmbControllerHostElement;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbDocumentTypeItemServerDataSource.
|
||||
* @param {UmbControllerHostElement} host
|
||||
* @memberof UmbDocumentTypeItemServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHostElement) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the items for the given ids from the server
|
||||
* @param {Array<string>} ids
|
||||
* @return {*}
|
||||
* @memberof UmbDocumentTypeItemServerDataSource
|
||||
*/
|
||||
async getItems(ids: Array<string>) {
|
||||
if (!ids) throw new Error('Ids are missing');
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
DocumentTypeResource.getDocumentTypeItem({
|
||||
id: ids,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user