Skip to content

Commit

Permalink
SLVSCODE-746 Use non trivial ID for first level nodes of connected mo…
Browse files Browse the repository at this point in the history
…de view
  • Loading branch information
jblievremont committed Jan 10, 2025
1 parent e009ae8 commit c89f00b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/connected/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ export class Connection extends VSCode.TreeItem {
}
}

type ConnectionType = '__sonarqube__' | '__sonarcloud__';

export class ConnectionGroup extends VSCode.TreeItem {
constructor(
public readonly id: 'sonarqube' | 'sonarcloud',
public readonly id: ConnectionType,
public readonly label: 'SonarQube Server' | 'SonarQube Cloud',
public readonly contextValue: 'sonarQubeGroup' | 'sonarCloudGroup'
) {
Expand All @@ -89,13 +91,13 @@ export class AllConnectionsTreeDataProvider implements VSCode.TreeDataProvider<C

constructor(private readonly client: SonarLintExtendedLanguageClient) {}

async getConnections(type: string): Promise<Connection[]> {
const contextValue = type === 'sonarqube' ? 'sonarqubeConnection' : 'sonarcloudConnection';
async getConnections(type: ConnectionType): Promise<Connection[]> {
const contextValue = type === '__sonarqube__' ? 'sonarqubeConnection' : 'sonarcloudConnection';
const labelKey = 'connectionId';
const alternativeLabelKey = type === 'sonarqube' ? 'serverUrl' : 'organizationKey';
const alternativeLabelKey = type === '__sonarqube__' ? 'serverUrl' : 'organizationKey';

const connectionsFromSettings: BaseConnection[] =
type === 'sonarqube'
type === '__sonarqube__'
? ConnectionSettingsService.instance.getSonarQubeConnections()
: ConnectionSettingsService.instance.getSonarCloudConnections();
const connections = await Promise.all(
Expand Down Expand Up @@ -141,9 +143,9 @@ export class AllConnectionsTreeDataProvider implements VSCode.TreeDataProvider<C
if (!element) {
return this.getInitialState();
} else if (element.contextValue === 'sonarQubeGroup') {
return this.getConnections('sonarqube');
return this.getConnections('__sonarqube__');
} else if (element.contextValue === 'sonarCloudGroup') {
return this.getConnections('sonarcloud');
return this.getConnections('__sonarcloud__');
} else if (element.contextValue === 'sonarqubeConnection' || element.contextValue === 'sonarcloudConnection') {
const connection = element as Connection;
const serverType = element.contextValue === 'sonarqubeConnection' ? 'SonarQube' : 'SonarCloud';
Expand Down Expand Up @@ -181,8 +183,8 @@ export class AllConnectionsTreeDataProvider implements VSCode.TreeDataProvider<C
const sqConnections = ConnectionSettingsService.instance.getSonarQubeConnections();
const scConnections = ConnectionSettingsService.instance.getSonarCloudConnections();
return [
sqConnections.length > 0 ? new ConnectionGroup('sonarqube', 'SonarQube Server', 'sonarQubeGroup') : null,
scConnections.length > 0 ? new ConnectionGroup('sonarcloud', 'SonarQube Cloud', 'sonarCloudGroup') : null
sqConnections.length > 0 ? new ConnectionGroup('__sonarqube__', 'SonarQube Server', 'sonarQubeGroup') : null,
scConnections.length > 0 ? new ConnectionGroup('__sonarcloud__', 'SonarQube Cloud', 'sonarCloudGroup') : null
];
}

Expand Down
4 changes: 2 additions & 2 deletions test/suite/connections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ suite('Connected Mode Test Suite', () => {
});

suite('ConnectedMode TreeView', () => {
const SQGroup = new ConnectionGroup('sonarqube', 'SonarQube Server', 'sonarQubeGroup');
const SCGroup = new ConnectionGroup('sonarcloud', 'SonarQube Cloud', 'sonarCloudGroup');
const SQGroup = new ConnectionGroup('__sonarqube__', 'SonarQube Server', 'sonarQubeGroup');
const SCGroup = new ConnectionGroup('__sonarcloud__', 'SonarQube Cloud', 'sonarCloudGroup');

test('should return empty lists when expanding SQ and SC tabs and no connections exist', async () => {
const underTest = new AllConnectionsTreeDataProvider(mockClient);
Expand Down

0 comments on commit c89f00b

Please sign in to comment.