2021-09-24 08:47:22 +12:00
|
|
|
<script>
|
2021-09-24 21:19:48 +12:00
|
|
|
import { goto } from "@roxi/routify"
|
2021-09-24 22:28:56 +12:00
|
|
|
import { ModalContent, notifications, Body, Layout } from "@budibase/bbui"
|
2021-09-24 21:58:04 +12:00
|
|
|
import analytics, { Events } from "analytics"
|
2021-09-24 08:47:22 +12:00
|
|
|
import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte"
|
2021-09-29 00:25:57 +13:00
|
|
|
import { datasources } from "stores/backend"
|
2021-09-24 08:47:22 +12:00
|
|
|
import { IntegrationNames } from "constants"
|
|
|
|
|
|
|
|
export let integration
|
2021-09-24 21:19:48 +12:00
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
function prepareData() {
|
|
|
|
let datasource = {}
|
|
|
|
let existingTypeCount = $datasources.list.filter(
|
2021-09-24 21:12:30 +12:00
|
|
|
ds => ds.source == integration.type
|
2021-09-24 08:47:22 +12:00
|
|
|
).length
|
|
|
|
|
|
|
|
let baseName = IntegrationNames[integration.type]
|
|
|
|
let name =
|
|
|
|
existingTypeCount == 0 ? baseName : `${baseName}-${existingTypeCount + 1}`
|
|
|
|
|
|
|
|
datasource.type = "datasource"
|
|
|
|
datasource.source = integration.type
|
|
|
|
datasource.config = integration.config
|
|
|
|
datasource.name = name
|
2021-09-24 21:01:53 +12:00
|
|
|
datasource.plus = integration.plus
|
2021-09-24 08:47:22 +12:00
|
|
|
|
|
|
|
return datasource
|
|
|
|
}
|
|
|
|
async function saveDatasource() {
|
2021-09-29 00:25:57 +13:00
|
|
|
const datasource = prepareData()
|
2021-09-24 08:47:22 +12:00
|
|
|
try {
|
|
|
|
// Create datasource
|
2021-09-29 00:25:57 +13:00
|
|
|
const resp = await datasources.save(datasource, datasource.plus)
|
2021-09-24 21:01:53 +12:00
|
|
|
|
2021-09-24 21:19:48 +12:00
|
|
|
await datasources.select(resp._id)
|
2021-09-27 22:04:01 +13:00
|
|
|
$goto(`./datasource/${resp._id}`)
|
2021-09-24 08:47:22 +12:00
|
|
|
notifications.success(`Datasource updated successfully.`)
|
2021-09-24 21:58:04 +12:00
|
|
|
analytics.captureEvent(Events.DATASOURCE.CREATED, {
|
|
|
|
name: resp.name,
|
|
|
|
source: resp.source,
|
|
|
|
})
|
2021-09-29 00:25:57 +13:00
|
|
|
return true
|
2021-09-24 08:47:22 +12:00
|
|
|
} catch (err) {
|
|
|
|
notifications.error(`Error saving datasource: ${err}`)
|
2021-09-29 00:25:57 +13:00
|
|
|
return false
|
2021-09-24 21:01:53 +12:00
|
|
|
}
|
|
|
|
}
|
2021-09-24 08:47:22 +12:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<ModalContent
|
2021-09-24 22:28:56 +12:00
|
|
|
title={`Connect to ${IntegrationNames[integration.type]}`}
|
2021-09-24 08:47:22 +12:00
|
|
|
onConfirm={() => saveDatasource()}
|
2021-09-24 21:01:53 +12:00
|
|
|
confirmText={integration.plus
|
|
|
|
? "Fetch tables from database"
|
|
|
|
: "Save and continue to query"}
|
|
|
|
cancelText="Back"
|
2021-09-24 08:47:22 +12:00
|
|
|
size="M"
|
|
|
|
>
|
2021-09-24 22:28:56 +12:00
|
|
|
<Layout noPadding>
|
|
|
|
<Body size="XS"
|
|
|
|
>Connect your database to Budibase using the config below.
|
|
|
|
</Body>
|
|
|
|
</Layout>
|
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
<IntegrationConfigForm
|
|
|
|
schema={integration.schema}
|
|
|
|
bind:integration={integration.config}
|
|
|
|
/>
|
|
|
|
</ModalContent>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
</style>
|