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