-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathindex.jsx
595 lines (586 loc) · 21.8 KB
/
index.jsx
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import {
BrowserRouter, Route, Switch, Redirect,
} from 'react-router-dom';
import { createBrowserHistory } from 'history';
import {
createReactRouterV5Options,
getWebInstrumentations,
initializeFaro,
ReactIntegration,
FaroRoute,
} from '@grafana/faro-react';
import { ThemeProvider } from 'styled-components';
import querystring from 'querystring';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faAngleUp, faAngleDown, faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons';
import { Helmet } from 'react-helmet';
import { datadogRum } from '@datadog/browser-rum';
import 'antd/dist/antd.css';
import '@gen3/ui-component/dist/css/base.less';
import { fetchAndSetCsrfToken } from './configs';
import {
fetchDictionary,
fetchSchema,
fetchVersionInfo,
fetchUserAccess,
fetchUserAuthMapping,
updateSystemUseNotice,
} from './actions';
import ReduxLogin, { fetchLogin } from './Login/ReduxLogin';
import ProtectedContent from './Login/ProtectedContent';
import HomePage from './Homepage/page';
import DocumentPage from './Document/page';
import { fetchCoreMetadata, ReduxCoreMetadataPage } from './CoreMetadata/reduxer';
import Indexing from './Indexing/Indexing';
import IndexPage from './Index/page';
import DataDictionary from './DataDictionary';
import ReduxPrivacyPolicy from './PrivacyPolicy/ReduxPrivacyPolicy';
import ProjectSubmission from './Submission/ReduxProjectSubmission';
import ReduxMapFiles from './Submission/ReduxMapFiles';
import ReduxMapDataModel from './Submission/ReduxMapDataModel';
import UserProfile, { fetchAccess } from './UserProfile/ReduxUserProfile';
import UserAgreementCert from './UserAgreement/ReduxCertPopup';
import GraphQLQuery from './GraphQLEditor/ReduxGqlEditor';
import theme from './theme';
import getReduxStore from './reduxStore';
import { ReduxNavBar, ReduxTopBar, ReduxFooter } from './Layout/reduxer';
import ReduxQueryNode, { submitSearchForm } from './QueryNode/ReduxQueryNode';
import {
basename, gaTrackingId, workspaceUrl, workspaceErrorUrl, Error403Url,
indexPublic, explorerPublic, enableResourceBrowser, resourceBrowserPublic, enableDAPTracker,
discoveryConfig, commonsWideAltText, ddApplicationId, ddClientToken, ddEnv, ddUrl, ddSampleRate, knownBotRegex,
userAccessToSite, grafanaFaroConfig, hostnameWithSubdomain,
} from './localconf';
import { portalVersion } from './versions';
import Analysis from './Analysis/Analysis';
import ReduxAnalysisApp from './Analysis/ReduxAnalysisApp';
import { components } from './params';
import { GAInit, GARouteTracker } from './components/GoogleAnalytics';
import { DAPRouteTracker } from './components/DAPAnalytics';
import GuppyDataExplorer from './GuppyDataExplorer';
import isEnabled from './helpers/featureFlags';
import sessionMonitor from './SessionMonitor';
import workspaceSessionMonitor from './Workspace/WorkspaceSessionMonitor';
import Workspace from './Workspace';
import ResourceBrowser from './ResourceBrowser';
import Discovery from './Discovery';
import ReduxWorkspaceShutdownPopup from './Popup/ReduxWorkspaceShutdownPopup';
import ReduxWorkspaceShutdownBanner from './Popup/ReduxWorkspaceShutdownBanner';
import ErrorWorkspacePlaceholder from './Workspace/ErrorWorkspacePlaceholder';
import { ReduxStudyViewer, ReduxSingleStudyViewer } from './StudyViewer/reduxer';
import NotFound from './components/NotFound';
import AccessDenied from './components/AccessDenied';
import ErrorPage403 from './components/ErrorPage403';
import GenericAccessRequestForm from './GenericAccessRequestForm/GenericAccessRequestForm';
// monitor user's session
sessionMonitor.start();
workspaceSessionMonitor.start();
// render the app after the store is configured
async function init() {
const store = await getReduxStore();
// Datadog setup
if (ddApplicationId && !ddClientToken) {
// eslint-disable-next-line no-console
console.warn('Datadog applicationId is set, but clientToken is missing');
} else if (!ddApplicationId && ddClientToken) {
// eslint-disable-next-line no-console
console.warn('Datadog clientToken is set, but applicationId is missing');
} else if (ddApplicationId && ddClientToken) {
const conditionalSampleRate = knownBotRegex.test(navigator.userAgent) ? 0 : ddSampleRate;
datadogRum.init({
applicationId: ddApplicationId,
clientToken: ddClientToken,
site: ddUrl,
service: 'portal',
env: ddEnv,
version: portalVersion,
sampleRate: conditionalSampleRate,
trackInteractions: true,
});
}
// setup Grafana Faro
const history = createBrowserHistory();
// to filter bots from RUM, see https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/instrument/filter-bots/#filter-bots-by-user-agent
let conditionalSampleRate = knownBotRegex.test(navigator.userAgent) ? 0 : grafanaFaroConfig.grafanaFaroSampleRate;
if (!grafanaFaroConfig.grafanaFaroEnable) {
conditionalSampleRate = 0;
}
initializeFaro({
url: grafanaFaroConfig.grafanaFaroUrl,
app: {
name: 'portal',
version: portalVersion,
namespace: grafanaFaroConfig.grafanaFaroNamespace,
environment: hostnameWithSubdomain,
},
instrumentations: [
...getWebInstrumentations(),
new ReactIntegration({
router: createReactRouterV5Options({
history,
Route,
}),
}),
],
sessionTracking: {
enabled: true,
persistent: true,
samplingRate: conditionalSampleRate,
},
ignoreUrls: ['https://*.logs.datadoghq.com', 'https://*.browser-intake-ddog-gov.com', 'https://www.google-analytics.com', 'https://*.analytics.google.com', 'https://analytics.google.com', 'https://*.g.doubleclick.net'],
});
await Promise.all(
[
store.dispatch(fetchSchema),
store.dispatch(fetchDictionary),
store.dispatch(fetchVersionInfo),
// resources can be open to anonymous users, so fetch access:
store.dispatch(fetchUserAccess),
store.dispatch(fetchUserAuthMapping),
store.dispatch(updateSystemUseNotice(null)),
// eslint-disable-next-line no-console
fetchAndSetCsrfToken().catch((err) => { console.log('error on csrf load - should still be ok', err); }),
],
);
// FontAwesome icons
library.add(faAngleUp, faAngleDown, faExternalLinkAlt);
// For any platform-wide branded logos (Gen3, CTDS logos), apply standardized
// alt text. For the commons-specific logo, use the appName attribute to apply
// accessible alt text.
for (let i = 0; i < components.footerLogos.length; i += 1) {
if (Object.prototype.hasOwnProperty.call(commonsWideAltText, components.footerLogos[i].href)) {
components.footerLogos[i].alt = commonsWideAltText[components.footerLogos[i].href];
}
}
render(
<div>
<Provider store={store}>
<ThemeProvider theme={theme}>
<BrowserRouter basename={basename}>
<div>
{(GAInit(gaTrackingId)) && <GARouteTracker />}
{enableDAPTracker && <DAPRouteTracker />}
{isEnabled('noIndex')
? (
<Helmet>
<meta name='robots' content='noindex,nofollow' />
</Helmet>
)
: null}
<ReduxTopBar />
<ReduxNavBar />
<div className='main-content' id='main-content'>
<ReduxWorkspaceShutdownBanner />
<ReduxWorkspaceShutdownPopup />
<Switch>
{/* process with trailing and duplicate slashes first */}
{/* see https://github.com/ReactTraining/react-router/issues/4841#issuecomment-523625186 */}
{/* Removes trailing slashes */}
<FaroRoute
path='/:url*(/+)'
exact
strict
render={({ location }) => (
<Redirect to={location.pathname.replace(/\/+$/, '')} />
)}
/>
{/* Removes duplicate slashes in the middle of the URL */}
<FaroRoute
path='/:url(.*//+.*)'
exact
strict
render={({ match }) => (
<Redirect to={`/${match.params.url.replace(/\/\/+/, '/')}`} />
)}
/>
<FaroRoute
exact
path='/login'
component={
(
(props) => (
<ProtectedContent
public
filter={() => store.dispatch(fetchLogin())}
component={ReduxLogin}
{...props}
/>
)
)
}
/>
<FaroRoute
exact
path='/'
component={
(props) => (
<ProtectedContent
public={indexPublic}
component={IndexPage}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/submission'
component={
(props) => <ProtectedContent component={HomePage} {...props} />
}
/>
<FaroRoute
exact
path='/submission/files'
component={
(props) => <ProtectedContent component={ReduxMapFiles} {...props} />
}
/>
<FaroRoute
exact
path='/submission/map'
component={
(props) => <ProtectedContent component={ReduxMapDataModel} {...props} />
}
/>
<FaroRoute
exact
path='/document'
component={
(props) => <ProtectedContent component={DocumentPage} {...props} />
}
/>
<FaroRoute
exact
path='/query'
component={
(props) => <ProtectedContent component={GraphQLQuery} {...props} />
}
/>
{
isEnabled('analysis')
? (
<FaroRoute
exact
path='/analysis/:app'
component={
(props) => <ProtectedContent component={ReduxAnalysisApp} {...props} />
}
/>
)
: null
}
{
isEnabled('analysis')
? (
<FaroRoute
exact
path='/analysis'
component={
(props) => <ProtectedContent component={Analysis} {...props} />
}
/>
)
: null
}
<FaroRoute
exact
path='/identity'
component={
(props) => (
<ProtectedContent
filter={() => store.dispatch(fetchAccess())}
component={UserProfile}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/indexing'
component={
(props) => (
<ProtectedContent
component={Indexing}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/quiz'
component={
(props) => (
<ProtectedContent
component={UserAgreementCert}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/dd/:node'
component={
(props) => (
<ProtectedContent
public
component={DataDictionary}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/dd'
component={
(props) => (
<ProtectedContent
public
component={DataDictionary}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/files/*'
component={
(props) => (
<ProtectedContent
filter={() => store.dispatch(fetchCoreMetadata(props.match.params[0]))}
component={ReduxCoreMetadataPage}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/files'
component={
(props) => (
<ProtectedContent
public={explorerPublic}
component={GuppyDataExplorer}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/workspace'
component={
(props) => <ProtectedContent component={Workspace} {...props} />
}
/>
{
isEnabled('workspaceRegistration')
? (
<FaroRoute
exact
path='/workspace/request-access'
component={
(props) => (
<ProtectedContent
component={GenericAccessRequestForm}
{...props}
/>
)
}
/>
)
: null
}
<FaroRoute
exact
path={workspaceUrl}
component={ErrorWorkspacePlaceholder}
/>
<FaroRoute
exact
path={workspaceErrorUrl}
component={ErrorWorkspacePlaceholder}
/>
<FaroRoute
path='/:project/search'
component={
(props) => {
const queryFilter = () => {
const { location } = props;
const queryParams = querystring.parse(location.search ? location.search.replace(/^\?+/, '') : '');
if (Object.keys(queryParams).length > 0) {
// Linking directly to a search result,
// so kick-off search here (rather than on button click)
return store.dispatch(
submitSearchForm({
project: props.match.params.project, ...queryParams,
}),
);
}
return Promise.resolve('ok');
};
return (
<ProtectedContent
filter={queryFilter}
component={ReduxQueryNode}
{...props}
/>
);
}
}
/>
{isEnabled('explorer')
? (
<FaroRoute
exact
path='/explorer'
component={
(props) => (
<ProtectedContent
public={explorerPublic}
component={GuppyDataExplorer}
{...props}
/>
)
}
/>
)
: null}
{components.privacyPolicy
&& (!!components.privacyPolicy.file || !!components.privacyPolicy.routeHref)
? (
<FaroRoute
exact
path='/privacy-policy'
component={ReduxPrivacyPolicy}
/>
)
: null}
{enableResourceBrowser
? (
<FaroRoute
exact
path='/resource-browser'
component={
(props) => (
<ProtectedContent
public={resourceBrowserPublic}
component={ResourceBrowser}
{...props}
/>
)
}
/>
)
: null}
<FaroRoute
exact
path='/study-viewer/:dataType'
component={
(props) => (
<ProtectedContent
public
component={ReduxStudyViewer}
{...props}
/>
)
}
/>
<FaroRoute
exact
path='/study-viewer/:dataType/:rowAccessor'
component={
(props) => (
<ProtectedContent
public
component={ReduxSingleStudyViewer}
{...props}
/>
)
}
/>
{isEnabled('discovery')
&& (
<FaroRoute
exact
path='/discovery'
component={
(props) => (
<ProtectedContent
public={discoveryConfig.public !== false}
component={Discovery}
{...props}
/>
)
}
/>
)}
{isEnabled('discovery') && (
<FaroRoute
exact
path='/discovery/:studyUID*'
component={
(props) => (
<ProtectedContent
public={discoveryConfig.public !== false}
component={Discovery}
{...props}
/>
)
}
/>
)}
<FaroRoute
path='/not-found'
component={NotFound}
/>
{userAccessToSite?.enabled && (
<FaroRoute
path={userAccessToSite.deniedPageURL || '/access-denied'}
component={AccessDenied}
/>
)}
<FaroRoute
path={Error403Url}
component={ErrorPage403}
/>
<FaroRoute
exact
path='/:project'
component={
(props) => (
<ProtectedContent
component={ProjectSubmission}
{...props}
/>
)
}
/>
<FaroRoute
path='*'
component={NotFound}
/>
</Switch>
</div>
<ReduxFooter
logos={components.footerLogos}
privacyPolicy={components.privacyPolicy}
/>
</div>
</BrowserRouter>
</ThemeProvider>
</Provider>
</div>,
document.getElementById('root'),
);
}
init();