Skip to content

Fix issue preventing blueprint derived values from being scaffolded #18917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,47 +283,64 @@
await this.structure.loadType((data as any)[this.#contentTypePropertyName].unique);

// Set culture and segment for all values:
const cutlures = this.#languages.getValue().map((x) => x.unique);
const cultures = this.#languages.getValue().map((x) => x.unique);

if (this.structure.variesBySegment) {
console.warn('Segments are not yet implemented for preset');
}
const segments: Array<string> | undefined = this.structure.variesBySegment ? [] : undefined;

const repo = new UmbDataTypeDetailRepository(this);

const propertyTypes = await this.structure.getContentTypeProperties();
const valueDefinitions = await Promise.all(
propertyTypes.map(async (property) => {
// TODO: Implement caching for data-type requests. [NL]
const dataType = (await repo.requestByUnique(property.dataType.unique)).data;
// This means if its not loaded this will never resolve and the error below will never happen.
if (!dataType) {
throw new Error(`DataType of "${property.dataType.unique}" not found.`);
}
if (!dataType.editorUiAlias) {
throw new Error(`DataType of "${property.dataType.unique}" did not have a editorUiAlias.`);
}

return {
alias: property.alias,
propertyEditorUiAlias: dataType.editorUiAlias,
propertyEditorSchemaAlias: dataType.editorAlias,
config: dataType.values,
typeArgs: {
variesByCulture: property.variesByCulture,
variesBySegment: property.variesBySegment,
} as UmbPropertyTypePresetModelTypeModel,
} as UmbPropertyTypePresetModel;
}),
);

const controller = new UmbPropertyValuePresetVariantBuilderController(this);
controller.setCultures(cutlures);
controller.setCultures(cultures);
if (segments) {
controller.setSegments(segments);
}
data.values = await controller.create(valueDefinitions);

const presetValues = await controller.create(valueDefinitions);

// Don't just set the values, as we could have some already populated from a blueprint.
// If we have a value from both a blueprint and a preset, use the latter as priority.
const dataValues = [...data.values];
for (let index = 0; index < presetValues.length; index++) {
const presetValue = presetValues[index];
const variantId = UmbVariantId.Create(presetValue);
const matchingDataValueIndex = dataValues.findIndex((v) => v.alias === presetValue.alias && variantId.compare(v));
if (matchingDataValueIndex > -1) {
dataValues[matchingDataValueIndex] = presetValue;
} else {
dataValues.push(presetValue);
}
}

data.values = dataValues;

Check warning on line 343 in src/Umbraco.Web.UI.Client/src/packages/core/content/workspace/content-detail-workspace-base.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v15/dev)

❌ New issue: Complex Method

_scaffoldProcessData has a cyclomatic complexity of 11, threshold = 9. 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.

return data;
}
Expand Down
Loading