Vliu put datasource in store (#1610)

* Move datasource from global store object to form_data

* Moved datasource_id  and datasource_name to form_data

* Refetch defaultFormData when switching datasource

* Fixed js tests
This commit is contained in:
vera-liu
2016-11-17 09:26:25 -08:00
committed by GitHub
parent ab5da5ba28
commit 4f7f437527
9 changed files with 76 additions and 48 deletions

View File

@@ -1,3 +1,4 @@
import { defaultFormData } from '../stores/store';
import * as actions from '../actions/exploreActions';
import { addToArr, removeFromArr, alterInArr } from '../../../utils/reducerUtils';
@@ -47,9 +48,15 @@ export const exploreReducer = function (state, action) {
return alterInArr(state, 'filters', action.filter, { value: action.value });
},
[actions.SET_FIELD_VALUE]() {
const newFormData = Object.assign({}, state.viz.form_data);
const newFormData = action.key === 'datasource' ?
defaultFormData(state.viz.form_data.viz_type) : Object.assign({}, state.viz.form_data);
if (action.key === 'datasource') {
newFormData.datasource_name = action.label;
newFormData.slice_id = state.viz.form_data.slice_id;
newFormData.slice_name = state.viz.form_data.slice_name;
newFormData.viz_type = state.viz.form_data.viz_type;
}
newFormData[action.key] = action.value ? action.value : (!state.viz.form_data[action.key]);
return Object.assign(
{},
state,