Merge branch 'master' of github.com:Budibase/budibase into autoscreen-templates

This commit is contained in:
Andrew Kingston 2020-10-16 12:57:29 +01:00
commit 42469e069d
14 changed files with 66 additions and 43 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "0.2.1", "version": "0.2.2",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*" "packages/*"

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/builder", "name": "@budibase/builder",
"version": "0.2.1", "version": "0.2.2",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"private": true, "private": true,
"scripts": { "scripts": {
@ -64,7 +64,7 @@
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.43.1", "@budibase/bbui": "^1.43.1",
"@budibase/client": "^0.2.1", "@budibase/client": "^0.2.2",
"@budibase/colorpicker": "^1.0.1", "@budibase/colorpicker": "^1.0.1",
"@fortawesome/fontawesome-free": "^5.14.0", "@fortawesome/fontawesome-free": "^5.14.0",
"@sentry/browser": "5.19.1", "@sentry/browser": "5.19.1",

View File

@ -1,4 +1,4 @@
import { writable } from "svelte/store" import { writable, get } from "svelte/store"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import api from "../api" import api from "../api"
@ -62,16 +62,30 @@ export const getBackendUiStore = () => {
}), }),
save: async table => { save: async table => {
const updatedTable = cloneDeep(table) const updatedTable = cloneDeep(table)
const oldTable = get(store).tables.filter(t => t._id === table._id)[0]
const fieldNames = []
// update any renamed schema keys to reflect their names // update any renamed schema keys to reflect their names
for (let key in updatedTable.schema) { for (let key of Object.keys(updatedTable.schema)) {
// if field name has been seen before remove it
if (fieldNames.indexOf(key.toLowerCase()) !== -1) {
delete updatedTable.schema[key]
continue
}
const field = updatedTable.schema[key] const field = updatedTable.schema[key]
const oldField = oldTable?.schema[key]
// if the type has changed then revert back to the old field
if (oldField != null && oldField.type !== field.type) {
updatedTable.schema[key] = oldField
}
// field has been renamed // field has been renamed
if (field.name && field.name !== key) { if (field.name && field.name !== key) {
updatedTable.schema[field.name] = field updatedTable.schema[field.name] = field
updatedTable._rename = { old: key, updated: field.name } updatedTable._rename = { old: key, updated: field.name }
delete updatedTable.schema[key] delete updatedTable.schema[key]
} }
// finally record this field has been used
fieldNames.push(key.toLowerCase())
} }
const SAVE_TABLE_URL = `/api/tables` const SAVE_TABLE_URL = `/api/tables`

View File

@ -132,7 +132,6 @@
font-size: 24px; font-size: 24px;
font-weight: 600; font-weight: 600;
text-rendering: optimizeLegibility; text-rendering: optimizeLegibility;
text-transform: capitalize;
margin-top: 0; margin-top: 0;
display: flex; display: flex;
flex-direction: row; flex-direction: row;

View File

@ -110,9 +110,6 @@
align-items: center; align-items: center;
gap: var(--spacing-xs); gap: var(--spacing-xs);
} }
.container span {
text-transform: capitalize;
}
h5 { h5 {
padding: var(--spacing-xl) 0 0 var(--spacing-xl); padding: var(--spacing-xl) 0 0 var(--spacing-xl);

View File

@ -27,15 +27,12 @@
const joinPath = join("/") const joinPath = join("/")
const normalizedName = name => const normalizedName = name =>
pipe( pipe(name, [
name, trimCharsStart("./"),
[ trimCharsStart("~/"),
trimCharsStart("./"), trimCharsStart("../"),
trimCharsStart("~/"), trimChars(" "),
trimCharsStart("../"), ])
trimChars(" "),
]
)
const changeScreen = screen => { const changeScreen = screen => {
store.setCurrentScreen(screen.props._instanceName) store.setCurrentScreen(screen.props._instanceName)

View File

@ -1,6 +1,6 @@
{ {
"name": "budibase", "name": "budibase",
"version": "0.2.1", "version": "0.2.2",
"description": "Budibase CLI", "description": "Budibase CLI",
"repository": "https://github.com/Budibase/Budibase", "repository": "https://github.com/Budibase/Budibase",
"homepage": "https://www.budibase.com", "homepage": "https://www.budibase.com",
@ -17,7 +17,7 @@
"author": "Budibase", "author": "Budibase",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"@budibase/server": "^0.2.1", "@budibase/server": "^0.2.2",
"@inquirer/password": "^0.0.6-alpha.0", "@inquirer/password": "^0.0.6-alpha.0",
"chalk": "^2.4.2", "chalk": "^2.4.2",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/client", "name": "@budibase/client",
"version": "0.2.1", "version": "0.2.2",
"license": "MPL-2.0", "license": "MPL-2.0",
"main": "dist/budibase-client.js", "main": "dist/budibase-client.js",
"module": "dist/budibase-client.esm.mjs", "module": "dist/budibase-client.esm.mjs",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/server", "name": "@budibase/server",
"version": "0.2.1", "version": "0.2.2",
"description": "Budibase Web Server", "description": "Budibase Web Server",
"main": "src/electron.js", "main": "src/electron.js",
"repository": { "repository": {
@ -42,7 +42,7 @@
"author": "Michael Shanks", "author": "Michael Shanks",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"@budibase/client": "^0.2.1", "@budibase/client": "^0.2.2",
"@koa/router": "^8.0.0", "@koa/router": "^8.0.0",
"@sendgrid/mail": "^7.1.1", "@sendgrid/mail": "^7.1.1",
"@sentry/node": "^5.19.2", "@sentry/node": "^5.19.2",

View File

@ -41,6 +41,18 @@ exports.save = async function(ctx) {
oldTable = await db.get(ctx.request.body._id) oldTable = await db.get(ctx.request.body._id)
} }
// make sure that types don't change of a column, have to remove
// the column if you want to change the type
if (oldTable && oldTable.schema) {
for (let propKey of Object.keys(tableToSave.schema)) {
let column = tableToSave.schema[propKey]
let oldColumn = oldTable.schema[propKey]
if (oldColumn && oldColumn.type !== column.type) {
ctx.throw(400, "Cannot change the type of a column")
}
}
}
// Don't rename if the name is the same // Don't rename if the name is the same
let { _rename } = tableToSave let { _rename } = tableToSave
if (_rename && _rename.old === _rename.updated) { if (_rename && _rename.old === _rename.updated) {
@ -50,9 +62,9 @@ exports.save = async function(ctx) {
// rename row fields when table column is renamed // rename row fields when table column is renamed
if (_rename && tableToSave.schema[_rename.updated].type === "link") { if (_rename && tableToSave.schema[_rename.updated].type === "link") {
throw "Cannot rename a linked field." ctx.throw(400, "Cannot rename a linked column.")
} else if (_rename && tableToSave.primaryDisplay === _rename.old) { } else if (_rename && tableToSave.primaryDisplay === _rename.old) {
throw "Cannot rename the display column." ctx.throw(400, "Cannot rename the display column.")
} else if (_rename) { } else if (_rename) {
const rows = await db.allDocs( const rows = await db.allDocs(
getRowParams(tableToSave._id, null, { getRowParams(tableToSave._id, null, {

View File

@ -1,5 +1,10 @@
const LinkController = require("./LinkController") const LinkController = require("./LinkController")
const { IncludeDocs, getLinkDocuments, createLinkView } = require("./linkUtils") const {
IncludeDocs,
getLinkDocuments,
createLinkView,
getUniqueByProp,
} = require("./linkUtils")
const _ = require("lodash") const _ = require("lodash")
/** /**
@ -110,7 +115,12 @@ exports.attachLinkInfo = async (instanceId, rows) => {
// now iterate through the rows and all field information // now iterate through the rows and all field information
for (let row of rows) { for (let row of rows) {
// get all links for row, ignore fieldName for now // get all links for row, ignore fieldName for now
const linkVals = responses.filter(el => el.thisId === row._id) // have to get unique as the previous table query can
// return duplicates, could be querying for both tables in a relation
const linkVals = getUniqueByProp(
responses.filter(el => el.thisId === row._id),
"id"
)
for (let linkVal of linkVals) { for (let linkVal of linkVals) {
// work out which link pertains to this row // work out which link pertains to this row
if (!(row[linkVal.fieldName] instanceof Array)) { if (!(row[linkVal.fieldName] instanceof Array)) {

View File

@ -92,3 +92,9 @@ exports.getLinkDocuments = async function({
} }
} }
} }
exports.getUniqueByProp = (array, prop) => {
return array.filter((obj, pos, arr) => {
return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos
})
}

View File

@ -13,7 +13,7 @@
"dev:builder": "rollup -cw" "dev:builder": "rollup -cw"
}, },
"devDependencies": { "devDependencies": {
"@budibase/client": "^0.2.1", "@budibase/client": "^0.2.2",
"@rollup/plugin-commonjs": "^11.1.0", "@rollup/plugin-commonjs": "^11.1.0",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"rollup": "^2.11.2", "rollup": "^2.11.2",
@ -31,7 +31,7 @@
"keywords": [ "keywords": [
"svelte" "svelte"
], ],
"version": "0.2.1", "version": "0.2.2",
"license": "MIT", "license": "MIT",
"gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691", "gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691",
"dependencies": { "dependencies": {

View File

@ -11,7 +11,6 @@
import { onMount } from "svelte" import { onMount } from "svelte"
import AgGrid from "@budibase/svelte-ag-grid" import AgGrid from "@budibase/svelte-ag-grid"
import CreateRowButton from "./CreateRow/Button.svelte"
import { import {
TextButton as DeleteButton, TextButton as DeleteButton,
Icon, Icon,
@ -72,7 +71,7 @@
headerCheckboxSelection: i === 0 && canEdit, headerCheckboxSelection: i === 0 && canEdit,
checkboxSelection: i === 0 && canEdit, checkboxSelection: i === 0 && canEdit,
valueSetter: setters.get(schema[key].type), valueSetter: setters.get(schema[key].type),
headerName: key.charAt(0).toUpperCase() + key.slice(1), headerName: key,
field: key, field: key,
hide: shouldHideField(key), hide: shouldHideField(key),
sortable: true, sortable: true,
@ -108,13 +107,6 @@
} }
}) })
const isEditable = type =>
type !== "boolean" &&
type !== "options" &&
// type !== "datetime" &&
type !== "link" &&
type !== "attachment"
const shouldHideField = name => { const shouldHideField = name => {
if (name.startsWith("_")) return true if (name.startsWith("_")) return true
// always 'row' // always 'row'
@ -125,10 +117,6 @@
return false return false
} }
const handleNewRow = async () => {
data = await fetchData(datasource)
}
const handleUpdate = ({ detail }) => { const handleUpdate = ({ detail }) => {
data[detail.row] = detail.data data[detail.row] = detail.data
updateRow(detail.data) updateRow(detail.data)
@ -162,7 +150,6 @@
{#if dataLoaded} {#if dataLoaded}
{#if canAddDelete} {#if canAddDelete}
<div class="controls"> <div class="controls">
<CreateRowButton {_bb} {table} on:newRow={handleNewRow} />
{#if selectedRows.length > 0} {#if selectedRows.length > 0}
<DeleteButton text small on:click={modal.show()}> <DeleteButton text small on:click={modal.show()}>
<Icon name="addrow" /> <Icon name="addrow" />
@ -203,6 +190,7 @@
} }
.controls { .controls {
min-height: 15px;
margin-bottom: var(--spacing-s); margin-bottom: var(--spacing-s);
display: grid; display: grid;
grid-gap: var(--spacing-s); grid-gap: var(--spacing-s);