Skip to content

Commit

Permalink
fix(explore): Prevent infinite rerenders when editing dataset (#22219)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored Nov 25, 2022
1 parent 9578a44 commit d1e576c
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions superset-frontend/src/explore/components/ControlPanelsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {

const prevState = usePrevious(props.exploreState);
const prevDatasource = usePrevious(props.exploreState.datasource);
const prevChartStatus = usePrevious(props.chart.chartStatus);

const [showDatasourceAlert, setShowDatasourceAlert] = useState(false);

Expand All @@ -277,40 +278,45 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
>(state => state.explore.controlsTransferred);

useEffect(() => {
let shouldUpdateControls = false;
const removeDatasourceWarningFromControl = (
value: JsonValue | undefined,
) => {
if (
typeof value === 'object' &&
isDefined(value) &&
'datasourceWarning' in value
'datasourceWarning' in value &&
value.datasourceWarning === true
) {
shouldUpdateControls = true;
return { ...value, datasourceWarning: false };
}
return value;
};
if (props.chart.chartStatus === 'success') {
if (
props.chart.chartStatus === 'success' &&
prevChartStatus !== 'success'
) {
controlsTransferred?.forEach(controlName => {
shouldUpdateControls = false;
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(
const alteredControls = Array.isArray(props.controls[controlName].value)
? ensureIsArray(props.controls[controlName].value)?.map(
removeDatasourceWarningFromControl,
)
: removeDatasourceWarningFromControl(
props.controls[controlName].value,
),
);
);
if (shouldUpdateControls) {
props.actions.setControlValue(controlName, alteredControls);
}
});
}
}, [
controlsTransferred,
prevChartStatus,
props.actions,
props.chart.chartStatus,
props.controls,
Expand Down

0 comments on commit d1e576c

Please sign in to comment.