fetch tables for datasource plus

This commit is contained in:
Peter Clement 2021-09-24 10:01:53 +01:00
parent 468a7caa07
commit af5280fa36
2 changed files with 24 additions and 9 deletions

View File

@ -1,11 +1,10 @@
<script>
import { ModalContent, notifications } from "@budibase/bbui"
import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte"
import { datasources } from "stores/backend"
import { datasources, tables } from "stores/backend"
import { IntegrationNames } from "constants"
export let integration
function prepareData() {
let datasource = {}
let existingTypeCount = $datasources.list.filter(
@ -20,25 +19,44 @@
datasource.source = integration.type
datasource.config = integration.config
datasource.name = name
datasource.plus = integration.plus
return datasource
}
async function saveDatasource() {
try {
// Create datasource
await datasources.save(prepareData())
const resp = await datasources.save(prepareData())
if (integration.plus) {
updateDatasourceSchema(resp)
}
await datasources.fetch()
await datasources.select(resp["_id"])
notifications.success(`Datasource updated successfully.`)
} catch (err) {
notifications.error(`Error saving datasource: ${err}`)
}
}
async function updateDatasourceSchema(datasourceJson) {
try {
await datasources.updateSchema(datasourceJson)
notifications.success(`Datasource ${name} tables updated successfully.`)
await tables.fetch()
} catch (err) {
notifications.error(`Error updating datasource schema: ${err}`)
}
}
</script>
<ModalContent
title="Add Data"
onConfirm={() => saveDatasource()}
confirmText="Continue"
cancelText="Start from scratch"
confirmText={integration.plus
? "Fetch tables from database"
: "Save and continue to query"}
cancelText="Back"
size="M"
>
<IntegrationConfigForm

View File

@ -8,10 +8,7 @@
$: setupComplete =
$datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1 ||
$datasources.list.length >= 1
$: console.log($datasources.list.length >= 1)
$: console.log(
$datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1
)
onMount(() => {
if (!setupComplete) {
modal.show()