Skip to content

Commit e9ef050

Browse files
authoredMar 3, 2025··
V15: Adds migration of data type configuration when changing property editor UI (#18534)
* feat: adds comparer to keep useful data around when migrating from one property editor ui to another this is really useful when migrating from tinymce to tiptap for example * stores values in property to access later
1 parent 8379cba commit e9ef050

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed
 

‎src/Umbraco.Web.UI.Client/src/packages/data-type/workspace/data-type-workspace.context.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,35 @@ export class UmbDataTypeWorkspaceContext
227227
const data = this._data.getCurrent();
228228
if (!data) return;
229229

230+
// We are going to transfer the default data from the schema and the UI (the UI can override the schema data).
231+
// Let us figure out which editors are alike from the inherited data, so we can keep that data around and only transfer the data that is not
232+
// inherited from the previous data type.
230233
this.#settingsDefaultData = [
231234
...this.#propertyEditorSchemaSettingsDefaultData,
232235
...this.#propertyEditorUISettingsDefaultData,
233236
] satisfies Array<UmbDataTypePropertyValueModel>;
234-
// We check for satisfied type, because we will be directly transferring them to become value. Future note, if they are not satisfied, we need to transfer alias and value. [NL]
235237

236-
this._data.updatePersisted({ values: this.#settingsDefaultData });
237-
this._data.updateCurrent({ values: this.#settingsDefaultData });
238+
const values: Array<UmbDataTypePropertyValueModel> = [];
239+
240+
// We want to keep the existing data, if it is not in the default data, and if it is in the default data, then we want to keep the default data.
241+
for (const defaultDataItem of this.#properties.getValue()) {
242+
// We are matching on the alias, as we assume that the alias is unique for the data type.
243+
// TODO: Consider if we should also match on the editorAlias just to be on the safe side [JOV]
244+
const existingData = data.values?.find((x) => x.alias === defaultDataItem.alias);
245+
if (existingData) {
246+
values.push(existingData);
247+
continue;
248+
}
249+
250+
// If the data is not in the existing data, then we want to add the default data if it exists.
251+
const existingDefaultData = this.#settingsDefaultData.find((x) => x.alias === defaultDataItem.alias);
252+
if (existingDefaultData) {
253+
values.push(existingDefaultData);
254+
}
255+
}
256+
257+
this._data.updatePersisted({ values });
258+
this._data.updateCurrent({ values });
238259
}
239260

240261
public getPropertyDefaultValue(alias: string) {

‎tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/DataType/DataType.spec.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ test('can change property editor in a data type', {tag: '@smoke'}, async ({umbra
6565
const updatedEditorName = 'Text Area';
6666
const updatedEditorAlias = 'Umbraco.TextArea';
6767
const updatedEditorUiAlias = 'Umb.PropertyEditorUi.TextArea';
68+
const maxChars = 999;
6869

69-
await umbracoApi.dataType.createTextstringDataType(dataTypeName);
70+
await umbracoApi.dataType.createTextstringDataType(dataTypeName, maxChars);
7071
expect(await umbracoApi.dataType.doesNameExist(dataTypeName)).toBeTruthy();
7172

7273
// Act
@@ -81,6 +82,9 @@ test('can change property editor in a data type', {tag: '@smoke'}, async ({umbra
8182
const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName);
8283
expect(dataTypeData.editorAlias).toBe(updatedEditorAlias);
8384
expect(dataTypeData.editorUiAlias).toBe(updatedEditorUiAlias);
85+
86+
const maxCharsSetting = dataTypeData.values.find((x: {alias: string, value: unknown}) => x.alias === 'maxChars');
87+
expect(maxCharsSetting.value, 'Stored configuration should be transferred').toBe(maxChars);
8488
});
8589

8690
test('cannot create a data type without selecting the property editor', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => {

0 commit comments

Comments
 (0)
Please sign in to comment.