Skip to content

Commit

Permalink
Adding Group by schema to OE (#17543)
Browse files Browse the repository at this point in the history
* Adding group by schema

* Adding group by schema

* Adding strings

* removing local config

* Fixing formatting

* Adding enable and disable group by schema menu item

* Fixing node refresh logic

* Fixing lint

* changing default

* Adding error message

* Fixing stuff

* Fixing error message

* fixing error message

* Update localization/xliff/enu/constants/localizedConstants.enu.xlf

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>

* Pushing new sts version

---------

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
  • Loading branch information
aasimkhan30 and Charles-Gagnon authored Feb 21, 2023
1 parent 5b76c23 commit bcdec95
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 39 deletions.
6 changes: 6 additions & 0 deletions localization/xliff/enu/constants/localizedConstants.enu.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@
<trans-unit id="columnWidthMustBePositiveError">
<source xml:lang="en">Width cannot be 0 or negative</source>
</trans-unit>
<trans-unit id="objectExplorerNodeRefreshError">
<source xml:lang="en">An error occurred refreshing nodes. See the MSSQL output channel for more details.</source>
</trans-unit>
<trans-unit id="showOutputChannelActionButtonText">
<source xml:lang="en">Show MSSQL output</source>
</trans-unit>
</body>
</file>
</xliff>
9 changes: 9 additions & 0 deletions localization/xliff/enu/localizedPackage.json.enu.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,15 @@
<trans-unit id="mssql.deviceCode.description">
<source xml:lang="en">Allows users to sign in to input-constrained devices.</source>
</trans-unit>
<trans-unit id="mssql.objectExplorer.groupBySchema">
<source xml:lang="en">When enabled, the database objects in Object Explorer will be categorized by schema.</source>
</trans-unit>
<trans-unit id="mssql.objectExplorer.enableGroupBySchema">
<source xml:lang="en">Enable Group By Schema</source>
</trans-unit>
<trans-unit id="mssql.objectExplorer.disableGroupBySchema">
<source xml:lang="en">Disable Group By Schema</source>
</trans-unit>
</body>
</file>
</xliff>
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@
"when": "view == queryHistory",
"title": "%mssql.clearAllQueryHistory%",
"group": "secondary"
},
{
"command": "mssql.objectExplorer.enableGroupBySchema",
"when": "view == objectExplorer && !config.mssql.objectExplorer.groupBySchema",
"title": "%mssql.objectExplorer.enableGroupBySchema%",
"group": "secondary"
},
{
"command": "mssql.objectExplorer.disableGroupBySchema",
"when": "view == objectExplorer && config.mssql.objectExplorer.groupBySchema",
"title": "%mssql.objectExplorer.disableGroupBySchema%",
"group": "secondary"
}
],
"view/item/context": [
Expand Down Expand Up @@ -439,6 +451,16 @@
"category": "MS SQL",
"icon": "$(add)"
},
{
"command": "mssql.objectExplorer.enableGroupBySchema",
"title": "%mssql.objectExplorer.enableGroupBySchema%",
"category": "MS SQL"
},
{
"command": "mssql.objectExplorer.disableGroupBySchema",
"title": "%mssql.objectExplorer.disableGroupBySchema%",
"category": "MS SQL"
},
{
"command": "mssql.objectExplorerNewQuery",
"title": "%mssql.objectExplorerNewQuery%",
Expand Down Expand Up @@ -1137,6 +1159,11 @@
"type": "boolean",
"description": "%mssql.ignorePlatformWarning%",
"default": false
},
"mssql.objectExplorer.groupBySchema": {
"type": "boolean",
"description": "%mssql.objectExplorer.groupBySchema%",
"default": false
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,8 @@
"mssql.Configuration":"MSSQL configuration",
"mssql.chooseAuthMethod":"Chooses which Authentication method to use",
"mssql.authCodeGrant.description":"Prompts users to sign in using their browser.",
"mssql.deviceCode.description":"Allows users to sign in to input-constrained devices."
"mssql.deviceCode.description":"Allows users to sign in to input-constrained devices.",
"mssql.objectExplorer.groupBySchema":"When enabled, the database objects in Object Explorer will be categorized by schema.",
"mssql.objectExplorer.enableGroupBySchema":"Enable Group By Schema",
"mssql.objectExplorer.disableGroupBySchema":"Disable Group By Schema"
}
24 changes: 12 additions & 12 deletions src/configurations/config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"service": {
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "4.5.0.8",
"version": "4.5.0.26",
"downloadFileNames": {
"Windows_86": "win-x86-net6.0.zip",
"Windows_64": "win-x64-net6.0.zip",
"OSX_10_11_64": "osx-x64-net6.0.tar.gz",
"CentOS_7": "rhel-x64-net6.0.tar.gz",
"Debian_8": "rhel-x64-net6.0.tar.gz",
"Fedora_23": "rhel-x64-net6.0.tar.gz",
"OpenSUSE_13_2": "rhel-x64-net6.0.tar.gz",
"SLES_12_2": "rhel-x64-net6.0.tar.gz",
"RHEL_7": "rhel-x64-net6.0.tar.gz",
"Ubuntu_14": "rhel-x64-net6.0.tar.gz",
"Ubuntu_16": "rhel-x64-net6.0.tar.gz"
"Windows_86": "win-x86-net7.0.zip",
"Windows_64": "win-x64-net7.0.zip",
"OSX_10_11_64": "osx-x64-net7.0.tar.gz",
"CentOS_7": "rhel-x64-net7.0.tar.gz",
"Debian_8": "rhel-x64-net7.0.tar.gz",
"Fedora_23": "rhel-x64-net7.0.tar.gz",
"OpenSUSE_13_2": "rhel-x64-net7.0.tar.gz",
"SLES_12_2": "rhel-x64-net7.0.tar.gz",
"RHEL_7": "rhel-x64-net7.0.tar.gz",
"Ubuntu_14": "rhel-x64-net7.0.tar.gz",
"Ubuntu_16": "rhel-x64-net7.0.tar.gz"
},
"installDir": "../sqltoolsservice/{#version#}/{#platform#}",
"executableFiles": [
Expand Down
3 changes: 3 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const cmdObjectExplorerNodeSignIn = 'mssql.objectExplorerNodeSignIn';
export const cmdConnectObjectExplorerNode = 'mssql.connectObjectExplorerNode';
export const cmdConnectObjectExplorerProfile = 'mssql.connectObjectExplorerProfile';
export const cmdOpenObjectExplorerCommand = 'workbench.view.extension.objectExplorer';
export const cmdObjectExplorerGroupBySchemaFlagName = 'mssql.objectExplorer.groupBySchema';
export const cmdObjectExplorerEnableGroupBySchemaCommand = 'mssql.objectExplorer.enableGroupBySchema';
export const cmdObjectExplorerDisableGroupBySchemaCommand = 'mssql.objectExplorer.disableGroupBySchema';
export const cmdScriptSelect = 'mssql.scriptSelect';
export const cmdScriptCreate = 'mssql.scriptCreate';
export const cmdScriptDelete = 'mssql.scriptDelete';
Expand Down
24 changes: 24 additions & 0 deletions src/controllers/mainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ export default class MainController implements vscode.Disposable {
});
});

this.registerCommand(Constants.cmdObjectExplorerEnableGroupBySchemaCommand);
this._event.on(Constants.cmdObjectExplorerEnableGroupBySchemaCommand, () => {
vscode.workspace.getConfiguration().update(Constants.cmdObjectExplorerGroupBySchemaFlagName, true, true);
});
this.registerCommand(Constants.cmdObjectExplorerDisableGroupBySchemaCommand);
this._event.on(Constants.cmdObjectExplorerDisableGroupBySchemaCommand, () => {
vscode.workspace.getConfiguration().update(Constants.cmdObjectExplorerGroupBySchemaFlagName, false, true);
});

this.initializeQueryHistory();

this.sqlTasksService = new SqlTasksService(SqlToolsServerClient.instance, this._untitledSqlDocumentService);
Expand Down Expand Up @@ -1178,6 +1187,21 @@ export default class MainController implements vscode.Disposable {

await this.sanitizeConnectionProfiles();

if (e.affectsConfiguration(Constants.cmdObjectExplorerGroupBySchemaFlagName)) {
let errorFoundWhileRefreshing = false;
(await this._objectExplorerProvider.getChildren()).forEach((n: TreeNodeInfo) => {
try {
this._objectExplorerProvider.refreshNode(n);
} catch (e) {
errorFoundWhileRefreshing = true;
Utils.logToOutputChannel(e.toString());
}
});
if (errorFoundWhileRefreshing) {
Utils.showErrorMsg(LocalizedConstants.objectExplorerNodeRefreshError);
}
}

if (needsRefresh) {
this._objectExplorerProvider.refresh(undefined);
}
Expand Down
17 changes: 15 additions & 2 deletions src/models/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const configTracingLevel = 'tracingLevel';
const configLogRetentionMinutes = 'logRetentionMinutes';
const configLogFilesRemovalLimit = 'logFilesRemovalLimit';

const outputChannel = vscode.window.createOutputChannel(Constants.outputChannelName);

// INTERFACES /////////////////////////////////////////////////////////////////////////////////////

// Interface for package.json information
Expand Down Expand Up @@ -110,8 +112,6 @@ export function getActiveTextEditorUri(): string {

// Helper to log messages to "MSSQL" output channel
export function logToOutputChannel(msg: any): void {
let outputChannel = vscode.window.createOutputChannel(Constants.outputChannelName);
outputChannel.show();
if (msg instanceof Array) {
msg.forEach(element => {
outputChannel.appendLine(element.toString());
Expand All @@ -121,6 +121,10 @@ export function logToOutputChannel(msg: any): void {
}
}

export function openOutputChannel(): void {
outputChannel.show();
}

// Helper to log debug messages
export function logDebug(msg: any): void {
let config = vscode.workspace.getConfiguration(Constants.extensionConfigSectionName);
Expand All @@ -147,6 +151,15 @@ export function showErrorMsg(msg: string): void {
vscode.window.showErrorMessage(Constants.extensionName + ': ' + msg);
}

// Helper to show an error message with an option to open the output channel
export function showOutputChannelErrorMsg(msg: string): void {
vscode.window.showErrorMessage(msg, LocalizedConstants.showOutputChannelActionButtonText).then((result) => {
if (result === LocalizedConstants.showOutputChannelActionButtonText) {
openOutputChannel();
}
});
}

export function isEmpty(str: any): boolean {
return (!str || '' === str);
}
Expand Down
59 changes: 35 additions & 24 deletions src/objectExplorer/objectTypes/Schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bcdec95

Please sign in to comment.