1
1
import { Box , Table , TableProps , Text } from '@mantine/core' ;
2
2
import {
3
3
Cell ,
4
+ Row ,
5
+ SortingState ,
4
6
createColumnHelper ,
5
7
flexRender ,
6
8
getCoreRowModel ,
7
9
getSortedRowModel ,
8
- Row ,
9
- SortingState ,
10
10
useReactTable ,
11
11
} from '@tanstack/react-table' ;
12
- import _ from 'lodash' ;
13
12
import React , { useCallback , useContext , useMemo , useState } from 'react' ;
14
13
import { useVirtual } from 'react-virtual' ;
15
14
import { useCurrentInteractionManager } from '~/interactions/hooks/use-current-interaction-manager' ;
@@ -18,12 +17,12 @@ import { HeadCell } from '~/plugins/viz-components/table/components/head-cell';
18
17
import { ClickCellContent } from '~/plugins/viz-components/table/triggers/click-cell-content' ;
19
18
import { baseTableSX , useTableStyles } from '~/plugins/viz-components/table/viz-table.styles' ;
20
19
import { AnyObject } from '~/types' ;
21
- import { VizInstance , VizViewProps } from '~/types/plugin' ;
20
+ import { VizInstance , VizViewContext , VizViewProps } from '~/types/plugin' ;
21
+ import { parseDataKey } from '~/utils/data' ;
22
22
import { IVizManager , PluginContext , useStorageData } from '../..' ;
23
23
import { TableCellContext } from './table-cell-context' ;
24
- import { DEFAULT_CONFIG , IColumnConf , ITableConf , TriggerConfigType , ValueType } from './type' ;
24
+ import { IColumnConf , ITableConf , TriggerConfigType , ValueType } from './type' ;
25
25
import { CellValue } from './value' ;
26
- import { parseDataKey } from '~/utils/data' ;
27
26
28
27
const useGetCellContext = ( context : {
29
28
vizManager : IVizManager ;
@@ -40,10 +39,16 @@ const useGetCellContext = (context: {
40
39
) ;
41
40
} ;
42
41
43
- export function VizTable ( { context, instance } : VizViewProps ) {
44
- const data = context . data ;
45
- const { height, width } = context . viewport ;
46
- const { value : conf = DEFAULT_CONFIG } = useStorageData < ITableConf > ( context . instanceData , 'config' ) ;
42
+ type IVizTableComponent = {
43
+ data : TPanelData ;
44
+ width : number ;
45
+ height : number ;
46
+ conf : ITableConf ;
47
+ instance : VizInstance ;
48
+ context : VizViewContext ;
49
+ } ;
50
+
51
+ function VizTableComponent ( { data, width, height, conf, context, instance } : IVizTableComponent ) {
47
52
const { id_field, use_raw_columns, columns, ...rest } = conf ;
48
53
49
54
const { classes, cx } = useTableStyles ( ) ;
@@ -126,13 +131,6 @@ export function VizTable({ context, instance }: VizViewProps) {
126
131
const showInfoBar = totalRows > 0 ;
127
132
const tableHeight = showInfoBar ? height - 22 : height ;
128
133
const theadTop = showInfoBar ? 22 : 0 ;
129
- if ( ! id_field ) {
130
- return (
131
- < Text color = "red" align = "center" >
132
- ID Field is not set, can't render a table without it
133
- </ Text >
134
- ) ;
135
- }
136
134
if ( ! Array . isArray ( queryData ) || queryData . length === 0 ) {
137
135
return (
138
136
< Text color = "gray" align = "center" >
@@ -194,3 +192,27 @@ export function VizTable({ context, instance }: VizViewProps) {
194
192
</ div >
195
193
) ;
196
194
}
195
+ export function VizTable ( { context, instance } : VizViewProps ) {
196
+ const data = context . data ;
197
+ const { height, width } = context . viewport ;
198
+ const { value : conf } = useStorageData < ITableConf > ( context . instanceData , 'config' ) ;
199
+
200
+ if ( ! conf ) {
201
+ return null ;
202
+ }
203
+
204
+ if ( ! conf . id_field ) {
205
+ console . group ( '🔴 what the fuck' ) ;
206
+ console . log ( conf ) ;
207
+ console . groupEnd ( ) ;
208
+ return (
209
+ < Text color = "red" align = "center" >
210
+ ID Field is not set, can't render a table without it
211
+ </ Text >
212
+ ) ;
213
+ }
214
+
215
+ return (
216
+ < VizTableComponent data = { data } width = { width } height = { height } conf = { conf } context = { context } instance = { instance } />
217
+ ) ;
218
+ }
0 commit comments