fix: New & Detail not displaying components when no model selected

This commit is contained in:
Michael Shanks 2020-10-12 10:51:20 +01:00
parent 4007152583
commit d62ed0fb48
2 changed files with 11 additions and 5 deletions

View File

@ -26,6 +26,10 @@
_bb.attachChildren(target, { _bb.attachChildren(target, {
context: record, context: record,
}) })
} else {
_bb.attachChildren(target, {
context: {},
})
} }
}) })
</script> </script>

View File

@ -30,7 +30,7 @@
let record let record
// if srcdoc, then we assume this is the builder preview // if srcdoc, then we assume this is the builder preview
if (pathParts.length === 0 || pathParts[0] === "srcdoc") { if (pathParts.length === 0 || pathParts[0] === "srcdoc") {
record = await fetchFirstRecord() if (model) record = await fetchFirstRecord()
} else if (_bb.routeParams().id) { } else if (_bb.routeParams().id) {
const GET_RECORD_URL = `/api/${model}/records/${_bb.routeParams().id}` const GET_RECORD_URL = `/api/${model}/records/${_bb.routeParams().id}`
const response = await _bb.api.get(GET_RECORD_URL) const response = await _bb.api.get(GET_RECORD_URL)
@ -45,18 +45,20 @@
if (record) { if (record) {
// Fetch model schema so we can check for linked records // Fetch model schema so we can check for linked records
const model = await fetchModel(record.modelId) const modelObj = await fetchModel(record.modelId)
for (let key of Object.keys(model.schema)) { for (let key of Object.keys(modelObj.schema)) {
if (model.schema[key].type === "link") { if (modelObj.schema[key].type === "link") {
record[key] = Array.isArray(record[key]) ? record[key].length : 0 record[key] = Array.isArray(record[key]) ? record[key].length : 0
} }
} }
record._model = model record._model = modelObj
_bb.attachChildren(target, { _bb.attachChildren(target, {
context: record, context: record,
}) })
} else {
_bb.attachChildren(target)
} }
} }