-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
Copy pathindex.tsx
175 lines (157 loc) · 4.37 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import React from 'react';
import { Routes, Route, Link } from 'react-router-dom';
import { ErrorBoundary } from '@ohif/ui-next';
// 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';
import PropTypes from 'prop-types';
import { routerBase, routerBasename } from '../utils/publicUrl';
const NotFoundServer = ({
message = 'Unable to query for studies at this time. Check your data source configuration or network connection',
}) => {
return (
<div className="absolute flex h-full w-full items-center justify-center text-white">
<div>
<h4>{message}</h4>
</div>
</div>
);
};
NotFoundServer.propTypes = {
message: PropTypes.string,
};
const NotFoundStudy = () => {
return (
<div className="absolute flex h-full w-full items-center justify-center text-white">
<div>
<h4>
One or more of the requested studies are not available at this time. Return to the{' '}
<Link
className="text-primary-light"
to={'/'}
>
study list
</Link>{' '}
to select a different study to view.
</h4>
</div>
</div>
);
};
NotFoundStudy.propTypes = {
message: PropTypes.string,
};
// TODO: Include "routes" debug route if dev build
const bakedInRoutes = [
{
path: `/notfoundserver`,
children: NotFoundServer,
},
{
path: `/notfoundstudy`,
children: NotFoundStudy,
},
{
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,
showStudyList,
}: withAppTypes) => {
const routes =
buildModeRoutes({
modes,
dataSources,
extensionManager,
servicesManager,
commandsManager,
hotkeysManager,
}) || [];
const { customizationService } = servicesManager.services;
const path =
routerBasename.length > 1 && routerBasename.endsWith('/')
? routerBasename.substring(0, routerBasename.length - 1)
: routerBasename;
console.log('Registering worklist route', routerBasename, path);
const WorkListRoute = {
path: '/',
children: DataSourceWrapper,
private: true,
props: { children: WorkList, servicesManager, extensionManager },
};
const customRoutes = customizationService.getCustomization('routes.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}`}>
<route.children
{...rest}
{...route.props}
route={route}
servicesManager={servicesManager}
extensionManager={extensionManager}
hotkeysManager={hotkeysManager}
/>
</ErrorBoundary>
);
}
const { userAuthenticationService } = servicesManager.services;
// All routes are private by default and then we let the user auth service
// to check if it is enabled or not
// Todo: I think we can remove the second public return below
return (
<Routes>
{allRoutes.map((route, i) => {
return route.private === true ? (
<Route
key={i}
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;