Skip to content

Commit

Permalink
Merge pull request #289 from redhat-developer/gh-288
Browse files Browse the repository at this point in the history
update repository quickpick with icons and descriptions
  • Loading branch information
mohitsuman authored Oct 16, 2022
2 parents ff615e1 + c673d27 commit d358fd5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@
],
"contributes": {
"commands": [
{
"command": "function.explorer.create",
"title": "Create Function",
"category": "Knative",
"icon": "$(plus)"
},
{
"command": "function.explorer.refresh",
"title": "Refresh View",
Expand All @@ -180,7 +186,7 @@
},
{
"command": "function.explorer.repository",
"title": "Repository",
"title": "Manage Repository",
"category": "Knative",
"icon": {
"dark": "images/context/repo-dark.svg",
Expand Down Expand Up @@ -303,12 +309,6 @@
"title": "Show Output Channel",
"category": "Knative"
},
{
"command": "function.explorer.create",
"title": "Create Function",
"category": "Knative",
"icon": "$(plus)"
},
{
"command": "function.invoke",
"title": "Invoke",
Expand Down Expand Up @@ -611,7 +611,7 @@
{
"command": "function.explorer.create",
"when": "view == knativeFunctionProjectExplorer",
"group": "navigation@1"
"group": "navigation@0"
},
{
"command": "function.explorer.refresh",
Expand Down
81 changes: 55 additions & 26 deletions src/functions/function-command/repository-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ export async function addRepository(): Promise<void> {
{
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: `Adding repository....`,
title: `Adding repository...`,
},
async () => {
const result = await executeCmdCli.executeExec(
FuncAPI.addRepository(name, repositoryURL, (await activeNamespace()) ?? 'default'),
);
if (result.error) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showErrorMessage(`Failed to add repository ${name} error: ${getStderrString(result.error)}`);
vscode.window.showErrorMessage(
`Failed to add ${name} repository with the following error: ${getStderrString(result.error)}`,
);
telemetryLogError('Function_repository_add_error', getStderrString(result.error));
return null;
}
Expand Down Expand Up @@ -98,25 +100,29 @@ async function getRepository(): Promise<string> {
export async function renameRepository(): Promise<void> {
const selectedRepository = await getRepository();
if (!selectedRepository) {
// eslint-disable-next-line no-unused-expressions, no-void
void vscode.window.showInformationMessage('There are no repository present.');
return null;
}
const name: string = await showInputBox('Rename repository name.', 'Name cannot be empty');
const name: string = await showInputBox('Edit repository name.', 'Name cannot be empty');
if (!name) {
return null;
}
await vscode.window.withProgress(
{
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: `Renaming repository....`,
title: `Renaming repository...`,
},
async () => {
const result = await executeCmdCli.executeExec(
FuncAPI.renameRepository(selectedRepository, name, (await activeNamespace()) ?? 'default'),
);
if (result.error) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showErrorMessage(`Failed to rename repository ${name} error: ${getStderrString(result.error)}`);
vscode.window.showErrorMessage(
`Failed to rename ${name} repository with the following error: ${getStderrString(result.error)}`,
);
telemetryLogError('Function_repository_rename_error', getStderrString(result.error));
return null;
}
Expand All @@ -129,13 +135,15 @@ export async function renameRepository(): Promise<void> {
export async function removeRepository(): Promise<void> {
const selectedRepository = await getRepository();
if (!selectedRepository) {
// eslint-disable-next-line no-void
void vscode.window.showInformationMessage('There are no repository present.');
return null;
}
await vscode.window.withProgress(
{
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: `Removing repository....`,
title: `Removing repository...`,
},
async () => {
const result = await executeCmdCli.executeExec(
Expand All @@ -144,7 +152,7 @@ export async function removeRepository(): Promise<void> {
if (result.error) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showErrorMessage(
`Failed to remove repository ${selectedRepository} error: ${getStderrString(result.error)}`,
`Failed to remove ${selectedRepository} repository with the following error: ${getStderrString(result.error)}`,
);
telemetryLogError('Function_repository_rename_error', getStderrString(result.error));
return null;
Expand All @@ -155,28 +163,49 @@ export async function removeRepository(): Promise<void> {
);
}

const RepositoryActions = [
{
label: `$(add) Add repository`,
description: 'Add a repository and create a new function using a template from it',
},
{
label: `$(list-flat) List repository`,
description: 'List all repositories including the URL from which remotes were installed',
},
{
label: `$(remove) Remove repository`,
description: 'Remove an installed repository',
},
{
label: `$(pencil) Rename repository`,
description: 'Rename an installed repository',
},
];

export async function repository(): Promise<void> {
const selectedRepository = await vscode.window.showQuickPick(
['Add repository', 'List repositories', 'Remove repository', 'Rename repository'],
{
canPickMany: false,
ignoreFocusOut: true,
placeHolder: 'Select repository',
},
);
const selectedRepository = await vscode.window.showQuickPick(RepositoryActions, {
canPickMany: false,
ignoreFocusOut: true,
placeHolder: 'Manage set of installed repositories.',
});
if (!selectedRepository) {
return null;
}
if (selectedRepository === 'Add repository') {
await addRepository();
}
if (selectedRepository === 'List repositories') {
await listRepository();
}
if (selectedRepository === 'Remove repository') {
await removeRepository();
}
if (selectedRepository === 'Rename repository') {
await renameRepository();

switch (selectedRepository.label) {
case 'Add repository':
await addRepository();
break;
case 'List repository':
await listRepository();
break;
case 'Remove repository':
await removeRepository();
break;
case 'Rename repository':
await renameRepository();
break;
default:
break;
}
}

0 comments on commit d358fd5

Please sign in to comment.