From 8e52500547ed96ac2d7e8573cd61580ac0139046 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Sun, 18 Aug 2024 08:51:55 +0100 Subject: [PATCH] Client-side redirect /classify to /classify/workflow/[workflowID] --- .../ClassifyPage/ClassifyPageConnector.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/app-project/src/screens/ClassifyPage/ClassifyPageConnector.js b/packages/app-project/src/screens/ClassifyPage/ClassifyPageConnector.js index f1015364f40..1b613ab9b3d 100644 --- a/packages/app-project/src/screens/ClassifyPage/ClassifyPageConnector.js +++ b/packages/app-project/src/screens/ClassifyPage/ClassifyPageConnector.js @@ -1,4 +1,5 @@ import { MobXProviderContext, observer } from 'mobx-react' +import { useRouter } from 'next/router' import { useContext } from 'react' import ClassifyPageContainer from './ClassifyPageContainer' @@ -22,7 +23,12 @@ function useStore(store) { } } -function ClassifyPageConnector(props) { +function ClassifyPageConnector({ + // workflow ID from the page URL + workflowID, + ...props +}) { + const router = useRouter() const { store } = useContext(MobXProviderContext) const { appLoadingState, @@ -32,8 +38,15 @@ function ClassifyPageConnector(props) { workflowAssignmentEnabled = false } = useStore(store) - if (props.workflowID && props.workflowID !== defaultWorkflow) { - setSelectedWorkflow(props.workflowID) + // store the workflow from the URL, if it isn't already stored + if (workflowID && workflowID !== defaultWorkflow) { + setSelectedWorkflow(workflowID) + } + + // client-side redirect if there's no workflow in the URL + if (!workflowID && defaultWorkflow) { + const newPath = router.asPath.replace('/classify', `/classify/workflow/${defaultWorkflow}`) + router.replace(newPath, newPath, { shallow: true }) } return ( @@ -43,7 +56,7 @@ function ClassifyPageConnector(props) { assignedWorkflowID={projectPreferences?.settings?.workflow_id} projectPreferences={projectPreferences} workflowAssignmentEnabled={workflowAssignmentEnabled} - workflowID={props.workflowID || defaultWorkflow} + workflowID={workflowID || defaultWorkflow} /> ) }