Add more SsmsMin interactions (#5267)

* Add support for more SsmsMin property dialogs and the Generate Script Wizard. Also fixed bug with ExtHostObjectExplorerNode getParent function

* Localize package.json entries

* Fix localization tokens

* Address PR comments

* Fix regex and getParent
This commit is contained in:
Charles Gagnon
2019-04-30 16:10:11 -07:00
committed by GitHub
parent 64416e05c1
commit 97cab22e00
8 changed files with 511 additions and 100 deletions

View File

@@ -8,7 +8,6 @@ import { IMainContext } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostObjectExplorerShape, SqlMainContext, MainThreadObjectExplorerShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { entries } from 'sql/base/common/objects';
export class ExtHostObjectExplorer implements ExtHostObjectExplorerShape {
@@ -41,7 +40,7 @@ export class ExtHostObjectExplorer implements ExtHostObjectExplorerShape {
}
}
class ExtHostObjectExplorerNode implements azdata.objectexplorer.ObjectExplorerNode {
export class ExtHostObjectExplorerNode implements azdata.objectexplorer.ObjectExplorerNode {
public connectionId: string;
public nodePath: string;
public nodeType: string;
@@ -74,11 +73,21 @@ class ExtHostObjectExplorerNode implements azdata.objectexplorer.ObjectExplorerN
}
getParent(): Thenable<azdata.objectexplorer.ObjectExplorerNode> {
let parentPathEndIndex = this.nodePath.lastIndexOf('/');
if (parentPathEndIndex === -1) {
return Promise.resolve(undefined);
// Object nodes have a name like <schema>.<name> in the nodePath - we can't use label because
// that may have additional display information appended to it. Items without metadata are nodes
// such as folders that don't correspond to actual objects and so just use the label
let nodePathName = this.metadata ?
`${this.metadata.schema ? this.metadata.schema + '.' : ''}${this.metadata.name}` :
this.label;
// -1 to remove the / as well
let parentPathEndIndex: number = this.nodePath.lastIndexOf(nodePathName) - 1;
if (parentPathEndIndex < 0) {
// At root node
Promise.resolve(undefined);
}
return this._proxy.$getNode(this.connectionId, this.nodePath.slice(0, parentPathEndIndex)).then(nodeInfo => nodeInfo ? new ExtHostObjectExplorerNode(nodeInfo, this.connectionId, this._proxy) : undefined);
return this._proxy.$getNode(this.connectionId, this.nodePath.slice(0, parentPathEndIndex)).then(
nodeInfo => nodeInfo ? new ExtHostObjectExplorerNode(nodeInfo, this.connectionId, this._proxy) : undefined);
}
refresh(): Thenable<void> {

View File

@@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import * as assert from 'assert';
import * as TypeMoq from 'typemoq';
import { MainThreadObjectExplorerShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import { ExtHostObjectExplorerNode } from 'sql/workbench/api/node/extHostObjectExplorer';
const nodes: { [nodeName: string]: azdata.NodeInfo } =
{
'Server1': {
nodePath: 'MyServer',
nodeStatus: '',
nodeSubType: '',
nodeType: 'Server',
isLeaf: false,
label: 'MyServer',
metadata: undefined,
errorMessage: ''
},
'DatabasesFolder': {
nodePath: 'MyServer/Databases',
nodeStatus: '',
nodeSubType: '',
nodeType: 'Folder',
isLeaf: false,
label: 'Databases',
metadata: undefined,
errorMessage: ''
},
'Database1': {
nodePath: 'MyServer/Databases/MyDatabase',
nodeStatus: '',
nodeSubType: '',
nodeType: 'Database',
isLeaf: false,
label: 'MyDatabase',
metadata: undefined,
errorMessage: ''
},
'Database2': {
nodePath: 'MyServer/Databases/My/TrickyDatabase',
nodeStatus: '',
nodeSubType: '',
nodeType: 'Database',
isLeaf: false,
label: 'My/TrickyDatabase',
metadata: undefined,
errorMessage: ''
},
'TablesFolder': {
nodePath: 'MyServer/Databases/My/TrickyDatabase/Tables',
nodeStatus: '',
nodeSubType: '',
nodeType: 'Folder',
isLeaf: false,
label: 'Tables',
metadata: undefined,
errorMessage: ''
}
};
suite('ExtHostObjectExplorer Tests', () => {
let mockProxy: TypeMoq.Mock<MainThreadObjectExplorerShape>;
suiteSetup(() => {
mockProxy = TypeMoq.Mock.ofInstance(<MainThreadObjectExplorerShape>{
$getNode: (connectionId: string, nodePath?: string): Thenable<azdata.NodeInfo> => undefined
});
mockProxy.setup(p =>
p.$getNode(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns((connectionId, nodePath) => {
return Promise.resolve<azdata.NodeInfo>(nodes[Object.keys(nodes).find(key =>
nodes[key].nodePath === nodePath)]);
});
});
suite('ExtHostObjectExplorerNode', () => {
let extHostObjectExplorerNode: ExtHostObjectExplorerNode;
suite('getParent', () => {
test('Should return undefined if no parent', async () => {
extHostObjectExplorerNode = new ExtHostObjectExplorerNode(nodes['Server1'], 'connectionId', mockProxy.object);
assert.equal(await extHostObjectExplorerNode.getParent(), undefined);
});
test('should return root with direct descendent of root', async () => {
extHostObjectExplorerNode = new ExtHostObjectExplorerNode(nodes['DatabasesFolder'], 'connectionId', mockProxy.object);
assert.equal((await extHostObjectExplorerNode.getParent()).nodePath, nodes['Server1'].nodePath);
});
test('should return correct parent with further descendent of root', async () => {
extHostObjectExplorerNode = new ExtHostObjectExplorerNode(nodes['Database1'], 'connectionId', mockProxy.object);
assert.equal((await extHostObjectExplorerNode.getParent()).nodePath, nodes['DatabasesFolder'].nodePath);
});
test('should return correct parent with node having / in its name', async () => {
extHostObjectExplorerNode = new ExtHostObjectExplorerNode(nodes['Database2'], 'connectionId', mockProxy.object);
assert.equal((await extHostObjectExplorerNode.getParent()).nodePath, nodes['DatabasesFolder'].nodePath);
});
test('should return correct parent with parent node having / in its name', async () => {
extHostObjectExplorerNode = new ExtHostObjectExplorerNode(nodes['TablesFolder'], 'connectionId', mockProxy.object);
assert.equal((await extHostObjectExplorerNode.getParent()).nodePath, nodes['Database2'].nodePath);
});
});
});
});