mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-24 09:35:37 -05:00
Changed connection title generation to use getConnections (including recent and saved). (#22954)
* remove advanced options for table designer and notebook Actions title (unnecessary in usage context)
* Revert "remove advanced options for table designer and notebook Actions title (unnecessary in usage context)"
This reverts commit e30aee5151319863aebbb4738fb30354c179c2c5.
* added changes based on feedback
* added null check and updated tests
* WIP change to connection title generation
* WIP connection management service update
* fix to connectionManagementService test
* fix editorConnectionTitles
* renamed nondefault to distinguishing options
* use stored connections for options
* removed erroneous connection name set to null
* added title by ID search for title generation
* Add recent connection title
* added fix for stub bug
* added child title options appended
* WIP rework of getEditorTitle
* more work done
* WIP changes for 5-2-2023
* moved server info to generate titles.
* added reworked title generation
* added working active connection title generation and cleanup
* added comments to argument
* remove unnecessary spaces
* added id fix assign
* added fromEditor save
* Revert "Revert new connection string format (#22997)"
This reverts commit 898bb73a34.
* added small fix to tests and exclude empty properties
* made small fixes for tests
* update expected ID
* added support for old password key and removed empty options
* added in authenticationType core property
* fix for whitespace indentation
* added connection save profile to thing
* made some small fixes to connection options
* added small change to connectionDialogService
* added nullcheck for saveProfile
* added negation for connection saveProfile
* remove duplicate editor title generation
* added edit profile handling for titles
* Cleanup serverCapabilities property
* fixed dependency issues
* removed connectionproviderproperties
* added fix for treeupdateutils
* made update to title generation
* added recent connections change
* Revert "Cleanup serverCapabilities property"
This reverts commit 2c7b94f98cabddb34116dcdd83177614a484c026.
* added dashboard text and fix for connection store test
* added group name to end also temporary added dashboard changes based on feedback
* added in new SQL version
* added fix to edit connections
* added clarifying information to title generation
---------
Co-authored-by: Cheena Malhotra <cmalhotra@microsoft.com>
This commit is contained in:
@@ -724,6 +724,183 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
return result;
|
||||
}
|
||||
|
||||
public getEditorConnectionProfileTitle(profile: interfaces.IConnectionProfile, getOptionsOnly?: boolean, includeGroupName: boolean = true): string {
|
||||
let result = '';
|
||||
if (profile) {
|
||||
let tempProfile = new ConnectionProfile(this._capabilitiesService, profile);
|
||||
let trimTitle = tempProfile.getOriginalTitle();
|
||||
let idToFind = tempProfile.id;
|
||||
let isChild = false;
|
||||
let totalConnections: ConnectionProfile[] = [];
|
||||
let allConnections = this.getConnections();
|
||||
|
||||
totalConnections = totalConnections.concat(allConnections);
|
||||
|
||||
let initialSearch = totalConnections.filter(inputProfile => {
|
||||
return inputProfile.id === tempProfile.id;
|
||||
});
|
||||
|
||||
let secondarySearch = totalConnections.filter(inputProfile => {
|
||||
return inputProfile.matches(tempProfile)
|
||||
});
|
||||
|
||||
if (initialSearch.length === 0) {
|
||||
if (secondarySearch.length === 1) {
|
||||
// Sometimes the connection id will change for an object explorer connection, especially when connecting from dashboard,
|
||||
// and it will identify as different from the stored one even without changes. Get the info for the stored version as it's the same profile.
|
||||
idToFind = secondarySearch[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle case where a profile may have been an edited existing connection (the one retrieved may not be up to date)
|
||||
if (initialSearch.length === 1 && !initialSearch[0].matches(tempProfile)) {
|
||||
// Remove the old profile with outdated information.
|
||||
totalConnections = totalConnections.filter(inputProfile => {
|
||||
return inputProfile.id !== tempProfile.id;
|
||||
});
|
||||
// Replace with up to date version of the profile.
|
||||
totalConnections = totalConnections.concat(tempProfile);
|
||||
}
|
||||
|
||||
let newConnectionTitles = [];
|
||||
|
||||
this.generateEditorConnectionTitles(totalConnections);
|
||||
if (includeGroupName) {
|
||||
this.appendGroupName(totalConnections);
|
||||
}
|
||||
newConnectionTitles = totalConnections;
|
||||
|
||||
let searchResult = newConnectionTitles.filter(inputProfile => inputProfile.id === idToFind);
|
||||
let finalTitle = searchResult[0]?.title;
|
||||
if (finalTitle) {
|
||||
let optionsAppend = finalTitle.substring(trimTitle.length);
|
||||
if (getOptionsOnly) {
|
||||
finalTitle = optionsAppend;
|
||||
}
|
||||
else if (!getOptionsOnly && isChild) {
|
||||
finalTitle = tempProfile.getOriginalTitle() + optionsAppend;
|
||||
}
|
||||
else {
|
||||
finalTitle = searchResult[0].getOriginalTitle() + optionsAppend;
|
||||
}
|
||||
result = finalTitle;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the connection title to display only the unique properties among profiles provided. (used for editors)
|
||||
*/
|
||||
private generateEditorConnectionTitles(inputList: ConnectionProfile[]): void {
|
||||
let profileListMap = new Map<string, number[]>();
|
||||
// Need to reset title to when it was before (as it may have contained a previously generated title)
|
||||
for (let i = 0; i < inputList.length; i++) {
|
||||
inputList[i].title = inputList[i].getOriginalTitle();
|
||||
}
|
||||
|
||||
// Map the indices of profiles that share the same server info
|
||||
for (let i = 0; i < inputList.length; i++) {
|
||||
// do not add if the profile is still loading as that will result in erroneous entries.
|
||||
if (inputList[i].serverCapabilities && inputList[i].hasLoaded()) {
|
||||
let titleKey = inputList[i].getOriginalTitle();
|
||||
if (profileListMap.has(titleKey)) {
|
||||
let profilesForKey = profileListMap.get(titleKey);
|
||||
profilesForKey.push(i);
|
||||
profileListMap.set(titleKey, profilesForKey);
|
||||
}
|
||||
else {
|
||||
profileListMap.set(titleKey, [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
profileListMap.forEach(function (indexes, titleString) {
|
||||
if (profileListMap.get(titleString)?.length > 1) {
|
||||
let combinedOptions = [];
|
||||
let needSpecial = false;
|
||||
if (titleString === inputList[indexes[0]].connectionName) {
|
||||
// check for potential connections with the same name but technically different connections.
|
||||
let listOfDuplicates = indexes.filter(item => inputList[item].getOptionsKey() !== inputList[indexes[0]].getOptionsKey());
|
||||
if (listOfDuplicates.length > 0) {
|
||||
// if we do find duplicates, we will need to include the special properties.
|
||||
needSpecial = true;
|
||||
}
|
||||
}
|
||||
indexes.forEach((indexValue) => {
|
||||
// Add all possible options across all profiles with the same title to an option list.
|
||||
let valueOptions = inputList[indexValue].getConnectionOptionsList(needSpecial, false);
|
||||
combinedOptions = combinedOptions.concat(valueOptions.filter(item => combinedOptions.indexOf(item) < 0));
|
||||
});
|
||||
|
||||
// Generate list of non default option keys for each profile that shares the same server info.
|
||||
let optionKeyMap = new Map<ConnectionProfile, string[]>();
|
||||
let optionValueOccuranceMap = new Map<string, number>();
|
||||
for (let p = 0; p < indexes.length; p++) {
|
||||
optionKeyMap.set(inputList[indexes[p]], []);
|
||||
for (let i = 0; i < combinedOptions.length; i++) {
|
||||
// See if the option is not default for the inputList profile or is.
|
||||
if (inputList[indexes[p]].getConnectionOptionsList(needSpecial, true).indexOf(combinedOptions[i]) > -1) {
|
||||
let optionValue = inputList[indexes[p]].getOptionValue(combinedOptions[i].name);
|
||||
let currentArray = optionKeyMap.get(inputList[indexes[p]]);
|
||||
let valueString = combinedOptions[i].name + ConnectionProfile.displayNameValueSeparator + optionValue;
|
||||
if (!optionValueOccuranceMap.get(valueString)) {
|
||||
optionValueOccuranceMap.set(valueString, 0);
|
||||
}
|
||||
optionValueOccuranceMap.set(valueString, optionValueOccuranceMap.get(valueString) + 1);
|
||||
currentArray.push(valueString);
|
||||
optionKeyMap.set(inputList[indexes[p]], currentArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out options that are found in ALL the entries with the same server info.
|
||||
optionValueOccuranceMap.forEach(function (count, optionValue) {
|
||||
optionKeyMap.forEach(function (connOptionValues, profile) {
|
||||
if (count === optionKeyMap.size) {
|
||||
optionKeyMap.set(profile, connOptionValues.filter(value => value !== optionValue));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Generate the final unique connection string for each profile in the list.
|
||||
optionKeyMap.forEach(function (connOptionValues, profile) {
|
||||
let uniqueOptionString = connOptionValues.join(ConnectionProfile.displayIdSeparator);
|
||||
if (uniqueOptionString.length > 0) {
|
||||
profile.title = profile.getOriginalTitle() + ' (' + uniqueOptionString + ')';
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private appendGroupName(inputList: ConnectionProfile[]): void {
|
||||
let profileListMap = new Map<string, number[]>();
|
||||
|
||||
// Map the indices of profiles that share the same server group
|
||||
for (let i = 0; i < inputList.length; i++) {
|
||||
let groupName = inputList[i].groupFullName;
|
||||
if (profileListMap.has(groupName)) {
|
||||
let profilesForKey = profileListMap.get(groupName);
|
||||
profilesForKey.push(i);
|
||||
profileListMap.set(groupName, profilesForKey);
|
||||
}
|
||||
else {
|
||||
profileListMap.set(groupName, [i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (profileListMap.size > 1) {
|
||||
profileListMap.forEach(function (indexes, groupName) {
|
||||
for (let t = 0; t < indexes.length; t++) {
|
||||
if (groupName !== '') {
|
||||
inputList[indexes[t]].title += nls.localize('connection.connTitleGroupSection', ' (Group: {0})', groupName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private doActionsAfterConnectionComplete(uri: string, options: IConnectionCompletionOptions): void {
|
||||
let connectionManagementInfo = this._connectionStatusManager.findConnection(uri);
|
||||
if (!connectionManagementInfo) {
|
||||
@@ -1298,7 +1475,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
this._connectionGlobalStatus.setStatusToConnected(info.connectionSummary);
|
||||
}
|
||||
|
||||
const connectionUniqueId = connection.connectionProfile.getConnectionInfoId();
|
||||
const connectionUniqueId = connection.connectionProfile.getOptionsKey();
|
||||
if (info.isSupportedVersion === false
|
||||
&& this._connectionsGotUnsupportedVersionWarning.indexOf(connectionUniqueId) === -1
|
||||
&& this._configurationService.getValue<boolean>('connection.showUnsupportedServerVersionWarning')) {
|
||||
|
||||
Reference in New Issue
Block a user