Fixing an issue where many rows were handled from different tables in client.

This commit is contained in:
mike12345567 2021-09-03 15:04:34 +01:00
parent 2dd1e7f45e
commit 42fb0584a2
1 changed files with 16 additions and 8 deletions

View File

@ -112,13 +112,21 @@ export const enrichRows = async (rows, tableId) => {
if (!Array.isArray(rows)) { if (!Array.isArray(rows)) {
return [] return []
} }
if (rows.length && tableId) { if (rows.length) {
// map of tables, incase a row being loaded is not from the same table
const tables = {}
for (let row of rows) {
// fallback to passed in tableId if row doesn't have it specified
let rowTableId = row.tableId || tableId
let table = tables[rowTableId]
if (!table) {
// Fetch table schema so we can check column types // Fetch table schema so we can check column types
const tableDefinition = await fetchTableDefinition(tableId) table = await fetchTableDefinition(rowTableId)
const schema = tableDefinition && tableDefinition.schema tables[rowTableId] = table
}
const schema = table?.schema
if (schema) { if (schema) {
const keys = Object.keys(schema) const keys = Object.keys(schema)
rows.forEach(row => {
for (let key of keys) { for (let key of keys) {
const type = schema[key].type const type = schema[key].type
if (type === "link" && Array.isArray(row[key])) { if (type === "link" && Array.isArray(row[key])) {
@ -137,7 +145,7 @@ export const enrichRows = async (rows, tableId) => {
row[`${key}_first`] = url row[`${key}_first`] = url
} }
} }
}) }
} }
} }
return rows return rows