Skip to content

Commit

Permalink
fix(explore): verified props is not updated (apache#31008)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored Nov 21, 2024
1 parent 90572be commit 9e5b568
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { JsonArray, JsonValue, t } from '@superset-ui/core';
import { ControlProps } from 'src/explore/components/Control';
import builtInControlComponents from 'src/explore/components/controls';
import useEffectEvent from 'src/hooks/useEffectEvent';

/**
* Full control component map.
Expand Down Expand Up @@ -72,7 +73,7 @@ export type AsyncVerify = (
* Whether the extra props will update the original props.
*/
function hasUpdates(
props: ControlPropsWithExtras,
props: Partial<ControlPropsWithExtras>,
newProps: ExtraControlProps,
) {
return (
Expand Down Expand Up @@ -165,17 +166,17 @@ export default function withAsyncVerification({
[basicOnChange, otherProps, verifiedProps],
);

useEffect(() => {
if (needAsyncVerification && verify) {
const verifyProps = useEffectEvent(
(verifyFunc: AsyncVerify, props: typeof otherProps) => {
if (showLoadingState) {
setIsLoading(true);
}
verify(otherProps)
verifyFunc(props)
.then(updatedProps => {
if (showLoadingState) {
setIsLoading(false);
}
if (updatedProps && hasUpdates(otherProps, updatedProps)) {
if (updatedProps && hasUpdates(verifiedProps, updatedProps)) {
setVerifiedProps({
// save isLoading in combination with other props to avoid
// rendering twice.
Expand All @@ -198,14 +199,14 @@ export default function withAsyncVerification({
);
}
});
},
);

useEffect(() => {
if (needAsyncVerification && verify) {
verifyProps(verify, otherProps);
}
}, [
needAsyncVerification,
showLoadingState,
verify,
otherProps,
addWarningToast,
]);
}, [needAsyncVerification, verify, otherProps, verifyProps]);

return (
<ControlComponent
Expand Down

0 comments on commit 9e5b568

Please sign in to comment.