From 99b11589c917b24fa593db9967bb462f88dfdb5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kurczewski?= Date: Mon, 9 Dec 2024 10:59:11 +0100 Subject: [PATCH] [CP-2950] Changed data migration error messages while cancelling (#2217) --- .../renderer/locales/default/en-US.json | 26 +++-- .../is-data-migration-abort-due-to-detach.ts | 8 +- ...hould-skip-processing-for-detached-pure.ts | 1 + .../data-migration/process-pure-database.ts | 2 +- .../store/src/lib/data-migration/reducer.ts | 13 ++- .../data-migration/transfer-migration-data.ts | 2 + .../lib/selectors/data-migration-progress.ts | 10 +- .../data-migration-pure-transfer-finished.ts | 12 +++ .../store/src/lib/selectors/index.ts | 1 + .../components/transfer-cancelled-modal.tsx | 6 -- .../components/transfer-error-modal.tsx | 5 +- .../components/transfer-fail-message.tsx | 100 ++++-------------- .../data-migration/data-migration.tsx | 5 +- 13 files changed, 80 insertions(+), 111 deletions(-) create mode 100644 libs/generic-view/store/src/lib/selectors/data-migration-pure-transfer-finished.ts diff --git a/libs/core/__deprecated__/renderer/locales/default/en-US.json b/libs/core/__deprecated__/renderer/locales/default/en-US.json index 689dec04de..877c8d05b2 100644 --- a/libs/core/__deprecated__/renderer/locales/default/en-US.json +++ b/libs/core/__deprecated__/renderer/locales/default/en-US.json @@ -996,9 +996,6 @@ "module.genericViews.dataMigration.pureError.updateRequired": "Please update MuditaOS on your device to continue.", "module.genericViews.dataMigration.pureError.criticalBattery": "Please charge your Pure to start the transfer.", "module.genericViews.dataMigration.pureError.connection.title": "Data transfer failed", - "module.genericViews.dataMigration.transferError.title": "Data transfer failed", - "module.genericViews.dataMigration.transferError.partialChangesDescription": "We transferred some data before the process failed, but we didn't transfer these items:", - "module.genericViews.dataMigration.transferError.notEnoughSpace": "Your phone’s storage is full.", "module.genericViews.dataMigration.progress.title": "Transferring data", "module.genericViews.dataMigration.progress.description": "Please don't unplug your devices from your computer.", "module.genericViews.dataMigration.progress.cancelButtonLabel": "Cancel", @@ -1006,6 +1003,17 @@ "module.genericViews.dataMigration.success.title": "Data transfer complete", "module.genericViews.dataMigration.success.description": "We transferred your data successfully.\nIt's safe to use your devices again.", "module.genericViews.dataMigration.success.buttonLabel": "Ok", + "module.genericViews.dataMigration.cancelConfirm.title": "Cancel data transfer?", + "module.genericViews.dataMigration.cancelConfirm.description": "We’ll stop the transfer but some data may already be on your Kompakt.", + "module.genericViews.dataMigration.cancelConfirm.cancelButtonLabel": "Cancel transfer", + "module.genericViews.dataMigration.cancelConfirm.backButtonLabel": "Back", + "module.genericViews.dataMigration.cancelConfirm.progress.title": "Cancelling, please wait...", + "module.genericViews.dataMigration.cancelled.title": "Data transfer cancelled", + "module.genericViews.dataMigration.failure.title": "Data transfer failed", + "module.genericViews.dataMigration.failure.noChangesDescription": "We didn’t transfer any data.", + "module.genericViews.dataMigration.failure.partialChangesDescription": "Some data transferred, but you'll need to check Kompakt to see what's missing.", + "module.genericViews.dataMigration.failure.notEnoughSpace": "Your phone’s storage is full.", + "module.genericViews.dataMigration.failure.closeButtonLabel": "Close", "module.recoveryMode.harmony.title": "Recovery Mode", "module.recoveryMode.harmony.header": "Harmony is Ready for Recovery", "module.recoveryMode.harmony.description": "Please read the instructions carefully. Not following the instructions may void the\nwarranty!", @@ -1037,15 +1045,5 @@ "module.recoveryMode.modal.terminalInfo.step3": "3. Enter your computer password when prompted", "module.recoveryMode.modal.terminalInfo.step4": "4. Repeat your computer password when prompted", "module.recoveryMode.modal.completed.subtitle": "Recovery process complete", - "module.recoveryMode.modal.completed.description": "Harmony is in transport mode. Press the light button when \"ON\" and \"OFF\" appear on harmony's screen.", - "module.genericViews.dataMigration.cancelConfirm.title": "Cancel data transfer?", - "module.genericViews.dataMigration.cancelConfirm.description": "We’ll stop the transfer but some data may already be on your Kompakt.", - "module.genericViews.dataMigration.cancelConfirm.cancelButtonLabel": "Cancel transfer", - "module.genericViews.dataMigration.cancelConfirm.backButtonLabel": "Back", - "module.genericViews.dataMigration.cancelConfirm.progress.title": "Cancelling, please wait...", - "module.genericViews.dataMigration.cancelled.title": "Data transfer cancelled", - "module.genericViews.dataMigration.cancelled.partialChangesDescription": "We transferred some data before you cancelled but we didn't transfer these items:", - "module.genericViews.dataMigration.failure.genericDescription": "The transfer process was interrupted.", - "module.genericViews.dataMigration.failure.noChangesDescription": "We didn’t transfer any data.", - "module.genericViews.dataMigration.failure.closeButtonLabel": "Close" + "module.recoveryMode.modal.completed.description": "Harmony is in transport mode. Press the light button when \"ON\" and \"OFF\" appear on harmony's screen." } diff --git a/libs/device-manager/feature/src/helpers/is-data-migration-abort-due-to-detach.ts b/libs/device-manager/feature/src/helpers/is-data-migration-abort-due-to-detach.ts index 568d20a618..ce42c77a55 100644 --- a/libs/device-manager/feature/src/helpers/is-data-migration-abort-due-to-detach.ts +++ b/libs/device-manager/feature/src/helpers/is-data-migration-abort-due-to-detach.ts @@ -6,7 +6,6 @@ import { DeviceBaseProperties } from "device-protocol/models" import { DataMigrationStatus } from "generic-view/store" - export const isDataMigrationAbortDueToDetach = ( events: DeviceBaseProperties[], migrationStatus: DataMigrationStatus, @@ -15,7 +14,12 @@ export const isDataMigrationAbortDueToDetach = ( ): boolean => { return events.some( (event) => - migrationStatus === DataMigrationStatus.DataTransferring && + ![ + DataMigrationStatus.Cancelled, + DataMigrationStatus.Failed, + DataMigrationStatus.Completed, + DataMigrationStatus.Idle, + ].includes(migrationStatus) && (sourceDevice?.serialNumber === event.serialNumber || targetDevice?.serialNumber === event.serialNumber) ) diff --git a/libs/device-manager/feature/src/helpers/should-skip-processing-for-detached-pure.ts b/libs/device-manager/feature/src/helpers/should-skip-processing-for-detached-pure.ts index c29032aa93..63d54b3f6e 100644 --- a/libs/device-manager/feature/src/helpers/should-skip-processing-for-detached-pure.ts +++ b/libs/device-manager/feature/src/helpers/should-skip-processing-for-detached-pure.ts @@ -18,6 +18,7 @@ export const shouldSkipProcessingForDetachedPure = ( [ DataMigrationStatus.PureDatabaseCreating, DataMigrationStatus.PureDatabaseIndexing, + DataMigrationStatus.DataReading, ].includes(migrationStatus) ) } diff --git a/libs/generic-view/store/src/lib/data-migration/process-pure-database.ts b/libs/generic-view/store/src/lib/data-migration/process-pure-database.ts index 8d5dc088bb..9628b0a6f5 100644 --- a/libs/generic-view/store/src/lib/data-migration/process-pure-database.ts +++ b/libs/generic-view/store/src/lib/data-migration/process-pure-database.ts @@ -90,7 +90,7 @@ export const processPureDatabase = createAsyncThunk< return rejectWithValue(undefined) } - dispatch(setDataMigrationStatus(DataMigrationStatus.DataTransferring)) + dispatch(setDataMigrationStatus(DataMigrationStatus.DataReading)) return } ) diff --git a/libs/generic-view/store/src/lib/data-migration/reducer.ts b/libs/generic-view/store/src/lib/data-migration/reducer.ts index d06cfea9a7..be2af1df47 100644 --- a/libs/generic-view/store/src/lib/data-migration/reducer.ts +++ b/libs/generic-view/store/src/lib/data-migration/reducer.ts @@ -25,6 +25,7 @@ export enum DataMigrationStatus { PureConnectionFailed = "PURE-CONNECTION-FAILED", PureDatabaseCreating = "PURE-DB-CREATING", PureDatabaseIndexing = "PURE-DB-INDEXING", + DataReading = "DATA-READING", DataTransferring = "DATA-TRANSFERRING", DataTransferred = "DATA-TRANSFERRED", Completed = "COMPLETED", @@ -40,12 +41,14 @@ interface DataMigrationState { pureDbTempDirectory?: string pureRestarting?: boolean pureBusy?: BaseDevice["serialNumber"] + pureTransferFinished: boolean } const initialState: DataMigrationState = { selectedFeatures: [], status: DataMigrationStatus.Idle, abortControllers: [], + pureTransferFinished: false, } export const dataMigrationReducer = createReducer(initialState, (builder) => { @@ -56,7 +59,15 @@ export const dataMigrationReducer = createReducer(initialState, (builder) => { state.selectedFeatures = action.payload }) builder.addCase(setDataMigrationStatus, (state, action) => { - state.status = action.payload + const status = action.payload + state.status = status + + if (status === DataMigrationStatus.DataTransferring) { + state.pureTransferFinished = true + } + if (status === DataMigrationStatus.Idle) { + state.pureTransferFinished = false + } }) builder.addCase(addDataMigrationAbortController, (state, action) => { state.abortControllers = [...state.abortControllers, action.payload] diff --git a/libs/generic-view/store/src/lib/data-migration/transfer-migration-data.ts b/libs/generic-view/store/src/lib/data-migration/transfer-migration-data.ts index 57db59e9bc..a91b3dd3f3 100644 --- a/libs/generic-view/store/src/lib/data-migration/transfer-migration-data.ts +++ b/libs/generic-view/store/src/lib/data-migration/transfer-migration-data.ts @@ -154,6 +154,8 @@ export const transferMigrationData = createAsyncThunk< } } + dispatch(setDataMigrationStatus(DataMigrationStatus.DataTransferring)) + if (signal.aborted) { return rejectWithValue(undefined) } diff --git a/libs/generic-view/store/src/lib/selectors/data-migration-progress.ts b/libs/generic-view/store/src/lib/selectors/data-migration-progress.ts index 2f35be5410..766cbb0acf 100644 --- a/libs/generic-view/store/src/lib/selectors/data-migration-progress.ts +++ b/libs/generic-view/store/src/lib/selectors/data-migration-progress.ts @@ -31,11 +31,17 @@ export const selectDataMigrationProgress = createSelector( } } + if (dataMigrationStatus === DataMigrationStatus.DataReading) { + return { + value: 40, + } + } + if (dataMigrationStatus === DataMigrationStatus.DataTransferring) { // Calculate overall progress as a weighted sum of data migration and data transfer progress - const dataTransferProgressFactor = (70 - 1) / 100 + const dataTransferProgressFactor = (60 - 1) / 100 const value = Math.floor( - 30 + dataTransferProgressFactor * dataTransferProgress + 40 + dataTransferProgressFactor * dataTransferProgress ) return { diff --git a/libs/generic-view/store/src/lib/selectors/data-migration-pure-transfer-finished.ts b/libs/generic-view/store/src/lib/selectors/data-migration-pure-transfer-finished.ts new file mode 100644 index 0000000000..27a9dc67d3 --- /dev/null +++ b/libs/generic-view/store/src/lib/selectors/data-migration-pure-transfer-finished.ts @@ -0,0 +1,12 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { createSelector } from "@reduxjs/toolkit" + +export const selectDataMigrationPureTransferFinished = createSelector( + (state: ReduxRootState) => state.dataMigration.pureTransferFinished, + (finished) => finished +) diff --git a/libs/generic-view/store/src/lib/selectors/index.ts b/libs/generic-view/store/src/lib/selectors/index.ts index 14cb7839cc..10d2638cc3 100644 --- a/libs/generic-view/store/src/lib/selectors/index.ts +++ b/libs/generic-view/store/src/lib/selectors/index.ts @@ -23,6 +23,7 @@ export * from "./data-migration-devices" export * from "./data-migration-features" export * from "./data-migration-status" export * from "./data-migration-progress" +export * from "./data-migration-pure-transfer-finished" export * from "./data-transfer-progress" export * from "./select-configured-devices" export * from "./select-devices" diff --git a/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-cancelled-modal.tsx b/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-cancelled-modal.tsx index 4a5c3f6c1e..585fa8fc6f 100644 --- a/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-cancelled-modal.tsx +++ b/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-cancelled-modal.tsx @@ -16,12 +16,6 @@ const messages = defineMessages({ title: { id: "module.genericViews.dataMigration.cancelled.title", }, - noChangesDescription: { - id: "module.genericViews.dataMigration.cancelled.noChanges.description", - }, - partialChangesDescription: { - id: "module.genericViews.dataMigration.cancelled.partialChanges.description", - }, closeButtonLabel: { id: "module.genericViews.dataMigration.failure.closeButtonLabel", }, diff --git a/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-error-modal.tsx b/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-error-modal.tsx index 076caaadf1..ad5d985ab2 100644 --- a/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-error-modal.tsx +++ b/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-error-modal.tsx @@ -12,10 +12,7 @@ import { TransferFailMessage } from "./transfer-fail-message" const messages = defineMessages({ title: { - id: "module.genericViews.dataMigration.transferError.title", - }, - description: { - id: "module.genericViews.dataMigration.transferError.genericDescription", + id: "module.genericViews.dataMigration.failure.title", }, closeButtonLabel: { id: "module.genericViews.dataMigration.failure.closeButtonLabel", diff --git a/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-fail-message.tsx b/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-fail-message.tsx index f8ac0a5476..38bf0b6e65 100644 --- a/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-fail-message.tsx +++ b/libs/generic-view/ui/src/lib/predefined/data-migration/components/transfer-fail-message.tsx @@ -3,107 +3,49 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import React, { useEffect, useMemo, useRef } from "react" +import React, { useMemo } from "react" import { defineMessages } from "react-intl" import { useSelector } from "react-redux" import { - selectDataMigrationFeatures, - selectDataMigrationStatus, - selectDataTransferDomains, + selectDataMigrationPureTransferFinished, selectDataTransferErrorType, } from "generic-view/store" import { intl } from "Core/__deprecated__/renderer/utils/intl" -import { isEmpty } from "lodash" import { ApiFileTransferError } from "device/models" import { FunctionComponent } from "Core/core/types/function-component.interface" const messages = defineMessages({ - genericDescription: { - id: "module.genericViews.dataMigration.failure.genericDescription", - }, noChangesDescription: { id: "module.genericViews.dataMigration.failure.noChangesDescription", }, - cancelledPartialChangesDescription: { - id: "module.genericViews.dataMigration.cancelled.partialChangesDescription", - }, - failedPartialChangesDescription: { - id: "module.genericViews.dataMigration.transferError.partialChangesDescription", + partialChangesDescription: { + id: "module.genericViews.dataMigration.failure.partialChangesDescription", }, notEnoughSpace: { - id: "module.genericViews.dataMigration.transferError.notEnoughSpace", + id: "module.genericViews.dataMigration.failure.notEnoughSpace", }, }) export const TransferFailMessage: FunctionComponent = () => { - const selectedFeatures = useSelector(selectDataMigrationFeatures) - const transferDomains = useSelector(selectDataTransferDomains) - const transferDomainsRef = useRef() - const dataMigrationStatus = useSelector(selectDataMigrationStatus) + const partialChanges = useSelector(selectDataMigrationPureTransferFinished) const dataTransferErrorType = useSelector(selectDataTransferErrorType) - const description = useMemo(() => { - const domains = isEmpty(transferDomainsRef.current) - ? transferDomains - : transferDomainsRef.current - const transferredDomains = Object.entries(domains) - .filter(([, { status }]) => status === "FINISHED") - .map(([domain]) => domain) - const notTransferredFeatures = selectedFeatures.filter((feature) => - transferredDomains?.every((domain) => !domain.startsWith(feature)) - ) - + return useMemo(() => { const notEnoughSpace = dataTransferErrorType === ApiFileTransferError.NotEnoughSpace - if (notEnoughSpace && isEmpty(domains)) { - return ( -

- {intl.formatMessage(messages.notEnoughSpace)}{" "} - {intl.formatMessage(messages.noChangesDescription)} -

- ) - } - - if (notEnoughSpace || !isEmpty(transferredDomains)) { - return ( -
-

- {notEnoughSpace && ( - <>{intl.formatMessage(messages.notEnoughSpace)} - )} - {intl.formatMessage( - dataMigrationStatus === "CANCELLED" - ? messages.cancelledPartialChangesDescription - : messages.failedPartialChangesDescription - )} -

-
    - {notTransferredFeatures.map((feature) => ( -
  • - {intl.formatMessage({ - id: `module.genericViews.dataMigration.features.${feature}`, - })} -
  • - ))} -
-
- ) - } - - if (!isEmpty(domains) && isEmpty(transferredDomains)) { - return

{intl.formatMessage(messages.noChangesDescription)}

- } - - return

{intl.formatMessage(messages.genericDescription)}

- // eslint-disable-next-line react-hooks/exhaustive-deps - }, [dataMigrationStatus, selectedFeatures, transferDomains]) - - useEffect(() => { - if (isEmpty(transferDomainsRef.current) && !isEmpty(transferDomains)) { - transferDomainsRef.current = transferDomains - } - }, [transferDomains]) - - return description + return ( +

+ {notEnoughSpace && ( + <> + {intl.formatMessage(messages.notEnoughSpace)} +
+ + )} + {partialChanges + ? intl.formatMessage(messages.partialChangesDescription) + : intl.formatMessage(messages.noChangesDescription)} +

+ ) + }, [dataTransferErrorType, partialChanges]) } diff --git a/libs/generic-view/ui/src/lib/predefined/data-migration/data-migration.tsx b/libs/generic-view/ui/src/lib/predefined/data-migration/data-migration.tsx index 4271d443c8..237bc1912a 100644 --- a/libs/generic-view/ui/src/lib/predefined/data-migration/data-migration.tsx +++ b/libs/generic-view/ui/src/lib/predefined/data-migration/data-migration.tsx @@ -156,7 +156,7 @@ const DataMigrationUI: FunctionComponent = ({ case DataMigrationStatus.PureDatabaseIndexing: dispatch(setDataMigrationPureRestarting(false)) break - case DataMigrationStatus.DataTransferring: + case DataMigrationStatus.DataReading: startTransfer() break } @@ -239,9 +239,10 @@ const DataMigrationUI: FunctionComponent = ({ defaultOpened: modalOpened && [ - DataMigrationStatus.DataTransferring, DataMigrationStatus.PureDatabaseCreating, DataMigrationStatus.PureDatabaseIndexing, + DataMigrationStatus.DataReading, + DataMigrationStatus.DataTransferring, DataMigrationStatus.DataTransferred, ].includes(dataMigrationStatus), size: "small",