1
0
Fork 0
mirror of synced 2024-06-02 02:25:17 +12:00
budibase/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte

60 lines
1.5 KiB
Svelte
Raw Normal View History

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"
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() {
const { type, plus, ...config } = integration
2020-12-19 07:19:43 +13:00
// Create datasource
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
})
notifications.success(`Datasource ${name} created successfully.`)
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}
disabled={error || !name || !integration?.type}
>
2020-12-19 07:19:43 +13:00
<Input
data-cy="datasource-name-input"
label="Datasource Name"
on:input={checkValid}
bind:value={name}
{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>