fix(explore): verified props is not updated (#31008)
This commit is contained in:
parent
90572be95a
commit
9e5b568cc9
|
|
@ -24,6 +24,7 @@ import {
|
||||||
import { JsonArray, JsonValue, t } from '@superset-ui/core';
|
import { JsonArray, JsonValue, t } from '@superset-ui/core';
|
||||||
import { ControlProps } from 'src/explore/components/Control';
|
import { ControlProps } from 'src/explore/components/Control';
|
||||||
import builtInControlComponents from 'src/explore/components/controls';
|
import builtInControlComponents from 'src/explore/components/controls';
|
||||||
|
import useEffectEvent from 'src/hooks/useEffectEvent';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full control component map.
|
* Full control component map.
|
||||||
|
|
@ -72,7 +73,7 @@ export type AsyncVerify = (
|
||||||
* Whether the extra props will update the original props.
|
* Whether the extra props will update the original props.
|
||||||
*/
|
*/
|
||||||
function hasUpdates(
|
function hasUpdates(
|
||||||
props: ControlPropsWithExtras,
|
props: Partial<ControlPropsWithExtras>,
|
||||||
newProps: ExtraControlProps,
|
newProps: ExtraControlProps,
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -165,17 +166,17 @@ export default function withAsyncVerification({
|
||||||
[basicOnChange, otherProps, verifiedProps],
|
[basicOnChange, otherProps, verifiedProps],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
const verifyProps = useEffectEvent(
|
||||||
if (needAsyncVerification && verify) {
|
(verifyFunc: AsyncVerify, props: typeof otherProps) => {
|
||||||
if (showLoadingState) {
|
if (showLoadingState) {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
}
|
}
|
||||||
verify(otherProps)
|
verifyFunc(props)
|
||||||
.then(updatedProps => {
|
.then(updatedProps => {
|
||||||
if (showLoadingState) {
|
if (showLoadingState) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
if (updatedProps && hasUpdates(otherProps, updatedProps)) {
|
if (updatedProps && hasUpdates(verifiedProps, updatedProps)) {
|
||||||
setVerifiedProps({
|
setVerifiedProps({
|
||||||
// save isLoading in combination with other props to avoid
|
// save isLoading in combination with other props to avoid
|
||||||
// rendering twice.
|
// rendering twice.
|
||||||
|
|
@ -198,14 +199,14 @@ export default function withAsyncVerification({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (needAsyncVerification && verify) {
|
||||||
|
verifyProps(verify, otherProps);
|
||||||
}
|
}
|
||||||
}, [
|
}, [needAsyncVerification, verify, otherProps, verifyProps]);
|
||||||
needAsyncVerification,
|
|
||||||
showLoadingState,
|
|
||||||
verify,
|
|
||||||
otherProps,
|
|
||||||
addWarningToast,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ControlComponent
|
<ControlComponent
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue