implement readonly observable in property context

This commit is contained in:
Mads Rasmussen
2024-07-31 13:15:05 +02:00
parent c17131bbec
commit 2e5664a0de

View File

@@ -4,6 +4,7 @@ import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import {
UmbArrayState,
UmbBasicState,
UmbBooleanState,
UmbClassState,
UmbDeepState,
UmbObjectState,
@@ -47,6 +48,9 @@ export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPrope
private _editor = new UmbBasicState<UmbPropertyEditorUiElement | undefined>(undefined);
public readonly editor = this._editor.asObservable();
#isReadOnly = new UmbBooleanState(false);
public readonly isReadOnly = this.#isReadOnly.asObservable();
setEditor(editor: UmbPropertyEditorUiElement | undefined) {
this._editor.setValue(editor ?? undefined);
}
@@ -105,6 +109,10 @@ export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPrope
},
'observeValue',
);
this.observe(this.#datasetContext.currentVariantCultureIsReadOnly, (value) => {
this.#isReadOnly.setValue(value);
});
}
private _generateVariantDifferenceString() {
@@ -259,6 +267,15 @@ export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPrope
return this.#validation.getValue();
}
/**
* Get the read only state of this property
* @return {*} {boolean}
* @memberof UmbPropertyContext
*/
public getIsReadOnly(): boolean {
return this.#isReadOnly.getValue();
}
/**
* Reset the value of this property.
* @memberof UmbPropertyContext
@@ -284,6 +301,7 @@ export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPrope
this.#configValues.destroy();
this.#value.destroy();
this.#config.destroy();
this.#isReadOnly.destroy();
this.#datasetContext = undefined;
}
}