@datorama/core 21.4.0-rc.3 → 21.4.0-rc.6

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/bundle.scss +8 -1
  2. package/bundles/datorama-core.umd.js +65 -23
  3. package/bundles/datorama-core.umd.js.map +1 -1
  4. package/bundles/datorama-core.umd.min.js +49 -49
  5. package/bundles/datorama-core.umd.min.js.map +1 -1
  6. package/datorama-core.metadata.json +1 -1
  7. package/esm2015/lib/grid-v2/grid-controller/grid-controller.component.js +2 -2
  8. package/esm2015/lib/grid-v2/grid-filter/filter-validator.js +7 -14
  9. package/esm2015/lib/grid-v2/grid-filter/grid-filter.component.js +7 -3
  10. package/esm2015/lib/grid-v2/grid-filter/grid-filter.types.js +1 -1
  11. package/esm2015/lib/grid-v2/grid-store/grid.query.js +12 -1
  12. package/esm2015/lib/grid-v2/grid-store/grid.service.js +33 -9
  13. package/esm2015/lib/grid-v2/grid-store/grid.store.types.js +1 -1
  14. package/esm2015/lib/grid-v2/grid-store/util.js +11 -1
  15. package/esm5/lib/grid-v2/grid-controller/grid-controller.component.js +2 -2
  16. package/esm5/lib/grid-v2/grid-filter/filter-validator.js +7 -14
  17. package/esm5/lib/grid-v2/grid-filter/grid-filter.component.js +8 -3
  18. package/esm5/lib/grid-v2/grid-filter/grid-filter.types.js +1 -1
  19. package/esm5/lib/grid-v2/grid-store/grid.query.js +12 -1
  20. package/esm5/lib/grid-v2/grid-store/grid.service.js +33 -9
  21. package/esm5/lib/grid-v2/grid-store/grid.store.types.js +1 -1
  22. package/esm5/lib/grid-v2/grid-store/util.js +11 -1
  23. package/fesm2015/datorama-core.js +64 -23
  24. package/fesm2015/datorama-core.js.map +1 -1
  25. package/fesm5/datorama-core.js +65 -23
  26. package/fesm5/datorama-core.js.map +1 -1
  27. package/lib/grid-v2/grid-controller/grid-controller.component.d.ts +2 -2
  28. package/lib/grid-v2/grid-filter/grid-filter.types.d.ts +6 -1
  29. package/lib/grid-v2/grid-store/grid.query.d.ts +2 -1
  30. package/lib/grid-v2/grid-store/grid.store.types.d.ts +4 -0
  31. package/lib/grid-v2/grid-store/util.d.ts +2 -0
  32. package/package.json +1 -1
@@ -11267,6 +11267,16 @@ function getColField(colDef) {
11267
11267
  var field = colDef.field, showRowGroup = colDef.showRowGroup, pivotValueColumn = colDef.pivotValueColumn;
11268
11268
  return pivotValueColumn ? pivotValueColumn.getColId() : field || showRowGroup;
11269
11269
  }
11270
+ function tryParsePivotValue(str) {
11271
+ var value;
11272
+ try {
11273
+ value = JSON.parse(str);
11274
+ }
11275
+ catch (e) {
11276
+ console.error("Can't parse " + str + " from JSON");
11277
+ }
11278
+ return value;
11279
+ }
11270
11280
 
11271
11281
  var GridQuery = /** @class */ (function (_super) {
11272
11282
  __extends(GridQuery, _super);
@@ -11407,6 +11417,17 @@ var GridQuery = /** @class */ (function (_super) {
11407
11417
  GridQuery.prototype.selectFilter = function () {
11408
11418
  return this.select(function (state) { return state.settings.filter; });
11409
11419
  };
11420
+ GridQuery.prototype.filterChanged = function () {
11421
+ return this.selectFilter().pipe(map$1(function (filter) {
11422
+ return Object.keys(filter).reduce(function (filters, key) {
11423
+ if (filter[key]) {
11424
+ var _a = filter[key], conditional = _a.conditional, pivotFieldsMap = _a.pivotFieldsMap;
11425
+ filters.push({ column: key, filter: conditional, pivotFieldsMap: pivotFieldsMap });
11426
+ }
11427
+ return filters;
11428
+ }, []);
11429
+ }));
11430
+ };
11410
11431
  GridQuery.prototype.getSearchTerm = function () {
11411
11432
  return this.getValue().settings.searchTerm;
11412
11433
  };
@@ -11559,7 +11580,7 @@ var OperatorTypes;
11559
11580
  function validateStringCondition(rowValue, _a) {
11560
11581
  var condition = _a.condition, filterValue = _a.value;
11561
11582
  var filterTextLowerCase = filterValue ? filterValue.toLowerCase() : '';
11562
- var valueLowerCase = rowValue ? rowValue.toLowerCase() : '';
11583
+ var valueLowerCase = rowValue ? ("" + rowValue).toLowerCase() : '';
11563
11584
  switch (condition) {
11564
11585
  case DatoFilterConditions.EQUALS:
11565
11586
  return valueLowerCase === filterTextLowerCase;
@@ -11650,7 +11671,7 @@ function validateFilter(_a, activeFilters) {
11650
11671
  var currentRowPivotKeys = row.parent.childrenMapped && getRowPivotKeys(row.parent.childrenMapped);
11651
11672
  var rowValue = api.getValue(filter, row);
11652
11673
  /** If value is under a pivoted column but doesn't match the filter pivot */
11653
- if (pivotKeys && !isArrayValuesEqual(pivotKeys, currentRowPivotKeys)) {
11674
+ if (pivotKeys && pivotKeys.length > 0 && !isArrayValuesEqual(pivotKeys, currentRowPivotKeys)) {
11654
11675
  return { value: true };
11655
11676
  }
11656
11677
  if (conditional) {
@@ -11690,17 +11711,9 @@ function validateFilter(_a, activeFilters) {
11690
11711
  function getRowPivotKeys(childrenMapped, keys) {
11691
11712
  if (keys === void 0) { keys = []; }
11692
11713
  var key = Object.keys(childrenMapped)[0];
11693
- var parsedKey;
11694
- try {
11695
- parsedKey = JSON.parse(key);
11696
- }
11697
- catch (e) {
11698
- console.error("Can't parse " + key + " from JSON");
11699
- }
11700
- finally {
11701
- if (parsedKey) {
11702
- keys = getRowPivotKeys(childrenMapped[key], __spread(keys, [parsedKey.value]));
11703
- }
11714
+ var parsedKey = tryParsePivotValue(key);
11715
+ if (parsedKey) {
11716
+ keys = getRowPivotKeys(childrenMapped[key], __spread(keys, [parsedKey.value]));
11704
11717
  }
11705
11718
  return keys;
11706
11719
  }
@@ -12741,11 +12754,15 @@ var DatoGridFilterComponent = /** @class */ (function () {
12741
12754
  return this.columnValues.filter(function (value) { return !includedSet.has(value); });
12742
12755
  };
12743
12756
  DatoGridFilterComponent.prototype.buildFilter = function () {
12757
+ var _this = this;
12744
12758
  var _a = this.filterForm.value, byValue = _a.byValue, conditional = _a.conditional;
12745
12759
  var filter = {};
12746
12760
  filter.pivotKeys = this.pivotKeys;
12747
12761
  if (this.pivotColumn) {
12748
- filter.pivotFields = this.getPivotFields(this.pivotColumn.getParent());
12762
+ filter.pivotFieldsMap = this.getPivotFields(this.pivotColumn.getParent()).reduce(function (fieldMap, field, index) {
12763
+ fieldMap[field] = _this.pivotKeys[index];
12764
+ return fieldMap;
12765
+ }, {});
12749
12766
  }
12750
12767
  if (this.filterSections.Conditional) {
12751
12768
  this.setConditionalFilter(filter, conditional);
@@ -13081,10 +13098,11 @@ var DatoGridFilterComponent = /** @class */ (function () {
13081
13098
  DatoGridFilterComponent.prototype.getPivotFields = function (parent, fields) {
13082
13099
  if (fields === void 0) { fields = []; }
13083
13100
  var grandParent = parent.getParent();
13101
+ var headerClass = parent.getOriginalColumnGroup().getColGroupDef().headerClass;
13084
13102
  if (grandParent) {
13085
13103
  this.getPivotFields(grandParent, fields);
13086
13104
  }
13087
- fields.push(parent.getOriginalColumnGroup().getColGroupDef().headerClass);
13105
+ headerClass && fields.push(headerClass[0]);
13088
13106
  return fields;
13089
13107
  };
13090
13108
  DatoGridFilterComponent.ctorParameters = function () { return [
@@ -14661,7 +14679,7 @@ var GridService = /** @class */ (function () {
14661
14679
  GridService.prototype.initPivotSecondaryColsProcess = function (_a) {
14662
14680
  var gridOptions = _a.gridOptions;
14663
14681
  gridOptions.processSecondaryColDef = function (colDef) {
14664
- var api = colDef.headerComponentParams.gridQuery.api;
14682
+ var api = colDef.headerComponentParams && colDef.headerComponentParams.gridQuery.api;
14665
14683
  if (api) {
14666
14684
  var valueColumns = colDef.headerComponentParams.gridQuery.api.columns.getValueColumns();
14667
14685
  var originalColDef = valueColumns
@@ -14678,17 +14696,40 @@ var GridService = /** @class */ (function () {
14678
14696
  }
14679
14697
  }
14680
14698
  if (colDef.pivotKeys) {
14681
- colDef.pivotKeys = colDef.pivotKeys.map(function (key) { return JSON.parse(key).value; });
14699
+ colDef.pivotKeys = colDef.pivotKeys.map(function (key) {
14700
+ var parsedKey = tryParsePivotValue(key);
14701
+ return (parsedKey && parsedKey.value) || '';
14702
+ });
14682
14703
  }
14683
14704
  };
14684
14705
  gridOptions.processSecondaryColGroupDef = function (colGroupDef) {
14685
14706
  if (colGroupDef.headerName) {
14686
- var _a = JSON.parse(colGroupDef.headerName), field = _a.field, value = _a.value;
14687
- colGroupDef.headerClass = field;
14688
- colGroupDef.headerName = value;
14707
+ var parsedValue = tryParsePivotValue(colGroupDef.headerName);
14708
+ if (parsedValue) {
14709
+ var field = parsedValue.field, value = parsedValue.value;
14710
+ colGroupDef.headerClass = [field];
14711
+ colGroupDef.headerName = value;
14712
+ if (colGroupDef.children && colGroupDef.children.length > 1) {
14713
+ colGroupDef.headerClass.push('group-pivot-cell');
14714
+ }
14715
+ }
14716
+ }
14717
+ else if (colGroupDef.children) {
14718
+ var _a = __read(colGroupDef.children, 1), colChild = _a[0];
14719
+ var pivotTotalColumnIds = colChild && colChild.pivotTotalColumnIds;
14720
+ if (pivotTotalColumnIds && pivotTotalColumnIds.length > 0) {
14721
+ colGroupDef.headerClass = ['total-pivot-cell'];
14722
+ colGroupDef.headerName = 'Total';
14723
+ }
14724
+ }
14725
+ else {
14726
+ colGroupDef.headerClass = ['empty-pivot-header'];
14689
14727
  }
14690
14728
  if (colGroupDef.pivotKeys) {
14691
- colGroupDef.pivotKeys = colGroupDef.pivotKeys.map(function (key) { return JSON.parse(key).value; });
14729
+ colGroupDef.pivotKeys = colGroupDef.pivotKeys.map(function (key) {
14730
+ var parsedKey = tryParsePivotValue(key);
14731
+ return (parsedKey && parsedKey.value) || '';
14732
+ });
14692
14733
  }
14693
14734
  };
14694
14735
  };
@@ -14701,7 +14742,8 @@ var GridService = /** @class */ (function () {
14701
14742
  for (var pivotColumns_1 = __values(pivotColumns), pivotColumns_1_1 = pivotColumns_1.next(); !pivotColumns_1_1.done; pivotColumns_1_1 = pivotColumns_1.next()) {
14702
14743
  var col = pivotColumns_1_1.value;
14703
14744
  var field = col.getColDef().field;
14704
- mappedValues[field] = JSON.stringify({ field: field, value: currentValue[field] });
14745
+ var pivotValue = { field: field, value: currentValue[field] };
14746
+ mappedValues[field] = JSON.stringify(pivotValue);
14705
14747
  }
14706
14748
  }
14707
14749
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
@@ -15229,7 +15271,7 @@ var DatoGridControllerComponent = /** @class */ (function () {
15229
15271
  this.gridService.setRows(data);
15230
15272
  };
15231
15273
  DatoGridControllerComponent.prototype.onFilterChanged = function () {
15232
- return this.gridQuery.selectFilter();
15274
+ return this.gridQuery.filterChanged();
15233
15275
  };
15234
15276
  DatoGridControllerComponent.prototype.onSortChanged = function () {
15235
15277
  return this.gridQuery.selectSort();