Skip to content

Commit 62bcd49

Browse files
authored
Activate new project after active one is deleted (#1689)
Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 403d197 commit 62bcd49

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/odo.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {Collapsed} = TreeItemCollapsibleState;
3535

3636
export interface OpenShiftObject extends QuickPickItem {
3737
getChildren(): ProviderResult<OpenShiftObject[]>;
38+
removeChild(item: OpenShiftObject): Promise<void>;
3839
getParent(): OpenShiftObject;
3940
getName(): string;
4041
contextValue: ContextType;
@@ -123,6 +124,11 @@ export abstract class OpenShiftObjectImpl implements OpenShiftObject {
123124
return;
124125
}
125126

127+
public async removeChild(item: OpenShiftObject): Promise<void> {
128+
const array = await item.getChildren();
129+
array.splice(array.indexOf(item), 1);
130+
}
131+
126132
getParent(): OpenShiftObject {
127133
return this.parent;
128134
}
@@ -146,6 +152,11 @@ export class OpenShiftCluster extends OpenShiftObjectImpl {
146152
async getChildren(): Promise<OpenShiftObject[]> {
147153
return [(await this.odo.getProjects()).find((prj:OpenShiftProject)=>prj.active)];
148154
}
155+
156+
public async removeChild(item: OpenShiftObject): Promise<void> {
157+
const array = await this.odo.getProjects();
158+
array.splice(array.indexOf(item), 1);
159+
}
149160
}
150161

151162
export class OpenShiftProject extends OpenShiftObjectImpl {
@@ -421,8 +432,7 @@ class OdoModel {
421432
}
422433

423434
public async delete(item: OpenShiftObject): Promise<void> {
424-
const array = await item.getParent().getChildren();
425-
array.splice(array.indexOf(item), 1);
435+
await item.getParent().removeChild(item);
426436
this.pathToObject.delete(item.path);
427437
if (item.contextPath) {
428438
this.contextToObject.delete(item.contextPath.fsPath);

src/openshift/project.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export class Project extends OpenShiftItem {
4545
if (value === 'Yes') {
4646
result = Progress.execFunctionWithProgress(`Deleting Project '${project.getName()}'`,
4747
() => Project.odo.deleteProject(project)
48+
.then(async () => {
49+
const p = await Project.odo.getProjects();
50+
if (p.length>0) {
51+
await Project.odo.execute(`odo project set ${p[0].getName()}`);
52+
Project.explorer.refresh();
53+
}
54+
})
4855
.then(() => `Project '${project.getName()}' successfully deleted`)
4956
.catch((err) => Promise.reject(new VsCommandError(`Failed to delete Project with error '${err}'`)))
5057
);

test/unit/openshift/testOSItem.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { Uri } from "vscode";
77
import { OpenShiftObject, ContextType } from "../../../src/odo";
88
import { SourceType } from "../../../src/odo/config";
9+
import { BuilderImage } from "../../../src/odo/builderImage";
910

1011
export class TestItem implements OpenShiftObject {
1112
public treeItem = null;
@@ -21,6 +22,13 @@ export class TestItem implements OpenShiftObject {
2122
public compType: string = SourceType.LOCAL) {
2223
}
2324

25+
builderImage?: BuilderImage;
26+
iconPath?: Uri;
27+
description?: string;
28+
detail?: string;
29+
picked?: boolean;
30+
alwaysShow?: boolean;
31+
2432
getName(): string {
2533
return this.name;
2634
}
@@ -33,11 +41,16 @@ export class TestItem implements OpenShiftObject {
3341
return this.children;
3442
}
3543

44+
removeChild(item: OpenShiftObject): Promise<void> {
45+
return;
46+
}
47+
3648
getParent(): OpenShiftObject {
3749
return this.parent;
3850
}
3951

4052
get label(): string {
4153
return this.name;
4254
}
55+
ge
4356
}

0 commit comments

Comments
 (0)