fix: add tree handler for ancestors to avoid api error
This commit is contained in:
@@ -21,6 +21,18 @@ export class UmbMockEntityTreeManager<T extends { id: string; parent?: { id: str
|
||||
return this.#pagedTreeResult({ items, skip, take });
|
||||
}
|
||||
|
||||
getAncestorsOf({ descendantId }: { descendantId: string }): Array<T> {
|
||||
const items = [];
|
||||
let currentId: string | undefined = descendantId;
|
||||
while (currentId) {
|
||||
const item = this.#db.read(currentId);
|
||||
if (!item) break;
|
||||
items.push(item);
|
||||
currentId = item.parent?.id;
|
||||
}
|
||||
return items.reverse();
|
||||
}
|
||||
|
||||
#pagedTreeResult({ items, skip, take }: { items: Array<T>; skip: number; take: number }) {
|
||||
const paged = pagedResult(items, skip, take);
|
||||
const treeItems = paged.items.map((item) => this.#treeItemMapper(item));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { rest } = window.MockServiceWorker;
|
||||
import { umbDocumentMockDb } from '../../data/document/document.db.js';
|
||||
import type { GetTreeDocumentAncestorsResponse } from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import { UMB_SLUG } from './slug.js';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
@@ -19,4 +20,11 @@ export const treeHandlers = [
|
||||
const response = umbDocumentMockDb.tree.getChildrenOf({ parentId, skip, take });
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.get(umbracoPath(`/tree${UMB_SLUG}/ancestors`), (req, res, ctx) => {
|
||||
const descendantId = req.url.searchParams.get('descendantId');
|
||||
if (!descendantId) return;
|
||||
const response = umbDocumentMockDb.tree.getAncestorsOf({ descendantId });
|
||||
return res(ctx.status(200), ctx.json<GetTreeDocumentAncestorsResponse>(response));
|
||||
}),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user