feat(SW-216): added table to contentstack query for contentpage
This commit is contained in:
@@ -5,6 +5,8 @@ import TextCols from "@/components/Blocks/TextCols"
|
||||
import UspGrid from "@/components/Blocks/UspGrid"
|
||||
import JsonToHtml from "@/components/JsonToHtml"
|
||||
|
||||
import Table from "../Table"
|
||||
|
||||
import type { BlocksProps } from "@/types/components/blocks"
|
||||
import { BlocksEnums } from "@/types/enums/blocks"
|
||||
|
||||
@@ -47,6 +49,8 @@ export default function Blocks({ blocks }: BlocksProps) {
|
||||
title={block.shortcuts.title}
|
||||
/>
|
||||
)
|
||||
case BlocksEnums.block.Table:
|
||||
return <Table columns={block.table.columns} rows={block.table.rows} />
|
||||
case BlocksEnums.block.TextCols:
|
||||
return <TextCols text_cols={block.text_cols} />
|
||||
case BlocksEnums.block.TextContent:
|
||||
|
||||
7
lib/graphql/Fragments/Blocks/Table.graphql
Normal file
7
lib/graphql/Fragments/Blocks/Table.graphql
Normal file
@@ -0,0 +1,7 @@
|
||||
fragment Table_ContentPage on ContentPageBlocksTable {
|
||||
__typename
|
||||
table {
|
||||
column_widths
|
||||
table
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#import "../../Fragments/Blocks/Content.graphql"
|
||||
#import "../../Fragments/Blocks/DynamicContent.graphql"
|
||||
#import "../../Fragments/Blocks/Shortcuts.graphql"
|
||||
#import "../../Fragments/Blocks/Table.graphql"
|
||||
#import "../../Fragments/Blocks/TextCols.graphql"
|
||||
#import "../../Fragments/Blocks/UspGrid.graphql"
|
||||
|
||||
@@ -28,6 +29,7 @@ query GetContentPage($locale: String!, $uid: String!) {
|
||||
...Content_ContentPage
|
||||
...DynamicContent_ContentPage
|
||||
...Shortcuts_ContentPage
|
||||
...Table_ContentPage
|
||||
...TextCols_ContentPage
|
||||
...UspGrid_ContentPage
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
shortcutsRefsSchema,
|
||||
shortcutsSchema,
|
||||
} from "../schemas/blocks/shortcuts"
|
||||
import { tableSchema } from "../schemas/blocks/table"
|
||||
import { textColsRefsSchema, textColsSchema } from "../schemas/blocks/textCols"
|
||||
import { uspGridRefsSchema, uspGridSchema } from "../schemas/blocks/uspGrid"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
@@ -75,11 +76,18 @@ export const contentPageUspGrid = z
|
||||
})
|
||||
.merge(uspGridSchema)
|
||||
|
||||
export const contentPageTable = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.Table),
|
||||
})
|
||||
.merge(tableSchema)
|
||||
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
contentPageCards,
|
||||
contentPageContent,
|
||||
contentPageDynamicContent,
|
||||
contentPageShortcuts,
|
||||
contentPageTable,
|
||||
contentPageTextCols,
|
||||
contentPageUspGrid,
|
||||
])
|
||||
|
||||
51
server/routers/contentstack/schemas/blocks/table.ts
Normal file
51
server/routers/contentstack/schemas/blocks/table.ts
Normal file
@@ -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,
|
||||
}
|
||||
}),
|
||||
})
|
||||
@@ -4,6 +4,7 @@ export namespace BlocksEnums {
|
||||
Content = "Content",
|
||||
DynamicContent = "DynamicContent",
|
||||
Shortcuts = "Shortcuts",
|
||||
Table = "Table",
|
||||
TextCols = "TextCols",
|
||||
TextContent = "TextContent",
|
||||
UspGrid = "UspGrid",
|
||||
|
||||
@@ -7,6 +7,7 @@ export namespace ContentPageEnum {
|
||||
Shortcuts = "ContentPageBlocksShortcuts",
|
||||
TextCols = "ContentPageBlocksTextCols",
|
||||
UspGrid = "ContentPageBlocksUspGrid",
|
||||
Table = "ContentPageBlocksTable",
|
||||
}
|
||||
|
||||
export const enum sidebar {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { cardsGridSchema } from "@/server/routers/contentstack/schemas/blocks/ca
|
||||
import { contentSchema } from "@/server/routers/contentstack/schemas/blocks/content"
|
||||
import { dynamicContentSchema } from "@/server/routers/contentstack/schemas/blocks/dynamicContent"
|
||||
import { shortcutsSchema } from "@/server/routers/contentstack/schemas/blocks/shortcuts"
|
||||
import { tableSchema } from "@/server/routers/contentstack/schemas/blocks/table"
|
||||
import { textColsSchema } from "@/server/routers/contentstack/schemas/blocks/textCols"
|
||||
import { uspGridSchema } from "@/server/routers/contentstack/schemas/blocks/uspGrid"
|
||||
|
||||
@@ -12,5 +13,7 @@ export interface Content extends z.output<typeof contentSchema> {}
|
||||
export interface DynamicContent extends z.output<typeof dynamicContentSchema> {}
|
||||
export interface Shortcuts extends z.output<typeof shortcutsSchema> {}
|
||||
export type Shortcut = Shortcuts["shortcuts"]
|
||||
export interface TableBlock extends z.output<typeof tableSchema> {}
|
||||
export type Table = TableBlock["table"]
|
||||
export interface TextCols extends z.output<typeof textColsSchema> {}
|
||||
export interface UspGrid extends z.output<typeof uspGridSchema> {}
|
||||
|
||||
Reference in New Issue
Block a user