Skip to content

Commit

Permalink
feat: Allow to specify the path to the devfile with factory workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitf committed Oct 19, 2021
1 parent 86893cd commit cd2bf74
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions packages/dashboard-frontend/src/services/helpers/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { History, Location } from 'history';
import { ROUTE } from '../../route.enum';
import { CreateWorkspaceTab, IdeLoaderTab, WorkspaceDetailsTab } from './types';
import { Workspace } from '../workspace-adapter';
import { constants } from 'os';

/* eslint-disable @typescript-eslint/no-non-null-assertion */

Expand Down Expand Up @@ -42,23 +43,41 @@ export function buildFactoryLoaderLocation(url?: string): Location {
const fullUrl = new window.URL(url.toString());

// search for an editor switch and if there is one, remove it from the URL
const editorParam = fullUrl.searchParams.get('che-editor');
let editor;
if (editorParam && typeof(editorParam) === 'string') {
editor = editorParam.slice();
const editor = extractUrlParam(fullUrl, 'che-editor');

// search for devfile switch and if there is one, remove it from the URL
let devfileFilename = extractUrlParam(fullUrl, 'devfileFilename');

// also use short name 'df' if long name is not found
if (!devfileFilename) {
devfileFilename = extractUrlParam(fullUrl, 'df');
}
fullUrl.searchParams.delete('che-editor');

const encodedUrl = encodeURIComponent(fullUrl.toString());

// if editor specified, add it as a new parameter
pathAndQuery = ROUTE.LOAD_FACTORY_URL.replace(':url', encodedUrl);
if (editor) {
pathAndQuery = `${pathAndQuery}&che-editor=${editor}`;
}
if (devfileFilename) {
pathAndQuery = `${pathAndQuery}&override.devfileFilename=${devfileFilename}`;
}
}
return _buildLocationObject(pathAndQuery);
}

// if the given param is defined in the URL, return the value and delete param from the URL
function extractUrlParam(fullUrl: URL, paramName: string): string | undefined {
const param = fullUrl.searchParams.get(paramName);
let value;
if (param && typeof(param) === 'string') {
value = param.slice();
}
fullUrl.searchParams.delete(paramName);
return value;
}

export function buildWorkspacesLocation(): Location {
return _buildLocationObject(ROUTE.WORKSPACES);
}
Expand Down

0 comments on commit cd2bf74

Please sign in to comment.