Skip to content

Commit 58b26d2

Browse files
Merge pull request github#3363 from github/robertbrignull/database-picker
Small usability improvements to database picker
2 parents 67870ca + 0f18c84 commit 58b26d2

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

extensions/ql-vscode/src/databases/local-databases-ui.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,12 @@ export class DatabaseUI extends DisposableObject {
828828
}
829829

830830
private async promptForDatabase(): Promise<void> {
831+
// If there aren't any existing databases,
832+
// don't bother asking the user if they want to pick one.
833+
if (this.databaseManager.databaseItems.length === 0) {
834+
return this.importNewDatabase();
835+
}
836+
831837
const quickPickItems: DatabaseSelectionQuickPickItem[] = [
832838
{
833839
label: "$(database) Existing database",
@@ -837,7 +843,8 @@ export class DatabaseUI extends DisposableObject {
837843
},
838844
{
839845
label: "$(arrow-down) New database",
840-
detail: "Import a new database from the cloud or your local machine",
846+
detail:
847+
"Import a new database from GitHub, a URL, or your local machine...",
841848
alwaysShow: true,
842849
databaseKind: "new",
843850
},
@@ -871,7 +878,7 @@ export class DatabaseUI extends DisposableObject {
871878
}));
872879

873880
const selectedDatabase = await window.showQuickPick(dbItems, {
874-
placeHolder: "Select a database",
881+
placeHolder: "Select an existing database from your workspace...",
875882
ignoreFocusOut: true,
876883
});
877884

@@ -913,7 +920,8 @@ export class DatabaseUI extends DisposableObject {
913920
];
914921
const selectedImportOption =
915922
await window.showQuickPick<DatabaseImportQuickPickItems>(importOptions, {
916-
placeHolder: "Import a database from...",
923+
placeHolder:
924+
"Import a new database from GitHub, a URL, or your local machine...",
917925
ignoreFocusOut: true,
918926
});
919927
if (!selectedImportOption) {

extensions/ql-vscode/test/vscode-tests/no-workspace/databases/local-databases-ui.test.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ describe("local-databases-ui", () => {
3030
// these two should be deleted
3131
const db4 = createDatabase(
3232
storageDir,
33-
"db2-notimported-with-db-info",
33+
"db4-notimported-with-db-info",
3434
QueryLanguage.Cpp,
3535
".dbinfo",
3636
);
3737
const db5 = createDatabase(
3838
storageDir,
39-
"db2-notimported-with-codeql-database.yml",
39+
"db5-notimported-with-codeql-database.yml",
4040
QueryLanguage.Cpp,
4141
"codeql-database.yml",
4242
);
@@ -246,6 +246,29 @@ describe("local-databases-ui", () => {
246246
expect(showQuickPickSpy).toHaveBeenCalledTimes(2);
247247
expect(handleChooseDatabaseGithubSpy).toHaveBeenCalledTimes(1);
248248
});
249+
250+
it("should skip straight to prompting to import a database if there are no existing databases", async () => {
251+
databaseManager.databaseItems = [];
252+
253+
const showQuickPickSpy = jest
254+
.spyOn(window, "showQuickPick")
255+
.mockResolvedValueOnce(
256+
mockedQuickPickItem(
257+
mockedObject<DatabaseImportQuickPickItems>({
258+
importType: "github",
259+
}),
260+
),
261+
);
262+
263+
const handleChooseDatabaseGithubSpy = jest
264+
.spyOn(databaseUI as any, "handleChooseDatabaseGithub")
265+
.mockResolvedValue(undefined);
266+
267+
await databaseUI.getDatabaseItem(progress, token);
268+
269+
expect(showQuickPickSpy).toHaveBeenCalledTimes(1);
270+
expect(handleChooseDatabaseGithubSpy).toHaveBeenCalledTimes(1);
271+
});
249272
});
250273
});
251274

0 commit comments

Comments
 (0)