mirror of
https://github.com/apache/superset.git
synced 2026-05-30 04:39:20 +00:00
refactor(explore): convert ControlPanelsContainer to typescript (#13221)
This commit is contained in:
@@ -18,13 +18,14 @@
|
||||
*/
|
||||
/* eslint camelcase: 0 */
|
||||
import { DYNAMIC_PLUGIN_CONTROLS_READY } from 'src/chart/chartAction';
|
||||
import { getControlsState } from '../store';
|
||||
import { DEFAULT_TIME_RANGE } from 'src/explore/constants';
|
||||
import { getControlsState } from 'src/explore/store';
|
||||
import {
|
||||
getControlConfig,
|
||||
getFormDataFromControls,
|
||||
getControlStateFromControlConfig,
|
||||
} from '../controlUtils';
|
||||
import * as actions from '../actions/exploreActions';
|
||||
} from 'src/explore/controlUtils';
|
||||
import * as actions from 'src/explore/actions/exploreActions';
|
||||
|
||||
export default function exploreReducer(state = {}, action) {
|
||||
const actionHandlers = {
|
||||
@@ -61,8 +62,38 @@ export default function exploreReducer(state = {}, action) {
|
||||
delete newFormData.time_grain_sqla;
|
||||
}
|
||||
}
|
||||
|
||||
const controls = { ...state.controls };
|
||||
if (
|
||||
action.datasource.id !== state.datasource.id ||
|
||||
action.datasource.type !== state.datasource.type
|
||||
) {
|
||||
// reset time range filter to default
|
||||
newFormData.time_range = DEFAULT_TIME_RANGE;
|
||||
|
||||
// reset control values for column/metric related controls
|
||||
Object.entries(controls).forEach(([controlName, controlState]) => {
|
||||
if (
|
||||
// for direct column select controls
|
||||
controlState.valueKey === 'column_name' ||
|
||||
// for all other controls
|
||||
'columns' in controlState
|
||||
) {
|
||||
// if a control use datasource columns, reset its value to `undefined`,
|
||||
// then `getControlsState` will pick up the default.
|
||||
// TODO: filter out only invalid columns and keep others
|
||||
controls[controlName] = {
|
||||
...controlState,
|
||||
value: undefined,
|
||||
};
|
||||
newFormData[controlName] = undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const newState = {
|
||||
...state,
|
||||
controls,
|
||||
datasource: action.datasource,
|
||||
datasource_id: action.datasource.id,
|
||||
datasource_type: action.datasource.type,
|
||||
@@ -85,12 +116,6 @@ export default function exploreReducer(state = {}, action) {
|
||||
datasources: action.datasources,
|
||||
};
|
||||
},
|
||||
[actions.REMOVE_CONTROL_PANEL_ALERT]() {
|
||||
return {
|
||||
...state,
|
||||
controlPanelAlert: null,
|
||||
};
|
||||
},
|
||||
[actions.SET_FIELD_VALUE]() {
|
||||
const new_form_data = state.form_data;
|
||||
const { controlName, value, validationErrors } = action;
|
||||
|
||||
Reference in New Issue
Block a user