mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
fix: initialize control state for inline control config object (#8221)
This commit is contained in:
parent
762edf430b
commit
1522d3fbaa
@ -91,7 +91,7 @@ export function applyMapStateToPropsToControl(control, state) {
|
|||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMissingChoice(controlKey, control) {
|
function handleMissingChoice(control) {
|
||||||
// If the value is not valid anymore based on choices, clear it
|
// If the value is not valid anymore based on choices, clear it
|
||||||
const value = control.value;
|
const value = control.value;
|
||||||
if (
|
if (
|
||||||
@ -113,11 +113,8 @@ function handleMissingChoice(controlKey, control) {
|
|||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getControlState(controlKey, vizType, state, value) {
|
export function getControlStateFromControlConfig(controlConfig, state, value) {
|
||||||
let controlValue = value;
|
const controlState = applyMapStateToPropsToControl({ ...controlConfig }, state);
|
||||||
const controlConfig = getControlConfig(controlKey, vizType);
|
|
||||||
let controlState = { ...controlConfig };
|
|
||||||
controlState = applyMapStateToPropsToControl(controlState, state);
|
|
||||||
|
|
||||||
// If default is a function, evaluate it
|
// If default is a function, evaluate it
|
||||||
if (typeof controlState.default === 'function') {
|
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 a choice control went from multi=false to true, wrap value in array
|
||||||
if (controlConfig.multi && value && !Array.isArray(value)) {
|
const controlValue = controlConfig.multi && value && !Array.isArray(value) ? [value] : value;
|
||||||
controlValue = [value];
|
controlState.value = typeof controlValue === 'undefined' ? controlState.default : controlValue;
|
||||||
}
|
|
||||||
controlState.value = controlValue === undefined ? controlState.default : controlValue;
|
return validateControl(handleMissingChoice(controlState));
|
||||||
controlState = handleMissingChoice(controlKey, controlState);
|
}
|
||||||
return validateControl(controlState);
|
|
||||||
|
export function getControlState(controlKey, vizType, state, value) {
|
||||||
|
return getControlStateFromControlConfig(getControlConfig(controlKey, vizType), state, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sectionsToRender(vizType, datasourceType) {
|
export function sectionsToRender(vizType, datasourceType) {
|
||||||
@ -169,7 +168,8 @@ export function getAllControlsState(vizType, datasourceType, state, formData) {
|
|||||||
controlsState[field] = getControlState(field, vizType, state, formData[field]);
|
controlsState[field] = getControlState(field, vizType, state, formData[field]);
|
||||||
} else if (field != null && typeof field === 'object') {
|
} else if (field != null && typeof field === 'object') {
|
||||||
if (field.config && field.name) {
|
if (field.config && field.name) {
|
||||||
controlsState[field.name] = { ...field.config };
|
const { config, name } = field;
|
||||||
|
controlsState[name] = getControlStateFromControlConfig(config, state, formData[name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user