@@ -22,7 +22,7 @@ import { getNetworkInterfaces, fetchStatus } from '../../redux/networking'
22
22
import { appShellRequestor } from '../../redux/shell/remote'
23
23
import OT2_PNG from '../../assets/images/OT2-R_HERO.png'
24
24
import FLEX_PNG from '../../assets/images/FLEX.png'
25
- import { useNotifyAllRunsQuery } from '../../resources/runs'
25
+ import { useCurrentRunId , useNotifyRunQuery } from '../../resources/runs'
26
26
27
27
import type { IconName } from '@opentrons/components'
28
28
import type { Runs } from '@opentrons/api-client'
@@ -59,17 +59,15 @@ export function AvailableRobotOption(
59
59
getRobotModelByName ( state , robotName )
60
60
)
61
61
62
- const { data : runsData } = useNotifyAllRunsQuery (
63
- { pageLength : 0 } ,
62
+ const [ isBusy , setIsBusy ] = React . useState ( true )
63
+
64
+ const currentRunId = useCurrentRunId (
64
65
{
65
66
onSuccess : data => {
66
- const currentInProgressRun = ( data as Runs ) ?. data ?. filter (
67
- runEl => runEl . current && runEl . completedAt != null
68
- )
69
- if ( currentInProgressRun != null ) {
70
- registerRobotBusyStatus ( { type : 'robotIsBusy' , robotName } )
71
- } else {
67
+ const definitelyIdle = ( data as Runs ) ?. links ?. current == null
68
+ if ( definitelyIdle ) {
72
69
registerRobotBusyStatus ( { type : 'robotIsIdle' , robotName } )
70
+ setIsBusy ( false )
73
71
}
74
72
} ,
75
73
} ,
@@ -78,7 +76,28 @@ export function AvailableRobotOption(
78
76
requestor : ip === OPENTRONS_USB ? appShellRequestor : undefined ,
79
77
}
80
78
)
81
- const robotHasCurrentRun = runsData ?. links ?. current != null
79
+
80
+ useNotifyRunQuery (
81
+ currentRunId ,
82
+ {
83
+ onSuccess : data => {
84
+ const busy = data ?. data != null && data . data . completedAt == null
85
+ registerRobotBusyStatus ( {
86
+ type : busy ? 'robotIsBusy' : 'robotIsIdle' ,
87
+ robotName,
88
+ } )
89
+ setIsBusy ( busy )
90
+ } ,
91
+ onError : ( ) => {
92
+ registerRobotBusyStatus ( { type : 'robotIsIdle' , robotName } )
93
+ setIsBusy ( false )
94
+ } ,
95
+ } ,
96
+ {
97
+ hostname : ip ,
98
+ requestor : ip === OPENTRONS_USB ? appShellRequestor : undefined ,
99
+ }
100
+ )
82
101
83
102
const { ethernet, wifi } = useSelector ( ( state : State ) =>
84
103
getNetworkInterfaces ( state , robotName )
@@ -98,7 +117,7 @@ export function AvailableRobotOption(
98
117
// eslint-disable-next-line react-hooks/exhaustive-deps
99
118
} , [ ] )
100
119
101
- return showIdleOnly && robotHasCurrentRun ? null : (
120
+ return showIdleOnly && isBusy ? null : (
102
121
< >
103
122
< MiniCard
104
123
onClick = { onClick }
0 commit comments