Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connections tree improvements #394

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
"clean": "rm -rf dist",
"test:e2e": "npm run build:dev && npm run test:apiAndUnit && npm run test:webviews",
"test:apiAndUnit": "npm run build:dev && rm -rf .vscode-test/user-data && node ./dist/tests/runApiAndUnitTests.js",
"test:webviews": "wdio run ./dist/tests/runWebviewTests.js"
"test:webviews": "npm run build:dev && wdio run ./dist/tests/runWebviewTests.js"
},
"dependencies": {
"@neo4j-cypher/language-server": "2.0.0-next.17",
Expand Down
4 changes: 4 additions & 0 deletions packages/vscode-extension/resources/images/ConnectedDark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/vscode-extension/resources/images/ConnectedLight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion packages/vscode-extension/src/connectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export function getActiveConnection(): Connection | null {

/**
* Gets all Connections from the global state as an array of Connection objects.
* This is artificially limited to one, for now.
* @returns An array of all Connection objects.
*/
export function getAllConnections(): Connection[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Database } from '@neo4j-cypher/schema-poller';
import path from 'path';
import {
Event,
EventEmitter,
Expand All @@ -7,6 +8,7 @@ import {
TreeItemCollapsibleState,
Uri,
} from 'vscode';
import { CONSTANTS } from '../constants';
import {
Connection,
getAllConnections,
Expand All @@ -29,8 +31,8 @@ export class ConnectionTreeDataProvider
readonly onDidChangeTreeData: Event<ConnectionItem | undefined | void> =
this._onDidChangeTreeData.event;

refresh(): void {
this._onDidChangeTreeData.fire();
refresh(item?: ConnectionItem): void {
this._onDidChangeTreeData.fire(item);
}

getTreeItem(element: ConnectionItem): TreeItem | Thenable<TreeItem> {
Expand Down Expand Up @@ -74,7 +76,7 @@ export class ConnectionTreeDataProvider
this.getConnectionName(connection),
description,
connection.state === 'active'
? TreeItemCollapsibleState.Collapsed
? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.None,
connection.key,
),
Expand Down Expand Up @@ -158,13 +160,101 @@ export class ConnectionItem extends TreeItem {

switch (type) {
case 'activeConnection':
this.iconPath = {
light: Uri.file(
path.join(
__dirname,
'..',
'resources',
'images',
'Neo4jActiveLight.svg',
),
Comment on lines +165 to +171
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried if the icons are visible in Windows?

You can generate a .vsix package doing:

cd packages/vscode-extension
npx vsce package

and then installing that VSIX manually when you click on the Marketplace icon in VSCode:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, looks like they're still there if I do it this way. How is building/installing with a VSIX file (from the current repo) different from what I get by running the vscode playground in the current repo?

),
dark: Uri.file(
path.join(
__dirname,
'..',
'resources',
'images',
'Neo4jActiveDark.svg',
),
),
};
this.id = key;
break;
case 'connection':
this.iconPath = {
light: Uri.file(
path.join(
__dirname,
'..',
'resources',
'images',
'Neo4jInactiveLight.svg',
),
),
dark: Uri.file(
path.join(
__dirname,
'..',
'resources',
'images',
'Neo4jInactiveDark.svg',
),
),
};
this.id = key;
this.command = {
title: 'onClickConnect',
command: CONSTANTS.COMMANDS.CONNECT_COMMAND,
arguments: [this],
};
break;
case 'activeDatabase':
this.resourceUri = Uri.from({ scheme: '', query: `type=${this.type}` });
this.iconPath = {
light: Uri.file(
path.join(
__dirname,
'..',
'resources',
'images',
'ConnectedLight.svg',
),
),
dark: Uri.file(
path.join(
__dirname,
'..',
'resources',
'images',
'ConnectedDark.svg',
),
),
};
break;
case 'database':
this.resourceUri = Uri.from({ scheme: '', query: `type=${this.type}` });
this.iconPath = '.';
this.iconPath = {
light: Uri.file(
path.join(
__dirname,
'..',
'resources',
'images',
'DisconnectedLight.svg',
),
),
dark: Uri.file(
path.join(
__dirname,
'..',
'resources',
'images',
'DisconnectedDark.svg',
),
),
};
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function testSyntaxValidation({
);
}

suite.only('Syntax validation spec', () => {
suite('Syntax validation spec', () => {
afterEach(async () => {
await toggleLinting(true);
});
Expand Down
14 changes: 14 additions & 0 deletions packages/vscode-extension/tests/specs/webviews/connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
closeActiveTab,
getConnectionSection,
openFixtureFile,
selectConnectionItem,
setText,
waitUntilNotification,
} from '../../webviewUtils';
Expand Down Expand Up @@ -37,6 +38,19 @@ suite('Connection testing', () => {
await waitUntilNotification(browser, 'Connected to Neo4j.');
});

test('should connect when selecting new connection', async function () {
await selectConnectionItem(connectionSection, 0);
await waitUntilNotification(browser, 'Connected to Neo4j.');
});

test('should expand connectionItems when selecting connected connection', async function () {
await selectConnectionItem(connectionSection, 1);
await waitUntilNotification(browser, 'Connected to Neo4j.');
await expect((await connectionSection.getVisibleItems()).length).toBe(2);
await selectConnectionItem(connectionSection, 1);
await expect((await connectionSection.getVisibleItems()).length).toBe(4);
});

test('should be able to connect to another instance', async function () {
if (os.platform() === 'darwin') {
this.skip();
Expand Down
12 changes: 12 additions & 0 deletions packages/vscode-extension/tests/webviewUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { integer } from 'vscode-languageclient';
import { TreeItem, ViewSection, WebView, Workbench } from 'wdio-vscode-service';
import { createAndStartTestContainer } from './setupTestContainer';

Expand Down Expand Up @@ -122,12 +123,23 @@ export async function getConnectionSection(
return connectionSection;
}

export async function selectConnectionItem(
connectionSection: ViewSection,
connectionIndex: integer,
): Promise<void> {
const items = await connectionSection.getVisibleItems();
await expect(items.length).toBeGreaterThan(connectionIndex);
const connectionItem = items.at(connectionIndex) as TreeItem;
await connectionItem.select();
}

export async function clickOnContextMenuItem(
connectionSection: ViewSection,
item: string,
connectionIndex: number,
): Promise<void> {
const items = await connectionSection.getVisibleItems();

await expect(items.length).toBeGreaterThan(connectionIndex);
const connectionItem = items.at(connectionIndex) as TreeItem;

Expand Down
Loading