expose methods without variantId
This commit is contained in:
@@ -141,7 +141,11 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
|
||||
originData: UmbBlockListWorkspaceOriginData,
|
||||
) {
|
||||
await this._retrieveManager;
|
||||
return this._manager?.insert(layoutEntry, content, settings, originData) ?? false;
|
||||
const success = this._manager?.insert(layoutEntry, content, settings, originData) ?? false;
|
||||
if (success) {
|
||||
this._manager?.setOneExpose(layoutEntry.contentKey);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// create Block?
|
||||
|
||||
@@ -566,7 +566,7 @@ export abstract class UmbBlockEntryContext<
|
||||
if (!variantId || !this.#contentKey) return;
|
||||
// TODO: Handle variantId changes
|
||||
this.observe(
|
||||
this._manager?.hasExposeOf(this.#contentKey, variantId),
|
||||
this._manager?.hasExposeOf(this.#contentKey),
|
||||
(hasExpose) => {
|
||||
this.#hasExpose.setValue(hasExpose);
|
||||
},
|
||||
@@ -604,9 +604,8 @@ export abstract class UmbBlockEntryContext<
|
||||
}
|
||||
|
||||
public expose() {
|
||||
const variantId = this.#variantId.getValue();
|
||||
if (!this.#contentKey || !variantId) return;
|
||||
this._manager?.setOneExpose(this.#contentKey, variantId);
|
||||
if (!this.#contentKey) return;
|
||||
this._manager?.setOneExpose(this.#contentKey);
|
||||
}
|
||||
|
||||
//copy
|
||||
|
||||
@@ -3,7 +3,13 @@ import type { UmbBlockLayoutBaseModel, UmbBlockDataModel, UmbBlockExposeModel }
|
||||
import { UMB_BLOCK_MANAGER_CONTEXT } from './block-manager.context-token.js';
|
||||
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbArrayState, UmbBooleanState, UmbClassState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import {
|
||||
UmbArrayState,
|
||||
UmbBooleanState,
|
||||
UmbClassState,
|
||||
UmbStringState,
|
||||
mergeObservables,
|
||||
} from '@umbraco-cms/backoffice/observable-api';
|
||||
import { UmbDocumentTypeDetailRepository } from '@umbraco-cms/backoffice/document-type';
|
||||
import { UmbContentTypeStructureManager, type UmbContentTypeModel } from '@umbraco-cms/backoffice/content-type';
|
||||
import { UmbId } from '@umbraco-cms/backoffice/id';
|
||||
@@ -170,12 +176,18 @@ export abstract class UmbBlockManagerContext<
|
||||
settingsOf(key: string) {
|
||||
return this.#settings.asObservablePart((source) => source.find((x) => x.key === key));
|
||||
}
|
||||
exposeOf(contentKey: string, variantId: UmbVariantId) {
|
||||
return this.#exposes.asObservablePart((source) =>
|
||||
source.filter((x) => x.contentKey === contentKey && variantId.compare(x)),
|
||||
currentExposeOf(contentKey: string) {
|
||||
const variantId = this.#variantId.getValue();
|
||||
if (!variantId) return;
|
||||
return mergeObservables(
|
||||
[this.#exposes.asObservablePart((source) => source.filter((x) => x.contentKey === contentKey)), this.variantId],
|
||||
([exposes, variantId]) => (variantId ? exposes.find((x) => variantId.compare(x)) : undefined),
|
||||
);
|
||||
}
|
||||
hasExposeOf(contentKey: string, variantId: UmbVariantId) {
|
||||
|
||||
hasExposeOf(contentKey: string) {
|
||||
const variantId = this.#variantId.getValue();
|
||||
if (!variantId) return;
|
||||
return this.#exposes.asObservablePart((source) =>
|
||||
source.some((x) => x.contentKey === contentKey && variantId.compare(x)),
|
||||
);
|
||||
@@ -196,7 +208,9 @@ export abstract class UmbBlockManagerContext<
|
||||
setOneSettings(settingsData: UmbBlockDataModel) {
|
||||
this.#settings.appendOne(settingsData);
|
||||
}
|
||||
setOneExpose(contentKey: string, variantId: UmbVariantId) {
|
||||
setOneExpose(contentKey: string) {
|
||||
const variantId = this.#variantId.getValue();
|
||||
if (!variantId) return;
|
||||
this.#exposes.appendOne({ contentKey, ...variantId.toObject() });
|
||||
}
|
||||
|
||||
@@ -209,7 +223,9 @@ export abstract class UmbBlockManagerContext<
|
||||
removeExposesOf(contentKey: string) {
|
||||
this.#exposes.filter((x) => x.contentKey !== contentKey);
|
||||
}
|
||||
removeOneExpose(contentKey: string, variantId: UmbVariantId) {
|
||||
removeCurrentExpose(contentKey: string) {
|
||||
const variantId = this.#variantId.getValue();
|
||||
if (!variantId) return;
|
||||
this.#exposes.filter((x) => !(x.contentKey === contentKey && variantId.compare(x)));
|
||||
}
|
||||
|
||||
|
||||
@@ -118,19 +118,19 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
|
||||
);
|
||||
|
||||
this.observe(
|
||||
observeMultiple([this.variantId, this.contentKey]),
|
||||
([variantId, contentKey]) => {
|
||||
if (!variantId || !contentKey) return;
|
||||
this.contentKey,
|
||||
(contentKey) => {
|
||||
if (!contentKey) return;
|
||||
|
||||
this.observe(
|
||||
manager.hasExposeOf(contentKey, variantId),
|
||||
manager.hasExposeOf(contentKey),
|
||||
(exposed) => {
|
||||
this.#exposed.setValue(exposed);
|
||||
},
|
||||
'observeHasExpose',
|
||||
);
|
||||
},
|
||||
'observeVariantIdContentKey',
|
||||
'observeContentKey',
|
||||
);
|
||||
}).asPromise();
|
||||
|
||||
@@ -469,12 +469,7 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
|
||||
}
|
||||
|
||||
#expose(unique: string) {
|
||||
const variantId = this.#variantId.getValue();
|
||||
if (!variantId) {
|
||||
throw new Error('Block could not bre exposed cause we where missing a variant ID.');
|
||||
}
|
||||
// expose
|
||||
this.#blockManager?.setOneExpose(unique, variantId);
|
||||
this.#blockManager?.setOneExpose(unique);
|
||||
}
|
||||
|
||||
#modalRejected = () => {
|
||||
|
||||
Reference in New Issue
Block a user