From 1522d3fbaaf1a317a59bb7f9ae6dd69a35c4c822 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Fri, 13 Sep 2019 10:36:53 -0700 Subject: [PATCH] fix: initialize control state for inline control config object (#8221) --- superset/assets/src/explore/controlUtils.js | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/superset/assets/src/explore/controlUtils.js b/superset/assets/src/explore/controlUtils.js index d203bd9e50..0c80a04f30 100644 --- a/superset/assets/src/explore/controlUtils.js +++ b/superset/assets/src/explore/controlUtils.js @@ -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 ( @@ -113,11 +113,8 @@ 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') { @@ -125,12 +122,14 @@ export function getControlState(controlKey, vizType, state, value) { } // 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) { @@ -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]); } } }),