simplify contentTypeNameOf

This commit is contained in:
Niels Lyngsø
2024-01-17 15:56:45 +01:00
parent ed55095def
commit df2be6d049
2 changed files with 19 additions and 19 deletions

View File

@@ -80,8 +80,8 @@ export class UmbBlockContext<
// Observe blockType:
this.observe(this.blockType, (blockType) => {
if (!blockType) return;
this.#observeBlockTypeLabel();
this.#observeBlockTypeContentElementName();
this.#observeBlockTypeLabel();
});
}
@@ -127,6 +127,21 @@ export class UmbBlockContext<
);
}
#observeBlockTypeContentElementName() {
if (!this.#manager) return;
const contentElementTypeKey = this.#blockType.value?.contentElementTypeKey;
if (!contentElementTypeKey) return;
// observe blockType:
this.observe(
this.#manager.contentTypeNameOf(contentElementTypeKey),
(contentTypeName) => {
this.#blockTypeName.next(contentTypeName);
},
'observeBlockTypeContentElementTypeName',
);
}
#observeBlockTypeLabel() {
if (!this.#manager) return;
const blockType = this.#blockType.value;
@@ -143,6 +158,7 @@ export class UmbBlockContext<
this.observe(
this.blockTypeName,
(contentTypeName) => {
// Currently the contentTypeName is used directly as the label, but later this should just be a prop for the label to use.
this.#label.next(contentTypeName ?? 'no name');
},
'observeBlockTypeName',
@@ -150,21 +166,6 @@ export class UmbBlockContext<
}
}
#observeBlockTypeContentElementName() {
if (!this.#manager) return;
const contentElementTypeKey = this.#blockType.value?.contentElementTypeKey;
if (!contentElementTypeKey) return;
// observe blockType:
this.observe(
this.#manager.contentTypeNameOf(contentElementTypeKey),
(contentTypeName) => {
this.#blockTypeName.next(contentTypeName);
},
'observeBlockTypeContentElementTypeName',
);
}
// Public methods:
public delete() {

View File

@@ -95,9 +95,8 @@ export class UmbBlockManagerContext<
const contentTypeId = getKeyFromUdi(contentTypeUdi);
return this.#contentTypes.asObservablePart((source) => source.find((x) => x.id === contentTypeId));
}
contentTypeNameOf(contentTypeUdi: string) {
const contentTypeId = getKeyFromUdi(contentTypeUdi);
return this.#contentTypes.asObservablePart((source) => source.find((x) => x.id === contentTypeId)?.name);
contentTypeNameOf(contentTypeKey: string) {
return this.#contentTypes.asObservablePart((source) => source.find((x) => x.id === contentTypeKey)?.name);
}
blockTypeOf(contentTypeKey: string) {
return this.#blockTypes.asObservablePart((source) =>