Skip to content

Commit 6b27548

Browse files
committed
Activate first project if odo return array without active one
This PR fixes #2359. Signed-off-by: Denis Golovin [email protected]
1 parent b8e52ce commit 6b27548

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/odo.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ export class OpenShiftCluster extends OpenShiftObjectImpl {
174174
}
175175

176176
async getChildren(): Promise<OpenShiftObject[]> {
177-
const activeProject = (await this.odo.getProjects()).find((prj:OpenShiftProject)=>prj.active)
177+
const prjs = await this.odo.getProjects();
178+
let activeProject = prjs.find((prj:OpenShiftProject)=>prj.active);
179+
if (prjs.length > 0 && !activeProject) {
180+
// no active project after login
181+
await OdoImpl.Instance.execute(Command.setActiveProject(prjs[0].getName()));
182+
activeProject = prjs[0];
183+
}
178184
return activeProject ? [activeProject] : [];
179185
}
180186

src/odo/command.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export class Command {
117117
);
118118
}
119119

120+
static setActiveProject(name: string): CommandText {
121+
return new CommandText('odo project set', name);
122+
}
123+
120124
static deleteProject(name: string): CommandText {
121125
return new CommandText(
122126
'odo project delete',

0 commit comments

Comments
 (0)