From d40fb215f9debd38e940e4e07accdc9338c1fc06 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 18 May 2021 22:14:27 +0100 Subject: [PATCH 1/2] Adding the ability to create options based on CSV, this will use the import data to create options. --- packages/bbui/src/Typography/Body.svelte | 2 +- packages/bbui/src/Typography/Heading.svelte | 2 +- .../TableNavigator/TableDataImport.svelte | 12 ++++++++---- .../modals/CreateTableModal.svelte | 15 ++++++++++++--- .../src/components/login/ForgotForm.svelte | 8 +++++--- .../src/components/login/ResetForm.svelte | 5 +++-- .../server/src/api/controllers/table/utils.js | 17 ++++++++++------- packages/server/src/utilities/csvParser.js | 12 +++++++----- 8 files changed, 47 insertions(+), 26 deletions(-) diff --git a/packages/bbui/src/Typography/Body.svelte b/packages/bbui/src/Typography/Body.svelte index ec32e54140..13e83434e4 100644 --- a/packages/bbui/src/Typography/Body.svelte +++ b/packages/bbui/src/Typography/Body.svelte @@ -8,7 +8,7 @@

diff --git a/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte b/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte index ba904061a3..42ab2b0406 100644 --- a/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte +++ b/packages/builder/src/components/backend/TableNavigator/TableDataImport.svelte @@ -1,5 +1,5 @@ diff --git a/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte b/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte index e870bc98bb..03d37ca6b5 100644 --- a/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte +++ b/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte @@ -3,7 +3,14 @@ import { store } from "builderStore" import { tables } from "stores/backend" import { notifications } from "@budibase/bbui" - import { Input, Label, ModalContent, Toggle, Divider } from "@budibase/bbui" + import { + Input, + Label, + ModalContent, + Toggle, + Divider, + Layout, + } from "@budibase/bbui" import TableDataImport from "../TableDataImport.svelte" import analytics from "analytics" import screenTemplates from "builderStore/store/screenTemplates" @@ -123,8 +130,10 @@ bind:value={createAutoscreens} />
- - + + + +
diff --git a/packages/builder/src/components/login/ForgotForm.svelte b/packages/builder/src/components/login/ForgotForm.svelte index afadf9f4cf..25d72228ef 100644 --- a/packages/builder/src/components/login/ForgotForm.svelte +++ b/packages/builder/src/components/login/ForgotForm.svelte @@ -30,12 +30,14 @@ Forgotten your password? - No problem! Just enter your account's email address and we'll send - you a link to reset it. + No problem! Just enter your account's email address and we'll send you + a link to reset it. - + diff --git a/packages/builder/src/components/login/ResetForm.svelte b/packages/builder/src/components/login/ResetForm.svelte index 4ae19b1ab1..83e9ab7a6e 100644 --- a/packages/builder/src/components/login/ResetForm.svelte +++ b/packages/builder/src/components/login/ResetForm.svelte @@ -16,7 +16,6 @@ } catch (err) { notifications.error("Unable to reset password") } - } @@ -33,7 +32,9 @@ - + diff --git a/packages/server/src/api/controllers/table/utils.js b/packages/server/src/api/controllers/table/utils.js index 3cf64e8e31..990840af06 100644 --- a/packages/server/src/api/controllers/table/utils.js +++ b/packages/server/src/api/controllers/table/utils.js @@ -6,7 +6,7 @@ const { InternalTables, } = require("../../../db/utils") const { isEqual } = require("lodash/fp") -const { AutoFieldSubTypes } = require("../../../constants") +const { AutoFieldSubTypes, FieldTypes } = require("../../../constants") const { inputProcessing } = require("../../../utilities/rowProcessor") const { USERS_TABLE_SCHEMA } = require("../../../constants") @@ -72,18 +72,21 @@ exports.handleDataImport = async (appId, user, table, dataImport) => { row._id = generateRowID(table._id) row.tableId = table._id const processed = inputProcessing(user, table, row) + table = processed.table row = processed.row - // these auto-fields will never actually link anywhere (always builder) for (let [fieldName, schema] of Object.entries(table.schema)) { + // check whether the options need to be updated for inclusion as part of the data import if ( - schema.autocolumn && - (schema.subtype === AutoFieldSubTypes.CREATED_BY || - schema.subtype === AutoFieldSubTypes.UPDATED_BY) + schema.type === FieldTypes.OPTIONS && + (!schema.constraints.inclusion || + schema.constraints.inclusion.indexOf(row[fieldName]) === -1) ) { - delete row[fieldName] + schema.constraints.inclusion = [ + ...schema.constraints.inclusion, + row[fieldName], + ] } } - table = processed.table data[i] = row } diff --git a/packages/server/src/utilities/csvParser.js b/packages/server/src/utilities/csvParser.js index 3ae020eb65..0d8b12cc0a 100644 --- a/packages/server/src/utilities/csvParser.js +++ b/packages/server/src/utilities/csvParser.js @@ -1,14 +1,16 @@ const csv = require("csvtojson") +const { FieldTypes } = require("../constants") const VALIDATORS = { - string: () => true, - number: attribute => !isNaN(Number(attribute)), - datetime: attribute => !isNaN(new Date(attribute).getTime()), + [FieldTypes.STRING]: () => true, + [FieldTypes.OPTIONS]: () => true, + [FieldTypes.NUMBER]: attribute => !isNaN(Number(attribute)), + [FieldTypes.DATETIME]: attribute => !isNaN(new Date(attribute).getTime()), } const PARSERS = { - number: attribute => Number(attribute), - datetime: attribute => new Date(attribute).toISOString(), + [FieldTypes.NUMBER]: attribute => Number(attribute), + [FieldTypes.DATETIME]: attribute => new Date(attribute).toISOString(), } function parse(csvString, parsers) { From 31f16090ee6ede912f5c96c2249e246ab688fd42 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 19 May 2021 11:27:19 +0100 Subject: [PATCH 2/2] Fixing test cases. --- .../server/src/api/controllers/application.js | 4 ++-- .../server/src/api/routes/tests/row.spec.js | 18 ------------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index b9f9dd8c5a..157060e855 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -210,7 +210,7 @@ exports.create = async function (ctx) { exports.update = async function (ctx) { const url = await getAppUrlIfNotInUse(ctx) const db = new CouchDB(ctx.params.appId) - const application = await db.get(ctx.params.appId) + const application = await db.get(DocumentTypes.APP_METADATA) const data = ctx.request.body const newData = { ...application, ...data, url } @@ -231,7 +231,7 @@ exports.update = async function (ctx) { exports.delete = async function (ctx) { const db = new CouchDB(ctx.params.appId) - const app = await db.get(ctx.params.appId) + const app = await db.get(DocumentTypes.APP_METADATA) const result = await db.destroy() /* istanbul ignore next */ if (!env.isTest()) { diff --git a/packages/server/src/api/routes/tests/row.spec.js b/packages/server/src/api/routes/tests/row.spec.js index fb8ff96efa..f67d6254db 100644 --- a/packages/server/src/api/routes/tests/row.spec.js +++ b/packages/server/src/api/routes/tests/row.spec.js @@ -304,24 +304,6 @@ describe("/rows", () => { }) }) - describe("search", () => { - it("should run a search on the table", async () => { - const res = await request - .post(`/api/${table._id}/rows/search`) - .send({ - query: { - name: "Test", - }, - pagination: { pageSize: 25 } - }) - .set(config.defaultHeaders()) - .expect('Content-Type', /json/) - .expect(200) - expect(res.body.rows.length).toEqual(1) - expect(res.body.bookmark).toBeDefined() - }) - }) - describe("fetchView", () => { it("should be able to fetch tables contents via 'view'", async () => { const row = await config.createRow()