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): allow ODD to poll for completed analysis on protocol setup #14197

Merged
merged 3 commits into from
Dec 14, 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
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 @@ -50,7 +52,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 @@ -199,6 +200,7 @@ export function ProtocolSetupStep({
)
}

const ANALYSIS_POLL_MS = 5000
interface PrepareToRunProps {
runId: string
setSetupScreen: React.Dispatch<React.SetStateAction<SetupScreens>>
Expand Down Expand Up @@ -239,7 +241,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
Loading