Skip to content

Commit b5fb176

Browse files
committed
Hotfix: refactor of #21221 (#21293)
* refactor reload method to entity-detail * refactor property value transfering when variation changes
1 parent 83882a9 commit b5fb176

File tree

6 files changed

+469
-200
lines changed

6 files changed

+469
-200
lines changed

src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/content-detail-workspace-base.ts

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { UmbContentCollectionWorkspaceContext } from '../collection/content
99
import type { UmbContentWorkspaceContext } from './content-workspace-context.interface.js';
1010
import { UmbContentDetailValidationPathTranslator } from './content-detail-validation-path-translator.js';
1111
import { UmbContentValidationToHintsManager } from './content-validation-to-hints.manager.js';
12+
import { UmbContentDetailWorkspaceTypeTransformController } from './content-detail-workspace-type-transform.controller.js';
1213
import {
1314
appendToFrozenArray,
1415
mergeObservables,
@@ -154,6 +155,9 @@ export abstract class UmbContentDetailWorkspaceContextBase<
154155
* @internal
155156
*/
156157
public readonly languages = this.#languages.asObservable();
158+
getLanguages(): Array<UmbLanguageDetailModel> {
159+
return this.#languages.getValue();
160+
}
157161

158162
protected readonly _segments = new UmbArrayState<UmbSegmentModel>([], (x) => x.alias);
159163

@@ -178,12 +182,6 @@ export abstract class UmbContentDetailWorkspaceContextBase<
178182
#saveModalToken?: UmbModalToken<UmbContentVariantPickerData<VariantOptionModelType>, UmbContentVariantPickerValue>;
179183
#contentTypePropertyName: string;
180184

181-
/**
182-
* Cache of property variation settings to detect changes when structure is updated.
183-
* Used to trigger value migration when properties change from invariant to variant or vice versa.
184-
*/
185-
#propertyVariationCache = new Map<string, { variesByCulture: boolean; variesBySegment: boolean }>();
186-
187185
constructor(
188186
host: UmbControllerHost,
189187
args: UmbContentDetailWorkspaceContextArgs<
@@ -228,6 +226,8 @@ export abstract class UmbContentDetailWorkspaceContextBase<
228226
this.view.hints,
229227
);
230228

229+
new UmbContentDetailWorkspaceTypeTransformController(this as any);
230+
231231
this.variantOptions = mergeObservables(
232232
[this.variesByCulture, this.variesBySegment, this.variants, this.languages, this._segments.asObservable()],
233233
([variesByCulture, variesBySegment, variants, languages, segments]) => {
@@ -385,16 +385,6 @@ export abstract class UmbContentDetailWorkspaceContextBase<
385385
null,
386386
);
387387

388-
// Observe property variation changes to trigger value migration when properties change
389-
// from invariant to variant (or vice versa) via Infinite Editing
390-
this.observe(
391-
this.structure.contentTypeProperties,
392-
(properties: Array<UmbPropertyTypeModel>) => {
393-
this.#handlePropertyVariationChanges(properties);
394-
},
395-
null,
396-
);
397-
398388
this.loadLanguages();
399389
}
400390

@@ -1124,67 +1114,6 @@ export abstract class UmbContentDetailWorkspaceContextBase<
11241114
variantId: UmbVariantId,
11251115
): UmbContentPropertyDatasetContext<DetailModelType, ContentTypeDetailModelType, VariantModelType>;
11261116

1127-
/**
1128-
* Handles property variation changes when the document type is updated via Infinite Editing.
1129-
* When a property's variation setting changes (e.g., from shared/invariant to variant or vice versa),
1130-
* this method reloads the document to get properly migrated values from the server.
1131-
*/
1132-
#handlePropertyVariationChanges(properties: Array<UmbPropertyTypeModel>): void {
1133-
// Skip if no current data or if this is initial load
1134-
const currentData = this._data.getCurrent();
1135-
if (!currentData || this.#propertyVariationCache.size === 0) {
1136-
// Initial load - just populate the cache
1137-
for (const property of properties) {
1138-
this.#propertyVariationCache.set(property.alias, {
1139-
variesByCulture: property.variesByCulture,
1140-
variesBySegment: property.variesBySegment,
1141-
});
1142-
}
1143-
return;
1144-
}
1145-
1146-
// Check for variation setting changes
1147-
let hasChanges = false;
1148-
for (const property of properties) {
1149-
const cached = this.#propertyVariationCache.get(property.alias);
1150-
if (cached) {
1151-
if (
1152-
cached.variesByCulture !== property.variesByCulture ||
1153-
cached.variesBySegment !== property.variesBySegment
1154-
) {
1155-
hasChanges = true;
1156-
}
1157-
}
1158-
// Update cache
1159-
this.#propertyVariationCache.set(property.alias, {
1160-
variesByCulture: property.variesByCulture,
1161-
variesBySegment: property.variesBySegment,
1162-
});
1163-
}
1164-
1165-
// If variation settings changed, reload to get properly migrated values
1166-
if (hasChanges) {
1167-
this.reload();
1168-
}
1169-
}
1170-
1171-
/**
1172-
* Override reload to process incoming data through the value migration pipeline.
1173-
* This ensures property values are properly transformed when variation settings change.
1174-
*/
1175-
public override async reload(): Promise<void> {
1176-
const unique = this.getUnique();
1177-
if (!unique) throw new Error('Unique is not set');
1178-
const { data } = await this._detailRepository!.requestByUnique(unique);
1179-
1180-
if (data) {
1181-
// Process the data through _processIncomingData to handle value migration
1182-
const processedData = await this._processIncomingData(data);
1183-
this._data.setPersisted(processedData);
1184-
this._data.setCurrent(processedData);
1185-
}
1186-
}
1187-
11881117
public override destroy(): void {
11891118
this.structure.destroy();
11901119
this.#languageRepository.destroy();

0 commit comments

Comments
 (0)