Skip to content

Commit

Permalink
fix(app): redirect to run summary screen based on run endpoint (#13125)
Browse files Browse the repository at this point in the history
closes RQA-1098
  • Loading branch information
shlokamin authored Jul 24, 2023
1 parent 4d819b1 commit 57b7c9b
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions app/src/App/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useAllProtocolIdsQuery,
useAllRunsQuery,
useHost,
useRunQuery,
} from '@opentrons/react-api-client'
import {
getProtocol,
Expand Down Expand Up @@ -118,25 +119,35 @@ export function useCurrentRunRoute(): string | null {
) // trim link path down to only runId
: null

const status = currentRun?.status
const actions = currentRun?.actions
if (status == null || actions == null || currentRun == null) return null
const currentRunId = currentRun?.id ?? null

const hasBeenStarted = actions?.some(
const { data: runRecord } = useRunQuery(currentRunId, {
staleTime: Infinity,
enabled: currentRunId != null,
})

const runStatus = runRecord?.data.status
const runActions = runRecord?.data.actions

if (runRecord == null || runStatus == null || runActions == null) return null
// grabbing run id off of the run query to have all routing info come from one source of truth
const runId = runRecord.data.id

const hasBeenStarted = runActions?.some(
action => action.actionType === RUN_ACTION_TYPE_PLAY
)
if (
status === RUN_STATUS_SUCCEEDED ||
status === RUN_STATUS_STOPPED ||
status === RUN_STATUS_FAILED
runStatus === RUN_STATUS_SUCCEEDED ||
runStatus === RUN_STATUS_STOPPED ||
runStatus === RUN_STATUS_FAILED
) {
return `/runs/${currentRun.id}/summary`
return `/runs/${runId}/summary`
} else if (
status === RUN_STATUS_IDLE ||
(!hasBeenStarted && status === RUN_STATUS_BLOCKED_BY_OPEN_DOOR)
runStatus === RUN_STATUS_IDLE ||
(!hasBeenStarted && runStatus === RUN_STATUS_BLOCKED_BY_OPEN_DOOR)
) {
return `/runs/${currentRun.id}/setup`
return `/runs/${runId}/setup`
} else {
return `/runs/${currentRun.id}/run`
return `/runs/${runId}/run`
}
}

0 comments on commit 57b7c9b

Please sign in to comment.