Skip to content

Commit

Permalink
Merge pull request #992 from umbraco/improvement-split-document-recyc…
Browse files Browse the repository at this point in the history
…le-bin-tree-repo

Improvement: Split document recycle bin tree into its own repo
  • Loading branch information
loivsen authored Nov 16, 2023
2 parents e20cec4 + 4cdb744 commit aff0162
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 125 deletions.
2 changes: 2 additions & 0 deletions src/packages/documents/documents/recycle-bin/entities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const UMB_DOCUMENT_RECYCLE_BIN_ROOT_ENTITY_TYPE = 'document-recycle-bin-root';
export const UMB_DOCUMENT_RECYCLE_BIN_ENTITY_TYPE = 'document-recycle-bin';
3 changes: 2 additions & 1 deletion src/packages/documents/documents/recycle-bin/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './repository/index.js';
export * from './tree/index.js';
export * from './entities.js';
3 changes: 1 addition & 2 deletions src/packages/documents/documents/recycle-bin/manifests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { manifests as repositoryManifests } from './repository/manifests.js';
import { manifests as treeManifests } from './tree/manifests.js';
import { manifests as menuItemManifests } from './menu-item/manifests.js';
import { manifests as entityActionManifests } from './entity-action/manifests.js';

export const manifests = [...repositoryManifests, ...treeManifests, ...menuItemManifests, ...entityActionManifests];
export const manifests = [...treeManifests, ...menuItemManifests, ...entityActionManifests];

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { UMB_DOCUMENT_RECYCLE_BIN_ROOT_ENTITY_TYPE } from '../entities.js';
import { UmbDocumentRecycleBinTreeServerDataSource } from './document-recycle-bin.server.data-source.js';
import { UmbDocumentRecycleBinTreeItemModel, UmbDocumentRecycleBinTreeRootModel } from './types.js';
import { UMB_DOCUMENT_RECYCLE_BIN_TREE_STORE_CONTEXT } from './document-recycle-bin-tree.store.js';
import { UmbTreeRepositoryBase } from '@umbraco-cms/backoffice/tree';
import { type UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbApi } from '@umbraco-cms/backoffice/extension-api';

export class UmbDocumentRecycleBinTreeRepository
extends UmbTreeRepositoryBase<UmbDocumentRecycleBinTreeItemModel, UmbDocumentRecycleBinTreeRootModel>
implements UmbApi
{
constructor(host: UmbControllerHost) {
super(host, UmbDocumentRecycleBinTreeServerDataSource, UMB_DOCUMENT_RECYCLE_BIN_TREE_STORE_CONTEXT);
}

async requestTreeRoot() {
const data = {
id: null,
type: UMB_DOCUMENT_RECYCLE_BIN_ROOT_ENTITY_TYPE,
name: 'Recycle Bin',
icon: 'icon-trash',
hasChildren: true,
};

return { data };
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UmbEntityTreeStore } from '@umbraco-cms/backoffice/tree';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbEntityTreeStore } from '@umbraco-cms/backoffice/tree';

/**
* @export
* @class UmbDocumentRecycleBinTreeStore
* @extends {UmbEntityTreeStore}
* @description - Tree Data Store for the Document Recycle Bin
* @extends {UmbStoreBase}
* @description - Tree Data Store for Document Recycle Bin Tree Items
*/
export class UmbDocumentRecycleBinTreeStore extends UmbEntityTreeStore {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type UmbTreeDataSource } from '@umbraco-cms/backoffice/tree';
import { DocumentResource } from '@umbraco-cms/backoffice/backend-api';
import { type UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type { UmbTreeDataSource } from '@umbraco-cms/backoffice/tree';
import { DocumentResource, RecycleBinItemResponseModel } from '@umbraco-cms/backoffice/backend-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';

/**
Expand All @@ -9,20 +9,21 @@ import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
* @class UmbDocumentRecycleBinTreeServerDataSource
* @implements {UmbTreeDataSource}
*/
export class UmbDocumentRecycleBinTreeServerDataSource implements UmbTreeDataSource {
export class UmbDocumentRecycleBinTreeServerDataSource implements UmbTreeDataSource<RecycleBinItemResponseModel> {
#host: UmbControllerHost;

/**
* Creates an instance of UmbDocumentRecycleBinTreeServerDataSource.
* @param {UmbControllerHost} host
* @memberof UmbDocumentTreeServerDataSource
* @memberof UmbDocumentRecycleBinTreeServerDataSource
*/
constructor(host: UmbControllerHost) {
this.#host = host;
}

/**
* Fetches the root items for the tree from the server
* @return {*}
* @memberof UmbDocumentRecycleBinTreeServerDataSource
*/
async getRootItems() {
Expand All @@ -31,8 +32,9 @@ export class UmbDocumentRecycleBinTreeServerDataSource implements UmbTreeDataSou

/**
* Fetches the children of a given parent id from the server
* @param {(string | null)} parentId
* @memberof UmbDocumentTreeServerDataSource
* @param {(string)} parentId
* @return {*}
* @memberof UmbDocumentRecycleBinTreeServerDataSource
*/
async getChildrenOf(parentId: string | null) {
if (parentId === undefined) throw new Error('Parent id is missing');
Expand Down
9 changes: 9 additions & 0 deletions src/packages/documents/documents/recycle-bin/tree/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export { UmbDocumentRecycleBinTreeRepository } from './document-recycle-bin-tree.repository.js';
export {
UMB_DOCUMENT_RECYCLE_BIN_TREE_REPOSITORY_ALIAS,
UMB_DOCUMENT_RECYCLE_BIN_TREE_STORE_ALIAS,
UMB_DOCUMENT_RECYCLE_BIN_TREE_ALIAS,
} from './manifests.js';
export { UMB_DOCUMENT_RECYCLE_BIN_TREE_STORE_CONTEXT } from './document-recycle-bin-tree.store.js';
export { type UmbDocumentRecycleBinTreeStore } from './document-recycle-bin-tree.store.js';
export * from './types.js';
39 changes: 32 additions & 7 deletions src/packages/documents/documents/recycle-bin/tree/manifests.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
import { DOCUMENT_RECYCLE_BIN_REPOSITORY_ALIAS } from '../repository/manifests.js';
import type { ManifestTree, ManifestTreeItem } from '@umbraco-cms/backoffice/extension-registry';
import { UMB_DOCUMENT_RECYCLE_BIN_ENTITY_TYPE, UMB_DOCUMENT_RECYCLE_BIN_ROOT_ENTITY_TYPE } from '../entities.js';
import { UmbDocumentRecycleBinTreeRepository } from './document-recycle-bin-tree.repository.js';
import { UmbDocumentRecycleBinTreeStore } from './document-recycle-bin-tree.store.js';
import type {
ManifestRepository,
ManifestTree,
ManifestTreeItem,
ManifestTreeStore,
} from '@umbraco-cms/backoffice/extension-registry';

export const UMB_DOCUMENT_RECYCLE_BIN_TREE_REPOSITORY_ALIAS = 'Umb.Repository.DocumentRecycleBin.Tree';
export const UMB_DOCUMENT_RECYCLE_BIN_TREE_STORE_ALIAS = 'Umb.Store.DocumentRecycleBin.Tree';
export const UMB_DOCUMENT_RECYCLE_BIN_TREE_ALIAS = 'Umb.Tree.DocumentRecycleBin';

const treeRepository: ManifestRepository = {
type: 'repository',
alias: UMB_DOCUMENT_RECYCLE_BIN_TREE_REPOSITORY_ALIAS,
name: 'Document Recycle Bin Tree Repository',
api: UmbDocumentRecycleBinTreeRepository,
};

const treeStore: ManifestTreeStore = {
type: 'treeStore',
alias: UMB_DOCUMENT_RECYCLE_BIN_TREE_STORE_ALIAS,
name: 'Document Recycle Bin Tree Store',
api: UmbDocumentRecycleBinTreeStore,
};

const tree: ManifestTree = {
type: 'tree',
alias: 'Umb.Tree.DocumentRecycleBin',
alias: UMB_DOCUMENT_RECYCLE_BIN_TREE_ALIAS,
name: 'Document Recycle Bin Tree',
meta: {
repositoryAlias: DOCUMENT_RECYCLE_BIN_REPOSITORY_ALIAS,
repositoryAlias: UMB_DOCUMENT_RECYCLE_BIN_TREE_REPOSITORY_ALIAS,
},
};

const treeItem: ManifestTreeItem = {
type: 'treeItem',
kind: 'entity',
alias: 'Umb.TreeItem.DocumentRecycleBin',
name: 'Document Recycle Bin Tree Item',
name: 'DocumentRecycleBin Tree Item',
meta: {
entityTypes: ['document-recycle-bin-root'],
entityTypes: [UMB_DOCUMENT_RECYCLE_BIN_ROOT_ENTITY_TYPE, UMB_DOCUMENT_RECYCLE_BIN_ENTITY_TYPE],
},
};

export const manifests = [tree, treeItem];
export const manifests = [treeRepository, treeStore, tree, treeItem];
5 changes: 5 additions & 0 deletions src/packages/documents/documents/recycle-bin/tree/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { RecycleBinItemResponseModel } from '@umbraco-cms/backoffice/backend-api';
import type { UmbEntityTreeItemModel, UmbEntityTreeRootModel } from '@umbraco-cms/backoffice/tree';

export type UmbDocumentRecycleBinTreeItemModel = RecycleBinItemResponseModel & UmbEntityTreeItemModel;
export type UmbDocumentRecycleBinTreeRootModel = RecycleBinItemResponseModel & UmbEntityTreeRootModel;

0 comments on commit aff0162

Please sign in to comment.