Skip to content

Commit

Permalink
Merge pull request #983 from umbraco/improvement-data-type-repo-split
Browse files Browse the repository at this point in the history
Improvement: Data Type Repository split
  • Loading branch information
madsrasmussen committed Nov 14, 2023
2 parents 34509c5 + c19cf92 commit 52e41be
Show file tree
Hide file tree
Showing 82 changed files with 718 additions and 585 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"./member-group": "./dist-cms/packages/members/member-groups/index.js",
"./member-type": "./dist-cms/packages/members/member-types/index.js",
"./package": "./dist-cms/packages/packages/package/index.js",
"./data-type": "./dist-cms/packages/settings/data-types/index.js",
"./data-type": "./dist-cms/packages/core/data-type/index.js",
"./language": "./dist-cms/packages/settings/languages/index.js",
"./logviewer": "./dist-cms/packages/settings/logviewer/index.js",
"./relation-type": "./dist-cms/packages/settings/relation-types/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UmbDataTypeDetailRepository } from '@umbraco-cms/backoffice/data-type';
import { UmbPropertyEditorConfig } from '../../property-editor/index.js';
import { UmbTextStyles } from "@umbraco-cms/backoffice/style";
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import { css, html, ifDefined, customElement, property, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbDataTypeRepository } from '@umbraco-cms/backoffice/data-type';
import type { DataTypeResponseModel, PropertyTypeModelBaseModel } from '@umbraco-cms/backoffice/backend-api';
import { UmbLitElement } from '@umbraco-cms/internal/lit-element';
import { UmbObserverController } from '@umbraco-cms/backoffice/observable-api';
Expand All @@ -27,16 +27,16 @@ export class UmbPropertyTypeBasedPropertyElement extends UmbLitElement {
@state()
private _dataTypeData?: UmbPropertyEditorConfig;

private _dataTypeRepository: UmbDataTypeRepository = new UmbDataTypeRepository(this);
private _dataTypeDetailRepository = new UmbDataTypeDetailRepository(this);
private _dataTypeObserver?: UmbObserverController<DataTypeResponseModel | undefined>;

private async _observeDataType(dataTypeId?: string) {
this._dataTypeObserver?.destroy();
if (dataTypeId) {
// Its not technically needed to have await here, this is only to ensure that the data is loaded before we observe it, and thereby only updating the DOM with the latest data.
await this._dataTypeRepository.requestById(dataTypeId);
await this._dataTypeDetailRepository.requestById(dataTypeId);
this._dataTypeObserver = this.observe(
await this._dataTypeRepository.byId(dataTypeId),
await this._dataTypeDetailRepository.byId(dataTypeId),
(dataType) => {
this._dataTypeData = dataType?.values;
this._propertyEditorUiAlias = dataType?.propertyEditorUiAlias || undefined;
Expand All @@ -50,11 +50,11 @@ export class UmbPropertyTypeBasedPropertyElement extends UmbLitElement {
this._propertyEditorUiAlias = extension?.meta.defaultPropertyEditorUiAlias;
this.removeControllerByAlias('_observePropertyEditorSchema');
},
'_observePropertyEditorSchema'
'_observePropertyEditorSchema',
);
}
},
'_observeDataType'
'_observeDataType',
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UmbDataTypeRepository } from '../../repository/data-type.repository.js';
import { UmbDataTypeDetailRepository } from '../../repository/detail/data-type-detail.repository.js';
import { UUIRefNodeElement } from '@umbraco-cms/backoffice/external/uui';
import { html, customElement, property, state, css } from '@umbraco-cms/backoffice/external/lit';
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
Expand Down Expand Up @@ -39,7 +39,7 @@ export class UmbRefDataTypeElement extends UmbElementMixin(UUIRefNodeElement) {
}
}

repository = new UmbDataTypeRepository(this);
repository = new UmbDataTypeDetailRepository(this);

/**
* Property Editor UI Alias
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UmbDataTypeRepository } from '../../repository/data-type.repository.js';
import { type UmbCopyDataTypeRepository } from '../../repository/copy/data-type-copy.repository.js';
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import {
Expand All @@ -8,7 +8,7 @@ import {
} from '@umbraco-cms/backoffice/modal';

// TODO: investigate what we need to make a generic copy action
export class UmbCopyDataTypeEntityAction extends UmbEntityActionBase<UmbDataTypeRepository> {
export class UmbCopyDataTypeEntityAction extends UmbEntityActionBase<UmbCopyDataTypeRepository> {
#modalManagerContext?: UmbModalManagerContext;

constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DATA_TYPE_ENTITY_TYPE } from '../../entities.js';
import { DATA_TYPE_REPOSITORY_ALIAS } from '../../repository/manifests.js';
import { COPY_DATA_TYPE_REPOSITORY_ALIAS } from '../../repository/copy/manifests.js';
import { UmbCopyDataTypeEntityAction } from './copy.action.js';
import { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';

Expand All @@ -13,7 +13,7 @@ const entityActions: Array<ManifestTypes> = [
meta: {
icon: 'icon-documents',
label: 'Copy to...',
repositoryAlias: DATA_TYPE_REPOSITORY_ALIAS,
repositoryAlias: COPY_DATA_TYPE_REPOSITORY_ALIAS,
entityTypes: [DATA_TYPE_ENTITY_TYPE],
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { UmbDataTypeRepository } from '../../repository/data-type.repository.js';
import { UmbDataTypeDetailRepository } from '../../repository/detail/data-type-detail.repository.js';
import { UMB_DATA_TYPE_CREATE_OPTIONS_MODAL } from './modal/index.js';
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbModalManagerContext, UMB_MODAL_MANAGER_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/modal';

export class UmbCreateDataTypeEntityAction extends UmbEntityActionBase<UmbDataTypeRepository> {
export class UmbCreateDataTypeEntityAction extends UmbEntityActionBase<UmbDataTypeDetailRepository> {
#modalManagerContext?: UmbModalManagerContext;

constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DATA_TYPE_ENTITY_TYPE, DATA_TYPE_FOLDER_ENTITY_TYPE, DATA_TYPE_ROOT_ENTITY_TYPE } from '../../entities.js';
import { DATA_TYPE_REPOSITORY_ALIAS } from '../../repository/manifests.js';
import { DATA_TYPE_DETAIL_REPOSITORY_ALIAS } from '../../repository/detail/manifests.js';
import { UmbCreateDataTypeEntityAction } from './create.action.js';
import { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';

Expand All @@ -13,7 +13,7 @@ const entityActions: Array<ManifestTypes> = [
meta: {
icon: 'icon-add',
label: 'Create...',
repositoryAlias: DATA_TYPE_REPOSITORY_ALIAS,
repositoryAlias: DATA_TYPE_DETAIL_REPOSITORY_ALIAS,
entityTypes: [DATA_TYPE_ENTITY_TYPE, DATA_TYPE_ROOT_ENTITY_TYPE, DATA_TYPE_FOLDER_ENTITY_TYPE],
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DATA_TYPE_REPOSITORY_ALIAS } from '../../../repository/manifests.js';
import { DATA_TYPE_FOLDER_REPOSITORY_ALIAS } from '../../../repository/folder/manifests.js';
import { UmbDataTypeCreateOptionsModalData } from './index.js';
import { html, customElement, property } from '@umbraco-cms/backoffice/external/lit';
import { UmbTextStyles } from "@umbraco-cms/backoffice/style";
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import {
UmbModalManagerContext,
UmbModalContext,
Expand Down Expand Up @@ -30,7 +30,7 @@ export class UmbDataTypeCreateOptionsModalElement extends UmbLitElement {
#onClick(event: PointerEvent) {
event.stopPropagation();
const folderModalHandler = this.#modalContext?.open(UMB_FOLDER_MODAL, {
repositoryAlias: DATA_TYPE_REPOSITORY_ALIAS,
repositoryAlias: DATA_TYPE_FOLDER_REPOSITORY_ALIAS,
});
folderModalHandler?.onSubmit().then(() => this.modalContext?.submit());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DATA_TYPE_FOLDER_ENTITY_TYPE, DATA_TYPE_ENTITY_TYPE } from '../entities.js';
import { DATA_TYPE_REPOSITORY_ALIAS } from '../repository/manifests.js';
import { DATA_TYPE_DETAIL_REPOSITORY_ALIAS } from '../repository/detail/manifests.js';
import { manifests as createManifests } from './create/manifests.js';
import { manifests as moveManifests } from './move/manifests.js';
import { manifests as copyManifests } from './copy/manifests.js';
Expand All @@ -10,6 +10,7 @@ import {
UmbFolderUpdateEntityAction,
} from '@umbraco-cms/backoffice/entity-action';
import { ManifestEntityAction } from '@umbraco-cms/backoffice/extension-registry';
import { DATA_TYPE_FOLDER_REPOSITORY_ALIAS } from '../repository/folder/manifests.js';

const entityActions: Array<ManifestEntityAction> = [
{
Expand All @@ -21,7 +22,7 @@ const entityActions: Array<ManifestEntityAction> = [
meta: {
icon: 'icon-trash',
label: 'Delete...',
repositoryAlias: DATA_TYPE_REPOSITORY_ALIAS,
repositoryAlias: DATA_TYPE_DETAIL_REPOSITORY_ALIAS,
entityTypes: [DATA_TYPE_ENTITY_TYPE],
},
},
Expand All @@ -34,7 +35,7 @@ const entityActions: Array<ManifestEntityAction> = [
meta: {
icon: 'icon-trash',
label: 'Delete Folder...',
repositoryAlias: DATA_TYPE_REPOSITORY_ALIAS,
repositoryAlias: DATA_TYPE_FOLDER_REPOSITORY_ALIAS,
entityTypes: [DATA_TYPE_ENTITY_TYPE, DATA_TYPE_FOLDER_ENTITY_TYPE],
},
},
Expand All @@ -47,7 +48,7 @@ const entityActions: Array<ManifestEntityAction> = [
meta: {
icon: 'icon-edit',
label: 'Rename Folder...',
repositoryAlias: DATA_TYPE_REPOSITORY_ALIAS,
repositoryAlias: DATA_TYPE_FOLDER_REPOSITORY_ALIAS,
entityTypes: [DATA_TYPE_ENTITY_TYPE, DATA_TYPE_FOLDER_ENTITY_TYPE],
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DATA_TYPE_ENTITY_TYPE } from '../../entities.js';
import { DATA_TYPE_REPOSITORY_ALIAS } from '../../repository/manifests.js';
import { MOVE_DATA_TYPE_REPOSITORY_ALIAS } from '../../repository/move/manifests.js';
import { UmbMoveDataTypeEntityAction } from './move.action.js';
import { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';

Expand All @@ -13,7 +13,7 @@ const entityActions: Array<ManifestTypes> = [
meta: {
icon: 'icon-enter',
label: 'Move to...',
repositoryAlias: DATA_TYPE_REPOSITORY_ALIAS,
repositoryAlias: MOVE_DATA_TYPE_REPOSITORY_ALIAS,
entityTypes: [DATA_TYPE_ENTITY_TYPE],
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UmbDataTypeRepository } from '../../repository/data-type.repository.js';
import { UmbMoveDataTypeRepository } from '../../repository/move/data-type-move.repository.js';
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import {
Expand All @@ -8,7 +8,7 @@ import {
} from '@umbraco-cms/backoffice/modal';

// TODO: investigate what we need to make a generic move action
export class UmbMoveDataTypeEntityAction extends UmbEntityActionBase<UmbDataTypeRepository> {
export class UmbMoveDataTypeEntityAction extends UmbEntityActionBase<UmbMoveDataTypeRepository> {
#modalManagerContext?: UmbModalManagerContext;

constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UmbDataTypeRepository } from '../../repository/data-type.repository.js';
import { UmbDataTypeDetailRepository } from '../../repository/detail/data-type-detail.repository.js';
import { UmbDataTypeTreeRepository } from '../../tree/data-type-tree.repository.js';
import { css, html, customElement, property, state, repeat, when } from '@umbraco-cms/backoffice/external/lit';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import {
Expand Down Expand Up @@ -32,26 +33,27 @@ export class UmbDataTypePickerFlowDataTypePickerModalElement extends UmbLitEleme
private async _observeDataTypesOf(propertyEditorUiAlias: string) {
if (!this.data) return;

const dataTypeRepository = new UmbDataTypeRepository(this);
const dataTypeDetailRepository = new UmbDataTypeDetailRepository(this);
const dataTypeTreeRepository = new UmbDataTypeTreeRepository(this);

// TODO: This is a hack to get the data types of a property editor ui alias.
// TODO: Make sure filtering works data-type that does not have a property editor ui, but should be using the default property editor UI for those.
// TODO: make an end-point just retrieving the data types using a given property editor ui alias.
const { data } = await dataTypeRepository.requestRootTreeItems();
const { data } = await dataTypeTreeRepository.requestRootTreeItems();

if (!data) return;

await Promise.all(
data.items.map((item) => {
if (item.id) {
return dataTypeRepository.requestById(item.id);
return dataTypeDetailRepository.requestById(item.id);
}
return Promise.resolve();
}),
);

// TODO: Use the asObservable from above onces end-point has been made.
const source = await dataTypeRepository.byPropertyEditorUiAlias(propertyEditorUiAlias);
const source = await dataTypeDetailRepository.byPropertyEditorUiAlias(propertyEditorUiAlias);
this.observe(source, (dataTypes) => {
this._dataTypes = dataTypes;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UmbDataTypeRepository } from '../../repository/data-type.repository.js';
import { UmbDataTypeTreeRepository } from '../../tree/data-type-tree.repository.js';
import { css, html, repeat, customElement, property, state, when, nothing } from '@umbraco-cms/backoffice/external/lit';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import type { UUIInputEvent } from '@umbraco-cms/backoffice/external/uui';
Expand Down Expand Up @@ -51,14 +51,14 @@ export class UmbDataTypePickerFlowModalElement extends UmbLitElement {

private _createDataTypeModal: UmbModalRouteRegistrationController;

#repository;
#treeRepository;
#dataTypes: Array<EntityTreeItemResponseModel> = [];
#propertyEditorUIs: Array<ManifestPropertyEditorUi> = [];
#currentFilterQuery = '';

constructor() {
super();
this.#repository = new UmbDataTypeRepository(this);
this.#treeRepository = new UmbDataTypeTreeRepository(this);

new UmbModalRouteRegistrationController(this, UMB_DATA_TYPE_PICKER_FLOW_DATA_TYPE_PICKER_MODAL)
.addAdditionalPath(':uiAlias')
Expand Down Expand Up @@ -102,7 +102,7 @@ export class UmbDataTypePickerFlowModalElement extends UmbLitElement {
async #init() {
// TODO: Get ALL items, or traverse the structure aka. multiple recursive calls.
this.observe(
(await this.#repository.requestRootTreeItems()).asObservable(),
(await this.#treeRepository.requestRootTreeItems()).asObservable(),
(items) => {
this.#dataTypes = items;
this._performFiltering();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { html } from '@umbraco-cms/backoffice/external/lit';
import type { UmbPropertyEditorUIPickerModalData } from '@umbraco-cms/backoffice/modal';

import './property-editor-ui-picker-modal.element.js';
import '../../../../core/components/body-layout/body-layout.element.js';
import '../../../components/body-layout/body-layout.element.js';

export default {
title: 'API/Modals/Layouts/Property Editor UI Picker',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { UmbDataTypeRepositoryBase } from '../data-type-repository-base.js';
import { UmbDataTypeDetailRepository } from '../detail/data-type-detail.repository.js';
import { UmbDataTypeCopyServerDataSource } from './data-type-copy.server.data-source.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbCopyDataSource, UmbCopyRepository } from '@umbraco-cms/backoffice/repository';

export class UmbCopyDataTypeRepository extends UmbDataTypeRepositoryBase implements UmbCopyRepository {
#copySource: UmbCopyDataSource;
#detailRepository: UmbDataTypeDetailRepository;

constructor(host: UmbControllerHost) {
super(host);
this.#copySource = new UmbDataTypeCopyServerDataSource(this);
this.#detailRepository = new UmbDataTypeDetailRepository(this);
}

async copy(id: string, targetId: string | null) {
await this._init;
const { data: dataTypeCopyId, error } = await this.#copySource.copy(id, targetId);
if (error) return { error };

if (dataTypeCopyId) {
const { data: dataTypeCopy } = await this.#detailRepository.requestById(dataTypeCopyId);
if (!dataTypeCopy) throw new Error('Could not find copied data type');

// TODO: Be aware about this responsibility.
this._treeStore!.appendItems([dataTypeCopy]);
// only update the target if its not the root
if (targetId) {
this._treeStore!.updateItem(targetId, { hasChildren: true });
}

const notification = { data: { message: `Data type copied` } };
this._notificationContext!.peek('positive', notification);
}

return { data: dataTypeCopyId };
}
}
2 changes: 2 additions & 0 deletions src/packages/core/data-type/repository/copy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { UmbCopyDataTypeRepository } from './data-type-copy.repository.js';
export { COPY_DATA_TYPE_REPOSITORY_ALIAS } from './manifests.js';
13 changes: 13 additions & 0 deletions src/packages/core/data-type/repository/copy/manifests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { UmbCopyDataTypeRepository } from './data-type-copy.repository.js';
import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';

export const COPY_DATA_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.DataType.Copy';

const copyRepository: ManifestRepository = {
type: 'repository',
alias: COPY_DATA_TYPE_REPOSITORY_ALIAS,
name: 'Copy Data Type Repository',
api: UmbCopyDataTypeRepository,
};

export const manifests = [copyRepository];
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { UMB_DATA_TYPE_TREE_STORE_CONTEXT, UmbDataTypeTreeStore } from '../tree/data-type.tree.store.js';
import { UMB_DATA_TYPE_ITEM_STORE_CONTEXT, UmbDataTypeItemStore } from './item/data-type-item.store.js';
import { UMB_DATA_TYPE_STORE_CONTEXT, UmbDataTypeDetailStore } from './detail/data-type-detail.store.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UMB_NOTIFICATION_CONTEXT_TOKEN, UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';

export class UmbDataTypeRepositoryBase extends UmbRepositoryBase {
protected _init: Promise<unknown>;

protected _detailStore?: UmbDataTypeDetailStore;
protected _treeStore?: UmbDataTypeTreeStore;
protected _itemStore?: UmbDataTypeItemStore;

protected _notificationContext?: UmbNotificationContext;

constructor(host: UmbControllerHost) {
super(host);

this._init = Promise.all([
this.consumeContext(UMB_DATA_TYPE_STORE_CONTEXT, (instance) => {
this._detailStore = instance;
}).asPromise(),

this.consumeContext(UMB_DATA_TYPE_TREE_STORE_CONTEXT, (instance) => {
this._treeStore = instance;
}).asPromise(),

this.consumeContext(UMB_DATA_TYPE_ITEM_STORE_CONTEXT, (instance) => {
this._itemStore = instance;
}).asPromise(),

this.consumeContext(UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
this._notificationContext = instance;
}).asPromise(),
]);
}
}

0 comments on commit 52e41be

Please sign in to comment.