Skip to content

Commit

Permalink
fix: Table chart column config issue (#19841)
Browse files Browse the repository at this point in the history
* Fix table chart column config issue

* resolve comment
  • Loading branch information
codemaster08240328 authored May 10, 2022
1 parent 35db7fb commit 9376940
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion superset-frontend/src/explore/reducers/exploreReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,30 @@ export default function exploreReducer(state = {}, action) {
},
[actions.SET_FIELD_VALUE]() {
const new_form_data = state.form_data;
const old_metrics_data = state.form_data.metrics;
const new_column_config = state.form_data.column_config;
const { controlName, value, validationErrors } = action;
new_form_data[controlName] = value;

const vizType = new_form_data.viz_type;

// if the controlName is metrics, and the metric column name is updated,
// need to update column config as well to keep the previou config.
if (controlName === 'metrics' && old_metrics_data && new_column_config) {
value.forEach((item, index) => {
if (
item.label !== old_metrics_data[index].label &&
!!new_column_config[old_metrics_data[index].label]
) {
new_column_config[item.label] =
new_column_config[old_metrics_data[index].label];

delete new_column_config[old_metrics_data[index].label];
}
});
new_form_data.column_config = new_column_config;
}

// Use the processed control config (with overrides and everything)
// if `controlName` does not existing in current controls,
const controlConfig =
Expand All @@ -148,9 +167,18 @@ export default function exploreReducer(state = {}, action) {
...getControlStateFromControlConfig(controlConfig, state, action.value),
};

const column_config = {
...state.controls.column_config,
...(new_column_config && { value: new_column_config }),
};

const newState = {
...state,
controls: { ...state.controls, [action.controlName]: control },
controls: {
...state.controls,
[controlName]: control,
...(controlName === 'metrics' && { column_config }),
},
};

const rerenderedControls = {};
Expand Down

0 comments on commit 9376940

Please sign in to comment.