From 9021a095b1a91d5daa80ce44b173408e477abb55 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 8 Jun 2023 10:56:21 +0100 Subject: [PATCH] Create datasource on the second step --- .../modals/GoogleDatasourceConfigModal.svelte | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index 39185350e0..83806153c9 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -21,6 +21,7 @@ import { saveDatasource } from "builderStore/datasource" import { DatasourceFeature } from "@budibase/types" + import { API } from "api" export let integration export let continueSetupId = false @@ -50,20 +51,6 @@ let allSheets let selectedSheets - const saveDatasourceAndRedirect = async () => { - try { - const resp = await saveDatasource(datasource, { - tablesFilter: selectedSheets, - }) - $goto(`./datasource/${resp._id}`) - notifications.success(`Datasource created successfully.`) - } catch (err) { - notifications.error(err?.message ?? "Error saving datasource") - // prevent the modal from closing - return false - } - } - $: modalConfig = { [GoogleDatasouceConfigStep.AUTH]: { title: `Connect to ${integrationName}`, @@ -82,8 +69,21 @@ } } + try { + const resp = await saveDatasource(datasource, { + tablesFilter: selectedSheets, + skipFetch: true, + }) + datasource = resp + } catch (err) { + notifications.error(err?.message ?? "Error saving datasource") + // prevent the modal from closing + return false + } + if (!integration.features[DatasourceFeature.FETCH_TABLE_NAMES]) { - saveDatasourceAndRedirect() + $goto(`./datasource/${datasource._id}`) + notifications.success(`Datasource created successfully.`) return } @@ -107,7 +107,23 @@ ? "Fetch sheets" : "Continue without fetching", onConfirm: async () => { - await saveDatasourceAndRedirect() + try { + if (selectedSheets.length) { + await API.buildDatasourceSchema({ + datasourceId: datasource._id, + tablesFilter: selectedSheets, + }) + } + + $goto(`./datasource/${datasource._id}`) + } catch (err) { + notifications.error(err?.message ?? "Error fetching the sheets") + // prevent the modal from closing + return false + } + }, + onCancel: async () => { + $goto(`./datasource/${datasource._id}`) }, }, } @@ -120,6 +136,7 @@ confirmText={modalConfig[step].confirmButtonText} showConfirmButton={!!modalConfig[step].onConfirm} onConfirm={modalConfig[step].onConfirm} + onCancel={modalConfig[step].onCancel} disabled={!isValid} > {#if step === GoogleDatasouceConfigStep.AUTH}