Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): invalidate OT2 calibration queries when calibration flows complete #13809

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/src/organisms/CalibrateDeck/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Deck Calibration Orchestration Component
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useQueryClient } from 'react-query'

import { useHost } from '@opentrons/react-api-client'
import { getPipetteModelSpecs } from '@opentrons/shared-data'
import { useConditionalConfirm } from '@opentrons/components'

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

const queryClient = useQueryClient()
const host = useHost()

const {
showConfirmation: showConfirmExit,
confirm: confirmExit,
Expand All @@ -97,6 +102,11 @@ export function CalibrateDeck(
}

function cleanUpAndExit(): void {
queryClient
.invalidateQueries([host, 'calibration'])
.catch((e: Error) =>
console.error(`error invalidating calibration queries: ${e.message}`)
)
if (
exitBeforeDeckConfigCompletion &&
currentStep !== Sessions.DECK_STEP_CALIBRATION_COMPLETE
Expand Down
10 changes: 10 additions & 0 deletions app/src/organisms/CalibratePipetteOffset/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Pipette Offset Calibration Orchestration Component
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useQueryClient } from 'react-query'

import { useHost } from '@opentrons/react-api-client'
import { getPipetteModelSpecs } from '@opentrons/shared-data'
import { useConditionalConfirm } from '@opentrons/components'

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

const queryClient = useQueryClient()
const host = useHost()

const {
showConfirmation: showConfirmExit,
confirm: confirmExit,
Expand Down Expand Up @@ -92,6 +97,11 @@ export function CalibratePipetteOffset(
}

function cleanUpAndExit(): void {
queryClient
.invalidateQueries([host, 'calibration'])
.catch((e: Error) =>
console.error(`error invalidating calibration queries: ${e.message}`)
)
if (session?.id != null) {
dispatchRequests(
Sessions.createSessionCommand(robotName, session.id, {
Expand Down
10 changes: 10 additions & 0 deletions app/src/organisms/CalibrateTipLength/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Tip Length Calibration Orchestration Component
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useQueryClient } from 'react-query'
import { css } from 'styled-components'

import { useHost } from '@opentrons/react-api-client'
import { getPipetteModelSpecs } from '@opentrons/shared-data'
import { useConditionalConfirm } from '@opentrons/components'

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

const queryClient = useQueryClient()
const host = useHost()

const isMulti = React.useMemo(() => {
const spec =
instrument != null ? getPipetteModelSpecs(instrument.model) : null
Expand All @@ -96,6 +101,11 @@ export function CalibrateTipLength(
}

function cleanUpAndExit(): void {
queryClient
.invalidateQueries([host, 'calibration'])
.catch((e: Error) =>
console.error(`error invalidating calibration queries: ${e.message}`)
)
if (session?.id != null) {
dispatchRequests(
Sessions.createSessionCommand(robotName, session.id, {
Expand Down
7 changes: 6 additions & 1 deletion components/src/testing/utils/mountWithProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from 'assert'
import * as React from 'react'
import { I18nextProvider } from 'react-i18next'
import { Provider } from 'react-redux'
import { QueryClient, QueryClientProvider } from 'react-query'
import { mount } from 'enzyme'

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

const queryClient = new QueryClient()

const I18nWrapper: React.ElementType<
React.ComponentProps<typeof I18nextProvider>
> = provideI18n
Expand Down Expand Up @@ -67,7 +70,9 @@ export function mountWithProviders<Element, State, Action>(
i18n: React.ComponentProps<typeof I18nextProvider>['i18n']
}): JSX.Element => (
<StateWrapper store={store}>
<I18nWrapper i18n={i18n}>{children}</I18nWrapper>
<QueryClientProvider client={queryClient}>
<I18nWrapper i18n={i18n}>{children}</I18nWrapper>
</QueryClientProvider>
</StateWrapper>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from 'assert'
import * as React from 'react'
import { Provider } from 'react-redux'
import { QueryClient, QueryClientProvider } from 'react-query'
import { mount } from 'enzyme'

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

const queryClient = new QueryClient()

const BaseProviders = ({
children,
store,
queryClient,
}: {
children: React.ReactNode
store: any
queryClient: any
}): JSX.Element => {
return (
<QueryClientProvider client={queryClient}>
<Provider store={store as any}>{children}</Provider>
</QueryClientProvider>
)
}

const wrapper = mount<Props>(node, {
wrappingComponent: Provider,
wrappingComponentProps: { store },
wrappingComponent: BaseProviders,
wrappingComponentProps: { store, queryClient },
})

// force a re-render by returning a new state to recalculate selectors
Expand Down
13 changes: 7 additions & 6 deletions components/src/testing/utils/renderWithProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ export function renderWithProviders<State>(
const ProviderWrapper: React.ComponentType<React.PropsWithChildren<{}>> = ({
children,
}) => {
const BaseWrapper = (
<QueryClientProvider client={queryClient}>
<Provider store={store}>{children}</Provider>
</QueryClientProvider>
)
if (i18nInstance != null) {
return (
<I18nextProvider i18n={i18nInstance}>
<QueryClientProvider client={queryClient}>
<Provider store={store}>{children}</Provider>
</QueryClientProvider>
</I18nextProvider>
<I18nextProvider i18n={i18nInstance}>{BaseWrapper}</I18nextProvider>
)
} else {
return <Provider store={store}>{children}</Provider>
return BaseWrapper
}
}

Expand Down