Skip to content

Commit

Permalink
fix: initialize control state for inline control config object (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw authored Sep 13, 2019
1 parent 762edf4 commit 1522d3f
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions superset/assets/src/explore/controlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function applyMapStateToPropsToControl(control, state) {
return control;
}

function handleMissingChoice(controlKey, control) {
function handleMissingChoice(control) {
// If the value is not valid anymore based on choices, clear it
const value = control.value;
if (
Expand All @@ -113,24 +113,23 @@ function handleMissingChoice(controlKey, control) {
return control;
}

export function getControlState(controlKey, vizType, state, value) {
let controlValue = value;
const controlConfig = getControlConfig(controlKey, vizType);
let controlState = { ...controlConfig };
controlState = applyMapStateToPropsToControl(controlState, state);
export function getControlStateFromControlConfig(controlConfig, state, value) {
const controlState = applyMapStateToPropsToControl({ ...controlConfig }, state);

// If default is a function, evaluate it
if (typeof controlState.default === 'function') {
controlState.default = controlState.default(controlState);
}

// If a choice control went from multi=false to true, wrap value in array
if (controlConfig.multi && value && !Array.isArray(value)) {
controlValue = [value];
}
controlState.value = controlValue === undefined ? controlState.default : controlValue;
controlState = handleMissingChoice(controlKey, controlState);
return validateControl(controlState);
const controlValue = controlConfig.multi && value && !Array.isArray(value) ? [value] : value;
controlState.value = typeof controlValue === 'undefined' ? controlState.default : controlValue;

return validateControl(handleMissingChoice(controlState));
}

export function getControlState(controlKey, vizType, state, value) {
return getControlStateFromControlConfig(getControlConfig(controlKey, vizType), state, value);
}

export function sectionsToRender(vizType, datasourceType) {
Expand Down Expand Up @@ -169,7 +168,8 @@ export function getAllControlsState(vizType, datasourceType, state, formData) {
controlsState[field] = getControlState(field, vizType, state, formData[field]);
} else if (field != null && typeof field === 'object') {
if (field.config && field.name) {
controlsState[field.name] = { ...field.config };
const { config, name } = field;
controlsState[name] = getControlStateFromControlConfig(config, state, formData[name]);
}
}
}),
Expand Down

0 comments on commit 1522d3f

Please sign in to comment.