Validate google sheets url

This commit is contained in:
Adria Navarro 2023-05-31 12:26:01 +02:00
parent d4ba73f331
commit 1e238ce693
3 changed files with 57 additions and 18 deletions

View File

@ -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
},
},
}
</script>
<ModalContent
title={`Connect to ${integrationName}`}
cancelText="Back"
cancelText="Cancel"
size="L"
showConfirmButton={false}
confirmText={modalConfig[step].confirmButtonText}
showConfirmButton={!!modalConfig[step].onConfirm}
onConfirm={modalConfig[step].onConfirm}
>
{#if step === GoogleDatasouceConfigStep.AUTH}
<!-- check true and false directly, don't render until flag is set -->
@ -48,8 +73,15 @@
{/if}
{/if}
{#if step === GoogleDatasouceConfigStep.SET_URL}
<Layout noPadding>
<Body size="S">Add the URL of the sheet you want to connect</Body>
<Layout noPadding no>
<Body size="S">Add the URL of the sheet you want to connect.</Body>
<IntegrationConfigForm
schema={datasource.schema}
bind:datasource
creating={true}
on:valid={e => (isValid = e.detail)}
/>
</Layout>
{/if}
</ModalContent>

View File

@ -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()
</script>
<Modal bind:this={internalTableModal}>
@ -158,8 +162,11 @@
continueGoogleSetup = false
}}
>
{#if integration?.auth?.type === "google" || continueGoogleSetup}
<GoogleDatasourceConfigModal continueSetup={continueGoogleSetup} />
{#if integration?.auth?.type === "google"}
<GoogleDatasourceConfigModal
continueSetup={isGoogleContinueAction}
{integration}
/>
{:else}
<DatasourceConfigModal {integration} />
{/if}

View File

@ -72,7 +72,7 @@ const SCHEMA: Integration = {
},
datasource: {
spreadsheetId: {
display: "Google Sheet URL",
display: "Spreadsheet URL",
type: DatasourceFieldType.STRING,
required: true,
},