Skip to content

Commit

Permalink
correctly ordering advanced option groups (#18472)
Browse files Browse the repository at this point in the history
* correctly ordering advanced option groups

* separating group translations of individual items

* rename

* Bumping STS
  • Loading branch information
Benjin authored Dec 9, 2024
1 parent 12f0333 commit 3109fe9
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/configurations/config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
71 changes: 43 additions & 28 deletions src/connectionconfig/connectionDialogWebviewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
AddFirewallRuleDialogProps,
IConnectionDialogProfile,
TrustServerCertDialogProps,
ConnectionComponentsInfo,
ConnectionComponentGroup,
} from "../sharedInterfaces/connectionDialog";
import {
CapabilitiesResult,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -208,7 +209,7 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
"connectTimeout",
"multiSubnetFailover",
],
groupedAdvancedOptions: {}, // computed below
groupedAdvancedOptions: [], // computed below
};

this.state.connectionComponents.groupedAdvancedOptions =
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -699,36 +706,44 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
return result;
}

private groupAdvancedOptions({
components,
mainOptions,
topAdvancedOptions,
}: {
components: Partial<
Record<keyof IConnectionDialogProfile, ConnectionDialogFormItemSpec>
>;
mainOptions: (keyof IConnectionDialogProfile)[];
topAdvancedOptions: (keyof IConnectionDialogProfile)[];
}): Record<string, (keyof IConnectionDialogProfile)[]> {
const result = {};
private groupAdvancedOptions(
componentsInfo: ConnectionComponentsInfo,
): ConnectionComponentGroup[] {
const groupMap: Map<string, ConnectionComponentGroup> = 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<string>([
Expand Down
7 changes: 5 additions & 2 deletions src/models/contracts/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 > ----------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/reactviews/pages/ConnectionDialog/azureBrowsePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,43 +79,48 @@ export const AdvancedOptionsDrawer = ({
)}
</div>
<Accordion multiple collapsible>
{Object.keys(
context.state.connectionComponents
.groupedAdvancedOptions,
).map((group, groupIndex) => {
return (
<AccordionItem value={group} key={groupIndex}>
<AccordionHeader>{group}</AccordionHeader>
<AccordionPanel>
{context.state.connectionComponents.groupedAdvancedOptions[
group
].map((optionName, idx) => {
if (
context.state.connectionComponents
.components[optionName]
.hidden === true
) {
return undefined;
}
return (
<FormField
key={idx}
context={context}
component={
{context.state.connectionComponents.groupedAdvancedOptions.map(
(group, groupIndex) => {
return (
<AccordionItem
value={group.groupName}
key={groupIndex}
>
<AccordionHeader>
{group.groupName}
</AccordionHeader>
<AccordionPanel>
{group.options.map(
(optionName, idx) => {
if (
context.state
.connectionComponents
.components[
optionName
] as FormItemSpec<IConnectionDialogProfile>
.components[optionName]
?.hidden === true
) {
return undefined;
}
idx={idx}
/>
);
})}
</AccordionPanel>
</AccordionItem>
);
})}
return (
<FormField
key={idx}
context={context}
component={
context.state
.connectionComponents
.components[
optionName
] as FormItemSpec<IConnectionDialogProfile>
}
idx={idx}
/>
);
},
)}
</AccordionPanel>
</AccordionItem>
);
},
)}
</Accordion>
</DrawerBody>
</OverlayDrawer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
41 changes: 17 additions & 24 deletions src/sharedInterfaces/connectionDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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[];
Expand Down Expand Up @@ -130,10 +108,25 @@ export interface AzureSqlServerInfo {
subscription: string;
}

export interface ConnectionComponentsInfo {
components: Partial<
Record<keyof IConnectionDialogProfile, ConnectionDialogFormItemSpec>
>;
mainOptions: (keyof IConnectionDialogProfile)[];
topAdvancedOptions: (keyof IConnectionDialogProfile)[];
groupedAdvancedOptions: ConnectionComponentGroup[];
}

export interface ConnectionComponentGroup {
groupName: string;
options: (keyof IConnectionDialogProfile)[];
}

export interface ConnectionDialogFormItemSpec
extends FormItemSpec<IConnectionDialogProfile> {
isAdvancedOption: boolean;
optionCategory?: string;
optionCategoryLabel?: string;
}

export enum ConnectionInputMode {
Expand Down
64 changes: 64 additions & 0 deletions typings/vscode-mssql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 3109fe9

Please sign in to comment.