From 3c15214c81658995092a2ce15d7fe2b574ace1ee Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Thu, 10 Oct 2024 11:15:09 +0200 Subject: [PATCH] [CP-3128] Cancel action handling for closing terminal information has been implemented --- .../src/lib/actions/abort-msc-flashing.ts | 21 +++++++++++++------ .../constants/flashing-process-state.enum.ts | 1 + .../lib/services/flash-msc-device.service.ts | 9 +++----- .../mac-terminal-info-modal.component.tsx | 1 - .../src/lib/ui/recovery-mode.tsx | 4 ++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/libs/msc-flash/msc-flash-harmony/src/lib/actions/abort-msc-flashing.ts b/libs/msc-flash/msc-flash-harmony/src/lib/actions/abort-msc-flashing.ts index b149303dc8..66b8f842e8 100644 --- a/libs/msc-flash/msc-flash-harmony/src/lib/actions/abort-msc-flashing.ts +++ b/libs/msc-flash/msc-flash-harmony/src/lib/actions/abort-msc-flashing.ts @@ -7,15 +7,24 @@ import { createAsyncThunk } from "@reduxjs/toolkit" import { ActionName } from "generic-view/store" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { selectFlashingAbortController } from "../selectors/select-flashing-abort-controller" +import { setFlashingProcessState } from "./set-flashing-process-state/set-flashing-process-state.action" +import { FlashingProcessState } from "../constants" export const abortMscFlashing = createAsyncThunk< void, - undefined, + { reason?: Extract } | undefined, { state: ReduxRootState } ->(ActionName.MscFlashingAbort, async (_, { getState }) => { - const abortController = selectFlashingAbortController(getState()) +>( + ActionName.MscFlashingAbort, + async ({ reason } = {}, { dispatch, getState }) => { + const abortController = selectFlashingAbortController(getState()) - abortController?.abort?.() + abortController?.abort?.() - return -}) + if (reason) { + dispatch(setFlashingProcessState(reason)) + } + + return + } +) diff --git a/libs/msc-flash/msc-flash-harmony/src/lib/constants/flashing-process-state.enum.ts b/libs/msc-flash/msc-flash-harmony/src/lib/constants/flashing-process-state.enum.ts index 1cd572fbe1..facbf15a38 100644 --- a/libs/msc-flash/msc-flash-harmony/src/lib/constants/flashing-process-state.enum.ts +++ b/libs/msc-flash/msc-flash-harmony/src/lib/constants/flashing-process-state.enum.ts @@ -12,5 +12,6 @@ export enum FlashingProcessState { TerminalOpened = "terminal-opened", Restarting = "restarting-device", Completed = "completed", + Canceled = "canceled", Failed = "failed", } diff --git a/libs/msc-flash/msc-flash-harmony/src/lib/services/flash-msc-device.service.ts b/libs/msc-flash/msc-flash-harmony/src/lib/services/flash-msc-device.service.ts index 72171778a5..4d86960eca 100644 --- a/libs/msc-flash/msc-flash-harmony/src/lib/services/flash-msc-device.service.ts +++ b/libs/msc-flash/msc-flash-harmony/src/lib/services/flash-msc-device.service.ts @@ -124,12 +124,9 @@ const startFlashingProcess = async ( await deviceFlash.waitForFlashCompletion({ signal: abortController.signal }) dispatch(setFlashingProcessState(FlashingProcessState.Restarting)) - // TODO: for mac - to check - // dispatch(setFlashingProcessState(FlashingProcessState.Completed)) - await removeDownloadedMscFiles() - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (error: any) { - throw new Error(`Flash process failed with error: ${error}`) + await removeDownloadedMscFiles() + } catch (error) { + throw new Error(`Flash process failed with error: ${JSON.stringify(error)}`) } } diff --git a/libs/msc-flash/msc-flash-harmony/src/lib/ui/mac-terminal-info-modal/mac-terminal-info-modal.component.tsx b/libs/msc-flash/msc-flash-harmony/src/lib/ui/mac-terminal-info-modal/mac-terminal-info-modal.component.tsx index 5a39355616..5582e12570 100644 --- a/libs/msc-flash/msc-flash-harmony/src/lib/ui/mac-terminal-info-modal/mac-terminal-info-modal.component.tsx +++ b/libs/msc-flash/msc-flash-harmony/src/lib/ui/mac-terminal-info-modal/mac-terminal-info-modal.component.tsx @@ -57,7 +57,6 @@ export const MacTerminalInfoModal: FunctionComponent< closeable={true} closeButton={false} closeModal={onClose} - onClose={onClose} > diff --git a/libs/msc-flash/msc-flash-harmony/src/lib/ui/recovery-mode.tsx b/libs/msc-flash/msc-flash-harmony/src/lib/ui/recovery-mode.tsx index b46b30cc2b..cf0a3fcc6f 100644 --- a/libs/msc-flash/msc-flash-harmony/src/lib/ui/recovery-mode.tsx +++ b/libs/msc-flash/msc-flash-harmony/src/lib/ui/recovery-mode.tsx @@ -27,7 +27,7 @@ import { FlashingProcessState } from "../constants" import theme from "Core/core/styles/theming/theme" import { RestartingDeviceModal } from "./restarting-device-modal/restarting-device-modal.component" import { ErrorHandlingModal } from "./error-handling-modal/error-handling-modal.component" -import { setFlashingProcessState } from "../actions" +import { abortMscFlashing, setFlashingProcessState } from "../actions" import { MacTerminalInfoModal } from "./mac-terminal-info-modal/mac-terminal-info-modal.component" const messages = defineMessages({ @@ -145,7 +145,7 @@ const RecoveryModeUI: FunctionComponent = () => { } const macTerminalInfoCloseHandler = (): void => { - dispatch(setFlashingProcessState(FlashingProcessState.Completed)) + dispatch(abortMscFlashing({ reason: FlashingProcessState.Canceled })) } return (