Skip to content

Commit

Permalink
fix(app): update useIsRobot busy hook to check for firmware update (#…
Browse files Browse the repository at this point in the history
…14457)

* fix(app): update useIsRobot busy hook to check for firmware update

closes RQA-2293
  • Loading branch information
ncdiehl11 committed Feb 9, 2024
1 parent 8dc6f79 commit a3428ad
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
37 changes: 36 additions & 1 deletion app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { UseQueryResult } from 'react-query'

import { useAllSessionsQuery, useEstopQuery } from '@opentrons/react-api-client'
import {
useAllSessionsQuery,
useEstopQuery,
useCurrentAllSubsystemUpdatesQuery,
} from '@opentrons/react-api-client'

import {
DISENGAGED,
Expand Down Expand Up @@ -43,6 +47,9 @@ const mockUseNotifyCurrentMaintenanceRun = useNotifyCurrentMaintenanceRun as jes
const mockUseEstopQuery = useEstopQuery as jest.MockedFunction<
typeof useEstopQuery
>
const mockUseCurrentAllSubsystemUpdatesQuery = useCurrentAllSubsystemUpdatesQuery as jest.MockedFunction<
typeof useCurrentAllSubsystemUpdatesQuery
>
const mockUseIsFlex = useIsFlex as jest.MockedFunction<typeof useIsFlex>

describe('useIsRobotBusy', () => {
Expand All @@ -61,6 +68,18 @@ describe('useIsRobotBusy', () => {
data: {},
} as any)
mockUseEstopQuery.mockReturnValue({ data: mockEstopStatus } as any)
mockUseCurrentAllSubsystemUpdatesQuery.mockReturnValue({
data: {
data: [
{
id: '123',
createdAt: 'today',
subsystem: 'pipette_right',
updateStatus: 'done',
},
],
},
} as any)
mockUseIsFlex.mockReturnValue(false)
})

Expand Down Expand Up @@ -200,4 +219,20 @@ describe('useIsRobotBusy', () => {
const result = useIsRobotBusy()
expect(result).toBe(true)
})
it('returns true when a subsystem update is in progress', () => {
mockUseCurrentAllSubsystemUpdatesQuery.mockReturnValue({
data: {
data: [
{
id: '123',
createdAt: 'today',
subsystem: 'pipette_right',
updateStatus: 'updating',
},
],
},
} as any)
const result = useIsRobotBusy()
expect(result).toBe(true)
})
})
14 changes: 13 additions & 1 deletion app/src/organisms/Devices/hooks/useIsRobotBusy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
useAllSessionsQuery,
useEstopQuery,
useHost,
useCurrentAllSubsystemUpdatesQuery,
} from '@opentrons/react-api-client'

import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun'
Expand Down Expand Up @@ -33,12 +34,23 @@ export function useIsRobotBusy(
...queryOptions,
enabled: isFlex,
})
const {
data: currentSubsystemsUpdatesData,
} = useCurrentAllSubsystemUpdatesQuery({
refetchInterval: ROBOT_STATUS_POLL_MS,
})
const isSubsystemUpdating =
currentSubsystemsUpdatesData?.data.some(
update =>
update.updateStatus === 'queued' || update.updateStatus === 'updating'
) ?? false

return (
robotHasCurrentRun ||
isMaintenanceRunExisting ||
(allSessionsQueryResponse?.data?.data != null &&
allSessionsQueryResponse?.data?.data?.length !== 0) ||
(isFlex && estopStatus?.data.status !== DISENGAGED && estopError == null)
(isFlex && estopStatus?.data.status !== DISENGAGED && estopError == null) ||
isSubsystemUpdating
)
}

0 comments on commit a3428ad

Please sign in to comment.