Fix a couple of crashes in frontend when doing various actions and fix record detail view

This commit is contained in:
Andrew Kingston 2020-10-06 16:04:58 +01:00
parent d8fd0dd2cb
commit fd4a7d95bc
1 changed files with 9 additions and 8 deletions

View File

@ -37,9 +37,9 @@ export default function({ componentInstanceId, screen, components, models }) {
.filter(isInstanceInSharedContext(walkResult)) .filter(isInstanceInSharedContext(walkResult))
.map(componentInstanceToBindable(walkResult)), .map(componentInstanceToBindable(walkResult)),
...walkResult.target._contexts ...(walkResult.target?._contexts
.map(contextToBindables(models, walkResult)) .map(contextToBindables(models, walkResult))
.flat(), .flat() ?? []),
] ]
} }
@ -73,6 +73,10 @@ const componentInstanceToBindable = walkResult => i => {
const contextToBindables = (models, walkResult) => context => { const contextToBindables = (models, walkResult) => context => {
const contextParentPath = getParentPath(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 => ({ const newBindable = key => ({
type: "context", type: "context",
@ -80,15 +84,12 @@ const contextToBindables = (models, walkResult) => context => {
// how the binding expression persists, and is used in the app at runtime // how the binding expression persists, and is used in the app at runtime
runtimeBinding: `${contextParentPath}data.${key}`, runtimeBinding: `${contextParentPath}data.${key}`,
// how the binding exressions looks to the user of the builder // 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 // see ModelViewSelect.svelte for the format of context.model
// ... this allows us to bind to Model scheams, or View schemas // ... this allows us to bind to Model schemas, or View schemas
const model = models.find(m => m._id === context.model.modelId) const schema = isModel ? model.schema : model.views[context.model.name].schema
const schema = context.model.isModel
? model.schema
: model.views[context.model.name].schema
return ( return (
Object.keys(schema) Object.keys(schema)