diff --git a/packages/builder/src/builderStore/fetchBindableProperties.js b/packages/builder/src/builderStore/fetchBindableProperties.js index 9a193112fb..962fb80ebf 100644 --- a/packages/builder/src/builderStore/fetchBindableProperties.js +++ b/packages/builder/src/builderStore/fetchBindableProperties.js @@ -24,7 +24,7 @@ import { cloneDeep, difference } from "lodash/fp" * @returns {Array.} */ export default function({ componentInstanceId, screen, components, tables }) { - const walkResult = walk({ + const result = walk({ // cloning so we are free to mutate props (e.g. by adding _contexts) instance: cloneDeep(screen.props), targetId: componentInstanceId, @@ -33,13 +33,10 @@ export default function({ componentInstanceId, screen, components, tables }) { }) return [ - ...walkResult.bindableInstances - .filter(isInstanceInSharedContext(walkResult)) - .map(componentInstanceToBindable(walkResult)), - - ...(walkResult.target?._contexts - .map(contextToBindables(tables, walkResult)) - .flat() ?? []), + ...result.bindableInstances + .filter(isInstanceInSharedContext(result)) + .map(componentInstanceToBindable), + ...(result.target?._contexts.map(contextToBindables(tables)).flat() ?? []), ] } @@ -53,26 +50,18 @@ const isInstanceInSharedContext = walkResult => i => // turns a component instance prop into binding expressions // used by the UI -const componentInstanceToBindable = walkResult => i => { - const lastContext = - i.instance._contexts.length && - i.instance._contexts[i.instance._contexts.length - 1] - const contextParentPath = lastContext - ? getParentPath(walkResult, lastContext) - : "" - +const componentInstanceToBindable = i => { return { type: "instance", instance: i.instance, // how the binding expression persists, and is used in the app at runtime - runtimeBinding: `${contextParentPath}${i.instance._id}.${i.prop}`, + runtimeBinding: `${i.instance._id}`, // how the binding exressions looks to the user of the builder readableBinding: `${i.instance._instanceName}`, } } -const contextToBindables = (tables, walkResult) => context => { - const contextParentPath = getParentPath(walkResult, context) +const contextToBindables = tables => context => { const tableId = context.table?.tableId ?? context.table const table = tables.find(table => table._id === tableId) let schema = @@ -98,7 +87,7 @@ const contextToBindables = (tables, walkResult) => context => { fieldSchema, instance: context.instance, // how the binding expression persists, and is used in the app at runtime - runtimeBinding: `${contextParentPath}data.${runtimeBoundKey}`, + runtimeBinding: `${context.instance._id}.${runtimeBoundKey}`, // how the binding expressions looks to the user of the builder readableBinding: `${context.instance._instanceName}.${table.name}.${key}`, // table / view info @@ -118,20 +107,6 @@ const contextToBindables = (tables, walkResult) => context => { ) } -const getParentPath = (walkResult, context) => { - // describes the number of "parent" in the path - // clone array first so original array is not mtated - const contextParentNumber = [...walkResult.target._contexts] - .reverse() - .indexOf(context) - - return ( - new Array(contextParentNumber).fill("parent").join(".") + - // trailing . if has parents - (contextParentNumber ? "." : "") - ) -} - const walk = ({ instance, targetId, components, tables, result }) => { if (!result) { result = { diff --git a/packages/builder/src/builderStore/replaceBindings.js b/packages/builder/src/builderStore/replaceBindings.js index aa57301261..0bf9f485c9 100644 --- a/packages/builder/src/builderStore/replaceBindings.js +++ b/packages/builder/src/builderStore/replaceBindings.js @@ -12,10 +12,7 @@ export function readableToRuntimeBinding(bindableProperties, textWithBindings) { return boundValue === `{{ ${readableBinding} }}` }) if (binding) { - result = textWithBindings.replace( - boundValue, - `{{ ${binding.runtimeBinding} }}` - ) + result = result.replace(boundValue, `{{ ${binding.runtimeBinding} }}`) } }) return result diff --git a/packages/builder/src/components/userInterface/AppPreview/CurrentItemPreview.svelte b/packages/builder/src/components/userInterface/AppPreview/CurrentItemPreview.svelte index 45a25bd71f..c9fe02e786 100644 --- a/packages/builder/src/components/userInterface/AppPreview/CurrentItemPreview.svelte +++ b/packages/builder/src/components/userInterface/AppPreview/CurrentItemPreview.svelte @@ -1,28 +1,13 @@
- {#if hasComponent && $store.currentPreviewItem} + {#if $store.currentPreviewItem}