Allow binding images to attachment types

This commit is contained in:
Andrew Kingston 2020-10-20 12:23:52 +01:00
parent 8ccaa86d01
commit b49e49ba36
3 changed files with 22 additions and 6 deletions

View File

@ -86,10 +86,12 @@ const contextToBindables = (tables, walkResult) => context => {
}
const newBindable = ([key, fieldSchema]) => {
// Replace link bindings with a new property representing the count
// Replace certain bindings with a new property to help display components
let runtimeBoundKey = key
if (fieldSchema.type === "link") {
runtimeBoundKey = `${key}_count`
} else if (fieldSchema.type === "attachment") {
runtimeBoundKey = `${key}_first`
}
return {
type: "context",

View File

@ -51,8 +51,15 @@
// Fetch table schema so we can check for linked rows
const tableObj = await fetchTable(row.tableId)
for (let key of Object.keys(tableObj.schema)) {
if (tableObj.schema[key].type === "link") {
const type = tableObj.schema[key].type
if (type === "link") {
row[`${key}_count`] = Array.isArray(row[key]) ? row[key].length : 0
} else if (type === "attachment") {
let url = null
if (Array.isArray(row[key]) && row[key][0] != null) {
url = row[key][0].url
}
row[`${key}_first`] = url
}
}

View File

@ -6,11 +6,11 @@ export default async function fetchData(datasource, store) {
if (name) {
let rows = []
if (type === "table") {
rows = fetchTableData()
rows = await fetchTableData()
} else if (type === "view") {
rows = fetchViewData()
rows = await fetchViewData()
} else if (type === "link") {
rows = fetchLinkedRowsData()
rows = await fetchLinkedRowsData()
}
// Fetch table schema so we can check for linked rows
@ -19,8 +19,15 @@ export default async function fetchData(datasource, store) {
const keys = Object.keys(table.schema)
rows.forEach(row => {
for (let key of keys) {
if (table.schema[key].type === "link") {
const type = table.schema[key].type
if (type === "link") {
row[`${key}_count`] = Array.isArray(row[key]) ? row[key].length : 0
} else if (type === "attachment") {
let url = null
if (Array.isArray(row[key]) && row[key][0] != null) {
url = row[key][0].url
}
row[`${key}_first`] = url
}
}
})