Skip to content

Commit

Permalink
Make reducer more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Feb 8, 2022
1 parent 9a77d01 commit 618a3ef
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions superset-frontend/src/explore/reducers/exploreReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,36 +238,34 @@ export default function exploreReducer(state = {}, action) {
};
},
[actions.SET_TIME_FORMATTED_COLUMN]() {
const newTimeFormattedColumns = { ...state.timeFormattedColumns };
const { datasourceId, columnName } = action;
const newTimeFormattedColumns = { ...state.timeFormattedColumns };
const newTimeFormattedColumnsForDatasource = ensureIsArray(
newTimeFormattedColumns[datasourceId],
).slice();

if (Array.isArray(newTimeFormattedColumns[action.datasourceId])) {
newTimeFormattedColumns[datasourceId] = [
...newTimeFormattedColumns[datasourceId],
columnName,
];
} else {
newTimeFormattedColumns[datasourceId] = [columnName];
}
newTimeFormattedColumnsForDatasource.push(columnName);
newTimeFormattedColumns[datasourceId] =
newTimeFormattedColumnsForDatasource;
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;
const newTimeFormattedColumns = { ...state.timeFormattedColumns };
const newTimeFormattedColumnsForDatasource = ensureIsArray(
newTimeFormattedColumns[datasourceId],
).slice();

if (Array.isArray(newTimeFormattedColumns[datasourceId])) {
newTimeFormattedColumns[datasourceId] = [
...newTimeFormattedColumns[datasourceId].slice(0, columnIndex),
...newTimeFormattedColumns[datasourceId].slice(columnIndex + 1),
];
newTimeFormattedColumnsForDatasource.splice(columnIndex, 1);
newTimeFormattedColumns[datasourceId] =
newTimeFormattedColumnsForDatasource;

if (newTimeFormattedColumns[datasourceId].length === 0) {
delete newTimeFormattedColumns[datasourceId];
}
if (newTimeFormattedColumnsForDatasource.length === 0) {
delete newTimeFormattedColumns[datasourceId];
}
setItem(
LocalStorageKeys.explore__data_table_time_formatted_columns,
Expand Down

0 comments on commit 618a3ef

Please sign in to comment.