Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UmbContentDetailModel, UmbElementValueModel } from '../types.js';

Check notice on line 1 in src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/content-detail-workspace-base.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (release/17.1)

✅ No longer an issue: Overall Code Complexity

The mean cyclomatic complexity in this module is no longer above the threshold
import { UmbContentCollectionManager } from '../collection/index.js';
import { UmbContentWorkspaceDataManager } from '../manager/index.js';
import { UmbMergeContentVariantDataController } from '../controller/merge-content-variant-data.controller.js';
Expand All @@ -9,6 +9,7 @@
import type { UmbContentWorkspaceContext } from './content-workspace-context.interface.js';
import { UmbContentDetailValidationPathTranslator } from './content-detail-validation-path-translator.js';
import { UmbContentValidationToHintsManager } from './content-validation-to-hints.manager.js';
import { UmbContentDetailWorkspaceTypeTransformController } from './content-detail-workspace-type-transform.controller.js';
import {
appendToFrozenArray,
mergeObservables,
Expand Down Expand Up @@ -154,6 +155,9 @@
* @internal
*/
public readonly languages = this.#languages.asObservable();
getLanguages(): Array<UmbLanguageDetailModel> {
return this.#languages.getValue();
}

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

Expand All @@ -178,12 +182,6 @@
#saveModalToken?: UmbModalToken<UmbContentVariantPickerData<VariantOptionModelType>, UmbContentVariantPickerValue>;
#contentTypePropertyName: string;

/**
* Cache of property variation settings to detect changes when structure is updated.
* Used to trigger value migration when properties change from invariant to variant or vice versa.
*/
#propertyVariationCache = new Map<string, { variesByCulture: boolean; variesBySegment: boolean }>();

constructor(
host: UmbControllerHost,
args: UmbContentDetailWorkspaceContextArgs<
Expand Down Expand Up @@ -228,6 +226,8 @@
this.view.hints,
);

new UmbContentDetailWorkspaceTypeTransformController(this as any);

this.variantOptions = mergeObservables(
[this.variesByCulture, this.variesBySegment, this.variants, this.languages, this._segments.asObservable()],
([variesByCulture, variesBySegment, variants, languages, segments]) => {
Expand Down Expand Up @@ -385,16 +385,6 @@
null,
);

// Observe property variation changes to trigger value migration when properties change
// from invariant to variant (or vice versa) via Infinite Editing
this.observe(
this.structure.contentTypeProperties,
(properties: Array<UmbPropertyTypeModel>) => {
this.#handlePropertyVariationChanges(properties);
},
null,
);

this.loadLanguages();
}

Expand Down Expand Up @@ -1108,68 +1098,7 @@
host: UmbControllerHost,
variantId: UmbVariantId,
): UmbContentPropertyDatasetContext<DetailModelType, ContentTypeDetailModelType, VariantModelType>;

Check notice on line 1101 in src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/content-detail-workspace-base.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (release/17.1)

✅ No longer an issue: Complex Method

handlePropertyVariationChanges is no longer above the threshold for cyclomatic complexity. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check notice on line 1101 in src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/content-detail-workspace-base.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (release/17.1)

✅ No longer an issue: Bumpy Road Ahead

handlePropertyVariationChanges is no longer above the threshold for logical blocks with deeply nested code. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
/**
* Handles property variation changes when the document type is updated via Infinite Editing.
* When a property's variation setting changes (e.g., from shared/invariant to variant or vice versa),
* this method reloads the document to get properly migrated values from the server.
*/
#handlePropertyVariationChanges(properties: Array<UmbPropertyTypeModel>): void {
// Skip if no current data or if this is initial load
const currentData = this._data.getCurrent();
if (!currentData || this.#propertyVariationCache.size === 0) {
// Initial load - just populate the cache
for (const property of properties) {
this.#propertyVariationCache.set(property.alias, {
variesByCulture: property.variesByCulture,
variesBySegment: property.variesBySegment,
});
}
return;
}

// Check for variation setting changes
let hasChanges = false;
for (const property of properties) {
const cached = this.#propertyVariationCache.get(property.alias);
if (cached) {
if (
cached.variesByCulture !== property.variesByCulture ||
cached.variesBySegment !== property.variesBySegment
) {
hasChanges = true;
}
}
// Update cache
this.#propertyVariationCache.set(property.alias, {
variesByCulture: property.variesByCulture,
variesBySegment: property.variesBySegment,
});
}

// If variation settings changed, reload to get properly migrated values
if (hasChanges) {
this.reload();
}
}

/**
* Override reload to process incoming data through the value migration pipeline.
* This ensures property values are properly transformed when variation settings change.
*/
public override async reload(): Promise<void> {
const unique = this.getUnique();
if (!unique) throw new Error('Unique is not set');
const { data } = await this._detailRepository!.requestByUnique(unique);

if (data) {
// Process the data through _processIncomingData to handle value migration
const processedData = await this._processIncomingData(data);
this._data.setPersisted(processedData);
this._data.setCurrent(processedData);
}
}

public override destroy(): void {
this.structure.destroy();
this.#languageRepository.destroy();
Expand Down
Loading
Loading