|
8 | 8 | useAllProtocolIdsQuery,
|
9 | 9 | useAllRunsQuery,
|
10 | 10 | useHost,
|
| 11 | + useRunQuery, |
11 | 12 | } from '@opentrons/react-api-client'
|
12 | 13 | import {
|
13 | 14 | getProtocol,
|
@@ -118,25 +119,35 @@ export function useCurrentRunRoute(): string | null {
|
118 | 119 | ) // trim link path down to only runId
|
119 | 120 | : null
|
120 | 121 |
|
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 |
124 | 123 |
|
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( |
126 | 137 | action => action.actionType === RUN_ACTION_TYPE_PLAY
|
127 | 138 | )
|
128 | 139 | 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 |
132 | 143 | ) {
|
133 |
| - return `/runs/${currentRun.id}/summary` |
| 144 | + return `/runs/${runId}/summary` |
134 | 145 | } 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) |
137 | 148 | ) {
|
138 |
| - return `/runs/${currentRun.id}/setup` |
| 149 | + return `/runs/${runId}/setup` |
139 | 150 | } else {
|
140 |
| - return `/runs/${currentRun.id}/run` |
| 151 | + return `/runs/${runId}/run` |
141 | 152 | }
|
142 | 153 | }
|
0 commit comments