Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export interface Odo {
deleteURL(url: OpenShiftObject): Promise<OpenShiftObject>;
createComponentCustomUrl(component: OpenShiftObject, name: string, port: string, secure?: boolean): Promise<OpenShiftObject>;
getOpenShiftObjectByContext(context: string): OpenShiftObject;
getSettingsByContext(context: string): odo.Component;
loadItems<I>(result: cliInstance.CliExitData, fetch: (data) => I[]): I[];
getRegistries(): Promise<Registry[]>;
readonly subject: Subject<OdoEvent>;
Expand Down Expand Up @@ -1029,6 +1030,10 @@ export class OdoImpl implements Odo {
return OdoImpl.data.getObjectByContext(Uri.file(context));
}

getSettingsByContext(context: string): odo.Component {
return OdoImpl.data.getSettingsByContext(context);
}

async loadWorkspaceComponents(event: WorkspaceFoldersChangeEvent): Promise<void> {
const clusters = (await this.getClusters());
if(!clusters) return;
Expand Down
24 changes: 23 additions & 1 deletion src/openshift/openshiftItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*-----------------------------------------------------------------------------------------------*/
/* eslint-disable @typescript-eslint/ban-types */

import { window, QuickPickItem, commands } from 'vscode';
import { window, QuickPickItem, commands, workspace } from 'vscode';
import * as validator from 'validator';
import { Odo, getInstance, OpenShiftObject, ContextType, OpenShiftApplication, OpenShiftProject } from '../odo';
import { OpenShiftExplorer } from '../explorer';
Expand Down Expand Up @@ -159,13 +159,35 @@ export default class OpenShiftItem {
let context: OpenShiftObject | QuickPickCommand = treeItem;
let project: OpenShiftObject;
if (!context) {

const clusters = await this.odo.getClusters();
if (clusters.length) { // connected to cluster because odo version printed out server url
const projects = await this.odo.getProjects();
context = projects.find((prj:OpenShiftProject)=>prj.active);
if (!context) {
throw new VsCommandError(errorMessage.Project)
}
// first try to get target component out of active editor
const currentEditorFile = window?.activeTextEditor?.document?.uri;
if (currentEditorFile) {
const contextFolder = workspace.getWorkspaceFolder(currentEditorFile);
if (contextFolder) {
const oso = this.odo.getOpenShiftObjectByContext(contextFolder.uri.fsPath);
if (!oso) {
const applications = await this.odo.getApplications(context);
const settings = this.odo.getSettingsByContext(contextFolder.uri.fsPath);
if (settings) {
const app = applications.find((a) => a.getName() === settings.spec.app);
if(app) {
await this.odo.getComponents(app);
context = this.odo.getOpenShiftObjectByContext(contextFolder.uri.fsPath);
}
}
} else if (context?.getName() === oso?.getParent()?.getParent()?.getName()) {
context = oso;
}
}
}
} else { // cluster is not accessible or user not logged in
const projectName = await OpenShiftItem.getName('Project Name', Promise.resolve([]))
if (projectName) {
Expand Down