forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIrisGridModel.ts
More file actions
628 lines (537 loc) · 16.1 KB
/
IrisGridModel.ts
File metadata and controls
628 lines (537 loc) · 16.1 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
/* eslint-disable class-methods-use-this */
import type { Event, EventTarget } from 'event-target-shim';
import {
BoundedAxisRange,
DataBarGridModel,
DataBarOptions,
GridCell,
GridModel,
GridRange,
GridThemeType,
ModelIndex,
MoveOperation,
VisibleIndex,
} from '@deephaven/grid';
import type { dh as DhType } from '@deephaven/jsapi-types';
import { type Formatter, type SortDescriptor } from '@deephaven/jsapi-utils';
import {
ColumnName,
UITotalsTableConfig,
PendingDataMap,
PendingDataErrorMap,
} from './CommonTypes';
import ColumnHeaderGroup from './ColumnHeaderGroup';
export type DisplayColumn = DhType.Column & {
/**
* Name to display with the column.
* The `name` property on `Column` is a unique identifier and must be a valid Java identifier,
* whereas `displayName` can be any string and does not need to be unique.
*/
displayName?: string;
/**
* Whether this column is a proxy column for other columns or not.
* If it's a proxy column, it may not appear in some lists.
*/
isProxy?: boolean;
};
type IrisGridModelEventNames =
(typeof IrisGridModel.EVENT)[keyof typeof IrisGridModel.EVENT];
type IrisGridModelEventMap = {
[E in IrisGridModelEventNames]: Event<E>;
};
const EMPTY_ARRAY: never[] = [];
const EMPTY_SET: Set<never> = new Set();
/**
* Abstract class that extends the GridModel to have more functionality, like filtering and sorting.
* For use from IrisGrid.
* Provides some abstraction from the dh.Table and dh.TreeTable classes, so we can treat them somewhat the same.
* Note that it still uses dh.Column, dh.FilterCondition, dh.Sort, etc., still. Theoretically should abstract
* those out as well, so there's no dependency on IrisAPI at all, but it's a lot of work for no real gain at this time.
*/
abstract class IrisGridModel<
TEventMap extends Record<string, Event<string>> = Record<
string,
Event<string>
>,
TMode extends 'standard' | 'strict' = 'standard',
>
extends GridModel<TEventMap & IrisGridModelEventMap, TMode>
implements DataBarGridModel
{
static EVENT = Object.freeze({
UPDATED: 'UPDATED',
FORMATTER_UPDATED: 'FORMATTER_UPDATED',
REQUEST_FAILED: 'REQUEST_FAILED',
COLUMNS_CHANGED: 'COLUMNS_CHANGED',
TABLE_CHANGED: 'TABLE_CHANGED',
FILTERS_CHANGED: 'FILTERS_CHANGED',
SORTS_CHANGED: 'SORTS_CHANGED',
DISCONNECT: 'DISCONNECT',
RECONNECT: 'RECONNECT',
TOTALS_UPDATED: 'TOTALS_UPDATED',
/** Fired when the viewport is applied to the table and we're waiting for a response. */
PENDING_DATA_UPDATED: 'PENDING_DATA_UPDATED',
VIEWPORT_UPDATED: 'VIEWPORT_UPDATED',
} as const);
constructor(dh: typeof DhType) {
super();
this.dh = dh;
this.listenerCount = 0;
}
dh: typeof DhType;
listenerCount: number;
// Pulled directly from event-target-shim implementation signature
// https://github.com/mysticatea/event-target-shim/blob/master/src/lib/event-target.ts#L99
// Using Parameters<GridModel['addEventListener']> doesn't work
addEventListener<T extends string & keyof TEventMap>(
type0: T,
callback0?: EventTarget.EventListener<this, TEventMap[T]> | null,
options0?: boolean | EventTarget.AddOptions
): void {
super.addEventListener(type0, callback0 as never, options0 as never);
this.listenerCount += 1;
if (this.listenerCount === 1) {
this.startListening();
}
}
removeEventListener<T extends string & keyof TEventMap>(
type0: T,
callback0?: EventTarget.EventListener<this, TEventMap[T]> | null,
options0?: boolean | EventTarget.Options
): void {
super.removeEventListener(type0, callback0 as never, options0 as never);
this.listenerCount -= 1;
if (this.listenerCount === 0) {
this.stopListening();
}
}
/**
* Function called when first listener is added.
* Override for implementation specific behaviour.
*/
startListening(): void {
// no-op
}
/**
* Function called when last listener is removed.
* Override for implementation specific behaviour.
*/
stopListening(): void {
// no-op
}
/**
* Gets the columns for this model
* @returns All columns in the model
*/
abstract get columns(): readonly DisplayColumn[];
/**
* Retrieve the aggregated columns for this model
* @returns The columns that are aggregated
*/
get aggregatedColumns(): readonly DisplayColumn[] {
return EMPTY_ARRAY;
}
/**
* Retrieve the grouped columns for this model
* @returns The columns that are grouped
*/
get groupedColumns(): readonly DisplayColumn[] {
return EMPTY_ARRAY;
}
/**
* Gets the columns for the model before any transformations (such as rollups) are applied.
* @returns All original columns in the model.
*/
get originalColumns(): readonly DisplayColumn[] {
return this.columns;
}
/**
* Gets the column index for this model
* @param name The model column name.
* @returns The numeric index of the requested column.
*/
abstract getColumnIndexByName(name: string): ModelIndex | undefined;
/**
* Retrieve the source cell for a given cell. Returns something different if the cell is a proxied cell
* that retrieves data from another cell.
* @param column Column to get the source for
* @param row Row to get the source for
* @returns Source cell where the data is coming from
*/
sourceForCell(column: ModelIndex, row: ModelIndex): GridCell {
return { column, row };
}
/**
* Retrieve the range of columns to clear filters on for a given column.
* @param column Column to get the range of filters to clear.
* @returns Axis range of the column filters to clear, or `null` if this should not have a clear filter option.
*/
getClearFilterRange(column: ModelIndex): BoundedAxisRange | null {
if (this.isFilterable(column)) {
return [column, column];
}
return null;
}
/** List of column movements defined by the model. Used as initial movements for IrisGrid */
get initialMovedColumns(): readonly MoveOperation[] {
return EMPTY_ARRAY;
}
/** List of row movements defined by the model. Used as initial movements for IrisGrid */
get initialMovedRows(): readonly MoveOperation[] {
return EMPTY_ARRAY;
}
/** List of column header groups defined by the model */
get initialColumnHeaderGroups(): readonly ColumnHeaderGroup[] {
return EMPTY_ARRAY;
}
/**
* @param column The model column index
* @param row The model row index
* @returns The format stored for that cell
*/
abstract formatForCell(
column: ModelIndex,
row: ModelIndex
): DhType.Format | undefined;
/**
* @param column The model column index
* @param row The model row index
* @returns The value stored for that cell
*/
abstract valueForCell(column: ModelIndex, row: ModelIndex): unknown;
/**
* @returns The filters set on this model
*/
abstract get filter(): readonly DhType.FilterCondition[];
/**
* @param filter The filters to set
*/
abstract set filter(filter: readonly DhType.FilterCondition[]);
/**
* @returns The formatter used when formatting data
*/
abstract get formatter(): Formatter;
/**
* @param formatter The formatter to set
*/
abstract set formatter(formatter: Formatter);
/**
* @param value The value to format
* @param columnType The column type to format
* @param columnName The column name to format
*/
abstract displayString(
value: unknown,
columnType: string,
columnName?: ColumnName
): string;
/**
* @returns The sorts used on this model
*/
abstract get sort(): readonly SortDescriptor[];
/**
* @param sort The sorts to use on this model
*/
abstract set sort(sort: readonly SortDescriptor[]);
/**
/**
* @returns The custom columns on this model
*/
abstract get customColumns(): readonly ColumnName[];
/**
* @param customColumns The custom columns to use
*/
abstract set customColumns(customColumns: readonly ColumnName[]);
/**
* @returns The format columns on this model
*/
abstract get formatColumns(): readonly DhType.CustomColumn[];
/**
* @param formatColumns The format columns to use
*/
abstract set formatColumns(formatColumns: readonly DhType.CustomColumn[]);
/**
* @param columns The columns to treat as frozen
*/
abstract updateFrozenColumns(columns: readonly ColumnName[]): void;
/**
* @returns The config to use for rolling up this table
*/
abstract get rollupConfig(): DhType.RollupConfig | null;
abstract set rollupConfig(rollupConfig: DhType.RollupConfig | null);
/**
* @returns The config to use for the totals table of this model
*/
abstract get totalsConfig(): UITotalsTableConfig | null;
abstract set totalsConfig(totalsConfig: UITotalsTableConfig | null);
/**
* @returns The LayoutHints to use for the columns of this table model
*/
get layoutHints(): DhType.LayoutHints | null | undefined {
return null;
}
/**
* @returns Names of columns which should be locked to the front, but not floating
*/
get frontColumns(): readonly ColumnName[] {
return EMPTY_ARRAY;
}
/**
* @returns Names of columns which should be locked to the back, but not floating
*/
get backColumns(): readonly ColumnName[] {
return EMPTY_ARRAY;
}
/**
* @returns Names of key columns
*/
get keyColumnSet(): Set<ColumnName> {
return EMPTY_SET;
}
/**
* @returns Names of columns which should be frozen to the front and floating
*/
get frozenColumns(): readonly ColumnName[] {
return EMPTY_ARRAY;
}
/**
* @param index The column index to check
* @returns Whether the column is one of LayoutHints' frozen columns
*/
isColumnFrozen(index: ModelIndex): boolean {
return false;
}
/**
* @param index The column index to check
* @returns Whether the column is sortable
*/
isColumnSortable(index: ModelIndex): boolean {
return false;
}
/**
* @deprecated Replaced with isPartitionRequired()
* @returns True if this model requires a filter to be set
*/
get isFilterRequired(): boolean {
return false;
}
get isReversible(): boolean {
return true;
}
/**
* @returns Returns a raw table that is frozen and can be used for exporting data
*/
abstract export(): Promise<DhType.Table>;
/**
* @returns True if this model supports the columnStatistics(column) function
*/
get isColumnStatisticsAvailable(): boolean {
return false;
}
/**
* The description for this model.
* @returns The description of the model
*/
get description(): string {
return '';
}
/**
* @param column The column to get statistics for
* @returns The column statistics
*/
abstract columnStatistics(
column: DhType.Column
): Promise<DhType.ColumnStatistics>;
/**
* @returns True if this model supports aggregatedColumns
*/
get isAggregatedColumnsAvailable(): boolean {
return false;
}
/**
* @returns True if this model supports column groups and moved columns
*/
get isOrganizeColumnsAvailable(): boolean {
return false;
}
/**
* @returns True if this model supports customColumns
*/
get isCustomColumnsAvailable(): boolean {
return false;
}
/**
* @returns True if this model supports customColumns
*/
get isFormatColumnsAvailable(): boolean {
return false;
}
/**
* @returns True if this model supports the export() function
*/
get isExportAvailable(): boolean {
return false;
}
/**
* @returns True if this model supports the valuesTable(column) function
*/
get isValuesTableAvailable(): boolean {
return false;
}
/**
* @returns True if this model should allow the chart builder
*/
get isChartBuilderAvailable(): boolean {
return false;
}
/**
* @returns True if the rollup rows functionality is available
*/
get isRollupAvailable(): boolean {
return false;
}
/**
* @returns True if select distinct functionality is available
*/
get isSelectDistinctAvailable(): boolean {
return false;
}
/**
* @returns True if the totals functionality is available
*/
get isTotalsAvailable(): boolean {
return false;
}
/**
* The names of columns with select distinct enabled
* @returns An array of column names
*/
abstract get selectDistinctColumns(): readonly ColumnName[];
/**
* Set the columns with select distinct enabled
* @param names The array of column names to enable select distinct on
*/
abstract set selectDistinctColumns(names: readonly ColumnName[]);
/**
* The pending data for this model
* @returns A map of row index to a map of column name/value pairs
*/
abstract get pendingDataMap(): PendingDataMap;
/**
* Set the pending data for this model
* @param A map of row index to a map of column name/value pairs
*/
abstract set pendingDataMap(map: PendingDataMap);
/**
* @returns The count of pending rows to show
*/
abstract get pendingRowCount(): number;
/**
* Set the count of pending rows to show
* @param count The count of pending rows to show
*/
abstract set pendingRowCount(count: number);
/**
* Errors for the pending data
* @returns Map from row number to the error
*/
abstract get pendingDataErrors(): PendingDataErrorMap;
/**
* Commit pending data and save all data to the table
*/
abstract commitPending(): Promise<void>;
/**
* Check if viewport is still loading data
*/
get isViewportPending(): boolean {
return false;
}
/**
* Check if a column is filterable
* @param columnIndex The column index to check for filterability
* @returns True if the current provided column index is filterable, false otherwise
*/
isFilterable(columnIndex: ModelIndex): boolean {
return false;
}
/**
* Set the indices of the viewport
* @param top Top of viewport
* @param bottom Bottom of viewport
* @param columns The columns in the viewport. `undefined` for all columns
*/
abstract setViewport(
top: VisibleIndex,
bottom: VisibleIndex,
columns?: DhType.Column[]
): void;
/**
* Takes a snapshot of the provided ranges
* @param ranges The model ranges to take the snapshot of
* @returns Returns the data in a row/column matrix
*/
abstract snapshot(
ranges: readonly GridRange[]
): Promise<readonly unknown[][]>;
/**
* @param ranges The ranges to take a snapshot of
* @param includeHeaders Whether to include the headers in the snapshot or not
* @param formatValue A function to format a value for a cell. Defaults to model format value.
* @returns A text formatted snapshot of the data for the specified range set
*/
abstract textSnapshot(
ranges: readonly GridRange[],
includeHeaders?: boolean,
formatValue?: (
value: unknown,
column: DhType.Column,
row?: DhType.Row
) => string
): Promise<string>;
/**
* @param column The columns to get the distinct values for
* @returns A table partitioned on the specified columns in the order given in
*/
abstract valuesTable(
columns: DhType.Column | readonly DhType.Column[]
): Promise<DhType.Table>;
/**
* Close this model. It can no longer be used after being closed
*/
close(): void {
// no-op
}
/**
* Don't allow any rows to be movable in any IrisGrids by default. Just columns.
*/
isRowMovable(): boolean {
return false;
}
abstract seekRow(
startRow: number,
column: DhType.Column,
valueType: DhType.ValueTypeType,
value: unknown,
insensitive?: boolean,
contains?: boolean,
isBackwards?: boolean
): Promise<number>;
get isSeekRowAvailable(): boolean {
return false;
}
abstract get columnHeaderGroups(): readonly ColumnHeaderGroup[];
abstract set columnHeaderGroups(groups: readonly ColumnHeaderGroup[]);
abstract get columnHeaderGroupMap(): ReadonlyMap<string, ColumnHeaderGroup>;
abstract getColumnHeaderParentGroup(
modelIndex: ModelIndex,
depth: number
): ColumnHeaderGroup | undefined;
dataBarOptionsForCell(
column: number,
row: number,
theme: GridThemeType
): DataBarOptions {
throw new Error('Method not implemented.');
}
}
export default IrisGridModel;