Merge pull request #3363 from github/robertbrignull/database-picker
Small usability improvements to database picker
This commit is contained in:
@@ -828,6 +828,12 @@ export class DatabaseUI extends DisposableObject {
|
||||
}
|
||||
|
||||
private async promptForDatabase(): Promise<void> {
|
||||
// If there aren't any existing databases,
|
||||
// don't bother asking the user if they want to pick one.
|
||||
if (this.databaseManager.databaseItems.length === 0) {
|
||||
return this.importNewDatabase();
|
||||
}
|
||||
|
||||
const quickPickItems: DatabaseSelectionQuickPickItem[] = [
|
||||
{
|
||||
label: "$(database) Existing database",
|
||||
@@ -837,7 +843,8 @@ export class DatabaseUI extends DisposableObject {
|
||||
},
|
||||
{
|
||||
label: "$(arrow-down) New database",
|
||||
detail: "Import a new database from the cloud or your local machine",
|
||||
detail:
|
||||
"Import a new database from GitHub, a URL, or your local machine...",
|
||||
alwaysShow: true,
|
||||
databaseKind: "new",
|
||||
},
|
||||
@@ -871,7 +878,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
}));
|
||||
|
||||
const selectedDatabase = await window.showQuickPick(dbItems, {
|
||||
placeHolder: "Select a database",
|
||||
placeHolder: "Select an existing database from your workspace...",
|
||||
ignoreFocusOut: true,
|
||||
});
|
||||
|
||||
@@ -913,7 +920,8 @@ export class DatabaseUI extends DisposableObject {
|
||||
];
|
||||
const selectedImportOption =
|
||||
await window.showQuickPick<DatabaseImportQuickPickItems>(importOptions, {
|
||||
placeHolder: "Import a database from...",
|
||||
placeHolder:
|
||||
"Import a new database from GitHub, a URL, or your local machine...",
|
||||
ignoreFocusOut: true,
|
||||
});
|
||||
if (!selectedImportOption) {
|
||||
|
||||
@@ -30,13 +30,13 @@ describe("local-databases-ui", () => {
|
||||
// these two should be deleted
|
||||
const db4 = createDatabase(
|
||||
storageDir,
|
||||
"db2-notimported-with-db-info",
|
||||
"db4-notimported-with-db-info",
|
||||
QueryLanguage.Cpp,
|
||||
".dbinfo",
|
||||
);
|
||||
const db5 = createDatabase(
|
||||
storageDir,
|
||||
"db2-notimported-with-codeql-database.yml",
|
||||
"db5-notimported-with-codeql-database.yml",
|
||||
QueryLanguage.Cpp,
|
||||
"codeql-database.yml",
|
||||
);
|
||||
@@ -246,6 +246,29 @@ describe("local-databases-ui", () => {
|
||||
expect(showQuickPickSpy).toHaveBeenCalledTimes(2);
|
||||
expect(handleChooseDatabaseGithubSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should skip straight to prompting to import a database if there are no existing databases", async () => {
|
||||
databaseManager.databaseItems = [];
|
||||
|
||||
const showQuickPickSpy = jest
|
||||
.spyOn(window, "showQuickPick")
|
||||
.mockResolvedValueOnce(
|
||||
mockedQuickPickItem(
|
||||
mockedObject<DatabaseImportQuickPickItems>({
|
||||
importType: "github",
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const handleChooseDatabaseGithubSpy = jest
|
||||
.spyOn(databaseUI as any, "handleChooseDatabaseGithub")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
await databaseUI.getDatabaseItem(progress, token);
|
||||
|
||||
expect(showQuickPickSpy).toHaveBeenCalledTimes(1);
|
||||
expect(handleChooseDatabaseGithubSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user