fetch tables for datasource plus
This commit is contained in:
parent
f365cf731c
commit
4f5343ded9
|
@ -1,11 +1,10 @@
|
||||||
<script>
|
<script>
|
||||||
import { ModalContent, notifications } from "@budibase/bbui"
|
import { ModalContent, notifications } from "@budibase/bbui"
|
||||||
import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte"
|
import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte"
|
||||||
import { datasources } from "stores/backend"
|
import { datasources, tables } from "stores/backend"
|
||||||
import { IntegrationNames } from "constants"
|
import { IntegrationNames } from "constants"
|
||||||
|
|
||||||
export let integration
|
export let integration
|
||||||
|
|
||||||
function prepareData() {
|
function prepareData() {
|
||||||
let datasource = {}
|
let datasource = {}
|
||||||
let existingTypeCount = $datasources.list.filter(
|
let existingTypeCount = $datasources.list.filter(
|
||||||
|
@ -20,25 +19,44 @@
|
||||||
datasource.source = integration.type
|
datasource.source = integration.type
|
||||||
datasource.config = integration.config
|
datasource.config = integration.config
|
||||||
datasource.name = name
|
datasource.name = name
|
||||||
|
datasource.plus = integration.plus
|
||||||
|
|
||||||
return datasource
|
return datasource
|
||||||
}
|
}
|
||||||
async function saveDatasource() {
|
async function saveDatasource() {
|
||||||
try {
|
try {
|
||||||
// Create datasource
|
// 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.`)
|
notifications.success(`Datasource updated successfully.`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notifications.error(`Error saving datasource: ${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>
|
</script>
|
||||||
|
|
||||||
<ModalContent
|
<ModalContent
|
||||||
title="Add Data"
|
title="Add Data"
|
||||||
onConfirm={() => saveDatasource()}
|
onConfirm={() => saveDatasource()}
|
||||||
confirmText="Continue"
|
confirmText={integration.plus
|
||||||
cancelText="Start from scratch"
|
? "Fetch tables from database"
|
||||||
|
: "Save and continue to query"}
|
||||||
|
cancelText="Back"
|
||||||
size="M"
|
size="M"
|
||||||
>
|
>
|
||||||
<IntegrationConfigForm
|
<IntegrationConfigForm
|
||||||
|
|
|
@ -8,10 +8,7 @@
|
||||||
$: setupComplete =
|
$: setupComplete =
|
||||||
$datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1 ||
|
$datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1 ||
|
||||||
$datasources.list.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(() => {
|
onMount(() => {
|
||||||
if (!setupComplete) {
|
if (!setupComplete) {
|
||||||
modal.show()
|
modal.show()
|
||||||
|
|
Loading…
Reference in New Issue