extend base for data type item server source

This commit is contained in:
Mads Rasmussen
2024-01-28 21:15:32 +01:00
parent 0fced1688a
commit afbdbe7244
4 changed files with 40 additions and 42 deletions

View File

@@ -1,4 +1,4 @@
import { UmbDataTypeItemServerDataSource } from './data-type-item.server.data.js';
import { UmbDataTypeItemServerDataSource } from './data-type-item.server.data-source.js';
import { UMB_DATA_TYPE_ITEM_STORE_CONTEXT } from './data-type-item.store.js';
import type { UmbDataTypeItemModel } from './types.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';

View File

@@ -0,0 +1,39 @@
import type { UmbDataTypeItemModel } from './types.js';
import { UmbItemServerDataSourceBase } from '@umbraco-cms/backoffice/repository';
import type { DataTypeItemResponseModel } from '@umbraco-cms/backoffice/backend-api';
import { DataTypeResource } from '@umbraco-cms/backoffice/backend-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
/**
* A server data source for Data Type items
* @export
* @class UmbDataTypeItemServerDataSource
* @implements {DocumentTreeDataSource}
*/
export class UmbDataTypeItemServerDataSource extends UmbItemServerDataSourceBase<
DataTypeItemResponseModel,
UmbDataTypeItemModel
> {
/**
* Creates an instance of UmbDataTypeItemServerDataSource.
* @param {UmbControllerHost} host
* @memberof UmbDataTypeItemServerDataSource
*/
constructor(host: UmbControllerHost) {
super(host, {
getItems,
mapper,
});
}
}
/* eslint-disable local-rules/no-direct-api-import */
const getItems = (uniques: Array<string>) => DataTypeResource.getDataTypeItem({ id: uniques });
const mapper = (item: DataTypeItemResponseModel): UmbDataTypeItemModel => {
return {
unique: item.id,
name: item.name,
propertyEditorUiAlias: item.editorUiAlias || '', // TODO: why can this be undefined or null on the server?
};
};

View File

@@ -1,40 +0,0 @@
import type { UmbItemDataSource } from '@umbraco-cms/backoffice/repository';
import type { DataTypeItemResponseModel} from '@umbraco-cms/backoffice/backend-api';
import { DataTypeResource } from '@umbraco-cms/backoffice/backend-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
/**
* A data source for Data Type items that fetches data from the server
* @export
* @class UmbDataTypeItemServerDataSource
* @implements {DocumentTreeDataSource}
*/
export class UmbDataTypeItemServerDataSource implements UmbItemDataSource<DataTypeItemResponseModel> {
#host: UmbControllerHost;
/**
* Creates an instance of UmbDataTypeItemServerDataSource.
* @param {UmbControllerHost} host
* @memberof UmbDataTypeItemServerDataSource
*/
constructor(host: UmbControllerHost) {
this.#host = host;
}
/**
* Fetches the items for the given ids from the server
* @param {Array<string>} ids
* @return {*}
* @memberof UmbDataTypeItemServerDataSource
*/
async getItems(ids: Array<string>) {
if (!ids) throw new Error('Ids are missing');
return tryExecuteAndNotify(
this.#host,
DataTypeResource.getDataTypeItem({
id: ids,
}),
);
}
}

View File

@@ -35,7 +35,6 @@ export class UmbDocumentWorkspaceElement extends UmbLitElement {
path: 'create/:parentId/:documentTypeKey',
component: this.#editorElement,
setup: async (_component, info) => {
debugger;
// TODO: Remember the perspective of permissions here, we need to check if the user has access to create a document of this type under this parent?
const parentId = info.match.params.parentId === 'null' ? null : info.match.params.parentId;
const documentTypeKey = info.match.params.documentTypeKey;