From ff3e10e178de0c4e2ace15a96b8a8039e3d3ae42 Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Wed, 15 Feb 2023 19:24:54 +1000 Subject: [PATCH] fixes registration of data types repository (#521) * fixes registration of data types repository removes old tree * fix for pr-first-response? * that was pointless - first run won't run again * add repository to extensions registry --------- Co-authored-by: Mads Rasmussen --- .../src/backoffice/backoffice.element.ts | 2 +- .../settings/data-types/manifests.ts | 3 +- .../data-types/repository/manifests.ts | 13 +++ .../data-types/tree/data-type.tree.store.ts | 91 ------------------- .../settings/data-types/tree/manifests.ts | 4 +- 5 files changed, 18 insertions(+), 95 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/repository/manifests.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/tree/data-type.tree.store.ts diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/backoffice.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/backoffice.element.ts index 120db8ddc7..36ba5c54f1 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/backoffice.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/backoffice.element.ts @@ -34,7 +34,7 @@ import { UmbDictionaryTreeStore } from './translation/dictionary/repository/dict import { UmbDocumentBlueprintDetailStore } from './documents/document-blueprints/document-blueprint.detail.store'; import { UmbDocumentBlueprintTreeStore } from './documents/document-blueprints/document-blueprint.tree.store'; import { UmbDataTypeStore } from './settings/data-types/repository/data-type.store'; -import { UmbDataTypeTreeStore } from './settings/data-types/tree/data-type.tree.store'; +import { UmbDataTypeTreeStore } from './settings/data-types/repository/data-type.tree.store'; import { UmbTemplateTreeStore } from './templating/templates/tree/data/template.tree.store'; import { UmbTemplateDetailStore } from './templating/templates/workspace/data/template.detail.store'; import { UmbThemeContext } from './themes/theme.context'; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/manifests.ts index a4edc8b4f1..50f50fc98b 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/manifests.ts @@ -1,5 +1,6 @@ import { manifests as sidebarMenuItemManifests } from './sidebar-menu-item/manifests'; import { manifests as treeManifests } from './tree/manifests'; import { manifests as workspaceManifests } from './workspace/manifests'; +import { manifests as repositoryManifests } from './repository/manifests'; -export const manifests = [...sidebarMenuItemManifests, ...treeManifests, ...workspaceManifests]; +export const manifests = [...sidebarMenuItemManifests, ...treeManifests, ...repositoryManifests, ...workspaceManifests]; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/repository/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/repository/manifests.ts new file mode 100644 index 0000000000..269c3db99d --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/repository/manifests.ts @@ -0,0 +1,13 @@ +import { UmbDataTypeRepository } from './data-type.repository'; +import { ManifestRepository } from 'libs/extensions-registry/repository.models'; + +export const DATA_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.DataTypes'; + +const repository: ManifestRepository = { + type: 'repository', + alias: DATA_TYPE_REPOSITORY_ALIAS, + name: 'Data Types Repository', + class: UmbDataTypeRepository, +}; + +export const manifests = [repository]; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/tree/data-type.tree.store.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/tree/data-type.tree.store.ts deleted file mode 100644 index 9ba41cf9d0..0000000000 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/tree/data-type.tree.store.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { DataTypeResource, DocumentTreeItemModel } from '@umbraco-cms/backend-api'; -import { tryExecuteAndNotify } from '@umbraco-cms/resources'; -import { UmbContextToken } from '@umbraco-cms/context-api'; -import { ArrayState } from '@umbraco-cms/observable-api'; -import { UmbStoreBase } from '@umbraco-cms/store'; -import { UmbControllerHostInterface } from '@umbraco-cms/controller'; - -export const UMB_DATA_TYPE_TREE_STORE_CONTEXT_TOKEN = new UmbContextToken('UmbDataTypeTreeStore'); - -/** - * @export - * @class UmbDataTypeTreeStore - * @extends {UmbStoreBase} - * @description - Tree Data Store for Data Types - */ -export class UmbDataTypeTreeStore extends UmbStoreBase { - #data = new ArrayState([], (x) => x.key); - - constructor(host: UmbControllerHostInterface) { - super(host, UMB_DATA_TYPE_TREE_STORE_CONTEXT_TOKEN.toString()); - } - - // TODO: How can we avoid having this in both stores? - /** - * @description - Delete a Data Type. - * @param {string[]} keys - * @memberof UmbDataTypesStore - * @return {*} {Promise} - */ - async delete(keys: string[]) { - // TODO: use backend cli when available. - await fetch('/umbraco/backoffice/data-type/delete', { - method: 'POST', - body: JSON.stringify(keys), - headers: { - 'Content-Type': 'application/json', - }, - }); - - this.#data.remove(keys); - } - - getTreeRoot() { - tryExecuteAndNotify(this._host, DataTypeResource.getTreeDataTypeRoot({})).then(({ data }) => { - if (data) { - // TODO: how do we handle if an item has been removed during this session(like in another tab or by another user)? - this.#data.append(data.items); - } - }); - - // TODO: how do we handle trashed items? - // TODO: remove ignore when we know how to handle trashed items. - return this.#data.getObservablePart((items) => items.filter((item) => item.parentKey === null && !item.isTrashed)); - } - - getTreeItemChildren(key: string) { - tryExecuteAndNotify( - this._host, - DataTypeResource.getTreeDataTypeChildren({ - parentKey: key, - }) - ).then(({ data }) => { - if (data) { - // TODO: how do we handle if an item has been removed during this session(like in another tab or by another user)? - this.#data.append(data.items); - } - }); - - // TODO: how do we handle trashed items? - // TODO: remove ignore when we know how to handle trashed items. - return this.#data.getObservablePart((items) => items.filter((item) => item.parentKey === key && !item.isTrashed)); - } - - getTreeItems(keys: Array) { - if (keys?.length > 0) { - tryExecuteAndNotify( - this._host, - DataTypeResource.getTreeDataTypeItem({ - key: keys, - }) - ).then(({ data }) => { - if (data) { - // TODO: how do we handle if an item has been removed during this session(like in another tab or by another user)? - this.#data.append(data); - } - }); - } - - return this.#data.getObservablePart((items) => items.filter((item) => keys.includes(item.key ?? ''))); - } -} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/tree/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/tree/manifests.ts index d4467cddb1..f3a81ccab9 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/tree/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/tree/manifests.ts @@ -1,4 +1,4 @@ -import { UMB_DATA_TYPE_TREE_STORE_CONTEXT_TOKEN } from './data-type.tree.store'; +import { UmbDataTypeRepository } from '../repository/data-type.repository'; import type { ManifestTree, ManifestTreeItemAction } from '@umbraco-cms/models'; const tree: ManifestTree = { @@ -6,7 +6,7 @@ const tree: ManifestTree = { alias: 'Umb.Tree.DataTypes', name: 'Data Types Tree', meta: { - storeAlias: UMB_DATA_TYPE_TREE_STORE_CONTEXT_TOKEN.toString(), + repository: UmbDataTypeRepository, }, };