Refactor handleUpdateValues function to include an optional delayAnimation parameter

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-04 11:34:04 -03:00
commit 780ce08604

View file

@ -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,6 +118,7 @@ export default function ParameterComponent({
} }
renderTooltips(); renderTooltips();
if (delayAnimation) {
try { try {
// Wait for at least 500 milliseconds // Wait for at least 500 milliseconds
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
@ -124,19 +129,20 @@ export default function ParameterComponent({
} finally { } finally {
setIsLoading(false); 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 => {