diff --git a/packages/builder/src/builderStore/datasource.js b/packages/builder/src/builderStore/datasource.js new file mode 100644 index 0000000000..47b9bc3f3c --- /dev/null +++ b/packages/builder/src/builderStore/datasource.js @@ -0,0 +1,44 @@ +import { datasources, tables } from "../stores/backend" +import { IntegrationNames } from "../constants" +import analytics, { Events } from "../analytics" +import { get } from "svelte/store" +import cloneDeep from "lodash/cloneDeepWith" + +function prepareData(config) { + let datasource = {} + let existingTypeCount = get(datasources).list.filter( + ds => ds.source === config.type + ).length + + let baseName = IntegrationNames[config.type] + let name = + existingTypeCount === 0 ? baseName : `${baseName}-${existingTypeCount + 1}` + + datasource.type = "datasource" + datasource.source = config.type + datasource.config = config.config + datasource.name = name + datasource.plus = config.plus + + return datasource +} + +export async function saveDatasource(config) { + const datasource = prepareData(config) + // Create datasource + const resp = await datasources.save(datasource, datasource.plus) + + // update the tables incase data source plus + await tables.fetch() + await datasources.select(resp._id) + analytics.captureEvent(Events.DATASOURCE.CREATED, { + name: resp.name, + source: resp.source, + }) + return resp +} + +export async function createRestDatasource(integration) { + const config = cloneDeep(integration) + return saveDatasource(config) +} diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/modals/CreateExternalTableModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/CreateExternalTableModal.svelte similarity index 100% rename from packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/modals/CreateExternalTableModal.svelte rename to packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/CreateExternalTableModal.svelte diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte index adec9afce7..e4e9f2035f 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte @@ -9,16 +9,40 @@ } from "@budibase/bbui" import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte" import { capitalise } from "helpers" + import { IntegrationTypes } from "constants" export let integration export let schema + export let creating + + function filter([key, value]) { + if (!value) { + return false + } + return !( + (integration.source === IntegrationTypes.REST && + key === "defaultHeaders") || + value.deprecated + ) + } + + $: config = integration.config + $: configKeys = Object.entries(schema || {}) + .filter(el => filter(el)) + .map(([key]) => key) let addButton
- {#each Object.keys(schema) as configKey} + {#if !creating} +
+ + +
+ {/if} + {#each configKeys as configKey} {#if schema[configKey].type === "object"}
@@ -29,13 +53,13 @@ {:else if schema[configKey].type === "boolean"}
- +
{:else if schema[configKey].type === "longForm"}
@@ -43,7 +67,7 @@