From 3fb83afa208509250aae511453e93c6b34024755 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Wed, 29 May 2024 18:37:22 +0200 Subject: [PATCH] Fix seafront group renaming local storage issue with redux persist migration --- frontend/src/store/migrations.ts | 6 ++++++ frontend/src/store/reducers.ts | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 frontend/src/store/migrations.ts diff --git a/frontend/src/store/migrations.ts b/frontend/src/store/migrations.ts new file mode 100644 index 0000000000..fb4b201112 --- /dev/null +++ b/frontend/src/store/migrations.ts @@ -0,0 +1,6 @@ +export const MAIN_PERSISTOR_MISSION_MIGRATIONS = { + 0: state => ({ + ...state, + listSeafrontGroup: state.listSeafrontGroup === 'ALL_SEAFRONT_GROUP' ? 'ALL' : state.listSeafrontGroup + }) +} diff --git a/frontend/src/store/reducers.ts b/frontend/src/store/reducers.ts index 0e766a8c65..3660e2b15f 100644 --- a/frontend/src/store/reducers.ts +++ b/frontend/src/store/reducers.ts @@ -1,8 +1,10 @@ import { drawReducer } from '@features/Draw/slice' +import createMigrate from 'redux-persist/es/createMigrate' import persistReducer from 'redux-persist/es/persistReducer' import autoMergeLevel2 from 'redux-persist/es/stateReconciler/autoMergeLevel2' import storage from 'redux-persist/es/storage' // LocalStorage +import { MAIN_PERSISTOR_MISSION_MIGRATIONS } from './migrations' import { monitorenvApi, monitorfishApi, monitorfishLightApi, monitorfishPublicApi } from '../api/api' import { beaconMalfunctionReducer } from '../domain/shared_slices/BeaconMalfunction' import { controlReducer } from '../domain/shared_slices/Control' @@ -91,7 +93,9 @@ export const mainReducer = { ...getCommonPersistReducerConfig('mainPersistorMission', [ 'listFilterValues', 'listSeafrontGroup' - ]) + ]), + migrate: createMigrate(MAIN_PERSISTOR_MISSION_MIGRATIONS), + version: 0 }, missionListReducer ),