@@ -13,6 +13,7 @@ import {ResizeableDataTable} from '../ResizeableDataTable/ResizeableDataTable';
1313
1414import { Cell } from './Cell' ;
1515import i18n from './i18n' ;
16+ import { getColumnWidth } from './utils/getColumnWidth' ;
1617
1718import './QueryResultTable.scss' ;
1819
@@ -21,30 +22,27 @@ const TABLE_SETTINGS: Settings = {
2122 stripedRows : true ,
2223 dynamicRenderType : 'variable' ,
2324 dynamicItemSizeGetter : ( ) => 40 ,
25+ sortable : false ,
2426} ;
2527
2628export const b = cn ( 'ydb-query-result-table' ) ;
2729
28- const prepareTypedColumns = ( columns : ColumnType [ ] ) => {
30+ const WIDTH_PREDICTION_ROWS_COUNT = 100 ;
31+
32+ const prepareTypedColumns = ( columns : ColumnType [ ] , data ?: KeyValueRow [ ] ) => {
2933 if ( ! columns . length ) {
3034 return [ ] ;
3135 }
3236
37+ const dataSlice = data ?. slice ( 0 , WIDTH_PREDICTION_ROWS_COUNT ) ;
38+
3339 return columns . map ( ( { name, type} ) => {
3440 const columnType = getColumnType ( type ) ;
3541
3642 const column : Column < KeyValueRow > = {
3743 name,
44+ width : getColumnWidth ( { data : dataSlice , name} ) ,
3845 align : columnType === 'number' ? DataTable . RIGHT : DataTable . LEFT ,
39- sortAccessor : ( row ) => {
40- const value = row [ name ] ;
41-
42- if ( value === undefined || value === null ) {
43- return null ;
44- }
45-
46- return columnType === 'number' ? BigInt ( value ) : value ;
47- } ,
4846 render : ( { row} ) => < Cell value = { String ( row [ name ] ) } /> ,
4947 } ;
5048
@@ -57,11 +55,13 @@ const prepareGenericColumns = (data: KeyValueRow[]) => {
5755 return [ ] ;
5856 }
5957
58+ const dataSlice = data ?. slice ( 0 , WIDTH_PREDICTION_ROWS_COUNT ) ;
59+
6060 return Object . keys ( data [ 0 ] ) . map ( ( name ) => {
6161 const column : Column < KeyValueRow > = {
6262 name,
63+ width : getColumnWidth ( { data : dataSlice , name} ) ,
6364 align : isNumeric ( data [ 0 ] [ name ] ) ? DataTable . RIGHT : DataTable . LEFT ,
64- sortAccessor : ( row ) => ( isNumeric ( row [ name ] ) ? Number ( row [ name ] ) : row [ name ] ) ,
6565 render : ( { row} ) => < Cell value = { String ( row [ name ] ) } /> ,
6666 } ;
6767
@@ -78,19 +78,12 @@ interface QueryResultTableProps
7878}
7979
8080export const QueryResultTable = ( props : QueryResultTableProps ) => {
81- const { columns : rawColumns , data : rawData , settings : settingsMix , ...restProps } = props ;
81+ const { columns : rawColumns , data : rawData , ...restProps } = props ;
8282
8383 const data = React . useMemo ( ( ) => prepareQueryResponse ( rawData ) , [ rawData ] ) ;
8484 const columns = React . useMemo ( ( ) => {
85- return rawColumns ? prepareTypedColumns ( rawColumns ) : prepareGenericColumns ( data ) ;
85+ return rawColumns ? prepareTypedColumns ( rawColumns , data ) : prepareGenericColumns ( data ) ;
8686 } , [ data , rawColumns ] ) ;
87- const settings = React . useMemo (
88- ( ) => ( {
89- ...TABLE_SETTINGS ,
90- ...settingsMix ,
91- } ) ,
92- [ settingsMix ] ,
93- ) ;
9487
9588 // empty data is expected to be be an empty array
9689 // undefined data is not rendered at all
@@ -106,7 +99,7 @@ export const QueryResultTable = (props: QueryResultTableProps) => {
10699 < ResizeableDataTable
107100 data = { data }
108101 columns = { columns }
109- settings = { settings }
102+ settings = { TABLE_SETTINGS }
110103 // prevent accessing row.id in case it is present but is not the PK (i.e. may repeat)
111104 rowKey = { getRowIndex }
112105 { ...restProps }
0 commit comments