Skip to content

Commit 57b7c9b

Browse files
authored
fix(app): redirect to run summary screen based on run endpoint (#13125)
closes RQA-1098
1 parent 4d819b1 commit 57b7c9b

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

app/src/App/hooks.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useAllProtocolIdsQuery,
99
useAllRunsQuery,
1010
useHost,
11+
useRunQuery,
1112
} from '@opentrons/react-api-client'
1213
import {
1314
getProtocol,
@@ -118,25 +119,35 @@ export function useCurrentRunRoute(): string | null {
118119
) // trim link path down to only runId
119120
: null
120121

121-
const status = currentRun?.status
122-
const actions = currentRun?.actions
123-
if (status == null || actions == null || currentRun == null) return null
122+
const currentRunId = currentRun?.id ?? null
124123

125-
const hasBeenStarted = actions?.some(
124+
const { data: runRecord } = useRunQuery(currentRunId, {
125+
staleTime: Infinity,
126+
enabled: currentRunId != null,
127+
})
128+
129+
const runStatus = runRecord?.data.status
130+
const runActions = runRecord?.data.actions
131+
132+
if (runRecord == null || runStatus == null || runActions == null) return null
133+
// grabbing run id off of the run query to have all routing info come from one source of truth
134+
const runId = runRecord.data.id
135+
136+
const hasBeenStarted = runActions?.some(
126137
action => action.actionType === RUN_ACTION_TYPE_PLAY
127138
)
128139
if (
129-
status === RUN_STATUS_SUCCEEDED ||
130-
status === RUN_STATUS_STOPPED ||
131-
status === RUN_STATUS_FAILED
140+
runStatus === RUN_STATUS_SUCCEEDED ||
141+
runStatus === RUN_STATUS_STOPPED ||
142+
runStatus === RUN_STATUS_FAILED
132143
) {
133-
return `/runs/${currentRun.id}/summary`
144+
return `/runs/${runId}/summary`
134145
} else if (
135-
status === RUN_STATUS_IDLE ||
136-
(!hasBeenStarted && status === RUN_STATUS_BLOCKED_BY_OPEN_DOOR)
146+
runStatus === RUN_STATUS_IDLE ||
147+
(!hasBeenStarted && runStatus === RUN_STATUS_BLOCKED_BY_OPEN_DOOR)
137148
) {
138-
return `/runs/${currentRun.id}/setup`
149+
return `/runs/${runId}/setup`
139150
} else {
140-
return `/runs/${currentRun.id}/run`
151+
return `/runs/${runId}/run`
141152
}
142153
}

0 commit comments

Comments
 (0)