Fetch info when enabled

This commit is contained in:
Adria Navarro 2023-06-06 12:13:56 +01:00
parent 258b3daf20
commit 77bd236557
2 changed files with 40 additions and 18 deletions

View File

@ -49,3 +49,9 @@ export async function getDatasourceInfo(config) {
const datasource = prepareData(config) const datasource = prepareData(config)
return await API.fetchInfoForDatasource(datasource) return await API.fetchInfoForDatasource(datasource)
} }
export async function getDatasourceInfo(config) {
const datasource = prepareData(config)
const resp = await API.fetchTablesForDatasource(datasource)
return resp
}

View File

@ -10,10 +10,14 @@
import GoogleButton from "../_components/GoogleButton.svelte" import GoogleButton from "../_components/GoogleButton.svelte"
import { organisation } from "stores/portal" import { organisation } from "stores/portal"
import { onMount } from "svelte" import { onMount } from "svelte"
import { validateDatasourceConfig } from "builderStore/datasource" import {
validateDatasourceConfig,
getDatasourceInfo,
} from "builderStore/datasource"
import cloneDeep from "lodash/cloneDeepWith" import cloneDeep from "lodash/cloneDeepWith"
import IntegrationConfigForm from "../TableIntegrationMenu/IntegrationConfigForm.svelte" import IntegrationConfigForm from "../TableIntegrationMenu/IntegrationConfigForm.svelte"
import { goto } from "@roxi/routify" import { goto } from "@roxi/routify"
import { API } from "api"
import { saveDatasource } from "builderStore/datasource" import { saveDatasource } from "builderStore/datasource"
import { DatasourceFeature } from "@budibase/types" import { DatasourceFeature } from "@budibase/types"
@ -43,6 +47,18 @@
let isValid = false let isValid = false
const saveDatasourceAndRedirect = async () => {
try {
const resp = await saveDatasource(datasource)
$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
}
}
const modalConfig = { const modalConfig = {
[GoogleDatasouceConfigStep.AUTH]: { [GoogleDatasouceConfigStep.AUTH]: {
title: `Connect to ${integrationName}`, title: `Connect to ${integrationName}`,
@ -61,12 +77,22 @@
} }
} }
if (!integration.features[DatasourceFeature.FETCH_TABLE_NAMES]) {
saveDatasourceAndRedirect()
return
}
getDatasourceInfo(datasource).then(i => {
debugger
console.log(i)
step = GoogleDatasouceConfigStep.SET_SHEETS step = GoogleDatasouceConfigStep.SET_SHEETS
notifications.success( notifications.success(
checkConnection checkConnection
? "Connection Successful" ? "Connection Successful"
: `Datasource created successfully.` : `Datasource created successfully.`
) )
})
// prevent the modal from closing // prevent the modal from closing
return false return false
@ -75,17 +101,7 @@
[GoogleDatasouceConfigStep.SET_SHEETS]: { [GoogleDatasouceConfigStep.SET_SHEETS]: {
title: `Choose your sheets`, title: `Choose your sheets`,
confirmButtonText: "Fetch sheets", confirmButtonText: "Fetch sheets",
onConfirm: async () => { onConfirm: saveDatasourceAndRedirect,
try {
const resp = await saveDatasource(datasource)
$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
}
},
}, },
} }
</script> </script>