2020-12-19 07:19:43 +13:00
|
|
|
<script>
|
2021-04-01 22:29:47 +13:00
|
|
|
import { goto } from "@roxi/routify"
|
2021-06-19 00:33:44 +12:00
|
|
|
import { datasources } from "stores/backend"
|
2021-04-09 22:02:53 +12:00
|
|
|
import { notifications } from "@budibase/bbui"
|
2021-04-23 00:38:35 +12:00
|
|
|
import { Input, Label, ModalContent } from "@budibase/bbui"
|
2020-12-19 07:19:43 +13:00
|
|
|
import TableIntegrationMenu from "../TableIntegrationMenu/index.svelte"
|
|
|
|
import analytics from "analytics"
|
|
|
|
|
|
|
|
let error = ""
|
|
|
|
|
|
|
|
let name
|
|
|
|
let integration
|
|
|
|
|
|
|
|
function checkValid(evt) {
|
|
|
|
const datasourceName = evt.target.value
|
2021-01-16 02:42:55 +13:00
|
|
|
if (
|
2021-05-04 22:32:22 +12:00
|
|
|
$datasources?.list.some(datasource => datasource.name === datasourceName)
|
2021-01-16 02:42:55 +13:00
|
|
|
) {
|
2020-12-19 07:19:43 +13:00
|
|
|
error = `Datasource with name ${datasourceName} already exists. Please choose another name.`
|
|
|
|
return
|
|
|
|
}
|
|
|
|
error = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveDatasource() {
|
2021-06-12 04:52:08 +12:00
|
|
|
const { type, plus, ...config } = integration
|
2020-12-19 07:19:43 +13:00
|
|
|
|
|
|
|
// Create datasource
|
2021-03-23 00:02:55 +13:00
|
|
|
const response = await datasources.save({
|
2020-12-19 07:19:43 +13:00
|
|
|
name,
|
|
|
|
source: type,
|
2021-01-16 02:42:55 +13:00
|
|
|
config,
|
2021-06-15 06:07:13 +12:00
|
|
|
plus,
|
2020-12-19 07:19:43 +13:00
|
|
|
})
|
2021-04-09 22:02:53 +12:00
|
|
|
notifications.success(`Datasource ${name} created successfully.`)
|
2021-06-12 04:52:08 +12:00
|
|
|
analytics.captureEvent("Datasource Created", { name, type })
|
2020-12-19 07:19:43 +13:00
|
|
|
|
|
|
|
// Navigate to new datasource
|
2020-12-31 00:46:37 +13:00
|
|
|
$goto(`./datasource/${response._id}`)
|
2020-12-19 07:19:43 +13:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<ModalContent
|
|
|
|
title="Create Datasource"
|
2021-05-04 22:07:26 +12:00
|
|
|
size="L"
|
2020-12-19 07:19:43 +13:00
|
|
|
confirmText="Create"
|
|
|
|
onConfirm={saveDatasource}
|
2021-06-28 21:55:58 +12:00
|
|
|
disabled={error || !name || !integration?.type}
|
2021-05-04 22:04:42 +12:00
|
|
|
>
|
2020-12-19 07:19:43 +13:00
|
|
|
<Input
|
|
|
|
data-cy="datasource-name-input"
|
|
|
|
label="Datasource Name"
|
|
|
|
on:input={checkValid}
|
|
|
|
bind:value={name}
|
2021-05-04 22:04:42 +12:00
|
|
|
{error}
|
|
|
|
/>
|
2021-04-23 00:38:35 +12:00
|
|
|
<Label>Datasource Type</Label>
|
2020-12-19 07:19:43 +13:00
|
|
|
<TableIntegrationMenu bind:integration />
|
|
|
|
</ModalContent>
|