Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a new route for Factory flow (#517) #518

Merged
merged 2 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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