Skip to content
Merged
Show file tree
Hide file tree
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 @@ -227,14 +227,35 @@ export class UmbDataTypeWorkspaceContext
const data = this._data.getCurrent();
if (!data) return;

// We are going to transfer the default data from the schema and the UI (the UI can override the schema data).
// 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
// inherited from the previous data type.
this.#settingsDefaultData = [
...this.#propertyEditorSchemaSettingsDefaultData,
...this.#propertyEditorUISettingsDefaultData,
] satisfies Array<UmbDataTypePropertyValueModel>;
// 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]

this._data.updatePersisted({ values: this.#settingsDefaultData });
this._data.updateCurrent({ values: this.#settingsDefaultData });
const values: Array<UmbDataTypePropertyValueModel> = [];

// 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.
for (const defaultDataItem of this.#properties.getValue()) {
// We are matching on the alias, as we assume that the alias is unique for the data type.
// TODO: Consider if we should also match on the editorAlias just to be on the safe side [JOV]
const existingData = data.values?.find((x) => x.alias === defaultDataItem.alias);
if (existingData) {
values.push(existingData);
continue;
}

// If the data is not in the existing data, then we want to add the default data if it exists.
const existingDefaultData = this.#settingsDefaultData.find((x) => x.alias === defaultDataItem.alias);
if (existingDefaultData) {
values.push(existingDefaultData);
}
}

this._data.updatePersisted({ values });
this._data.updateCurrent({ values });
}

public getPropertyDefaultValue(alias: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ test('can change property editor in a data type', {tag: '@smoke'}, async ({umbra
const updatedEditorName = 'Text Area';
const updatedEditorAlias = 'Umbraco.TextArea';
const updatedEditorUiAlias = 'Umb.PropertyEditorUi.TextArea';
const maxChars = 999;

await umbracoApi.dataType.createTextstringDataType(dataTypeName);
await umbracoApi.dataType.createTextstringDataType(dataTypeName, maxChars);
expect(await umbracoApi.dataType.doesNameExist(dataTypeName)).toBeTruthy();

// Act
Expand All @@ -81,6 +82,9 @@ test('can change property editor in a data type', {tag: '@smoke'}, async ({umbra
const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName);
expect(dataTypeData.editorAlias).toBe(updatedEditorAlias);
expect(dataTypeData.editorUiAlias).toBe(updatedEditorUiAlias);

const maxCharsSetting = dataTypeData.values.find((x: {alias: string, value: unknown}) => x.alias === 'maxChars');
expect(maxCharsSetting.value, 'Stored configuration should be transferred').toBe(maxChars);
});

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