-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathIrisGrid.tsx
More file actions
5405 lines (4878 loc) · 161 KB
/
IrisGrid.tsx
File metadata and controls
5405 lines (4878 loc) · 161 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React, {
type ChangeEvent,
Component,
type CSSProperties,
type ReactElement,
type ReactNode,
} from 'react';
import memoize from 'memoizee';
import classNames from 'classnames';
import { CSSTransition } from 'react-transition-group';
import deepEqual from 'fast-deep-equal';
import Log from '@deephaven/log';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
ContextActions,
Stack,
Menu,
Page,
Popper,
ThemeExport,
Tooltip,
type ContextAction,
type PopperOptions,
type ReferenceObject,
Button,
ContextActionUtils,
type ResolvableContextAction,
SlideTransition,
} from '@deephaven/components';
import {
Grid,
type GridMetrics,
type GridMouseHandler,
GridRange,
type GridRangeIndex,
GridUtils,
type KeyHandler,
type ModelIndex,
type ModelSizeMap,
type MoveOperation,
type VisibleIndex,
type GridState,
isEditableGridModel,
type BoundedAxisRange,
isExpandableGridModel,
isDeletableGridModel,
isExpandableColumnGridModel,
} from '@deephaven/grid';
import {
dhEye,
dhFilterFilled,
dhGraphLineUp,
dhTriangleDownSquare,
vsClose,
vsCloudDownload,
vsEdit,
vsFilter,
vsMenu,
vsReply,
vsRuby,
vsSearch,
vsSplitHorizontal,
vsSymbolOperator,
vsTools,
} from '@deephaven/icons';
import type { dh as DhType } from '@deephaven/jsapi-types';
import {
DateUtils,
Formatter,
FormatterUtils,
TableUtils,
type FormattingRule,
type ReverseType,
type RowDataMap,
type SortDirection,
type DateTimeColumnFormatterOptions,
type TableColumnFormat,
type Settings,
isSortDirection,
type SortDescriptor,
} from '@deephaven/jsapi-utils';
import {
assertNotNull,
copyToClipboard,
EMPTY_ARRAY,
EMPTY_MAP,
Pending,
PromiseUtils,
ValidationError,
getOrThrow,
type EventT,
} from '@deephaven/utils';
import {
Type as FilterType,
type TypeValue as FilterTypeValue,
} from '@deephaven/filters';
import throttle from 'lodash.throttle';
import debounce from 'lodash.debounce';
import clamp from 'lodash.clamp';
import {
type FormattingRule as SidebarFormattingRule,
getFormatColumns,
} from './sidebar/conditional-formatting/ConditionalFormattingUtils';
import PendingDataBottomBar from './PendingDataBottomBar';
import IrisGridCopyHandler, { type CopyOperation } from './IrisGridCopyHandler';
import FilterInputField from './FilterInputField';
import {
CopyCellKeyHandler,
ClearFilterKeyHandler,
CopyKeyHandler,
ReverseKeyHandler,
} from './key-handlers';
import {
IrisGridCellOverflowMouseHandler,
IrisGridColumnSelectMouseHandler,
IrisGridColumnTooltipMouseHandler,
IrisGridContextMenuHandler,
IrisGridCopyCellMouseHandler,
IrisGridDataSelectMouseHandler,
IrisGridPartitionedTableMouseHandler,
IrisGridFilterMouseHandler,
IrisGridRowTreeMouseHandler,
IrisGridSortMouseHandler,
IrisGridTokenMouseHandler,
PendingMouseHandler,
} from './mousehandlers';
import ToastBottomBar from './ToastBottomBar';
import IrisGridMetricCalculator, {
type IrisGridMetricState,
} from './IrisGridMetricCalculator';
import IrisGridModelUpdater from './IrisGridModelUpdater';
import IrisGridRenderer from './IrisGridRenderer';
import {
createDefaultIrisGridTheme,
type IrisGridThemeType,
} from './IrisGridTheme';
import ColumnStatistics from './ColumnStatistics';
import './IrisGrid.scss';
import AdvancedFilterCreator from './AdvancedFilterCreator';
import {
Aggregations,
AggregationEdit,
AggregationUtils,
ChartBuilder,
CustomColumnBuilder,
OptionType,
RollupRows,
TableCsvExporter,
TableSaver,
VisibilityOrderingBuilder,
DownloadServiceWorkerUtils,
} from './sidebar';
import IrisGridUtils from './IrisGridUtils';
import CrossColumnSearch from './CrossColumnSearch';
import IrisGridModel from './IrisGridModel';
import {
isPartitionedGridModel,
type PartitionConfig,
type PartitionedGridModel,
} from './PartitionedGridModel';
import IrisGridPartitionSelector from './IrisGridPartitionSelector';
import SelectDistinctBuilder from './sidebar/SelectDistinctBuilder';
import AdvancedSettingsType from './sidebar/AdvancedSettingsType';
import AdvancedSettingsMenu, {
type AdvancedSettingsMenuCallback,
} from './sidebar/AdvancedSettingsMenu';
import SHORTCUTS from './IrisGridShortcuts';
import ConditionalFormattingMenu from './sidebar/conditional-formatting/ConditionalFormattingMenu';
import ConditionalFormatEditor from './sidebar/conditional-formatting/ConditionalFormatEditor';
import IrisGridCellOverflowModal from './IrisGridCellOverflowModal';
import GotoRow, { type GotoRowElement } from './GotoRow';
import {
type Aggregation,
type AggregationSettings,
} from './sidebar/aggregations/Aggregations';
import { type ChartBuilderSettings } from './sidebar/ChartBuilder';
import AggregationOperation from './sidebar/aggregations/AggregationOperation';
import { type UIRollupConfig } from './sidebar/RollupRows';
import {
type Action,
type AdvancedFilterMap,
type AdvancedFilterOptions,
type ColumnName,
type InputFilter,
type IrisGridStateOverride,
type OperationMap,
type OptionItem,
type PendingDataErrorMap,
type PendingDataMap,
type QuickFilterMap,
type ReadonlyAdvancedFilterMap,
type ReadonlyAggregationMap,
type ReadonlyQuickFilterMap,
type UITotalsTableConfig,
} from './CommonTypes';
import type ColumnHeaderGroup from './ColumnHeaderGroup';
import { IrisGridThemeContext } from './IrisGridThemeProvider';
import { isMissingPartitionError } from './MissingPartitionError';
import { NoPastePermissionModal } from './NoPastePermissionModal';
import { isColumnHeaderGroup } from './ColumnHeaderGroup';
const log = Log.module('IrisGrid');
const VIEWPORT_LOADING_DELAY = 500;
const UPDATE_DOWNLOAD_THROTTLE = 500;
const SET_FILTER_DEBOUNCE = 250;
const SEEK_ROW_DEBOUNCE = 250;
const SET_CONDITIONAL_FORMAT_DEBOUNCE = 250;
const DEFAULT_AGGREGATION_SETTINGS = Object.freeze({
aggregations: EMPTY_ARRAY,
showOnTop: false,
});
const UNFORMATTED_DATE_PATTERN = `yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS z`;
function isEmptyConfig({
advancedFilters,
aggregationSettings,
customColumns,
quickFilters,
reverse,
rollupConfig,
searchFilter,
selectDistinctColumns,
sorts,
}: {
advancedFilters: ReadonlyAdvancedFilterMap;
aggregationSettings: AggregationSettings;
customColumns: readonly ColumnName[];
quickFilters: ReadonlyQuickFilterMap;
reverse: boolean;
rollupConfig?: UIRollupConfig;
searchFilter?: DhType.FilterCondition;
selectDistinctColumns: readonly ColumnName[];
sorts: readonly SortDescriptor[];
}): boolean {
return (
advancedFilters.size === 0 &&
aggregationSettings.aggregations.length === 0 &&
customColumns.length === 0 &&
quickFilters.size === 0 &&
!reverse &&
rollupConfig == null &&
searchFilter == null &&
selectDistinctColumns.length === 0 &&
sorts.length === 0
);
}
export type FilterData = {
operator?: FilterTypeValue; // Default behavior treats no operator as equals
text: string;
value: unknown;
startColumnIndex: number;
};
export type FilterMap = Map<
ColumnName,
{
columnType: string | null;
filterList: FilterData[];
}
>;
export interface IrisGridContextMenuData {
model: IrisGridModel;
value: unknown;
valueText: string | null;
column: DhType.Column;
rowIndex: GridRangeIndex;
columnIndex: GridRangeIndex;
modelRow: GridRangeIndex;
modelColumn: GridRangeIndex;
}
export type MouseHandlersProp = readonly (
| GridMouseHandler
| ((irisGrid: IrisGrid) => GridMouseHandler)
)[];
export type GetMetricCalculatorType = (
...args: ConstructorParameters<typeof IrisGridMetricCalculator>
) => IrisGridMetricCalculator;
export interface IrisGridProps {
children?: React.ReactNode;
advancedFilters: ReadonlyAdvancedFilterMap;
advancedSettings: ReadonlyMap<AdvancedSettingsType, boolean>;
alwaysFetchColumns: readonly ColumnName[];
isFilterBarShown: boolean;
applyInputFiltersOnInit: boolean;
conditionalFormats: readonly SidebarFormattingRule[];
customColumnFormatMap: ReadonlyMap<ColumnName, FormattingRule>;
columnAlignmentMap: ReadonlyMap<string, CanvasTextAlign>;
model: IrisGridModel;
movedColumns: readonly MoveOperation[];
movedRows: readonly MoveOperation[];
inputFilters: readonly InputFilter[];
customFilters: readonly DhType.FilterCondition[];
onCreateChart: (settings: ChartBuilderSettings, model: IrisGridModel) => void;
onColumnSelected: (column: DhType.Column) => void;
onError: (error: unknown) => void;
onDataSelected: (index: ModelIndex, map: RowDataMap) => void;
onStateChange: (irisGridState: IrisGridState, gridState: GridState) => void;
onAdvancedSettingsChange: AdvancedSettingsMenuCallback;
/** @deprecated use `partitionConfig` instead */
partitions?: (string | null)[];
partitionConfig?: PartitionConfig;
sorts: readonly SortDescriptor[];
/** @deprecated use `reverse` instead */
reverseType?: ReverseType;
reverse: boolean;
quickFilters: ReadonlyQuickFilterMap | null;
customColumns: readonly ColumnName[];
selectDistinctColumns: readonly ColumnName[];
settings?: Settings;
userColumnWidths: ReadonlyMap<ModelIndex, number>;
userRowHeights: ReadonlyMap<ModelIndex, number>;
onSelectionChanged: (gridRanges: readonly GridRange[]) => void;
rollupConfig?: UIRollupConfig;
aggregationSettings: AggregationSettings;
isSelectingColumn: boolean;
isSelectingPartition: boolean;
isStuckToBottom: boolean;
isStuckToRight: boolean;
// eslint-disable-next-line react/no-unused-prop-types
columnSelectionValidator?: (value: DhType.Column | null) => boolean;
columnAllowedCursor: string;
// eslint-disable-next-line react/no-unused-prop-types
columnNotAllowedCursor: string;
// eslint-disable-next-line react/no-unused-prop-types
copyCursor: string;
name: string;
onlyFetchVisibleColumns: boolean;
showSearchBar: boolean;
searchValue: string;
selectedSearchColumns?: readonly ColumnName[];
invertSearchColumns: boolean;
// eslint-disable-next-line react/no-unused-prop-types
onContextMenu: (
data: IrisGridContextMenuData
) => readonly ResolvableContextAction[];
pendingDataMap?: PendingDataMap;
getDownloadWorker: () => Promise<ServiceWorker>;
canCopy: boolean;
canDownloadCsv: boolean;
frozenColumns: readonly ColumnName[];
// Theme override for IrisGridTheme
theme?: Partial<IrisGridThemeType> & Record<string, unknown>;
canToggleSearch: boolean;
columnHeaderGroups?: readonly ColumnHeaderGroup[];
// Optional key and mouse handlers
keyHandlers: readonly KeyHandler[];
mouseHandlers: MouseHandlersProp;
// Pass in a custom renderer to the grid for advanced use cases
renderer?: IrisGridRenderer;
density?: 'compact' | 'regular' | 'spacious';
getMetricCalculator: GetMetricCalculatorType;
}
export interface IrisGridState {
isFilterBarShown: boolean;
isSelectingPartition: boolean;
focusedFilterBarColumn: number | null;
metricCalculator: IrisGridMetricCalculator;
metrics?: GridMetrics;
partitionConfig?: PartitionConfig;
// setAdvancedFilter and setQuickFilter mutate the arguments
// so we want to always use map copies from the state instead of props
quickFilters: ReadonlyQuickFilterMap;
advancedFilters: ReadonlyAdvancedFilterMap;
shownAdvancedFilter: number | null;
hoverAdvancedFilter: number | null;
sorts: readonly SortDescriptor[];
reverse: boolean;
customColumns: readonly ColumnName[];
selectDistinctColumns: readonly ColumnName[];
// selected range in table
selectedRanges: readonly GridRange[];
// Current ongoing copy operation
copyOperation: CopyOperation | null;
// The filter that is currently being applied. Reset after update is received
loadingText: string | null;
loadingScrimProgress: number | null;
loadingSpinnerShown: boolean;
loadingCancelShown: boolean;
loadingBlocksGrid: boolean;
movedColumns: readonly MoveOperation[];
movedRows: readonly MoveOperation[];
shownColumnTooltip: number | null;
formatter: Formatter;
isMenuShown: boolean;
customColumnFormatMap: Map<ColumnName, FormattingRule>;
columnAlignmentMap: Map<string, CanvasTextAlign>;
conditionalFormats: readonly SidebarFormattingRule[];
conditionalFormatEditIndex: number | null;
conditionalFormatPreview?: SidebarFormattingRule;
// Column user is hovering over for selection
hoverSelectColumn: GridRangeIndex;
isTableDownloading: boolean;
isReady: boolean;
tableDownloadStatus: string;
tableDownloadProgress: number;
tableDownloadEstimatedTime: number | null;
showSearchBar: boolean;
searchFilter?: DhType.FilterCondition;
searchValue: string;
selectedSearchColumns: readonly ColumnName[];
invertSearchColumns: boolean;
rollupConfig?: UIRollupConfig;
rollupSelectedColumns: readonly ColumnName[];
aggregationSettings: AggregationSettings;
selectedAggregation: Aggregation | null;
openOptions: readonly OptionItem[];
pendingRowCount: number;
pendingDataMap: PendingDataMap;
pendingDataErrors: PendingDataErrorMap;
pendingSavePromise: Promise<void> | null;
pendingSaveError: string | null;
toastMessage: JSX.Element | null;
frozenColumns: readonly ColumnName[];
showOverflowModal: boolean;
showNoPastePermissionModal: boolean;
noPastePermissionError: string;
overflowText: string;
overflowButtonTooltipProps: CSSProperties | null;
expandCellTooltipProps: CSSProperties | null;
expandTooltipDisplayValue: string;
hoverTooltipProps: CSSProperties | null;
hoverDisplayValue: ReactNode;
gotoRow: string;
gotoRowError: string;
gotoValueError: string;
isGotoShown: boolean;
gotoValueSelectedColumnName: ColumnName;
gotoValueSelectedFilter: FilterTypeValue;
gotoValueManuallyChanged: boolean;
gotoValue: string;
columnHeaderGroups: readonly ColumnHeaderGroup[];
}
class IrisGrid extends Component<IrisGridProps, IrisGridState> {
static contextType = IrisGridThemeContext;
// eslint-disable-next-line react/static-property-placement, react/sort-comp
declare context: React.ContextType<typeof IrisGridThemeContext>;
static minDebounce = 150;
static maxDebounce = 500;
static loadingSpinnerDelay = 800;
static defaultProps = {
advancedFilters: EMPTY_MAP,
advancedSettings: EMPTY_MAP,
alwaysFetchColumns: EMPTY_ARRAY,
conditionalFormats: EMPTY_ARRAY,
customColumnFormatMap: EMPTY_MAP,
columnAlignmentMap: EMPTY_MAP,
isFilterBarShown: false,
applyInputFiltersOnInit: false,
movedColumns: EMPTY_ARRAY,
movedRows: EMPTY_ARRAY,
inputFilters: EMPTY_ARRAY,
customFilters: EMPTY_ARRAY,
onCreateChart: undefined,
onColumnSelected: (): void => undefined,
onDataSelected: (): void => undefined,
onError: (): void => undefined,
onStateChange: (): void => undefined,
onAdvancedSettingsChange: (): void => undefined,
partitions: undefined,
partitionConfig: undefined,
quickFilters: EMPTY_MAP,
selectDistinctColumns: EMPTY_ARRAY,
sorts: EMPTY_ARRAY,
reverse: false,
customColumns: EMPTY_ARRAY,
aggregationSettings: DEFAULT_AGGREGATION_SETTINGS,
rollupConfig: undefined,
userColumnWidths: EMPTY_MAP,
userRowHeights: EMPTY_MAP,
onSelectionChanged: (): void => undefined,
isSelectingColumn: false,
isSelectingPartition: false,
isStuckToBottom: false,
isStuckToRight: false,
columnAllowedCursor: 'linker',
columnNotAllowedCursor: 'linker-not-allowed',
copyCursor: 'copy',
name: 'table',
onlyFetchVisibleColumns: true,
showSearchBar: false,
searchValue: '',
invertSearchColumns: true,
onContextMenu: (): readonly ResolvableContextAction[] => EMPTY_ARRAY,
pendingDataMap: EMPTY_MAP,
getDownloadWorker: DownloadServiceWorkerUtils.getServiceWorker,
settings: {
timeZone: 'America/New_York',
defaultDateTimeFormat: DateUtils.FULL_DATE_FORMAT,
showTimeZone: false,
showTSeparator: true,
truncateNumbersWithPound: false,
showEmptyStrings: true,
showNullStrings: true,
showExtraGroupColumn: true,
formatter: EMPTY_ARRAY,
},
canCopy: true,
canDownloadCsv: true,
frozenColumns: undefined,
// Do not set a default density prop since we need to know if it overrides the global density setting
density: undefined,
canToggleSearch: true,
mouseHandlers: EMPTY_ARRAY,
keyHandlers: EMPTY_ARRAY,
getMetricCalculator: (
...args: ConstructorParameters<typeof IrisGridMetricCalculator>
): IrisGridMetricCalculator => new IrisGridMetricCalculator(...args),
} satisfies Partial<IrisGridProps>;
constructor(props: IrisGridProps) {
super(props);
this.handleAdvancedFilterChange =
this.handleAdvancedFilterChange.bind(this);
this.handleAdvancedFilterSortChange =
this.handleAdvancedFilterSortChange.bind(this);
this.handleAdvancedFilterDone = this.handleAdvancedFilterDone.bind(this);
this.handleAdvancedMenuOpened = this.handleAdvancedMenuOpened.bind(this);
this.handleGotoRowOpened = this.handleGotoRowOpened.bind(this);
this.handleGotoRowClosed = this.handleGotoRowClosed.bind(this);
this.handleAdvancedMenuClosed = this.handleAdvancedMenuClosed.bind(this);
this.handleAggregationChange = this.handleAggregationChange.bind(this);
this.handleAggregationsChange = this.handleAggregationsChange.bind(this);
this.handleAggregationEdit = this.handleAggregationEdit.bind(this);
this.handleAnimationLoop = this.handleAnimationLoop.bind(this);
this.handleAnimationStart = this.handleAnimationStart.bind(this);
this.handleAnimationEnd = this.handleAnimationEnd.bind(this);
this.handleChartChange = this.handleChartChange.bind(this);
this.handleChartCreate = this.handleChartCreate.bind(this);
this.handleGridError = this.handleGridError.bind(this);
this.handleFilterBarChange = this.handleFilterBarChange.bind(this);
this.handleFilterBarDone = this.handleFilterBarDone.bind(this);
this.handleFilterBarTab = this.handleFilterBarTab.bind(this);
this.handleCancel = this.handleCancel.bind(this);
this.handleMenu = this.handleMenu.bind(this);
this.handleMenuClose = this.handleMenuClose.bind(this);
this.handleMenuSelect = this.handleMenuSelect.bind(this);
this.handleMenuBack = this.handleMenuBack.bind(this);
this.handleRequestFailed = this.handleRequestFailed.bind(this);
this.handleSelectionChanged = this.handleSelectionChanged.bind(this);
this.handleMovedColumnsChanged = this.handleMovedColumnsChanged.bind(this);
this.handleHeaderGroupsChanged = this.handleHeaderGroupsChanged.bind(this);
this.handleUpdate = this.handleUpdate.bind(this);
this.handleTableChanged = this.handleTableChanged.bind(this);
this.handleTooltipRef = this.handleTooltipRef.bind(this);
this.handleViewChanged = this.handleViewChanged.bind(this);
this.handleFormatSelection = this.handleFormatSelection.bind(this);
this.handleColumnAlignmentChange =
this.handleColumnAlignmentChange.bind(this);
this.handleConditionalFormatCreate =
this.handleConditionalFormatCreate.bind(this);
this.handleConditionalFormatEdit =
this.handleConditionalFormatEdit.bind(this);
this.handleConditionalFormatsChange =
this.handleConditionalFormatsChange.bind(this);
this.handleConditionalFormatEditorSave =
this.handleConditionalFormatEditorSave.bind(this);
this.handleConditionalFormatEditorCancel =
this.handleConditionalFormatEditorCancel.bind(this);
this.handleUpdateCustomColumns = this.handleUpdateCustomColumns.bind(this);
this.handleCustomColumnsChanged =
this.handleCustomColumnsChanged.bind(this);
this.handleSelectDistinctChanged =
this.handleSelectDistinctChanged.bind(this);
this.handlePendingDataUpdated = this.handlePendingDataUpdated.bind(this);
this.handleViewportUpdated = this.handleViewportUpdated.bind(this);
this.handlePendingCommitClicked =
this.handlePendingCommitClicked.bind(this);
this.handlePendingDiscardClicked =
this.handlePendingDiscardClicked.bind(this);
this.handleGotoRowSelectedRowNumberSubmit =
this.handleGotoRowSelectedRowNumberSubmit.bind(this);
this.focusRowInGrid = this.focusRowInGrid.bind(this);
this.handleDownloadTable = this.handleDownloadTable.bind(this);
this.handleDownloadTableStart = this.handleDownloadTableStart.bind(this);
this.handleCancelDownloadTable = this.handleCancelDownloadTable.bind(this);
this.handleDownloadCanceled = this.handleDownloadCanceled.bind(this);
this.handleDownloadCompleted = this.handleDownloadCompleted.bind(this);
this.handlePartitionChange = this.handlePartitionChange.bind(this);
this.handleColumnVisibilityChanged =
this.handleColumnVisibilityChanged.bind(this);
this.handleColumnVisibilityReset =
this.handleColumnVisibilityReset.bind(this);
this.handleCrossColumnSearch = this.handleCrossColumnSearch.bind(this);
this.handleRollupChange = this.handleRollupChange.bind(this);
this.handleOverflowClose = this.handleOverflowClose.bind(this);
this.handleCloseNoPastePermissionModal =
this.handleCloseNoPastePermissionModal.bind(this);
this.getColumnBoundingRect = this.getColumnBoundingRect.bind(this);
this.handleGotoRowSelectedRowNumberChanged =
this.handleGotoRowSelectedRowNumberChanged.bind(this);
this.handleGotoValueSelectedColumnNameChanged =
this.handleGotoValueSelectedColumnNameChanged.bind(this);
this.handleGotoValueSelectedFilterChanged =
this.handleGotoValueSelectedFilterChanged.bind(this);
this.handleGotoValueChanged = this.handleGotoValueChanged.bind(this);
this.handleGotoValueSubmitted = this.handleGotoValueSubmitted.bind(this);
this.handleViewportUpdated = this.handleViewportUpdated.bind(this);
this.makeQuickFilter = this.makeQuickFilter.bind(this);
this.setFilterMap = this.setFilterMap.bind(this);
this.handleFrozenColumnsChanged =
this.handleFrozenColumnsChanged.bind(this);
this.grid = null;
this.lastLoadedConfig = null;
this.pending = new Pending();
this.globalColumnFormats = EMPTY_ARRAY;
this.decimalFormatOptions = {};
this.integerFormatOptions = {};
this.truncateNumbersWithPound = false;
this.showEmptyStrings = true;
this.showNullStrings = true;
this.showExtraGroupColumn = true;
// When the loading scrim started/when it should extend to the end of the screen.
this.tableSaver = null;
this.crossColumnRef = React.createRef();
this.isAnimating = false;
this.filterInputRef = React.createRef();
this.gotoRowRef = React.createRef();
this.isCopying = false;
this.toggleFilterBarAction = {
action: () => this.toggleFilterBar(),
shortcut: SHORTCUTS.TABLE.TOGGLE_QUICK_FILTER,
};
this.toggleSearchBarAction = {
action: () => this.toggleSearchBar(),
shortcut: SHORTCUTS.TABLE.TOGGLE_SEARCH,
};
this.toggleGotoRowAction = {
action: () => this.toggleGotoRow(),
shortcut: SHORTCUTS.TABLE.GOTO_ROW,
};
this.discardAction = {
action: () => {
const { model } = this.props;
if (
isEditableGridModel(model) &&
model.isEditable &&
model.pendingDataMap.size > 0
) {
this.discardPending().catch(log.error);
}
},
shortcut: SHORTCUTS.INPUT_TABLE.DISCARD,
};
this.commitAction = {
action: () => {
const { model } = this.props;
if (
isEditableGridModel(model) &&
model.isEditable &&
model.pendingDataMap.size > 0 &&
model.pendingDataErrors.size === 0
) {
this.commitPending().catch(log.error);
}
},
shortcut: SHORTCUTS.INPUT_TABLE.COMMIT,
};
this.contextActions = [
this.toggleFilterBarAction,
this.toggleSearchBarAction,
this.toggleGotoRowAction,
this.discardAction,
this.commitAction,
];
const {
aggregationSettings,
conditionalFormats,
customColumnFormatMap,
columnAlignmentMap,
isFilterBarShown,
isSelectingPartition,
partitions,
partitionConfig,
model,
movedColumns: movedColumnsProp,
movedRows: movedRowsProp,
rollupConfig,
userColumnWidths,
userRowHeights,
showSearchBar,
searchValue,
selectedSearchColumns,
invertSearchColumns,
advancedFilters,
quickFilters,
selectDistinctColumns,
pendingDataMap,
canCopy,
frozenColumns,
columnHeaderGroups,
getMetricCalculator,
} = props;
const { dh } = model;
const keyHandlers: KeyHandler[] = [
new CopyCellKeyHandler(this),
new ReverseKeyHandler(this),
new ClearFilterKeyHandler(this),
];
const mouseHandlers: MouseHandlersProp = [
new IrisGridCellOverflowMouseHandler(this),
new IrisGridRowTreeMouseHandler(this),
new IrisGridTokenMouseHandler(this),
new IrisGridColumnSelectMouseHandler(this),
new IrisGridColumnTooltipMouseHandler(this),
new IrisGridSortMouseHandler(this),
new IrisGridFilterMouseHandler(this),
new IrisGridContextMenuHandler(this, dh),
new IrisGridDataSelectMouseHandler(this),
new PendingMouseHandler(this),
new IrisGridPartitionedTableMouseHandler(this),
...(canCopy ? [new IrisGridCopyCellMouseHandler(this)] : []),
];
if (canCopy) {
keyHandlers.push(new CopyKeyHandler(this));
}
const movedColumns =
movedColumnsProp.length > 0
? movedColumnsProp
: model.initialMovedColumns;
const movedRows =
movedRowsProp.length > 0 ? movedRowsProp : model.initialMovedRows;
const metricCalculator = getMetricCalculator({
userColumnWidths: new Map(userColumnWidths),
userRowHeights: new Map(userRowHeights),
movedColumns,
initialColumnWidths: new Map(
model?.layoutHints?.hiddenColumns?.map(name => [
model.getColumnIndexByName(name),
0,
])
),
});
const searchColumns = selectedSearchColumns ?? [];
const searchFilter = CrossColumnSearch.createSearchFilter(
dh,
searchValue,
searchColumns,
model.columns,
invertSearchColumns
);
this.tableUtils = new TableUtils(dh);
this.mouseHandlers = mouseHandlers;
this.keyHandlers = keyHandlers;
this.state = {
isFilterBarShown,
isSelectingPartition,
focusedFilterBarColumn: null,
metricCalculator,
metrics: undefined,
partitionConfig:
partitionConfig ??
(partitions && partitions.length
? { partitions, mode: 'partition' }
: undefined),
// setAdvancedFilter and setQuickFilter mutate the arguments
// so we want to always use map copies from the state instead of props
quickFilters: quickFilters ? new Map(quickFilters) : new Map(),
advancedFilters: new Map(advancedFilters),
shownAdvancedFilter: null,
hoverAdvancedFilter: null,
sorts: [],
reverse: false,
customColumns: [],
selectDistinctColumns,
// selected range in table
selectedRanges: [],
// Current ongoing copy operation
copyOperation: null,
// The filter that is currently being applied. Reset after update is received
loadingText: null,
loadingScrimProgress: null,
loadingSpinnerShown: false,
loadingCancelShown: false,
loadingBlocksGrid: false,
movedColumns,
movedRows,
shownColumnTooltip: null,
formatter: new Formatter(dh),
isMenuShown: false,
customColumnFormatMap: new Map(customColumnFormatMap),
columnAlignmentMap: new Map(columnAlignmentMap),
conditionalFormats,
conditionalFormatEditIndex: null,
conditionalFormatPreview: undefined,
// Column user is hovering over for selection
hoverSelectColumn: null,
isTableDownloading: false,
isReady: false,
tableDownloadStatus: '',
tableDownloadProgress: 0,
tableDownloadEstimatedTime: 0,
showSearchBar,
searchFilter,
searchValue,
selectedSearchColumns: searchColumns,
invertSearchColumns,
rollupConfig,
rollupSelectedColumns: [],
aggregationSettings:
// Pin aggregations to the top if the grid is editable, so that the bottom is reserved for pending rows
isEditableGridModel(model) && model.isEditable
? { ...aggregationSettings, showOnTop: true }
: aggregationSettings,
selectedAggregation: null,
openOptions: [],
pendingRowCount: 0,
pendingDataMap: pendingDataMap ?? new Map(),
pendingDataErrors: new Map(),
pendingSavePromise: null,
pendingSaveError: null,
toastMessage: null,
frozenColumns,
showOverflowModal: false,
showNoPastePermissionModal: false,
noPastePermissionError: '',
overflowText: '',
overflowButtonTooltipProps: null,
expandCellTooltipProps: null,
expandTooltipDisplayValue: 'expand',
hoverTooltipProps: null,
hoverDisplayValue: '',
isGotoShown: false,
gotoRow: '',
gotoRowError: '',
gotoValueError: '',
gotoValueSelectedColumnName: model.columns[0]?.name ?? '',
gotoValueSelectedFilter: FilterType.eqIgnoreCase,
gotoValue: '',
gotoValueManuallyChanged: false,
columnHeaderGroups: columnHeaderGroups ?? model.initialColumnHeaderGroups,
};
}
componentDidMount(): void {
const { model } = this.props;
this.initState();
this.startListening(model);
}
componentDidUpdate(prevProps: IrisGridProps, prevState: IrisGridState): void {
const {
inputFilters,
isSelectingColumn,
settings,
model,
customFilters,
sorts,
} = this.props;
if (model !== prevProps.model) {
this.stopListening(prevProps.model);
this.startListening(model);
}
const changedInputFilters =
inputFilters !== prevProps.inputFilters
? inputFilters.filter(
inputFilter => !prevProps.inputFilters.includes(inputFilter)
)
: [];
if (changedInputFilters.length > 0) {
const { advancedSettings } = this.props;
const replaceExistingFilters =
advancedSettings.get(
AdvancedSettingsType.FILTER_CONTROL_CHANGE_CLEARS_ALL_FILTERS
) ?? false;
if (replaceExistingFilters) {
this.clearGridInputField();
this.clearCrossColumSearch();
}
const isChanged = this.applyInputFilters(
changedInputFilters,
replaceExistingFilters
);
if (isChanged) {
this.startLoading('Filtering...', { resetRanges: true });
}
}
if (isSelectingColumn !== prevProps.isSelectingColumn) {
this.resetColumnSelection();
}
if (settings !== prevProps.settings) {
this.updateFormatterSettings(settings);
}
if (customFilters !== prevProps.customFilters) {
this.startLoading('Filtering...', { resetRanges: true });
}
if (sorts !== prevProps.sorts) {
this.updateSorts(sorts);
}
const { loadingScrimStartTime, loadingScrimFinishTime } = this;
if (loadingScrimStartTime != null && loadingScrimFinishTime != null) {
window.requestAnimationFrame(() => {
const now = Date.now();
const currentTime = now - loadingScrimStartTime;
const totalTime = loadingScrimFinishTime - loadingScrimStartTime;
const loadingScrimProgress = Math.min(currentTime / totalTime, 1);
if (loadingScrimFinishTime < now) {
this.loadingScrimStartTime = undefined;
this.loadingScrimFinishTime = undefined;
}
this.setState(state => {
if (state.loadingScrimProgress == null) {
log.debug2('Ignoring scrim update because loading cancelled.');
return null;
}
return { loadingScrimProgress };