Merge pull request #1502 from Budibase/feature/csv-options

CSV options
This commit is contained in:
Michael Drury 2021-05-19 15:56:45 +01:00 committed by GitHub
commit b5b45ad1dc
10 changed files with 49 additions and 46 deletions

View File

@ -8,7 +8,7 @@
</script>
<p
style="{textAlign ? `text-align:${textAlign}` : ``}"
style={textAlign ? `text-align:${textAlign}` : ``}
class:noPadding
class="spectrum-Body spectrum-Body--size{size}"
class:spectrum-Body--serif={serif}

View File

@ -8,7 +8,7 @@
</script>
<h1
style="{textAlign ? `text-align:${textAlign}` : ``}"
style={textAlign ? `text-align:${textAlign}` : ``}
class:noPadding
class="spectrum-Heading spectrum-Heading--size{size}"
>

View File

@ -1,5 +1,5 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { Select } from "@budibase/bbui"
import { notifications } from "@budibase/bbui"
import { FIELDS } from "constants/backend"
import api from "builderStore/api"
@ -99,15 +99,19 @@
const typeOptions = [
{
label: "Text",
value: "string",
value: FIELDS.STRING.type,
},
{
label: "Number",
value: "number",
value: FIELDS.NUMBER.type,
},
{
label: "Date",
value: "datetime",
value: FIELDS.DATETIME.type,
},
{
label: "Options",
value: FIELDS.OPTIONS.type,
},
]
</script>

View File

@ -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}
/>
<div>
<Layout gap="XS" noPadding>
<Label grey extraSmall>Create Table from CSV (Optional)</Label>
<TableDataImport bind:dataImport />
</Layout>
</div>
</ModalContent>

View File

@ -30,12 +30,14 @@
<Layout gap="XS" noPadding>
<Heading textAlign="center">Forgotten your password?</Heading>
<Body size="S" textAlign="center">
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.
</Body>
<Input label="Email" bind:value={email} />
</Layout>
<Button cta on:click={forgot} disabled={!email}>Reset your password</Button>
<Button cta on:click={forgot} disabled={!email}
>Reset your password</Button
>
</Layout>
</div>
</div>

View File

@ -16,7 +16,6 @@
} catch (err) {
notifications.error("Unable to reset password")
}
}
</script>
@ -33,7 +32,9 @@
</Body>
<PasswordRepeatInput bind:password bind:error />
</Layout>
<Button cta on:click={reset} disabled={error || !resetCode}>Reset your password</Button>
<Button cta on:click={reset} disabled={error || !resetCode}
>Reset your password</Button
>
</Layout>
</div>
</div>

View File

@ -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()) {

View File

@ -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)
row = processed.row
// these auto-fields will never actually link anywhere (always builder)
for (let [fieldName, schema] of Object.entries(table.schema)) {
if (
schema.autocolumn &&
(schema.subtype === AutoFieldSubTypes.CREATED_BY ||
schema.subtype === AutoFieldSubTypes.UPDATED_BY)
) {
delete row[fieldName]
}
}
table = processed.table
row = processed.row
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.type === FieldTypes.OPTIONS &&
(!schema.constraints.inclusion ||
schema.constraints.inclusion.indexOf(row[fieldName]) === -1)
) {
schema.constraints.inclusion = [
...schema.constraints.inclusion,
row[fieldName],
]
}
}
data[i] = row
}

View File

@ -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()

View File

@ -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) {