Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(explore): Value undefined and Unhashable type errors #22207

Merged
merged 2 commits into from
Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions superset-frontend/src/explore/components/ControlPanelsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
SupersetTheme,
useTheme,
isDefined,
JsonValue,
} from '@superset-ui/core';
import {
ControlPanelSectionConfig,
Expand Down Expand Up @@ -276,21 +277,36 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
>(state => state.explore.controlsTransferred);

useEffect(() => {
const removeDatasourceWarningFromControl = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could we define this outside in a useCallback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but that wouldn't bring much value I think since we won't use it in any other place. I guess it's a style preference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I've tended to err on the side of just spraying useCallback everywhere, but I agree it's not really needed in trivial cases like this where 1) creating it is dirt cheap 2) it's not being used in a prop.

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,
),
);
}
});
}
}, [
Expand Down