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 1a21306dd2
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",
"packages": [
"packages/*"

View File

@ -1,6 +1,6 @@
{
"name": "@budibase/builder",
"version": "0.2.1",
"version": "0.2.2",
"license": "AGPL-3.0",
"private": true,
"scripts": {
@ -64,7 +64,7 @@
},
"dependencies": {
"@budibase/bbui": "^1.43.1",
"@budibase/client": "^0.2.1",
"@budibase/client": "^0.2.2",
"@budibase/colorpicker": "^1.0.1",
"@fortawesome/fontawesome-free": "^5.14.0",
"@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 api from "../api"
@ -62,16 +62,30 @@ export const getBackendUiStore = () => {
}),
save: async 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
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 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
if (field.name && field.name !== key) {
updatedTable.schema[field.name] = field
updatedTable._rename = { old: key, updated: field.name }
delete updatedTable.schema[key]
}
// finally record this field has been used
fieldNames.push(key.toLowerCase())
}
const SAVE_TABLE_URL = `/api/tables`

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -41,6 +41,18 @@ exports.save = async function(ctx) {
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
let { _rename } = tableToSave
if (_rename && _rename.old === _rename.updated) {
@ -50,9 +62,9 @@ exports.save = async function(ctx) {
// rename row fields when table column is renamed
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) {
throw "Cannot rename the display column."
ctx.throw(400, "Cannot rename the display column.")
} else if (_rename) {
const rows = await db.allDocs(
getRowParams(tableToSave._id, null, {

View File

@ -1,5 +1,10 @@
const LinkController = require("./LinkController")
const { IncludeDocs, getLinkDocuments, createLinkView } = require("./linkUtils")
const {
IncludeDocs,
getLinkDocuments,
createLinkView,
getUniqueByProp,
} = require("./linkUtils")
const _ = require("lodash")
/**
@ -110,7 +115,12 @@ exports.attachLinkInfo = async (instanceId, rows) => {
// now iterate through the rows and all field information
for (let row of rows) {
// 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) {
// work out which link pertains to this row
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"
},
"devDependencies": {
"@budibase/client": "^0.2.1",
"@budibase/client": "^0.2.2",
"@rollup/plugin-commonjs": "^11.1.0",
"lodash": "^4.17.15",
"rollup": "^2.11.2",
@ -31,7 +31,7 @@
"keywords": [
"svelte"
],
"version": "0.2.1",
"version": "0.2.2",
"license": "MIT",
"gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691",
"dependencies": {

View File

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