Skip to content

Commit

Permalink
Client-side redirect /classify to /classify/workflow/[workflowID]
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Aug 18, 2024
1 parent a85f46d commit 348092d
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MobXProviderContext, observer } from 'mobx-react'
import { useRouter } from 'next/router'
import { useContext } from 'react'
import ClassifyPageContainer from './ClassifyPageContainer'

Expand All @@ -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,
Expand All @@ -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 (
Expand All @@ -43,7 +56,7 @@ function ClassifyPageConnector(props) {
assignedWorkflowID={projectPreferences?.settings?.workflow_id}
projectPreferences={projectPreferences}
workflowAssignmentEnabled={workflowAssignmentEnabled}
workflowID={props.workflowID || defaultWorkflow}
workflowID={workflowID || defaultWorkflow}
/>
)
}
Expand Down

0 comments on commit 348092d

Please sign in to comment.