diff --git a/src/components/TableResult.tsx b/src/components/TableResult.tsx index 6b0f49a..d368456 100644 --- a/src/components/TableResult.tsx +++ b/src/components/TableResult.tsx @@ -1,30 +1,70 @@ +import { Tooltip2 } from "@blueprintjs/popover2"; +import { Cell, Column, Table2 } from "@blueprintjs/table"; import { JsonResult } from "../lib/peform-query"; -import { Table2, Column, Cell, SelectionModes } from "@blueprintjs/table"; type Params = { result: JsonResult; }; export default function TableResult({ result }: Params) { + const widths = Array.from( + { length: Math.min(50, result.data.length) }, + (_: undefined, i: number) => i + ) + .map((i) => + result.data[i].map((cell, colIndex) => + Math.max( + Math.min( + Math.floor( + [...(cell || "").toString()] + .map((l) => (l.match(/[a-zA-Z0-9]/) ? 1.1 : 1)) + .reduce((a, c) => a + c, 0) + ), + 50 + ) * 8, + result.meta[colIndex].name.length * 10 + ) + ) + ) + .reduce((acc, curr) => acc.map((accCell, i) => Math.max(accCell, curr[i]))); + const tableDatasetComponents = result.meta.map((meta, columnNumber) => ( ( - -
{String(result.data[rowNumber][columnNumber])}
-
- )} + cellRenderer={(rowNumber) => { + const rawValue = result.data[rowNumber][columnNumber]; + + if (rawValue == null) { + return ( + +
(null)
+
+ ); + } + const value = String(rawValue); + return ( + + {value.length < 50 ? ( +
{value}
+ ) : ( + + {value} + + )} +
+ ); + }} /> )); return ( -
+