Skip to content

Commit

Permalink
refactor events to match new specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Nov 7, 2024
1 parent 85d7dac commit 4a4574a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
43 changes: 39 additions & 4 deletions protocol-designer/src/analytics/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,45 @@ export const reduxActionToAnalyticsEvent = (
}

const stepName = stepArgs.commandCreatorFnName
const modifiedStepName = stepName === 'delay' ? 'pause' : stepName
return {
name: `${modifiedStepName}Step`,
properties: { ...stepArgs, ...additionalProperties },
const modifiedStepName =
stepName === 'delay' || stepName === 'waitForTemperature'
? 'pause'
: stepName

if (
modifiedStepName === 'engageMagnet' ||
modifiedStepName === 'disengageMagnet'
) {
return {
name: `magnetStep`,
properties: { type: modifiedStepName },
}
} else if (
modifiedStepName === 'deactivateTemperature' ||
modifiedStepName === 'setTemperature'
) {
return {
name: `temperatureStep`,
properties: { type: modifiedStepName },
}
} else if (
modifiedStepName === 'thermocyclerProfile' ||
modifiedStepName === 'thermocyclerState'
) {
return {
name: 'thermocyclerStep',
properties: { type: modifiedStepName },
}
} else if (modifiedStepName === 'heaterShaker') {
return {
name: 'heaterShakerStep',
properties: {},
}
} else {
return {
name: `${modifiedStepName}Step`,
properties: { ...stepArgs, ...additionalProperties },
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getDeckSetupForActiveItem } from '../../../top-selectors/labware-locati
import { selectors } from '../../../labware-ingred/selectors'
import { getDesignerTab, getFileMetadata } from '../../../file-data/selectors'
import { generateNewProtocol } from '../../../labware-ingred/actions'
import { analyticsEvent } from '../../../analytics/actions'
import { DeckSetupContainer } from '../DeckSetup'
import { Designer } from '../index'
import { LiquidsOverflowMenu } from '../LiquidsOverflowMenu'
Expand All @@ -21,7 +20,6 @@ vi.mock('../ProtocolSteps')
vi.mock('../../../labware-ingred/actions')
vi.mock('../../../labware-ingred/selectors')
vi.mock('../LiquidsOverflowMenu')
vi.mock('../../../analytics/actions')
vi.mock('../DeckSetup')
vi.mock('../../../file-data/selectors')
vi.mock('../../../top-selectors/labware-locations')
Expand Down Expand Up @@ -109,7 +107,6 @@ describe('Designer', () => {
vi.mocked(getDesignerTab).mockReturnValue('protocolSteps')
render()
fireEvent.click(screen.getByText('Protocol steps'))
expect(vi.mocked(analyticsEvent)).toHaveBeenCalled()
screen.getByText('mock ProtocolSteps')
})
})
17 changes: 0 additions & 17 deletions protocol-designer/src/pages/Designer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { getDeckSetupForActiveItem } from '../../top-selectors/labware-locations
import { generateNewProtocol } from '../../labware-ingred/actions'
import { DefineLiquidsModal, ProtocolMetadataNav } from '../../organisms'
import { selectDesignerTab } from '../../file-data/actions'
import { analyticsEvent } from '../../analytics/actions'
import { getDesignerTab, getFileMetadata } from '../../file-data/selectors'
import { DeckSetupContainer } from './DeckSetup'
import { selectors } from '../../labware-ingred/selectors'
Expand All @@ -34,7 +33,6 @@ import { ProtocolSteps } from './ProtocolSteps'

import type { CutoutId } from '@opentrons/shared-data'
import type { DeckSlot } from '@opentrons/step-generation'
import type { AnalyticsEvent } from '../../analytics/mixpanel'

export interface OpenSlot {
cutoutId: CutoutId
Expand All @@ -47,9 +45,6 @@ export function Designer(): JSX.Element {
'protocol_steps',
'shared',
])
const [analyticsStartTime, setAnalyticsStartTime] = useState<Date | null>(
null
)
const { bakeToast, makeSnackbar } = useKitchen()
const navigate = useNavigate()
const dispatch = useDispatch()
Expand All @@ -73,15 +68,6 @@ export function Designer(): JSX.Element {
ae => ae.name === 'trashBin' || ae.name === 'wasteChute'
)

const handleAnalyticsEndTime = (): void => {
const duration = new Date().getTime() - (analyticsStartTime?.getTime() ?? 0)
const deckSetupDuration: AnalyticsEvent = {
name: 'deckSetupDuration',
properties: { duration: `${duration / 1000} seconds` },
}
dispatch(analyticsEvent(deckSetupDuration))
}

const startingDeckTab = {
text: t('protocol_starting_deck'),
isActive: tab === 'startingDeck',
Expand All @@ -95,7 +81,6 @@ export function Designer(): JSX.Element {
onClick: () => {
if (hasTrashEntity) {
dispatch(selectDesignerTab({ tab: 'protocolSteps' }))
handleAnalyticsEndTime()
} else {
makeSnackbar(t('trash_required') as string)
}
Expand Down Expand Up @@ -146,7 +131,6 @@ export function Designer(): JSX.Element {
if (tab === 'startingDeck') {
// ensure that the starting deck page is always showing the initial deck setup
dispatch(selectTerminalItem('__initial_setup__'))
setAnalyticsStartTime(new Date())
}
}, [tab])

Expand Down Expand Up @@ -198,7 +182,6 @@ export function Designer(): JSX.Element {
if (hasTrashEntity) {
navigate('/overview')
dispatch(selectTerminalItem('__initial_setup__'))
handleAnalyticsEndTime()
} else {
makeSnackbar(t('trash_required') as string)
}
Expand Down

0 comments on commit 4a4574a

Please sign in to comment.