2022-10-12 10:21:49 -04:00
|
|
|
import { useMemo, useState } from 'react';
|
2022-10-31 15:09:21 -04:00
|
|
|
// @ts-ignore
|
2022-10-31 16:03:14 -04:00
|
|
|
import { Content } from '@carbon/react';
|
2022-10-12 10:21:49 -04:00
|
|
|
|
|
|
|
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
2022-11-15 14:40:35 -05:00
|
|
|
import { defineAbility } from '@casl/ability';
|
2022-10-12 10:21:49 -04:00
|
|
|
import ErrorContext from './contexts/ErrorContext';
|
|
|
|
import NavigationBar from './components/NavigationBar';
|
|
|
|
|
2022-11-10 17:30:27 -05:00
|
|
|
import HomePageRoutes from './routes/HomePageRoutes';
|
2022-10-12 10:21:49 -04:00
|
|
|
import ErrorBoundary from './components/ErrorBoundary';
|
|
|
|
import AdminRoutes from './routes/AdminRoutes';
|
2022-10-18 16:41:13 -04:00
|
|
|
import { ErrorForDisplay } from './interfaces';
|
2022-10-12 10:21:49 -04:00
|
|
|
|
2022-11-15 14:40:35 -05:00
|
|
|
import { AbilityContext } from './contexts/Can';
|
2022-12-14 12:23:49 -05:00
|
|
|
import UserService from './services/UserService';
|
2022-12-28 15:03:02 -05:00
|
|
|
import { Notification } from './components/Notification';
|
2022-11-15 14:40:35 -05:00
|
|
|
|
2022-10-12 10:21:49 -04:00
|
|
|
export default function App() {
|
2022-12-28 16:29:17 -05:00
|
|
|
const [errorObject, setErrorObject] = useState<ErrorForDisplay | null>(null);
|
2022-10-12 10:21:49 -04:00
|
|
|
|
|
|
|
const errorContextValueArray = useMemo(
|
2022-12-28 16:29:17 -05:00
|
|
|
() => [errorObject, setErrorObject],
|
|
|
|
[errorObject]
|
2022-10-12 10:21:49 -04:00
|
|
|
);
|
|
|
|
|
2022-12-14 12:23:49 -05:00
|
|
|
if (!UserService.isLoggedIn()) {
|
|
|
|
UserService.doLogin();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-15 17:35:16 -05:00
|
|
|
const ability = defineAbility(() => {});
|
2022-11-15 14:40:35 -05:00
|
|
|
|
2022-10-12 10:21:49 -04:00
|
|
|
let errorTag = null;
|
2022-12-28 16:29:17 -05:00
|
|
|
if (errorObject) {
|
2022-10-18 16:41:13 -04:00
|
|
|
let sentryLinkTag = null;
|
2022-12-28 16:29:17 -05:00
|
|
|
if (errorObject.sentry_link) {
|
2022-10-18 16:41:13 -04:00
|
|
|
sentryLinkTag = (
|
|
|
|
<span>
|
|
|
|
{
|
|
|
|
': Find details about this error here (it may take a moment to become available): '
|
|
|
|
}
|
2022-12-28 16:29:17 -05:00
|
|
|
<a href={errorObject.sentry_link} target="_blank" rel="noreferrer">
|
|
|
|
{errorObject.sentry_link}
|
2022-10-18 16:41:13 -04:00
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
2022-12-28 16:29:17 -05:00
|
|
|
|
|
|
|
let message = <div>{errorObject.message}</div>;
|
|
|
|
let title = 'Error:';
|
|
|
|
if ('task_name' in errorObject) {
|
|
|
|
title = `Error in python script:`;
|
|
|
|
message = (
|
|
|
|
<>
|
|
|
|
<br />
|
|
|
|
<div>
|
|
|
|
Task: {errorObject.task_name} ({errorObject.task_id})
|
|
|
|
</div>
|
|
|
|
<div>File name: {errorObject.file_name}</div>
|
|
|
|
<div>Line number in script task: {errorObject.line_number}</div>
|
|
|
|
<br />
|
|
|
|
<div>{errorObject.message}</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-12 10:21:49 -04:00
|
|
|
errorTag = (
|
2022-12-28 15:03:02 -05:00
|
|
|
<Notification
|
2022-12-28 16:29:17 -05:00
|
|
|
title={title}
|
|
|
|
onClose={() => setErrorObject(null)}
|
2022-12-28 15:03:02 -05:00
|
|
|
type="error"
|
|
|
|
>
|
2022-12-28 16:29:17 -05:00
|
|
|
{message}
|
2022-10-18 16:41:13 -04:00
|
|
|
{sentryLinkTag}
|
2022-12-28 15:03:02 -05:00
|
|
|
</Notification>
|
2022-10-12 10:21:49 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-11-07 10:10:47 -05:00
|
|
|
<div className="cds--white">
|
2022-11-15 14:40:35 -05:00
|
|
|
{/* @ts-ignore */}
|
|
|
|
<AbilityContext.Provider value={ability}>
|
|
|
|
<ErrorContext.Provider value={errorContextValueArray}>
|
|
|
|
<BrowserRouter>
|
|
|
|
<NavigationBar />
|
|
|
|
<Content>
|
|
|
|
{errorTag}
|
|
|
|
<ErrorBoundary>
|
|
|
|
<Routes>
|
2022-11-16 12:57:17 -05:00
|
|
|
<Route path="/*" element={<HomePageRoutes />} />
|
2022-11-15 14:40:35 -05:00
|
|
|
<Route path="/tasks/*" element={<HomePageRoutes />} />
|
|
|
|
<Route path="/admin/*" element={<AdminRoutes />} />
|
|
|
|
</Routes>
|
|
|
|
</ErrorBoundary>
|
|
|
|
</Content>
|
|
|
|
</BrowserRouter>
|
|
|
|
</ErrorContext.Provider>
|
|
|
|
</AbilityContext.Provider>
|
2022-11-07 10:10:47 -05:00
|
|
|
</div>
|
2022-10-12 10:21:49 -04:00
|
|
|
);
|
|
|
|
}
|