Skip to content

Commit 7fb9c29

Browse files
authored
Change the way we show progress for long running commands (#422)
1 parent 4398c24 commit 7fb9c29

File tree

5 files changed

+39
-57
lines changed

5 files changed

+39
-57
lines changed

src/openshift/component.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*-----------------------------------------------------------------------------------------------*/
55

66
import { OpenShiftItem } from './openshiftItem';
7-
import { OpenShiftObject } from '../odo';
7+
import { OpenShiftObject, OdoImpl } from '../odo';
88
import * as vscode from 'vscode';
99
import { Progress } from '../util/progress';
1010
import opn = require('opn');
@@ -163,15 +163,10 @@ export class Component extends OpenShiftItem {
163163

164164
if (!componentTypeVersion) return null;
165165
const project = application.getParent();
166-
return Progress.execWithProgress({
167-
cancellable: false,
168-
location: vscode.ProgressLocation.Notification,
169-
title: `Creating new component '${componentName}'`
170-
}, [{command: `odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --local ${folder.uri.fsPath} --app ${application.getName()} --project ${project.getName()}`, increment: 50},
171-
{command: `odo push ${componentName} --local ${folder.uri.fsPath} --app ${application.getName()} --project ${project.getName()}`, increment: 50}
172-
], Component.odo)
173-
.then(() => Component.explorer.refresh(application))
174-
.then(() => `Component '${componentName}' successfully created`);
166+
return Progress.execCmdWithProgress(`Creating new component '${componentName}'`, `odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --local ${folder.uri.fsPath} --app ${application.getName()} --project ${project.getName()}`)
167+
.then(() => Component.explorer.refresh(application))
168+
.then(() => Component.odo.executeInTerminal(`odo push ${componentName} --local ${folder.uri.fsPath} --app ${application.getName()} --project ${project.getName()}`))
169+
.then(() => `Component '${componentName}' successfully created`);
175170
}
176171

177172
private static async createFromGit(application: OpenShiftObject): Promise<string> {
@@ -209,14 +204,11 @@ export class Component extends OpenShiftItem {
209204
});
210205

211206
const project = application.getParent();
212-
return Progress.execWithProgress({
213-
cancellable: false,
214-
location: vscode.ProgressLocation.Notification,
215-
title: `Creating new component '${componentName}'`
216-
}, [{command: `odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --git ${repoURI} --app ${application.getName()} --project ${project.getName()}`, increment: 100}
217-
], Component.odo)
218-
.then(() => Component.explorer.refresh(application))
219-
.then(() => `Component '${componentName}' successfully created`);
207+
return Promise.resolve()
208+
.then(() => Component.odo.executeInTerminal(`odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --git ${repoURI} --app ${application.getName()} --project ${project.getName()}`))
209+
.then(() => Component.wait())
210+
.then(() => Component.explorer.refresh(application))
211+
.then(() => `Component '${componentName}' successfully created`);
220212
}
221213

222214
private static async createFromBinary(application: OpenShiftObject): Promise<string> {
@@ -243,13 +235,9 @@ export class Component extends OpenShiftItem {
243235
if (!componentTypeVersion) return null;
244236

245237
const project = application.getParent();
246-
return Progress.execWithProgress({
247-
cancellable: false,
248-
location: vscode.ProgressLocation.Notification,
249-
title: `Creating new component '${componentName}'`
250-
}, [{command: `odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --binary ${binaryFile[0].fsPath} --app ${application.getName()} --project ${project.getName()}`, increment: 100}
251-
], Component.odo)
252-
.then(() => Component.explorer.refresh(application))
253-
.then(() => `Component '${componentName}' successfully created`);
238+
return Progress.execCmdWithProgress(`Creating new component '${componentName}'`,
239+
`odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --binary ${binaryFile[0].fsPath} --app ${application.getName()} --project ${project.getName()}`)
240+
.then(() => Component.explorer.refresh(application))
241+
.then(() => `Component '${componentName}' successfully created`);
254242
}
255243
}

src/openshift/openshiftItem.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export abstract class OpenShiftItem {
1212

1313
static create(context: OpenShiftObject): Promise<String> { return Promise.reject(); }
1414
static del(context: OpenShiftObject): Promise<String> { return Promise.reject(); }
15+
static wait(timeout: number = 2500): Promise<void> { return new Promise((res)=>setTimeout(res, timeout)); }
1516
}

src/openshift/service.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,8 @@ export class Service extends OpenShiftItem {
3333
});
3434
if (serviceName) {
3535
const project = application.getParent();
36-
return Promise.resolve().then(() =>
37-
Progress.execWithProgress({
38-
cancellable: false,
39-
location: vscode.ProgressLocation.Notification,
40-
title: `Creating new service '${serviceName}'`
41-
}, [{command: `odo service create ${serviceTemplateName} --plan ${serviceTemplatePlanName} ${serviceName.trim()} --app ${application.getName()} --project ${project.getName()}`, increment: 100}
42-
], Service.odo))
36+
return Progress.execCmdWithProgress(`Creating new service '${serviceName}'`,
37+
`odo service create ${serviceTemplateName} --plan ${serviceTemplatePlanName} ${serviceName.trim()} --app ${application.getName()} --project ${project.getName()}`)
4338
.then(() => Service.explorer.refresh(application))
4439
.then(() => `Service '${serviceName}' successfully created`)
4540
.catch((err) => Promise.reject(`Failed to create service with error '${err}'`));
@@ -54,9 +49,9 @@ export class Service extends OpenShiftItem {
5449
if (!componentToLink) return null;
5550

5651
return Promise.resolve()
57-
.then(() => Service.odo.execute(`odo link ${context.getName()} --app ${app.getName()} --project ${project.getName()} --component ${componentToLink.getName()}`))
58-
.then(() => `service '${context.getName()}' successfully linked with component '${componentToLink.getName()}'`)
59-
.catch((err) => Promise.reject(`Failed to link service with error '${err}'`));
52+
.then(() => Service.odo.execute(`odo link ${context.getName()} --app ${app.getName()} --project ${project.getName()} --component ${componentToLink.getName()}`))
53+
.then(() => `service '${context.getName()}' successfully linked with component '${componentToLink.getName()}'`)
54+
.catch((err) => Promise.reject(`Failed to link service with error '${err}'`));
6055
}
6156

6257
static async del(treeItem: OpenShiftObject): Promise<string> {

test/openshift/component.test.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ suite('Openshift/Component', () => {
2727
sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([]);
2828
sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([]);
2929
sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([]);
30+
sandbox.stub(Component, 'wait').resolves();
3031
});
3132

3233
teardown(() => {
@@ -37,7 +38,10 @@ suite('Openshift/Component', () => {
3738
const componentType = 'nodejs';
3839
const version = 'latest';
3940
const folder = { uri: { fsPath: 'folder' } };
40-
let quickPickStub: sinon.SinonStub, inputStub: sinon.SinonStub, progressStub: sinon.SinonStub;
41+
let quickPickStub: sinon.SinonStub,
42+
inputStub: sinon.SinonStub,
43+
progressStub: sinon.SinonStub,
44+
progressCmdStub: sinon.SinonStub;
4145

4246
setup(() => {
4347
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
@@ -46,6 +50,7 @@ suite('Openshift/Component', () => {
4650
quickPickStub.onThirdCall().resolves(version);
4751
inputStub = sandbox.stub(vscode.window, 'showInputBox');
4852
progressStub = sandbox.stub(Progress, 'execWithProgress').resolves();
53+
progressCmdStub = sandbox.stub(Progress, 'execCmdWithProgress').resolves();
4954
});
5055

5156
test('returns null when cancelled', async () => {
@@ -75,14 +80,13 @@ suite('Openshift/Component', () => {
7580
});
7681

7782
test('happy path works', async () => {
78-
const steps = [
79-
{command: `odo create ${componentType}:${version} ${componentItem.getName()} --local ${folder.uri.fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`, increment: 50},
80-
{command: `odo push ${componentItem.getName()} --local ${folder.uri.fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`, increment: 50}
81-
];
8283
const result = await Component.create(appItem);
8384

8485
expect(result).equals(`Component '${componentItem.getName()}' successfully created`);
85-
expect(progressStub).calledOnceWith(sinon.match.object, steps);
86+
expect(progressCmdStub).calledOnceWith(
87+
`Creating new component '${componentItem.getName()}'`,
88+
`odo create ${componentType}:${version} ${componentItem.getName()} --local ${folder.uri.fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`);
89+
expect(termStub).calledOnceWith(`odo push ${componentItem.getName()} --local ${folder.uri.fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`);
8690
});
8791

8892
test('returns null when no folder selected', async () => {
@@ -126,13 +130,10 @@ suite('Openshift/Component', () => {
126130
});
127131

128132
test('happy path works', async () => {
129-
const steps = [
130-
{command: `odo create ${componentType}:${version} ${componentItem.getName()} --git ${uri} --app ${appItem.getName()} --project ${projectItem.getName()}`, increment: 100}
131-
];
132133
const result = await Component.create(appItem);
133134

134135
expect(result).equals(`Component '${componentItem.getName()}' successfully created`);
135-
expect(progressStub).calledOnceWith(sinon.match.object, steps);
136+
expect(termStub).calledOnceWith(`odo create ${componentType}:${version} ${componentItem.getName()} --git ${uri} --app ${appItem.getName()} --project ${projectItem.getName()}`);
136137
});
137138

138139
test('returns null when no git repo selected', async () => {
@@ -183,13 +184,13 @@ suite('Openshift/Component', () => {
183184
});
184185

185186
test('happy path works', async () => {
186-
const steps = [
187-
{command: `odo create ${componentType}:${version} ${componentItem.getName()} --binary ${files[0].fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`, increment: 100}
188-
];
187+
189188
const result = await Component.create(appItem);
190189

191190
expect(result).equals(`Component '${componentItem.getName()}' successfully created`);
192-
expect(progressStub).calledOnceWith(sinon.match.object, steps);
191+
expect(progressCmdStub).calledOnceWith(
192+
`Creating new component '${componentItem.getName()}'`,
193+
`odo create ${componentType}:${version} ${componentItem.getName()} --binary ${files[0].fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`);
193194
});
194195

195196
test('returns null when no binary file selected', async () => {

test/openshift/service.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,15 @@ suite('Openshift/Service', () => {
4545
quickPickStub.onFirstCall().resolves(templateName);
4646
quickPickStub.onSecondCall().resolves(templatePlan);
4747
inputStub = sandbox.stub(vscode.window, 'showInputBox').resolves(serviceItem.getName());
48-
progressStub = sandbox.stub(Progress, 'execWithProgress').resolves();
48+
progressStub = sandbox.stub(Progress, 'execCmdWithProgress').resolves();
4949
});
5050

5151
test('works with correct inputs', async () => {
5252
const result = await Service.create(appItem);
53-
const steps = [{
54-
command: `odo service create ${templateName} --plan ${templatePlan} ${serviceItem.getName()} --app ${appItem.getName()} --project ${projectItem.getName()}`,
55-
increment: 100
56-
}];
57-
5853
expect(result).equals(`Service '${serviceItem.getName()}' successfully created`);
59-
expect(progressStub).calledOnceWith(sinon.match.object, steps);
54+
expect(progressStub).calledOnceWith(
55+
`Creating new service '${serviceItem.getName()}'`,
56+
`odo service create ${templateName} --plan ${templatePlan} ${serviceItem.getName()} --app ${appItem.getName()} --project ${projectItem.getName()}`);
6057
});
6158

6259
test('returns null with no template selected', async () => {

0 commit comments

Comments
 (0)