Skip to content

Commit

Permalink
fix(app): better idle robots display
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sfoster1 committed Jul 30, 2024
1 parent 17871df commit 4411713
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions app/src/organisms/ChooseRobotSlideout/AvailableRobotOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getNetworkInterfaces, fetchStatus } from '../../redux/networking'
import { appShellRequestor } from '../../redux/shell/remote'
import OT2_PNG from '../../assets/images/OT2-R_HERO.png'
import FLEX_PNG from '../../assets/images/FLEX.png'
import { useNotifyAllRunsQuery } from '../../resources/runs'
import { useCurrentRunId, useNotifyRunQuery } from '../../resources/runs'

import type { IconName } from '@opentrons/components'
import type { Runs } from '@opentrons/api-client'
Expand Down Expand Up @@ -59,17 +59,15 @@ export function AvailableRobotOption(
getRobotModelByName(state, robotName)
)

const { data: runsData } = useNotifyAllRunsQuery(
{ pageLength: 0 },
const [isBusy, setIsBusy] = React.useState(true)

const currentRunId = useCurrentRunId(
{
onSuccess: data => {
const currentInProgressRun = (data as Runs)?.data?.filter(
runEl => runEl.current && runEl.completedAt != null
)
if (currentInProgressRun != null) {
registerRobotBusyStatus({ type: 'robotIsBusy', robotName })
} else {
const definitelyIdle = (data as Runs)?.links?.current == null
if (definitelyIdle) {
registerRobotBusyStatus({ type: 'robotIsIdle', robotName })
setIsBusy(false)
}
},
},
Expand All @@ -78,7 +76,28 @@ export function AvailableRobotOption(
requestor: ip === OPENTRONS_USB ? appShellRequestor : undefined,
}
)
const robotHasCurrentRun = runsData?.links?.current != null

useNotifyRunQuery(
currentRunId,
{
onSuccess: data => {
const busy = data?.data != null && data.data.completedAt == null
registerRobotBusyStatus({
type: busy ? 'robotIsBusy' : 'robotIsIdle',
robotName,
})
setIsBusy(busy)
},
onError: () => {
registerRobotBusyStatus({ type: 'robotIsIdle', robotName })
setIsBusy(false)
},
},
{
hostname: ip,
requestor: ip === OPENTRONS_USB ? appShellRequestor : undefined,
}
)

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

return showIdleOnly && robotHasCurrentRun ? null : (
return showIdleOnly && isBusy ? null : (
<>
<MiniCard
onClick={onClick}
Expand Down

0 comments on commit 4411713

Please sign in to comment.