feat(SW-441): Added table block component

This commit is contained in:
Erik Tiekstra
2024-10-04 11:51:39 +02:00
committed by Pontus Dreij
parent ef411b4cf9
commit dfd40aa7aa
23 changed files with 431 additions and 29 deletions

View File

@@ -28,17 +28,20 @@ export const tableSchema = z.object({
}),
})
.transform((data) => {
const totalWidth = data.column_widths.reduce(
(acc, width) => acc + width,
0
)
const columns = data.table.tableState.columns.map((col, idx) => ({
id: col.id,
Header: col.label || "",
accessor: col.accessor,
columnWidth: data.column_widths[idx] || 0,
header: col.label || "",
width: data.column_widths[idx] || 0,
}))
const rows = data.table.tableState.data.map((rowData) => {
const transformedRow: Record<string, string> = {}
columns.forEach((col) => {
transformedRow[col.accessor] = rowData[col.accessor] || ""
columns.forEach((header) => {
transformedRow[header.id] = rowData[header.id] || ""
})
return transformedRow
})
@@ -46,6 +49,7 @@ export const tableSchema = z.object({
return {
columns,
rows,
totalWidth,
}
}),
})