[WIP] [explorev2] Refactor filter into FieldSet (#1981)

* [explorev2] Refactor filter into FieldSet

* Fixed tests

* Added tests

* Modifications based on comments
This commit is contained in:
vera-liu
2017-01-24 13:32:40 -08:00
committed by GitHub
parent 2b7673ad5d
commit 1c338ba742
19 changed files with 274 additions and 324 deletions

View File

@@ -1,7 +1,6 @@
/* eslint camelcase: 0 */
import { defaultFormData } from '../stores/store';
import * as actions from '../actions/exploreActions';
import { addToArr, removeFromArr, alterInArr } from '../../../utils/reducerUtils';
import { now } from '../../modules/dates';
import { getExploreUrl } from '../exploreUtils';
@@ -41,37 +40,6 @@ export const exploreReducer = function (state, action) {
[actions.SET_DATASOURCE]() {
return Object.assign({}, state, { datasource: action.datasource });
},
[actions.SET_FILTER_COLUMN_OPTS]() {
return Object.assign({}, state, { filterColumnOpts: action.filterColumnOpts });
},
[actions.ADD_FILTER]() {
const newFormData = addToArr(state.viz.form_data, 'filters', action.filter);
const newState = Object.assign(
{},
state,
{ viz: Object.assign({}, state.viz, { form_data: newFormData }) }
);
return newState;
},
[actions.REMOVE_FILTER]() {
const newFormData = removeFromArr(state.viz.form_data, 'filters', action.filter);
return Object.assign(
{},
state,
{ viz: Object.assign({}, state.viz, { form_data: newFormData }) }
);
},
[actions.CHANGE_FILTER]() {
const changes = {};
changes[action.field] = action.value;
const newFormData = alterInArr(
state.viz.form_data, 'filters', action.filter, changes);
return Object.assign(
{},
state,
{ viz: Object.assign({}, state.viz, { form_data: newFormData }) }
);
},
[actions.SET_FIELD_VALUE]() {
let newFormData = Object.assign({}, state.viz.form_data);
if (action.fieldName === 'datasource') {