From 8a717e34317f7f4d3971198c5329ff5674760d26 Mon Sep 17 00:00:00 2001 From: jasquat <2487833+jasquat@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:24:15 -0400 Subject: [PATCH] feature/admin-redirect (#514) * add in a redirect in frontend for admin pages to redirect without admin * use a regex to replace admin * moved the root route to own component to remove routing warnings w/ burnettk --------- Co-authored-by: jasquat --- .../src/components/TaskRouteTabs.tsx | 41 +++++++++++++++++ .../src/routes/AdminRedirect.tsx | 12 +++++ .../src/routes/BaseRoutes.tsx | 5 ++- .../src/routes/HomeRoutes.tsx | 45 ++----------------- .../src/routes/RootRoute.tsx | 13 ++++++ 5 files changed, 73 insertions(+), 43 deletions(-) create mode 100644 spiffworkflow-frontend/src/components/TaskRouteTabs.tsx create mode 100644 spiffworkflow-frontend/src/routes/AdminRedirect.tsx create mode 100644 spiffworkflow-frontend/src/routes/RootRoute.tsx diff --git a/spiffworkflow-frontend/src/components/TaskRouteTabs.tsx b/spiffworkflow-frontend/src/components/TaskRouteTabs.tsx new file mode 100644 index 00000000..3957d937 --- /dev/null +++ b/spiffworkflow-frontend/src/components/TaskRouteTabs.tsx @@ -0,0 +1,41 @@ +import { useEffect, useState } from 'react'; +import { useLocation, useNavigate } from 'react-router-dom'; +import { Tabs, TabList, Tab } from '@carbon/react'; + +export default function TaskRouteTabs() { + const location = useLocation(); + const [selectedTabIndex, setSelectedTabIndex] = useState(0); + const navigate = useNavigate(); + + useEffect(() => { + // Do not remove errors here, or they always get removed. + let newSelectedTabIndex = 0; + if (location.pathname.match(/^\/tasks\/completed-instances\b/)) { + newSelectedTabIndex = 1; + } else if (location.pathname.match(/^\/tasks\/create-new-instance\b/)) { + newSelectedTabIndex = 2; + } + setSelectedTabIndex(newSelectedTabIndex); + }, [location]); + + if (location.pathname.match(/^\/tasks\/\d+\/\b/)) { + return null; + } + return ( + <> + + + {/* navigate('/tasks/my-tasks')}>My Tasks */} + navigate('/tasks/grouped')}>In Progress + navigate('/tasks/completed-instances')}> + Completed + + navigate('/tasks/create-new-instance')}> + Start New + + + + +
+ + ); +} diff --git a/spiffworkflow-frontend/src/routes/AdminRedirect.tsx b/spiffworkflow-frontend/src/routes/AdminRedirect.tsx new file mode 100644 index 00000000..064680f3 --- /dev/null +++ b/spiffworkflow-frontend/src/routes/AdminRedirect.tsx @@ -0,0 +1,12 @@ +import { useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; + +export default function AdminRedirect() { + const navigate = useNavigate(); + useEffect(() => { + const newPath = window.location.pathname.replace(/^\/admin\//, '/'); + navigate(newPath); + }, [navigate]); + + return null; +} diff --git a/spiffworkflow-frontend/src/routes/BaseRoutes.tsx b/spiffworkflow-frontend/src/routes/BaseRoutes.tsx index 919f557f..205a2b01 100644 --- a/spiffworkflow-frontend/src/routes/BaseRoutes.tsx +++ b/spiffworkflow-frontend/src/routes/BaseRoutes.tsx @@ -11,6 +11,8 @@ import ErrorDisplay from '../components/ErrorDisplay'; import ProcessInstanceShortLink from './ProcessInstanceShortLink'; import About from './About'; import Page404 from './Page404'; +import AdminRedirect from './AdminRedirect'; +import RootRoute from './RootRoute'; type OwnProps = { extensionUxElements?: UiSchemaUxElement[] | null; @@ -21,7 +23,7 @@ export default function BaseRoutes({ extensionUxElements }: OwnProps) {
- } /> + } /> } /> } /> } /> @@ -37,6 +39,7 @@ export default function BaseRoutes({ extensionUxElements }: OwnProps) { } /> } /> } /> + } /> } />
diff --git a/spiffworkflow-frontend/src/routes/HomeRoutes.tsx b/spiffworkflow-frontend/src/routes/HomeRoutes.tsx index e7c1873a..1f51b912 100644 --- a/spiffworkflow-frontend/src/routes/HomeRoutes.tsx +++ b/spiffworkflow-frontend/src/routes/HomeRoutes.tsx @@ -1,56 +1,17 @@ -import { useEffect, useState } from 'react'; -import { Route, Routes, useLocation, useNavigate } from 'react-router-dom'; -import { Tabs, TabList, Tab } from '@carbon/react'; +import { Route, Routes } from 'react-router-dom'; import TaskShow from './TaskShow'; import MyTasks from './MyTasks'; import CompletedInstances from './CompletedInstances'; import CreateNewInstance from './CreateNewInstance'; import InProgressInstances from './InProgressInstances'; import OnboardingView from './OnboardingView'; +import TaskRouteTabs from '../components/TaskRouteTabs'; export default function HomeRoutes() { - const location = useLocation(); - const [selectedTabIndex, setSelectedTabIndex] = useState(0); - const navigate = useNavigate(); - - useEffect(() => { - // Do not remove errors here, or they always get removed. - let newSelectedTabIndex = 0; - if (location.pathname.match(/^\/tasks\/completed-instances\b/)) { - newSelectedTabIndex = 1; - } else if (location.pathname.match(/^\/tasks\/create-new-instance\b/)) { - newSelectedTabIndex = 2; - } - setSelectedTabIndex(newSelectedTabIndex); - }, [location]); - - const renderTabs = () => { - if (location.pathname.match(/^\/tasks\/\d+\/\b/)) { - return null; - } - return ( - <> - - - {/* navigate('/tasks/my-tasks')}>My Tasks */} - navigate('/tasks/grouped')}>In Progress - navigate('/tasks/completed-instances')}> - Completed - - navigate('/tasks/create-new-instance')}> - Start New + - - - -
- - ); - }; - return ( <> - {renderTabs()} + } /> } /> diff --git a/spiffworkflow-frontend/src/routes/RootRoute.tsx b/spiffworkflow-frontend/src/routes/RootRoute.tsx new file mode 100644 index 00000000..8aa87ae8 --- /dev/null +++ b/spiffworkflow-frontend/src/routes/RootRoute.tsx @@ -0,0 +1,13 @@ +import InProgressInstances from './InProgressInstances'; +import OnboardingView from './OnboardingView'; +import TaskRouteTabs from '../components/TaskRouteTabs'; + +export default function RootRoute() { + return ( + <> + + + + + ); +}