@zeedhi/teknisa-components-common 1.130.0 → 1.132.0

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.
Files changed (32) hide show
  1. package/coverage/clover.xml +1224 -1109
  2. package/coverage/coverage-final.json +48 -46
  3. package/coverage/lcov-report/index.html +22 -22
  4. package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +3 -3
  5. package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +1 -1
  6. package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +11 -11
  7. package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
  8. package/coverage/lcov-report/tests/__helpers__/index.ts.html +4 -4
  9. package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +3 -3
  10. package/coverage/lcov.info +2230 -1993
  11. package/dist/tek-components-common.esm.js +393 -195
  12. package/dist/tek-components-common.umd.js +393 -194
  13. package/package.json +2 -2
  14. package/tests/unit/components/tek-grid/grid-columns-button.spec.ts +123 -2
  15. package/tests/unit/components/tek-grid/grid-export-button.spec.ts +403 -0
  16. package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +147 -4
  17. package/tests/unit/components/tek-grid/grid.spec.ts +182 -9
  18. package/tests/unit/components/tek-grid/layout_options.spec.ts +680 -25
  19. package/tests/unit/utils/object-comparison.spec.ts +89 -0
  20. package/types/components/index.d.ts +1 -0
  21. package/types/components/tek-grid/grid-columns-button.d.ts +2 -1
  22. package/types/components/tek-grid/grid-export-button.d.ts +19 -0
  23. package/types/components/tek-grid/grid-filter-button.d.ts +1 -0
  24. package/types/components/tek-grid/grid.d.ts +4 -0
  25. package/types/components/tek-grid/interfaces.d.ts +8 -0
  26. package/types/components/tek-grid/layout-options.d.ts +15 -0
  27. package/types/components/tek-tree-grid/tree-grid.d.ts +2 -0
  28. package/types/utils/grid-base/export-options/button-option.d.ts +3 -1
  29. package/types/utils/grid-base/export-options/multi-option.d.ts +3 -1
  30. package/types/utils/grid-base/grid-base.d.ts +1 -3
  31. package/types/utils/index.d.ts +1 -0
  32. package/types/utils/object-comparison.d.ts +3 -0
@@ -639,6 +639,18 @@
639
639
  PERFORMANCE OF THIS SOFTWARE.
640
640
  ***************************************************************************** */
641
641
 
642
+ function __rest(s, e) {
643
+ var t = {};
644
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
645
+ t[p] = s[p];
646
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
647
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
648
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
649
+ t[p[i]] = s[p[i]];
650
+ }
651
+ return t;
652
+ }
653
+
642
654
  function __decorate(decorators, target, key, desc) {
643
655
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
644
656
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -715,98 +727,8 @@
715
727
  }
716
728
  }
717
729
 
718
- class ButtonOption {
719
- constructor(config) {
720
- this.config = config;
721
- }
722
- buildComponent(grid) {
723
- const { type, label, portrait = true, iconName, } = this.config;
724
- const orientation = portrait ? 'portrait' : 'landscape';
725
- return {
726
- label,
727
- iconName,
728
- name: `${grid.name}_export_${type}_${orientation}`,
729
- component: 'ZdButton',
730
- flat: true,
731
- events: {
732
- click: () => grid.getReport(type, portrait),
733
- },
734
- };
735
- }
736
- }
737
-
738
- class MultiOption {
739
- constructor(config) {
740
- this.config = config;
741
- }
742
- formatName(id, type, grid) {
743
- return `${grid.name}_export_${type}_${id}`;
744
- }
745
- buildTooltip(option, type, grid) {
746
- const { label } = option;
747
- return {
748
- name: this.formatName(`tooltip_${label}`, type, grid),
749
- component: 'ZdTooltip',
750
- bottom: true,
751
- label,
752
- children: [],
753
- };
754
- }
755
- buildButton(option, type, grid) {
756
- const { cssClass, label, iconName, reportParams, } = option;
757
- const { portrait: optionPortrait, rowObj } = reportParams || {};
758
- return {
759
- name: this.formatName(`button_${label}`, type, grid),
760
- component: 'ZdButton',
761
- cssClass,
762
- icon: true,
763
- iconName,
764
- events: {
765
- click: () => grid.getReport(type, optionPortrait, rowObj),
766
- },
767
- };
768
- }
769
- buildDivider(option, type, grid) {
770
- const { label } = option;
771
- return {
772
- name: this.formatName(`divider_${label}`, type, grid),
773
- component: 'ZdDivider',
774
- cssClass: 'zd-my-1',
775
- vertical: true,
776
- };
777
- }
778
- buildComponent(grid) {
779
- const { type, label, multiOption, } = this.config;
780
- const optionComponents = multiOption.map((option) => ([
781
- Object.assign(Object.assign({}, this.buildTooltip(option, type, grid)), { children: [
782
- this.buildButton(option, type, grid),
783
- ] }),
784
- this.buildDivider(option, type, grid),
785
- ]))
786
- .flat();
787
- optionComponents.pop();
788
- const text = {
789
- name: this.formatName('text', type, grid),
790
- component: 'ZdText',
791
- cssClass: 'zd-display-flex zd-align-center zd-flex-grow-1 tek-grid-export-multioption-text',
792
- events: {
793
- click: ({ event }) => event === null || event === void 0 ? void 0 : event.stopPropagation(),
794
- },
795
- text: label || '',
796
- };
797
- const result = {
798
- name: this.formatName('row', type, grid),
799
- component: 'ZdRow',
800
- cssClass: 'zd-display-flex zd-ma-0 zd-py-0 zd-gap-x-1 tek-grid-export-multioption-row',
801
- children: [text, ...optionComponents],
802
- };
803
- return result;
804
- }
805
- }
806
-
807
730
  class GridBase {
808
731
  constructor(grid) {
809
- this.exportConfigButtons = [];
810
732
  this.defaultToolbar = {};
811
733
  this.atoms = {
812
734
  TITLE: '_gridTitle',
@@ -828,20 +750,8 @@
828
750
  ACTIONS_DROPDOWN: '_actions_dropdown',
829
751
  };
830
752
  this.grid = grid;
831
- this.exportConfigButtons = this.getExportConfigButtons();
832
753
  this.initializeDefaultToolbarItems();
833
754
  }
834
- getOption(config) {
835
- if (config.multiOption)
836
- return new MultiOption(config);
837
- return new ButtonOption(config);
838
- }
839
- getExportConfigButtons() {
840
- return this.grid.exportConfig.map((config) => {
841
- const option = this.getOption(config);
842
- return option.buildComponent(this.grid);
843
- });
844
- }
845
755
  initializeDefaultToolbarItems() {
846
756
  this.defaultToolbar = {
847
757
  title: () => ({
@@ -949,7 +859,7 @@
949
859
  name: `${this.grid.name}_columnsButton`,
950
860
  component: 'TekGridColumnsButton',
951
861
  isVisible: `{{GridController_${this.grid.componentId}.showColumnsButton}}`,
952
- iterableComponentName: this.grid.name,
862
+ gridName: this.grid.name,
953
863
  hideGroups: !(this.grid instanceof TekGrid),
954
864
  ignoreColumns: `{{GridController_${this.grid.componentId}.columnsButtonIgnore}}`,
955
865
  },
@@ -958,21 +868,15 @@
958
868
  layoutOptions: () => ({
959
869
  name: `${this.grid.name}_layout_options`,
960
870
  component: 'TekGridLayoutOptions',
871
+ gridName: this.grid.name,
961
872
  isVisible: `{{GridController_${this.grid.componentId}.showLayoutOptionsButton}}`,
962
873
  }),
963
874
  exportDropdown: () => ({
964
875
  name: `${this.grid.name}_export_dropdown`,
965
- component: 'ZdDropdown',
966
- cssClass: 'tekgrid-actions-dropdown',
967
- offsetY: true,
968
- activator: {
969
- name: `${this.grid.name}_exportButton`,
970
- component: 'ZdButton',
971
- icon: true,
972
- iconName: 'fileDownload',
973
- isVisible: `{{GridController_${this.grid.componentId}.showExportButton}}`,
974
- },
975
- children: this.grid.exportActions || this.exportConfigButtons,
876
+ component: 'TekGridExportButton',
877
+ grid: this.grid,
878
+ gridName: this.grid.name,
879
+ isVisible: `{{GridController_${this.grid.componentId}.showExportButton}}`,
976
880
  }),
977
881
  actionsDivider: (index) => ({
978
882
  name: `${this.grid.name}_actions_divider${index}`,
@@ -1141,7 +1045,10 @@
1141
1045
  return toolbarItems;
1142
1046
  }
1143
1047
  loadFilterButton({ component }) {
1144
- this.filterButton = component;
1048
+ this.registerFilterButton(component);
1049
+ }
1050
+ registerFilterButton(filterButton) {
1051
+ this.filterButton = filterButton;
1145
1052
  }
1146
1053
  hideButtonClick({ event }) {
1147
1054
  if (!event.defaultPrevented) {
@@ -1243,7 +1150,14 @@
1243
1150
  return __awaiter(this, void 0, void 0, function* () {
1244
1151
  const { datasource } = this.grid;
1245
1152
  if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
1246
- const lookupColumns = this.grid.columns.filter((column) => !!column.componentProps.datasource && !column.skipLookupSearch);
1153
+ const searchIn = datasource.searchIn || [];
1154
+ const lookupColumns = this.grid.columns.filter((column) => {
1155
+ if (!column.componentProps.datasource || column.skipLookupSearch)
1156
+ return false;
1157
+ if (searchIn.length > 0)
1158
+ return searchIn.indexOf(column.name) !== -1;
1159
+ return true;
1160
+ });
1247
1161
  const searchJoin = {};
1248
1162
  if (search) {
1249
1163
  const promises = lookupColumns.map((column) => __awaiter(this, void 0, void 0, function* () {
@@ -1581,6 +1495,95 @@
1581
1495
  }
1582
1496
  }
1583
1497
 
1498
+ class ButtonOption {
1499
+ constructor(config) {
1500
+ this.config = config;
1501
+ }
1502
+ buildComponent(grid) {
1503
+ const { type, label, portrait = true, iconName, } = this.config;
1504
+ const orientation = portrait ? 'portrait' : 'landscape';
1505
+ return {
1506
+ label,
1507
+ iconName,
1508
+ name: `${grid.name}_export_${type}_${orientation}`,
1509
+ component: 'ZdButton',
1510
+ flat: true,
1511
+ events: {
1512
+ click: () => grid.getReport(type, portrait),
1513
+ },
1514
+ };
1515
+ }
1516
+ }
1517
+
1518
+ class MultiOption {
1519
+ constructor(config) {
1520
+ this.config = config;
1521
+ }
1522
+ formatName(id, type, grid) {
1523
+ return `${grid.name}_export_${type}_${id}`;
1524
+ }
1525
+ buildTooltip(option, type, grid) {
1526
+ const { label } = option;
1527
+ return {
1528
+ name: this.formatName(`tooltip_${label}`, type, grid),
1529
+ component: 'ZdTooltip',
1530
+ bottom: true,
1531
+ label,
1532
+ children: [],
1533
+ };
1534
+ }
1535
+ buildButton(option, type, grid) {
1536
+ const { cssClass, label, iconName, reportParams, } = option;
1537
+ const { portrait: optionPortrait, rowObj } = reportParams || {};
1538
+ return {
1539
+ name: this.formatName(`button_${label}`, type, grid),
1540
+ component: 'ZdButton',
1541
+ cssClass,
1542
+ icon: true,
1543
+ iconName,
1544
+ events: {
1545
+ click: () => grid.getReport(type, optionPortrait, rowObj),
1546
+ },
1547
+ };
1548
+ }
1549
+ buildDivider(option, type, grid) {
1550
+ const { label } = option;
1551
+ return {
1552
+ name: this.formatName(`divider_${label}`, type, grid),
1553
+ component: 'ZdDivider',
1554
+ cssClass: 'zd-my-1',
1555
+ vertical: true,
1556
+ };
1557
+ }
1558
+ buildComponent(grid) {
1559
+ const { type, label, multiOption, } = this.config;
1560
+ const optionComponents = multiOption.map((option) => ([
1561
+ Object.assign(Object.assign({}, this.buildTooltip(option, type, grid)), { children: [
1562
+ this.buildButton(option, type, grid),
1563
+ ] }),
1564
+ this.buildDivider(option, type, grid),
1565
+ ]))
1566
+ .flat();
1567
+ optionComponents.pop();
1568
+ const text = {
1569
+ name: this.formatName('text', type, grid),
1570
+ component: 'ZdText',
1571
+ cssClass: 'zd-display-flex zd-align-center zd-flex-grow-1 tek-grid-export-multioption-text',
1572
+ events: {
1573
+ click: ({ event }) => event === null || event === void 0 ? void 0 : event.stopPropagation(),
1574
+ },
1575
+ text: label || '',
1576
+ };
1577
+ const result = {
1578
+ name: this.formatName('row', type, grid),
1579
+ component: 'ZdRow',
1580
+ cssClass: 'zd-display-flex zd-ma-0 zd-py-0 zd-gap-x-1 tek-grid-export-multioption-row',
1581
+ children: [text, ...optionComponents],
1582
+ };
1583
+ return result;
1584
+ }
1585
+ }
1586
+
1584
1587
  /**
1585
1588
  * Extracts properties from an object based on a list of properties
1586
1589
  * @param obj object whose properties will be extracted
@@ -1597,6 +1600,40 @@
1597
1600
  return result;
1598
1601
  };
1599
1602
 
1603
+ const EMPTY_VALUE = null;
1604
+ function cloneComparableValue(value) {
1605
+ return JSON.parse(JSON.stringify(value));
1606
+ }
1607
+ function normalizeComparableValue(value) {
1608
+ if (value === undefined || value === null || value === '') {
1609
+ return EMPTY_VALUE;
1610
+ }
1611
+ if (Array.isArray(value)) {
1612
+ if (!value.length)
1613
+ return EMPTY_VALUE;
1614
+ return value.map((item) => normalizeComparableValue(item));
1615
+ }
1616
+ if (value && typeof value === 'object') {
1617
+ const normalizedValue = Object.keys(value)
1618
+ .sort()
1619
+ .reduce((result, key) => {
1620
+ const normalizedItem = normalizeComparableValue(value[key]);
1621
+ if (normalizedItem !== EMPTY_VALUE) {
1622
+ result[key] = normalizedItem;
1623
+ }
1624
+ return result;
1625
+ }, {});
1626
+ if (!Object.keys(normalizedValue).length)
1627
+ return EMPTY_VALUE;
1628
+ return normalizedValue;
1629
+ }
1630
+ return value;
1631
+ }
1632
+ function areObjectsEqual(first, second) {
1633
+ return JSON.stringify(normalizeComparableValue(first))
1634
+ === JSON.stringify(normalizeComparableValue(second));
1635
+ }
1636
+
1600
1637
  const DynamicFilterOperations = {
1601
1638
  CONTAINS: true,
1602
1639
  NOT_CONTAINS: true,
@@ -2418,7 +2455,7 @@
2418
2455
  */
2419
2456
  this.tasksBeforeLoad = [];
2420
2457
  this.request = debounce__default["default"](() => { this.datasource.get(); }, 500);
2421
- this.updateGrouping = debounce__default["default"]((lazyLoad = false) => {
2458
+ this.updateGrouping = debounce__default["default"]((lazyLoad = this.defaultLazy) => {
2422
2459
  this.updateGroupedData(lazyLoad);
2423
2460
  }, 100);
2424
2461
  this.title = this.getInitValue('title', props.title, this.title);
@@ -3000,44 +3037,38 @@
3000
3037
  super.navigateDown();
3001
3038
  return;
3002
3039
  }
3003
- if (this.cellSelection && this.viewNavigate) {
3040
+ if (this.viewNavigate) {
3004
3041
  this.viewNavigate('down');
3005
3042
  return;
3006
3043
  }
3007
- const { index } = params;
3008
- if (!this.groupedData.length || index === this.groupedData.length)
3009
- return;
3010
- const { uniqueKey, currentRow } = this.datasource;
3011
- const rowIndex = index !== undefined
3012
- ? index
3013
- : this.groupedData.findIndex((row) => {
3014
- if (currentRow.group) {
3015
- return row.group && row.groupValue === currentRow.groupValue;
3016
- }
3017
- return row[uniqueKey] && row[uniqueKey] === currentRow[uniqueKey];
3018
- });
3019
- const newRow = this.groupedData[rowIndex + 1];
3020
- if (!newRow || !this.isItemVisible(newRow) || newRow.groupFooter) {
3021
- this.navigateDown({ index: rowIndex + 1 });
3022
- return;
3023
- }
3024
- this.datasource.currentRow = newRow;
3044
+ this.navigateGroupedDatasource(false, params);
3025
3045
  }
3026
3046
  navigateUp(params) {
3027
3047
  if (!this.isGrouped()) {
3028
3048
  super.navigateUp();
3029
3049
  return;
3030
3050
  }
3031
- if (this.cellSelection && this.viewNavigate) {
3051
+ if (this.viewNavigate) {
3032
3052
  this.viewNavigate('up');
3033
3053
  return;
3034
3054
  }
3055
+ this.navigateGroupedDatasource(true, params);
3056
+ }
3057
+ navigateDatasource(up) {
3058
+ if (!this.isGrouped()) {
3059
+ super.navigateDatasource(up);
3060
+ return;
3061
+ }
3062
+ this.navigateGroupedDatasource(up);
3063
+ }
3064
+ navigateGroupedDatasource(up, params = {}) {
3035
3065
  const { index } = params;
3036
- if (!this.groupedData.length || index === -1)
3066
+ if (!this.groupedData.length
3067
+ || (!up && index === this.groupedData.length)
3068
+ || (up && index === -1))
3037
3069
  return;
3038
3070
  const { uniqueKey, currentRow } = this.datasource;
3039
- let rowIndex;
3040
- rowIndex = index !== undefined
3071
+ let rowIndex = index !== undefined
3041
3072
  ? index
3042
3073
  : this.groupedData.findIndex((row) => {
3043
3074
  if (currentRow.group) {
@@ -3045,11 +3076,12 @@
3045
3076
  }
3046
3077
  return row[uniqueKey] && row[uniqueKey] === currentRow[uniqueKey];
3047
3078
  });
3048
- if (rowIndex === -1)
3079
+ if (up && rowIndex === -1)
3049
3080
  rowIndex = this.groupedData.length;
3050
- const newRow = this.groupedData[rowIndex - 1];
3081
+ const nextIndex = rowIndex + (up ? -1 : 1);
3082
+ const newRow = this.groupedData[nextIndex];
3051
3083
  if (!newRow || !this.isItemVisible(newRow) || newRow.groupFooter) {
3052
- this.navigateUp({ index: rowIndex - 1 });
3084
+ this.navigateGroupedDatasource(up, { index: nextIndex });
3053
3085
  return;
3054
3086
  }
3055
3087
  this.datasource.currentRow = newRow;
@@ -3172,6 +3204,9 @@
3172
3204
  getFilterInputs(columnName) {
3173
3205
  return this.gridBase.getFilterInputs(columnName);
3174
3206
  }
3207
+ registerFilterButton(filterButton) {
3208
+ this.gridBase.registerFilterButton(filterButton);
3209
+ }
3175
3210
  isColumnSearchable(column) {
3176
3211
  return column.searchable && (!this.searchVisibleOnly || column.isVisible || column.grouped);
3177
3212
  }
@@ -3380,16 +3415,14 @@
3380
3415
  */
3381
3416
  class TekGridColumnsButton extends common.IterableColumnsButton {
3382
3417
  constructor(props) {
3383
- super(props);
3418
+ super(Object.assign(Object.assign({}, props), { iterableComponentName: props.gridName || props.iterableComponentName }));
3384
3419
  this.hideGroups = false;
3385
3420
  this.aggregationDataSet = [];
3386
3421
  this.hideGroups = this.getInitValue('hideGroups', props.hideGroups, this.hideGroups);
3387
3422
  this.createAccessors();
3388
3423
  }
3389
- onCreated() {
3390
- super.onCreated();
3391
- this.controller = new TekGridColumnsButtonController(this.iterableComponent);
3392
- core.Loader.addController(`IterableColumnsButtonController_${this.componentId}`, this.controller);
3424
+ createController() {
3425
+ return new TekGridColumnsButtonController(this.iterableComponent);
3393
3426
  }
3394
3427
  getAggregationSelectData() {
3395
3428
  if (!this.aggregationDataSet.length) {
@@ -3402,6 +3435,67 @@
3402
3435
  }
3403
3436
  }
3404
3437
 
3438
+ /**
3439
+ * Base class for TekGrid export button/dropdown component.
3440
+ */
3441
+ class TekGridExportButton extends common.ComponentRender {
3442
+ constructor(props) {
3443
+ super(props);
3444
+ this.gridName = this.getInitValue('gridName', props.gridName, this.gridName);
3445
+ this.grid = this.getInitValue('grid', props.grid, this.grid);
3446
+ this.exportConfig = this.getInitValue('exportConfig', props.exportConfig, this.exportConfig);
3447
+ this.exportActions = this.getInitValue('exportActions', props.exportActions, this.exportActions);
3448
+ this.children = this.getInitValue('children', props.children, []);
3449
+ this.cssClass = this.getInitValue('cssClass', props.cssClass, this.cssClass);
3450
+ this.createAccessors();
3451
+ this.loadGrid();
3452
+ }
3453
+ getOption(config) {
3454
+ if (config.multiOption)
3455
+ return new MultiOption(config);
3456
+ return new ButtonOption(config);
3457
+ }
3458
+ getExportConfigButtons() {
3459
+ if (!this.grid)
3460
+ return [];
3461
+ const exportConfig = this.exportConfig || this.grid.exportConfig;
3462
+ return exportConfig.map((config) => {
3463
+ const option = this.getOption(config);
3464
+ return option.buildComponent(this.grid);
3465
+ });
3466
+ }
3467
+ loadChildren() {
3468
+ if (!this.grid)
3469
+ return;
3470
+ if (this.exportActions) {
3471
+ this.children = this.exportActions;
3472
+ return;
3473
+ }
3474
+ if (this.exportConfig) {
3475
+ this.children = this.getExportConfigButtons();
3476
+ return;
3477
+ }
3478
+ this.children = this.grid.exportActions || this.getExportConfigButtons();
3479
+ }
3480
+ loadGrid(gridName) {
3481
+ if (gridName)
3482
+ this.gridName = gridName;
3483
+ if (!this.grid && this.gridName) {
3484
+ const grid = core.Metadata.getInstances(this.gridName)[0];
3485
+ if (grid)
3486
+ this.grid = grid;
3487
+ }
3488
+ if (this.grid) {
3489
+ this.gridName = this.grid.name;
3490
+ this.loadChildren();
3491
+ }
3492
+ }
3493
+ onCreated() {
3494
+ super.onCreated();
3495
+ this.loadGrid();
3496
+ }
3497
+ }
3498
+
3405
3499
  class TekFilterHelper {
3406
3500
  static getLabel(name) {
3407
3501
  return core.DateHelper.getLabel(name);
@@ -3429,23 +3523,35 @@
3429
3523
  this.grid = this.getInitValue('grid', props.grid, undefined);
3430
3524
  this.showCheckboxAll = this.getInitValue('showCheckboxAll', props.showCheckboxAll, this.showCheckboxAll);
3431
3525
  this.createAccessors();
3432
- if (!this.grid)
3433
- this.loadGrid();
3526
+ this.loadGrid();
3434
3527
  }
3435
3528
  loadGrid(gridName) {
3436
3529
  if (gridName)
3437
3530
  this.gridName = gridName;
3438
- if (!this.gridName)
3439
- return;
3440
- this.grid = core.Metadata.getInstances(this.gridName)[0];
3531
+ if (!this.grid && this.gridName) {
3532
+ const grid = core.Metadata.getInstances(this.gridName)[0];
3533
+ if (grid)
3534
+ this.grid = grid;
3535
+ }
3536
+ if (this.grid) {
3537
+ this.gridName = this.grid.name;
3538
+ this.grid.registerFilterButton(this);
3539
+ }
3441
3540
  }
3442
3541
  click(event) {
3443
3542
  this.callEvent('click', { component: this, event });
3543
+ this.loadGrid();
3544
+ if (!this.grid)
3545
+ return;
3444
3546
  this.grid.callEvent('filterClick', { component: this.grid, event });
3445
3547
  if (!(event === null || event === void 0 ? void 0 : event.defaultPrevented)) {
3446
3548
  this.createFilterFromColumns.call(this);
3447
3549
  }
3448
3550
  }
3551
+ onCreated() {
3552
+ super.onCreated();
3553
+ this.loadGrid();
3554
+ }
3449
3555
  loadFilterValues({ component }) {
3450
3556
  const changedCompNames = [];
3451
3557
  const { datasource } = this.grid;
@@ -3501,7 +3607,8 @@
3501
3607
  });
3502
3608
  }
3503
3609
  hideFilterModal() {
3504
- this.filterModal.hide();
3610
+ if (this.filterModal)
3611
+ this.filterModal.hide();
3505
3612
  }
3506
3613
  destroyFilterModal() {
3507
3614
  if (this.filterModal)
@@ -3547,9 +3654,14 @@
3547
3654
  },
3548
3655
  {
3549
3656
  name: `${this.grid.name}-filter-close-button`,
3550
- component: 'ZdModalCloseButton',
3657
+ component: 'ZdButton',
3658
+ icon: true,
3659
+ iconName: 'close',
3660
+ flat: true,
3551
3661
  small: true,
3552
- modalName: `${this.grid.name}-filter-modal`,
3662
+ events: {
3663
+ click: this.hideFilterModal.bind(this),
3664
+ },
3553
3665
  },
3554
3666
  ],
3555
3667
  },
@@ -3695,15 +3807,20 @@
3695
3807
  this.setFilter(filter, event, datasource.setBaseFilter.bind(datasource));
3696
3808
  }
3697
3809
  else {
3810
+ const structuredFilter = {};
3698
3811
  Object.keys(formValue).forEach((item) => {
3699
3812
  let columnName = item.split(`${this.grid.name}-filter-AND-CONTAINS-`)[1];
3700
3813
  columnName = columnName.split('-').slice(0, -1).join('-'); // remove index
3701
- if (formValue[item]) {
3702
- filter[columnName] = formValue[item];
3814
+ const itemValue = formValue[item];
3815
+ if (itemValue && !(Array.isArray(itemValue) && !itemValue.length)) {
3816
+ filter[columnName] = itemValue;
3817
+ if (!structuredFilter[columnName])
3818
+ structuredFilter[columnName] = [];
3819
+ structuredFilter[columnName].push({ relation: 'AND', operation: 'CONTAINS', value: itemValue });
3703
3820
  }
3704
3821
  });
3705
3822
  datasource.filter = filter;
3706
- this.setFilter(filter, event, datasource.setBaseFilter.bind(datasource));
3823
+ this.setFilter(structuredFilter, event, datasource.setBaseFilter.bind(datasource));
3707
3824
  }
3708
3825
  this.grid.changeLayout(event);
3709
3826
  }
@@ -3753,7 +3870,8 @@
3753
3870
  columnComponentName = `${this.grid.name}-filter-AND-CONTAINS-${column.name}-${index}`;
3754
3871
  }
3755
3872
  this.filterFormInputs[column.name].push(columnComponentName);
3756
- const newColumnComponent = Object.assign(Object.assign(Object.assign({ label: column.label }, column.componentProps), filterItem), { name: columnComponentName });
3873
+ const _b = column.componentProps || {}, componentProps = __rest(_b, ["dataValueOut"]);
3874
+ const newColumnComponent = Object.assign(Object.assign(Object.assign({ label: column.label }, componentProps), filterItem), { name: columnComponentName });
3757
3875
  if (filterItem.helperOptions) {
3758
3876
  if (!newColumnComponent.events)
3759
3877
  newColumnComponent.events = {};
@@ -3787,8 +3905,8 @@
3787
3905
  }
3788
3906
 
3789
3907
  class TekGridLayoutOptions extends common.ComponentRender {
3790
- constructor() {
3791
- super(...arguments);
3908
+ constructor(props) {
3909
+ super(props);
3792
3910
  this.currentLayoutName = '';
3793
3911
  this.layoutEdited = false;
3794
3912
  this.layouts = {};
@@ -3797,6 +3915,8 @@
3797
3915
  this.originalDatasourceOrder = [];
3798
3916
  this.originalDatasourceDynamicFilter = {};
3799
3917
  this.originalDatasourceFilter = {};
3918
+ this.gridName = this.getInitValue('gridName', props.gridName, this.gridName);
3919
+ this.createAccessors();
3800
3920
  }
3801
3921
  getParentGrid() {
3802
3922
  let { parent } = this;
@@ -3807,30 +3927,44 @@
3807
3927
  }
3808
3928
  return parent;
3809
3929
  }
3930
+ loadGrid(gridName) {
3931
+ if (gridName)
3932
+ this.gridName = gridName;
3933
+ if (this.gridName) {
3934
+ const grid = core.Metadata.getInstances(this.gridName)[0];
3935
+ if (grid)
3936
+ this.grid = grid;
3937
+ }
3938
+ else {
3939
+ this.grid = this.getParentGrid();
3940
+ }
3941
+ if (this.grid) {
3942
+ this.gridName = this.grid.name;
3943
+ }
3944
+ return this.grid;
3945
+ }
3946
+ onGridChangeLayout() {
3947
+ this.layoutEdited = this.hasLayoutChanges();
3948
+ }
3949
+ registerChangeLayoutEvent() {
3950
+ if (!this.grid || this.changeLayoutEventGrid === this.grid)
3951
+ return;
3952
+ this.grid.addEvent('changeLayout', this.onGridChangeLayout.bind(this));
3953
+ this.changeLayoutEventGrid = this.grid;
3954
+ }
3810
3955
  onMounted(element) {
3811
3956
  const _super = Object.create(null, {
3812
3957
  onMounted: { get: () => super.onMounted }
3813
3958
  });
3814
3959
  return __awaiter(this, void 0, void 0, function* () {
3815
3960
  _super.onMounted.call(this, element);
3816
- this.grid = this.getParentGrid();
3961
+ this.loadGrid();
3962
+ this.registerChangeLayoutEvent();
3817
3963
  this.originalDatasourceOrder = [...this.grid.datasource.order];
3818
3964
  this.originalDatasourceDynamicFilter = Object.assign({}, this.grid.datasource.dynamicFilter);
3819
3965
  this.originalDatasourceFilter = Object.assign({}, this.grid.datasource.filter);
3820
- this.originalColumnProps = this.grid.columns.map((column) => ({
3821
- name: column.name,
3822
- label: column.label,
3823
- align: column.align,
3824
- isVisible: column.isVisible,
3825
- minWidth: column.minWidth,
3826
- maxWidth: column.maxWidth,
3827
- width: column.width,
3828
- fixed: column.fixed,
3829
- grouped: column.grouped,
3830
- groupOpened: column.groupOpened,
3831
- aggregation: column.aggregation,
3832
- filterHelperValue: this.getHelperValue(column),
3833
- }));
3966
+ this.originalColumnProps = this.grid.columns.map((column) => this.getLayoutColumnSnapshot(column));
3967
+ this.originalLayoutSnapshot = cloneComparableValue(this.getCurrentLayoutSnapshot(''));
3834
3968
  let layoutsInfo = {};
3835
3969
  const promise = this.loadLayoutsInfo();
3836
3970
  if (this.grid instanceof TekGrid) {
@@ -3875,6 +4009,74 @@
3875
4009
  }
3876
4010
  return '';
3877
4011
  }
4012
+ getLayoutColumnSnapshot(column, isVisible = column.isVisible) {
4013
+ const filterHelperValue = this.getHelperValue(column);
4014
+ return {
4015
+ name: column.name,
4016
+ label: column.label,
4017
+ align: column.align,
4018
+ isVisible,
4019
+ minWidth: column.minWidth || '',
4020
+ maxWidth: column.maxWidth || '',
4021
+ width: column.width,
4022
+ fixed: !!column.fixed,
4023
+ grouped: !!column.grouped,
4024
+ groupOpened: !!column.groupOpened,
4025
+ aggregation: column.aggregation,
4026
+ filterHelperValue: Array.isArray(filterHelperValue)
4027
+ ? filterHelperValue
4028
+ : filterHelperValue || '',
4029
+ };
4030
+ }
4031
+ getCurrentLayoutSnapshot(name) {
4032
+ if (this.viewGetCurrentLayout) {
4033
+ return this.viewGetCurrentLayout(name);
4034
+ }
4035
+ return {
4036
+ name,
4037
+ gridWidth: 'auto',
4038
+ order: [...this.grid.datasource.order],
4039
+ filter: Object.assign({}, this.grid.datasource.filter),
4040
+ dynamicFilter: Object.assign({}, this.grid.datasource.dynamicFilter),
4041
+ columns: this.grid.columns.map((column) => this.getLayoutColumnSnapshot(column)),
4042
+ };
4043
+ }
4044
+ getBaselineLayoutSnapshot() {
4045
+ if (this.currentLayoutName) {
4046
+ const currentLayout = this.layouts[this.currentLayoutName];
4047
+ return currentLayout;
4048
+ }
4049
+ return this.originalLayoutSnapshot;
4050
+ }
4051
+ getOriginalLayoutSnapshot() {
4052
+ return cloneComparableValue({
4053
+ name: '',
4054
+ gridWidth: 'auto',
4055
+ order: [...this.originalDatasourceOrder],
4056
+ filter: Object.assign({}, this.originalDatasourceFilter),
4057
+ dynamicFilter: Object.assign({}, this.originalDatasourceDynamicFilter),
4058
+ columns: this.originalColumnProps,
4059
+ });
4060
+ }
4061
+ hasLayoutChanges() {
4062
+ const baselineLayout = this.getBaselineLayoutSnapshot();
4063
+ if (!baselineLayout)
4064
+ return false;
4065
+ const currentLayout = this.getCurrentLayoutSnapshot(this.currentLayoutName);
4066
+ return !areObjectsEqual(currentLayout, baselineLayout);
4067
+ }
4068
+ getCurrentLayout() {
4069
+ return this.getCurrentLayoutSnapshot(this.currentLayoutName);
4070
+ }
4071
+ getLayout(name = this.currentLayoutName) {
4072
+ if (name === '') {
4073
+ return this.getOriginalLayoutSnapshot();
4074
+ }
4075
+ const layout = this.layouts[name];
4076
+ if (!layout)
4077
+ return undefined;
4078
+ return cloneComparableValue(layout);
4079
+ }
3878
4080
  layoutHasFilter(layout) {
3879
4081
  if (layout === '')
3880
4082
  return false;
@@ -3979,16 +4181,16 @@
3979
4181
  this.layoutEdited = false;
3980
4182
  }
3981
4183
  applyLayout(name, save = true) {
4184
+ const layoutSelected = name === '' ? this.getLayout(name) : this.layouts[name];
3982
4185
  if (this.grid.events.beforeApplyLayout) {
3983
4186
  const canApply = this.grid.callEvent('beforeApplyLayout', {
3984
4187
  component: this.grid,
3985
- layout: this.layouts[name],
4188
+ layout: layoutSelected,
3986
4189
  });
3987
4190
  if (canApply === false)
3988
4191
  return;
3989
4192
  }
3990
4193
  this.currentLayoutName = name;
3991
- const layoutSelected = this.layouts[name];
3992
4194
  if (this.viewApplyLayout) {
3993
4195
  this.viewApplyLayout(layoutSelected);
3994
4196
  }
@@ -4023,7 +4225,12 @@
4023
4225
  delete this.layouts[name];
4024
4226
  this.saveLayouts();
4025
4227
  }
4026
- updateLayout(name, layout) {
4228
+ updateLayout(name = this.currentLayoutName, layout = this.getCurrentLayout()) {
4229
+ if (name === '') {
4230
+ this.updateDefaultLayout(layout);
4231
+ this.layoutEdited = false;
4232
+ return;
4233
+ }
4027
4234
  this.fixColumns(layout);
4028
4235
  this.currentLayoutName = name;
4029
4236
  layout.name = name;
@@ -4045,6 +4252,7 @@
4045
4252
  return Object.assign(Object.assign({}, originalColumn), column);
4046
4253
  });
4047
4254
  }
4255
+ this.originalLayoutSnapshot = this.getOriginalLayoutSnapshot();
4048
4256
  if (this.currentLayoutName === '') {
4049
4257
  this.applyLayout(this.currentLayoutName, false);
4050
4258
  }
@@ -4056,20 +4264,7 @@
4056
4264
  this.grid.columns.forEach((gridColumn) => {
4057
4265
  if (!hasLayoutColumns
4058
4266
  || layoutColumnNames.indexOf(gridColumn.name) === -1) {
4059
- layout.columns.push({
4060
- name: gridColumn.name,
4061
- label: gridColumn.label,
4062
- align: gridColumn.align,
4063
- isVisible: !hasLayoutColumns && gridColumn.isVisible,
4064
- width: gridColumn.width,
4065
- minWidth: gridColumn.minWidth,
4066
- maxWidth: gridColumn.maxWidth,
4067
- fixed: gridColumn.fixed,
4068
- grouped: gridColumn.grouped,
4069
- groupOpened: gridColumn.groupOpened,
4070
- aggregation: gridColumn.aggregation,
4071
- filterHelperValue: this.getHelperValue(gridColumn),
4072
- });
4267
+ layout.columns.push(this.getLayoutColumnSnapshot(gridColumn, !hasLayoutColumns && gridColumn.isVisible));
4073
4268
  }
4074
4269
  });
4075
4270
  }
@@ -4350,6 +4545,9 @@
4350
4545
  getFilterInputs(columnName) {
4351
4546
  return this.gridBase.getFilterInputs(columnName);
4352
4547
  }
4548
+ registerFilterButton(filterButton) {
4549
+ this.gridBase.registerFilterButton(filterButton);
4550
+ }
4353
4551
  getColumn(name) {
4354
4552
  return super.getColumn(name);
4355
4553
  }
@@ -4958,6 +5156,7 @@
4958
5156
  exports.TekGridColumn = TekGridColumn;
4959
5157
  exports.TekGridColumnsButton = TekGridColumnsButton;
4960
5158
  exports.TekGridColumnsButtonController = TekGridColumnsButtonController;
5159
+ exports.TekGridExportButton = TekGridExportButton;
4961
5160
  exports.TekGridFilterButton = TekGridFilterButton;
4962
5161
  exports.TekGridLayoutOptions = TekGridLayoutOptions;
4963
5162
  exports.TekMemoryDatasource = TekMemoryDatasource;