diff --git a/packages/standard-components/src/DataTable.svelte b/packages/standard-components/src/DataTable.svelte
index 7eca3ede3f..ab99f4bebe 100644
--- a/packages/standard-components/src/DataTable.svelte
+++ b/packages/standard-components/src/DataTable.svelte
@@ -20,6 +20,7 @@
let sort = {}
let sorted = []
let schema = {}
+ let store = _bb.store
$: cssVariables = {
backgroundColor,
@@ -39,7 +40,7 @@
onMount(async () => {
if (!isEmpty(datasource)) {
- data = await fetchData(datasource, _bb)
+ data = await fetchData(datasource, $store)
if (data && data.length) {
await fetchModel(data[0].modelId)
headers = Object.keys(schema).filter(shouldDisplayField)
@@ -99,7 +100,7 @@
{#if schema[header].type === 'attachment'}
{:else if schema[header].type === 'link'}
-
{row[header]} related row(s) |
+ {row[header].length} related row(s) |
{:else}
{row[header] == null ? '' : row[header]} |
{/if}
diff --git a/packages/standard-components/src/List.svelte b/packages/standard-components/src/List.svelte
index e31d510fbf..410e100ce5 100644
--- a/packages/standard-components/src/List.svelte
+++ b/packages/standard-components/src/List.svelte
@@ -7,10 +7,11 @@
export let datasource = []
let target
+ let store = _bb.store
onMount(async () => {
if (!isEmpty(datasource)) {
- const data = await fetchData(datasource, _bb)
+ const data = await fetchData(datasource, $store)
_bb.attachChildren(target, {
hydrate: false,
context: data,
diff --git a/packages/standard-components/src/RowDetail.svelte b/packages/standard-components/src/RowDetail.svelte
index a974bc9d1a..f17c035b1e 100644
--- a/packages/standard-components/src/RowDetail.svelte
+++ b/packages/standard-components/src/RowDetail.svelte
@@ -52,7 +52,9 @@
const modelObj = await fetchModel(record.modelId)
for (let key of Object.keys(modelObj.schema)) {
if (modelObj.schema[key].type === "link") {
- record[key] = Array.isArray(record[key]) ? record[key].length : 0
+ record[`${key}_count`] = Array.isArray(record[key])
+ ? record[key].length
+ : 0
}
}
diff --git a/packages/standard-components/src/fetchData.js b/packages/standard-components/src/fetchData.js
index 2193010530..12f021029b 100644
--- a/packages/standard-components/src/fetchData.js
+++ b/packages/standard-components/src/fetchData.js
@@ -1,10 +1,10 @@
import api from "./api"
-export default async function fetchData(datasource, _bb) {
+export default async function fetchData(datasource, store) {
const { type, name } = datasource
if (name) {
- let records
+ let records = []
if (type === "model") {
records = await fetchModelData()
} else if (type === "view") {
@@ -20,7 +20,9 @@ export default async function fetchData(datasource, _bb) {
records.forEach(record => {
for (let key of keys) {
if (model.schema[key].type === "link") {
- record[key] = Array.isArray(record[key]) ? record[key].length : 0
+ record[`${key}_count`] = Array.isArray(record[key])
+ ? record[key].length
+ : 0
}
}
})
@@ -62,14 +64,10 @@ export default async function fetchData(datasource, _bb) {
}
async function fetchLinkedRecordsData() {
- if (
- !_bb.store.state ||
- !_bb.store.state.data ||
- !_bb.store.state.data._id
- ) {
+ if (!store || !store.data || !store.data._id) {
return []
}
- const QUERY_URL = `/api/${_bb.store.state.data.modelId}/${_bb.store.state.data._id}/enrich`
+ const QUERY_URL = `/api/${store.data.modelId}/${store.data._id}/enrich`
const response = await api.get(QUERY_URL)
const record = await response.json()
return record[datasource.fieldName]