Skip to content

Commit

Permalink
[CP-2950] Changed data migration error messages while cancelling (#2217)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurczewski authored Dec 9, 2024
1 parent 1619404 commit 99b1158
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 111 deletions.
26 changes: 12 additions & 14 deletions libs/core/__deprecated__/renderer/locales/default/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -996,16 +996,24 @@
"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",
"module.genericViews.dataMigration.progress.genericMessage": "This might take a few minutes",
"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!",
Expand Down Expand Up @@ -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."
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { DeviceBaseProperties } from "device-protocol/models"
import { DataMigrationStatus } from "generic-view/store"


export const isDataMigrationAbortDueToDetach = (
events: DeviceBaseProperties[],
migrationStatus: DataMigrationStatus,
Expand All @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const shouldSkipProcessingForDetachedPure = (
[
DataMigrationStatus.PureDatabaseCreating,
DataMigrationStatus.PureDatabaseIndexing,
DataMigrationStatus.DataReading,
].includes(migrationStatus)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const processPureDatabase = createAsyncThunk<
return rejectWithValue(undefined)
}

dispatch(setDataMigrationStatus(DataMigrationStatus.DataTransferring))
dispatch(setDataMigrationStatus(DataMigrationStatus.DataReading))
return
}
)
13 changes: 12 additions & 1 deletion libs/generic-view/store/src/lib/data-migration/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) => {
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export const transferMigrationData = createAsyncThunk<
}
}

dispatch(setDataMigrationStatus(DataMigrationStatus.DataTransferring))

if (signal.aborted) {
return rejectWithValue(undefined)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
1 change: 1 addition & 0 deletions libs/generic-view/store/src/lib/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof transferDomains>()
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 (
<p>
{intl.formatMessage(messages.notEnoughSpace)}{" "}
{intl.formatMessage(messages.noChangesDescription)}
</p>
)
}

if (notEnoughSpace || !isEmpty(transferredDomains)) {
return (
<div>
<p style={{ marginBottom: "1.4rem" }}>
{notEnoughSpace && (
<>{intl.formatMessage(messages.notEnoughSpace)} </>
)}
{intl.formatMessage(
dataMigrationStatus === "CANCELLED"
? messages.cancelledPartialChangesDescription
: messages.failedPartialChangesDescription
)}
</p>
<ul>
{notTransferredFeatures.map((feature) => (
<li key={feature}>
{intl.formatMessage({
id: `module.genericViews.dataMigration.features.${feature}`,
})}
</li>
))}
</ul>
</div>
)
}

if (!isEmpty(domains) && isEmpty(transferredDomains)) {
return <p>{intl.formatMessage(messages.noChangesDescription)}</p>
}

return <p>{intl.formatMessage(messages.genericDescription)}</p>
// 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 (
<p>
{notEnoughSpace && (
<>
{intl.formatMessage(messages.notEnoughSpace)}
<br />
</>
)}
{partialChanges
? intl.formatMessage(messages.partialChangesDescription)
: intl.formatMessage(messages.noChangesDescription)}
</p>
)
}, [dataTransferErrorType, partialChanges])
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const DataMigrationUI: FunctionComponent<McDataMigrationConfig> = ({
case DataMigrationStatus.PureDatabaseIndexing:
dispatch(setDataMigrationPureRestarting(false))
break
case DataMigrationStatus.DataTransferring:
case DataMigrationStatus.DataReading:
startTransfer()
break
}
Expand Down Expand Up @@ -239,9 +239,10 @@ const DataMigrationUI: FunctionComponent<McDataMigrationConfig> = ({
defaultOpened:
modalOpened &&
[
DataMigrationStatus.DataTransferring,
DataMigrationStatus.PureDatabaseCreating,
DataMigrationStatus.PureDatabaseIndexing,
DataMigrationStatus.DataReading,
DataMigrationStatus.DataTransferring,
DataMigrationStatus.DataTransferred,
].includes(dataMigrationStatus),
size: "small",
Expand Down

0 comments on commit 99b1158

Please sign in to comment.