Avoid persisting the selected action between sessions (#1122)

* Avoid persisting the selected action between sessions

* Create giant-oranges-report.md
This commit is contained in:
Nathan Bierema 2022-04-03 18:05:14 -04:00 committed by GitHub
parent 14e4178d59
commit ab3c0e29dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,7 @@
---
'@redux-devtools/app': patch
'@redux-devtools/core': patch
'remotedev-redux-devtools-extension': patch
---
Avoid persisting the selected action index between sessions

View File

@ -1,5 +1,6 @@
import { SchemeName, ThemeName } from '@redux-devtools/ui';
import { AuthStates, States } from 'socketcluster-client/lib/scclientsocket';
import { REHYDRATE } from 'redux-persist';
import {
CHANGE_SECTION,
CHANGE_THEME,
@ -559,6 +560,11 @@ export interface ErrorAction {
payload: string;
}
interface ReduxPersistRehydrateAction {
type: typeof REHYDRATE;
payload: unknown;
}
export type StoreActionWithoutUpdateStateOrLiftedAction =
| ChangeSectionAction
| ChangeThemeAction
@ -594,7 +600,8 @@ export type StoreActionWithoutUpdateStateOrLiftedAction =
| UpdateReportsAction
| GetReportError
| GetReportSuccess
| ErrorAction;
| ErrorAction
| ReduxPersistRehydrateAction;
export type StoreActionWithoutUpdateState =
| StoreActionWithoutUpdateStateOrLiftedAction

View File

@ -1,3 +1,4 @@
import { REHYDRATE } from 'redux-persist';
import {
MONITOR_ACTION,
SELECT_MONITOR,
@ -93,6 +94,31 @@ export function monitor(
...state,
dispatcherIsOpen: !state.dispatcherIsOpen,
};
case REHYDRATE: {
const rehydratedState = action.payload as
| {
readonly monitor: MonitorState;
}
| undefined;
if (!rehydratedState) return state;
if (
rehydratedState.monitor.monitorState &&
(typeof rehydratedState.monitor.monitorState.selectedActionId ===
'number' ||
typeof rehydratedState.monitor.monitorState.startActionId ===
'number')
) {
return {
...rehydratedState.monitor,
monitorState: {
...rehydratedState.monitor.monitorState,
selectedActionId: null,
startActionId: null,
},
};
}
return rehydratedState.monitor;
}
default:
return state;
}