@adaptabletools/adaptable-cjs 20.1.5 → 20.1.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.
@@ -220,15 +220,43 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
220
220
  }
221
221
  this.triggerGridLayoutChange(layout);
222
222
  }
223
- triggerGridLayoutChange(layout) {
223
+ triggerGridLayoutChange(layout, prevLayout = this._prevFiredLayout, options) {
224
224
  layout = (0, simplifyLayoutModel_1.simplifyLayoutModel)(layout);
225
- const prevLayout = this._prevFiredLayout;
225
+ prevLayout = prevLayout ? (0, simplifyLayoutModel_1.simplifyLayoutModel)(prevLayout) : undefined;
226
+ const shouldSkipTriggerChange = options?.skipTriggerChange === true;
226
227
  this._prevFiredLayout = layout;
227
228
  this.currentLayout = layout;
228
- // emit an event that the layout has changed from the grid
229
- this.emitSync('gridLayoutChanged', layout);
230
- const log = this.debugger.extend('gridLayoutChanged');
231
- log('current grid layout:', JSON.stringify(layout, null, 2), '\nprev layout:\n', prevLayout ? JSON.stringify(prevLayout, null, 2) : 'no prev layout', '\nchanges from prev to current:\n', (0, isLayoutEqual_1.getChanges)(prevLayout, layout));
229
+ if ((!prevLayout?.RowGroupedColumns || !prevLayout?.RowGroupedColumns.length) &&
230
+ layout.RowGroupedColumns &&
231
+ layout.RowGroupedColumns.length > 0 &&
232
+ layout.RowGroupValues) {
233
+ // most likely the user has changed grouping via some AG Grid action
234
+ // and we need to make sure the expand/collapse state is applied
235
+ // but we want to suspend the listener
236
+ // as it would re-trigger another change
237
+ const unsupress = this.suspendAgGridListener();
238
+ this.applyRowGroupValues(layout.RowGroupValues);
239
+ unsupress();
240
+ }
241
+ if ((!prevLayout?.RowGroupedColumns || !prevLayout?.RowGroupedColumns.length) &&
242
+ layout.RowGroupedColumns &&
243
+ layout.RowGroupedColumns.length > 0 &&
244
+ layout.RowGroupValues) {
245
+ // most likely the user has changed grouping via some AG Grid action
246
+ // and we need to make sure the expand/collapse state is applied
247
+ // but we want to suspend the listener
248
+ // as it would re-trigger another change
249
+ const unsupress = this.suspendAgGridListener();
250
+ this.applyRowGroupValues(layout.RowGroupValues);
251
+ unsupress();
252
+ }
253
+ if (!shouldSkipTriggerChange) {
254
+ // emit an event that the layout has changed from the grid
255
+ this.emitSync('gridLayoutChanged', layout);
256
+ const log = this.debugger.extend('gridLayoutChanged');
257
+ const changes = (0, isLayoutEqual_1.getChanges)(prevLayout, layout);
258
+ log('current grid layout:', JSON.stringify(layout, null, 2), '\nprev layout:\n', prevLayout ? JSON.stringify(prevLayout, null, 2) : 'no prev layout', '\nchanges from prev to current:\n', changes);
259
+ }
232
260
  }
233
261
  onChange(fn) {
234
262
  return this.on('gridLayoutChanged', fn);
@@ -263,6 +291,17 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
263
291
  }
264
292
  delete layout.TableColumns;
265
293
  const pivotLayout = {
294
+ Ignore_Name: layout.Ignore_Name,
295
+ Ignore_GridFilter: layout.Ignore_GridFilter,
296
+ Ignore_ColumnFilters: layout.Ignore_ColumnFilters,
297
+ Ignore_ColumnHeaders: layout.Ignore_ColumnHeaders,
298
+ Ignore_AutoSizeColumns: layout.Ignore_AutoSizeColumns,
299
+ Ignore_RowSummaries: layout.Ignore_RowSummaries,
300
+ Ignore_IsReadOnly: layout.Ignore_IsReadOnly,
301
+ Ignore_Tags: layout.Ignore_Tags,
302
+ Ignore_Source: layout.Ignore_Source,
303
+ Ignore_AdaptableVersion: layout.Ignore_AdaptableVersion,
304
+ Ignore_Uuid: layout.Ignore_Uuid,
266
305
  PivotColumns,
267
306
  ColumnPinning: layout.ColumnPinning,
268
307
  ColumnSorts: layout.ColumnSorts,
@@ -426,6 +465,10 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
426
465
  });
427
466
  }
428
467
  if (RowGroupedColumns && RowGroupedColumns.length) {
468
+ // if it's a new grouping, try and take it
469
+ const isGroupingNew = RowGroupedColumns &&
470
+ !this.currentLayout?.RowGroupedColumns &&
471
+ !this.currentLayout?.PivotGroupedColumns;
429
472
  if (this.currentLayout?.RowGroupValues) {
430
473
  const currentRowGroupValues = this.currentLayout.RowGroupValues;
431
474
  if (currentRowGroupValues.RowGroupDisplay === 'always-collapsed') {
@@ -439,18 +482,22 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
439
482
  };
440
483
  }
441
484
  else if (currentRowGroupValues.RowGroupDisplay === 'collapsed') {
442
- const ExpandedValues = this.getRowGroupNodePathsAs({
443
- expanded: true,
444
- });
485
+ const ExpandedValues = isGroupingNew
486
+ ? currentRowGroupValues.Values || []
487
+ : this.getRowGroupNodePathsAs({
488
+ expanded: true,
489
+ });
445
490
  RowGroupValues = {
446
491
  RowGroupDisplay: 'collapsed',
447
492
  Values: ExpandedValues,
448
493
  };
449
494
  }
450
495
  else if (currentRowGroupValues.RowGroupDisplay === 'expanded') {
451
- const CollapsedValues = this.getRowGroupNodePathsAs({
452
- expanded: false,
453
- });
496
+ const CollapsedValues = isGroupingNew
497
+ ? currentRowGroupValues.Values || []
498
+ : this.getRowGroupNodePathsAs({
499
+ expanded: false,
500
+ });
454
501
  RowGroupValues = {
455
502
  RowGroupDisplay: 'expanded',
456
503
  Values: CollapsedValues,
@@ -458,7 +505,23 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
458
505
  }
459
506
  }
460
507
  }
508
+ else {
509
+ if (this.currentLayout?.RowGroupValues) {
510
+ RowGroupValues = this.currentLayout.RowGroupValues;
511
+ }
512
+ }
461
513
  const layout = (0, simplifyLayoutModel_1.simplifyTableLayoutModel)({
514
+ Ignore_Name: this.currentLayout?.Ignore_Name || 'Default',
515
+ Ignore_GridFilter: this.currentLayout?.Ignore_GridFilter,
516
+ Ignore_ColumnFilters: this.currentLayout?.Ignore_ColumnFilters,
517
+ Ignore_ColumnHeaders: this.currentLayout?.Ignore_ColumnHeaders,
518
+ Ignore_AutoSizeColumns: this.currentLayout?.Ignore_AutoSizeColumns,
519
+ Ignore_RowSummaries: this.currentLayout?.Ignore_RowSummaries,
520
+ Ignore_IsReadOnly: this.currentLayout?.Ignore_IsReadOnly,
521
+ Ignore_Tags: this.currentLayout?.Ignore_Tags,
522
+ Ignore_Source: this.currentLayout?.Ignore_Source,
523
+ Ignore_AdaptableVersion: this.currentLayout?.Ignore_AdaptableVersion,
524
+ Ignore_Uuid: this.currentLayout?.Ignore_Uuid,
462
525
  TableColumns: TableColumns,
463
526
  ColumnVisibility,
464
527
  ColumnWidths: ColumnWidths,
@@ -671,18 +734,39 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
671
734
  }
672
735
  setLayout(layout, options) {
673
736
  layout = (0, normalizeLayoutModel_1.normalizeLayoutModel)(layout, { isTree: this.isTreeMode() });
737
+ const shouldSkipTriggerChange = options?.skipTriggerChange === true;
674
738
  const shouldSkipEqualityCheck = options?.force === true;
675
739
  if (!shouldSkipEqualityCheck && (0, isLayoutEqual_1.isLayoutEqual)(this.currentLayout, layout)) {
676
740
  return false;
677
741
  }
742
+ const prevCurrent = this.currentLayout;
678
743
  this.silentSetCurrentLayout(layout);
679
744
  this.applyLayout(layout, options);
680
- this.triggerGridLayoutChange(layout);
745
+ this.triggerGridLayoutChange(layout, prevCurrent, {
746
+ skipTriggerChange: shouldSkipTriggerChange,
747
+ });
681
748
  return true;
682
749
  }
683
750
  isCurrentLayoutPivot() {
684
751
  return this.currentLayout && (0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout);
685
752
  }
753
+ suspendAgGridListener() {
754
+ if (this.supressGlobalAgGridEventTimeoutId) {
755
+ clearTimeout(this.supressGlobalAgGridEventTimeoutId);
756
+ this.supressGlobalAgGridEventTimeoutId = null;
757
+ }
758
+ this.suppressGlobalAgGridEventListener = true;
759
+ return () => this.resumeAgGridListener();
760
+ }
761
+ resumeAgGridListener(options) {
762
+ if (options?.immediate) {
763
+ this.suppressGlobalAgGridEventListener = false;
764
+ return;
765
+ }
766
+ this.supressGlobalAgGridEventTimeoutId = setTimeout(() => {
767
+ this.suppressGlobalAgGridEventListener = false;
768
+ }, 0);
769
+ }
686
770
  applyLayout(layout, options) {
687
771
  this.warn('applyLayout', layout);
688
772
  // we want to do this supress/unsupress thing
@@ -691,16 +775,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
691
775
  // yes, we do check for same layout and bail out if it is the same
692
776
  // but we still want to avoid this unnecessary initial loop
693
777
  // which may cause more adaptable work
694
- if (this.supressGlobalAgGridEventTimeoutId) {
695
- clearTimeout(this.supressGlobalAgGridEventTimeoutId);
696
- this.supressGlobalAgGridEventTimeoutId = null;
697
- }
698
- const unsuppress = () => {
699
- this.supressGlobalAgGridEventTimeoutId = setTimeout(() => {
700
- this.suppressGlobalAgGridEventListener = false;
701
- }, 0);
702
- };
703
- this.suppressGlobalAgGridEventListener = true;
778
+ const resume = this.suspendAgGridListener();
704
779
  const pivotMode = this.gridApi.isPivotMode();
705
780
  if (!!layout.SuppressAggFuncInHeader !== !!this.gridApi.getGridOption('suppressAggFuncInHeader')) {
706
781
  this.gridApi.setGridOption('suppressAggFuncInHeader', !!layout.SuppressAggFuncInHeader);
@@ -724,7 +799,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
724
799
  perfApplyPivot.end();
725
800
  }
726
801
  finally {
727
- unsuppress();
802
+ resume();
728
803
  }
729
804
  return;
730
805
  }
@@ -737,7 +812,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
737
812
  perfApplyTable.end();
738
813
  }
739
814
  finally {
740
- unsuppress();
815
+ resume();
741
816
  }
742
817
  }
743
818
  applyTableLayout(layout, options) {
@@ -824,7 +899,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
824
899
  }
825
900
  computeColumnStateForPivotLayout(layout) {
826
901
  let columnState = {};
827
- const pivotColumnsToIndexes = layout.PivotColumns.reduce((acc, colId, index) => {
902
+ const pivotColumnsToIndexes = (layout.PivotColumns || []).reduce((acc, colId, index) => {
828
903
  acc[colId] = index;
829
904
  return acc;
830
905
  }, {});
@@ -837,10 +912,6 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
837
912
  ...layout.PivotColumns,
838
913
  ...(layout.PivotAggregationColumns || []).map((col) => col.ColumnId),
839
914
  ], this.gridApi.getColumnDefs());
840
- const pivotAggsToIndexes = layout.PivotAggregationColumns.reduce((acc, { ColumnId }, index) => {
841
- acc[ColumnId] = index;
842
- return acc;
843
- }, {});
844
915
  columnState.state = columnIds.map((columnId) => {
845
916
  const pivotIndex = pivotColumnsToIndexes[columnId];
846
917
  const rowGroupIndex = rowGroupColumnIndexes[columnId];
@@ -859,14 +930,15 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
859
930
  return columnState;
860
931
  }
861
932
  computePivotAggregations(layout, columnState) {
862
- const pivotAggsToIndexes = layout.PivotAggregationColumns.reduce((acc, { ColumnId }, index) => {
933
+ const PivotAggregationColumns = layout.PivotAggregationColumns || [];
934
+ const pivotAggsToIndexes = PivotAggregationColumns.reduce((acc, { ColumnId }, index) => {
863
935
  acc[ColumnId] = index;
864
936
  return acc;
865
937
  }, {});
866
938
  columnState.state = columnState.state.map((colState) => {
867
939
  const columnId = colState.colId;
868
940
  const aggIndex = pivotAggsToIndexes[columnId];
869
- const aggFunc = aggIndex != null ? layout.PivotAggregationColumns[aggIndex].AggFunc.aggFunc : null;
941
+ const aggFunc = aggIndex != null ? PivotAggregationColumns[aggIndex].AggFunc.aggFunc : null;
870
942
  return {
871
943
  ...colState,
872
944
  aggFunc: aggIndex != null ? (aggFunc === true ? DEFAULT_AGG_FUNC : aggFunc) : null,
@@ -1041,7 +1113,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1041
1113
  // fourth: ...etc
1042
1114
  // so we apply the states for all aggregations except the last one
1043
1115
  //
1044
- const aggregationsMapForOrder = layout.PivotAggregationColumns.map((_, index) => layout.PivotAggregationColumns.slice(0, index));
1116
+ const aggregationsMapForOrder = (layout.PivotAggregationColumns || []).map((_, index) => layout.PivotAggregationColumns.slice(0, index));
1045
1117
  aggregationsMapForOrder.forEach((agg) => {
1046
1118
  // we're mutating the columnState here
1047
1119
  this.computePivotAggregations({ ...layout, PivotAggregationColumns: agg }, columnState);
@@ -1236,7 +1308,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1236
1308
  };
1237
1309
  const colIdInfo = (0, destructurePivotColumnId_1.destructurePivotColumnId)(colDef, {
1238
1310
  pivotColIds: this.currentLayout.PivotColumns,
1239
- aggColIds: this.currentLayout.PivotAggregationColumns.map((col) => col.ColumnId),
1311
+ aggColIds: (this.currentLayout.PivotAggregationColumns || []).map((col) => col.ColumnId),
1240
1312
  }, (message) => this.warn(message));
1241
1313
  if (colIdInfo === '!unknown!') {
1242
1314
  return defaultHiddenConfig;
@@ -54,8 +54,17 @@ function isTableLayoutEqual(l1, l2) {
54
54
  exports.isTableLayoutEqual = isTableLayoutEqual;
55
55
  //#clearIgnoredProperties
56
56
  function clearIgnoredProperties(layout) {
57
- delete layout.GridFilter;
58
- delete layout.ColumnFilters;
57
+ delete layout.Ignore_GridFilter;
58
+ delete layout.Ignore_ColumnFilters;
59
+ delete layout.Ignore_Name;
60
+ delete layout.Ignore_ColumnHeaders;
61
+ delete layout.Ignore_AutoSizeColumns;
62
+ delete layout.Ignore_RowSummaries;
63
+ delete layout.Ignore_IsReadOnly;
64
+ delete layout.Ignore_Tags;
65
+ delete layout.Ignore_Source;
66
+ delete layout.Ignore_AdaptableVersion;
67
+ delete layout.Ignore_Uuid;
59
68
  }
60
69
  function isPivotLayoutEqual(l1, l2) {
61
70
  l1 = (0, normalizeLayoutModel_1.normalizePivotLayoutModel)(l1);
@@ -17,6 +17,9 @@ function normalizeTableLayoutModel(layout, options) {
17
17
  if (!layout.TableAggregationColumns) {
18
18
  layout.TableAggregationColumns = [];
19
19
  }
20
+ if (!layout.Ignore_ColumnFilters) {
21
+ layout.Ignore_ColumnFilters = [];
22
+ }
20
23
  if (!layout.ColumnSorts) {
21
24
  layout.ColumnSorts = [];
22
25
  }
@@ -118,6 +121,9 @@ function normalizePivotLayoutModel(layout) {
118
121
  if (!layout.ColumnVisibility) {
119
122
  layout.ColumnVisibility = {};
120
123
  }
124
+ if (!layout.Ignore_ColumnFilters) {
125
+ layout.Ignore_ColumnFilters = [];
126
+ }
121
127
  if (!layout.PivotAggregationColumns) {
122
128
  layout.PivotAggregationColumns = [];
123
129
  }
@@ -14,6 +14,9 @@ function simplifyTableLayoutModel(layout) {
14
14
  if (layout.ColumnSorts && !layout.ColumnSorts.length) {
15
15
  delete layout.ColumnSorts;
16
16
  }
17
+ if (layout.Ignore_ColumnFilters && !layout.Ignore_ColumnFilters) {
18
+ delete layout.Ignore_ColumnFilters;
19
+ }
17
20
  if (layout.RowGroupedColumns && !layout.RowGroupedColumns.length) {
18
21
  delete layout.RowGroupedColumns;
19
22
  }
@@ -76,9 +79,6 @@ function simplifyPivotLayoutModel(layout) {
76
79
  if (layout.ColumnSorts && !layout.ColumnSorts.length) {
77
80
  delete layout.ColumnSorts;
78
81
  }
79
- if (!layout.PivotGroupedColumns && layout.RowGroupValues) {
80
- delete layout.RowGroupValues;
81
- }
82
82
  if (layout.GrandTotalRow === undefined) {
83
83
  delete layout.GrandTotalRow;
84
84
  }