Files
ohif-viewer/platform/viewer/src/routes/index.tsx
T
Alireza e055f25ea6 fix(local): should use dicomlocal for localbasic (#3397)
* fix(local): should use dicomlocal for localbasic

* chore(github): styling for issues forms

* try to fix netlify

* apply review comments

* apply review comments
2023-05-17 12:45:06 -04:00

124 lines
3.0 KiB
TypeScript

import React from 'react';
import { Routes, Route } from 'react-router-dom';
import { ErrorBoundary } from '@ohif/ui';
// Route Components
import DataSourceWrapper from './DataSourceWrapper';
import WorkList from './WorkList';
import Local from './Local';
import Debug from './Debug';
import NotFound from './NotFound';
import buildModeRoutes from './buildModeRoutes';
import PrivateRoute from './PrivateRoute';
// TODO: Include "routes" debug route if dev build
const bakedInRoutes = [
{
path: '/debug',
children: Debug,
},
{
path: '/local',
children: Local.bind(null, { modePath: '' }), // navigate to the worklist
},
{
path: '/localbasic',
children: Local.bind(null, { modePath: 'viewer/dicomlocal' }),
},
];
// NOT FOUND (404)
const notFoundRoute = { component: NotFound };
const createRoutes = ({
modes,
dataSources,
extensionManager,
servicesManager,
commandsManager,
hotkeysManager,
routerBasename,
showStudyList,
}) => {
const routes =
buildModeRoutes({
modes,
dataSources,
extensionManager,
servicesManager,
commandsManager,
hotkeysManager,
}) || [];
const { customizationService } = servicesManager.services;
const WorkListRoute = {
path: '/',
children: DataSourceWrapper,
private: true,
props: { children: WorkList, servicesManager },
};
const customRoutes = customizationService.getGlobalCustomization(
'customRoutes'
);
const allRoutes = [
...routes,
...(showStudyList ? [WorkListRoute] : []),
...(customRoutes?.routes || []),
...bakedInRoutes,
customRoutes?.notFoundRoute || notFoundRoute,
];
function RouteWithErrorBoundary({ route, ...rest }) {
// eslint-disable-next-line react/jsx-props-no-spreading
return (
<ErrorBoundary context={`Route ${route.path}`} fallbackRoute="/">
<route.children
{...rest}
{...route.props}
route={route}
servicesManager={servicesManager}
extensionManager={extensionManager}
hotkeysManager={hotkeysManager}
/>
</ErrorBoundary>
);
}
const { userAuthenticationService } = servicesManager.services;
// Note: PrivateRoutes in react-router-dom 6.x should be defined within
// a Route element
return (
<Routes>
{allRoutes.map((route, i) => {
return route.private === true ? (
<Route
key={i}
exact
path={route.path}
element={
<PrivateRoute
handleUnauthenticated={
userAuthenticationService.handleUnauthenticated
}
>
<RouteWithErrorBoundary route={route} />
</PrivateRoute>
}
></Route>
) : (
<Route
key={i}
path={route.path}
element={<RouteWithErrorBoundary route={route} />}
/>
);
})}
</Routes>
);
};
export default createRoutes;