mirror of
https://github.com/apache/superset.git
synced 2026-04-24 02:25:13 +00:00
Put formData in store (#1281)
* Put formData in store * Reform actions and reducers * Maded modifications based on comments:
This commit is contained in:
@@ -2,71 +2,50 @@ import { defaultFormData, defaultOpts } from '../stores/store';
|
||||
import * as actions from '../actions/exploreActions';
|
||||
import { addToArr, removeFromArr, alterInArr } from '../../../utils/reducerUtils';
|
||||
|
||||
const setFormInViz = function (state, action) {
|
||||
const newFormData = Object.assign({}, state);
|
||||
newFormData[action.key] = action.value;
|
||||
return newFormData;
|
||||
};
|
||||
|
||||
const setVizInState = function (state, action) {
|
||||
switch (action.type) {
|
||||
case actions.SET_FORM_DATA:
|
||||
return {
|
||||
...state,
|
||||
formData: setFormInViz(state.formData, action),
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export const exploreReducer = function (state, action) {
|
||||
const actionHandlers = {
|
||||
[actions.SET_DATASOURCE]() {
|
||||
return Object.assign({}, state, { datasourceId: action.datasourceId });
|
||||
},
|
||||
[actions.SET_VIZTYPE]() {
|
||||
return Object.assign({}, state, { vizType: action.vizType });
|
||||
},
|
||||
[actions.SET_TIME_COLUMN_OPTS]() {
|
||||
return Object.assign({}, state, { timeColumnOpts: action.timeColumnOpts });
|
||||
},
|
||||
[actions.SET_TIME_GRAIN_OPTS]() {
|
||||
return Object.assign({}, state, { timeGrainOpts: action.timeGrainOpts });
|
||||
},
|
||||
[actions.SET_TIME_COLUMN]() {
|
||||
return Object.assign({}, state, { timeColumn: action.timeColumn });
|
||||
},
|
||||
[actions.SET_TIME_GRAIN]() {
|
||||
return Object.assign({}, state, { timeGrain: action.timeGrain });
|
||||
},
|
||||
[actions.SET_SINCE]() {
|
||||
return Object.assign({}, state, { since: action.since });
|
||||
},
|
||||
[actions.SET_UNTIL]() {
|
||||
return Object.assign({}, state, { until: action.until });
|
||||
},
|
||||
[actions.SET_GROUPBY_COLUMN_OPTS]() {
|
||||
return Object.assign({}, state, { groupByColumnOpts: action.groupByColumnOpts });
|
||||
},
|
||||
[actions.SET_GROUPBY_COLUMNS]() {
|
||||
return Object.assign({}, state, { groupByColumns: action.groupByColumns });
|
||||
},
|
||||
[actions.SET_METRICS_OPTS]() {
|
||||
return Object.assign({}, state, { metricsOpts: action.metricsOpts });
|
||||
},
|
||||
[actions.SET_METRICS]() {
|
||||
return Object.assign({}, state, { metrics: action.metrics });
|
||||
},
|
||||
[actions.SET_COLUMN_OPTS]() {
|
||||
return Object.assign({}, state, { columnOpts: action.columnOpts });
|
||||
},
|
||||
[actions.SET_NOT_GROUPBY_COLUMNS]() {
|
||||
return Object.assign({}, state, { columns: action.columns });
|
||||
},
|
||||
[actions.SET_ORDERING_OPTS]() {
|
||||
return Object.assign({}, state, { orderingOpts: action.orderingOpts });
|
||||
},
|
||||
[actions.SET_ORDERINGS]() {
|
||||
return Object.assign({}, state, { orderings: action.orderings });
|
||||
},
|
||||
[actions.SET_TIME_STAMP_FORMAT]() {
|
||||
return Object.assign({}, state, { timeStampFormat: action.timeStampFormat });
|
||||
},
|
||||
[actions.SET_ROW_LIMIT]() {
|
||||
return Object.assign({}, state, { rowLimit: action.rowLimit });
|
||||
},
|
||||
[actions.TOGGLE_SEARCHBOX]() {
|
||||
return Object.assign({}, state, { searchBox: action.searchBox });
|
||||
},
|
||||
[actions.SET_WHERE_CLAUSE]() {
|
||||
return Object.assign({}, state, { whereClause: action.whereClause });
|
||||
},
|
||||
[actions.SET_HAVING_CLAUSE]() {
|
||||
return Object.assign({}, state, { havingClause: action.havingClause });
|
||||
},
|
||||
[actions.SET_FILTER_COLUMN_OPTS]() {
|
||||
return Object.assign({}, state, { filterColumnOpts: action.filterColumnOpts });
|
||||
},
|
||||
@@ -94,6 +73,12 @@ export const exploreReducer = function (state, action) {
|
||||
[actions.SET_DATASOURCE_TYPE]() {
|
||||
return Object.assign({}, state, { datasourceType: action.datasourceType });
|
||||
},
|
||||
[actions.SET_FORM_DATA]() {
|
||||
return {
|
||||
...state,
|
||||
viz: setVizInState(state.viz, action),
|
||||
};
|
||||
},
|
||||
};
|
||||
if (action.type in actionHandlers) {
|
||||
return actionHandlers[action.type]();
|
||||
|
||||
Reference in New Issue
Block a user