Browse Source

Allow binding images to attachment types

pull/4023/head
Andrew Kingston 6 years ago
parent
commit
7e74889131
  1. 4
      packages/builder/src/builderStore/fetchBindableProperties.js
  2. 9
      packages/standard-components/src/RowDetail.svelte
  3. 15
      packages/standard-components/src/fetchData.js

4
packages/builder/src/builderStore/fetchBindableProperties.js

@ -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",

9
packages/standard-components/src/RowDetail.svelte

@ -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
}
}

15
packages/standard-components/src/fetchData.js

@ -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…
Cancel
Save