1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Display enriched relationship info in grids and bindings

This commit is contained in:
Andrew Kingston 2021-02-19 12:00:06 +00:00
parent fa6d3e5e63
commit 7b4b22377d
3 changed files with 19 additions and 9 deletions

View file

@ -136,7 +136,7 @@ const getContextBindings = (asset, componentId) => {
// Replace certain bindings with a new property to help display components // 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}_text`
} else if (fieldSchema.type === "attachment") { } else if (fieldSchema.type === "attachment") {
runtimeBoundKey = `${key}_first` runtimeBoundKey = `${key}_first`
} }
@ -176,7 +176,7 @@ const getUserBindings = () => {
// Replace certain bindings with a new property to help display components // 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}_text`
} else if (fieldSchema.type === "attachment") { } else if (fieldSchema.type === "attachment") {
runtimeBoundKey = `${key}_first` runtimeBoundKey = `${key}_first`
} }

View file

@ -119,8 +119,8 @@ export const enrichRows = async (rows, tableId) => {
for (let key of keys) { for (let key of keys) {
const type = schema[key].type const type = schema[key].type
if (type === "link") { if (type === "link") {
// Enrich row with the count of any relationship fields // Enrich row a string join of relationship fields
row[`${key}_count`] = Array.isArray(row[key]) ? row[key].length : 0 row[`${key}_text`] = row[key]?.join(", ") || ""
} else if (type === "attachment") { } else if (type === "attachment") {
// Enrich row with the first image URL for any attachment fields // Enrich row with the first image URL for any attachment fields
let url = null let url = null

View file

@ -2,13 +2,14 @@
export let columnName export let columnName
export let row export let row
$: count = $: items = row?.[columnName] || []
row && columnName && Array.isArray(row[columnName])
? row[columnName].length
: 0
</script> </script>
<div class="container">{count} related row(s)</div> <div class="container">
{#each items as item}
<div class="item">{item}</div>
{/each}
</div>
<style> <style>
.container { .container {
@ -19,4 +20,13 @@
gap: var(--spacing-xs); gap: var(--spacing-xs);
width: 100%; width: 100%;
} }
.item {
font-size: var(--font-size-xs);
padding: var(--spacing-xs) var(--spacing-s);
border: 1px solid #888;
color: #666;
line-height: normal;
border-radius: 4px;
}
</style> </style>