@datorama/core 21.4.0-rc.5 → 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.
@@ -10010,6 +10010,16 @@ function getColField(colDef) {
10010
10010
  const { field, showRowGroup, pivotValueColumn } = colDef;
10011
10011
  return pivotValueColumn ? pivotValueColumn.getColId() : field || showRowGroup;
10012
10012
  }
10013
+ function tryParsePivotValue(str) {
10014
+ let value;
10015
+ try {
10016
+ value = JSON.parse(str);
10017
+ }
10018
+ catch (e) {
10019
+ console.error(`Can't parse ${str} from JSON`);
10020
+ }
10021
+ return value;
10022
+ }
10013
10023
 
10014
10024
  let GridQuery = class GridQuery extends Query {
10015
10025
  constructor(store) {
@@ -10392,17 +10402,9 @@ function validateFilter({ row, api }, activeFilters) {
10392
10402
  */
10393
10403
  function getRowPivotKeys(childrenMapped, keys = []) {
10394
10404
  const key = Object.keys(childrenMapped)[0];
10395
- let parsedKey;
10396
- try {
10397
- parsedKey = JSON.parse(key);
10398
- }
10399
- catch (e) {
10400
- console.error(`Can't parse ${key} from JSON`);
10401
- }
10402
- finally {
10403
- if (parsedKey) {
10404
- keys = getRowPivotKeys(childrenMapped[key], [...keys, parsedKey.value]);
10405
- }
10405
+ const parsedKey = tryParsePivotValue(key);
10406
+ if (parsedKey) {
10407
+ keys = getRowPivotKeys(childrenMapped[key], [...keys, parsedKey.value]);
10406
10408
  }
10407
10409
  return keys;
10408
10410
  }
@@ -13110,16 +13112,22 @@ let GridService = class GridService {
13110
13112
  }
13111
13113
  }
13112
13114
  if (colDef.pivotKeys) {
13113
- colDef.pivotKeys = colDef.pivotKeys.map(key => JSON.parse(key).value);
13115
+ colDef.pivotKeys = colDef.pivotKeys.map(key => {
13116
+ const parsedKey = tryParsePivotValue(key);
13117
+ return (parsedKey && parsedKey.value) || '';
13118
+ });
13114
13119
  }
13115
13120
  };
13116
13121
  gridOptions.processSecondaryColGroupDef = (colGroupDef) => {
13117
13122
  if (colGroupDef.headerName) {
13118
- const { field, value } = JSON.parse(colGroupDef.headerName);
13119
- colGroupDef.headerClass = [field];
13120
- colGroupDef.headerName = value;
13121
- if (colGroupDef.children && colGroupDef.children.length > 1) {
13122
- colGroupDef.headerClass.push('group-pivot-cell');
13123
+ const parsedValue = tryParsePivotValue(colGroupDef.headerName);
13124
+ if (parsedValue) {
13125
+ const { field, value } = parsedValue;
13126
+ colGroupDef.headerClass = [field];
13127
+ colGroupDef.headerName = value;
13128
+ if (colGroupDef.children && colGroupDef.children.length > 1) {
13129
+ colGroupDef.headerClass.push('group-pivot-cell');
13130
+ }
13123
13131
  }
13124
13132
  }
13125
13133
  else if (colGroupDef.children) {
@@ -13134,7 +13142,10 @@ let GridService = class GridService {
13134
13142
  colGroupDef.headerClass = ['empty-pivot-header'];
13135
13143
  }
13136
13144
  if (colGroupDef.pivotKeys) {
13137
- colGroupDef.pivotKeys = colGroupDef.pivotKeys.map(key => JSON.parse(key).value);
13145
+ colGroupDef.pivotKeys = colGroupDef.pivotKeys.map(key => {
13146
+ const parsedKey = tryParsePivotValue(key);
13147
+ return (parsedKey && parsedKey.value) || '';
13148
+ });
13138
13149
  }
13139
13150
  };
13140
13151
  }
@@ -13144,7 +13155,8 @@ let GridService = class GridService {
13144
13155
  const mappedValues = Object.assign({}, currentValue);
13145
13156
  for (const col of pivotColumns) {
13146
13157
  const field = col.getColDef().field;
13147
- mappedValues[field] = JSON.stringify({ field, value: currentValue[field] });
13158
+ const pivotValue = { field, value: currentValue[field] };
13159
+ mappedValues[field] = JSON.stringify(pivotValue);
13148
13160
  }
13149
13161
  return mappedValues;
13150
13162
  });