Allow binding images to attachment types
This commit is contained in:
parent
8ccaa86d01
commit
b49e49ba36
|
@ -86,10 +86,12 @@ const contextToBindables = (tables, walkResult) => context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const newBindable = ([key, fieldSchema]) => {
|
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
|
let runtimeBoundKey = key
|
||||||
if (fieldSchema.type === "link") {
|
if (fieldSchema.type === "link") {
|
||||||
runtimeBoundKey = `${key}_count`
|
runtimeBoundKey = `${key}_count`
|
||||||
|
} else if (fieldSchema.type === "attachment") {
|
||||||
|
runtimeBoundKey = `${key}_first`
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: "context",
|
type: "context",
|
||||||
|
|
|
@ -51,8 +51,15 @@
|
||||||
// Fetch table schema so we can check for linked rows
|
// Fetch table schema so we can check for linked rows
|
||||||
const tableObj = await fetchTable(row.tableId)
|
const tableObj = await fetchTable(row.tableId)
|
||||||
for (let key of Object.keys(tableObj.schema)) {
|
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
|
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) {
|
if (name) {
|
||||||
let rows = []
|
let rows = []
|
||||||
if (type === "table") {
|
if (type === "table") {
|
||||||
rows = fetchTableData()
|
rows = await fetchTableData()
|
||||||
} else if (type === "view") {
|
} else if (type === "view") {
|
||||||
rows = fetchViewData()
|
rows = await fetchViewData()
|
||||||
} else if (type === "link") {
|
} else if (type === "link") {
|
||||||
rows = fetchLinkedRowsData()
|
rows = await fetchLinkedRowsData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch table schema so we can check for linked rows
|
// 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)
|
const keys = Object.keys(table.schema)
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
for (let key of keys) {
|
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
|
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