diff --git a/src/odo.ts b/src/odo.ts index 07210c1fd..dbc8ba85f 100644 --- a/src/odo.ts +++ b/src/odo.ts @@ -806,9 +806,10 @@ export class OdoImpl implements Odo { return this.insertAndReveal(new OpenShiftObjectImpl(project, applicationName, ContextType.APPLICATION, false, this)); } - public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, ref: string = 'master'): Promise { + public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri): Promise { await this.execute(Command.createLocalComponent(application.getParent().getName(), application.getName(), type, version, name, location.fsPath), location.fsPath); await this.executeInTerminal(Command.pushComponent(), location.fsPath); + workspace.updateWorkspaceFolders(workspace.workspaceFolders? workspace.workspaceFolders.length : 0 , null, { uri: location }); OdoImpl.data.addContexts([workspace.getWorkspaceFolder(location)]); const targetApplication = (await this.getApplications(application.getParent())).find((value) => value === application); if (!targetApplication) { @@ -833,7 +834,7 @@ export class OdoImpl implements Odo { return null; } - public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, ref: string = 'master'): Promise { + public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: Uri): Promise { await this.execute(Command.createBinaryComponent(application.getParent().getName(), application.getName(), type, version, name, location.fsPath)); return this.insertAndReveal(new OpenShiftObjectImpl(application, name, ContextType.COMPONENT, false, this, Collapsed, undefined, 'binary')); } diff --git a/src/openshift/component.ts b/src/openshift/component.ts index 8d9cc84ef..9835efa8a 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -18,11 +18,17 @@ import { contextGlobalState } from '../extension'; import { Platform } from '../util/platform'; import path = require('path'); import fs = require('fs-extra'); - interface WorkspaceFolderItem extends QuickPickItem { uri: Uri; } +class CreateWorkspaceItem implements QuickPickItem { + + constructor() { } + + get label(): string { return `$(plus) Add new workspace folder.`; } + get description(): string { return 'Folder which does not have an openshift context'; } +} export class Component extends OpenShiftItem { static async getOpenshiftData(context: OpenShiftObject): Promise { @@ -272,30 +278,39 @@ export class Component extends OpenShiftItem { static async createFromLocal(context: OpenShiftObject): Promise { let application: OpenShiftObject = context; + let folder: WorkspaceFolderItem[]; + if (!application) application = await Component.getOpenshiftData(context); if (!application) return null; - let folder: WorkspaceFolderItem; if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) { - folder = await window.showQuickPick( - (async (): Promise => workspace.workspaceFolders.filter( - (value) => { - let result = true; - try { - result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile(); - } catch (ignore) { - } - return result; + folder = workspace.workspaceFolders.filter( + (value) => { + let result = true; + try { + result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile(); + } catch (ignore) { } - ).map( - (folder) => ({ label: folder.uri.fsPath, uri: folder.uri}) - ))(), { - placeHolder: 'Select workspace folder' + return result; } + ).map( + (folder) => ({ label: `$(file-directory) ${folder.uri.fsPath}`, uri: folder.uri }) ); - } else { - window.showInformationMessage('Workspace is empty. Please, add folder(s) to workspace and try again.'); } - if (!folder) return null; + const addWorkspaceFolder = new CreateWorkspaceItem(); + const choice = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select workspace folder"}); + + if (!choice) return null; + const workspacePath: Uri = (choice.label === addWorkspaceFolder.label) ? + await window.showOpenDialog({ + canSelectFiles: false, + canSelectFolders: true, + canSelectMany: false, + defaultUri: Uri.file(Platform.getUserHomePath()), + openLabel: "Add workspace Folder for Component" + })[0] : folder[0].uri; + + if (!workspacePath) return null; + const componentList: Array = await Component.odo.getComponents(application); const componentName = await Component.getName('Component name', componentList, application.getName()); @@ -308,7 +323,7 @@ export class Component extends OpenShiftItem { const componentTypeVersion = await window.showQuickPick(Component.odo.getComponentTypeVersions(componentTypeName), {placeHolder: "Component type version"}); if (!componentTypeVersion) return null; - await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, folder.uri)); + await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, workspacePath)); return `Component '${componentName}' successfully created`; }