From 019118b914030a387f53ddff18520ea15fe01f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 21 Feb 2023 22:34:21 +0100 Subject: [PATCH] property uses variantid --- .../workspace/document-workspace.context.ts | 35 ++++++++++++------- .../property-type-based-property.element.ts | 3 +- .../variantable-property.element.ts | 1 - .../workspace-property.element.ts | 8 ++++- ...orkspace-property-set-context.interface.ts | 9 ----- .../workspace-property-set.context.ts | 26 -------------- .../src/core/mocks/data/document.data.ts | 24 +++++++++++++ 7 files changed, 56 insertions(+), 50 deletions(-) delete mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-property-set-context.interface.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-property-set.context.ts diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts index 3a21e815f4..0adc3faba3 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts @@ -157,30 +157,41 @@ export class UmbDocumentWorkspaceContext return this.#activeVariantsInfo.getObservablePart((data) => data[index] || undefined); } - getName(variantId = new UmbVariantId()) { + getName(variantId?: UmbVariantId) { const variants = this.#draft.getValue()?.variants; if (!variants) return; - return variants.find((x) => variantId.compare(x))?.name; + if (variantId) { + return variants.find((x) => variantId.compare(x))?.name; + } else { + return variants[0]?.name; + } } - setName(name: string, variantId = new UmbVariantId()) { + setName(name: string, variantId?: UmbVariantId) { const oldVariants = this.#draft.getValue()?.variants || []; - const variants = partialUpdateFrozenArray(oldVariants, { name }, (x) => variantId.compare(x)); + const variants = partialUpdateFrozenArray( + oldVariants, + { name }, + variantId ? (x) => variantId.compare(x) : () => true + ); this.#draft.update({ variants }); } - propertyValuesOf(variantId = new UmbVariantId()) { - return this.#draft.getObservablePart((data) => data?.values?.filter((x) => variantId.compare(x))); - } - - propertyDataByAlias(propertyAlias: string, variantId = new UmbVariantId()) { + propertyValuesOf(variantId?: UmbVariantId) { return this.#draft.getObservablePart((data) => - data?.values?.find((x) => x?.alias === propertyAlias && variantId.compare(x)) + variantId ? data?.values?.filter((x) => variantId.compare(x)) : data?.values ); } - propertyValueByAlias(propertyAlias: string, variantId = new UmbVariantId()) { + + propertyDataByAlias(propertyAlias: string, variantId?: UmbVariantId) { + return this.#draft.getObservablePart((data) => + data?.values?.find((x) => x?.alias === propertyAlias && (variantId ? variantId.compare(x) : true)) + ); + } + propertyValueByAlias(propertyAlias: string, variantId?: UmbVariantId) { return this.#draft.getObservablePart( - (data) => data?.values?.find((x) => x?.alias === propertyAlias && variantId.compare(x))?.value + (data) => + data?.values?.find((x) => x?.alias === propertyAlias && (variantId ? variantId.compare(x) : true))?.value ); } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/property-type-based-property/property-type-based-property.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/property-type-based-property/property-type-based-property.element.ts index 45b3a1c14d..21e1df6fe2 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/property-type-based-property/property-type-based-property.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/property-type-based-property/property-type-based-property.element.ts @@ -80,11 +80,12 @@ export class UmbPropertyTypeBasedPropertyElement extends UmbLitElement { private _observeProperty() { if (!this._workspaceContext || !this.property || !this._property?.alias) return; - console.log('_observeProperty', this._property.alias); + console.log('_observeProperty', this._property.alias, this._variantId); this.observe( this._workspaceContext.propertyValueByAlias(this._property.alias, this._variantId), (value) => { + console.log('!!!!!!!!!!!!propertyValueByAlias', value); this._value = value; }, '_observePropertyValueByAlias' diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/variantable-property/variantable-property.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/variantable-property/variantable-property.element.ts index b12858558b..0a191b22fe 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/variantable-property/variantable-property.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/variantable-property/variantable-property.element.ts @@ -48,7 +48,6 @@ export class UmbVariantablePropertyElement extends UmbLitElement { private _observeVariantContext() { if (!this._variantContext || !this.property) return; this.observe(this._variantContext.variantId, (variantId) => { - console.log('property got variantId: ', variantId); this._workspaceVariantId = variantId; this._updatePropertyVariantId(); }); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace-property/workspace-property.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace-property/workspace-property.element.ts index b4d5174fc4..dddfd879c6 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace-property/workspace-property.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace-property/workspace-property.element.ts @@ -102,6 +102,7 @@ export class UmbWorkspacePropertyElement extends UmbLitElement { */ @property({ attribute: false }) public set value(value: unknown) { + console.log('workspace-property.element.ts: set value', value); this._propertyContext.setValue(value); } @@ -137,6 +138,9 @@ export class UmbWorkspacePropertyElement extends UmbLitElement { @state() private _element?: { value?: any; config?: any } & HTMLElement; // TODO: invent interface for propertyEditorUI. + @state() + private _value?: unknown; + @state() private _alias?: string; @@ -205,6 +209,8 @@ export class UmbWorkspacePropertyElement extends UmbLitElement { this._element.addEventListener('property-value-change', this._onPropertyEditorChange as any as EventListener); this._valueObserver = this.observe(this._propertyContext.value, (value) => { + console.log('workspace property this._valueObserver', value); + this._value = value; if (this._element) { this._element.value = value; } @@ -243,7 +249,7 @@ export class UmbWorkspacePropertyElement extends UmbLitElement { slot="property-action-menu" id="property-action-menu" .propertyEditorUiAlias="${this._propertyEditorUiAlias}" - .value="${this.value}">` + .value="${this._value}">` : ''}`; } } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-property-set-context.interface.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-property-set-context.interface.ts deleted file mode 100644 index b130ca5b7b..0000000000 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-property-set-context.interface.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Observable } from 'rxjs'; -import { ValueViewModelBaseModel } from '@umbraco-cms/backend-api'; - -export interface UmbWorkspacePropertySetContextInterface { - propertyDataByAlias(alias: string): Observable; - propertyValueByAlias(alias: string): Observable; - getPropertyValue(alias: string): void; - setPropertyValue(alias: string, value: unknown): void; -} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-property-set.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-property-set.context.ts deleted file mode 100644 index 83bdec5af9..0000000000 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-property-set.context.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { UmbWorkspacePropertySetContextInterface } from './workspace-property-set-context.interface'; -import { UmbWorkspaceInvariantableEntityContextInterface } from './workspace-invariantable-entity-context.interface'; -import { UmbContextProviderController } from '@umbraco-cms/context-api'; -import { UmbControllerHostInterface } from '@umbraco-cms/controller'; - -export class UmbWorkspacePropertySetContext implements UmbWorkspacePropertySetContextInterface { - workspaceContext: UmbWorkspaceInvariantableEntityContextInterface; - - constructor(host: UmbControllerHostInterface, workspaceContext: UmbWorkspaceInvariantableEntityContextInterface) { - this.workspaceContext = workspaceContext; - new UmbContextProviderController(host, 'umbWorkspacePropertySetContext', this); - } - - propertyDataByAlias(alias: string) { - return this.workspaceContext.propertyDataByAlias(alias); - } - propertyValueByAlias(alias: string) { - return this.workspaceContext.propertyValueByAlias(alias); - } - getPropertyValue(alias: string) { - return this.workspaceContext.getPropertyValue(alias); - } - setPropertyValue(alias: string, value: unknown) { - return this.workspaceContext.setPropertyValue(alias, value); - } -} diff --git a/src/Umbraco.Web.UI.Client/src/core/mocks/data/document.data.ts b/src/Umbraco.Web.UI.Client/src/core/mocks/data/document.data.ts index 3eb0eb28e1..a6ffc1d99b 100644 --- a/src/Umbraco.Web.UI.Client/src/core/mocks/data/document.data.ts +++ b/src/Umbraco.Web.UI.Client/src/core/mocks/data/document.data.ts @@ -266,6 +266,18 @@ export const data: Array = [ alias: 'blogTextStringUnderGroupUnderMasterTab', value: 'which is under another group in the tab', }, + { + culture: 'da-dk', + segment: null, + alias: 'blogTextStringUnderMasterTab', + value: 'på master dokument tab B', + }, + { + culture: 'da-dk', + segment: null, + alias: 'blogTextStringUnderGroupUnderMasterTab', + value: 'denne er under en anden gruppe i tab B', + }, { culture: null, segment: null, @@ -330,6 +342,18 @@ export const data: Array = [ alias: 'blogTextStringUnderGroupUnderMasterTab', value: 'which is under another group in the tab B', }, + { + culture: 'da-dk', + segment: null, + alias: 'blogTextStringUnderMasterTab', + value: 'på master dokument tab B', + }, + { + culture: 'da-dk', + segment: null, + alias: 'blogTextStringUnderGroupUnderMasterTab', + value: 'denne er under en anden gruppe i tab B', + }, { culture: null, segment: null,