From 780f67210024c76f4fee2e5381b84a9de54b15f8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 Jul 2024 10:06:03 +0200 Subject: [PATCH] Handle state issues --- .../ExistingTableDataImport.svelte | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/packages/builder/src/components/backend/TableNavigator/ExistingTableDataImport.svelte b/packages/builder/src/components/backend/TableNavigator/ExistingTableDataImport.svelte index 80655d1099..f1d85a6a30 100644 --- a/packages/builder/src/components/backend/TableNavigator/ExistingTableDataImport.svelte +++ b/packages/builder/src/components/backend/TableNavigator/ExistingTableDataImport.svelte @@ -100,51 +100,43 @@ async function handleFile(e) { loading = true error = null + const previousValidation = validation validation = {} try { const response = await parseFile(e) rows = response.rows fileName = response.fileName + + const newValidateHash = JSON.stringify(rows) + if (newValidateHash === validateHash) { + validation = previousValidation + } else { + await validate(rows) + validateHash = newValidateHash + } } catch (e) { + error = e.message || e + } finally { loading = false - error = e } } async function validate(rows) { - loading = true error = null validation = {} allValid = false - try { - if (rows.length > 0) { - const response = await API.validateExistingTableImport({ - rows, - tableId, - }) + if (rows.length > 0) { + const response = await API.validateExistingTableImport({ + rows, + tableId, + }) - validation = response.schemaValidation - invalidColumns = response.invalidColumns - allValid = response.allValid - } - } catch (e) { - error = e.message + validation = response.schemaValidation + invalidColumns = response.invalidColumns + allValid = response.allValid } - - loading = false - } - - $: { - // binding in consumer is causing double renders here - const newValidateHash = JSON.stringify(rows) - - if (newValidateHash !== validateHash) { - validate(rows) - } - - validateHash = newValidateHash }