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 08:47:22 +12:00
|
|
|
import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte"
|
2021-12-07 06:39:51 +13:00
|
|
|
import { IntegrationNames } from "constants/backend"
|
2021-10-07 03:06:48 +13:00
|
|
|
import cloneDeep from "lodash/cloneDeepWith"
|
2021-12-01 05:21:16 +13:00
|
|
|
import { saveDatasource as save } from "builderStore/datasource"
|
2022-01-07 04:28:38 +13:00
|
|
|
import { onMount } from "svelte"
|
2021-09-24 08:47:22 +12:00
|
|
|
|
|
|
|
export let integration
|
2021-10-07 03:06:48 +13:00
|
|
|
export let modal
|
|
|
|
|
|
|
|
// kill the reference so the input isn't saved
|
2021-12-01 06:56:15 +13:00
|
|
|
let datasource = cloneDeep(integration)
|
2022-01-07 04:28:38 +13:00
|
|
|
let skipFetch = false
|
2022-07-08 09:06:57 +12:00
|
|
|
let isValid = false
|
2021-09-24 21:19:48 +12:00
|
|
|
|
2022-08-17 21:05:13 +12:00
|
|
|
$: name =
|
|
|
|
IntegrationNames[datasource.type] || datasource.name || datasource.type
|
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
async function saveDatasource() {
|
|
|
|
try {
|
2022-08-17 22:01:25 +12:00
|
|
|
if (!datasource.name) {
|
|
|
|
datasource.name = name
|
|
|
|
}
|
2022-01-07 04:28:38 +13:00
|
|
|
const resp = await save(datasource, skipFetch)
|
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.`)
|
|
|
|
} catch (err) {
|
2022-03-08 23:15:02 +13:00
|
|
|
notifications.error(err?.message ?? "Error saving datasource")
|
|
|
|
// prevent the modal from closing
|
|
|
|
return false
|
2021-09-24 21:01:53 +12:00
|
|
|
}
|
|
|
|
}
|
2022-01-07 04:28:38 +13:00
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
skipFetch = false
|
|
|
|
})
|
2021-09-24 08:47:22 +12:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<ModalContent
|
2022-08-17 21:05:13 +12:00
|
|
|
title={`Connect to ${name}`}
|
2021-09-24 08:47:22 +12:00
|
|
|
onConfirm={() => saveDatasource()}
|
2021-10-07 03:06:48 +13:00
|
|
|
onCancel={() => modal.show()}
|
2021-12-01 06:56:15 +13:00
|
|
|
confirmText={datasource.plus
|
2022-01-07 04:28:38 +13:00
|
|
|
? "Save and fetch tables"
|
2021-09-24 21:01:53 +12:00
|
|
|
: "Save and continue to query"}
|
|
|
|
cancelText="Back"
|
2022-01-07 04:28:38 +13:00
|
|
|
showSecondaryButton={datasource.plus}
|
|
|
|
secondaryButtonText={datasource.plus ? "Skip table fetch" : undefined}
|
|
|
|
secondaryAction={() => {
|
|
|
|
skipFetch = true
|
|
|
|
saveDatasource()
|
|
|
|
return true
|
|
|
|
}}
|
2021-10-13 04:13:54 +13:00
|
|
|
size="L"
|
2022-07-08 09:06:57 +12:00
|
|
|
disabled={!isValid}
|
2021-09-24 08:47:22 +12:00
|
|
|
>
|
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-12-01 05:21:16 +13:00
|
|
|
<IntegrationConfigForm
|
2021-12-01 06:56:15 +13:00
|
|
|
schema={datasource.schema}
|
|
|
|
bind:datasource
|
2021-12-01 05:21:16 +13:00
|
|
|
creating={true}
|
2022-07-08 09:06:57 +12:00
|
|
|
on:valid={e => (isValid = e.detail)}
|
2021-12-01 05:21:16 +13:00
|
|
|
/>
|
2021-09-24 08:47:22 +12:00
|
|
|
</ModalContent>
|