From 693298c2aa8c016af20e154232899a2ed112d59b Mon Sep 17 00:00:00 2001 From: Nick Diehl <47604184+ncdiehl11@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:05:58 -0500 Subject: [PATCH] fix(app): update useIsRobot busy hook to check for firmware update (#14457) * fix(app): update useIsRobot busy hook to check for firmware update closes RQA-2293 --- .../hooks/__tests__/useIsRobotBusy.test.ts | 37 ++++++++++++++++++- .../organisms/Devices/hooks/useIsRobotBusy.ts | 14 ++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts b/app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts index 3057f76d168a..b4f2fc4011b7 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts +++ b/app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts @@ -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, @@ -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 describe('useIsRobotBusy', () => { @@ -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) }) @@ -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) + }) }) diff --git a/app/src/organisms/Devices/hooks/useIsRobotBusy.ts b/app/src/organisms/Devices/hooks/useIsRobotBusy.ts index d867f78f123d..772039b22d27 100644 --- a/app/src/organisms/Devices/hooks/useIsRobotBusy.ts +++ b/app/src/organisms/Devices/hooks/useIsRobotBusy.ts @@ -2,6 +2,7 @@ import { useAllSessionsQuery, useEstopQuery, useHost, + useCurrentAllSubsystemUpdatesQuery, } from '@opentrons/react-api-client' import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun' @@ -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 ) }