From 4a4574acdb397878e21b1871d8b48cfbb68aaaa9 Mon Sep 17 00:00:00 2001 From: Jethary Date: Wed, 6 Nov 2024 16:26:42 -0500 Subject: [PATCH] refactor events to match new specs --- protocol-designer/src/analytics/middleware.ts | 43 +++++++++++++++++-- .../Designer/__tests__/Designer.test.tsx | 3 -- .../src/pages/Designer/index.tsx | 17 -------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/protocol-designer/src/analytics/middleware.ts b/protocol-designer/src/analytics/middleware.ts index c8579157039..514f4a59b14 100644 --- a/protocol-designer/src/analytics/middleware.ts +++ b/protocol-designer/src/analytics/middleware.ts @@ -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 }, + } } } } diff --git a/protocol-designer/src/pages/Designer/__tests__/Designer.test.tsx b/protocol-designer/src/pages/Designer/__tests__/Designer.test.tsx index 1100f40395e..d7a05a8efe0 100644 --- a/protocol-designer/src/pages/Designer/__tests__/Designer.test.tsx +++ b/protocol-designer/src/pages/Designer/__tests__/Designer.test.tsx @@ -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' @@ -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') @@ -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') }) }) diff --git a/protocol-designer/src/pages/Designer/index.tsx b/protocol-designer/src/pages/Designer/index.tsx index 96c1ea0574f..85597ba3e66 100644 --- a/protocol-designer/src/pages/Designer/index.tsx +++ b/protocol-designer/src/pages/Designer/index.tsx @@ -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' @@ -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 @@ -47,9 +45,6 @@ export function Designer(): JSX.Element { 'protocol_steps', 'shared', ]) - const [analyticsStartTime, setAnalyticsStartTime] = useState( - null - ) const { bakeToast, makeSnackbar } = useKitchen() const navigate = useNavigate() const dispatch = useDispatch() @@ -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', @@ -95,7 +81,6 @@ export function Designer(): JSX.Element { onClick: () => { if (hasTrashEntity) { dispatch(selectDesignerTab({ tab: 'protocolSteps' })) - handleAnalyticsEndTime() } else { makeSnackbar(t('trash_required') as string) } @@ -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]) @@ -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) }