Skip to content

Commit

Permalink
fix(app): allow ODD to poll for completed analysis on protocol setup (#…
Browse files Browse the repository at this point in the history
…14197)

Prevent bug where odd will not proceed past protocol setup screen because of lack of completed
analysis

RQA-2074
  • Loading branch information
b-cooper authored Dec 14, 2023
1 parent f5c4dc2 commit c08937e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useDoorQuery,
useModulesQuery,
useDeckConfigurationQuery,
useProtocolAnalysisAsDocumentQuery,
} from '@opentrons/react-api-client'
import { renderWithProviders } from '@opentrons/components'
import { mockHeaterShaker } from '../../../../redux/modules/__fixtures__'
Expand All @@ -33,7 +34,6 @@ import {
useRobotType,
} from '../../../../organisms/Devices/hooks'
import { getLocalRobot } from '../../../../redux/discovery'
import { useMostRecentCompletedAnalysis } from '../../../../organisms/LabwarePositionCheck/useMostRecentCompletedAnalysis'
import { ProtocolSetupLiquids } from '../../../../organisms/ProtocolSetupLiquids'
import { getProtocolModulesInfo } from '../../../../organisms/Devices/ProtocolRun/utils/getProtocolModulesInfo'
import { ProtocolSetupModulesAndDeck } from '../../../../organisms/ProtocolSetupModulesAndDeck'
Expand Down Expand Up @@ -117,9 +117,6 @@ const mockUseRunControls = useRunControls as jest.MockedFunction<
const mockUseRunStatus = useRunStatus as jest.MockedFunction<
typeof useRunStatus
>
const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction<
typeof useMostRecentCompletedAnalysis
>
const mockProtocolSetupLiquids = ProtocolSetupLiquids as jest.MockedFunction<
typeof ProtocolSetupLiquids
>
Expand Down Expand Up @@ -154,6 +151,9 @@ const mockUseDoorQuery = useDoorQuery as jest.MockedFunction<
const mockUseModulesQuery = useModulesQuery as jest.MockedFunction<
typeof useModulesQuery
>
const mockUseProtocolAnalysisAsDocumentQuery = useProtocolAnalysisAsDocumentQuery as jest.MockedFunction<
typeof useProtocolAnalysisAsDocumentQuery
>
const mockUseDeckConfigurationQuery = useDeckConfigurationQuery as jest.MockedFunction<
typeof useDeckConfigurationQuery
>
Expand Down Expand Up @@ -273,9 +273,9 @@ describe('ProtocolSetup', () => {
isResetRunLoading: false,
})
when(mockUseRunStatus).calledWith(RUN_ID).mockReturnValue(RUN_STATUS_IDLE)
when(mockUseMostRecentCompletedAnalysis)
.calledWith(RUN_ID)
.mockReturnValue(mockEmptyAnalysis)
mockUseProtocolAnalysisAsDocumentQuery.mockReturnValue({
data: mockEmptyAnalysis,
} as any)
when(mockUseRunCreatedAtTimestamp)
.calledWith(RUN_ID)
.mockReturnValue(CREATED_AT)
Expand Down Expand Up @@ -370,9 +370,9 @@ describe('ProtocolSetup', () => {
})

it('should launch protocol setup modules screen when click modules', () => {
when(mockUseMostRecentCompletedAnalysis)
.calledWith(RUN_ID)
.mockReturnValue(mockRobotSideAnalysis)
mockUseProtocolAnalysisAsDocumentQuery.mockReturnValue({
data: mockRobotSideAnalysis,
} as any)
when(mockGetProtocolModulesInfo)
.calledWith(mockRobotSideAnalysis, ot3StandardDeckDef as any)
.mockReturnValue(mockProtocolModuleInfo)
Expand All @@ -386,9 +386,9 @@ describe('ProtocolSetup', () => {
})

it('should launch protocol setup liquids screen when click liquids', () => {
when(mockUseMostRecentCompletedAnalysis)
.calledWith(RUN_ID)
.mockReturnValue({ ...mockRobotSideAnalysis, liquids: mockLiquids })
mockUseProtocolAnalysisAsDocumentQuery.mockReturnValue({
data: { ...mockRobotSideAnalysis, liquids: mockLiquids },
} as any)
when(mockGetProtocolModulesInfo)
.calledWith(
{ ...mockRobotSideAnalysis, liquids: mockLiquids },
Expand Down Expand Up @@ -422,7 +422,9 @@ describe('ProtocolSetup', () => {
getByText('mock ConfirmAttachedModal')
})
it('should render a loading skeleton while awaiting a response from the server', () => {
mockUseMostRecentCompletedAnalysis.mockReturnValue(null)
mockUseProtocolAnalysisAsDocumentQuery.mockReturnValue({
data: null,
} as any)
const [{ getAllByTestId }] = render(`/runs/${RUN_ID}/setup/`)
expect(getAllByTestId('Skeleton').length).toBeGreaterThan(0)
})
Expand Down
30 changes: 28 additions & 2 deletions app/src/pages/OnDeviceDisplay/ProtocolSetup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'
import last from 'lodash/last'
import { useSelector } from 'react-redux'
import { useTranslation } from 'react-i18next'
import { useHistory, useParams } from 'react-router-dom'
Expand Down Expand Up @@ -28,6 +29,7 @@ import {
useRunQuery,
useInstrumentsQuery,
useDoorQuery,
useProtocolAnalysisAsDocumentQuery,
} from '@opentrons/react-api-client'
import {
getDeckDefFromRobotType,
Expand All @@ -51,7 +53,6 @@ import {
useRequiredProtocolHardwareFromAnalysis,
useMissingProtocolHardwareFromAnalysis,
} from '../../Protocols/hooks'
import { useMostRecentCompletedAnalysis } from '../../../organisms/LabwarePositionCheck/useMostRecentCompletedAnalysis'
import { getProtocolModulesInfo } from '../../../organisms/Devices/ProtocolRun/utils/getProtocolModulesInfo'
import { ProtocolSetupLabware } from '../../../organisms/ProtocolSetupLabware'
import { ProtocolSetupModulesAndDeck } from '../../../organisms/ProtocolSetupModulesAndDeck'
Expand Down Expand Up @@ -202,6 +203,7 @@ export function ProtocolSetupStep({
)
}

const ANALYSIS_POLL_MS = 5000
interface PrepareToRunProps {
runId: string
setSetupScreen: React.Dispatch<React.SetStateAction<SetupScreens>>
Expand Down Expand Up @@ -242,7 +244,31 @@ function PrepareToRun({
protocolRecord?.data.metadata.protocolName ??
protocolRecord?.data.files[0].name ??
''
const mostRecentAnalysis = useMostRecentCompletedAnalysis(runId)

const mostRecentAnalysisSummary = last(protocolRecord?.data.analysisSummaries)
const [
isPollingForCompletedAnalysis,
setIsPollingForCompletedAnalysis,
] = React.useState<boolean>(mostRecentAnalysisSummary?.status !== 'completed')

const {
data: mostRecentAnalysis = null,
} = useProtocolAnalysisAsDocumentQuery(
protocolId,
last(protocolRecord?.data.analysisSummaries)?.id ?? null,
{
enabled: protocolRecord != null && isPollingForCompletedAnalysis,
refetchInterval: ANALYSIS_POLL_MS,
}
)

React.useEffect(() => {
if (mostRecentAnalysis?.status === 'completed') {
setIsPollingForCompletedAnalysis(false)
} else {
setIsPollingForCompletedAnalysis(true)
}
}, [mostRecentAnalysis?.status])

const robotType = useRobotType(robotName)
const { launchLPC, LPCWizard } = useLaunchLPC(runId, robotType, protocolName)
Expand Down

0 comments on commit c08937e

Please sign in to comment.