@deephaven/jsapi-utils 0.38.1-beta.3 → 0.38.1-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DateUtils.d.ts +4 -4
- package/dist/DateUtils.d.ts.map +1 -1
- package/dist/DateUtils.js +16 -17
- package/dist/DateUtils.js.map +1 -1
- package/dist/SessionUtils.d.ts +1 -1
- package/dist/SessionUtils.d.ts.map +1 -1
- package/dist/SessionUtils.js.map +1 -1
- package/dist/TableUtils.d.ts +59 -57
- package/dist/TableUtils.d.ts.map +1 -1
- package/dist/TableUtils.js +309 -280
- package/dist/TableUtils.js.map +1 -1
- package/package.json +8 -8
package/dist/TableUtils.js
CHANGED
|
@@ -5,7 +5,6 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
5
5
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
6
|
import { Type as FilterType, Operator as FilterOperator } from '@deephaven/filters';
|
|
7
7
|
import Log from '@deephaven/log';
|
|
8
|
-
import dh from '@deephaven/jsapi-shim';
|
|
9
8
|
import { PromiseUtils, TextUtils, TimeoutError } from '@deephaven/utils';
|
|
10
9
|
import DateUtils from "./DateUtils.js";
|
|
11
10
|
var log = Log.module('TableUtils');
|
|
@@ -388,6 +387,207 @@ export class TableUtils {
|
|
|
388
387
|
return TableUtils.getNormalizedType(type1) === TableUtils.getNormalizedType(type2);
|
|
389
388
|
}
|
|
390
389
|
|
|
390
|
+
/**
|
|
391
|
+
* Adds quotes to a value if they're not already added
|
|
392
|
+
* @param value Value to add quotes around
|
|
393
|
+
*/
|
|
394
|
+
static quoteValue(value) {
|
|
395
|
+
if (value.length >= 2 && (value.charAt(0) === '"' && value.charAt(value.length - 1) === '"' || value.charAt(0) === "'" && value.charAt(value.length - 1) === "'")) {
|
|
396
|
+
return value;
|
|
397
|
+
}
|
|
398
|
+
return "\"".concat(value, "\"");
|
|
399
|
+
}
|
|
400
|
+
static isRangeOperation(operation) {
|
|
401
|
+
switch (operation) {
|
|
402
|
+
case '<':
|
|
403
|
+
case '<=':
|
|
404
|
+
case '=<':
|
|
405
|
+
case '>':
|
|
406
|
+
case '>=':
|
|
407
|
+
case '=>':
|
|
408
|
+
return true;
|
|
409
|
+
default:
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* @param filter The column filter to apply the range operation to
|
|
416
|
+
* @param operation The range operation to run
|
|
417
|
+
* @param value The value to use for the operation
|
|
418
|
+
* @returns The condition with the specified operation
|
|
419
|
+
*/
|
|
420
|
+
static makeRangeFilterWithOperation(filter, operation, value) {
|
|
421
|
+
switch (operation) {
|
|
422
|
+
case '=':
|
|
423
|
+
return filter.eq(value);
|
|
424
|
+
case '<':
|
|
425
|
+
return filter.lessThan(value);
|
|
426
|
+
case '<=':
|
|
427
|
+
case '=<':
|
|
428
|
+
return filter.lessThanOrEqualTo(value);
|
|
429
|
+
case '>':
|
|
430
|
+
return filter.greaterThan(value);
|
|
431
|
+
case '>=':
|
|
432
|
+
case '=>':
|
|
433
|
+
return filter.greaterThanOrEqualTo(value);
|
|
434
|
+
case '!=':
|
|
435
|
+
case '!':
|
|
436
|
+
return filter.notEq(value);
|
|
437
|
+
default:
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Wraps a table promise in a cancelable promise that will close the table if the promise is cancelled.
|
|
444
|
+
* Use in a component that loads a table, and call cancel when unmounting.
|
|
445
|
+
* @param table The table promise to wrap
|
|
446
|
+
*/
|
|
447
|
+
static makeCancelableTablePromise(table) {
|
|
448
|
+
return PromiseUtils.makeCancelable(table, resolved => {
|
|
449
|
+
resolved.close();
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Make a cancelable promise for a one-shot table event with a timeout.
|
|
455
|
+
* @param table Table to listen for events on
|
|
456
|
+
* @param eventName Event to listen for
|
|
457
|
+
* @param timeout Event timeout in milliseconds, defaults to 0
|
|
458
|
+
* @param matcher Optional function to determine if the promise can be resolved or stays pending
|
|
459
|
+
* @returns Resolves with the event data
|
|
460
|
+
*/
|
|
461
|
+
static makeCancelableTableEventPromise(table, eventName) {
|
|
462
|
+
var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
463
|
+
var matcher = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
464
|
+
var eventCleanup;
|
|
465
|
+
var timeoutId;
|
|
466
|
+
var isPending = true;
|
|
467
|
+
var wrappedPromise = new Promise((resolve, reject) => {
|
|
468
|
+
timeoutId = setTimeout(() => {
|
|
469
|
+
eventCleanup();
|
|
470
|
+
isPending = false;
|
|
471
|
+
reject(new TimeoutError("Event \"".concat(eventName, "\" timed out.")));
|
|
472
|
+
}, timeout);
|
|
473
|
+
eventCleanup = table.addEventListener(eventName, event => {
|
|
474
|
+
if (matcher != null && !matcher(event)) {
|
|
475
|
+
log.debug2('Event triggered, but matcher returned false.');
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
log.debug2('Event triggered, resolving.');
|
|
479
|
+
eventCleanup();
|
|
480
|
+
clearTimeout(timeoutId);
|
|
481
|
+
isPending = false;
|
|
482
|
+
resolve(event);
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
wrappedPromise.cancel = () => {
|
|
486
|
+
if (isPending) {
|
|
487
|
+
log.debug2('Pending promise cleanup.');
|
|
488
|
+
eventCleanup();
|
|
489
|
+
clearTimeout(timeoutId);
|
|
490
|
+
isPending = false;
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
log.debug2('Ignoring non-pending promise cancel.');
|
|
494
|
+
};
|
|
495
|
+
return wrappedPromise;
|
|
496
|
+
}
|
|
497
|
+
static removeCommas(value) {
|
|
498
|
+
return value.replace(/[\s|,]/g, '');
|
|
499
|
+
}
|
|
500
|
+
static makeBooleanValue(text) {
|
|
501
|
+
var allowEmpty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
502
|
+
if (text === '' && allowEmpty) {
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
switch (text === null || text === void 0 ? void 0 : text.toLowerCase()) {
|
|
506
|
+
case 'null':
|
|
507
|
+
return null;
|
|
508
|
+
case '0':
|
|
509
|
+
case 'f':
|
|
510
|
+
case 'fa':
|
|
511
|
+
case 'fal':
|
|
512
|
+
case 'fals':
|
|
513
|
+
case 'false':
|
|
514
|
+
case 'n':
|
|
515
|
+
case 'no':
|
|
516
|
+
return false;
|
|
517
|
+
case '1':
|
|
518
|
+
case 't':
|
|
519
|
+
case 'tr':
|
|
520
|
+
case 'tru':
|
|
521
|
+
case 'true':
|
|
522
|
+
case 'y':
|
|
523
|
+
case 'ye':
|
|
524
|
+
case 'yes':
|
|
525
|
+
return true;
|
|
526
|
+
default:
|
|
527
|
+
throw new Error("Invalid boolean '".concat(text, "'"));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
static makeNumberValue(text) {
|
|
531
|
+
if (text === 'null' || text === '') {
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
var cleanText = text.toLowerCase().trim();
|
|
535
|
+
if (cleanText === '∞' || cleanText === 'infinity' || cleanText === 'inf') {
|
|
536
|
+
return Number.POSITIVE_INFINITY;
|
|
537
|
+
}
|
|
538
|
+
if (cleanText === '-∞' || cleanText === '-infinity' || cleanText === '-inf') {
|
|
539
|
+
return Number.NEGATIVE_INFINITY;
|
|
540
|
+
}
|
|
541
|
+
var numberText = TableUtils.removeCommas(cleanText);
|
|
542
|
+
if (TableUtils.NUMBER_REGEX.test(numberText)) {
|
|
543
|
+
return parseFloat(numberText);
|
|
544
|
+
}
|
|
545
|
+
throw new Error("Invalid number '".concat(text, "'"));
|
|
546
|
+
}
|
|
547
|
+
static getFilterOperatorString(operation) {
|
|
548
|
+
switch (operation) {
|
|
549
|
+
case FilterType.eq:
|
|
550
|
+
return '=';
|
|
551
|
+
case FilterType.notEq:
|
|
552
|
+
return '!=';
|
|
553
|
+
case FilterType.greaterThan:
|
|
554
|
+
return '>';
|
|
555
|
+
case FilterType.greaterThanOrEqualTo:
|
|
556
|
+
return '>=';
|
|
557
|
+
case FilterType.lessThan:
|
|
558
|
+
return '<';
|
|
559
|
+
case FilterType.lessThanOrEqualTo:
|
|
560
|
+
return '<=';
|
|
561
|
+
case FilterType.contains:
|
|
562
|
+
return '~';
|
|
563
|
+
case FilterType.notContains:
|
|
564
|
+
return '!~';
|
|
565
|
+
default:
|
|
566
|
+
throw new Error("Unexpected filter type ".concat(operation));
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
static isTreeTable(table) {
|
|
570
|
+
return table != null && table.expand !== undefined && table.collapse !== undefined;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Copies the provided array, sorts by column name case insensitive, and returns the sorted array.
|
|
575
|
+
* @param columns The columns to sort
|
|
576
|
+
* @param isAscending Whether to sort ascending
|
|
577
|
+
*/
|
|
578
|
+
static sortColumns(columns) {
|
|
579
|
+
var isAscending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
580
|
+
return [...columns].sort((a, b) => {
|
|
581
|
+
var aName = a.name.toUpperCase();
|
|
582
|
+
var bName = b.name.toUpperCase();
|
|
583
|
+
return TextUtils.sort(aName, bName, isAscending);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
constructor(dh) {
|
|
587
|
+
_defineProperty(this, "dh", void 0);
|
|
588
|
+
this.dh = dh;
|
|
589
|
+
}
|
|
590
|
+
|
|
391
591
|
/**
|
|
392
592
|
* Create filter with the provided column and text. Handles multiple filters joined with && or ||
|
|
393
593
|
* @param column The column to set the filter on
|
|
@@ -395,7 +595,7 @@ export class TableUtils {
|
|
|
395
595
|
* @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York
|
|
396
596
|
* @returns Returns the created filter, null if text could not be parsed
|
|
397
597
|
*/
|
|
398
|
-
|
|
598
|
+
makeQuickFilter(column, text, timeZone) {
|
|
399
599
|
var orComponents = text.split('||');
|
|
400
600
|
var orFilter = null;
|
|
401
601
|
for (var i = 0; i < orComponents.length; i += 1) {
|
|
@@ -405,7 +605,7 @@ export class TableUtils {
|
|
|
405
605
|
for (var j = 0; j < andComponents.length; j += 1) {
|
|
406
606
|
var andComponent = andComponents[j].trim();
|
|
407
607
|
if (andComponent.length > 0) {
|
|
408
|
-
var filter =
|
|
608
|
+
var filter = this.makeQuickFilterFromComponent(column, andComponent, timeZone);
|
|
409
609
|
if (filter) {
|
|
410
610
|
if (andFilter) {
|
|
411
611
|
andFilter = andFilter.and(filter);
|
|
@@ -433,7 +633,7 @@ export class TableUtils {
|
|
|
433
633
|
* @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York
|
|
434
634
|
* @returns Returns the created filter, null if text could not be parsed
|
|
435
635
|
*/
|
|
436
|
-
|
|
636
|
+
makeQuickFilterFromComponent(column, text, timeZone) {
|
|
437
637
|
var {
|
|
438
638
|
type
|
|
439
639
|
} = column;
|
|
@@ -451,8 +651,11 @@ export class TableUtils {
|
|
|
451
651
|
}
|
|
452
652
|
return this.makeQuickTextFilter(column, text);
|
|
453
653
|
}
|
|
454
|
-
|
|
654
|
+
makeQuickNumberFilter(column, text) {
|
|
455
655
|
var columnFilter = column.filter();
|
|
656
|
+
var {
|
|
657
|
+
dh
|
|
658
|
+
} = this;
|
|
456
659
|
var filter = null;
|
|
457
660
|
var regex = /\s*(>=|<=|=>|=<|>|<|!=|=|!)?(\s*-\s*)?(\s*\d*(?:,\d{3})*(?:\.\d*)?\s*)?(null|nan|infinity|inf|\u221E)?(.*)/i;
|
|
458
661
|
var result = regex.exec(text);
|
|
@@ -522,7 +725,10 @@ export class TableUtils {
|
|
|
522
725
|
filter = column.filter();
|
|
523
726
|
return TableUtils.makeRangeFilterWithOperation(filter, operation, value);
|
|
524
727
|
}
|
|
525
|
-
|
|
728
|
+
makeQuickTextFilter(column, text) {
|
|
729
|
+
var {
|
|
730
|
+
dh
|
|
731
|
+
} = this;
|
|
526
732
|
var cleanText = "".concat(text).trim();
|
|
527
733
|
var regex = /^(!~|!=|~|=|!)?(.*)/;
|
|
528
734
|
var result = regex.exec(cleanText);
|
|
@@ -596,7 +802,9 @@ export class TableUtils {
|
|
|
596
802
|
}
|
|
597
803
|
return null;
|
|
598
804
|
}
|
|
599
|
-
|
|
805
|
+
|
|
806
|
+
// eslint-disable-next-line class-methods-use-this
|
|
807
|
+
makeQuickBooleanFilter(column, text) {
|
|
600
808
|
var regex = /^(!=|=|!)?(.*)/;
|
|
601
809
|
var result = regex.exec("".concat(text).trim());
|
|
602
810
|
if (result === null) {
|
|
@@ -627,7 +835,7 @@ export class TableUtils {
|
|
|
627
835
|
* @param text The date string text to parse.
|
|
628
836
|
* @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York
|
|
629
837
|
*/
|
|
630
|
-
|
|
838
|
+
makeQuickDateFilter(column, text, timeZone) {
|
|
631
839
|
var cleanText = text.trim();
|
|
632
840
|
var regex = /\s*(>=|<=|=>|=<|>|<|!=|!|=)?(.*)/;
|
|
633
841
|
var result = regex.exec(cleanText);
|
|
@@ -663,7 +871,7 @@ export class TableUtils {
|
|
|
663
871
|
filterOperation = FilterType.eq;
|
|
664
872
|
break;
|
|
665
873
|
}
|
|
666
|
-
return
|
|
874
|
+
return this.makeQuickDateFilterWithOperation(column, dateText, filterOperation, timeZone);
|
|
667
875
|
}
|
|
668
876
|
|
|
669
877
|
/**
|
|
@@ -673,8 +881,11 @@ export class TableUtils {
|
|
|
673
881
|
* @param operation The filter operation to use.
|
|
674
882
|
* @param timeZone The time zone to make this filter with. E.g. America/New_York
|
|
675
883
|
*/
|
|
676
|
-
|
|
677
|
-
var
|
|
884
|
+
makeQuickDateFilterWithOperation(column, text, operation, timeZone) {
|
|
885
|
+
var {
|
|
886
|
+
dh
|
|
887
|
+
} = this;
|
|
888
|
+
var [startDate, endDate] = DateUtils.parseDateRange(dh, text, timeZone);
|
|
678
889
|
var startValue = startDate != null ? dh.FilterValue.ofNumber(startDate) : null;
|
|
679
890
|
var endValue = endDate != null ? dh.FilterValue.ofNumber(endDate) : null;
|
|
680
891
|
var filter = column.filter();
|
|
@@ -724,31 +935,10 @@ export class TableUtils {
|
|
|
724
935
|
throw new Error("Invalid operator: ".concat(operation));
|
|
725
936
|
}
|
|
726
937
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
*/
|
|
732
|
-
static quoteValue(value) {
|
|
733
|
-
if (value.length >= 2 && (value.charAt(0) === '"' && value.charAt(value.length - 1) === '"' || value.charAt(0) === "'" && value.charAt(value.length - 1) === "'")) {
|
|
734
|
-
return value;
|
|
735
|
-
}
|
|
736
|
-
return "\"".concat(value, "\"");
|
|
737
|
-
}
|
|
738
|
-
static isRangeOperation(operation) {
|
|
739
|
-
switch (operation) {
|
|
740
|
-
case '<':
|
|
741
|
-
case '<=':
|
|
742
|
-
case '=<':
|
|
743
|
-
case '>':
|
|
744
|
-
case '>=':
|
|
745
|
-
case '=>':
|
|
746
|
-
return true;
|
|
747
|
-
default:
|
|
748
|
-
return false;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
static makeQuickCharFilter(column, text) {
|
|
938
|
+
makeQuickCharFilter(column, text) {
|
|
939
|
+
var {
|
|
940
|
+
dh
|
|
941
|
+
} = this;
|
|
752
942
|
var cleanText = "".concat(text).trim();
|
|
753
943
|
var regex = /^(>=|<=|=>|=<|>|<|!=|=|!)?(null|"."|'.'|.)?(.*)/;
|
|
754
944
|
var result = regex.exec(cleanText);
|
|
@@ -786,91 +976,7 @@ export class TableUtils {
|
|
|
786
976
|
var filterValue = dh.FilterValue.ofString(TableUtils.isRangeOperation(operation) ? TableUtils.quoteValue(value) : value);
|
|
787
977
|
return TableUtils.makeRangeFilterWithOperation(filter, operation, filterValue);
|
|
788
978
|
}
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* @param filter The column filter to apply the range operation to
|
|
792
|
-
* @param operation The range operation to run
|
|
793
|
-
* @param value The value to use for the operation
|
|
794
|
-
* @returns The condition with the specified operation
|
|
795
|
-
*/
|
|
796
|
-
static makeRangeFilterWithOperation(filter, operation, value) {
|
|
797
|
-
switch (operation) {
|
|
798
|
-
case '=':
|
|
799
|
-
return filter.eq(value);
|
|
800
|
-
case '<':
|
|
801
|
-
return filter.lessThan(value);
|
|
802
|
-
case '<=':
|
|
803
|
-
case '=<':
|
|
804
|
-
return filter.lessThanOrEqualTo(value);
|
|
805
|
-
case '>':
|
|
806
|
-
return filter.greaterThan(value);
|
|
807
|
-
case '>=':
|
|
808
|
-
case '=>':
|
|
809
|
-
return filter.greaterThanOrEqualTo(value);
|
|
810
|
-
case '!=':
|
|
811
|
-
case '!':
|
|
812
|
-
return filter.notEq(value);
|
|
813
|
-
default:
|
|
814
|
-
return null;
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
/**
|
|
819
|
-
* Wraps a table promise in a cancelable promise that will close the table if the promise is cancelled.
|
|
820
|
-
* Use in a component that loads a table, and call cancel when unmounting.
|
|
821
|
-
* @param table The table promise to wrap
|
|
822
|
-
*/
|
|
823
|
-
static makeCancelableTablePromise(table) {
|
|
824
|
-
return PromiseUtils.makeCancelable(table, resolved => {
|
|
825
|
-
resolved.close();
|
|
826
|
-
});
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
/**
|
|
830
|
-
* Make a cancelable promise for a one-shot table event with a timeout.
|
|
831
|
-
* @param table Table to listen for events on
|
|
832
|
-
* @param eventName Event to listen for
|
|
833
|
-
* @param timeout Event timeout in milliseconds, defaults to 0
|
|
834
|
-
* @param matcher Optional function to determine if the promise can be resolved or stays pending
|
|
835
|
-
* @returns Resolves with the event data
|
|
836
|
-
*/
|
|
837
|
-
static makeCancelableTableEventPromise(table, eventName) {
|
|
838
|
-
var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
839
|
-
var matcher = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
840
|
-
var eventCleanup;
|
|
841
|
-
var timeoutId;
|
|
842
|
-
var isPending = true;
|
|
843
|
-
var wrappedPromise = new Promise((resolve, reject) => {
|
|
844
|
-
timeoutId = setTimeout(() => {
|
|
845
|
-
eventCleanup();
|
|
846
|
-
isPending = false;
|
|
847
|
-
reject(new TimeoutError("Event \"".concat(eventName, "\" timed out.")));
|
|
848
|
-
}, timeout);
|
|
849
|
-
eventCleanup = table.addEventListener(eventName, event => {
|
|
850
|
-
if (matcher != null && !matcher(event)) {
|
|
851
|
-
log.debug2('Event triggered, but matcher returned false.');
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
log.debug2('Event triggered, resolving.');
|
|
855
|
-
eventCleanup();
|
|
856
|
-
clearTimeout(timeoutId);
|
|
857
|
-
isPending = false;
|
|
858
|
-
resolve(event);
|
|
859
|
-
});
|
|
860
|
-
});
|
|
861
|
-
wrappedPromise.cancel = () => {
|
|
862
|
-
if (isPending) {
|
|
863
|
-
log.debug2('Pending promise cleanup.');
|
|
864
|
-
eventCleanup();
|
|
865
|
-
clearTimeout(timeoutId);
|
|
866
|
-
isPending = false;
|
|
867
|
-
return;
|
|
868
|
-
}
|
|
869
|
-
log.debug2('Ignoring non-pending promise cancel.');
|
|
870
|
-
};
|
|
871
|
-
return wrappedPromise;
|
|
872
|
-
}
|
|
873
|
-
static makeAdvancedFilter(column, options, timeZone) {
|
|
979
|
+
makeAdvancedFilter(column, options, timeZone) {
|
|
874
980
|
var {
|
|
875
981
|
filterItems,
|
|
876
982
|
filterOperators,
|
|
@@ -886,7 +992,7 @@ export class TableUtils {
|
|
|
886
992
|
} = filterItem;
|
|
887
993
|
if (selectedType != null && selectedType.length > 0 && value != null && value.length > 0) {
|
|
888
994
|
try {
|
|
889
|
-
var newFilter =
|
|
995
|
+
var newFilter = this.makeAdvancedValueFilter(column, selectedType, value, timeZone);
|
|
890
996
|
if (newFilter != null) {
|
|
891
997
|
if (i === 0) {
|
|
892
998
|
filter = newFilter;
|
|
@@ -912,7 +1018,7 @@ export class TableUtils {
|
|
|
912
1018
|
}
|
|
913
1019
|
}
|
|
914
1020
|
}
|
|
915
|
-
var selectValueFilter =
|
|
1021
|
+
var selectValueFilter = this.makeSelectValueFilter(column, selectedValues, invertSelection);
|
|
916
1022
|
if (selectValueFilter != null) {
|
|
917
1023
|
if (filter != null) {
|
|
918
1024
|
filter = filter.and(selectValueFilter);
|
|
@@ -922,149 +1028,14 @@ export class TableUtils {
|
|
|
922
1028
|
}
|
|
923
1029
|
return filter;
|
|
924
1030
|
}
|
|
925
|
-
|
|
926
|
-
return value.replace(/[\s|,]/g, '');
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
/**
|
|
930
|
-
* @param columnType The column type to make the filter value from.
|
|
931
|
-
* @param value The value to make the filter value from.
|
|
932
|
-
* @returns The FilterValue item for this column/value combination
|
|
933
|
-
*/
|
|
934
|
-
static makeFilterValue(columnType, value) {
|
|
935
|
-
var type = TableUtils.getBaseType(columnType);
|
|
936
|
-
if (TableUtils.isTextType(type)) {
|
|
937
|
-
return dh.FilterValue.ofString(value);
|
|
938
|
-
}
|
|
939
|
-
if (TableUtils.isLongType(type)) {
|
|
940
|
-
return dh.FilterValue.ofNumber(dh.LongWrapper.ofString(TableUtils.removeCommas(value)));
|
|
941
|
-
}
|
|
942
|
-
return dh.FilterValue.ofNumber(TableUtils.removeCommas(value));
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
/**
|
|
946
|
-
* Takes a value and converts it to an `dh.FilterValue`
|
|
947
|
-
*
|
|
948
|
-
* @param columnType The column type to make the filter value from.
|
|
949
|
-
* @param value The value to actually set
|
|
950
|
-
* @returns The FilterValue item for this column/value combination
|
|
951
|
-
*/
|
|
952
|
-
static makeFilterRawValue(columnType, rawValue) {
|
|
953
|
-
if (TableUtils.isTextType(columnType)) {
|
|
954
|
-
return dh.FilterValue.ofString(rawValue);
|
|
955
|
-
}
|
|
956
|
-
if (TableUtils.isBooleanType(columnType)) {
|
|
957
|
-
return dh.FilterValue.ofBoolean(rawValue);
|
|
958
|
-
}
|
|
959
|
-
return dh.FilterValue.ofNumber(rawValue);
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
/**
|
|
963
|
-
* Converts a string value to a value appropriate for the column
|
|
964
|
-
* @param columnType The column type to make the value for
|
|
965
|
-
* @param text The string value to make a type for
|
|
966
|
-
* @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York
|
|
967
|
-
*/
|
|
968
|
-
static makeValue(columnType, text, timeZone) {
|
|
969
|
-
if (text === 'null') {
|
|
970
|
-
return null;
|
|
971
|
-
}
|
|
972
|
-
if (TableUtils.isTextType(columnType)) {
|
|
973
|
-
return text;
|
|
974
|
-
}
|
|
975
|
-
if (TableUtils.isLongType(columnType)) {
|
|
976
|
-
return dh.LongWrapper.ofString(TableUtils.removeCommas(text));
|
|
977
|
-
}
|
|
978
|
-
if (TableUtils.isBooleanType(columnType)) {
|
|
979
|
-
return TableUtils.makeBooleanValue(text, true);
|
|
980
|
-
}
|
|
981
|
-
if (TableUtils.isDateType(columnType)) {
|
|
982
|
-
var [date] = DateUtils.parseDateRange(text, timeZone);
|
|
983
|
-
return date;
|
|
984
|
-
}
|
|
985
|
-
if (TableUtils.isNumberType(columnType)) {
|
|
986
|
-
return TableUtils.makeNumberValue(text);
|
|
987
|
-
}
|
|
988
|
-
log.error('Unexpected column type', columnType);
|
|
989
|
-
return null;
|
|
990
|
-
}
|
|
991
|
-
static makeBooleanValue(text) {
|
|
992
|
-
var allowEmpty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
993
|
-
if (text === '' && allowEmpty) {
|
|
994
|
-
return null;
|
|
995
|
-
}
|
|
996
|
-
switch (text === null || text === void 0 ? void 0 : text.toLowerCase()) {
|
|
997
|
-
case 'null':
|
|
998
|
-
return null;
|
|
999
|
-
case '0':
|
|
1000
|
-
case 'f':
|
|
1001
|
-
case 'fa':
|
|
1002
|
-
case 'fal':
|
|
1003
|
-
case 'fals':
|
|
1004
|
-
case 'false':
|
|
1005
|
-
case 'n':
|
|
1006
|
-
case 'no':
|
|
1007
|
-
return false;
|
|
1008
|
-
case '1':
|
|
1009
|
-
case 't':
|
|
1010
|
-
case 'tr':
|
|
1011
|
-
case 'tru':
|
|
1012
|
-
case 'true':
|
|
1013
|
-
case 'y':
|
|
1014
|
-
case 'ye':
|
|
1015
|
-
case 'yes':
|
|
1016
|
-
return true;
|
|
1017
|
-
default:
|
|
1018
|
-
throw new Error("Invalid boolean '".concat(text, "'"));
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
static makeNumberValue(text) {
|
|
1022
|
-
if (text === 'null' || text === '') {
|
|
1023
|
-
return null;
|
|
1024
|
-
}
|
|
1025
|
-
var cleanText = text.toLowerCase().trim();
|
|
1026
|
-
if (cleanText === '∞' || cleanText === 'infinity' || cleanText === 'inf') {
|
|
1027
|
-
return Number.POSITIVE_INFINITY;
|
|
1028
|
-
}
|
|
1029
|
-
if (cleanText === '-∞' || cleanText === '-infinity' || cleanText === '-inf') {
|
|
1030
|
-
return Number.NEGATIVE_INFINITY;
|
|
1031
|
-
}
|
|
1032
|
-
var numberText = TableUtils.removeCommas(cleanText);
|
|
1033
|
-
if (TableUtils.NUMBER_REGEX.test(numberText)) {
|
|
1034
|
-
return parseFloat(numberText);
|
|
1035
|
-
}
|
|
1036
|
-
throw new Error("Invalid number '".concat(text, "'"));
|
|
1037
|
-
}
|
|
1038
|
-
static getFilterOperatorString(operation) {
|
|
1039
|
-
switch (operation) {
|
|
1040
|
-
case FilterType.eq:
|
|
1041
|
-
return '=';
|
|
1042
|
-
case FilterType.notEq:
|
|
1043
|
-
return '!=';
|
|
1044
|
-
case FilterType.greaterThan:
|
|
1045
|
-
return '>';
|
|
1046
|
-
case FilterType.greaterThanOrEqualTo:
|
|
1047
|
-
return '>=';
|
|
1048
|
-
case FilterType.lessThan:
|
|
1049
|
-
return '<';
|
|
1050
|
-
case FilterType.lessThanOrEqualTo:
|
|
1051
|
-
return '<=';
|
|
1052
|
-
case FilterType.contains:
|
|
1053
|
-
return '~';
|
|
1054
|
-
case FilterType.notContains:
|
|
1055
|
-
return '!~';
|
|
1056
|
-
default:
|
|
1057
|
-
throw new Error("Unexpected filter type ".concat(operation));
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
static makeAdvancedValueFilter(column, operation, value, timeZone) {
|
|
1031
|
+
makeAdvancedValueFilter(column, operation, value, timeZone) {
|
|
1061
1032
|
if (TableUtils.isDateType(column.type)) {
|
|
1062
|
-
return
|
|
1033
|
+
return this.makeQuickDateFilterWithOperation(column, value, operation, timeZone);
|
|
1063
1034
|
}
|
|
1064
1035
|
if (TableUtils.isNumberType(column.type) || TableUtils.isCharType(column.type)) {
|
|
1065
|
-
return
|
|
1036
|
+
return this.makeQuickFilter(column, "".concat(TableUtils.getFilterOperatorString(operation)).concat(value));
|
|
1066
1037
|
}
|
|
1067
|
-
var filterValue =
|
|
1038
|
+
var filterValue = this.makeFilterValue(column.type, value);
|
|
1068
1039
|
var filter = column.filter();
|
|
1069
1040
|
switch (operation) {
|
|
1070
1041
|
case FilterType.eq:
|
|
@@ -1128,6 +1099,78 @@ export class TableUtils {
|
|
|
1128
1099
|
return eqFilter.and(notEqFilter);
|
|
1129
1100
|
}
|
|
1130
1101
|
|
|
1102
|
+
/**
|
|
1103
|
+
* @param columnType The column type to make the filter value from.
|
|
1104
|
+
* @param value The value to make the filter value from.
|
|
1105
|
+
* @returns The FilterValue item for this column/value combination
|
|
1106
|
+
*/
|
|
1107
|
+
makeFilterValue(columnType, value) {
|
|
1108
|
+
var {
|
|
1109
|
+
dh
|
|
1110
|
+
} = this;
|
|
1111
|
+
var type = TableUtils.getBaseType(columnType);
|
|
1112
|
+
if (TableUtils.isTextType(type)) {
|
|
1113
|
+
return dh.FilterValue.ofString(value);
|
|
1114
|
+
}
|
|
1115
|
+
if (TableUtils.isLongType(type)) {
|
|
1116
|
+
return dh.FilterValue.ofNumber(dh.LongWrapper.ofString(TableUtils.removeCommas(value)));
|
|
1117
|
+
}
|
|
1118
|
+
return dh.FilterValue.ofNumber(TableUtils.removeCommas(value));
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Takes a value and converts it to an `dh.FilterValue`
|
|
1123
|
+
*
|
|
1124
|
+
* @param columnType The column type to make the filter value from.
|
|
1125
|
+
* @param value The value to actually set
|
|
1126
|
+
* @returns The FilterValue item for this column/value combination
|
|
1127
|
+
*/
|
|
1128
|
+
makeFilterRawValue(columnType, rawValue) {
|
|
1129
|
+
var {
|
|
1130
|
+
dh
|
|
1131
|
+
} = this;
|
|
1132
|
+
if (TableUtils.isTextType(columnType)) {
|
|
1133
|
+
return dh.FilterValue.ofString(rawValue);
|
|
1134
|
+
}
|
|
1135
|
+
if (TableUtils.isBooleanType(columnType)) {
|
|
1136
|
+
return dh.FilterValue.ofBoolean(rawValue);
|
|
1137
|
+
}
|
|
1138
|
+
return dh.FilterValue.ofNumber(rawValue);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* Converts a string value to a value appropriate for the column
|
|
1143
|
+
* @param columnType The column type to make the value for
|
|
1144
|
+
* @param text The string value to make a type for
|
|
1145
|
+
* @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York
|
|
1146
|
+
*/
|
|
1147
|
+
makeValue(columnType, text, timeZone) {
|
|
1148
|
+
var {
|
|
1149
|
+
dh
|
|
1150
|
+
} = this;
|
|
1151
|
+
if (text === 'null') {
|
|
1152
|
+
return null;
|
|
1153
|
+
}
|
|
1154
|
+
if (TableUtils.isTextType(columnType)) {
|
|
1155
|
+
return text;
|
|
1156
|
+
}
|
|
1157
|
+
if (TableUtils.isLongType(columnType)) {
|
|
1158
|
+
return dh.LongWrapper.ofString(TableUtils.removeCommas(text));
|
|
1159
|
+
}
|
|
1160
|
+
if (TableUtils.isBooleanType(columnType)) {
|
|
1161
|
+
return TableUtils.makeBooleanValue(text, true);
|
|
1162
|
+
}
|
|
1163
|
+
if (TableUtils.isDateType(columnType)) {
|
|
1164
|
+
var [date] = DateUtils.parseDateRange(dh, text, timeZone);
|
|
1165
|
+
return date;
|
|
1166
|
+
}
|
|
1167
|
+
if (TableUtils.isNumberType(columnType)) {
|
|
1168
|
+
return TableUtils.makeNumberValue(text);
|
|
1169
|
+
}
|
|
1170
|
+
log.error('Unexpected column type', columnType);
|
|
1171
|
+
return null;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1131
1174
|
/**
|
|
1132
1175
|
* Create a filter using the selected items
|
|
1133
1176
|
* Has a flag for invertSelection as we start from a "Select All" state and a user just deselects items.
|
|
@@ -1137,7 +1180,10 @@ export class TableUtils {
|
|
|
1137
1180
|
* @param invertSelection Invert the selection (eg. All items are selected, then you deselect items)
|
|
1138
1181
|
* @returns Returns a `in` or `notIn` FilterCondition as necessary, or null if no filtering should be applied (everything selected)
|
|
1139
1182
|
*/
|
|
1140
|
-
|
|
1183
|
+
makeSelectValueFilter(column, selectedValues, invertSelection) {
|
|
1184
|
+
var {
|
|
1185
|
+
dh
|
|
1186
|
+
} = this;
|
|
1141
1187
|
if (selectedValues.length === 0) {
|
|
1142
1188
|
if (invertSelection) {
|
|
1143
1189
|
// No filter means select everything
|
|
@@ -1180,23 +1226,6 @@ export class TableUtils {
|
|
|
1180
1226
|
}
|
|
1181
1227
|
return column.filter().in(values);
|
|
1182
1228
|
}
|
|
1183
|
-
static isTreeTable(table) {
|
|
1184
|
-
return table != null && table.expand !== undefined && table.collapse !== undefined;
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
/**
|
|
1188
|
-
* Copies the provided array, sorts by column name case insensitive, and returns the sorted array.
|
|
1189
|
-
* @param columns The columns to sort
|
|
1190
|
-
* @param isAscending Whether to sort ascending
|
|
1191
|
-
*/
|
|
1192
|
-
static sortColumns(columns) {
|
|
1193
|
-
var isAscending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1194
|
-
return [...columns].sort((a, b) => {
|
|
1195
|
-
var aName = a.name.toUpperCase();
|
|
1196
|
-
var bName = b.name.toUpperCase();
|
|
1197
|
-
return TextUtils.sort(aName, bName, isAscending);
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
1229
|
}
|
|
1201
1230
|
_defineProperty(TableUtils, "dataType", {
|
|
1202
1231
|
BOOLEAN: 'boolean',
|