From 8b8a80045345bad8e24f8cbe33351f3013ed159c Mon Sep 17 00:00:00 2001 From: Matt Weiden <538456+mweiden@users.noreply.github.com> Date: Mon, 27 Jan 2020 08:29:41 -0800 Subject: [PATCH] Undo feature: fix case where previous state has no state filter (#1124) * Undo feature: fix case where previous state has no state filter Fixes https://github.com/chanzuckerberg/cellxgene/issues/1099 When the previous state that the undo feature is trying to roll back to has no filter state, merging javascript dictionaries result in keeping the current state filter, preventing the actionFilter from saving the new state. * Fix whitespace --- client/src/reducers/undoable.js | 2 ++ client/src/reducers/undoableConfig.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/client/src/reducers/undoable.js b/client/src/reducers/undoable.js index 803b74e0..be51cd23 100644 --- a/client/src/reducers/undoable.js +++ b/client/src/reducers/undoable.js @@ -85,6 +85,7 @@ const Undoable = (reducer, undoableKeys, options = {}) => { ); const newPast = [...past]; const newState = newPast.pop(); + const newStateFilterState = newState[filterStateKey]; const newFuture = push(future, currentUndoableState); const nextState = { ...currentState, @@ -93,6 +94,7 @@ const Undoable = (reducer, undoableKeys, options = {}) => { [futureKey]: newFuture, [pendingKey]: null }; + nextState[filterStateKey] = newStateFilterState; return nextState; } diff --git a/client/src/reducers/undoableConfig.js b/client/src/reducers/undoableConfig.js index d29017d4..e30a101a 100644 --- a/client/src/reducers/undoableConfig.js +++ b/client/src/reducers/undoableConfig.js @@ -170,6 +170,8 @@ const actionFilter = debug => (state, action, prevFilterState) => { } if ( debounceOnActions.has(actionType) && + prevFilterState !== undefined && + prevFilterState.prevAction !== undefined && shallowObjectEq(action, prevFilterState.prevAction) ) { return { [actionKey]: "skip", [stateKey]: filterState };