diff --git a/lerna.json b/lerna.json index 44d7024afe..5f06e73f5e 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.9.38", + "version": "0.9.39", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/auth/package.json b/packages/auth/package.json index e0979c1a09..7faa482e84 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/auth", - "version": "0.9.38", + "version": "0.9.39", "description": "Authentication middlewares for budibase builder and apps", "main": "src/index.js", "author": "Budibase", diff --git a/packages/bbui/package.json b/packages/bbui/package.json index a7d58fa075..018a5f5d15 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/bbui", "description": "A UI solution used in the different Budibase projects.", - "version": "0.9.38", + "version": "0.9.39", "license": "AGPL-3.0", "svelte": "src/index.js", "module": "dist/bbui.es.js", diff --git a/packages/builder/package.json b/packages/builder/package.json index 1499c61c25..32975defa9 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "0.9.38", + "version": "0.9.39", "license": "AGPL-3.0", "private": true, "scripts": { @@ -65,10 +65,10 @@ } }, "dependencies": { - "@budibase/bbui": "^0.9.38", - "@budibase/client": "^0.9.38", + "@budibase/bbui": "^0.9.39", + "@budibase/client": "^0.9.39", "@budibase/colorpicker": "1.1.2", - "@budibase/string-templates": "^0.9.38", + "@budibase/string-templates": "^0.9.39", "@sentry/browser": "5.19.1", "@spectrum-css/page": "^3.0.1", "@spectrum-css/vars": "^3.0.1", diff --git a/packages/builder/src/builderStore/store/screenTemplates/newRowScreen.js b/packages/builder/src/builderStore/store/screenTemplates/newRowScreen.js index be399b4bb8..980f71742b 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/newRowScreen.js +++ b/packages/builder/src/builderStore/store/screenTemplates/newRowScreen.js @@ -35,6 +35,7 @@ const createScreen = table => { const form = makeMainForm() .instanceName("Form") .customProps({ + actionType: "Create", theme: "spectrum--lightest", size: "spectrum--medium", dataSource: { diff --git a/packages/builder/src/builderStore/store/screenTemplates/rowDetailScreen.js b/packages/builder/src/builderStore/store/screenTemplates/rowDetailScreen.js index b0cf694a5d..f15f1de5a4 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/rowDetailScreen.js +++ b/packages/builder/src/builderStore/store/screenTemplates/rowDetailScreen.js @@ -110,6 +110,7 @@ const createScreen = table => { const form = makeMainForm() .instanceName("Form") .customProps({ + actionType: "Update", theme: "spectrum--lightest", size: "spectrum--medium", dataSource: { diff --git a/packages/builder/src/pages/builder/portal/manage/email/index.svelte b/packages/builder/src/pages/builder/portal/manage/email/index.svelte index 44442767a8..46af44ec93 100644 --- a/packages/builder/src/pages/builder/portal/manage/email/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/email/index.svelte @@ -38,17 +38,21 @@ let loading async function saveSmtp() { - try { - // Save your SMTP config - const response = await api.post(`/api/admin/configs`, smtpConfig) + // Save your SMTP config + const response = await api.post(`/api/admin/configs`, smtpConfig) + + if (response.status !== 200) { + const error = await response.text() + let message = error + try { + message = JSON.parse(error).message + } catch (err) {} + notifications.error(`Failed to save email settings, reason: ${message}`) + } else { const json = await response.json() - if (response.status !== 200) throw new Error(json.message) smtpConfig._rev = json._rev smtpConfig._id = json._id - notifications.success(`Settings saved.`) - } catch (err) { - notifications.error(`Failed to save email settings. ${err}`) } } diff --git a/packages/cli/package.json b/packages/cli/package.json index aefd140f7a..0b2f6b54db 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/cli", - "version": "0.9.38", + "version": "0.9.39", "description": "Budibase CLI, for developers, self hosting and migrations.", "main": "src/index.js", "bin": { diff --git a/packages/client/package.json b/packages/client/package.json index 719a88ed3c..65c318c211 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "0.9.38", + "version": "0.9.39", "license": "MPL-2.0", "module": "dist/budibase-client.js", "main": "dist/budibase-client.js", @@ -18,13 +18,13 @@ "dev:builder": "rollup -cw" }, "dependencies": { - "@budibase/string-templates": "^0.9.38", + "@budibase/string-templates": "^0.9.39", "regexparam": "^1.3.0", "shortid": "^2.2.15", "svelte-spa-router": "^3.0.5" }, "devDependencies": { - "@budibase/standard-components": "^0.9.38", + "@budibase/standard-components": "^0.9.39", "@rollup/plugin-commonjs": "^18.0.0", "@rollup/plugin-node-resolve": "^11.2.1", "fs-extra": "^8.1.0", diff --git a/packages/server/package.json b/packages/server/package.json index b26e4df205..56f55ada88 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/server", "email": "hi@budibase.com", - "version": "0.9.38", + "version": "0.9.39", "description": "Budibase Web Server", "main": "src/electron.js", "repository": { @@ -55,9 +55,9 @@ "author": "Budibase", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/auth": "^0.9.38", - "@budibase/client": "^0.9.38", - "@budibase/string-templates": "^0.9.38", + "@budibase/auth": "^0.9.39", + "@budibase/client": "^0.9.39", + "@budibase/string-templates": "^0.9.39", "@elastic/elasticsearch": "7.10.0", "@koa/router": "8.0.0", "@sendgrid/mail": "7.1.1", @@ -110,7 +110,7 @@ "devDependencies": { "@babel/core": "^7.14.3", "@babel/preset-env": "^7.14.4", - "@budibase/standard-components": "^0.9.38", + "@budibase/standard-components": "^0.9.39", "@jest/test-sequencer": "^24.8.0", "babel-jest": "^27.0.2", "docker-compose": "^0.23.6", diff --git a/packages/standard-components/manifest.json b/packages/standard-components/manifest.json index 8f0f63f681..81aa63e1e3 100644 --- a/packages/standard-components/manifest.json +++ b/packages/standard-components/manifest.json @@ -1023,6 +1023,13 @@ "ValidateForm" ], "settings": [ + { + "type": "select", + "label": "Type", + "key": "actionType", + "options": ["Create", "Update"], + "defaultValue": "Create" + }, { "type": "schema", "label": "Schema", diff --git a/packages/standard-components/package.json b/packages/standard-components/package.json index 897b38e957..8e88318439 100644 --- a/packages/standard-components/package.json +++ b/packages/standard-components/package.json @@ -29,11 +29,11 @@ "keywords": [ "svelte" ], - "version": "0.9.38", + "version": "0.9.39", "license": "MIT", "gitHead": "d1836a898cab3f8ab80ee6d8f42be1a9eed7dcdc", "dependencies": { - "@budibase/bbui": "^0.9.38", + "@budibase/bbui": "^0.9.39", "@spectrum-css/page": "^3.0.1", "@spectrum-css/vars": "^3.0.1", "apexcharts": "^3.22.1", diff --git a/packages/standard-components/src/forms/Form.svelte b/packages/standard-components/src/forms/Form.svelte index d73af72a47..327cc70572 100644 --- a/packages/standard-components/src/forms/Form.svelte +++ b/packages/standard-components/src/forms/Form.svelte @@ -8,6 +8,7 @@ export let theme export let size export let disabled = false + export let actionType = "Create" const component = getContext("component") const context = getContext("context") @@ -19,15 +20,29 @@ let fieldMap = {} // Returns the closes data context which isn't a built in context - const getInitialValues = context => { + const getInitialValues = (type, dataSource, context) => { + // Only inherit values for update forms + if (type !== "Update") { + return {} + } + // Only inherit values for forms targetting internal tables + if (!dataSource?.tableId) { + return {} + } + // Don't inherit values representing built in contexts if (["user", "url"].includes(context.closestComponentId)) { return {} } - return context[`${context.closestComponentId}`] || {} + // Only inherit values if the table ID matches + const closestContext = context[`${context.closestComponentId}`] || {} + if (dataSource.tableId !== closestContext?.tableId) { + return {} + } + return closestContext } // Use the closest data context as the initial form values - const initialValues = getInitialValues($context) + const initialValues = getInitialValues(actionType, dataSource, $context) // Form state contains observable data about the form const formState = writable({ values: initialValues, errors: {}, valid: true }) @@ -42,22 +57,11 @@ // Auto columns are always disabled const isAutoColumn = !!schema?.[field]?.autocolumn - if (fieldMap[field] != null) { - // Update disabled property just so that toggling the disabled field - // state in the builder makes updates in real time. - // We only need this because of optimisations which prevent fully - // remounting when settings change. - fieldMap[field].fieldState.update(state => { - state.disabled = disabled || fieldDisabled || isAutoColumn - return state - }) - return fieldMap[field] - } - // Create validation function based on field schema const constraints = schema?.[field]?.constraints const validate = createValidatorFromConstraints(constraints, field, table) + // Construct field object fieldMap[field] = { fieldState: makeFieldState( field, @@ -67,6 +71,17 @@ fieldApi: makeFieldApi(field, defaultValue, validate), fieldSchema: schema?.[field] ?? {}, } + + // Set initial value + const initialValue = get(fieldMap[field].fieldState).value + formState.update(state => ({ + ...state, + values: { + ...state.values, + [field]: initialValue, + }, + })) + return fieldMap[field] }, validate: () => { diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json index eef3409d12..f604c36da3 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/string-templates", - "version": "0.9.38", + "version": "0.9.39", "description": "Handlebars wrapper for Budibase templating.", "main": "src/index.cjs", "module": "dist/bundle.mjs", diff --git a/packages/string-templates/src/index.cjs b/packages/string-templates/src/index.cjs index a14a3efcda..0b4515b815 100644 --- a/packages/string-templates/src/index.cjs +++ b/packages/string-templates/src/index.cjs @@ -16,9 +16,6 @@ registerAll(hbsInstance) * utility function to check if the object is valid */ function testObject(object) { - if (object == null) { - throw "Unable to process null object" - } // JSON stringify will fail if there are any cycles, stops infinite recursion try { JSON.stringify(object) diff --git a/packages/string-templates/test/basic.spec.js b/packages/string-templates/test/basic.spec.js index f5c7c8be75..f9b994be99 100644 --- a/packages/string-templates/test/basic.spec.js +++ b/packages/string-templates/test/basic.spec.js @@ -81,14 +81,14 @@ describe("Test that the object processing works correctly", () => { expect(error).not.toBeNull() }) - it("should fail gracefully when wrong type is passed in", async () => { + it("should be able to handle null objects", async () => { let error = null try { await processObject(null, null) } catch (err) { error = err } - expect(error).not.toBeNull() + expect(error).toBeNull() }) }) diff --git a/packages/worker/package.json b/packages/worker/package.json index 8c0dcb5f4c..2c124f7280 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/worker", "email": "hi@budibase.com", - "version": "0.9.38", + "version": "0.9.39", "description": "Budibase background service", "main": "src/index.js", "repository": { @@ -21,8 +21,8 @@ "author": "Budibase", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/auth": "^0.9.38", - "@budibase/string-templates": "^0.9.38", + "@budibase/auth": "^0.9.39", + "@budibase/string-templates": "^0.9.39", "@koa/router": "^8.0.0", "aws-sdk": "^2.811.0", "bcryptjs": "^2.4.3", diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index 82466249a2..e1bd385384 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -27,11 +27,15 @@ exports.save = async function (ctx) { }) } - // verify the configuration - switch (type) { - case Configs.SMTP: - await email.verifyConfig(config) - break + try { + // verify the configuration + switch (type) { + case Configs.SMTP: + await email.verifyConfig(config) + break + } + } catch (err) { + ctx.throw(400, err) } try { @@ -42,7 +46,7 @@ exports.save = async function (ctx) { _rev: response.rev, } } catch (err) { - ctx.throw(err.status, err) + ctx.throw(400, err) } } diff --git a/packages/worker/src/api/routes/admin/configs.js b/packages/worker/src/api/routes/admin/configs.js index 09b8f97f84..c388b83456 100644 --- a/packages/worker/src/api/routes/admin/configs.js +++ b/packages/worker/src/api/routes/admin/configs.js @@ -14,7 +14,6 @@ function smtpValidation() { host: Joi.string().required(), from: Joi.string().email().required(), secure: Joi.boolean().optional(), - selfSigned: Joi.boolean().optional(), auth: Joi.object({ type: Joi.string().valid("login", "oauth2", null), user: Joi.string().required(), diff --git a/packages/worker/src/utilities/email.js b/packages/worker/src/utilities/email.js index 778ad8af4b..4e48844843 100644 --- a/packages/worker/src/utilities/email.js +++ b/packages/worker/src/utilities/email.js @@ -27,10 +27,8 @@ function createSMTPTransport(config) { secure: config.secure || false, auth: config.auth, } - if (config.selfSigned) { - options.tls = { - rejectUnauthorized: false, - } + options.tls = { + rejectUnauthorized: false, } } else { options = {