mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
change to freeze configuration models (#9644)
This commit is contained in:
@@ -13,6 +13,7 @@ import { generateUuid } from 'vs/base/common/uuid';
|
|||||||
import * as nls from 'vs/nls';
|
import * as nls from 'vs/nls';
|
||||||
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
import { find, firstIndex } from 'vs/base/common/arrays';
|
import { find, firstIndex } from 'vs/base/common/arrays';
|
||||||
|
import { deepClone } from 'vs/base/common/objects';
|
||||||
|
|
||||||
const GROUPS_CONFIG_KEY = 'datasource.connectionGroups';
|
const GROUPS_CONFIG_KEY = 'datasource.connectionGroups';
|
||||||
const CONNECTIONS_CONFIG_KEY = 'datasource.connections';
|
const CONNECTIONS_CONFIG_KEY = 'datasource.connections';
|
||||||
@@ -49,7 +50,7 @@ export class ConnectionConfig {
|
|||||||
}
|
}
|
||||||
allGroups = allGroups.concat(userValue);
|
allGroups = allGroups.concat(userValue);
|
||||||
}
|
}
|
||||||
return allGroups.map(g => {
|
return deepClone(allGroups).map(g => {
|
||||||
if (g.parentId === '' || !g.parentId) {
|
if (g.parentId === '' || !g.parentId) {
|
||||||
g.parentId = undefined;
|
g.parentId = undefined;
|
||||||
}
|
}
|
||||||
@@ -63,7 +64,7 @@ export class ConnectionConfig {
|
|||||||
public addConnection(profile: IConnectionProfile): Promise<IConnectionProfile> {
|
public addConnection(profile: IConnectionProfile): Promise<IConnectionProfile> {
|
||||||
if (profile.saveProfile) {
|
if (profile.saveProfile) {
|
||||||
return this.addGroupFromProfile(profile).then(groupId => {
|
return this.addGroupFromProfile(profile).then(groupId => {
|
||||||
let profiles = this.configurationService.inspect<IConnectionProfileStore[]>(CONNECTIONS_CONFIG_KEY).userValue;
|
let profiles = deepClone(this.configurationService.inspect<IConnectionProfileStore[]>(CONNECTIONS_CONFIG_KEY).userValue);
|
||||||
if (!profiles) {
|
if (!profiles) {
|
||||||
profiles = [];
|
profiles = [];
|
||||||
}
|
}
|
||||||
@@ -108,7 +109,7 @@ export class ConnectionConfig {
|
|||||||
if (profile.groupId && profile.groupId !== Utils.defaultGroupId) {
|
if (profile.groupId && profile.groupId !== Utils.defaultGroupId) {
|
||||||
return Promise.resolve(profile.groupId);
|
return Promise.resolve(profile.groupId);
|
||||||
} else {
|
} else {
|
||||||
let groups = this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).userValue;
|
let groups = deepClone(this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).userValue);
|
||||||
let result = this.saveGroup(groups!, profile.groupFullName, undefined, undefined);
|
let result = this.saveGroup(groups!, profile.groupFullName, undefined, undefined);
|
||||||
groups = result.groups;
|
groups = result.groups;
|
||||||
|
|
||||||
@@ -123,7 +124,7 @@ export class ConnectionConfig {
|
|||||||
if (profileGroup.id) {
|
if (profileGroup.id) {
|
||||||
return Promise.resolve(profileGroup.id);
|
return Promise.resolve(profileGroup.id);
|
||||||
} else {
|
} else {
|
||||||
let groups = this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).userValue;
|
let groups = deepClone(this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).userValue);
|
||||||
let sameNameGroup = groups ? find(groups, group => group.name === profileGroup.name) : undefined;
|
let sameNameGroup = groups ? find(groups, group => group.name === profileGroup.name) : undefined;
|
||||||
if (sameNameGroup) {
|
if (sameNameGroup) {
|
||||||
let errMessage: string = nls.localize('invalidServerName', "A server group with the same name already exists.");
|
let errMessage: string = nls.localize('invalidServerName', "A server group with the same name already exists.");
|
||||||
@@ -148,7 +149,7 @@ export class ConnectionConfig {
|
|||||||
fromConfig = configs.workspaceValue || [];
|
fromConfig = configs.workspaceValue || [];
|
||||||
}
|
}
|
||||||
if (fromConfig) {
|
if (fromConfig) {
|
||||||
profiles = fromConfig;
|
profiles = deepClone(fromConfig);
|
||||||
if (this.fixConnectionIds(profiles)) {
|
if (this.fixConnectionIds(profiles)) {
|
||||||
this.configurationService.updateValue(CONNECTIONS_CONFIG_KEY, profiles, configTarget);
|
this.configurationService.updateValue(CONNECTIONS_CONFIG_KEY, profiles, configTarget);
|
||||||
}
|
}
|
||||||
@@ -262,7 +263,7 @@ export class ConnectionConfig {
|
|||||||
* Moves the source group under the target group.
|
* Moves the source group under the target group.
|
||||||
*/
|
*/
|
||||||
public changeGroupIdForConnectionGroup(source: ConnectionProfileGroup, target: ConnectionProfileGroup): Promise<void> {
|
public changeGroupIdForConnectionGroup(source: ConnectionProfileGroup, target: ConnectionProfileGroup): Promise<void> {
|
||||||
let groups = this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).userValue;
|
let groups = deepClone(this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).userValue);
|
||||||
groups = groups!.map(g => {
|
groups = groups!.map(g => {
|
||||||
if (g.id === source.id) {
|
if (g.id === source.id) {
|
||||||
g.parentId = target.id;
|
g.parentId = target.id;
|
||||||
@@ -286,8 +287,8 @@ export class ConnectionConfig {
|
|||||||
* Moves the connection under the target group with the new ID.
|
* Moves the connection under the target group with the new ID.
|
||||||
*/
|
*/
|
||||||
private changeGroupIdForConnectionInSettings(profile: ConnectionProfile, newGroupID: string, target: ConfigurationTarget = ConfigurationTarget.USER): Promise<void> {
|
private changeGroupIdForConnectionInSettings(profile: ConnectionProfile, newGroupID: string, target: ConfigurationTarget = ConfigurationTarget.USER): Promise<void> {
|
||||||
let profiles = target === ConfigurationTarget.USER ? this.configurationService.inspect<IConnectionProfileStore[]>(CONNECTIONS_CONFIG_KEY).userValue :
|
let profiles = deepClone(target === ConfigurationTarget.USER ? this.configurationService.inspect<IConnectionProfileStore[]>(CONNECTIONS_CONFIG_KEY).userValue :
|
||||||
this.configurationService.inspect<IConnectionProfileStore[]>(CONNECTIONS_CONFIG_KEY).workspaceValue;
|
this.configurationService.inspect<IConnectionProfileStore[]>(CONNECTIONS_CONFIG_KEY).workspaceValue);
|
||||||
if (profiles) {
|
if (profiles) {
|
||||||
if (profile.parent && profile.parent.id === UNSAVED_GROUP_ID) {
|
if (profile.parent && profile.parent.id === UNSAVED_GROUP_ID) {
|
||||||
profile.groupId = newGroupID;
|
profile.groupId = newGroupID;
|
||||||
@@ -328,7 +329,7 @@ export class ConnectionConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public editGroup(source: ConnectionProfileGroup): Promise<void> {
|
public editGroup(source: ConnectionProfileGroup): Promise<void> {
|
||||||
let groups = this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).userValue;
|
let groups = deepClone(this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).userValue);
|
||||||
let sameNameGroup = groups ? find(groups, group => group.name === source.name && group.id !== source.id) : undefined;
|
let sameNameGroup = groups ? find(groups, group => group.name === source.name && group.id !== source.id) : undefined;
|
||||||
if (sameNameGroup) {
|
if (sameNameGroup) {
|
||||||
let errMessage: string = nls.localize('invalidServerName', "A server group with the same name already exists.");
|
let errMessage: string = nls.localize('invalidServerName', "A server group with the same name already exists.");
|
||||||
|
|||||||
@@ -489,6 +489,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
this._logService.error(message);
|
||||||
this._errorMessageService.showDialog(severity, headerTitle, message, messageDetails, actions);
|
this._errorMessageService.showDialog(severity, headerTitle, message, messageDetails, actions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,8 +122,7 @@ export class ConfigurationModel implements IConfigurationModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
freeze(): ConfigurationModel {
|
freeze(): ConfigurationModel {
|
||||||
// {{SQL CARBON EDIT}} @todo anthonydresser 4/12/19 needs investigation; we shouldn't need to do this
|
this.isFrozen = true;
|
||||||
// this.isFrozen = true;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user