Skip to content

Commit 4411713

Browse files
committed
fix(app): better idle robots display
Fix up idle robots to actually function. Use the current run's completed at timestamp to decide whether or not the run is complete for the purposes of idle. This requires fetching the current run, which we do by ID. Closes EXEC-519
1 parent 17871df commit 4411713

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

app/src/organisms/ChooseRobotSlideout/AvailableRobotOption.tsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { getNetworkInterfaces, fetchStatus } from '../../redux/networking'
2222
import { appShellRequestor } from '../../redux/shell/remote'
2323
import OT2_PNG from '../../assets/images/OT2-R_HERO.png'
2424
import FLEX_PNG from '../../assets/images/FLEX.png'
25-
import { useNotifyAllRunsQuery } from '../../resources/runs'
25+
import { useCurrentRunId, useNotifyRunQuery } from '../../resources/runs'
2626

2727
import type { IconName } from '@opentrons/components'
2828
import type { Runs } from '@opentrons/api-client'
@@ -59,17 +59,15 @@ export function AvailableRobotOption(
5959
getRobotModelByName(state, robotName)
6060
)
6161

62-
const { data: runsData } = useNotifyAllRunsQuery(
63-
{ pageLength: 0 },
62+
const [isBusy, setIsBusy] = React.useState(true)
63+
64+
const currentRunId = useCurrentRunId(
6465
{
6566
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) {
7269
registerRobotBusyStatus({ type: 'robotIsIdle', robotName })
70+
setIsBusy(false)
7371
}
7472
},
7573
},
@@ -78,7 +76,28 @@ export function AvailableRobotOption(
7876
requestor: ip === OPENTRONS_USB ? appShellRequestor : undefined,
7977
}
8078
)
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+
)
82101

83102
const { ethernet, wifi } = useSelector((state: State) =>
84103
getNetworkInterfaces(state, robotName)
@@ -98,7 +117,7 @@ export function AvailableRobotOption(
98117
// eslint-disable-next-line react-hooks/exhaustive-deps
99118
}, [])
100119

101-
return showIdleOnly && robotHasCurrentRun ? null : (
120+
return showIdleOnly && isBusy ? null : (
102121
<>
103122
<MiniCard
104123
onClick={onClick}

0 commit comments

Comments
 (0)