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

64 lines
1.6 KiB
Svelte
Raw Normal View History

2020-12-19 07:19:43 +13:00
<script>
<<<<<<< HEAD
2021-03-18 00:40:24 +13:00
import { goto, params } from "@roxi/routify"
2020-12-19 07:19:43 +13:00
import { backendUiStore, store } from "builderStore"
=======
import { goto } from "@sveltech/routify"
import { datasources } from 'stores/backend/'
>>>>>>> d803aa0bd7a74220e432f4a1b338abdd7fbe9b7d
2020-12-19 07:19:43 +13:00
import { notifier } from "builderStore/store/notifications"
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 (
$datasources?.list.some(
2021-01-16 02:42:55 +13:00
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
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,
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>