Skip to content

Commit

Permalink
fix(app): add robotSerialNumber to proceedToRun event (#14976)
Browse files Browse the repository at this point in the history
* fix(app): add robotSerialNumber to proceedToRun event
  • Loading branch information
koji authored and Carlos-fernandez committed May 20, 2024
1 parent 67f80be commit 2c8f7cd
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
10 changes: 8 additions & 2 deletions app/src/organisms/Devices/HistoricalProtocolRunOverflowMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
ANALYTICS_PROTOCOL_RUN_AGAIN,
} from '../../redux/analytics'
import { getRobotUpdateDisplayInfo } from '../../redux/robot-update'
import { useDownloadRunLog, useTrackProtocolRunEvent } from './hooks'
import { useDownloadRunLog, useTrackProtocolRunEvent, useRobot } from './hooks'
import { useIsEstopNotDisengaged } from '../../resources/devices/hooks/useIsEstopNotDisengaged'

import type { Run } from '@opentrons/api-client'
Expand Down Expand Up @@ -132,6 +132,9 @@ function MenuDropdown(props: MenuDropdownProps): JSX.Element {
const { trackProtocolRunEvent } = useTrackProtocolRunEvent(runId, robotName)
const { reset } = useRunControls(runId, onResetSuccess)
const { deleteRun } = useDeleteRunMutation()
const robot = useRobot(robotName)
const robotSerialNumber =
robot?.health?.robot_serial ?? robot?.serverHealth?.serialNumber ?? null

const handleResetClick: React.MouseEventHandler<HTMLButtonElement> = (
e
Expand All @@ -142,7 +145,10 @@ function MenuDropdown(props: MenuDropdownProps): JSX.Element {
reset()
trackEvent({
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
properties: { sourceLocation: 'HistoricalProtocolRun' },
properties: {
sourceLocation: 'HistoricalProtocolRun',
robotSerialNumber,
},
})
trackProtocolRunEvent({ name: ANALYTICS_PROTOCOL_RUN_AGAIN })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ import '@testing-library/jest-dom/vitest'
import { renderWithProviders } from '../../../__testing-utils__'
import { when } from 'vitest-when'
import { MemoryRouter } from 'react-router-dom'
import { UseQueryResult } from 'react-query'
import {
useAllCommandsQuery,
useDeleteRunMutation,
} from '@opentrons/react-api-client'
import { i18n } from '../../../i18n'
import runRecord from '../../../organisms/RunDetails/__fixtures__/runRecord.json'
import { useDownloadRunLog, useTrackProtocolRunEvent } from '../hooks'
import { useDownloadRunLog, useTrackProtocolRunEvent, useRobot } from '../hooks'
import { useRunControls } from '../../RunTimeControl/hooks'
import {
useTrackEvent,
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
} from '../../../redux/analytics'
import { mockConnectableRobot } from '../../../redux/discovery/__fixtures__'
import { getRobotUpdateDisplayInfo } from '../../../redux/robot-update'
import { useIsEstopNotDisengaged } from '../../../resources/devices/hooks/useIsEstopNotDisengaged'
import { HistoricalProtocolRunOverflowMenu } from '../HistoricalProtocolRunOverflowMenu'

import type { UseQueryResult } from 'react-query'
import type { CommandsData } from '@opentrons/api-client'

vi.mock('../../../redux/analytics')
Expand Down Expand Up @@ -104,6 +105,9 @@ describe('HistoricalProtocolRunOverflowMenu', () => {
robotName: ROBOT_NAME,
robotIsBusy: false,
}
when(vi.mocked(useRobot))
.calledWith(ROBOT_NAME)
.thenReturn(mockConnectableRobot)
})

it('renders the correct menu when a runId is present', () => {
Expand All @@ -122,7 +126,10 @@ describe('HistoricalProtocolRunOverflowMenu', () => {
fireEvent.click(rerunBtn)
expect(mockTrackEvent).toHaveBeenCalledWith({
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
properties: { sourceLocation: 'HistoricalProtocolRun' },
properties: {
robotSerialNumber: 'mock-serial',
sourceLocation: 'HistoricalProtocolRun',
},
})
expect(useRunControls).toHaveBeenCalled()
expect(mockTrackProtocolRunEvent).toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('useProtocolAnalysisErrors hook', () => {
protocolText: 'hashedString',
protocolType: '',
robotType: 'OT-2 Standard',
robotSerialNumber: '',
robotSerialNumber: 'mock-serial',
},
runTime: '1:00:00',
})
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('useProtocolAnalysisErrors hook', () => {
protocolText: 'hashedString',
protocolType: 'json',
robotType: 'OT-2 Standard',
robotSerialNumber: '',
robotSerialNumber: 'mock-serial',
},
runTime: '1:00:00',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import {
} from '@opentrons/api-client'

import { ODD_FOCUS_VISIBLE } from '../../../atoms/buttons//constants'
import { useTrackEvent } from '../../../redux/analytics'
import {
useTrackEvent,
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
} from '../../../redux/analytics'
import { Skeleton } from '../../../atoms/Skeleton'
import { useMissingProtocolHardware } from '../../../pages/Protocols/hooks'
import { useCloneRun } from '../../ProtocolUpload/hooks'
Expand Down Expand Up @@ -147,7 +150,7 @@ export function ProtocolWithLastRun({
} else {
cloneRun()
trackEvent({
name: 'proceedToRun',
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
properties: { sourceLocation: 'RecentRunProtocolCard' },
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { i18n } from '../../../../i18n'
import { Skeleton } from '../../../../atoms/Skeleton'
import { useMissingProtocolHardware } from '../../../../pages/Protocols/hooks'
import { useTrackProtocolRunEvent } from '../../../Devices/hooks'
import { useTrackEvent } from '../../../../redux/analytics'
import {
useTrackEvent,
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
} from '../../../../redux/analytics'
import { useCloneRun } from '../../../ProtocolUpload/hooks'
import { useRerunnableStatusText } from '../hooks'
import { RecentRunProtocolCard } from '../'
Expand Down Expand Up @@ -250,7 +253,7 @@ describe('RecentRunProtocolCard', () => {
expect(button).toHaveStyle(`background-color: ${COLORS.green40}`)
fireEvent.click(button)
expect(mockTrackEvent).toHaveBeenCalledWith({
name: 'proceedToRun',
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
properties: { sourceLocation: 'RecentRunProtocolCard' },
})
// TODO(BC, 08/30/23): reintroduce check for tracking when tracking is reintroduced lazily
Expand Down
9 changes: 7 additions & 2 deletions app/src/pages/RunSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
// ANALYTICS_PROTOCOL_RUN_CANCEL,
ANALYTICS_PROTOCOL_RUN_AGAIN,
ANALYTICS_PROTOCOL_RUN_FINISH,
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
} from '../../redux/analytics'
import { getLocalRobot } from '../../redux/discovery'
import { RunFailedModal } from '../../organisms/OnDeviceDisplay/RunningProtocol'
Expand Down Expand Up @@ -124,6 +125,10 @@ export function RunSummary(): JSX.Element {
const [showRunAgainSpinner, setShowRunAgainSpinner] = React.useState<boolean>(
false
)
const robotSerialNumber =
localRobot?.health?.robot_serial ??
localRobot?.serverHealth?.serialNumber ??
null

let headerText = t('run_complete_splash')
if (runStatus === RUN_STATUS_FAILED) {
Expand Down Expand Up @@ -167,8 +172,8 @@ export function RunSummary(): JSX.Element {
setShowRunAgainSpinner(true)
reset()
trackEvent({
name: 'proceedToRun',
properties: { sourceLocation: 'RunSummary' },
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
properties: { sourceLocation: 'RunSummary', robotSerialNumber },
})
trackProtocolRunEvent({ name: ANALYTICS_PROTOCOL_RUN_AGAIN })
}
Expand Down
1 change: 1 addition & 0 deletions app/src/redux/discovery/__fixtures__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const mockHealthResponse = {
api_version: '0.0.0-mock',
fw_version: '0.0.0-mock',
system_version: '0.0.0-mock',
robot_serial: 'mock-serial',
logs: [] as string[],
protocol_api_version: [2, 0] as [number, number],
}
Expand Down

0 comments on commit 2c8f7cd

Please sign in to comment.