From f3553979c46273c78f3c41e991dda4ab964089b9 Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Fri, 6 Nov 2020 11:00:53 -0500 Subject: [PATCH] fix(app): debounce jogs in calcheck (#6933) Debounce jog commands in the same way in calibration check that we do in the other calibration flows. --- .../__tests__/CheckCalibration.test.js | 42 ++++++++++++++++++- app/src/components/CheckCalibration/index.js | 4 +- app/src/components/CheckCalibration/types.js | 1 + .../RobotSettings/CheckCalibrationControl.js | 15 +++++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/app/src/components/CheckCalibration/__tests__/CheckCalibration.test.js b/app/src/components/CheckCalibration/__tests__/CheckCalibration.test.js index 6f27d7c31cb..e5146dbad52 100644 --- a/app/src/components/CheckCalibration/__tests__/CheckCalibration.test.js +++ b/app/src/components/CheckCalibration/__tests__/CheckCalibration.test.js @@ -42,6 +42,7 @@ describe('CheckCalibration', () => { let mockStore let render let dispatch + let dispatchRequests let mockCalibrationCheckSession: Sessions.CalibrationCheckSession = { id: 'fake_check_session_id', ...mockCalibrationCheckSessionAttributes, @@ -87,16 +88,18 @@ describe('CheckCalibration', () => { id: 'fake_check_session_id', ...mockCalibrationCheckSessionAttributes, } + dispatchRequests = jest.fn() render = (props = {}) => { - const { showSpinner = false } = props + const { showSpinner = false, isJogging = false } = props return mount( , { wrappingComponent: Provider, @@ -148,4 +151,39 @@ describe('CheckCalibration', () => { const wrapper = render({ showSpinner: true }) expect(wrapper.find('SpinnerModalPage').exists()).toBe(true) }) + + it('does dispatch jog requests when not isJogging', () => { + mockCalibrationCheckSession = { + ...mockCalibrationCheckSession, + details: { + ...mockCalibrationCheckSession.details, + currentStep: 'preparingPipette', + }, + } + const wrapper = render({ isJogging: false }) + wrapper.find('button[title="forward"]').invoke('onClick')() + expect(dispatchRequests).toHaveBeenCalledWith( + Sessions.createSessionCommand( + 'robot-name', + mockCalibrationCheckSession.id, + { + command: Sessions.sharedCalCommands.JOG, + data: { vector: [0, -0.1, 0] }, + } + ) + ) + }) + it('does not dispatch jog requests when isJogging', () => { + mockCalibrationCheckSession = { + ...mockCalibrationCheckSession, + details: { + ...mockCalibrationCheckSession.details, + currentStep: 'preparingPipette', + }, + } + const wrapper = render({ isJogging: true }) + dispatch.mockClear() + wrapper.find('button[title="forward"]').invoke('onClick')() + expect(dispatchRequests).not.toHaveBeenCalled() + }) }) diff --git a/app/src/components/CheckCalibration/index.js b/app/src/components/CheckCalibration/index.js index c831dfbcd25..89b4966bd3c 100644 --- a/app/src/components/CheckCalibration/index.js +++ b/app/src/components/CheckCalibration/index.js @@ -101,7 +101,7 @@ const PANEL_STYLE_PROPS_BY_STEP: { export function CheckHealthCalibration( props: CalibrationHealthCheckParentProps ): React.Node { - const { session, robotName, dispatchRequests, showSpinner } = props + const { session, robotName, dispatchRequests, showSpinner, isJogging } = props const { currentStep, activePipette, @@ -129,7 +129,7 @@ export function CheckHealthCalibration( : null function sendCommands(...commands: Array) { - if (session?.id) { + if (session?.id && !isJogging) { const sessionCommandActions = commands.map(c => Sessions.createSessionCommand(robotName, session.id, { command: c.command, diff --git a/app/src/components/CheckCalibration/types.js b/app/src/components/CheckCalibration/types.js index 120e9d4ffb7..fa6635c6d36 100644 --- a/app/src/components/CheckCalibration/types.js +++ b/app/src/components/CheckCalibration/types.js @@ -13,6 +13,7 @@ export type CalibrationHealthCheckParentProps = {| dispatchRequests: ( ...Array<{ ...Action, meta: { requestId: string } }> ) => void, + isJogging: boolean, showSpinner: boolean, hasBlock?: boolean, |} diff --git a/app/src/components/RobotSettings/CheckCalibrationControl.js b/app/src/components/RobotSettings/CheckCalibrationControl.js index 972d9f7cc76..c8f2abf545c 100644 --- a/app/src/components/RobotSettings/CheckCalibrationControl.js +++ b/app/src/components/RobotSettings/CheckCalibrationControl.js @@ -50,6 +50,7 @@ export function CheckCalibrationControl({ const trackedRequestId = React.useRef(null) const deleteRequestId = React.useRef(null) const createRequestId = React.useRef(null) + const jogRequestId = React.useRef(null) const [dispatchRequests] = RobotApi.useDispatchApiRequests( dispatchedAction => { @@ -60,6 +61,12 @@ export function CheckCalibrationControl({ checkHealthSession?.id === dispatchedAction.payload.sessionId ) { deleteRequestId.current = dispatchedAction.meta.requestId + } else if ( + dispatchedAction.type === Sessions.CREATE_SESSION_COMMAND && + dispatchedAction.payload.command.command === + Sessions.sharedCalCommands.JOG + ) { + jogRequestId.current = dispatchedAction.meta.requestId } else if ( dispatchedAction.type !== Sessions.CREATE_SESSION_COMMAND || !spinnerCommandBlockList.includes( @@ -85,6 +92,13 @@ export function CheckCalibrationControl({ : null )?.status === RobotApi.PENDING + const isJogging = + useSelector((state: State) => + jogRequestId.current + ? RobotApi.getRequestById(state, jogRequestId.current) + : null + )?.status === RobotApi.PENDING + const shouldClose = useSelector(state => deleteRequestId.current @@ -203,6 +217,7 @@ export function CheckCalibrationControl({ robotName={robotName} dispatchRequests={dispatchRequests} showSpinner={showSpinner} + isJogging={isJogging} /> )}