now works
This commit is contained in:
@@ -3,6 +3,5 @@ import type { DataSourceResponse } from '@umbraco-cms/models';
|
||||
|
||||
export interface RepositoryTreeDataSource {
|
||||
getRootItems(): Promise<DataSourceResponse<PagedEntityTreeItemModel>>;
|
||||
getChildrenOf(parentKey: string): Promise<DataSourceResponse<PagedEntityTreeItemModel>>;
|
||||
getItems(key: Array<string>): Promise<DataSourceResponse<EntityTreeItemModel[]>>;
|
||||
}
|
||||
|
||||
@@ -7,11 +7,6 @@ export interface UmbTreeRepository {
|
||||
error: ProblemDetailsModel | undefined;
|
||||
asObservable?: () => Observable<EntityTreeItemModel[]>;
|
||||
}>;
|
||||
requestTreeItemsOf: (parentKey: string | null) => Promise<{
|
||||
data: PagedEntityTreeItemModel | undefined;
|
||||
error: ProblemDetailsModel | undefined;
|
||||
asObservable?: () => Observable<EntityTreeItemModel[]>;
|
||||
}>;
|
||||
requestTreeItems: (keys: string[]) => Promise<{
|
||||
data: Array<EntityTreeItemModel> | undefined;
|
||||
error: ProblemDetailsModel | undefined;
|
||||
|
||||
@@ -66,23 +66,6 @@ export class UmbRelationTypeRepository implements UmbTreeRepository, UmbDetailRe
|
||||
return { data, error, asObservable: () => this.#treeStore!.rootItems };
|
||||
}
|
||||
|
||||
async requestTreeItemsOf(parentKey: string | null) {
|
||||
await this.#init;
|
||||
|
||||
if (!parentKey) {
|
||||
const error: ProblemDetailsModel = { title: 'Parent key is missing' };
|
||||
return { data: undefined, error };
|
||||
}
|
||||
|
||||
const { data, error } = await this.#treeSource.getChildrenOf(parentKey);
|
||||
|
||||
if (data) {
|
||||
this.#treeStore?.appendItems(data.items);
|
||||
}
|
||||
|
||||
return { data, error, asObservable: () => this.#treeStore!.childrenOf(parentKey) };
|
||||
}
|
||||
|
||||
async requestTreeItems(keys: Array<string>) {
|
||||
await this.#init;
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import type { RepositoryTreeDataSource } from '../../../../../../libs/repository/repository-tree-data-source.interface';
|
||||
import { ProblemDetailsModel, RelationTypeResource } from '@umbraco-cms/backend-api';
|
||||
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/resources';
|
||||
|
||||
/**
|
||||
* A data source for the Document tree that fetches data from the server
|
||||
* A data source for the RelationType tree that fetches data from the server
|
||||
* @export
|
||||
* @class DocumentTreeServerDataSource
|
||||
* @implements {DocumentTreeDataSource}
|
||||
* @class RelationTypeTreeServerDataSource
|
||||
* @implements {RelationTypeTreeDataSource}
|
||||
*/
|
||||
export class RelationTypeTreeServerDataSource implements RepositoryTreeDataSource {
|
||||
export class RelationTypeTreeServerDataSource implements RelationTypeTreeDataSource {
|
||||
#host: UmbControllerHostInterface;
|
||||
|
||||
// TODO: how do we handle trashed items?
|
||||
@@ -46,9 +45,9 @@ export class RelationTypeTreeServerDataSource implements RepositoryTreeDataSourc
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of DocumentTreeServerDataSource.
|
||||
* Creates an instance of RelationTypeTreeServerDataSource.
|
||||
* @param {UmbControllerHostInterface} host
|
||||
* @memberof DocumentTreeServerDataSource
|
||||
* @memberof RelationTypeTreeServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
this.#host = host;
|
||||
@@ -57,37 +56,17 @@ export class RelationTypeTreeServerDataSource implements RepositoryTreeDataSourc
|
||||
/**
|
||||
* Fetches the root items for the tree from the server
|
||||
* @return {*}
|
||||
* @memberof DocumentTreeServerDataSource
|
||||
* @memberof RelationTypeTreeServerDataSource
|
||||
*/
|
||||
async getRootItems() {
|
||||
return tryExecuteAndNotify(this.#host, RelationTypeResource.getTreeRelationTypeRoot({}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the children of a given parent key from the server
|
||||
* @param {(string | null)} parentKey
|
||||
* @return {*}
|
||||
* @memberof DocumentTreeServerDataSource
|
||||
*/
|
||||
async getChildrenOf(parentKey: string | null) {
|
||||
if (!parentKey) {
|
||||
const error: ProblemDetailsModel = { title: 'Parent key is missing' };
|
||||
return { error };
|
||||
}
|
||||
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
RelationTypeResource.getTreeRelationTypeChildren({
|
||||
parentKey,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the items for the given keys from the server
|
||||
* @param {Array<string>} keys
|
||||
* @return {*}
|
||||
* @memberof DocumentTreeServerDataSource
|
||||
* @memberof RelationTypeTreeServerDataSource
|
||||
*/
|
||||
async getItems(keys: Array<string>) {
|
||||
if (keys) {
|
||||
|
||||
@@ -73,6 +73,7 @@ export class UmbTreeElement extends UmbLitElement {
|
||||
.pipe(map((trees) => trees.find((tree) => tree.alias === this.alias))),
|
||||
async (tree) => {
|
||||
if (this._tree?.alias === tree?.alias) return;
|
||||
|
||||
this._tree = tree;
|
||||
this.#provideTreeContext();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { UmbEntityData } from './entity.data';
|
||||
import { createEntityTreeItem, createFolderTreeItem } from './utils';
|
||||
import { createEntityTreeItem } from './utils';
|
||||
import type { FolderTreeItemModel, RelationTypeResponseModel } from '@umbraco-cms/backend-api';
|
||||
|
||||
// TODO: investigate why we don't get an entity type as part of the RelationTypeResponseModel
|
||||
@@ -17,6 +17,7 @@ export const data: Array<RelationTypeResponseModel & { type: 'relation-type' }>
|
||||
parentObjectTypeName: 'Document',
|
||||
childObjectTypeName: 'Document',
|
||||
type: 'relation-type',
|
||||
parentKey: null,
|
||||
},
|
||||
{
|
||||
key: 'ac68cde6-763f-4231-a751-1101b57defd2',
|
||||
@@ -31,6 +32,7 @@ export const data: Array<RelationTypeResponseModel & { type: 'relation-type' }>
|
||||
parentObjectTypeName: 'Document',
|
||||
childObjectTypeName: 'Document',
|
||||
type: 'relation-type',
|
||||
parentKey: null,
|
||||
},
|
||||
{
|
||||
key: '6f9b800c-762c-42d4-85d9-bf40a77d689e',
|
||||
@@ -45,6 +47,7 @@ export const data: Array<RelationTypeResponseModel & { type: 'relation-type' }>
|
||||
parentObjectTypeName: 'Document',
|
||||
childObjectTypeName: 'Document',
|
||||
type: 'relation-type',
|
||||
parentKey: null,
|
||||
},
|
||||
{
|
||||
key: 'd421727d-43de-4205-b4c6-037404f309ad',
|
||||
@@ -59,6 +62,7 @@ export const data: Array<RelationTypeResponseModel & { type: 'relation-type' }>
|
||||
parentObjectTypeName: 'Document',
|
||||
childObjectTypeName: 'Document',
|
||||
type: 'relation-type',
|
||||
parentKey: null,
|
||||
},
|
||||
{
|
||||
key: 'e9a0a28e-2d5b-4229-ac00-66f2df230513',
|
||||
@@ -73,6 +77,7 @@ export const data: Array<RelationTypeResponseModel & { type: 'relation-type' }>
|
||||
parentObjectTypeName: 'Document',
|
||||
childObjectTypeName: 'Document',
|
||||
type: 'relation-type',
|
||||
parentKey: null,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user