Skip to content

Commit 17ff592

Browse files
Hide system defined lists when enterprise URI is set
1 parent 1c267e4 commit 17ff592

File tree

4 files changed

+163
-17
lines changed

4 files changed

+163
-17
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ export async function setRemoteControllerRepo(repo: string | undefined) {
570570
export interface VariantAnalysisConfig {
571571
controllerRepo: string | undefined;
572572
onDidChangeConfiguration?: Event<void>;
573+
showSystemDefinedRepositoryLists: boolean;
573574
}
574575

575576
export class VariantAnalysisConfigListener
@@ -578,14 +579,18 @@ export class VariantAnalysisConfigListener
578579
{
579580
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
580581
this.handleDidChangeConfigurationForRelevantSettings(
581-
[VARIANT_ANALYSIS_SETTING],
582+
[VARIANT_ANALYSIS_SETTING, VSCODE_GITHUB_ENTERPRISE_URI_SETTING],
582583
e,
583584
);
584585
}
585586

586587
public get controllerRepo(): string | undefined {
587588
return getRemoteControllerRepo();
588589
}
590+
591+
public get showSystemDefinedRepositoryLists(): boolean {
592+
return !hasEnterpriseUri();
593+
}
589594
}
590595

591596
const VARIANT_ANALYSIS_FILTER_RESULTS = new Setting(

extensions/ql-vscode/src/databases/db-manager.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ import {
1616
} from "./db-item-selection";
1717
import { createRemoteTree } from "./db-tree-creator";
1818
import type { DbConfigValidationError } from "./db-validation-errors";
19+
import { VariantAnalysisConfigListener } from "../config";
1920

2021
export class DbManager extends DisposableObject {
2122
public readonly onDbItemsChanged: AppEvent<void>;
2223
public static readonly DB_EXPANDED_STATE_KEY = "db_expanded";
2324
private readonly onDbItemsChangesEventEmitter: AppEventEmitter<void>;
25+
private readonly variantAnalysisConfigListener =
26+
new VariantAnalysisConfigListener();
2427

2528
constructor(
2629
private readonly app: App,
@@ -36,6 +39,10 @@ export class DbManager extends DisposableObject {
3639
this.dbConfigStore.onDidChangeConfig(() => {
3740
this.onDbItemsChangesEventEmitter.fire();
3841
});
42+
43+
this.variantAnalysisConfigListener.onDidChangeConfiguration(() => {
44+
this.onDbItemsChangesEventEmitter.fire();
45+
});
3946
}
4047

4148
public getSelectedDbItem(): DbItem | undefined {
@@ -56,7 +63,11 @@ export class DbManager extends DisposableObject {
5663

5764
const expandedItems = this.getExpandedItems();
5865

59-
const remoteTree = createRemoteTree(configResult.value, expandedItems);
66+
const remoteTree = createRemoteTree(
67+
configResult.value,
68+
this.variantAnalysisConfigListener,
69+
expandedItems,
70+
);
6071
return ValueResult.ok(remoteTree.children);
6172
}
6273

extensions/ql-vscode/src/databases/db-tree-creator.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { VariantAnalysisConfig } from "../config";
12
import type { DbConfig, RemoteRepositoryList } from "./config/db-config";
23
import { SelectedDbItemKind } from "./config/db-config";
34
import type {
@@ -13,13 +14,17 @@ import { ExpandedDbItemKind } from "./db-item-expansion";
1314

1415
export function createRemoteTree(
1516
dbConfig: DbConfig,
17+
variantAnalysisConfig: VariantAnalysisConfig,
1618
expandedItems: ExpandedDbItem[],
1719
): RootRemoteDbItem {
18-
const systemDefinedLists = [
19-
createSystemDefinedList(10, dbConfig),
20-
createSystemDefinedList(100, dbConfig),
21-
createSystemDefinedList(1000, dbConfig),
22-
];
20+
const systemDefinedLists =
21+
variantAnalysisConfig.showSystemDefinedRepositoryLists
22+
? [
23+
createSystemDefinedList(10, dbConfig),
24+
createSystemDefinedList(100, dbConfig),
25+
createSystemDefinedList(1000, dbConfig),
26+
]
27+
: [];
2328

2429
const userDefinedRepoLists =
2530
dbConfig.databases.variantAnalysis.repositoryLists.map((r) =>

extensions/ql-vscode/test/unit-tests/databases/db-tree-creator.test.ts

Lines changed: 135 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { VariantAnalysisConfig } from "../../../src/config";
12
import type { DbConfig } from "../../../src/databases/config/db-config";
23
import { SelectedDbItemKind } from "../../../src/databases/config/db-config";
34
import {
@@ -12,11 +13,20 @@ import { createRemoteTree } from "../../../src/databases/db-tree-creator";
1213
import { createDbConfig } from "../../factories/db-config-factories";
1314

1415
describe("db tree creator", () => {
16+
const defaultVariantAnalysisConfig: VariantAnalysisConfig = {
17+
controllerRepo: "foo/bar",
18+
showSystemDefinedRepositoryLists: true,
19+
};
20+
1521
describe("createRemoteTree", () => {
1622
it("should build root node and system defined lists", () => {
1723
const dbConfig = createDbConfig();
1824

19-
const dbTreeRoot = createRemoteTree(dbConfig, []);
25+
const dbTreeRoot = createRemoteTree(
26+
dbConfig,
27+
defaultVariantAnalysisConfig,
28+
[],
29+
);
2030

2131
expect(dbTreeRoot).toBeTruthy();
2232
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -45,6 +55,24 @@ describe("db tree creator", () => {
4555
});
4656
});
4757

58+
it("displays empty list when no remote user defined list nodes and system defined lists are disabled", () => {
59+
const dbConfig = createDbConfig();
60+
61+
const dbTreeRoot = createRemoteTree(
62+
dbConfig,
63+
{
64+
...defaultVariantAnalysisConfig,
65+
showSystemDefinedRepositoryLists: false,
66+
},
67+
[],
68+
);
69+
70+
expect(dbTreeRoot).toBeTruthy();
71+
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
72+
expect(dbTreeRoot.expanded).toBe(false);
73+
expect(dbTreeRoot.children.length).toBe(0);
74+
});
75+
4876
it("should create remote user defined list nodes", () => {
4977
const dbConfig = createDbConfig({
5078
remoteLists: [
@@ -59,10 +87,15 @@ describe("db tree creator", () => {
5987
],
6088
});
6189

62-
const dbTreeRoot = createRemoteTree(dbConfig, []);
90+
const dbTreeRoot = createRemoteTree(
91+
dbConfig,
92+
defaultVariantAnalysisConfig,
93+
[],
94+
);
6395

6496
expect(dbTreeRoot).toBeTruthy();
6597
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
98+
expect(dbTreeRoot.children.length).toBe(5);
6699
const repositoryListNodes = dbTreeRoot.children.filter(
67100
isRemoteUserDefinedListDbItem,
68101
);
@@ -102,12 +135,76 @@ describe("db tree creator", () => {
102135
});
103136
});
104137

138+
it("shows only user defined list nodes when system defined lists are disabled", () => {
139+
const dbConfig = createDbConfig({
140+
remoteLists: [
141+
{
142+
name: "my-list-1",
143+
repositories: ["owner1/repo1", "owner1/repo2", "owner2/repo1"],
144+
},
145+
{
146+
name: "my-list-2",
147+
repositories: ["owner3/repo1", "owner3/repo2", "owner4/repo1"],
148+
},
149+
],
150+
});
151+
152+
const dbTreeRoot = createRemoteTree(
153+
dbConfig,
154+
{
155+
...defaultVariantAnalysisConfig,
156+
showSystemDefinedRepositoryLists: false,
157+
},
158+
[],
159+
);
160+
161+
expect(dbTreeRoot).toBeTruthy();
162+
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
163+
expect(dbTreeRoot.children.length).toBe(2);
164+
expect(dbTreeRoot.children[0]).toEqual({
165+
kind: DbItemKind.RemoteUserDefinedList,
166+
selected: false,
167+
expanded: false,
168+
listName: dbConfig.databases.variantAnalysis.repositoryLists[0].name,
169+
repos:
170+
dbConfig.databases.variantAnalysis.repositoryLists[0].repositories.map(
171+
(repo) => ({
172+
kind: DbItemKind.RemoteRepo,
173+
selected: false,
174+
repoFullName: repo,
175+
parentListName:
176+
dbConfig.databases.variantAnalysis.repositoryLists[0].name,
177+
}),
178+
),
179+
});
180+
expect(dbTreeRoot.children[1]).toEqual({
181+
kind: DbItemKind.RemoteUserDefinedList,
182+
selected: false,
183+
expanded: false,
184+
listName: dbConfig.databases.variantAnalysis.repositoryLists[1].name,
185+
repos:
186+
dbConfig.databases.variantAnalysis.repositoryLists[1].repositories.map(
187+
(repo) => ({
188+
kind: DbItemKind.RemoteRepo,
189+
selected: false,
190+
repoFullName: repo,
191+
parentListName:
192+
dbConfig.databases.variantAnalysis.repositoryLists[1].name,
193+
}),
194+
),
195+
});
196+
});
197+
105198
it("should create remote owner nodes", () => {
106199
const dbConfig: DbConfig = createDbConfig({
107200
remoteOwners: ["owner1", "owner2"],
108201
});
109202

110-
const dbTreeRoot = createRemoteTree(dbConfig, []);
203+
const dbTreeRoot = createRemoteTree(
204+
dbConfig,
205+
defaultVariantAnalysisConfig,
206+
[],
207+
);
111208

112209
expect(dbTreeRoot).toBeTruthy();
113210
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -131,7 +228,11 @@ describe("db tree creator", () => {
131228
remoteRepos: ["owner1/repo1", "owner1/repo2", "owner2/repo1"],
132229
});
133230

134-
const dbTreeRoot = createRemoteTree(dbConfig, []);
231+
const dbTreeRoot = createRemoteTree(
232+
dbConfig,
233+
defaultVariantAnalysisConfig,
234+
[],
235+
);
135236

136237
expect(dbTreeRoot).toBeTruthy();
137238
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -170,7 +271,11 @@ describe("db tree creator", () => {
170271
},
171272
});
172273

173-
const dbTreeRoot = createRemoteTree(dbConfig, []);
274+
const dbTreeRoot = createRemoteTree(
275+
dbConfig,
276+
defaultVariantAnalysisConfig,
277+
[],
278+
);
174279

175280
expect(dbTreeRoot).toBeTruthy();
176281
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -191,7 +296,11 @@ describe("db tree creator", () => {
191296
},
192297
});
193298

194-
const dbTreeRoot = createRemoteTree(dbConfig, []);
299+
const dbTreeRoot = createRemoteTree(
300+
dbConfig,
301+
defaultVariantAnalysisConfig,
302+
[],
303+
);
195304

196305
expect(dbTreeRoot).toBeTruthy();
197306
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -213,7 +322,11 @@ describe("db tree creator", () => {
213322
},
214323
});
215324

216-
const dbTreeRoot = createRemoteTree(dbConfig, []);
325+
const dbTreeRoot = createRemoteTree(
326+
dbConfig,
327+
defaultVariantAnalysisConfig,
328+
[],
329+
);
217330

218331
expect(dbTreeRoot).toBeTruthy();
219332
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -240,7 +353,11 @@ describe("db tree creator", () => {
240353
},
241354
});
242355

243-
const dbTreeRoot = createRemoteTree(dbConfig, []);
356+
const dbTreeRoot = createRemoteTree(
357+
dbConfig,
358+
defaultVariantAnalysisConfig,
359+
[],
360+
);
244361

245362
expect(dbTreeRoot).toBeTruthy();
246363

@@ -265,7 +382,11 @@ describe("db tree creator", () => {
265382
},
266383
];
267384

268-
const dbTreeRoot = createRemoteTree(dbConfig, expanded);
385+
const dbTreeRoot = createRemoteTree(
386+
dbConfig,
387+
defaultVariantAnalysisConfig,
388+
expanded,
389+
);
269390

270391
expect(dbTreeRoot).toBeTruthy();
271392
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -291,7 +412,11 @@ describe("db tree creator", () => {
291412
},
292413
];
293414

294-
const dbTreeRoot = createRemoteTree(dbConfig, expanded);
415+
const dbTreeRoot = createRemoteTree(
416+
dbConfig,
417+
defaultVariantAnalysisConfig,
418+
expanded,
419+
);
295420

296421
expect(dbTreeRoot).toBeTruthy();
297422
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);

0 commit comments

Comments
 (0)