Ask for user input and add response to list
This commit is contained in:
@@ -145,6 +145,31 @@ export class DbConfigStore extends DisposableObject {
|
||||
await this.writeConfig(config);
|
||||
}
|
||||
|
||||
public async addRemoteReposToList(
|
||||
repoNwoList: string[],
|
||||
parentList: string,
|
||||
): Promise<void> {
|
||||
if (!this.config) {
|
||||
throw Error("Cannot add variant analysis repos if config is not loaded");
|
||||
}
|
||||
|
||||
const config = cloneDbConfig(this.config);
|
||||
const parent = config.databases.variantAnalysis.repositoryLists.find(
|
||||
(list) => list.name === parentList,
|
||||
);
|
||||
if (!parent) {
|
||||
throw Error(`Cannot find parent list '${parentList}'`);
|
||||
}
|
||||
|
||||
const newRepositoriesList = new Set([
|
||||
...new Set(parent.repositories),
|
||||
...new Set(repoNwoList),
|
||||
]);
|
||||
parent.repositories = [...newRepositoriesList];
|
||||
|
||||
await this.writeConfig(config);
|
||||
}
|
||||
|
||||
public async addRemoteRepo(
|
||||
repoNwo: string,
|
||||
parentList?: string,
|
||||
|
||||
@@ -100,6 +100,13 @@ export class DbManager {
|
||||
await this.dbConfigStore.addRemoteRepo(nwo, parentList);
|
||||
}
|
||||
|
||||
public async addNewRemoteReposToList(
|
||||
nwoList: string[],
|
||||
parentList: string,
|
||||
): Promise<void> {
|
||||
await this.dbConfigStore.addRemoteReposToList(nwoList, parentList);
|
||||
}
|
||||
|
||||
public async addNewRemoteOwner(owner: string): Promise<void> {
|
||||
await this.dbConfigStore.addRemoteOwner(owner);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ import { getControllerRepo } from "../../variant-analysis/run-remote-query";
|
||||
import { getErrorMessage } from "../../pure/helpers-pure";
|
||||
import { DatabasePanelCommands } from "../../common/commands";
|
||||
import { App } from "../../common/app";
|
||||
import { getCodeSearchRepositories } from "../../variant-analysis/gh-api/gh-api-client";
|
||||
import { QueryLanguage } from "../../common/query-language";
|
||||
|
||||
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
|
||||
remoteDatabaseKind: string;
|
||||
@@ -41,6 +43,10 @@ export interface AddListQuickPickItem extends QuickPickItem {
|
||||
databaseKind: DbListKind;
|
||||
}
|
||||
|
||||
export interface CodeSearchQuickPickItem extends QuickPickItem {
|
||||
language: string;
|
||||
}
|
||||
|
||||
export class DbPanel extends DisposableObject {
|
||||
private readonly dataProvider: DbTreeDataProvider;
|
||||
private readonly treeView: TreeView<DbTreeViewItem>;
|
||||
@@ -326,9 +332,51 @@ export class DbPanel extends DisposableObject {
|
||||
}
|
||||
|
||||
private async importCodeSearch(treeViewItem: DbTreeViewItem): Promise<void> {
|
||||
if (treeViewItem.dbItem === undefined) {
|
||||
if (treeViewItem.dbItem?.kind !== DbItemKind.RemoteUserDefinedList) {
|
||||
throw new Error("Please select a valid list to add code search results.");
|
||||
}
|
||||
|
||||
const languageQuickPickItems: CodeSearchQuickPickItem[] = Object.values(
|
||||
QueryLanguage,
|
||||
).map((language) => ({
|
||||
label: language.toString(),
|
||||
alwaysShow: true,
|
||||
language: language.toString(),
|
||||
}));
|
||||
|
||||
const codeSearchLanguage =
|
||||
await window.showQuickPick<CodeSearchQuickPickItem>(
|
||||
languageQuickPickItems,
|
||||
{
|
||||
title: "Select the language you want to query",
|
||||
placeHolder: "Select an option",
|
||||
ignoreFocusOut: true,
|
||||
},
|
||||
);
|
||||
if (!codeSearchLanguage) {
|
||||
// We don't need to display a warning pop-up in this case, since the user just escaped out of the operation.
|
||||
// We set 'true' to make this a silent exception.
|
||||
throw new UserCancellationException("No language selected", true);
|
||||
}
|
||||
|
||||
const codeSearchQuery = await window.showInputBox({
|
||||
title: "Code search query",
|
||||
prompt: "Insert code search query",
|
||||
placeHolder: "org:github",
|
||||
});
|
||||
if (codeSearchQuery === undefined || codeSearchQuery === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
const repositories = await getCodeSearchRepositories(
|
||||
this.app.credentials,
|
||||
`${codeSearchQuery} language:${codeSearchLanguage.language}`,
|
||||
);
|
||||
|
||||
await this.dbManager.addNewRemoteReposToList(
|
||||
repositories,
|
||||
treeViewItem.dbItem.listName,
|
||||
);
|
||||
}
|
||||
|
||||
private async onDidCollapseElement(
|
||||
|
||||
@@ -62,12 +62,17 @@ describe("getDbItemActions", () => {
|
||||
expect(actions.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("should set canBeSelected, canBeRemoved and canBeRenamed for remote user defined db list", () => {
|
||||
it("should set canBeSelected, canBeRemoved, canBeRenamed and canImportCodeSearch for remote user defined db list", () => {
|
||||
const dbItem = createRemoteUserDefinedListDbItem();
|
||||
|
||||
const actions = getDbItemActions(dbItem);
|
||||
|
||||
expect(actions).toEqual(["canBeSelected", "canBeRemoved", "canBeRenamed"]);
|
||||
expect(actions).toEqual([
|
||||
"canBeSelected",
|
||||
"canBeRemoved",
|
||||
"canBeRenamed",
|
||||
"canImportCodeSearch",
|
||||
]);
|
||||
});
|
||||
|
||||
it("should not set canBeSelected for remote user defined db list that is already selected", () => {
|
||||
|
||||
@@ -349,7 +349,12 @@ describe("db panel rendering nodes", () => {
|
||||
expect(item.tooltip).toBeUndefined();
|
||||
expect(item.iconPath).toBeUndefined();
|
||||
expect(item.collapsibleState).toBe(TreeItemCollapsibleState.Collapsed);
|
||||
checkDbItemActions(item, ["canBeSelected", "canBeRenamed", "canBeRemoved"]);
|
||||
checkDbItemActions(item, [
|
||||
"canBeSelected",
|
||||
"canBeRenamed",
|
||||
"canBeRemoved",
|
||||
"canImportCodeSearch",
|
||||
]);
|
||||
expect(item.children).toBeTruthy();
|
||||
expect(item.children.length).toBe(repos.length);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user