Skip to content

Commit fd8adeb

Browse files
authored
provide context folder if no workspace present (#950)
* provide context folder if no workspace present
1 parent dd1b56a commit fd8adeb

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/odo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,10 @@ export class OdoImpl implements Odo {
806806
return this.insertAndReveal(new OpenShiftObjectImpl(project, applicationName, ContextType.APPLICATION, false, this));
807807
}
808808

809-
public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, ref: string = 'master'): Promise<OpenShiftObject> {
809+
public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri): Promise<OpenShiftObject> {
810810
await this.execute(Command.createLocalComponent(application.getParent().getName(), application.getName(), type, version, name, location.fsPath), location.fsPath);
811811
await this.executeInTerminal(Command.pushComponent(), location.fsPath);
812+
workspace.updateWorkspaceFolders(workspace.workspaceFolders? workspace.workspaceFolders.length : 0 , null, { uri: location });
812813
OdoImpl.data.addContexts([workspace.getWorkspaceFolder(location)]);
813814
const targetApplication = (await this.getApplications(application.getParent())).find((value) => value === application);
814815
if (!targetApplication) {
@@ -833,7 +834,7 @@ export class OdoImpl implements Odo {
833834
return null;
834835
}
835836

836-
public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, ref: string = 'master'): Promise<OpenShiftObject> {
837+
public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: Uri): Promise<OpenShiftObject> {
837838
await this.execute(Command.createBinaryComponent(application.getParent().getName(), application.getName(), type, version, name, location.fsPath));
838839
return this.insertAndReveal(new OpenShiftObjectImpl(application, name, ContextType.COMPONENT, false, this, Collapsed, undefined, 'binary'));
839840
}

src/openshift/component.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ import { contextGlobalState } from '../extension';
1818
import { Platform } from '../util/platform';
1919
import path = require('path');
2020
import fs = require('fs-extra');
21-
2221
interface WorkspaceFolderItem extends QuickPickItem {
2322
uri: Uri;
2423
}
24+
class CreateWorkspaceItem implements QuickPickItem {
25+
26+
constructor() { }
27+
28+
get label(): string { return `$(plus) Add new workspace folder.`; }
29+
get description(): string { return 'Folder which does not have an openshift context'; }
2530

31+
}
2632
export class Component extends OpenShiftItem {
2733

2834
static async getOpenshiftData(context: OpenShiftObject): Promise<OpenShiftObject> {
@@ -272,30 +278,39 @@ export class Component extends OpenShiftItem {
272278

273279
static async createFromLocal(context: OpenShiftObject): Promise<string> {
274280
let application: OpenShiftObject = context;
281+
let folder: WorkspaceFolderItem[];
282+
275283
if (!application) application = await Component.getOpenshiftData(context);
276284
if (!application) return null;
277-
let folder: WorkspaceFolderItem;
278285
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
279-
folder = await window.showQuickPick(
280-
(async (): Promise<WorkspaceFolderItem[]> => workspace.workspaceFolders.filter(
281-
(value) => {
282-
let result = true;
283-
try {
284-
result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile();
285-
} catch (ignore) {
286-
}
287-
return result;
286+
folder = workspace.workspaceFolders.filter(
287+
(value) => {
288+
let result = true;
289+
try {
290+
result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile();
291+
} catch (ignore) {
288292
}
289-
).map(
290-
(folder) => ({ label: folder.uri.fsPath, uri: folder.uri})
291-
))(), {
292-
placeHolder: 'Select workspace folder'
293+
return result;
293294
}
295+
).map(
296+
(folder) => ({ label: `$(file-directory) ${folder.uri.fsPath}`, uri: folder.uri })
294297
);
295-
} else {
296-
window.showInformationMessage('Workspace is empty. Please, add folder(s) to workspace and try again.');
297298
}
298-
if (!folder) return null;
299+
const addWorkspaceFolder = new CreateWorkspaceItem();
300+
const choice = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select workspace folder"});
301+
302+
if (!choice) return null;
303+
const workspacePath: Uri = (choice.label === addWorkspaceFolder.label) ?
304+
await window.showOpenDialog({
305+
canSelectFiles: false,
306+
canSelectFolders: true,
307+
canSelectMany: false,
308+
defaultUri: Uri.file(Platform.getUserHomePath()),
309+
openLabel: "Add workspace Folder for Component"
310+
})[0] : folder[0].uri;
311+
312+
if (!workspacePath) return null;
313+
299314
const componentList: Array<OpenShiftObject> = await Component.odo.getComponents(application);
300315
const componentName = await Component.getName('Component name', componentList, application.getName());
301316

@@ -308,7 +323,7 @@ export class Component extends OpenShiftItem {
308323
const componentTypeVersion = await window.showQuickPick(Component.odo.getComponentTypeVersions(componentTypeName), {placeHolder: "Component type version"});
309324

310325
if (!componentTypeVersion) return null;
311-
await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, folder.uri));
326+
await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, workspacePath));
312327
return `Component '${componentName}' successfully created`;
313328
}
314329

0 commit comments

Comments
 (0)