Allow binding images to attachment types
This commit is contained in:
parent
2772892492
commit
7e74889131
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue