From 49875d5c42fd5d1e283ab9d7e76fb653b51bbb46 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 6 Oct 2020 16:04:58 +0100 Subject: [PATCH] Fix a couple of crashes in frontend when doing various actions and fix record detail view --- .../src/builderStore/fetchBindableProperties.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/builderStore/fetchBindableProperties.js b/packages/builder/src/builderStore/fetchBindableProperties.js index 65cc861c50..c71c498a32 100644 --- a/packages/builder/src/builderStore/fetchBindableProperties.js +++ b/packages/builder/src/builderStore/fetchBindableProperties.js @@ -37,9 +37,9 @@ export default function({ componentInstanceId, screen, components, models }) { .filter(isInstanceInSharedContext(walkResult)) .map(componentInstanceToBindable(walkResult)), - ...walkResult.target._contexts + ...(walkResult.target?._contexts .map(contextToBindables(models, walkResult)) - .flat(), + .flat() ?? []), ] } @@ -73,6 +73,10 @@ const componentInstanceToBindable = walkResult => i => { const contextToBindables = (models, walkResult) => context => { const contextParentPath = getParentPath(walkResult, context) + const isModel = context.model?.isModel || typeof context.model === "string" + const modelId = + typeof context.model === "string" ? context.model : context.model.modelId + const model = models.find(model => model._id === modelId) const newBindable = key => ({ type: "context", @@ -80,15 +84,12 @@ const contextToBindables = (models, walkResult) => context => { // how the binding expression persists, and is used in the app at runtime runtimeBinding: `${contextParentPath}data.${key}`, // how the binding exressions looks to the user of the builder - readableBinding: `${context.instance._instanceName}.${context.model.label}.${key}`, + readableBinding: `${context.instance._instanceName}.${model.name}.${key}`, }) // see ModelViewSelect.svelte for the format of context.model - // ... this allows us to bind to Model scheams, or View schemas - const model = models.find(m => m._id === context.model.modelId) - const schema = context.model.isModel - ? model.schema - : model.views[context.model.name].schema + // ... this allows us to bind to Model schemas, or View schemas + const schema = isModel ? model.schema : model.views[context.model.name].schema return ( Object.keys(schema)