diff --git a/packages/builder/src/builderStore/fetchBindableProperties.js b/packages/builder/src/builderStore/fetchBindableProperties.js
index 081d643637..90e2de2041 100644
--- a/packages/builder/src/builderStore/fetchBindableProperties.js
+++ b/packages/builder/src/builderStore/fetchBindableProperties.js
@@ -90,6 +90,8 @@ const contextToBindables = (tables, walkResult) => context => {
runtimeBinding: `${contextParentPath}data.${key}`,
// how the binding exressions looks to the user of the builder
readableBinding: `${context.instance._instanceName}.${table.name}.${key}`,
+ // table / view info
+ table: context.table,
})
// see TableViewSelect.svelte for the format of context.table
diff --git a/packages/builder/src/components/backend/DataTable/popovers/FilterPopover.svelte b/packages/builder/src/components/backend/DataTable/popovers/FilterPopover.svelte
index c6d00f2875..5e8b5d1d77 100644
--- a/packages/builder/src/components/backend/DataTable/popovers/FilterPopover.svelte
+++ b/packages/builder/src/components/backend/DataTable/popovers/FilterPopover.svelte
@@ -79,7 +79,7 @@
}
function fieldOptions(field) {
- return viewTable.schema[field].type === "string"
+ return viewTable.schema[field].type === "options"
? viewTable.schema[field].constraints.inclusion
: [true, false]
}
diff --git a/packages/builder/src/components/userInterface/NewScreenModal.svelte b/packages/builder/src/components/userInterface/NewScreenModal.svelte
index 403a982d6d..5bf7931a0b 100644
--- a/packages/builder/src/components/userInterface/NewScreenModal.svelte
+++ b/packages/builder/src/components/userInterface/NewScreenModal.svelte
@@ -3,6 +3,7 @@
import { Input, Button, Spacer, Select, ModalContent } from "@budibase/bbui"
import getTemplates from "builderStore/store/screenTemplates"
import { some } from "lodash/fp"
+ import analytics from "analytics"
const CONTAINER = "@budibase/standard-components/container"
@@ -29,7 +30,7 @@
const templateChanged = newTemplateIndex => {
if (newTemplateIndex === undefined) return
-
+ const template = templates[newTemplateIndex]
draftScreen = templates[newTemplateIndex].create()
if (draftScreen.props._instanceName) {
name = draftScreen.props._instanceName
@@ -63,6 +64,13 @@
store.createScreen(draftScreen)
+ if (templateIndex !== undefined) {
+ const template = templates[templateIndex]
+ analytics.captureEvent("Screen Created", {
+ template: template.id || template.name,
+ })
+ }
+
finished()
}
diff --git a/packages/builder/src/components/userInterface/ScreenSelect.svelte b/packages/builder/src/components/userInterface/ScreenSelect.svelte
index 412f0719fc..1022289d45 100644
--- a/packages/builder/src/components/userInterface/ScreenSelect.svelte
+++ b/packages/builder/src/components/userInterface/ScreenSelect.svelte
@@ -1,18 +1,75 @@
diff --git a/packages/builder/src/components/userInterface/pagesParsing/createProps.js b/packages/builder/src/components/userInterface/pagesParsing/createProps.js
index 44d23c5c3e..b628b6e15b 100644
--- a/packages/builder/src/components/userInterface/pagesParsing/createProps.js
+++ b/packages/builder/src/components/userInterface/pagesParsing/createProps.js
@@ -1,4 +1,4 @@
-import { isString, isUndefined } from "lodash/fp"
+import { isString, isUndefined, cloneDeep } from "lodash/fp"
import { TYPE_MAP } from "./types"
import { assign } from "lodash"
import { uuid } from "builderStore/uuid"
@@ -83,13 +83,13 @@ const parsePropDef = propDef => {
if (isString(propDef)) {
if (!TYPE_MAP[propDef]) return error(`Type ${propDef} is not recognised.`)
- return TYPE_MAP[propDef].default
+ return cloneDeep(TYPE_MAP[propDef].default)
}
const type = TYPE_MAP[propDef.type]
if (!type) return error(`Type ${propDef.type} is not recognised.`)
- return propDef.default
+ return cloneDeep(propDef.default)
}
export const arrayElementComponentName = (parentComponentName, arrayPropName) =>
diff --git a/packages/builder/src/components/userInterface/pagesParsing/types.js b/packages/builder/src/components/userInterface/pagesParsing/types.js
index f85c83a733..9050cb72b7 100644
--- a/packages/builder/src/components/userInterface/pagesParsing/types.js
+++ b/packages/builder/src/components/userInterface/pagesParsing/types.js
@@ -10,7 +10,6 @@ export const TYPE_MAP = {
},
options: {
default: [],
- options: [],
},
event: {
default: [],
diff --git a/packages/builder/src/components/userInterface/temporaryPanelStructure.js b/packages/builder/src/components/userInterface/temporaryPanelStructure.js
index e38ac63727..07a646e9dd 100644
--- a/packages/builder/src/components/userInterface/temporaryPanelStructure.js
+++ b/packages/builder/src/components/userInterface/temporaryPanelStructure.js
@@ -356,7 +356,7 @@ export default {
{
label: "destinationUrl",
key: "destinationUrl",
- control: Input,
+ control: ScreenSelect,
placeholder: "/table/_id",
},
],
@@ -405,7 +405,7 @@ export default {
{
label: "Link Url",
key: "linkUrl",
- control: Input,
+ control: ScreenSelect,
placeholder: "Link URL",
},
{
@@ -480,7 +480,7 @@ export default {
{
label: "Link Url",
key: "linkUrl",
- control: Input,
+ control: ScreenSelect,
placeholder: "Link URL",
},
{
diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js
index 55a2d2c6c7..a735e4b864 100644
--- a/packages/builder/src/constants/backend/index.js
+++ b/packages/builder/src/constants/backend/index.js
@@ -15,7 +15,7 @@ export const FIELDS = {
type: "options",
constraints: {
type: "string",
- presence: { allowEmpty: true },
+ presence: false,
inclusion: [],
},
},
@@ -67,7 +67,7 @@ export const FIELDS = {
type: "link",
constraints: {
type: "array",
- presence: { allowEmpty: true },
+ presence: false,
},
},
}
diff --git a/packages/server/src/api/controllers/table.js b/packages/server/src/api/controllers/table.js
index 08854b3bba..df3acaff8a 100644
--- a/packages/server/src/api/controllers/table.js
+++ b/packages/server/src/api/controllers/table.js
@@ -33,6 +33,7 @@ exports.save = async function(ctx) {
views: {},
...rest,
}
+ let renameDocs = []
// if the table obj had an _id then it will have been retrieved
const oldTable = ctx.preExisting
@@ -49,14 +50,11 @@ exports.save = async function(ctx) {
include_docs: true,
})
)
-
- const docs = rows.rows.map(({ doc }) => {
+ renameDocs = rows.rows.map(({ doc }) => {
doc[_rename.updated] = doc[_rename.old]
delete doc[_rename.old]
return doc
})
-
- await db.bulkDocs(docs)
delete tableToSave._rename
}
@@ -69,9 +67,6 @@ exports.save = async function(ctx) {
tableView.schema = tableToSave.schema
}
- const result = await db.post(tableToSave)
- tableToSave._rev = result.rev
-
// update linked rows
await linkRows.updateLinks({
instanceId,
@@ -82,6 +77,14 @@ exports.save = async function(ctx) {
oldTable: oldTable,
})
+ // don't perform any updates until relationships have been
+ // checked by the updateLinks function
+ if (renameDocs.length !== 0) {
+ await db.bulkDocs(renameDocs)
+ }
+ const result = await db.post(tableToSave)
+ tableToSave._rev = result.rev
+
ctx.eventEmitter &&
ctx.eventEmitter.emitTable(`table:save`, instanceId, tableToSave)
@@ -105,18 +108,17 @@ exports.save = async function(ctx) {
exports.destroy = async function(ctx) {
const instanceId = ctx.user.instanceId
const db = new CouchDB(instanceId)
-
const tableToDelete = await db.get(ctx.params.tableId)
- await db.remove(tableToDelete)
-
// Delete all rows for that table
const rows = await db.allDocs(
getRowParams(ctx.params.tableId, null, {
include_docs: true,
})
)
- await db.bulkDocs(rows.rows.map(row => ({ _id: row.id, _deleted: true })))
+ await db.bulkDocs(
+ rows.rows.map(row => ({ ...row.doc, _deleted: true }))
+ )
// update linked rows
await linkRows.updateLinks({
@@ -125,6 +127,9 @@ exports.destroy = async function(ctx) {
table: tableToDelete,
})
+ // don't remove the table itself until very end
+ await db.remove(tableToDelete)
+
ctx.eventEmitter &&
ctx.eventEmitter.emitTable(`table:delete`, instanceId, tableToDelete)
ctx.status = 200
diff --git a/packages/server/src/db/linkedRows/LinkController.js b/packages/server/src/db/linkedRows/LinkController.js
index d8e78ac151..06e4aab1f2 100644
--- a/packages/server/src/db/linkedRows/LinkController.js
+++ b/packages/server/src/db/linkedRows/LinkController.js
@@ -161,7 +161,7 @@ class LinkController {
})
// now add the docs to be deleted to the bulk operation
operations.push(...toDeleteDocs)
- // replace this field with a simple entry to denote there are links
+ // remove the field from this row, link doc will be added to row on way out
delete row[fieldName]
}
}
@@ -234,8 +234,16 @@ class LinkController {
for (let fieldName of Object.keys(schema)) {
const field = schema[fieldName]
if (field.type === "link") {
+ // handle this in a separate try catch, want
+ // the put to bubble up as an error, if can't update
+ // table for some reason
+ let linkedTable
+ try {
+ linkedTable = await this._db.get(field.tableId)
+ } catch (err) {
+ continue
+ }
// create the link field in the other table
- const linkedTable = await this._db.get(field.tableId)
linkedTable.schema[field.fieldName] = {
name: field.fieldName,
type: "link",
diff --git a/packages/server/src/db/linkedRows/index.js b/packages/server/src/db/linkedRows/index.js
index ebbba3ec1d..0932fc665f 100644
--- a/packages/server/src/db/linkedRows/index.js
+++ b/packages/server/src/db/linkedRows/index.js
@@ -42,6 +42,7 @@ exports.updateLinks = async function({
table,
oldTable,
}) {
+ const baseReturnObj = row == null ? table : row
if (instanceId == null) {
throw "Cannot operate without an instance ID."
}
@@ -50,12 +51,16 @@ exports.updateLinks = async function({
arguments[0].tableId = table._id
}
let linkController = new LinkController(arguments[0])
- if (
- !(await linkController.doesTableHaveLinkedFields()) &&
- (oldTable == null ||
- !(await linkController.doesTableHaveLinkedFields(oldTable)))
- ) {
- return row
+ try {
+ if (
+ !(await linkController.doesTableHaveLinkedFields()) &&
+ (oldTable == null ||
+ !(await linkController.doesTableHaveLinkedFields(oldTable)))
+ ) {
+ return baseReturnObj
+ }
+ } catch (err) {
+ return baseReturnObj
}
switch (eventType) {
case EventType.ROW_SAVE:
diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js
index 7577a3b638..d4027df528 100644
--- a/packages/server/src/db/utils.js
+++ b/packages/server/src/db/utils.js
@@ -57,19 +57,26 @@ exports.generateTableID = () => {
/**
* Gets the DB allDocs/query params for retrieving a row.
- * @param {string} tableId The table in which the rows have been stored.
+ * @param {string|null} tableId The table in which the rows have been stored.
* @param {string|null} rowId The ID of the row which is being specifically queried for. This can be
* left null to get all the rows in the table.
* @param {object} otherProps Any other properties to add to the request.
* @returns {object} Parameters which can then be used with an allDocs request.
*/
-exports.getRowParams = (tableId, rowId = null, otherProps = {}) => {
+exports.getRowParams = (
+ tableId = null,
+ rowId = null,
+ otherProps = {}
+) => {
if (tableId == null) {
- throw "Cannot build params for rows without a table ID"
+ return getDocParams(DocumentTypes.ROW, null, otherProps)
+ } else {
+ const endOfKey =
+ rowId == null
+ ? `${tableId}${SEPARATOR}`
+ : `${tableId}${SEPARATOR}${rowId}`
+ return getDocParams(DocumentTypes.ROW, endOfKey, otherProps)
}
- const endOfKey =
- rowId == null ? `${tableId}${SEPARATOR}` : `${tableId}${SEPARATOR}${rowId}`
- return getDocParams(DocumentTypes.ROW, endOfKey, otherProps)
}
/**