From afe70d1ba2b81426acbd40179f31af52bd64d6af Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 22 Feb 2021 15:49:57 +0000 Subject: [PATCH 1/5] Fixing issue - this will replace any bindings when copying and pasting a stack of components with 'Invalid binding'. --- packages/builder/src/builderStore/dataBinding.js | 15 +++++++++++++++ .../builder/src/builderStore/store/frontend.js | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index b2eb30c55a..858bfa8801 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -7,6 +7,7 @@ import { TableNames } from "../constants" // Regex to match all instances of template strings const CAPTURE_VAR_INSIDE_TEMPLATE = /{{([^}]+)}}/g +const CAPTURE_HBS_TEMPLATE = /{{[\S\s]*?}}/g /** * Gets all bindable data context fields and instance fields. @@ -273,6 +274,20 @@ const buildFormSchema = component => { return schema } +/** + * Recurses the input object to remove any instances of bindings. + */ +export function removeBindings(obj) { + for (let [key, value] of Object.entries(obj)) { + if (typeof value === "object") { + obj[key] = removeBindings(value) + } else if (typeof value === "string") { + obj[key] = value.replace(CAPTURE_HBS_TEMPLATE, "Invalid binding") + } + } + return obj +} + /** * utility function for the readableToRuntimeBinding and runtimeToReadableBinding. */ diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 27427c6ef0..51ed83266a 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -15,6 +15,7 @@ import { FrontendTypes } from "constants" import analytics from "analytics" import { findComponentType, findComponentParent } from "../storeUtils" import { uuid } from "../uuid" +import { removeBindings } from "../dataBinding" const INITIAL_FRONTEND_STATE = { apps: [], @@ -408,6 +409,9 @@ export const getFrontendStore = () => { return state } + // immediately need to remove bindings, currently these aren't valid when pasted + state.componentToPaste = removeBindings(state.componentToPaste) + // Clone the component to paste // Retain the same ID if cutting as things may be referencing this component const cut = state.componentToPaste.isCut From 22f1ee6d37053c6ecb76a7f5150d352f46f4cabf Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 22 Feb 2021 15:53:49 +0000 Subject: [PATCH 2/5] Adding prettier ignore statement as it kept re-formatting the spacing in query viewer file. --- .../builder/src/components/integration/QueryViewer.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/integration/QueryViewer.svelte b/packages/builder/src/components/integration/QueryViewer.svelte index fe8f7a7687..14123a1a9d 100644 --- a/packages/builder/src/components/integration/QueryViewer.svelte +++ b/packages/builder/src/components/integration/QueryViewer.svelte @@ -204,7 +204,9 @@ {#if data} {#if tab === 'JSON'} -
+              
+                
                 {#if !data[0]}
                   
                   Please run your query to fetch some data.

From 0345323a3d6fefb909eff34c02305a07c087e239 Mon Sep 17 00:00:00 2001
From: mike12345567 
Date: Mon, 22 Feb 2021 16:10:29 +0000
Subject: [PATCH 3/5] Adding fix in for views including internal views which
 shouldn't be added to view calculation.

---
 .../server/src/api/controllers/deploy/quota.js | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/packages/server/src/api/controllers/deploy/quota.js b/packages/server/src/api/controllers/deploy/quota.js
index 4e4c869670..130ceaa3b9 100644
--- a/packages/server/src/api/controllers/deploy/quota.js
+++ b/packages/server/src/api/controllers/deploy/quota.js
@@ -1,5 +1,12 @@
 const PouchDB = require("../../../db")
-const { DocumentTypes, SEPARATOR, UNICODE_MAX } = require("../../../db/utils")
+const {
+  DocumentTypes,
+  SEPARATOR,
+  UNICODE_MAX,
+  ViewNames,
+} = require("../../../db/utils")
+
+const EXCLUDED_VIEWS = [ViewNames.USERS, ViewNames.LINK, ViewNames.ROUTING]
 
 exports.getAppQuota = async function(appId) {
   const db = new PouchDB(appId)
@@ -19,9 +26,16 @@ exports.getAppQuota = async function(appId) {
 
   const designDoc = await db.get("_design/database")
 
+  let views = 0
+  for (let viewName of Object.keys(designDoc.views)) {
+    if (EXCLUDED_VIEWS.indexOf(viewName) === -1) {
+      views++
+    }
+  }
+
   return {
     rows: existingRows,
     users: existingUsers,
-    views: Object.keys(designDoc.views).length,
+    views: views,
   }
 }

From 794d7cc0214e9c4d5b759e943354feadcac937f4 Mon Sep 17 00:00:00 2001
From: mike12345567 
Date: Mon, 22 Feb 2021 16:13:11 +0000
Subject: [PATCH 4/5] Quick change to make sure as long as internal views are
 denoted in the db constant they'll be handled.

---
 packages/server/src/api/controllers/deploy/quota.js | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/packages/server/src/api/controllers/deploy/quota.js b/packages/server/src/api/controllers/deploy/quota.js
index 130ceaa3b9..5e8880c7a9 100644
--- a/packages/server/src/api/controllers/deploy/quota.js
+++ b/packages/server/src/api/controllers/deploy/quota.js
@@ -6,8 +6,6 @@ const {
   ViewNames,
 } = require("../../../db/utils")
 
-const EXCLUDED_VIEWS = [ViewNames.USERS, ViewNames.LINK, ViewNames.ROUTING]
-
 exports.getAppQuota = async function(appId) {
   const db = new PouchDB(appId)
 
@@ -28,7 +26,7 @@ exports.getAppQuota = async function(appId) {
 
   let views = 0
   for (let viewName of Object.keys(designDoc.views)) {
-    if (EXCLUDED_VIEWS.indexOf(viewName) === -1) {
+    if (Object.values(ViewNames).indexOf(viewName) === -1) {
       views++
     }
   }

From 563b0cc077c1d8669caa8869f1a6470a9f5f2c70 Mon Sep 17 00:00:00 2001
From: mike12345567 
Date: Tue, 23 Feb 2021 10:26:37 +0000
Subject: [PATCH 5/5] Only performing the change on copies, allowing cuts
 through.

---
 packages/builder/src/builderStore/store/frontend.js | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js
index 51ed83266a..7edc378900 100644
--- a/packages/builder/src/builderStore/store/frontend.js
+++ b/packages/builder/src/builderStore/store/frontend.js
@@ -409,12 +409,16 @@ export const getFrontendStore = () => {
             return state
           }
 
+          // defines if this is a copy or a cut
+          const cut = state.componentToPaste.isCut
+
           // immediately need to remove bindings, currently these aren't valid when pasted
-          state.componentToPaste = removeBindings(state.componentToPaste)
+          if (!cut) {
+            state.componentToPaste = removeBindings(state.componentToPaste)
+          }
 
           // Clone the component to paste
           // Retain the same ID if cutting as things may be referencing this component
-          const cut = state.componentToPaste.isCut
           delete state.componentToPaste.isCut
           let componentToPaste = cloneDeep(state.componentToPaste)
           if (cut) {