From 95963656053a52f46f74f6f8552f89479e39b8be Mon Sep 17 00:00:00 2001 From: Jamey H Date: Mon, 18 Dec 2023 13:31:02 -0500 Subject: [PATCH 1/3] fix(app): fix viewing error modal dismissing error and drop tip banners The error modal render should not be tied to CurrentRun but rather if the mostRecentRun is the currently viewed run. --- app/src/organisms/Devices/ProtocolRun/ProtocolRunHeader.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/organisms/Devices/ProtocolRun/ProtocolRunHeader.tsx b/app/src/organisms/Devices/ProtocolRun/ProtocolRunHeader.tsx index 50f5b5b6c2a..ab7042fd935 100644 --- a/app/src/organisms/Devices/ProtocolRun/ProtocolRunHeader.tsx +++ b/app/src/organisms/Devices/ProtocolRun/ProtocolRunHeader.tsx @@ -364,7 +364,7 @@ export function ProtocolRunHeader({ CANCELLABLE_STATUSES.includes(runStatus) ? ( {t('shared:close_robot_door')} ) : null} - {isRunCurrent ? ( + {mostRecentRunId === runId ? ( Date: Mon, 18 Dec 2023 13:36:05 -0500 Subject: [PATCH 2/3] refactor(app): refactor useMostRunRecentId to be safer --- .../__tests__/ProtocolRunHeader.test.tsx | 22 ------------------- .../__tests__/useMostRecentRunId.test.tsx | 9 ++++++++ .../hooks/useMostRecentRunId.ts | 5 +++-- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunHeader.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunHeader.test.tsx index 4dc85eb7dcf..d35cc238795 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunHeader.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunHeader.test.tsx @@ -1054,26 +1054,4 @@ describe('ProtocolRunHeader', () => { expect(queryByText('Tips may be attached.')).not.toBeInTheDocument() }) }) - - it('does not show the drop tip banner when the run is not over', async () => { - when(mockUseRunQuery) - .calledWith(RUN_ID) - .mockReturnValue({ - data: { - data: { - ...mockIdleUnstartedRun, - current: false, - status: RUN_STATUS_SUCCEEDED, - }, - }, - } as UseQueryResult) - when(mockUseRunStatus) - .calledWith(RUN_ID) - .mockReturnValue(RUN_STATUS_SUCCEEDED) - - const [{ queryByText }] = render() - await waitFor(() => { - expect(queryByText('Tips may be attached.')).not.toBeInTheDocument() - }) - }) }) diff --git a/app/src/organisms/ProtocolUpload/hooks/__tests__/useMostRecentRunId.test.tsx b/app/src/organisms/ProtocolUpload/hooks/__tests__/useMostRecentRunId.test.tsx index eb0d55f639c..94c4bb30e82 100644 --- a/app/src/organisms/ProtocolUpload/hooks/__tests__/useMostRecentRunId.test.tsx +++ b/app/src/organisms/ProtocolUpload/hooks/__tests__/useMostRecentRunId.test.tsx @@ -31,6 +31,15 @@ describe('useMostRecentRunId hook', () => { const { result } = renderHook(useMostRecentRunId) + expect(result.current).toBeNull() + }) + it('should return null if no run data exists', async () => { + when(mockUseAllRunsQuery) + .calledWith() + .mockReturnValue({ data: { data: null } } as any) + + const { result } = renderHook(useMostRecentRunId) + expect(result.current).toBeNull() }) }) diff --git a/app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts b/app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts index 759a5aa2e06..02e2ee34237 100644 --- a/app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts +++ b/app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts @@ -1,8 +1,9 @@ import { useAllRunsQuery } from '@opentrons/react-api-client' +import { last } from 'lodash' export function useMostRecentRunId(): string | null { const { data: allRuns } = useAllRunsQuery() - return allRuns != null && allRuns.data.length > 0 - ? allRuns.data[allRuns.data.length - 1].id + return allRuns != null && allRuns.data?.length > 0 + ? last(allRuns.data)?.id ?? null : null } From 0917d9e286420463ec59c3921a029baaa15d0fed Mon Sep 17 00:00:00 2001 From: Jamey H Date: Mon, 18 Dec 2023 14:15:14 -0500 Subject: [PATCH 3/3] feedback --- app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts b/app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts index 02e2ee34237..f3f29c10d7a 100644 --- a/app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts +++ b/app/src/organisms/ProtocolUpload/hooks/useMostRecentRunId.ts @@ -1,5 +1,5 @@ import { useAllRunsQuery } from '@opentrons/react-api-client' -import { last } from 'lodash' +import last from 'lodash/last' export function useMostRecentRunId(): string | null { const { data: allRuns } = useAllRunsQuery()