From 1e238ce69376987e13db2ac1fabfe281a0d7df52 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 May 2023 12:26:01 +0200 Subject: [PATCH] Validate google sheets url --- .../modals/GoogleDatasourceConfigModal.svelte | 40 +++++++++++++++++-- .../builder/app/[application]/data/new.svelte | 33 +++++++++------ .../server/src/integrations/googlesheets.ts | 2 +- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index 79fb0f6b5b..a0b0902480 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -4,9 +4,15 @@ import GoogleButton from "../_components/GoogleButton.svelte" import { organisation } from "stores/portal" import { onMount } from "svelte" + import { validateDatasourceConfig } from "builderStore/datasource" + import cloneDeep from "lodash/cloneDeepWith" + import IntegrationConfigForm from "../TableIntegrationMenu/IntegrationConfigForm.svelte" + export let integration export let continueSetup = false + let datasource = cloneDeep(integration) + $: isGoogleConfigured = !!$organisation.googleDatasourceConfigured onMount(async () => { @@ -22,13 +28,32 @@ let step = continueSetup ? GoogleDatasouceConfigStep.SET_URL : GoogleDatasouceConfigStep.AUTH + + let isValid + + const modalConfig = { + [GoogleDatasouceConfigStep.AUTH]: {}, + [GoogleDatasouceConfigStep.SET_URL]: { + confirmButtonText: "Connect", + onConfirm: async () => { + const resp = await validateDatasourceConfig(datasource) + if (!resp.connected) { + displayError(`Unable to connect - ${resp.error}`) + } + + return false + }, + }, + } {#if step === GoogleDatasouceConfigStep.AUTH} @@ -48,8 +73,15 @@ {/if} {/if} {#if step === GoogleDatasouceConfigStep.SET_URL} - - Add the URL of the sheet you want to connect + + Add the URL of the sheet you want to connect. + + (isValid = e.detail)} + /> {/if} diff --git a/packages/builder/src/pages/builder/app/[application]/data/new.svelte b/packages/builder/src/pages/builder/app/[application]/data/new.svelte index ed2e7f360d..536859d4f9 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/new.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/new.svelte @@ -131,21 +131,25 @@ return integrationsArray } - const fetchIntegrations = async () => { - const unsortedIntegrations = await API.getIntegrations() - integrations = sortIntegrations(unsortedIntegrations) - } - - $: fetchIntegrations() - + let isGoogleContinueAction onMount(() => { const urlParams = new URLSearchParams(window.location.search) const action = urlParams.get("action") - if (action === "google_continue") { - continueGoogleSetup = true - externalDatasourceModal.show() - } + + isGoogleContinueAction = action === "google_continue" }) + + const fetchIntegrations = async () => { + const unsortedIntegrations = await API.getIntegrations() + integrations = sortIntegrations(unsortedIntegrations) + console.log(integrations[IntegrationTypes.GOOGLE_SHEETS]) + + if (isGoogleContinueAction) { + handleIntegrationSelect(IntegrationTypes.GOOGLE_SHEETS) + } + } + + $: fetchIntegrations() @@ -158,8 +162,11 @@ continueGoogleSetup = false }} > - {#if integration?.auth?.type === "google" || continueGoogleSetup} - + {#if integration?.auth?.type === "google"} + {:else} {/if} diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index 8863aa0b3a..2598f6db62 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -72,7 +72,7 @@ const SCHEMA: Integration = { }, datasource: { spreadsheetId: { - display: "Google Sheet URL", + display: "Spreadsheet URL", type: DatasourceFieldType.STRING, required: true, },