message: fix: initialize control state for inline control config object
diff: @@ -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];
  + const controlValue = controlConfig.multi && value && !Array.isArray(value) ? [value] : value;
  + controlState.value = typeof controlValue === 'undefined' ? controlState.default : controlValue;
  +
  + return validateControl(handleMissingChoice(controlState));
  }
  - controlState.value = controlValue === undefined ? controlState.default : controlValue;
  - 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) {
  @@ -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]);
  }
  }
  }),
  