From 1809d2b957394290cc55666b6e56c838fc8841c9 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Wed, 23 Nov 2022 20:45:10 +0100 Subject: [PATCH] fix(explore): Value undefined and Unhashable type errors (#22207) --- .../components/ControlPanelsContainer.tsx | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/superset-frontend/src/explore/components/ControlPanelsContainer.tsx b/superset-frontend/src/explore/components/ControlPanelsContainer.tsx index 7ed11a964b..0c235c3c35 100644 --- a/superset-frontend/src/explore/components/ControlPanelsContainer.tsx +++ b/superset-frontend/src/explore/components/ControlPanelsContainer.tsx @@ -37,6 +37,7 @@ import { SupersetTheme, useTheme, isDefined, + JsonValue, } from '@superset-ui/core'; import { ControlPanelSectionConfig, @@ -276,21 +277,36 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => { >(state => state.explore.controlsTransferred); useEffect(() => { + const removeDatasourceWarningFromControl = ( + value: JsonValue | undefined, + ) => { + if ( + typeof value === 'object' && + isDefined(value) && + 'datasourceWarning' in value + ) { + return { ...value, datasourceWarning: false }; + } + return value; + }; if (props.chart.chartStatus === 'success') { controlsTransferred?.forEach(controlName => { - const alteredControls = ensureIsArray( - props.controls[controlName].value, - ).map(value => { - if ( - typeof value === 'object' && - isDefined(value) && - 'datasourceWarning' in value - ) { - return { ...value, datasourceWarning: false }; - } - return value; - }); - props.actions.setControlValue(controlName, alteredControls); + if (!isDefined(props.controls[controlName])) { + return; + } + if (Array.isArray(props.controls[controlName].value)) { + const alteredControls = ensureIsArray( + props.controls[controlName].value, + )?.map(removeDatasourceWarningFromControl); + props.actions.setControlValue(controlName, alteredControls); + } else { + props.actions.setControlValue( + controlName, + removeDatasourceWarningFromControl( + props.controls[controlName].value, + ), + ); + } }); } }, [