Skip to content

Commit

Permalink
fix(app): debounce jogs in calcheck (#6933)
Browse files Browse the repository at this point in the history
Debounce jog commands in the same way in calibration check that we do in
the other calibration flows.
  • Loading branch information
sfoster1 authored Nov 6, 2020
1 parent 14659b8 commit f355397
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('CheckCalibration', () => {
let mockStore
let render
let dispatch
let dispatchRequests
let mockCalibrationCheckSession: Sessions.CalibrationCheckSession = {
id: 'fake_check_session_id',
...mockCalibrationCheckSessionAttributes,
Expand Down Expand Up @@ -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(
<CheckHealthCalibration
robotName="robot-name"
session={mockCalibrationCheckSession}
dispatchRequests={jest.fn()}
dispatchRequests={dispatchRequests}
showSpinner={showSpinner}
hasBlock={false}
isJogging={isJogging}
/>,
{
wrappingComponent: Provider,
Expand Down Expand Up @@ -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()
})
})
4 changes: 2 additions & 2 deletions app/src/components/CheckCalibration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -129,7 +129,7 @@ export function CheckHealthCalibration(
: null

function sendCommands(...commands: Array<SessionCommandParams>) {
if (session?.id) {
if (session?.id && !isJogging) {
const sessionCommandActions = commands.map(c =>
Sessions.createSessionCommand(robotName, session.id, {
command: c.command,
Expand Down
1 change: 1 addition & 0 deletions app/src/components/CheckCalibration/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type CalibrationHealthCheckParentProps = {|
dispatchRequests: (
...Array<{ ...Action, meta: { requestId: string } }>
) => void,
isJogging: boolean,
showSpinner: boolean,
hasBlock?: boolean,
|}
Expand Down
15 changes: 15 additions & 0 deletions app/src/components/RobotSettings/CheckCalibrationControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function CheckCalibrationControl({
const trackedRequestId = React.useRef<string | null>(null)
const deleteRequestId = React.useRef<string | null>(null)
const createRequestId = React.useRef<string | null>(null)
const jogRequestId = React.useRef<string | null>(null)

const [dispatchRequests] = RobotApi.useDispatchApiRequests(
dispatchedAction => {
Expand All @@ -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(
Expand All @@ -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, RequestState | null>(state =>
deleteRequestId.current
Expand Down Expand Up @@ -203,6 +217,7 @@ export function CheckCalibrationControl({
robotName={robotName}
dispatchRequests={dispatchRequests}
showSpinner={showSpinner}
isJogging={isJogging}
/>
)}
</Portal>
Expand Down

0 comments on commit f355397

Please sign in to comment.