kgabryje commented on a change in pull request #18569:
URL: https://github.com/apache/superset/pull/18569#discussion_r801582061



##########
File path: superset-frontend/src/explore/reducers/exploreReducer.js
##########
@@ -236,7 +237,46 @@ export default function exploreReducer(state = {}, action) 
{
         sliceName: action.slice.slice_name ?? state.sliceName,
       };
     },
+    [actions.SET_TIME_FORMATTED_COLUMN]() {
+      const newTimeFormattedColumns = { ...state.timeFormattedColumns };
+      const { datasourceId, columnName } = action;
+
+      if (Array.isArray(newTimeFormattedColumns[action.datasourceId])) {
+        newTimeFormattedColumns[datasourceId] = [
+          ...newTimeFormattedColumns[datasourceId],
+          columnName,
+        ];
+      } else {
+        newTimeFormattedColumns[datasourceId] = [columnName];
+      }
+      setItem(
+        LocalStorageKeys.explore__data_table_time_formatted_columns,
+        newTimeFormattedColumns,
+      );
+      return { ...state, timeFormattedColumns: newTimeFormattedColumns };
+    },
+    [actions.UNSET_TIME_FORMATTED_COLUMN]() {
+      const newTimeFormattedColumns = { ...state.timeFormattedColumns };
+      const { datasourceId, columnIndex } = action;
+
+      if (Array.isArray(newTimeFormattedColumns[datasourceId])) {
+        newTimeFormattedColumns[datasourceId] = [
+          ...newTimeFormattedColumns[datasourceId].slice(0, columnIndex),
+          ...newTimeFormattedColumns[datasourceId].slice(columnIndex + 1),
+        ];
+
+        if (newTimeFormattedColumns[datasourceId].length === 0) {
+          delete newTimeFormattedColumns[datasourceId];
+        }

Review comment:
       Thanks for comments! According to [redux 
docs](https://redux.js.org/usage/structuring-reducers/immutable-update-patterns),
 we cannot mutate the state - only immutable operations like `slice` are 
allowed. Splice mutates the original array. Same goes for using `push` in your 
second comment.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to