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

59 lines
1.5 KiB
Svelte
Raw Normal View History

2020-12-19 07:19:43 +13:00
<script>
import { goto, params } from "@sveltech/routify"
import { backendUiStore, store } from "builderStore"
import { notifier } from "builderStore/store/notifications"
import { Input, Label, ModalContent, Button, Spacer } from "@budibase/bbui"
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 (
$backendUiStore.datasources?.some(
datasource => datasource.name === datasourceName
)
) {
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, ...config } = integration
// Create datasource
2020-12-31 00:46:37 +13:00
const response = await backendUiStore.actions.datasources.save({
2020-12-19 07:19:43 +13:00
name,
source: type,
2021-01-16 02:42:55 +13:00
config,
2020-12-19 07:19:43 +13:00
})
notifier.success(`Datasource ${name} created successfully.`)
analytics.captureEvent("Datasource Created", { name })
// 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"
confirmText="Create"
onConfirm={saveDatasource}
disabled={error || !name}>
<Input
data-cy="datasource-name-input"
thin
label="Datasource Name"
on:input={checkValid}
bind:value={name}
{error} />
2021-01-13 05:49:11 +13:00
<Label grey extraSmall>Source</Label>
2020-12-19 07:19:43 +13:00
<TableIntegrationMenu bind:integration />
</ModalContent>