2020-12-19 07:19:43 +13:00
|
|
|
<script>
|
2022-01-24 23:44:37 +13:00
|
|
|
import {
|
|
|
|
ModalContent,
|
|
|
|
Modal,
|
|
|
|
Body,
|
|
|
|
Layout,
|
|
|
|
Detail,
|
2022-06-23 22:35:57 +12:00
|
|
|
Heading,
|
2022-01-24 23:44:37 +13:00
|
|
|
notifications,
|
|
|
|
} from "@budibase/bbui"
|
2021-09-24 08:47:22 +12:00
|
|
|
import { onMount } from "svelte"
|
|
|
|
import ICONS from "../icons"
|
2022-01-24 23:44:37 +13:00
|
|
|
import { API } from "api"
|
2022-06-23 22:35:57 +12:00
|
|
|
import { IntegrationTypes } from "constants/backend"
|
2021-07-08 04:12:13 +12:00
|
|
|
import CreateTableModal from "components/backend/TableNavigator/modals/CreateTableModal.svelte"
|
2021-09-24 21:58:04 +12:00
|
|
|
import DatasourceConfigModal from "components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte"
|
2022-01-18 22:25:59 +13:00
|
|
|
import GoogleDatasourceConfigModal from "components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte"
|
2021-12-01 05:21:16 +13:00
|
|
|
import { createRestDatasource } from "builderStore/datasource"
|
|
|
|
import { goto } from "@roxi/routify"
|
2021-11-29 23:37:31 +13:00
|
|
|
import ImportRestQueriesModal from "./ImportRestQueriesModal.svelte"
|
2022-08-17 21:46:17 +12:00
|
|
|
import DatasourceCard from "../_components/DatasourceCard.svelte"
|
2020-12-19 07:19:43 +13:00
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
export let modal
|
2022-01-24 23:44:37 +13:00
|
|
|
let integrations = {}
|
2021-09-24 08:47:22 +12:00
|
|
|
let integration = {}
|
|
|
|
let internalTableModal
|
|
|
|
let externalDatasourceModal
|
2021-11-26 06:14:07 +13:00
|
|
|
let importModal
|
|
|
|
|
|
|
|
$: showImportButton = false
|
|
|
|
|
|
|
|
checkShowImport()
|
2020-12-19 07:19:43 +13:00
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
onMount(() => {
|
|
|
|
fetchIntegrations()
|
|
|
|
})
|
2021-07-08 04:12:13 +12:00
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
function selectIntegration(integrationType) {
|
|
|
|
const selected = integrations[integrationType]
|
|
|
|
|
|
|
|
// build the schema
|
|
|
|
const config = {}
|
|
|
|
for (let key of Object.keys(selected.datasource)) {
|
|
|
|
config[key] = selected.datasource[key].default
|
|
|
|
}
|
|
|
|
integration = {
|
|
|
|
type: integrationType,
|
|
|
|
plus: selected.plus,
|
|
|
|
config,
|
|
|
|
schema: selected.datasource,
|
2022-01-06 21:08:54 +13:00
|
|
|
auth: selected.auth,
|
2020-12-19 07:19:43 +13:00
|
|
|
}
|
2022-08-17 21:05:13 +12:00
|
|
|
if (selected.friendlyName) {
|
|
|
|
integration.name = selected.friendlyName
|
|
|
|
}
|
2021-11-26 06:14:07 +13:00
|
|
|
checkShowImport()
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkShowImport() {
|
|
|
|
showImportButton = integration.type === "REST"
|
|
|
|
}
|
|
|
|
|
|
|
|
function showImportModal() {
|
|
|
|
importModal.show()
|
2020-12-19 07:19:43 +13:00
|
|
|
}
|
|
|
|
|
2021-12-01 05:21:16 +13:00
|
|
|
async function chooseNextModal() {
|
|
|
|
if (integration.type === IntegrationTypes.INTERNAL) {
|
2021-09-24 08:47:22 +12:00
|
|
|
externalDatasourceModal.hide()
|
|
|
|
internalTableModal.show()
|
2021-12-01 05:21:16 +13:00
|
|
|
} else if (integration.type === IntegrationTypes.REST) {
|
2022-01-25 01:37:22 +13:00
|
|
|
try {
|
|
|
|
// Skip modal for rest, create straight away
|
|
|
|
const resp = await createRestDatasource(integration)
|
|
|
|
$goto(`./datasource/${resp._id}`)
|
|
|
|
} catch (error) {
|
|
|
|
notifications.error("Error creating datasource")
|
|
|
|
}
|
2021-09-24 08:47:22 +12:00
|
|
|
} else {
|
|
|
|
externalDatasourceModal.show()
|
2021-07-08 04:12:13 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
async function fetchIntegrations() {
|
2022-01-24 23:44:37 +13:00
|
|
|
let newIntegrations = {
|
2021-12-01 05:21:16 +13:00
|
|
|
[IntegrationTypes.INTERNAL]: { datasource: {}, name: "INTERNAL/CSV" },
|
2021-09-24 08:47:22 +12:00
|
|
|
}
|
2022-01-24 23:44:37 +13:00
|
|
|
try {
|
|
|
|
const integrationList = await API.getIntegrations()
|
|
|
|
newIntegrations = {
|
|
|
|
...newIntegrations,
|
|
|
|
...integrationList,
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
notifications.error("Error fetching integrations")
|
|
|
|
}
|
|
|
|
integrations = newIntegrations
|
2020-12-19 07:19:43 +13:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
<Modal bind:this={internalTableModal}>
|
|
|
|
<CreateTableModal />
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<Modal bind:this={externalDatasourceModal}>
|
2022-01-18 22:25:59 +13:00
|
|
|
{#if integration?.auth?.type === "google"}
|
|
|
|
<GoogleDatasourceConfigModal {integration} {modal} />
|
|
|
|
{:else}
|
|
|
|
<DatasourceConfigModal {integration} {modal} />
|
|
|
|
{/if}
|
2021-09-24 08:47:22 +12:00
|
|
|
</Modal>
|
|
|
|
|
2021-11-26 06:14:07 +13:00
|
|
|
<Modal bind:this={importModal}>
|
|
|
|
{#if integration.type === "REST"}
|
2021-12-04 00:14:22 +13:00
|
|
|
<ImportRestQueriesModal
|
|
|
|
navigateDatasource={true}
|
|
|
|
createDatasource={true}
|
|
|
|
onCancel={() => modal.show()}
|
|
|
|
/>
|
2021-11-26 06:14:07 +13:00
|
|
|
{/if}
|
|
|
|
</Modal>
|
|
|
|
|
2021-09-24 08:47:22 +12:00
|
|
|
<Modal bind:this={modal}>
|
|
|
|
<ModalContent
|
|
|
|
disabled={!Object.keys(integration).length}
|
2022-06-23 22:35:57 +12:00
|
|
|
title="Add data source"
|
2021-09-24 08:47:22 +12:00
|
|
|
confirmText="Continue"
|
2021-11-26 06:14:07 +13:00
|
|
|
showSecondaryButton={showImportButton}
|
|
|
|
secondaryButtonText="Import"
|
|
|
|
secondaryAction={() => showImportModal()}
|
2021-09-30 22:50:27 +13:00
|
|
|
showCancelButton={false}
|
2021-09-24 08:47:22 +12:00
|
|
|
size="M"
|
|
|
|
onConfirm={() => {
|
|
|
|
chooseNextModal()
|
|
|
|
}}
|
|
|
|
>
|
2022-06-23 23:05:05 +12:00
|
|
|
<Layout noPadding gap="XS">
|
|
|
|
<Body size="S">Get started with Budibase DB</Body>
|
|
|
|
<div
|
|
|
|
class:selected={integration.type === IntegrationTypes.INTERNAL}
|
|
|
|
on:click={() => selectIntegration(IntegrationTypes.INTERNAL)}
|
|
|
|
class="item hoverable"
|
|
|
|
>
|
|
|
|
<div class="item-body with-type">
|
|
|
|
<svelte:component this={ICONS.BUDIBASE} height="20" width="20" />
|
|
|
|
<div class="text">
|
|
|
|
<Heading size="XXS">Budibase DB</Heading>
|
|
|
|
<Detail size="S" class="type">Non-relational</Detail>
|
2021-09-24 08:47:22 +12:00
|
|
|
</div>
|
2022-06-23 22:35:57 +12:00
|
|
|
</div>
|
2022-06-23 23:05:05 +12:00
|
|
|
</div>
|
|
|
|
</Layout>
|
|
|
|
|
|
|
|
<Layout noPadding gap="XS">
|
|
|
|
<Body size="S">Connect to an external data source</Body>
|
|
|
|
<div class="item-list">
|
2022-08-17 21:46:17 +12:00
|
|
|
{#each Object.entries(integrations).filter(([key, val]) => key !== IntegrationTypes.INTERNAL && !val.custom) as [integrationType, schema]}
|
|
|
|
<DatasourceCard
|
|
|
|
on:selected={evt => selectIntegration(evt.detail)}
|
|
|
|
{schema}
|
|
|
|
bind:integrationType
|
|
|
|
{integration}
|
|
|
|
/>
|
2022-06-23 23:05:05 +12:00
|
|
|
{/each}
|
|
|
|
</div>
|
2022-08-17 21:46:17 +12:00
|
|
|
<Body size="S">Custom data source</Body>
|
|
|
|
{#each Object.entries(integrations).filter(entry => entry[1].custom) as [integrationType, schema]}
|
|
|
|
<DatasourceCard
|
|
|
|
on:selected={evt => selectIntegration(evt.detail)}
|
|
|
|
{schema}
|
|
|
|
bind:integrationType
|
|
|
|
{integration}
|
|
|
|
/>
|
|
|
|
{/each}
|
2021-09-24 08:47:22 +12:00
|
|
|
</Layout>
|
|
|
|
</ModalContent>
|
2021-07-08 04:12:13 +12:00
|
|
|
</Modal>
|
2021-09-24 08:47:22 +12:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.item-list {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
|
|
|
grid-gap: var(--spectrum-alias-grid-baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
.item {
|
|
|
|
cursor: pointer;
|
|
|
|
display: grid;
|
|
|
|
grid-gap: var(--spectrum-alias-grid-margin-xsmall);
|
2022-06-23 22:35:57 +12:00
|
|
|
padding: var(--spectrum-alias-item-padding-s)
|
|
|
|
var(--spectrum-alias-item-padding-m);
|
2021-09-24 08:47:22 +12:00
|
|
|
background: var(--spectrum-alias-background-color-secondary);
|
2022-06-23 22:35:57 +12:00
|
|
|
transition: background 0.13s ease-out;
|
2021-09-24 08:47:22 +12:00
|
|
|
border: solid var(--spectrum-alias-border-color);
|
|
|
|
border-radius: 5px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
border-width: 2px;
|
|
|
|
}
|
2022-06-23 22:35:57 +12:00
|
|
|
.item:hover,
|
|
|
|
.item.selected {
|
2021-09-24 08:47:22 +12:00
|
|
|
background: var(--spectrum-alias-background-color-tertiary);
|
|
|
|
}
|
|
|
|
|
2022-06-23 22:35:57 +12:00
|
|
|
.item-body {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
gap: var(--spacing-m);
|
|
|
|
}
|
|
|
|
.item-body.with-type {
|
|
|
|
align-items: flex-start;
|
|
|
|
}
|
|
|
|
.item-body.with-type :global(svg) {
|
|
|
|
margin-top: 4px;
|
|
|
|
}
|
|
|
|
|
2022-06-23 23:05:05 +12:00
|
|
|
.text :global(.spectrum-Detail) {
|
2022-06-23 22:35:57 +12:00
|
|
|
color: var(--spectrum-global-color-gray-700);
|
2021-09-24 08:47:22 +12:00
|
|
|
}
|
|
|
|
</style>
|