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

feat(app): push recent RTP run card click to protocol details #14906

Merged
merged 2 commits into from
Apr 15, 2024
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 @@ -3,6 +3,7 @@ import { css } from 'styled-components'
import { useTranslation } from 'react-i18next'
import { useHistory } from 'react-router-dom'
import { formatDistance } from 'date-fns'
import last from 'lodash/last'

import {
BORDERS,
Expand All @@ -17,14 +18,14 @@ import {
StyledText,
TYPOGRAPHY,
} from '@opentrons/components'
import { useProtocolQuery } from '@opentrons/react-api-client'
import {
useProtocolAnalysisAsDocumentQuery,
useProtocolQuery,
} from '@opentrons/react-api-client'
import {
RUN_STATUS_FAILED,
RUN_STATUS_STOPPED,
RUN_STATUS_SUCCEEDED,
Run,
RunData,
RunStatus,
} from '@opentrons/api-client'

import { ODD_FOCUS_VISIBLE } from '../../../atoms/buttons//constants'
Expand All @@ -38,6 +39,7 @@ import {
INIT_STATUS,
} from '../../../resources/health/hooks'

import type { Run, RunData, RunStatus } from '@opentrons/api-client'
import type { ProtocolResource } from '@opentrons/shared-data'

interface RecentRunProtocolCardProps {
Expand Down Expand Up @@ -98,6 +100,14 @@ export function ProtocolWithLastRun({
const protocolName =
protocolData.metadata.protocolName ?? protocolData.files[0].name

const protocolId = protocolData.id

const { data: analysis } = useProtocolAnalysisAsDocumentQuery(
protocolId,
last(protocolData?.analysisSummaries)?.id ?? null,
{ enabled: protocolData != null }
)

const PROTOCOL_CARD_STYLE = css`
flex: 1 0 0;
&:active {
Expand Down Expand Up @@ -125,13 +135,22 @@ export function ProtocolWithLastRun({
height: max-content;
`

const hasRunTimeParameters =
analysis?.runTimeParameters != null
? analysis?.runTimeParameters.length > 0
: false

const handleCardClick = (): void => {
setShowSpinner(true)
cloneRun()
trackEvent({
name: 'proceedToRun',
properties: { sourceLocation: 'RecentRunProtocolCard' },
})
if (hasRunTimeParameters) {
history.push(`/protocols/${protocolId}`)
} else {
cloneRun()
trackEvent({
name: 'proceedToRun',
properties: { sourceLocation: 'RecentRunProtocolCard' },
})
}
// TODO(BC, 08/29/23): reintroduce this analytics event when we refactor the hook to fetch data lazily (performance concern)
// trackProtocolRunEvent({ name: 'runAgain' })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import { MemoryRouter } from 'react-router-dom'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { when } from 'vitest-when'

import { useProtocolQuery } from '@opentrons/react-api-client'
import { RUN_STATUS_FAILED } from '@opentrons/api-client'
import {
useProtocolQuery,
useProtocolAnalysisAsDocumentQuery,
} from '@opentrons/react-api-client'
import {
RUN_STATUS_FAILED,
simpleAnalysisFileFixture,
} from '@opentrons/api-client'
import { COLORS } from '@opentrons/components'

import { renderWithProviders } from '../../../../__testing-utils__'
Expand All @@ -24,11 +30,23 @@ import {
INIT_STATUS,
} from '../../../../resources/health/hooks'

import type { useHistory } from 'react-router-dom'
import type { ProtocolHardware } from '../../../../pages/Protocols/hooks'

const mockPush = vi.fn()

vi.mock('react-router-dom', async importOriginal => {
const actual = await importOriginal<typeof useHistory>()
return {
...actual,
useHistory: () => ({ push: mockPush } as any),
}
})

vi.mock('@opentrons/react-api-client')
vi.mock('../../../../atoms/Skeleton')
vi.mock('../../../../pages/Protocols/hooks')
vi.mock('../../../../pages/ProtocolDetails')
vi.mock('../../../../organisms/Devices/hooks')
vi.mock('../../../../organisms/RunTimeControl/hooks')
vi.mock('../../../../organisms/ProtocolUpload/hooks')
Expand Down Expand Up @@ -128,7 +146,18 @@ describe('RecentRunProtocolCard', () => {
data: { data: [mockRunData] },
} as any)
vi.mocked(useProtocolQuery).mockReturnValue({
data: { data: { metadata: { protocolName: 'mockProtocol' } } },
data: {
data: {
metadata: { protocolName: 'mockProtocol' },
id: 'mockProtocolId',
},
},
} as any)
vi.mocked(useProtocolAnalysisAsDocumentQuery).mockReturnValue({
data: {
...simpleAnalysisFileFixture,
runTimeParameters: [],
},
} as any)
vi.mocked(useRobotInitializationStatus).mockReturnValue(
INIT_STATUS.SUCCEEDED
Expand Down Expand Up @@ -252,4 +281,14 @@ describe('RecentRunProtocolCard', () => {
const [{ getByText }] = render(props)
getByText('mock Skeleton')
})

it('should push to protocol details if protocol contains runtime parameters', () => {
vi.mocked(useProtocolAnalysisAsDocumentQuery).mockReturnValue({
data: simpleAnalysisFileFixture,
} as any)
render(props)
const button = screen.getByLabelText('RecentRunProtocolCard')
fireEvent.click(button)
expect(mockPush).toBeCalledWith('/protocols/mockProtocolId')
})
})
Loading