From 0de6b554383fe5136ae355bc61167c1d74130831 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 23 Sep 2021 21:47:22 +0100 Subject: [PATCH 01/22] add base wizard for datasources --- .../modals/CreateDatasourceModal.svelte | 207 ++++++++++++------ .../modals/DatasourceDetailsModal.svelte | 51 +++++ packages/builder/src/constants/index.js | 14 ++ .../app/[application]/data/_layout.svelte | 8 +- .../app/[application]/data/index.svelte | 11 +- 5 files changed, 224 insertions(+), 67 deletions(-) create mode 100644 packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte index 9cdd893230..bf8585d401 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte @@ -1,74 +1,159 @@ - - + + - - - - - + + + + + + + { + chooseNextModal() + }} + > + All apps need data. You can connect to a data source below, or add data + to your app using Budibase's built-in database - it's simple! + + + +
selectIntegration(INTERNAL)} + class="item hoverable" + > +
+ + + Budibase DB (no prior data required) +
+
+ + +
+ {#each Object.entries(integrations).filter(([key]) => key !== INTERNAL) as [integrationType, schema]} +
selectIntegration(integrationType)} + class="item hoverable" + > +
+ + + + {schema.name || IntegrationNames[integrationType]} +
+
+ {/each} +
+
+
+
+ + diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte new file mode 100644 index 0000000000..dcdd2da497 --- /dev/null +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte @@ -0,0 +1,51 @@ + + + saveDatasource()} + confirmText="Continue" + cancelText="Start from scratch" + size="M" +> + + + + diff --git a/packages/builder/src/constants/index.js b/packages/builder/src/constants/index.js index a892eb2129..c0d283b0ea 100644 --- a/packages/builder/src/constants/index.js +++ b/packages/builder/src/constants/index.js @@ -15,6 +15,20 @@ export const AppStatus = { DEPLOYED: "published", } +export const IntegrationNames = { + POSTGRES: "PostgreSQL", + MONGODB: "MongoDB", + COUCHDB: "CouchDB", + S3: "S3", + MYSQL: "MySQL", + REST: "REST", + DYNAMODB: "DynamoDB", + ELASTICSEARCH: "ElasticSearch", + SQL_SERVER: "SQL Server", + AIRTABLE: "Airtable", + ARANGODB: "ArangoDB", +} + // fields on the user table that cannot be edited export const UNEDITABLE_USER_FIELDS = [ "email", diff --git a/packages/builder/src/pages/builder/app/[application]/data/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/data/_layout.svelte index 5202bd45f2..f321a2c422 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/_layout.svelte @@ -1,12 +1,14 @@ +{#if !setupComplete} + +{/if} From f365cf731c464f1e418f8c08fa824b1360a1ab31 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 23 Sep 2021 22:02:35 +0100 Subject: [PATCH 02/22] fix flow of wizard --- .../app/[application]/data/index.svelte | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/data/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/index.svelte index d3b5cff4f2..2d1d94d267 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/index.svelte @@ -1,13 +1,25 @@ -{#if !setupComplete} - -{/if} + From 4f5343ded9d4d8634b8f018ad8ce4884261b88ef Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 24 Sep 2021 10:01:53 +0100 Subject: [PATCH 03/22] fetch tables for datasource plus --- .../modals/DatasourceDetailsModal.svelte | 28 +++++++++++++++---- .../app/[application]/data/index.svelte | 5 +--- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte index dcdd2da497..6d494378b3 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte @@ -1,11 +1,10 @@ saveDatasource()} - confirmText="Continue" - cancelText="Start from scratch" + confirmText={integration.plus + ? "Fetch tables from database" + : "Save and continue to query"} + cancelText="Back" size="M" > (x._id = "bb_internal")).entities.length > 1 || $datasources.list.length >= 1 - $: console.log($datasources.list.length >= 1) - $: console.log( - $datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1 - ) + onMount(() => { if (!setupComplete) { modal.show() From 4c8a2b3a2d69740c42f4b4c46da61237fe6670a7 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 24 Sep 2021 10:12:30 +0100 Subject: [PATCH 04/22] fix naming of datasources --- .../DatasourceNavigator/modals/DatasourceDetailsModal.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte index 6d494378b3..74c176c534 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte @@ -8,7 +8,7 @@ function prepareData() { let datasource = {} let existingTypeCount = $datasources.list.filter( - ds => ds.type == integration.type + ds => ds.source == integration.type ).length let baseName = IntegrationNames[integration.type] @@ -31,8 +31,8 @@ if (integration.plus) { updateDatasourceSchema(resp) } - await datasources.fetch() await datasources.select(resp["_id"]) + console.log($datasources) notifications.success(`Datasource updated successfully.`) } catch (err) { notifications.error(`Error saving datasource: ${err}`) From b438b3d7b5b95567cf5500f73ff946d56918a438 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 24 Sep 2021 10:19:48 +0100 Subject: [PATCH 05/22] redirect to created datasource --- .../modals/DatasourceDetailsModal.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte index 74c176c534..130037ac23 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceDetailsModal.svelte @@ -1,10 +1,12 @@ saveDatasource()} confirmText={integration.plus ? "Fetch tables from database" @@ -65,6 +65,12 @@ cancelText="Back" size="M" > + + Connect your database to Budibase using the config below. + + + Date: Mon, 27 Sep 2021 09:59:56 +0100 Subject: [PATCH 08/22] trigger internal table modal on modal cancel --- packages/bbui/src/Modal/ModalContent.svelte | 11 ++++++++++- .../modals/CreateDatasourceModal.svelte | 5 ++--- .../modals/DatasourceConfigModal.svelte | 12 ++++++++++-- .../builder/app/[application]/data/index.svelte | 8 +++++++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/bbui/src/Modal/ModalContent.svelte b/packages/bbui/src/Modal/ModalContent.svelte index 678a813a61..09cc4f6c52 100644 --- a/packages/bbui/src/Modal/ModalContent.svelte +++ b/packages/bbui/src/Modal/ModalContent.svelte @@ -14,6 +14,7 @@ export let showConfirmButton = true export let showCloseIcon = true export let onConfirm = undefined + export let onCancel = undefined export let disabled = false export let showDivider = true @@ -28,6 +29,14 @@ } loading = false } + + async function close() { + loading = true + if (!onCancel || (await onCancel()) !== false) { + cancel() + } + loading = false + }
{#if showCancelButton} - + {/if} {#if showConfirmButton}
diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte index 9221cbf083..e29d7d5232 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte @@ -27,15 +27,20 @@ return datasource } async function saveDatasource() { + let success = true try { // Create datasource const resp = await datasources.save(prepareData()) if (integration.plus) { - updateDatasourceSchema(resp) + fetchedSchema = updateDatasourceSchema(resp) } + + if (!fetchedSchema) { + return false + } + await datasources.select(resp._id) - $goto(`./datasource/${resp._id}`) notifications.success(`Datasource updated successfully.`) analytics.captureEvent(Events.DATASOURCE.CREATED, { name: resp.name, @@ -43,6 +48,7 @@ }) } catch (err) { notifications.error(`Error saving datasource: ${err}`) + return false } } @@ -50,8 +56,10 @@ try { await datasources.updateSchema(datasourceJson) await tables.fetch() + return true } catch (err) { notifications.error(`Error updating datasource schema: ${err}`) + return false } } diff --git a/packages/builder/src/pages/builder/app/[application]/data/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/index.svelte index ca457cd1aa..873f721a59 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/index.svelte @@ -7,7 +7,13 @@ let modal $: setupComplete = $datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1 || - $datasources.list.length >= 1 + $datasources.list.length > 1 + + $: console.log( + $datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1 + ) + $: console.log($datasources.list.length >= 1) + $: console.log($datasources.list) onMount(() => { if (!setupComplete) { From 2a4d6ce64592d73216e7ce26af3d8b2d0978c18b Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 27 Sep 2021 10:04:01 +0100 Subject: [PATCH 09/22] fix layout of config modal --- .../modals/DatasourceConfigModal.svelte | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte index e29d7d5232..9221cbf083 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte @@ -27,20 +27,15 @@ return datasource } async function saveDatasource() { - let success = true try { // Create datasource const resp = await datasources.save(prepareData()) if (integration.plus) { - fetchedSchema = updateDatasourceSchema(resp) + updateDatasourceSchema(resp) } - - if (!fetchedSchema) { - return false - } - await datasources.select(resp._id) + $goto(`./datasource/${resp._id}`) notifications.success(`Datasource updated successfully.`) analytics.captureEvent(Events.DATASOURCE.CREATED, { name: resp.name, @@ -48,7 +43,6 @@ }) } catch (err) { notifications.error(`Error saving datasource: ${err}`) - return false } } @@ -56,10 +50,8 @@ try { await datasources.updateSchema(datasourceJson) await tables.fetch() - return true } catch (err) { notifications.error(`Error updating datasource schema: ${err}`) - return false } } From 5ca4da11460cb88109291d77ab2ed859db0b5094 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 28 Sep 2021 12:25:57 +0100 Subject: [PATCH 10/22] check tables can be fetched before saving config --- .../modals/DatasourceConfigModal.svelte | 19 +++-------- .../app/[application]/data/index.svelte | 6 ---- .../builder/src/stores/backend/datasources.js | 7 ++-- .../server/src/api/controllers/datasource.js | 32 +++++++++++++------ 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte index 9221cbf083..56fa26ee0a 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte @@ -3,7 +3,7 @@ import { ModalContent, notifications, Body, Layout } from "@budibase/bbui" import analytics, { Events } from "analytics" import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte" - import { datasources, tables } from "stores/backend" + import { datasources } from "stores/backend" import { IntegrationNames } from "constants" export let integration @@ -27,13 +27,11 @@ return datasource } async function saveDatasource() { + const datasource = prepareData() try { // Create datasource - const resp = await datasources.save(prepareData()) + const resp = await datasources.save(datasource, datasource.plus) - if (integration.plus) { - updateDatasourceSchema(resp) - } await datasources.select(resp._id) $goto(`./datasource/${resp._id}`) notifications.success(`Datasource updated successfully.`) @@ -41,17 +39,10 @@ name: resp.name, source: resp.source, }) + return true } catch (err) { notifications.error(`Error saving datasource: ${err}`) - } - } - - async function updateDatasourceSchema(datasourceJson) { - try { - await datasources.updateSchema(datasourceJson) - await tables.fetch() - } catch (err) { - notifications.error(`Error updating datasource schema: ${err}`) + return false } } diff --git a/packages/builder/src/pages/builder/app/[application]/data/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/index.svelte index 873f721a59..c27ee7b342 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/index.svelte @@ -9,12 +9,6 @@ $datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1 || $datasources.list.length > 1 - $: console.log( - $datasources.list.find(x => (x._id = "bb_internal")).entities.length > 1 - ) - $: console.log($datasources.list.length >= 1) - $: console.log($datasources.list) - onMount(() => { if (!setupComplete) { modal.show() diff --git a/packages/builder/src/stores/backend/datasources.js b/packages/builder/src/stores/backend/datasources.js index 5c6ed3f2cb..f7e689d8ad 100644 --- a/packages/builder/src/stores/backend/datasources.js +++ b/packages/builder/src/stores/backend/datasources.js @@ -58,7 +58,7 @@ export function createDatasourcesStore() { }) return json }, - save: async datasource => { + save: async (datasource, fetchSchema = false) => { let response if (datasource._id) { response = await api.put( @@ -66,7 +66,10 @@ export function createDatasourcesStore() { datasource ) } else { - response = await api.post("/api/datasources", datasource) + response = await api.post("/api/datasources", { + datasource: datasource, + fetchSchema, + }) } const json = await response.json() diff --git a/packages/server/src/api/controllers/datasource.js b/packages/server/src/api/controllers/datasource.js index 4a2fd7d86a..2ff7c7f9b8 100644 --- a/packages/server/src/api/controllers/datasource.js +++ b/packages/server/src/api/controllers/datasource.js @@ -41,15 +41,10 @@ exports.fetch = async function (ctx) { exports.buildSchemaFromDb = async function (ctx) { const db = new CouchDB(ctx.appId) - const datasourceId = ctx.params.datasourceId - const datasource = await db.get(datasourceId) + const datasource = await db.get(ctx.params.datasourceId) - const Connector = integrations[datasource.source] - - // Connect to the DB and build the schema - const connector = new Connector(datasource.config) - await connector.buildSchema(datasource._id, datasource.entities) - datasource.entities = connector.tables + const tables = await buildSchemaHelper(datasource) + datasource.entities = tables const response = await db.put(datasource) datasource._rev = response.rev @@ -81,12 +76,18 @@ exports.update = async function (ctx) { exports.save = async function (ctx) { const db = new CouchDB(ctx.appId) - const plus = ctx.request.body.plus + const plus = ctx.request.body.datasource.plus + const fetchSchema = ctx.request.body.fetchSchema const datasource = { _id: generateDatasourceID({ plus }), type: plus ? DocumentTypes.DATASOURCE_PLUS : DocumentTypes.DATASOURCE, - ...ctx.request.body, + ...ctx.request.body.datasource, + } + + if (fetchSchema) { + let tables = await buildSchemaHelper(datasource) + datasource.entities = tables } const response = await db.put(datasource) @@ -133,3 +134,14 @@ exports.query = async function (ctx) { ctx.throw(400, err) } } + +const buildSchemaHelper = async datasource => { + const Connector = integrations[datasource.source] + + // Connect to the DB and build the schema + const connector = new Connector(datasource.config) + await connector.buildSchema(datasource._id, datasource.entities) + datasource.entities = connector.tables + + return connector.tables +} From fa4f0b07f4ea7cc2551fbc6b644a64ae6de67134 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 28 Sep 2021 12:26:38 +0100 Subject: [PATCH 11/22] update cypress tests to account for new modal --- packages/builder/cypress.json | 4 ++-- .../cypress/integration/createTable.spec.js | 6 ++--- packages/builder/cypress/support/commands.js | 22 ++++++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/builder/cypress.json b/packages/builder/cypress.json index 0908f2c839..669ee5af34 100644 --- a/packages/builder/cypress.json +++ b/packages/builder/cypress.json @@ -1,9 +1,9 @@ { - "baseUrl": "http://localhost:10001/builder/", + "baseUrl": "http://localhost:10000/builder/", "video": true, "projectId": "bmbemn", "env": { - "PORT": "10001", + "PORT": "10000", "JWT_SECRET": "test" } } diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index eda72ba36d..a0d741910c 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -6,7 +6,7 @@ context("Create a Table", () => { it("should create a new Table", () => { cy.createTable("dog") - + cy.wait(1000) // Check if Table exists cy.get(".table-title h1").should("have.text", "dog") }) @@ -36,7 +36,7 @@ context("Create a Table", () => { it("edits a row", () => { cy.contains("button", "Edit").click({ force: true }) cy.wait(1000) - cy.get(".spectrum-Modal input").type("Updated") + cy.get(".spectrum-Modal input").type("RoverUpdated") cy.contains("Save").click() cy.contains("RoverUpdated").should("have.text", "RoverUpdated") }) @@ -62,7 +62,7 @@ context("Create a Table", () => { it("deletes a table", () => { cy.get(".actions > :nth-child(1) > .icon > .spectrum-Icon > use") - .first() + .eq(1) .click({ force: true }) cy.get(".spectrum-Menu > :nth-child(2)").click() cy.contains("Delete Table").click() diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index ea6ca81e66..d681fda8ad 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -35,8 +35,11 @@ Cypress.Commands.add("createApp", name => { .within(() => { cy.get("input").eq(0).type(name).should("have.value", name).blur() cy.get(".spectrum-ButtonGroup").contains("Create app").click() + cy.wait(7000) }) .then(() => { + // Because we show the datasource modal on entry, we need to create a table to get rid of the modal in the future + cy.createInitialDatasource("initialTable") cy.expandBudibaseConnection() cy.get(".nav-item.selected > .content").should("be.visible") }) @@ -69,11 +72,28 @@ Cypress.Commands.add("createTestTableWithData", () => { cy.addColumn("dog", "age", "Number") }) -Cypress.Commands.add("createTable", tableName => { +Cypress.Commands.add("createInitialDatasource", tableName => { // Enter table name + cy.get(".spectrum-Modal").within(() => { + cy.contains("Budibase DB").trigger("mouseover").click().click() + cy.wait(1000) + cy.contains("Continue").click() + }) + + cy.get(".spectrum-Modal").within(() => { + cy.wait(1000) + cy.get("input").first().type(tableName).blur() + cy.get(".spectrum-ButtonGroup").contains("Create").click() + }) + cy.contains(tableName).should("be.visible") +}) + +Cypress.Commands.add("createTable", tableName => { cy.contains("Budibase DB").click() cy.contains("Create new table").click() + cy.get(".spectrum-Modal").within(() => { + cy.wait(1000) cy.get("input").first().type(tableName).blur() cy.get(".spectrum-ButtonGroup").contains("Create").click() }) From d1280dcf887456077501ce111d5aac282a36be69 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 28 Sep 2021 12:29:54 +0100 Subject: [PATCH 12/22] update modal button text --- .../DatasourceNavigator/modals/CreateDatasourceModal.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte index bbf3ec22ee..be0e83f80c 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte @@ -68,7 +68,7 @@ disabled={!Object.keys(integration).length} title="Data" confirmText="Continue" - cancelText="Start from scratch" + cancelText="Create a new table with Budibase DB" size="M" onCancel={() => internalTableModal.show()} onConfirm={() => { From 22bbbb5ba488bd72b88055561b02cdd614a705bd Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 28 Sep 2021 15:29:42 +0100 Subject: [PATCH 13/22] fix tests --- packages/server/src/api/controllers/datasource.js | 1 + packages/server/src/api/routes/tests/query.spec.js | 12 ++++++++---- packages/server/src/tests/utilities/structures.js | 10 ++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/server/src/api/controllers/datasource.js b/packages/server/src/api/controllers/datasource.js index 2ff7c7f9b8..7ebe8b9a5b 100644 --- a/packages/server/src/api/controllers/datasource.js +++ b/packages/server/src/api/controllers/datasource.js @@ -75,6 +75,7 @@ exports.update = async function (ctx) { } exports.save = async function (ctx) { + console.log(ctx.request.body) const db = new CouchDB(ctx.appId) const plus = ctx.request.body.datasource.plus const fetchSchema = ctx.request.body.fetchSchema diff --git a/packages/server/src/api/routes/tests/query.spec.js b/packages/server/src/api/routes/tests/query.spec.js index eadd475ed4..716817509b 100644 --- a/packages/server/src/api/routes/tests/query.spec.js +++ b/packages/server/src/api/routes/tests/query.spec.js @@ -1,6 +1,7 @@ // mock out postgres for this jest.mock("pg") +const { findLastKey } = require("lodash/fp") const setup = require("./utilities") const { checkBuilderEndpoint } = require("./utilities/TestFunctions") const { basicQuery, basicDatasource } = setup.structures @@ -19,10 +20,10 @@ describe("/queries", () => { }) async function createInvalidIntegration() { - const datasource = await config.createDatasource({ - ...basicDatasource(), + const datasource = await config.createDatasource({datasource: { + ...basicDatasource().datasource, source: "INVALID_INTEGRATION", - }) + }}) const query = await config.createQuery() return { datasource, query } } @@ -183,11 +184,14 @@ describe("/queries", () => { }) it("should fail with invalid integration type", async () => { - const { query } = await createInvalidIntegration() + const { query, datasource } = await createInvalidIntegration() await request .post(`/api/queries/${query._id}`) .send({ + datasourceId: datasource._id, parameters: {}, + fields: {}, + queryVerb: "read", }) .set(config.defaultHeaders()) .expect(400) diff --git a/packages/server/src/tests/utilities/structures.js b/packages/server/src/tests/utilities/structures.js index e4b2c7e1f0..9c900fec09 100644 --- a/packages/server/src/tests/utilities/structures.js +++ b/packages/server/src/tests/utilities/structures.js @@ -70,10 +70,12 @@ exports.basicRole = () => { exports.basicDatasource = () => { return { - type: "datasource", - name: "Test", - source: "POSTGRES", - config: {}, + datasource: { + type: "datasource", + name: "Test", + source: "POSTGRES", + config: {}, + }, } } From b8772ad9fb187790a0bb7bf150988594f0a5ade9 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 28 Sep 2021 15:49:39 +0100 Subject: [PATCH 14/22] fix cypress --- packages/builder/cypress.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/builder/cypress.json b/packages/builder/cypress.json index 669ee5af34..0908f2c839 100644 --- a/packages/builder/cypress.json +++ b/packages/builder/cypress.json @@ -1,9 +1,9 @@ { - "baseUrl": "http://localhost:10000/builder/", + "baseUrl": "http://localhost:10001/builder/", "video": true, "projectId": "bmbemn", "env": { - "PORT": "10000", + "PORT": "10001", "JWT_SECRET": "test" } } From 27850ab248b935cea714f19c0ab2c090e7234a27 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 28 Sep 2021 19:29:25 +0100 Subject: [PATCH 15/22] cypress tests... --- packages/builder/cypress/integration/createTable.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index a0d741910c..a510eb0af1 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -62,7 +62,7 @@ context("Create a Table", () => { it("deletes a table", () => { cy.get(".actions > :nth-child(1) > .icon > .spectrum-Icon > use") - .eq(1) + .first() .click({ force: true }) cy.get(".spectrum-Menu > :nth-child(2)").click() cy.contains("Delete Table").click() From 03d7ffc09ce4bc1ac546a923eef52fd695a585f8 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 28 Sep 2021 22:37:04 +0100 Subject: [PATCH 16/22] test cypress fix --- packages/builder/cypress/integration/createTable.spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index a510eb0af1..8e44b59c78 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -1,3 +1,4 @@ +/* context("Create a Table", () => { before(() => { cy.login() @@ -69,3 +70,4 @@ context("Create a Table", () => { cy.contains("dog").should("not.exist") }) }) +*/ \ No newline at end of file From 7d1310d56110dbda0c9231f7b73384f3bcb9ead4 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 29 Sep 2021 09:53:31 +0100 Subject: [PATCH 17/22] fix cypress tests again --- packages/builder/cypress/integration/createTable.spec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index 8e44b59c78..f6748e7224 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -1,4 +1,3 @@ -/* context("Create a Table", () => { before(() => { cy.login() @@ -37,7 +36,7 @@ context("Create a Table", () => { it("edits a row", () => { cy.contains("button", "Edit").click({ force: true }) cy.wait(1000) - cy.get(".spectrum-Modal input").type("RoverUpdated") + cy.get(".spectrum-Modal input").type("Updated") cy.contains("Save").click() cy.contains("RoverUpdated").should("have.text", "RoverUpdated") }) @@ -70,4 +69,3 @@ context("Create a Table", () => { cy.contains("dog").should("not.exist") }) }) -*/ \ No newline at end of file From f7984d3dbeee4c6b8a8fbc07110b790f9e5a692c Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 29 Sep 2021 10:11:52 +0100 Subject: [PATCH 18/22] fix mysql ssl --- packages/server/src/integrations/mysql.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index c17cca0745..8b81f68733 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -84,7 +84,7 @@ module MySQLModule { required: true, }, ssl: { - type: DatasourceFieldTypes.OBJECT, + type: DatasourceFieldTypes.BOOLEAN, required: false, }, }, From ebd26cb42e61b016a9fffa0343f42e2f66bf7463 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 29 Sep 2021 11:27:58 +0100 Subject: [PATCH 19/22] cypress fix???? --- packages/builder/cypress/integration/createTable.spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index f6748e7224..faaae3f8a3 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -36,7 +36,8 @@ context("Create a Table", () => { it("edits a row", () => { cy.contains("button", "Edit").click({ force: true }) cy.wait(1000) - cy.get(".spectrum-Modal input").type("Updated") + cy.get(".spectrum-Modal input").clear() + cy.get(".spectrum-Modal input").type("RoverUpdated") cy.contains("Save").click() cy.contains("RoverUpdated").should("have.text", "RoverUpdated") }) @@ -62,7 +63,7 @@ context("Create a Table", () => { it("deletes a table", () => { cy.get(".actions > :nth-child(1) > .icon > .spectrum-Icon > use") - .first() + .eq(1) .click({ force: true }) cy.get(".spectrum-Menu > :nth-child(2)").click() cy.contains("Delete Table").click() From 42e38ad8761a18360ae0f39a3a6b1a8e1c315d21 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 29 Sep 2021 13:02:30 +0100 Subject: [PATCH 20/22] update ssl ux --- .../IntegrationConfigForm.svelte | 19 +++++++++++++++++-- .../integration/KeyValueBuilder.svelte | 5 +++-- packages/server/src/integrations/mysql.ts | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte index 4541052acf..f67a46d9a1 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte @@ -1,20 +1,28 @@
{#each Object.keys(schema) as configKey} {#if schema[configKey].type === "object"} - +
+ + +
{:else if schema[configKey].type === "boolean"}
@@ -42,4 +50,11 @@ grid-gap: var(--spacing-l); align-items: center; } + + .form-row.ssl { + display: grid; + grid-template-columns: 20% 20%; + grid-gap: var(--spacing-l); + align-items: center; + } diff --git a/packages/builder/src/components/integration/KeyValueBuilder.svelte b/packages/builder/src/components/integration/KeyValueBuilder.svelte index 83977fa2a8..04ab56103e 100644 --- a/packages/builder/src/components/integration/KeyValueBuilder.svelte +++ b/packages/builder/src/components/integration/KeyValueBuilder.svelte @@ -4,6 +4,7 @@ export let defaults export let object = defaults || {} export let readOnly + export let noAddButton let fields = Object.entries(object).map(([name, value]) => ({ name, value })) @@ -12,7 +13,7 @@ {} ) - function addEntry() { + export function addEntry() { fields = [...fields, {}] } @@ -32,7 +33,7 @@ {/if} {/each}
-{#if !readOnly} +{#if !readOnly && !noAddButton}
diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index 8b81f68733..c17cca0745 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -84,7 +84,7 @@ module MySQLModule { required: true, }, ssl: { - type: DatasourceFieldTypes.BOOLEAN, + type: DatasourceFieldTypes.OBJECT, required: false, }, }, From e0e4048b37ffb53bacfc202e6e95aee95f797eef Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 30 Sep 2021 10:39:21 +0100 Subject: [PATCH 21/22] remove log statement --- packages/server/src/api/controllers/datasource.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/server/src/api/controllers/datasource.js b/packages/server/src/api/controllers/datasource.js index 7ebe8b9a5b..2ff7c7f9b8 100644 --- a/packages/server/src/api/controllers/datasource.js +++ b/packages/server/src/api/controllers/datasource.js @@ -75,7 +75,6 @@ exports.update = async function (ctx) { } exports.save = async function (ctx) { - console.log(ctx.request.body) const db = new CouchDB(ctx.appId) const plus = ctx.request.body.datasource.plus const fetchSchema = ctx.request.body.fetchSchema From 978f08f30dacde5777cedab19042802087b5dbe6 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 30 Sep 2021 10:50:27 +0100 Subject: [PATCH 22/22] remove create budibase db button --- .../DatasourceNavigator/modals/CreateDatasourceModal.svelte | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte index be0e83f80c..0a04d8dc73 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte @@ -68,9 +68,8 @@ disabled={!Object.keys(integration).length} title="Data" confirmText="Continue" - cancelText="Create a new table with Budibase DB" + showCancelButton={false} size="M" - onCancel={() => internalTableModal.show()} onConfirm={() => { chooseNextModal() }}