diff --git a/app/src/App/TopLevelRedirects/constants.ts b/app/src/App/ODDTopLevelRedirects/constants.ts similarity index 100% rename from app/src/App/TopLevelRedirects/constants.ts rename to app/src/App/ODDTopLevelRedirects/constants.ts diff --git a/app/src/App/TopLevelRedirects/hooks/__tests__/useCurrentRunRoute.test.ts b/app/src/App/ODDTopLevelRedirects/hooks/__tests__/useCurrentRunRoute.test.ts similarity index 87% rename from app/src/App/TopLevelRedirects/hooks/__tests__/useCurrentRunRoute.test.ts rename to app/src/App/ODDTopLevelRedirects/hooks/__tests__/useCurrentRunRoute.test.ts index 53b2100fd8b6..0771914e8645 100644 --- a/app/src/App/TopLevelRedirects/hooks/__tests__/useCurrentRunRoute.test.ts +++ b/app/src/App/ODDTopLevelRedirects/hooks/__tests__/useCurrentRunRoute.test.ts @@ -29,7 +29,7 @@ describe('useCurrentRunRoute', () => { it('returns null when isFetching is true', () => { vi.mocked(useNotifyRunQuery).mockReturnValue({ - data: { data: {} }, + data: { data: { startedAt: '123' } }, isFetching: true, } as any) @@ -41,7 +41,11 @@ describe('useCurrentRunRoute', () => { it('returns the summary route for a run with succeeded status', () => { vi.mocked(useNotifyRunQuery).mockReturnValue({ data: { - data: { id: MOCK_RUN_ID, status: RUN_STATUS_SUCCEEDED, actions: [] }, + data: { + id: MOCK_RUN_ID, + status: RUN_STATUS_SUCCEEDED, + startedAt: '123', + }, }, isFetching: false, } as any) @@ -57,7 +61,7 @@ describe('useCurrentRunRoute', () => { data: { id: MOCK_RUN_ID, status: RUN_STATUS_STOPPED, - actions: [{ actionType: RUN_ACTION_TYPE_PLAY }], + startedAt: '123', }, }, isFetching: false, @@ -71,7 +75,7 @@ describe('useCurrentRunRoute', () => { it('returns summary route for a run with failed status', () => { vi.mocked(useNotifyRunQuery).mockReturnValue({ data: { - data: { id: MOCK_RUN_ID, status: RUN_STATUS_FAILED, actions: [] }, + data: { id: MOCK_RUN_ID, status: RUN_STATUS_FAILED, startedAt: '123' }, }, isFetching: false, } as any) @@ -83,7 +87,9 @@ describe('useCurrentRunRoute', () => { it('returns the setup route for a run with an idle status', () => { vi.mocked(useNotifyRunQuery).mockReturnValue({ - data: { data: { id: MOCK_RUN_ID, status: RUN_STATUS_IDLE, actions: [] } }, + data: { + data: { id: MOCK_RUN_ID, status: RUN_STATUS_IDLE, startedAt: null }, + }, isFetching: false, } as any) @@ -98,7 +104,7 @@ describe('useCurrentRunRoute', () => { data: { id: MOCK_RUN_ID, status: RUN_STATUS_BLOCKED_BY_OPEN_DOOR, - actions: [], + startedAt: null, }, }, isFetching: false, @@ -115,7 +121,7 @@ describe('useCurrentRunRoute', () => { data: { id: MOCK_RUN_ID, status: RUN_STATUS_BLOCKED_BY_OPEN_DOOR, - actions: [{ actionType: RUN_ACTION_TYPE_PLAY }], + startedAt: '123', }, }, isFetching: false, @@ -129,7 +135,7 @@ describe('useCurrentRunRoute', () => { it('returns null for cancelled run before starting', () => { vi.mocked(useNotifyRunQuery).mockReturnValue({ data: { - data: { id: MOCK_RUN_ID, status: RUN_STATUS_STOPPED, actions: [] }, + data: { id: MOCK_RUN_ID, status: RUN_STATUS_STOPPED, startedAt: null }, }, isFetching: false, } as any) diff --git a/app/src/App/TopLevelRedirects/hooks/index.ts b/app/src/App/ODDTopLevelRedirects/hooks/index.ts similarity index 100% rename from app/src/App/TopLevelRedirects/hooks/index.ts rename to app/src/App/ODDTopLevelRedirects/hooks/index.ts diff --git a/app/src/App/TopLevelRedirects/hooks/useCurrentRunRoute.ts b/app/src/App/ODDTopLevelRedirects/hooks/useCurrentRunRoute.ts similarity index 77% rename from app/src/App/TopLevelRedirects/hooks/useCurrentRunRoute.ts rename to app/src/App/ODDTopLevelRedirects/hooks/useCurrentRunRoute.ts index 1152b2371ba8..47a9d5e670b1 100644 --- a/app/src/App/TopLevelRedirects/hooks/useCurrentRunRoute.ts +++ b/app/src/App/ODDTopLevelRedirects/hooks/useCurrentRunRoute.ts @@ -1,5 +1,4 @@ import { - RUN_ACTION_TYPE_PLAY, RUN_STATUS_BLOCKED_BY_OPEN_DOOR, RUN_STATUS_FAILED, RUN_STATUS_IDLE, @@ -10,27 +9,20 @@ import { import { useNotifyRunQuery } from '../../../resources/runs' import { CURRENT_RUN_POLL } from '../constants' +// Returns the route to which React Router should navigate, if any. export function useCurrentRunRoute(currentRunId: string): string | null { const { data: runRecord, isFetching } = useNotifyRunQuery(currentRunId, { refetchInterval: CURRENT_RUN_POLL, }) + // grabbing run id off of the run query to have all routing info come from one source of truth + const runId = runRecord?.data.id + const hasRunStarted = runRecord?.data.startedAt != null const runStatus = runRecord?.data.status - const runActions = runRecord?.data.actions - if ( - runRecord == null || - runStatus == null || - runActions == null || - isFetching - ) { + + if (isFetching) { return null - } - // grabbing run id off of the run query to have all routing info come from one source of truth - const runId = runRecord.data.id - const hasRunStarted = runActions?.some( - action => action.actionType === RUN_ACTION_TYPE_PLAY - ) - if ( + } else if ( runStatus === RUN_STATUS_SUCCEEDED || (runStatus === RUN_STATUS_STOPPED && hasRunStarted) || runStatus === RUN_STATUS_FAILED diff --git a/app/src/App/TopLevelRedirects/index.tsx b/app/src/App/ODDTopLevelRedirects/index.tsx similarity index 92% rename from app/src/App/TopLevelRedirects/index.tsx rename to app/src/App/ODDTopLevelRedirects/index.tsx index 9c83cbb99f7e..4ecfc50e618d 100644 --- a/app/src/App/TopLevelRedirects/index.tsx +++ b/app/src/App/ODDTopLevelRedirects/index.tsx @@ -5,7 +5,7 @@ import { useCurrentRunId } from '../../resources/runs' import { CURRENT_RUN_POLL } from './constants' import { useCurrentRunRoute } from './hooks' -export function TopLevelRedirects(): JSX.Element | null { +export function ODDTopLevelRedirects(): JSX.Element | null { const currentRunId = useCurrentRunId({ refetchInterval: CURRENT_RUN_POLL }) return currentRunId != null ? ( diff --git a/app/src/App/OnDeviceDisplayApp.tsx b/app/src/App/OnDeviceDisplayApp.tsx index 6f9787ec96be..dbc67e582f5a 100644 --- a/app/src/App/OnDeviceDisplayApp.tsx +++ b/app/src/App/OnDeviceDisplayApp.tsx @@ -50,7 +50,7 @@ import { getOnDeviceDisplaySettings, updateConfigValue } from '../redux/config' import { updateBrightness } from '../redux/shell' import { SLEEP_NEVER_MS } from './constants' import { useProtocolReceiptToast, useSoftwareUpdatePoll } from './hooks' -import { TopLevelRedirects } from './TopLevelRedirects' +import { ODDTopLevelRedirects } from './ODDTopLevelRedirects' import { OnDeviceDisplayAppFallback } from './OnDeviceDisplayAppFallback' @@ -198,7 +198,7 @@ export const OnDeviceDisplayApp = (): JSX.Element => { )} - + diff --git a/app/src/App/__tests__/OnDeviceDisplayApp.test.tsx b/app/src/App/__tests__/OnDeviceDisplayApp.test.tsx index 4e3d880de604..5f107b819995 100644 --- a/app/src/App/__tests__/OnDeviceDisplayApp.test.tsx +++ b/app/src/App/__tests__/OnDeviceDisplayApp.test.tsx @@ -29,7 +29,7 @@ import { getLocalRobot } from '../../redux/discovery' import { mockConnectedRobot } from '../../redux/discovery/__fixtures__' import { useProtocolReceiptToast } from '../hooks' import { useNotifyCurrentMaintenanceRun } from '../../resources/maintenance_runs' -import { TopLevelRedirects } from '../TopLevelRedirects' +import { ODDTopLevelRedirects } from '../ODDTopLevelRedirects' import type { UseQueryResult } from 'react-query' import type { RobotSettingsResponse } from '@opentrons/api-client' @@ -90,7 +90,7 @@ describe('OnDeviceDisplayApp', () => { beforeEach(() => { vi.mocked(getOnDeviceDisplaySettings).mockReturnValue(mockSettings as any) vi.mocked(getIsShellReady).mockReturnValue(true) - vi.mocked(TopLevelRedirects).mockReturnValue(null) + vi.mocked(ODDTopLevelRedirects).mockReturnValue(null) vi.mocked(getLocalRobot).mockReturnValue(mockConnectedRobot) vi.mocked(useNotifyCurrentMaintenanceRun).mockReturnValue({ data: { @@ -190,7 +190,7 @@ describe('OnDeviceDisplayApp', () => { expect(vi.mocked(useProtocolReceiptToast)).toHaveBeenCalled() }) it('renders TopLevelRedirects when it should conditionally render', () => { - vi.mocked(TopLevelRedirects).mockReturnValue(
MOCK_REDIRECTS
) + vi.mocked(ODDTopLevelRedirects).mockReturnValue(
MOCK_REDIRECTS
) render('/') screen.getByText('MOCK_REDIRECTS') })