Skip to content
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

[Settings Editor] Correctly handle null default values for objects #101807

Merged
merged 1 commit into from
Jul 6, 2020
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
30 changes: 22 additions & 8 deletions src/vs/workbench/contrib/preferences/browser/settingsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,17 @@ function getObjectValueType(schema: IJSONSchema): ObjectValue['type'] {
}

function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectDataItem[] {
const elementDefaultValue: Record<string, unknown> = typeof element.defaultValue === 'object'
? element.defaultValue ?? {}
: {};

const elementScopeValue: Record<string, unknown> = typeof element.scopeValue === 'object'
? element.scopeValue ?? {}
: {};

const data = element.isConfigured ?
{ ...element.defaultValue, ...element.scopeValue } :
element.defaultValue;
{ ...elementDefaultValue, ...elementScopeValue } :
elementDefaultValue;

const { objectProperties, objectPatternProperties, objectAdditionalProperties } = element.setting;
const patternsAndSchemas = Object
Expand All @@ -129,7 +137,7 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData

return Object.keys(data).map(key => {
if (isDefined(objectProperties) && key in objectProperties) {
const defaultValue = element.defaultValue[key];
const defaultValue = elementDefaultValue[key];
const valueEnumOptions = getEnumOptionsFromSchema(objectProperties[key]);

return {
Expand All @@ -144,7 +152,7 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData
options: valueEnumOptions,
},
removable: isUndefinedOrNull(defaultValue),
};
} as IObjectDataItem;
}

const schema = patternsAndSchemas.find(({ pattern }) => pattern.test(key))?.schema;
Expand All @@ -159,7 +167,7 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData
options: valueEnumOptions,
},
removable: true,
};
} as IObjectDataItem;
}

return {
Expand All @@ -170,7 +178,7 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData
options: additionalValueEnums,
},
removable: true,
};
} as IObjectDataItem;
});
}

Expand Down Expand Up @@ -1055,8 +1063,14 @@ export class SettingObjectRenderer extends AbstractSettingRenderer implements IT

private onDidChangeObject(template: ISettingObjectItemTemplate, e: ISettingListChangeEvent<IObjectDataItem>): void {
if (template.context) {
const defaultValue: Record<string, unknown> = template.context.defaultValue;
const scopeValue: Record<string, unknown> = template.context.scopeValue;
const defaultValue: Record<string, unknown> = typeof template.context.defaultValue === 'object'
? template.context.defaultValue ?? {}
: {};

const scopeValue: Record<string, unknown> = typeof template.context.scopeValue === 'object'
? template.context.scopeValue ?? {}
: {};

const newValue: Record<string, unknown> = {};
let newItems: IObjectDataItem[] = [];

Expand Down