import { Card, CardBody, Flex } from "@chakra-ui/react"; import { Cell, CellContext } from "@tanstack/react-table"; import { ChevronDown, ChevronRight } from "lucide-react"; type ExpandableRow = Omit & { shouldExpand?: boolean; }; export const createJsonExpandRowModel = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const renderCell = ({ row, getValue }: CellContext, any>) => { if (!row.original.shouldExpand) { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { shouldExpand, ...res } = row.original; return (
{JSON.stringify(res, null, 2)}
); } return ( {row.getCanExpand() ? ( ) : null}{" "} {getValue()} ); }; // eslint-disable-next-line @typescript-eslint/no-explicit-any const span = (cell: Cell, any>) => cell.row.original.shouldExpand ? undefined : cell.row.getVisibleCells().length; const getSubRows = (row: ExpandableRow) => row.shouldExpand ? [ { ...row, shouldExpand: false, }, ] : undefined; const toExpandable = function (arr: T[] | undefined, val = true): ExpandableRow[] { return !arr ? [] : arr.map((element) => ({ ...element, shouldExpand: val })); }; return { renderCell, span, getSubRows, toExpandable }; };