1
1
import {
2
2
ColumnDef ,
3
+ ColumnResizeMode ,
3
4
flexRender ,
4
5
getCoreRowModel ,
6
+ TableOptions ,
5
7
Row as TableRow ,
6
8
useReactTable ,
7
9
} from '@tanstack/react-table' ;
@@ -20,7 +22,7 @@ import FieldMultiSelect from './FieldMultiSelect';
20
22
import InstallInstructionsModal from './InstallInstructionsModal' ;
21
23
import LogLevel from './LogLevel' ;
22
24
import api from './api' ;
23
- import { usePrevious , useWindowSize } from './utils' ;
25
+ import { useLocalStorage , usePrevious , useWindowSize } from './utils' ;
24
26
import { useSearchEventStream } from './search' ;
25
27
import { useHotkeys } from 'react-hotkeys-hook' ;
26
28
@@ -211,6 +213,7 @@ function LogTableSettingsModal({
211
213
212
214
export const RawLogTable = memo (
213
215
( {
216
+ tableId,
214
217
displayedColumns,
215
218
fetchNextPage,
216
219
formatUTC,
@@ -252,6 +255,7 @@ export const RawLogTable = memo(
252
255
onScroll : ( scrollTop : number ) => void ;
253
256
isLive : boolean ;
254
257
onShowPatternsClick ?: ( ) => void ;
258
+ tableId ?: string ;
255
259
} ) => {
256
260
const dedupLogs = useMemo ( ( ) => {
257
261
const lIds = new Set ( ) ;
@@ -267,6 +271,10 @@ export const RawLogTable = memo(
267
271
const { width } = useWindowSize ( ) ;
268
272
const isSmallScreen = ( width ?? 1000 ) < 900 ;
269
273
274
+ const [ columnSizeStorage , setColumnSizeStorage ] = useLocalStorage <
275
+ Record < string , number >
276
+ > ( `${ tableId } -column-sizes` , { } ) ;
277
+
270
278
const tsFormat = 'MMM d HH:mm:ss.SSS' ;
271
279
const tsShortFormat = 'HH:mm:ss' ;
272
280
// https://github.com/TanStack/table/discussions/3192#discussioncomment-3873093
@@ -336,7 +344,7 @@ export const RawLogTable = memo(
336
344
</ span >
337
345
) ;
338
346
} ,
339
- size : isSmallScreen ? 75 : 180 ,
347
+ size : columnSizeStorage . timestamp ?? ( isSmallScreen ? 75 : 180 ) ,
340
348
} ,
341
349
{
342
350
accessorKey : 'severity_text' ,
@@ -351,7 +359,7 @@ export const RawLogTable = memo(
351
359
< LogLevel level = { info . getValue < string > ( ) } />
352
360
</ span >
353
361
) ,
354
- size : isSmallScreen ? 50 : 100 ,
362
+ size : columnSizeStorage . severity_text ?? ( isSmallScreen ? 50 : 100 ) ,
355
363
} ,
356
364
{
357
365
accessorKey : '_service' ,
@@ -366,7 +374,7 @@ export const RawLogTable = memo(
366
374
{ info . getValue < string > ( ) }
367
375
</ span >
368
376
) ,
369
- size : isSmallScreen ? 70 : 100 ,
377
+ size : columnSizeStorage . _service ?? ( isSmallScreen ? 70 : 100 ) ,
370
378
} ,
371
379
...( displayedColumns . map ( column => ( {
372
380
accessorFn : curry ( retrieveColumnValue ) ( column ) , // Columns can contain '.' and will not work with accessorKey
@@ -383,7 +391,7 @@ export const RawLogTable = memo(
383
391
</ span >
384
392
) ;
385
393
} ,
386
- size : 150 ,
394
+ size : columnSizeStorage [ column ] ?? 150 ,
387
395
} ) ) as ColumnDef < any > [ ] ) ,
388
396
{
389
397
accessorKey : 'body' ,
@@ -416,6 +424,7 @@ export const RawLogTable = memo(
416
424
displayedColumns ,
417
425
onShowPatternsClick ,
418
426
isSmallScreen ,
427
+ columnSizeStorage ,
419
428
] ,
420
429
) ;
421
430
@@ -441,14 +450,38 @@ export const RawLogTable = memo(
441
450
fetchMoreOnBottomReached ( tableContainerRef . current ) ;
442
451
} , [ fetchMoreOnBottomReached ] ) ;
443
452
444
- const table = useReactTable ( {
445
- data : dedupLogs ,
446
- columns,
447
- getCoreRowModel : getCoreRowModel ( ) ,
448
- // debugTable: true,
449
- enableColumnResizing : true ,
450
- columnResizeMode : 'onChange' ,
451
- } ) ;
453
+ const reactTableProps = useMemo ( ( ) : TableOptions < any > => {
454
+ //TODO: fix any
455
+ const onColumnSizingChange = ( updaterOrValue : any ) => {
456
+ const state =
457
+ updaterOrValue instanceof Function
458
+ ? updaterOrValue ( )
459
+ : updaterOrValue ;
460
+ setColumnSizeStorage ( { ...columnSizeStorage , ...state } ) ;
461
+ } ;
462
+
463
+ const initReactTableProps = {
464
+ data : dedupLogs ,
465
+ columns,
466
+ getCoreRowModel : getCoreRowModel ( ) ,
467
+ // debugTable: true,
468
+ enableColumnResizing : true ,
469
+ columnResizeMode : 'onChange' as ColumnResizeMode ,
470
+ } ;
471
+
472
+ const columnSizeProps = {
473
+ state : {
474
+ columnSizing : columnSizeStorage ,
475
+ } ,
476
+ onColumnSizingChange : onColumnSizingChange ,
477
+ } ;
478
+
479
+ return tableId
480
+ ? { ...initReactTableProps , ...columnSizeProps }
481
+ : initReactTableProps ;
482
+ } , [ columns , dedupLogs , tableId , columnSizeStorage , setColumnSizeStorage ] ) ;
483
+
484
+ const table = useReactTable ( reactTableProps ) ;
452
485
453
486
const { rows } = table . getRowModel ( ) ;
454
487
@@ -531,7 +564,7 @@ export const RawLogTable = memo(
531
564
532
565
return (
533
566
< div
534
- className = "overflow-auto h-100 fs-8 bg-inherit"
567
+ className = "overflow-auto h-100 fs-8 bg-inherit py-2 "
535
568
onScroll = { e => {
536
569
fetchMoreOnBottomReached ( e . target as HTMLDivElement ) ;
537
570
@@ -544,7 +577,11 @@ export const RawLogTable = memo(
544
577
// Fixes flickering scroll bar: https://github.com/TanStack/virtual/issues/426#issuecomment-1403438040
545
578
// style={{ overflowAnchor: 'none' }}
546
579
>
547
- < table className = "w-100 bg-inherit" style = { { tableLayout : 'fixed' } } >
580
+ < table
581
+ className = "w-100 bg-inherit"
582
+ id = { tableId }
583
+ style = { { tableLayout : 'fixed' } }
584
+ >
548
585
< thead
549
586
className = "bg-inherit"
550
587
style = { {
@@ -600,22 +637,38 @@ export const RawLogTable = memo(
600
637
< i className = "bi bi-three-dots-vertical" />
601
638
</ div >
602
639
) }
603
- { headerIndex === headerGroup . headers . length - 1 &&
604
- onSettingsClick != null ? (
640
+ { headerIndex === headerGroup . headers . length - 1 && (
605
641
< div
606
- className = "fs-8 text-muted-hover "
642
+ className = "d-flex align-items-center "
607
643
style = { {
608
644
position : 'absolute' ,
609
645
right : 8 ,
610
646
top : 0 ,
611
647
bottom : 0 ,
612
648
} }
613
- role = "button"
614
- onClick = { ( ) => onSettingsClick ( ) }
615
649
>
616
- < i className = "bi bi-gear-fill" />
650
+ { tableId != null &&
651
+ Object . keys ( columnSizeStorage ) . length > 0 && (
652
+ < div
653
+ className = "fs-8 text-muted-hover disabled"
654
+ role = "button"
655
+ onClick = { ( ) => setColumnSizeStorage ( { } ) }
656
+ title = "Reset Column Widths"
657
+ >
658
+ < i className = "bi bi-arrow-clockwise" />
659
+ </ div >
660
+ ) }
661
+ { onSettingsClick != null && (
662
+ < div
663
+ className = "fs-8 text-muted-hover ms-2"
664
+ role = "button"
665
+ onClick = { ( ) => onSettingsClick ( ) }
666
+ >
667
+ < i className = "bi bi-gear-fill" />
668
+ </ div >
669
+ ) }
617
670
</ div >
618
- ) : null }
671
+ ) }
619
672
</ th >
620
673
) ;
621
674
} ) }
@@ -730,6 +783,7 @@ export default function LogTable({
730
783
setIsUTC,
731
784
onEnd,
732
785
onShowPatternsClick,
786
+ tableId,
733
787
} : {
734
788
config : {
735
789
where : string ;
@@ -747,6 +801,7 @@ export default function LogTable({
747
801
setIsUTC : ( isUTC : boolean ) => void ;
748
802
onEnd ?: ( ) => void ;
749
803
onShowPatternsClick ?: ( ) => void ;
804
+ tableId ?: string ;
750
805
} ) {
751
806
const [ instructionsOpen , setInstructionsOpen ] = useState ( false ) ;
752
807
const [ settingsOpen , setSettingsOpen ] = useState ( false ) ;
@@ -833,6 +888,7 @@ export default function LogTable({
833
888
}
834
889
/>
835
890
< RawLogTable
891
+ tableId = { tableId }
836
892
isLive = { isLive }
837
893
wrapLines = { wrapLines }
838
894
displayedColumns = { displayedColumns }
0 commit comments