From 1e1f8015d9597edc1744f425ddfb67e23beaf877 Mon Sep 17 00:00:00 2001 From: MateuszMudita <165778944+MateuszMudita@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:38:36 +0100 Subject: [PATCH 1/2] [CP-3276] Trigger reload of all entities (#2219) --- .../entities/entities-metadata.validator.ts | 1 + libs/generic-view/store/src/index.ts | 1 + .../store/src/lib/action-names.ts | 1 + .../src/lib/backup/restore-backup.action.ts | 9 ++++ .../data-migration/transfer-migration-data.ts | 17 +++++++ ...esh-entities-if-metadata-changed.action.ts | 46 +++++++++++++++++++ .../start-contacts-import-to-device.ts | 8 ++++ 7 files changed, 83 insertions(+) create mode 100644 libs/generic-view/store/src/lib/entities/refresh-entities-if-metadata-changed.action.ts diff --git a/libs/device/models/src/lib/entities/entities-metadata.validator.ts b/libs/device/models/src/lib/entities/entities-metadata.validator.ts index 826bbe4ba7..86aac61b90 100644 --- a/libs/device/models/src/lib/entities/entities-metadata.validator.ts +++ b/libs/device/models/src/lib/entities/entities-metadata.validator.ts @@ -7,6 +7,7 @@ import { z } from "zod" export const entitiesMetadataValidator = z.object({ totalEntities: z.number().nonnegative(), + uniqueKey: z.string().optional(), }) export type EntitiesMetadata = z.infer diff --git a/libs/generic-view/store/src/index.ts b/libs/generic-view/store/src/index.ts index f9a8c48530..91df371b0c 100644 --- a/libs/generic-view/store/src/index.ts +++ b/libs/generic-view/store/src/index.ts @@ -52,6 +52,7 @@ export * from "./lib/entities/get-entities-metadata.action" export * from "./lib/entities/delete-entities-data.action" export * from "./lib/entities/create-entity-data.action" export * from "./lib/entities/update-entity-data.action" +export * from "./lib/entities/refresh-entities-if-metadata-changed.action" export * from "./lib/data-migration/reducer" export * from "./lib/data-migration/actions" diff --git a/libs/generic-view/store/src/lib/action-names.ts b/libs/generic-view/store/src/lib/action-names.ts index 0c559870fc..3e59c504d2 100644 --- a/libs/generic-view/store/src/lib/action-names.ts +++ b/libs/generic-view/store/src/lib/action-names.ts @@ -109,4 +109,5 @@ export enum ActionName { DeleteEntityData = "entities/delete-entity-data", CreateEntityData = "entities/create-entity-data", UpdateEntityData = "entities/update-entity-data", + RefreshEntitiesIfMetadataChanged = "entities/refresh-entities-if-metadata-changed", } diff --git a/libs/generic-view/store/src/lib/backup/restore-backup.action.ts b/libs/generic-view/store/src/lib/backup/restore-backup.action.ts index f1b6d61612..5a08e441f1 100644 --- a/libs/generic-view/store/src/lib/backup/restore-backup.action.ts +++ b/libs/generic-view/store/src/lib/backup/restore-backup.action.ts @@ -21,6 +21,7 @@ import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-i import { setRestoreProcessFileStatus, setRestoreProcessStatus } from "./actions" import { BackupProcessFileStatus, RestoreProcessStatus } from "./backup.types" import { delay } from "shared/utils" +import { refreshEntitiesIfMetadataChanged } from "../entities/refresh-entities-if-metadata-changed.action" export const restoreBackup = createAsyncThunk< undefined, @@ -221,6 +222,14 @@ export const restoreBackup = createAsyncThunk< return rejectWithValue(undefined) } dispatch(setRestoreProcessStatus({ status: RestoreProcessStatus.Done })) + + await dispatch( + refreshEntitiesIfMetadataChanged({ + deviceId: deviceId, + entitiesType: "contacts", + }) + ) + return undefined } ) 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 a91b3dd3f3..2a412f1422 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 @@ -26,6 +26,8 @@ import { removeDirectory } from "system-utils/feature" import { DataMigrationStatus } from "./reducer" import { clearMigrationData } from "./clear-migration-data" import { pureToUnifiedMessage } from "./data-migration-mappers/pure-to-unified-message" +import { refreshEntitiesIfMetadataChanged } from "../entities/refresh-entities-if-metadata-changed.action" +import { selectActiveApiDeviceId } from "../selectors" export const transferMigrationData = createAsyncThunk< void, @@ -56,6 +58,12 @@ export const transferMigrationData = createAsyncThunk< return rejectWithValue(undefined) } + const deviceId = selectActiveApiDeviceId(getState()) + + if (!deviceId) { + return handleError("Device not found") + } + const sourceDeviceId = dataMigration.sourceDevice if (!sourceDeviceId) { return handleError("Source device not selected") @@ -173,6 +181,15 @@ export const transferMigrationData = createAsyncThunk< await delay() + if (domainsData.some((obj) => obj.domain === "contacts-v1")) { + await dispatch( + refreshEntitiesIfMetadataChanged({ + deviceId: deviceId, + entitiesType: "contacts", + }) + ) + } + dispatch(setDataMigrationStatus(DataMigrationStatus.Completed)) return diff --git a/libs/generic-view/store/src/lib/entities/refresh-entities-if-metadata-changed.action.ts b/libs/generic-view/store/src/lib/entities/refresh-entities-if-metadata-changed.action.ts new file mode 100644 index 0000000000..b6775541f1 --- /dev/null +++ b/libs/generic-view/store/src/lib/entities/refresh-entities-if-metadata-changed.action.ts @@ -0,0 +1,46 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createAsyncThunk } from "@reduxjs/toolkit" +import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { ActionName } from "../action-names" +import { getEntitiesMetadataAction } from "./get-entities-metadata.action" +import { selectEntitiesMetadata } from "../selectors" +import { getEntitiesDataAction } from "./get-entities-data.action" +import { EntitiesMetadata } from "Libs/device/models/src" + +export const refreshEntitiesIfMetadataChanged = createAsyncThunk< + void, + { deviceId: string; entitiesType: string }, + { state: ReduxRootState } +>( + ActionName.RefreshEntitiesIfMetadataChanged, + async ( + { deviceId, entitiesType }, + { dispatch, getState, rejectWithValue } + ) => { + if (!deviceId) { + return rejectWithValue(undefined) + } + + const currentMetadata = selectEntitiesMetadata(getState(), { + deviceId, + entitiesType, + }) + + const metadata = await dispatch( + getEntitiesMetadataAction({ deviceId, entitiesType }) + ) + + if ( + currentMetadata?.uniqueKey !== + (metadata.payload as EntitiesMetadata)?.uniqueKey + ) { + dispatch(getEntitiesDataAction({ deviceId, entitiesType })) + } + + return + } +) diff --git a/libs/generic-view/store/src/lib/imports/start-contacts-import-to-device.ts b/libs/generic-view/store/src/lib/imports/start-contacts-import-to-device.ts index 9680ef2264..d729d16935 100644 --- a/libs/generic-view/store/src/lib/imports/start-contacts-import-to-device.ts +++ b/libs/generic-view/store/src/lib/imports/start-contacts-import-to-device.ts @@ -23,6 +23,7 @@ import { sendFile } from "../file-transfer/send-file.action" import { selectActiveApiDeviceId } from "../selectors" import { setImportProcessFileStatus, setImportProcessStatus } from "./actions" import { delay } from "shared/utils" +import { refreshEntitiesIfMetadataChanged } from "../entities/refresh-entities-if-metadata-changed.action" export const startImportToDevice = createAsyncThunk< undefined, @@ -254,6 +255,13 @@ export const startImportToDevice = createAsyncThunk< return rejectWithValue(undefined) } + await dispatch( + refreshEntitiesIfMetadataChanged({ + deviceId: deviceId, + entitiesType: "contacts", + }) + ) + return undefined } ) From 106f4b5df4b080e21e5272d378ba51bdbec14f78 Mon Sep 17 00:00:00 2001 From: MateuszMudita <165778944+MateuszMudita@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:01:22 +0100 Subject: [PATCH 2/2] [CP-3351] Update copy for Harmony Recovery Complete modal (#2235) --- libs/core/__deprecated__/renderer/locales/default/en-US.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/core/__deprecated__/renderer/locales/default/en-US.json b/libs/core/__deprecated__/renderer/locales/default/en-US.json index 877c8d05b2..396d56691c 100644 --- a/libs/core/__deprecated__/renderer/locales/default/en-US.json +++ b/libs/core/__deprecated__/renderer/locales/default/en-US.json @@ -1045,5 +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.recoveryMode.modal.completed.description": "Hold down the light button on Harmony to turn it on when prompted." }