Refactor handleUpdateValues function to include an optional delayAnimation parameter
This commit is contained in:
parent
09c154aba8
commit
780ce08604
1 changed files with 19 additions and 13 deletions
|
|
@ -86,7 +86,11 @@ export default function ParameterComponent({
|
||||||
|
|
||||||
const takeSnapshot = useFlowsManagerStore((state) => state.takeSnapshot);
|
const takeSnapshot = useFlowsManagerStore((state) => state.takeSnapshot);
|
||||||
|
|
||||||
const handleUpdateValues = async (name: string, data: NodeDataType) => {
|
const handleUpdateValues = async (
|
||||||
|
name: string,
|
||||||
|
data: NodeDataType,
|
||||||
|
delayAnimation: boolean = true
|
||||||
|
) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const code = data.node?.template["code"]?.value;
|
const code = data.node?.template["code"]?.value;
|
||||||
if (!code) {
|
if (!code) {
|
||||||
|
|
@ -114,29 +118,31 @@ export default function ParameterComponent({
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTooltips();
|
renderTooltips();
|
||||||
try {
|
if (delayAnimation) {
|
||||||
// Wait for at least 500 milliseconds
|
try {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
// Wait for at least 500 milliseconds
|
||||||
// Continue with the request
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
// If the request takes longer than 500 milliseconds, it will not wait an additional 500 milliseconds
|
// Continue with the request
|
||||||
} catch (error) {
|
// If the request takes longer than 500 milliseconds, it will not wait an additional 500 milliseconds
|
||||||
console.error("Error occurred while waiting for refresh:", error);
|
} catch (error) {
|
||||||
} finally {
|
console.error("Error occurred while waiting for refresh:", error);
|
||||||
setIsLoading(false);
|
} finally {
|
||||||
}
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
} else setIsLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function fetchData() {
|
function fetchData() {
|
||||||
if (data.node?.template[name]?.refresh) {
|
if (data.node?.template[name]?.refresh) {
|
||||||
handleUpdateValues(name, data);
|
handleUpdateValues(name, data, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetchData();
|
fetchData();
|
||||||
// I want this to run as soon as the component mounts
|
// I want this to run as soon as the component mounts
|
||||||
// but it is not updating the data
|
// but it is not updating the data
|
||||||
// the .refresh does not change
|
// the .refresh does not change
|
||||||
}, [data.node?.template[name]?.refresh]);
|
}, []);
|
||||||
const handleOnNewValue = (
|
const handleOnNewValue = (
|
||||||
newValue: string | string[] | boolean | Object[]
|
newValue: string | string[] | boolean | Object[]
|
||||||
): void => {
|
): void => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue