From dff63475a6ccf53c664cc4e24cc9afecc657c0ae Mon Sep 17 00:00:00 2001 From: Jamey Huffnagle Date: Mon, 16 Sep 2024 15:46:38 -0400 Subject: [PATCH] fix(app): fix auto transitioning run from recovery-paused to waiting recovery (#16259) Closes EXEC-702 In #16245, we made sure to block an open door while on the recovery splash view, but the logic for automatically transition a run from paused -> awaiting recovery is not quite right, which results in the app seemingly automatically issuing a POST play to transition a run from a recovery paused state to awaiting recovery whenever a user opens the door during error recovery flows (ie, anywhere but the splash screen). The tricky part is that when checking the network tab, there are no POST requests to initiate the transition. This problem occurs because another app issues the POST request. The logic for dispatching this POST in the useEffect condition within RecoverySplash is to check if the error recovery wizard is active, but this doesn't account for any other app that isn't doing the recovery. The solution: if the current app displays the takeover modal (which is true for any app except the sole app controlling the robot), then don't fire the POST request. --- .../ErrorRecoveryFlows/RecoverySplash.tsx | 14 +++++++++----- .../__tests__/RecoverySplash.test.tsx | 4 ++-- app/src/organisms/ErrorRecoveryFlows/index.tsx | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/organisms/ErrorRecoveryFlows/RecoverySplash.tsx b/app/src/organisms/ErrorRecoveryFlows/RecoverySplash.tsx index 041cc85cadb..c938fb9f4ad 100644 --- a/app/src/organisms/ErrorRecoveryFlows/RecoverySplash.tsx +++ b/app/src/organisms/ErrorRecoveryFlows/RecoverySplash.tsx @@ -62,10 +62,11 @@ export function useRecoverySplash( type RecoverySplashProps = ErrorRecoveryFlowsProps & ERUtilsResults & { isOnDevice: boolean - isWizardActive: boolean failedCommand: ReturnType robotType: RobotType robotName: string + /* Whether the app should resume any paused recovery state without user action. */ + resumePausedRecovery: boolean toggleERWizAsActiveUser: UseRecoveryTakeoverResult['toggleERWizAsActiveUser'] analytics: UseRecoveryAnalyticsResult } @@ -79,7 +80,7 @@ export function RecoverySplash(props: RecoverySplashProps): JSX.Element | null { robotName, runStatus, recoveryActionMutationUtils, - isWizardActive, + resumePausedRecovery, } = props const { t } = useTranslation('error_recovery') const errorKind = getErrorKind(failedCommand?.byRunRecord ?? null) @@ -99,12 +100,15 @@ export function RecoverySplash(props: RecoverySplashProps): JSX.Element | null { // Resume recovery when the run when the door is closed. // The CTA/flow for handling a door open event within the ER wizard is different, and because this splash always renders - // behind the wizard, we want to ensure we only implicitly resume recovery when only viewing the splash. + // behind the wizard, we want to ensure we only implicitly resume recovery when only viewing the splash from this app. React.useEffect(() => { - if (runStatus === RUN_STATUS_AWAITING_RECOVERY_PAUSED && !isWizardActive) { + if ( + runStatus === RUN_STATUS_AWAITING_RECOVERY_PAUSED && + resumePausedRecovery + ) { recoveryActionMutationUtils.resumeRecovery() } - }, [runStatus, isWizardActive]) + }, [runStatus, resumePausedRecovery]) const buildDoorOpenAlert = (): void => { makeToast(t('close_door_to_resume') as string, WARNING_TOAST) } diff --git a/app/src/organisms/ErrorRecoveryFlows/__tests__/RecoverySplash.test.tsx b/app/src/organisms/ErrorRecoveryFlows/__tests__/RecoverySplash.test.tsx index c09a35ff5fc..f0cf0099f41 100644 --- a/app/src/organisms/ErrorRecoveryFlows/__tests__/RecoverySplash.test.tsx +++ b/app/src/organisms/ErrorRecoveryFlows/__tests__/RecoverySplash.test.tsx @@ -95,7 +95,7 @@ describe('RecoverySplash', () => { recoveryActionMutationUtils: { resumeRecovery: mockResumeRecovery, } as any, - isWizardActive: false, + resumePausedRecovery: true, } vi.mocked(StepInfo).mockReturnValue(
MOCK STEP INFO
) @@ -177,7 +177,7 @@ describe('RecoverySplash', () => { expect(mockMakeToast).toHaveBeenCalled() }) - it(`should transition the run status from ${RUN_STATUS_AWAITING_RECOVERY_PAUSED} to ${RUN_STATUS_AWAITING_RECOVERY}`, () => { + it(`should transition the run status from ${RUN_STATUS_AWAITING_RECOVERY_PAUSED} to ${RUN_STATUS_AWAITING_RECOVERY} when resumePausedRecovery is true`, () => { props = { ...props, runStatus: RUN_STATUS_AWAITING_RECOVERY_PAUSED } render(props) diff --git a/app/src/organisms/ErrorRecoveryFlows/index.tsx b/app/src/organisms/ErrorRecoveryFlows/index.tsx index b1b82fad236..3656fb7fa52 100644 --- a/app/src/organisms/ErrorRecoveryFlows/index.tsx +++ b/app/src/organisms/ErrorRecoveryFlows/index.tsx @@ -147,6 +147,8 @@ export function ErrorRecoveryFlows( failedCommand: failedCommandBySource, }) + console.log('=>(index.tsx:180) showTakeover', showTakeover) + return ( <> {showTakeover ? ( @@ -176,7 +178,7 @@ export function ErrorRecoveryFlows( isOnDevice={isOnDevice} toggleERWizAsActiveUser={toggleERWizAsActiveUser} failedCommand={failedCommandBySource} - isWizardActive={renderWizard} + resumePausedRecovery={!renderWizard && !showTakeover} /> ) : null}