From ce7898fbd6d26f394410b4c4410c84566b7f6ab5 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 25 Sep 2023 11:31:02 -0400 Subject: [PATCH] some fixes for the error page when backend is down w/ burnettk --- spiffworkflow-frontend/src/App.tsx | 6 - .../src/ContainerForExtensions.tsx | 2 + .../src/components/NavigationBar.tsx | 111 +++++++++--------- spiffworkflow-frontend/src/index.tsx | 2 - 4 files changed, 58 insertions(+), 63 deletions(-) diff --git a/spiffworkflow-frontend/src/App.tsx b/spiffworkflow-frontend/src/App.tsx index fc2bf60e..998a6605 100644 --- a/spiffworkflow-frontend/src/App.tsx +++ b/spiffworkflow-frontend/src/App.tsx @@ -3,16 +3,10 @@ import { defineAbility } from '@casl/ability'; import React from 'react'; import { AbilityContext } from './contexts/Can'; -import UserService from './services/UserService'; import APIErrorProvider from './contexts/APIErrorContext'; import ContainerForExtensions from './ContainerForExtensions'; export default function App() { - if (!UserService.isLoggedIn()) { - UserService.doLogin(); - return null; - } - const ability = defineAbility(() => {}); return (
diff --git a/spiffworkflow-frontend/src/ContainerForExtensions.tsx b/spiffworkflow-frontend/src/ContainerForExtensions.tsx index b9382cbc..22eb8775 100644 --- a/spiffworkflow-frontend/src/ContainerForExtensions.tsx +++ b/spiffworkflow-frontend/src/ContainerForExtensions.tsx @@ -18,6 +18,7 @@ import HttpService from './services/HttpService'; import { ErrorBoundaryFallback } from './ErrorBoundaryFallack'; import BaseRoutes from './routes/BaseRoutes'; import BackendIsDown from './routes/BackendIsDown'; +import UserService from './services/UserService'; export default function ContainerForExtensions() { const [backendIsUp, setBackendIsUp] = useState(null); @@ -93,6 +94,7 @@ export default function ContainerForExtensions() { ]); const routeComponents = () => { + UserService.loginIfNeeded(); return ( (''); const { targetUris } = useUriListForPermissions(); - - // App.jsx forces login (which redirects to keycloak) so we should never get here if we're not logged in. - if (!UserService.isLoggedIn()) { - throw new UnauthenticatedError('You must be authenticated to do this.'); - } const permissionRequestData: PermissionsToCheck = { [targetUris.authenticationListPath]: ['GET'], [targetUris.messageInstanceListPath]: ['GET'], @@ -99,12 +93,6 @@ export default function NavigationBar({ extensionUxElements }: OwnProps) { return activeKey === menuItemPath; }; - let aboutLinkElement = null; - - if (Object.keys(versionInfo).length) { - aboutLinkElement = About; - } - const userEmail = UserService.getUserEmail(); const username = UserService.getPreferredUsername(); @@ -113,48 +101,56 @@ export default function NavigationBar({ extensionUxElements }: OwnProps) { return {uxElement.label}; }; - const profileToggletip = ( -
- - -
{username[0].toUpperCase()}
-
- -

- {username} -

- {username !== userEmail &&

{userEmail}

} -
- {aboutLinkElement} - - Documentation - - - {!UserService.authenticationDisabled() ? ( - <> -
- - - ) : null} -
-
-
- ); + const profileToggletip = () => { + let aboutLinkElement = null; + + if (Object.keys(versionInfo).length) { + aboutLinkElement = About; + } + + return ( +
+ + +
{username[0].toUpperCase()}
+
+ +

+ {username} +

+ {username !== userEmail &&

{userEmail}

} +
+ {aboutLinkElement} + + Documentation + + + {!UserService.authenticationDisabled() ? ( + <> +
+ + + ) : null} +
+
+
+ ); + }; const loginAndLogoutAction = () => { if (UserService.isLoggedIn()) { @@ -168,7 +164,7 @@ export default function NavigationBar({ extensionUxElements }: OwnProps) { {SPIFF_ENVIRONMENT} ) : null} - {profileToggletip} + {profileToggletip()} ); } @@ -292,6 +288,11 @@ export default function NavigationBar({ extensionUxElements }: OwnProps) { ); }; + // App.jsx forces login (which redirects to keycloak) so we should never get here if we're not logged in. + if (!UserService.isLoggedIn()) { + return null; + } + if (activeKey && ability && !UserService.onlyGuestTaskCompletion()) { return ( { ); }; -UserService.loginIfNeeded(); doRender(); // If you want to start measuring performance in your app, pass a function