Skip to content

Commit

Permalink
feat: add a new route for Factory flow (#517)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Apr 27, 2022
1 parent 96fd9b2 commit 27ca2f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/dashboard-frontend/src/Routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
*/

import React from 'react';
import { Redirect, Route, Switch } from 'react-router';
import { Redirect, Route, RouteComponentProps, Switch } from 'react-router';

import { ROUTE } from '../route.enum';
import { buildFactoryLoaderPath } from '../preload';

const CreateWorkspace = React.lazy(() => import('../pages/GetStarted'));
const WorkspacesListContainer = React.lazy(() => import('../containers/WorkspacesList'));
Expand Down Expand Up @@ -45,11 +46,23 @@ function Routes(): React.ReactElement {
));
return (
<Switch>
<Route key="simple-factory-url-1" path="/http:\/\/*" render={redirectToFactoryLoader} />
<Route key="simple-factory-url-2" path="/https:\/\/*" render={redirectToFactoryLoader} />
{...routes}
<Redirect key="redirect-to-home" path="*" to="/" />
<Redirect key="redirect-to-home" path="*" to={ROUTE.HOME} />
</Switch>
);
}

function redirectToFactoryLoader(props: RouteComponentProps): React.ReactElement {
const { pathname, search } = props.location;
let factoryUrl = pathname.substring(1) + search;
if (!factoryUrl.includes('?')) {
factoryUrl = factoryUrl.replace('&', '?');
}
const factoryLoaderPath = buildFactoryLoaderPath(factoryUrl).replace(/^\/f/, ROUTE.LOAD_FACTORY);
return <Redirect key="redirect-to-factory" to={factoryLoaderPath} />;
}

Routes.displayName = 'RoutesComponent';
export default Routes;
3 changes: 3 additions & 0 deletions packages/dashboard-frontend/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*/

(function acceptNewFactoryLink(): void {
if (window.location.pathname !== '/') {
return;
}
const hash = window.location.hash.replace(/(\/?)#(\/?)/, '#');
if (hash.startsWith('#http')) {
let factoryUrl = hash.substring(1);
Expand Down

0 comments on commit 27ca2f9

Please sign in to comment.