feat(SW-216): added table to contentstack query for contentpage
This commit is contained in:
committed by
Pontus Dreij
parent
ee6a40a553
commit
ef411b4cf9
@@ -0,0 +1,51 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "@/types/enums/blocks"
|
||||
|
||||
export const tableSchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.Table)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.Table),
|
||||
table: z
|
||||
.object({
|
||||
column_widths: z.array(z.number()),
|
||||
table: z.object({
|
||||
tableState: z.object({
|
||||
columns: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
label: z.string().default(""),
|
||||
accessor: z.string(),
|
||||
dataType: z.string(),
|
||||
})
|
||||
),
|
||||
data: z.array(z.object({}).catchall(z.string())),
|
||||
skipReset: z.boolean(),
|
||||
tableActionEnabled: z.boolean(),
|
||||
headerRowAdded: z.boolean(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
const columns = data.table.tableState.columns.map((col, idx) => ({
|
||||
id: col.id,
|
||||
Header: col.label || "",
|
||||
accessor: col.accessor,
|
||||
columnWidth: 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] || ""
|
||||
})
|
||||
return transformedRow
|
||||
})
|
||||
|
||||
return {
|
||||
columns,
|
||||
rows,
|
||||
}
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user