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 3f960e4f13
commit a864c511c4
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)) {
return []
}
if (rows.length && tableId) {
// Fetch table schema so we can check column types
const tableDefinition = await fetchTableDefinition(tableId)
const schema = tableDefinition && tableDefinition.schema
if (schema) {
const keys = Object.keys(schema)
rows.forEach(row => {
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
table = await fetchTableDefinition(rowTableId)
tables[rowTableId] = table
}
const schema = table?.schema
if (schema) {
const keys = Object.keys(schema)
for (let key of keys) {
const type = schema[key].type
if (type === "link" && Array.isArray(row[key])) {
@ -137,7 +145,7 @@ export const enrichRows = async (rows, tableId) => {
row[`${key}_first`] = url
}
}
})
}
}
}
return rows