Skip to content

Commit 692888c

Browse files
b-coopershlokamin
andauthored
fix(app): invalidate OT2 calibration queries when calibration flows complete (#13809)
Ensure that all queries for /calibration endpoints (OT2 only) are invalidated upon completion of any of the three OT2 calibration flows. Closes RQA-1814 Co-authored-by: Shlok Amin <[email protected]>
1 parent 855ec92 commit 692888c

File tree

6 files changed

+64
-9
lines changed

6 files changed

+64
-9
lines changed

app/src/organisms/CalibrateDeck/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Deck Calibration Orchestration Component
22
import * as React from 'react'
33
import { useTranslation } from 'react-i18next'
4+
import { useQueryClient } from 'react-query'
45

6+
import { useHost } from '@opentrons/react-api-client'
57
import { getPipetteModelSpecs } from '@opentrons/shared-data'
68
import { useConditionalConfirm } from '@opentrons/components'
79

@@ -71,6 +73,9 @@ export function CalibrateDeck(
7173
const { currentStep, instrument, labware, supportedCommands } =
7274
session?.details || {}
7375

76+
const queryClient = useQueryClient()
77+
const host = useHost()
78+
7479
const {
7580
showConfirmation: showConfirmExit,
7681
confirm: confirmExit,
@@ -97,6 +102,11 @@ export function CalibrateDeck(
97102
}
98103

99104
function cleanUpAndExit(): void {
105+
queryClient
106+
.invalidateQueries([host, 'calibration'])
107+
.catch((e: Error) =>
108+
console.error(`error invalidating calibration queries: ${e.message}`)
109+
)
100110
if (
101111
exitBeforeDeckConfigCompletion &&
102112
currentStep !== Sessions.DECK_STEP_CALIBRATION_COMPLETE

app/src/organisms/CalibratePipetteOffset/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Pipette Offset Calibration Orchestration Component
22
import * as React from 'react'
33
import { useTranslation } from 'react-i18next'
4+
import { useQueryClient } from 'react-query'
45

6+
import { useHost } from '@opentrons/react-api-client'
57
import { getPipetteModelSpecs } from '@opentrons/shared-data'
68
import { useConditionalConfirm } from '@opentrons/components'
79

@@ -60,6 +62,9 @@ export function CalibratePipetteOffset(
6062
const { currentStep, instrument, labware, supportedCommands } =
6163
session?.details ?? {}
6264

65+
const queryClient = useQueryClient()
66+
const host = useHost()
67+
6368
const {
6469
showConfirmation: showConfirmExit,
6570
confirm: confirmExit,
@@ -92,6 +97,11 @@ export function CalibratePipetteOffset(
9297
}
9398

9499
function cleanUpAndExit(): void {
100+
queryClient
101+
.invalidateQueries([host, 'calibration'])
102+
.catch((e: Error) =>
103+
console.error(`error invalidating calibration queries: ${e.message}`)
104+
)
95105
if (session?.id != null) {
96106
dispatchRequests(
97107
Sessions.createSessionCommand(robotName, session.id, {

app/src/organisms/CalibrateTipLength/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Tip Length Calibration Orchestration Component
22
import * as React from 'react'
33
import { useTranslation } from 'react-i18next'
4+
import { useQueryClient } from 'react-query'
45
import { css } from 'styled-components'
56

7+
import { useHost } from '@opentrons/react-api-client'
68
import { getPipetteModelSpecs } from '@opentrons/shared-data'
79
import { useConditionalConfirm } from '@opentrons/components'
810

@@ -72,6 +74,9 @@ export function CalibrateTipLength(
7274
} = props
7375
const { currentStep, instrument, labware } = session?.details ?? {}
7476

77+
const queryClient = useQueryClient()
78+
const host = useHost()
79+
7580
const isMulti = React.useMemo(() => {
7681
const spec =
7782
instrument != null ? getPipetteModelSpecs(instrument.model) : null
@@ -96,6 +101,11 @@ export function CalibrateTipLength(
96101
}
97102

98103
function cleanUpAndExit(): void {
104+
queryClient
105+
.invalidateQueries([host, 'calibration'])
106+
.catch((e: Error) =>
107+
console.error(`error invalidating calibration queries: ${e.message}`)
108+
)
99109
if (session?.id != null) {
100110
dispatchRequests(
101111
Sessions.createSessionCommand(robotName, session.id, {

components/src/testing/utils/mountWithProviders.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from 'assert'
22
import * as React from 'react'
33
import { I18nextProvider } from 'react-i18next'
44
import { Provider } from 'react-redux'
5+
import { QueryClient, QueryClientProvider } from 'react-query'
56
import { mount } from 'enzyme'
67

78
import type { Store } from 'redux'
@@ -33,6 +34,8 @@ export function mountWithProviders<Element, State, Action>(
3334
dispatch: jest.fn(),
3435
}
3536

37+
const queryClient = new QueryClient()
38+
3639
const I18nWrapper: React.ElementType<
3740
React.ComponentProps<typeof I18nextProvider>
3841
> = provideI18n
@@ -67,7 +70,9 @@ export function mountWithProviders<Element, State, Action>(
6770
i18n: React.ComponentProps<typeof I18nextProvider>['i18n']
6871
}): JSX.Element => (
6972
<StateWrapper store={store}>
70-
<I18nWrapper i18n={i18n}>{children}</I18nWrapper>
73+
<QueryClientProvider client={queryClient}>
74+
<I18nWrapper i18n={i18n}>{children}</I18nWrapper>
75+
</QueryClientProvider>
7176
</StateWrapper>
7277
)
7378

components/src/testing/utils/mountWithStore.ts renamed to components/src/testing/utils/mountWithStore.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from 'assert'
22
import * as React from 'react'
33
import { Provider } from 'react-redux'
4+
import { QueryClient, QueryClientProvider } from 'react-query'
45
import { mount } from 'enzyme'
56

67
import type { ReactWrapper } from 'enzyme'
@@ -35,9 +36,27 @@ export function mountWithStore<Props, State = {}, Action = {}>(
3536
dispatch: jest.fn(),
3637
}
3738

39+
const queryClient = new QueryClient()
40+
41+
const BaseProviders = ({
42+
children,
43+
store,
44+
queryClient,
45+
}: {
46+
children: React.ReactNode
47+
store: any
48+
queryClient: any
49+
}): JSX.Element => {
50+
return (
51+
<QueryClientProvider client={queryClient}>
52+
<Provider store={store as any}>{children}</Provider>
53+
</QueryClientProvider>
54+
)
55+
}
56+
3857
const wrapper = mount<Props>(node, {
39-
wrappingComponent: Provider,
40-
wrappingComponentProps: { store },
58+
wrappingComponent: BaseProviders,
59+
wrappingComponentProps: { store, queryClient },
4160
})
4261

4362
// force a re-render by returning a new state to recalculate selectors

components/src/testing/utils/renderWithProviders.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ export function renderWithProviders<State>(
3131
const ProviderWrapper: React.ComponentType<React.PropsWithChildren<{}>> = ({
3232
children,
3333
}) => {
34+
const BaseWrapper = (
35+
<QueryClientProvider client={queryClient}>
36+
<Provider store={store}>{children}</Provider>
37+
</QueryClientProvider>
38+
)
3439
if (i18nInstance != null) {
3540
return (
36-
<I18nextProvider i18n={i18nInstance}>
37-
<QueryClientProvider client={queryClient}>
38-
<Provider store={store}>{children}</Provider>
39-
</QueryClientProvider>
40-
</I18nextProvider>
41+
<I18nextProvider i18n={i18nInstance}>{BaseWrapper}</I18nextProvider>
4142
)
4243
} else {
43-
return <Provider store={store}>{children}</Provider>
44+
return BaseWrapper
4445
}
4546
}
4647

0 commit comments

Comments
 (0)