From 9021a095b1a91d5daa80ce44b173408e477abb55 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 8 Jun 2023 10:56:21 +0100 Subject: [PATCH 1/3] 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} From 0bd35be8614268711dc3aebb04ee35d11f5a73d0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 9 Jun 2023 11:57:17 +0100 Subject: [PATCH 2/3] Navigate when the modal is closed and the datasource was created --- .../modals/GoogleDatasourceConfigModal.svelte | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index 83806153c9..819d1e7d2d 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -10,7 +10,7 @@ import { IntegrationNames, IntegrationTypes } from "constants/backend" import GoogleButton from "../_components/GoogleButton.svelte" import { organisation } from "stores/portal" - import { onMount } from "svelte" + import { onMount, onDestroy } from "svelte" import { validateDatasourceConfig, getDatasourceInfo, @@ -34,6 +34,7 @@ onMount(async () => { await organisation.init() }) + const integrationName = IntegrationNames[IntegrationTypes.GOOGLE_SHEETS] export const GoogleDatasouceConfigStep = { @@ -82,7 +83,6 @@ } if (!integration.features[DatasourceFeature.FETCH_TABLE_NAMES]) { - $goto(`./datasource/${datasource._id}`) notifications.success(`Datasource created successfully.`) return } @@ -115,18 +115,22 @@ }) } - $goto(`./datasource/${datasource._id}`) + return } catch (err) { notifications.error(err?.message ?? "Error fetching the sheets") // prevent the modal from closing return false } }, - onCancel: async () => { - $goto(`./datasource/${datasource._id}`) - }, }, } + + // This will handle the user closing the modal pressing outside the modal + onDestroy(async () => { + if (step === GoogleDatasouceConfigStep.SET_SHEETS) { + await $goto(`./datasource/${datasource._id}`) + } + }) {#if step === GoogleDatasouceConfigStep.AUTH} From 86fa2626498c47c81c99360640f1fc679d7b49ee Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 9 Jun 2023 12:00:16 +0100 Subject: [PATCH 3/3] Fix flash --- .../modals/GoogleDatasourceConfigModal.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index 819d1e7d2d..5733a8c015 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -29,6 +29,8 @@ let datasource = cloneDeep(integration) datasource.config.continueSetupId = continueSetupId + let { schema } = datasource + $: isGoogleConfigured = !!$organisation.googleDatasourceConfigured onMount(async () => { @@ -164,7 +166,7 @@ Add the URL of the sheet you want to connect. (isValid = e.detail)}