From 23d10e1949fa092c88ac30423c44a5e2b4bf6c77 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 22 Feb 2021 15:49:57 +0000 Subject: [PATCH] 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