correct block catalogue data parsing

This commit is contained in:
Niels Lyngsø
2024-02-27 16:44:46 +01:00
parent bd8a62943d
commit 27d6bfa14d
2 changed files with 28 additions and 29 deletions

View File

@@ -244,33 +244,32 @@ export class UmbBlockGridEntriesContext
// Area entries:
if (!this.#areaType) return [];
if (this.#areaType.specifiedAllowance && this.#areaType.specifiedAllowance.length > 0) {
return this.#areaType.specifiedAllowance
.flatMap((permission) => {
if (permission.groupKey) {
return (
this._manager
?.getBlockTypes()
.filter(
(blockType) => blockType.groupKey === permission.groupKey && blockType.allowInAreas === true,
) ?? []
);
} else if (permission.elementTypeKey) {
return (
this._manager?.getBlockTypes().filter((x) => x.contentElementTypeKey === permission.elementTypeKey) ??
[]
);
}
return [];
})
.filter((v, i, a) => a.find((x) => x.contentElementTypeKey === v.contentElementTypeKey) === undefined);
if (this.#areaType.specifiedAllowance && this.#areaType.specifiedAllowance?.length > 0) {
return (
this.#areaType.specifiedAllowance
.flatMap((permission) => {
if (permission.groupKey) {
return (
this._manager?.getBlockTypes().filter((blockType) => blockType.groupKey === permission.groupKey) ?? []
);
} else if (permission.elementTypeKey) {
return (
this._manager?.getBlockTypes().filter((x) => x.contentElementTypeKey === permission.elementTypeKey) ??
[]
);
}
return [];
})
// Remove duplicates:
.filter((v, i, a) => a.findIndex((x) => x.contentElementTypeKey === v.contentElementTypeKey) === i)
);
}
// No specific permissions setup, so we will fallback to items allowed in areas:
return this._manager.getBlockTypes().filter((x) => x.allowInAreas);
}
// If no AreaKey, then we are representing the items of the root:
// Root entries:
// If no AreaKey, then we are in the root, looking for items allowed as root:
return this._manager.getBlockTypes().filter((x) => x.allowAtRoot);
}

View File

@@ -16,7 +16,9 @@ export class UmbBlockCatalogueModalElement extends UmbModalBaseElement<
UmbBlockCatalogueModalData,
UmbBlockCatalogueModalValue
> {
@state()
//
private _search = '';
private _groupedBlocks: Array<{ name?: string; blocks: Array<UmbBlockTypeWithGroupKey> }> = [];
@state()
@@ -28,9 +30,6 @@ export class UmbBlockCatalogueModalElement extends UmbModalBaseElement<
@state()
private _filtered: Array<{ name?: string; blocks: Array<UmbBlockTypeWithGroupKey> }> = [];
@state()
private _search = '';
constructor() {
super();
@@ -68,10 +67,11 @@ export class UmbBlockCatalogueModalElement extends UmbModalBaseElement<
}));
this._groupedBlocks = [{ blocks: noGroupBlocks }, ...grouped];
this.#onFilter();
this.#updateFiltered();
}
#onFilter() {
#updateFiltered() {
// A minimum of 3 characters is required to start filtering:
if (this._search.length <= 3) {
this._filtered = this._groupedBlocks;
} else {
@@ -84,7 +84,7 @@ export class UmbBlockCatalogueModalElement extends UmbModalBaseElement<
#onSearch(e: UUIInputEvent) {
this._search = e.target.value as string;
this.#onFilter();
this.#updateFiltered();
}
render() {