Skip to content

Commit

Permalink
fix(app): dismiss run on AnalysisFailedModal CTA (#16054)
Browse files Browse the repository at this point in the history
# Overview

On ODD, because `TopLevelRedirects` navigates to the current run route
if such a run exists, we need to be sure to explicitly clear the current
run when navigating away, or we will be immediately bounced back to the
current run screen. With the introduction of RTPs that will cause
reanalysis to fail at the run, we show a new `AnalysisFailedModal`
component. The CTA button should first dismiss the current run, then
navigate to protocol details or protocols landing, ensuring this bounce
does not occur.

Closes RQA-3004
  • Loading branch information
ncdiehl11 authored Aug 20, 2024
1 parent 5cadbb6 commit d43a8bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SPACING,
LegacyStyledText,
} from '@opentrons/components'
import { useDismissCurrentRunMutation } from '@opentrons/react-api-client'

import { SmallButton } from '../../atoms/buttons'
import { Modal } from '../../molecules/Modal'
Expand All @@ -18,12 +19,14 @@ import type { ModalHeaderBaseProps } from '../../molecules/Modal/types'
interface AnalysisFailedModalProps {
errors: string[]
protocolId: string | null
runId: string
setShowAnalysisFailedModal: (showAnalysisFailedModal: boolean) => void
}

export function AnalysisFailedModal({
errors,
protocolId,
runId,
setShowAnalysisFailedModal,
}: AnalysisFailedModalProps): JSX.Element {
const { t } = useTranslation('protocol_setup')
Expand All @@ -35,8 +38,15 @@ export function AnalysisFailedModal({
hasExitIcon: true,
}

const {
isLoading: isDismissing,
mutateAsync: dismissCurrentRunAsync,
} = useDismissCurrentRunMutation()

const handleRestartSetup = (): void => {
navigate(protocolId != null ? `/protocols/${protocolId}` : '/protocols')
dismissCurrentRunAsync(runId).then(() => {
navigate(protocolId != null ? `/protocols/${protocolId}` : '/protocols')
})
}

return (
Expand Down Expand Up @@ -76,6 +86,9 @@ export function AnalysisFailedModal({
onClick={handleRestartSetup}
buttonText={t('restart_setup')}
buttonType="alert"
iconName={isDismissing ? 'ot-spinner' : null}
iconPlacement="startIcon"
disabled={isDismissing}
/>
</Flex>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import * as React from 'react'
import { describe, it, vi, beforeEach, expect } from 'vitest'
import { when } from 'vitest-when'
import { fireEvent, screen } from '@testing-library/react'
import { useDismissCurrentRunMutation } from '@opentrons/react-api-client'

import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { AnalysisFailedModal } from '../AnalysisFailedModal'
import type { NavigateFunction } from 'react-router-dom'

const mockNavigate = vi.fn()
const PROTOCOL_ID = 'mockId'
const PROTOCOL_ID = 'mockProtocolId'
const RUN_ID = 'mockRunId'
const mockSetShowAnalysisFailedModal = vi.fn()
const mockNavigate = vi.fn()
const mockDismissCurrentRunAsync = vi.fn(
() => new Promise(resolve => resolve({}))
)

vi.mock('@opentrons/react-api-client')
vi.mock('react-router-dom', async importOriginal => {
const reactRouterDom = await importOriginal<NavigateFunction>()
return {
Expand All @@ -28,13 +35,19 @@ const render = (props: React.ComponentProps<typeof AnalysisFailedModal>) => {
describe('AnalysisFailedModal', () => {
let props: React.ComponentProps<typeof AnalysisFailedModal>

when(vi.mocked(useDismissCurrentRunMutation))
.calledWith()
.thenReturn({
mutateAsync: mockDismissCurrentRunAsync,
} as any)
beforeEach(() => {
props = {
errors: [
'analysis failed reason message 1',
'analysis failed reason message 2',
],
protocolId: PROTOCOL_ID,
runId: RUN_ID,
setShowAnalysisFailedModal: mockSetShowAnalysisFailedModal,
}
})
Expand All @@ -55,15 +68,10 @@ describe('AnalysisFailedModal', () => {
expect(mockSetShowAnalysisFailedModal).toHaveBeenCalled()
})

it('should call a mock function when tapping restart setup button', () => {
it('should call mock dismiss current run function when tapping restart setup button', () => {
render(props)
fireEvent.click(screen.getByText('Restart setup'))
expect(mockNavigate).toHaveBeenCalledWith(`/protocols/${PROTOCOL_ID}`)
})

it('should push to protocols dashboard when tapping restart setup button and protocol ID is null', () => {
render({ ...props, protocolId: null })
fireEvent.click(screen.getByText('Restart setup'))
expect(mockNavigate).toHaveBeenCalledWith('/protocols')
console.log(mockDismissCurrentRunAsync)
expect(mockDismissCurrentRunAsync).toBeCalled()
})
})
1 change: 1 addition & 0 deletions app/src/pages/ProtocolSetup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ export function ProtocolSetup(): JSX.Element {
<AnalysisFailedModal
setShowAnalysisFailedModal={setShowAnalysisFailedModal}
protocolId={runRecord?.data.protocolId ?? null}
runId={runId}
errors={analysisErrors.map(error => error.detail)}
/>
) : null}
Expand Down

0 comments on commit d43a8bd

Please sign in to comment.