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 bb9ff53
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions packages/dashboard-frontend/src/services/helpers/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,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 devfilePath = extractUrlParam(fullUrl, 'devfilePath');

// also use short name 'df' if long name is not found
if (!devfilePath) {
devfilePath = 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 (devfilePath) {
pathAndQuery = `${pathAndQuery}&override.devfileFilename=${devfilePath}`;
}
}
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 bb9ff53

Please sign in to comment.