Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Table chart column config issue #19841

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
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) {
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
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;
codemaster08240328 marked this conversation as resolved.
Show resolved Hide resolved
}

// 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