From 3109fe9681b9c333f53c50e549cffe30150570b3 Mon Sep 17 00:00:00 2001 From: Benjin Dubishar Date: Mon, 9 Dec 2024 11:55:02 -0800 Subject: [PATCH] correctly ordering advanced option groups (#18472) * correctly ordering advanced option groups * separating group translations of individual items * rename * Bumping STS --- src/configurations/config.json | 2 +- .../connectionDialogWebviewController.ts | 71 +++++++++++------- src/models/contracts/connection.ts | 7 +- .../ConnectionDialog/azureBrowsePage.tsx | 2 +- .../advancedOptionsDrawer.component.tsx | 73 ++++++++++--------- .../ConnectionDialog/connectionFormPage.tsx | 2 +- src/sharedInterfaces/connectionDialog.ts | 41 +++++------ typings/vscode-mssql.d.ts | 64 ++++++++++++++++ 8 files changed, 171 insertions(+), 91 deletions(-) diff --git a/src/configurations/config.json b/src/configurations/config.json index 364ce696a9..f89f19287d 100644 --- a/src/configurations/config.json +++ b/src/configurations/config.json @@ -1,7 +1,7 @@ { "service": { "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", - "version": "5.0.20241112.1", + "version": "5.0.20241206.1", "downloadFileNames": { "Windows_86": "win-x86-net8.0.zip", "Windows_64": "win-x64-net8.0.zip", diff --git a/src/connectionconfig/connectionDialogWebviewController.ts b/src/connectionconfig/connectionDialogWebviewController.ts index e50dc2b5be..439acb39e8 100644 --- a/src/connectionconfig/connectionDialogWebviewController.ts +++ b/src/connectionconfig/connectionDialogWebviewController.ts @@ -21,6 +21,8 @@ import { AddFirewallRuleDialogProps, IConnectionDialogProfile, TrustServerCertDialogProps, + ConnectionComponentsInfo, + ConnectionComponentGroup, } from "../sharedInterfaces/connectionDialog"; import { CapabilitiesResult, @@ -53,8 +55,7 @@ import { import { ApiStatus } from "../sharedInterfaces/webview"; import { AzureController } from "../azure/azureController"; import { AzureSubscription } from "@microsoft/vscode-azext-azureauth"; -import { ConnectionOption } from "azdata"; -import { IConnectionInfo } from "vscode-mssql"; +import { IConnectionInfo, ConnectionOption } from "vscode-mssql"; import { Logger } from "../models/logger"; import MainController from "../controllers/mainController"; import { ObjectExplorerProvider } from "../objectExplorer/objectExplorerProvider"; @@ -103,7 +104,7 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll components: {} as any, // force empty record for intial blank state mainOptions: [], topAdvancedOptions: [], - groupedAdvancedOptions: {}, + groupedAdvancedOptions: [], }, azureSubscriptions: [], azureServers: [], @@ -208,7 +209,7 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll "connectTimeout", "multiSubnetFailover", ], - groupedAdvancedOptions: {}, // computed below + groupedAdvancedOptions: [], // computed below }; this.state.connectionComponents.groupedAdvancedOptions = @@ -663,6 +664,10 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll const connectionOptions: ConnectionOption[] = capabilitiesResult.capabilities.connectionProvider.options; + const groupNames = + capabilitiesResult.capabilities.connectionProvider + .groupDisplayNames; + const result: Record< keyof IConnectionDialogProfile, ConnectionDialogFormItemSpec @@ -675,6 +680,8 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll ...this.convertToFormComponent(option), isAdvancedOption: !this._mainOptionNames.has(option.name), optionCategory: option.groupName, + optionCategoryLabel: + groupNames[option.groupName] ?? option.groupName, }; } catch (err) { console.error( @@ -699,36 +706,44 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll return result; } - private groupAdvancedOptions({ - components, - mainOptions, - topAdvancedOptions, - }: { - components: Partial< - Record - >; - mainOptions: (keyof IConnectionDialogProfile)[]; - topAdvancedOptions: (keyof IConnectionDialogProfile)[]; - }): Record { - const result = {}; + private groupAdvancedOptions( + componentsInfo: ConnectionComponentsInfo, + ): ConnectionComponentGroup[] { + const groupMap: Map = new Map([ + // intialize with display order; any that aren't pre-defined will be appended + // these values must match the GroupName defined in SQL Tools Service. + ["security", undefined], + ["initialization", undefined], + ["resiliency", undefined], + ["pooling", undefined], + ["context", undefined], + ]); + + const optionsToGroup = Object.values(componentsInfo.components).filter( + (c) => + c.isAdvancedOption && + !componentsInfo.mainOptions.includes(c.propertyName) && + !componentsInfo.topAdvancedOptions.includes(c.propertyName), + ); - for (const component of Object.values(components)) { + for (const option of optionsToGroup) { if ( - component.isAdvancedOption && - !mainOptions.includes(component.propertyName) && - !topAdvancedOptions.includes(component.propertyName) + // new group ID or group ID hasn't been initialized yet + !groupMap.has(option.optionCategory) || + groupMap.get(option.optionCategory) === undefined ) { - if (!result[component.optionCategory]) { - result[component.optionCategory] = [component.propertyName]; - } else { - result[component.optionCategory].push( - component.propertyName, - ); - } + groupMap.set(option.optionCategory, { + groupName: option.optionCategoryLabel, + options: [option.propertyName], + }); + } else { + groupMap + .get(option.optionCategory) + .options.push(option.propertyName); } } - return result; + return Array.from(groupMap.values()); } private _mainOptionNames = new Set([ diff --git a/src/models/contracts/connection.ts b/src/models/contracts/connection.ts index e48260f667..2af2406081 100644 --- a/src/models/contracts/connection.ts +++ b/src/models/contracts/connection.ts @@ -3,9 +3,12 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { DataProtocolServerCapabilities } from "azdata"; import { NotificationType, RequestType } from "vscode-languageclient"; -import { ConnectionDetails, IServerInfo } from "vscode-mssql"; +import { + ConnectionDetails, + IServerInfo, + DataProtocolServerCapabilities, +} from "vscode-mssql"; // ------------------------------- < Connect Request > ---------------------------------------------- diff --git a/src/reactviews/pages/ConnectionDialog/azureBrowsePage.tsx b/src/reactviews/pages/ConnectionDialog/azureBrowsePage.tsx index 58eb353069..cb38ba97b2 100644 --- a/src/reactviews/pages/ConnectionDialog/azureBrowsePage.tsx +++ b/src/reactviews/pages/ConnectionDialog/azureBrowsePage.tsx @@ -380,7 +380,7 @@ export const AzureBrowsePage = () => { context.state.connectionComponents.components[ inputName as keyof IConnectionDialogProfile ]; - if (component.hidden === true) { + if (component?.hidden !== false) { return undefined; } diff --git a/src/reactviews/pages/ConnectionDialog/components/advancedOptionsDrawer.component.tsx b/src/reactviews/pages/ConnectionDialog/components/advancedOptionsDrawer.component.tsx index d29db29057..e08290521d 100644 --- a/src/reactviews/pages/ConnectionDialog/components/advancedOptionsDrawer.component.tsx +++ b/src/reactviews/pages/ConnectionDialog/components/advancedOptionsDrawer.component.tsx @@ -79,43 +79,48 @@ export const AdvancedOptionsDrawer = ({ )} - {Object.keys( - context.state.connectionComponents - .groupedAdvancedOptions, - ).map((group, groupIndex) => { - return ( - - {group} - - {context.state.connectionComponents.groupedAdvancedOptions[ - group - ].map((optionName, idx) => { - if ( - context.state.connectionComponents - .components[optionName] - .hidden === true - ) { - return undefined; - } - return ( - { + return ( + + + {group.groupName} + + + {group.options.map( + (optionName, idx) => { + if ( context.state .connectionComponents - .components[ - optionName - ] as FormItemSpec + .components[optionName] + ?.hidden === true + ) { + return undefined; } - idx={idx} - /> - ); - })} - - - ); - })} + return ( + + } + idx={idx} + /> + ); + }, + )} + + + ); + }, + )} diff --git a/src/reactviews/pages/ConnectionDialog/connectionFormPage.tsx b/src/reactviews/pages/ConnectionDialog/connectionFormPage.tsx index aead82f7ab..729fb6c6bf 100644 --- a/src/reactviews/pages/ConnectionDialog/connectionFormPage.tsx +++ b/src/reactviews/pages/ConnectionDialog/connectionFormPage.tsx @@ -30,7 +30,7 @@ export const ConnectionFormPage = () => { context.state.connectionComponents.components[ inputName as keyof IConnectionDialogProfile ]; - if (component.hidden === true) { + if (component?.hidden !== false) { return undefined; } diff --git a/src/sharedInterfaces/connectionDialog.ts b/src/sharedInterfaces/connectionDialog.ts index 519221da6c..4484bdf55e 100644 --- a/src/sharedInterfaces/connectionDialog.ts +++ b/src/sharedInterfaces/connectionDialog.ts @@ -25,18 +25,7 @@ export class ConnectionDialogWebviewState this.formState = value; } public selectedInputMode: ConnectionInputMode; - public connectionComponents: { - components: Record< - keyof IConnectionDialogProfile, - ConnectionDialogFormItemSpec - >; - mainOptions: (keyof IConnectionDialogProfile)[]; - topAdvancedOptions: (keyof IConnectionDialogProfile)[]; - groupedAdvancedOptions: Record< - string, - (keyof IConnectionDialogProfile)[] - >; - }; + public connectionComponents: ConnectionComponentsInfo; public azureSubscriptions: AzureSubscriptionInfo[]; public azureServers: AzureSqlServerInfo[]; public savedConnections: IConnectionDialogProfile[]; @@ -63,18 +52,7 @@ export class ConnectionDialogWebviewState }: { connectionProfile: IConnectionDialogProfile; selectedInputMode: ConnectionInputMode; - connectionComponents: { - components: Record< - keyof IConnectionDialogProfile, - ConnectionDialogFormItemSpec - >; - mainOptions: (keyof IConnectionDialogProfile)[]; - topAdvancedOptions: (keyof IConnectionDialogProfile)[]; - groupedAdvancedOptions: Record< - string, - (keyof IConnectionDialogProfile)[] - >; - }; + connectionComponents: ConnectionComponentsInfo; azureServers: AzureSqlServerInfo[]; azureSubscriptions: AzureSubscriptionInfo[]; savedConnections: IConnectionDialogProfile[]; @@ -130,10 +108,25 @@ export interface AzureSqlServerInfo { subscription: string; } +export interface ConnectionComponentsInfo { + components: Partial< + Record + >; + mainOptions: (keyof IConnectionDialogProfile)[]; + topAdvancedOptions: (keyof IConnectionDialogProfile)[]; + groupedAdvancedOptions: ConnectionComponentGroup[]; +} + +export interface ConnectionComponentGroup { + groupName: string; + options: (keyof IConnectionDialogProfile)[]; +} + export interface ConnectionDialogFormItemSpec extends FormItemSpec { isAdvancedOption: boolean; optionCategory?: string; + optionCategoryLabel?: string; } export enum ConnectionInputMode { diff --git a/typings/vscode-mssql.d.ts b/typings/vscode-mssql.d.ts index b289e8cc37..1510362b91 100644 --- a/typings/vscode-mssql.d.ts +++ b/typings/vscode-mssql.d.ts @@ -1604,6 +1604,70 @@ declare module 'vscode-mssql' { options: { [name: string]: any }; } + export interface DataProtocolServerCapabilities { + protocolVersion: string; + + providerName: string; + + providerDisplayName: string; + + connectionProvider: ConnectionProviderOptions; + + adminServicesProvider: AdminServicesOptions; + + features: FeatureMetadataProvider[]; + } + + export interface ConnectionProviderOptions { + options: ConnectionOption[]; + + groupDisplayNames: { [groupId: string]: string }; + } + + export interface ServiceOption { + name: string; + + displayName: string; + + description: string; + + groupName: string; + + valueType: ServiceOptionType; + + defaultValue: string; + + objectType: string; + + categoryValues: CategoryValue[]; + + isRequired: boolean; + + isArray: boolean; + } + + export interface ConnectionOption extends ServiceOption { + specialValueType: ConnectionOptionSpecialType; + + isIdentity: boolean; + } + + export interface AdminServicesOptions { + databaseInfoOptions: ServiceOption[]; + + databaseFileInfoOptions: ServiceOption[]; + + fileGroupInfoOptions: ServiceOption[]; + } + + export interface FeatureMetadataProvider { + enabled: boolean; + + featureName: string; + + optionsMetadata: ServiceOption[]; + } + /** * Namespace for Azure APIs */