@@ -28,67 +28,7 @@ export const b = cn('ydb-query-result-table');
2828
2929const WIDTH_PREDICTION_ROWS_COUNT = 100 ;
3030
31- type ActiveCellState = {
32- row : KeyValueRow ;
33- columnName : string ;
34- } | null ;
35-
36- type ActiveCellAction = {
37- type : 'toggle' ;
38- payload : {
39- row : KeyValueRow ;
40- columnName : string ;
41- } ;
42- } ;
43-
44- function activeCellReducer ( state : ActiveCellState , action : ActiveCellAction ) : ActiveCellState {
45- switch ( action . type ) {
46- case 'toggle' :
47- if (
48- state &&
49- state . row === action . payload . row &&
50- state . columnName === action . payload . columnName
51- ) {
52- return null ;
53- }
54- return action . payload ;
55- default :
56- return state ;
57- }
58- }
59-
60- type RenderCellArgs = { row : KeyValueRow ; columnName : string } ;
61- type RenderCell = ( args : RenderCellArgs ) => React . ReactNode ;
62-
63- interface CreateRenderCellParams {
64- activeCell : ActiveCellState ;
65- dispatch : React . Dispatch < ActiveCellAction > ;
66- }
67-
68- function createRenderCell ( { activeCell, dispatch} : CreateRenderCellParams ) : RenderCell {
69- return ( { row, columnName} : RenderCellArgs ) => {
70- const isActive = Boolean (
71- activeCell && activeCell . row === row && activeCell . columnName === columnName ,
72- ) ;
73-
74- const value = row [ columnName ] ;
75-
76- const onToggle = ( ) => {
77- dispatch ( {
78- type : 'toggle' ,
79- payload : { row, columnName} ,
80- } ) ;
81- } ;
82-
83- return < Cell value = { String ( value ) } isActive = { isActive } onToggle = { onToggle } /> ;
84- } ;
85- }
86-
87- const prepareTypedColumns = (
88- columns : ColumnType [ ] ,
89- data : KeyValueRow [ ] | undefined ,
90- renderCell : RenderCell ,
91- ) => {
31+ const prepareTypedColumns = ( columns : ColumnType [ ] , data : KeyValueRow [ ] | undefined ) => {
9232 if ( ! columns . length ) {
9333 return [ ] ;
9434 }
@@ -102,14 +42,14 @@ const prepareTypedColumns = (
10242 name,
10343 width : getColumnWidth ( { data : dataSlice , name} ) ,
10444 align : columnType === 'number' ? DataTable . RIGHT : DataTable . LEFT ,
105- render : ( { row} ) => renderCell ( { row, columnName : name } ) ,
45+ render : ( { row} ) => < Cell value = { String ( row [ name ] ) } /> ,
10646 } ;
10747
10848 return column ;
10949 } ) ;
11050} ;
11151
112- const prepareGenericColumns = ( data : KeyValueRow [ ] | undefined , renderCell : RenderCell ) => {
52+ const prepareGenericColumns = ( data : KeyValueRow [ ] | undefined ) => {
11353 if ( ! data ?. length ) {
11454 return [ ] ;
11555 }
@@ -121,7 +61,7 @@ const prepareGenericColumns = (data: KeyValueRow[] | undefined, renderCell: Rend
12161 name,
12262 width : getColumnWidth ( { data : dataSlice , name} ) ,
12363 align : isNumeric ( data [ 0 ] [ name ] ) ? DataTable . RIGHT : DataTable . LEFT ,
124- render : ( { row} ) => renderCell ( { row, columnName : name } ) ,
64+ render : ( { row} ) => < Cell value = { String ( row [ name ] ) } /> ,
12565 } ;
12666
12767 return column ;
@@ -143,18 +83,9 @@ interface QueryResultTableProps
14383export const QueryResultTable = ( props : QueryResultTableProps ) => {
14484 const { columns, data, settings : propsSettings } = props ;
14585
146- const [ activeCell , dispatch ] = React . useReducer ( activeCellReducer , null ) ;
147-
148- const renderCell = React . useMemo (
149- ( ) => createRenderCell ( { activeCell, dispatch} ) ,
150- [ activeCell , dispatch ] ,
151- ) ;
152-
15386 const preparedColumns = React . useMemo ( ( ) => {
154- return columns
155- ? prepareTypedColumns ( columns , data , renderCell )
156- : prepareGenericColumns ( data , renderCell ) ;
157- } , [ columns , data , renderCell ] ) ;
87+ return columns ? prepareTypedColumns ( columns , data ) : prepareGenericColumns ( data ) ;
88+ } , [ columns , data ] ) ;
15889
15990 const settings = React . useMemo ( ( ) => {
16091 return {
0 commit comments