diff --git a/app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx b/app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx index 2fb5f75efb2..e39e46ef62f 100644 --- a/app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx +++ b/app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx @@ -38,7 +38,7 @@ import { useMissingProtocolHardware } from '../../../pages/Protocols/hooks' import { useCloneRun } from '../../ProtocolUpload/hooks' import { useRerunnableStatusText } from './hooks' -import type { Run, RunData, RunStatus } from '@opentrons/api-client' +import type { RunData, RunStatus } from '@opentrons/api-client' import type { ProtocolResource } from '@opentrons/shared-data' interface RecentRunProtocolCardProps { @@ -88,10 +88,7 @@ export function ProtocolWithLastRun({ const trackEvent = useTrackEvent() // TODO(BC, 08/29/23): reintroduce this analytics event when we refactor the hook to fetch data lazily (performance concern) // const { trackProtocolRunEvent } = useTrackProtocolRunEvent(runData.id) - const onResetSuccess = (createRunResponse: Run): void => { - navigate(`runs/${createRunResponse.data.id}/setup`) - } - const { cloneRun } = useCloneRun(runData.id, onResetSuccess) + const { cloneRun } = useCloneRun(runData.id) const [showSpinner, setShowSpinner] = React.useState(false) const protocolName = @@ -143,6 +140,9 @@ export function ProtocolWithLastRun({ navigate(`/protocols/${protocolId}`) } else { cloneRun() + // Navigate to a dummy setup skeleton until TopLevelRedirects routes to the proper setup page. Doing so prevents + // needing to manage complex UI state updates for protocol cards, overzealous dashboard rendering, and potential navigation pitfalls. + navigate('/runs/1234/setup') trackEvent({ name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN, properties: { sourceLocation: 'RecentRunProtocolCard' }, diff --git a/app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx b/app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx index 006bf2dc43e..d9d4959814d 100644 --- a/app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx +++ b/app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx @@ -158,9 +158,10 @@ describe('RecentRunProtocolCard', () => { when(useTrackProtocolRunEvent).calledWith(RUN_ID, ROBOT_NAME).thenReturn({ trackProtocolRunEvent: mockTrackProtocolRunEvent, }) - when(useCloneRun) - .calledWith(RUN_ID, expect.anything()) - .thenReturn({ cloneRun: mockCloneRun, isLoading: false }) + vi.mocked(useCloneRun).mockReturnValue({ + cloneRun: mockCloneRun, + isLoading: false, + }) }) afterEach(() => { diff --git a/app/src/organisms/ProtocolUpload/hooks/useCloneRun.ts b/app/src/organisms/ProtocolUpload/hooks/useCloneRun.ts index 0132adf7298..41277f47e86 100644 --- a/app/src/organisms/ProtocolUpload/hooks/useCloneRun.ts +++ b/app/src/organisms/ProtocolUpload/hooks/useCloneRun.ts @@ -36,10 +36,13 @@ export function useCloneRun( 'protocols', protocolKey, ]) - Promise.all([invalidateRuns, invalidateProtocols]).catch((e: Error) => { - console.error(`error invalidating runs query: ${e.message}`) - }) - if (onSuccessCallback != null) onSuccessCallback(response) + Promise.all([invalidateRuns, invalidateProtocols]) + .then(() => { + onSuccessCallback?.(response) + }) + .catch((e: Error) => { + console.error(`error invalidating runs query: ${e.message}`) + }) }, }) const { createProtocolAnalysis } = useCreateProtocolAnalysisMutation(