@datarailsshared/dr_renderer 1.2.368 → 1.2.370

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.368",
3
+ "version": "1.2.370",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -1547,7 +1547,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1547
1547
  const chart_series = [];
1548
1548
  const row_n_keys = pivotData.getRowKeys();
1549
1549
  const col_n_keys = pivotData.getColKeys();
1550
- const rows_by_cols = pivotData.rowKeysByCols;
1550
+ const rows_by_cols = pivotData.getRowKeysByCols();
1551
1551
 
1552
1552
  let resultObject = {
1553
1553
  data: [],
@@ -3584,7 +3584,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3584
3584
  ? opts.chartOptions
3585
3585
  : highchartsRenderer.getDefaultValueForChart(highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN);
3586
3586
 
3587
- pivotData.colKeys = lodash.map(lodash.keys(pivotData.colTotals), key => [key]);
3587
+ if (!highchartsRenderer.isSortingOnBackendEnabled) {
3588
+ pivotData.colKeys = lodash.map(lodash.keys(pivotData.colTotals), key => [key]);
3589
+ }
3588
3590
 
3589
3591
  chartOptions.chart = {
3590
3592
  type: 'waterfall',
@@ -5412,6 +5414,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5412
5414
  widgetOptions.pivot.chartOptions = widgetOptions.options;
5413
5415
  widgetOptions.pivot.chartRender = highchartsRenderer.getChartRendererFunction(widgetOptions.pivot.chartType, drilldownFunc, drillDownListFunc, insightsTooltipFunc, trackUserInsightsTooltipFunc);
5414
5416
 
5417
+ if (highchartsRenderer.isSortingOnBackendEnabled) return;
5415
5418
  // TODO: remove this logic after BE sort is implemented
5416
5419
  // it is required to do sort by totals for comparative analysis - we need to change deltas if columns swaped vice versa
5417
5420
  const isTwoColumnComparisonWidget = widgetOptions.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN
@@ -6548,25 +6551,29 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6548
6551
  element_type: 'input',
6549
6552
  value_name: 'low',
6550
6553
  element_label: 'Low %',
6551
- default_value: 10
6554
+ default_value: 10,
6555
+ value_type: 'number'
6552
6556
  },
6553
6557
  {
6554
6558
  element_type: 'input',
6555
6559
  value_name: 'medium',
6556
6560
  element_label: 'Medium %',
6557
- default_value: 50
6561
+ default_value: 50,
6562
+ value_type: 'number'
6558
6563
  },
6559
6564
  {
6560
6565
  element_type: 'input',
6561
6566
  value_name: 'high',
6562
6567
  element_label: 'High %',
6563
- default_value: 90
6568
+ default_value: 90,
6569
+ value_type: 'number'
6564
6570
  },
6565
6571
  {
6566
6572
  element_type: 'input',
6567
6573
  value_name: 'max',
6568
6574
  element_label: 'Max',
6569
- default_value: 1000
6575
+ default_value: 1000,
6576
+ value_type: 'number'
6570
6577
  }
6571
6578
  ]
6572
6579
  },
@@ -8856,6 +8863,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8856
8863
  return res;
8857
8864
  };
8858
8865
 
8866
+ highchartsRenderer.replaceSortingKeysWithMappedValues = function(keys, invertedDateStringMap, widgetFields) {
8867
+ if (!keys || !invertedDateStringMap) {
8868
+ return;
8869
+ }
8870
+ const replaceNestedKeys = (nestedKeys) => {
8871
+ for (let i = 0; i < nestedKeys.length; i++) {
8872
+ if (Array.isArray(nestedKeys[i])) {
8873
+ replaceNestedKeys(nestedKeys[i]);
8874
+ } else if (invertedDateStringMap[nestedKeys[i]] && widgetFields[i] && widgetFields[i].type === 'Date') {
8875
+ nestedKeys[i] = invertedDateStringMap[nestedKeys[i]];
8876
+ }
8877
+ }
8878
+ };
8879
+
8880
+ for (let i = 0; i < keys.length; i++) {
8881
+ replaceNestedKeys(keys[i]);
8882
+ }
8883
+ }
8884
+
8859
8885
  highchartsRenderer.getWidgetDataSorters = function (res, widget, defaultDateFormat) {
8860
8886
  const isFormattingDatesAsOtherAxisTypes = highchartsRenderer.isFormattingDatesAsOtherAxisTypes();
8861
8887
  let sorters;
@@ -8896,7 +8922,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8896
8922
  row.val_not_convert = highchartsRenderer.check_values_not_for_convert(widget, row.name);
8897
8923
  });
8898
8924
  }
8899
-
8925
+
8900
8926
  if (datesFields.length > 0) {
8901
8927
  const invertedDateStringMap = {};
8902
8928
  lodash.forEach(res, function (element) {
@@ -8920,25 +8946,15 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8920
8946
  }
8921
8947
  }
8922
8948
  }
8923
- });
8949
+ if (highchartsRenderer.sortHasBeenDoneOnBE(lodash.get(widget, 'pivot.keysObject')) && !isFormattingDatesAsOtherAxisTypes) {
8950
+ const keysObject = lodash.get(widget, 'pivot.keysObject');
8924
8951
 
8925
- if (highchartsRenderer.sortHasBeenDoneOnBE(lodash.get(widget, 'pivot.keysObject')) && !isFormattingDatesAsOtherAxisTypes) {
8926
- lodash.forEach(['col_keys', 'row_keys'], (keysListName, index) => {
8927
- const widgetFields = index ? widget.rows : widget.cols;
8928
- const uniqueFormattedKeysList = [];
8929
- lodash.forEach(widget.pivot.keysObject[keysListName], subKeysList => {
8930
- lodash.forEach(subKeysList, (key, index) => {
8931
- if (widgetFields[index] && widgetFields[index].type === 'Date') {
8932
- subKeysList[index] = invertedDateStringMap[key] || key;
8933
- }
8934
- });
8935
- if (!lodash.find(uniqueFormattedKeysList, formattedSubKeys => lodash.isEqual(formattedSubKeys, subKeysList))) {
8936
- uniqueFormattedKeysList.push(subKeysList);
8937
- }
8952
+ lodash.forEach(['col_keys', 'row_keys', 'row_keys_by_cols'], (keysListName) => {
8953
+ const widgetFields = keysListName === 'col_keys' ? widget.cols : widget.rows;
8954
+ highchartsRenderer.replaceSortingKeysWithMappedValues(lodash.get(keysObject, keysListName), invertedDateStringMap, widgetFields);
8938
8955
  });
8939
- widget.pivot.keysObject[keysListName] = uniqueFormattedKeysList;
8940
- });
8941
- }
8956
+ }
8957
+ });
8942
8958
  }
8943
8959
 
8944
8960
  if (!highchartsRenderer.sortHasBeenDoneOnBE(lodash.get(widget, 'pivot.keysObject'))) {
@@ -8976,7 +8992,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8976
8992
  var rowsAndCols = [];
8977
8993
  rowsAndCols = widget.rows.concat(widget.cols);
8978
8994
 
8979
- if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
8995
+ if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN && !highchartsRenderer.sortHasBeenDoneOnBE(lodash.get(widget, 'pivot.keysObject'))) {
8980
8996
 
8981
8997
  // if it is breakdown widget - redefine sorting according to breakdown_options
8982
8998
  // TODO: remove this when BE sort will be implemented (FE subtickets for story DR-18469)
package/src/pivottable.js CHANGED
@@ -671,6 +671,7 @@ let initPivotTable = function($, window, document) {
671
671
  this.getAggregator = bind(this.getAggregator, this);
672
672
  this.getRowKeys = bind(this.getRowKeys, this);
673
673
  this.getColKeys = bind(this.getColKeys, this);
674
+ this.getRowKeysByCols = bind(this.getRowKeysByCols, this);
674
675
  this.sortKeys = bind(this.sortKeys, this);
675
676
  this.arrSort = bind(this.arrSort, this);
676
677
  this.input = input;
@@ -693,7 +694,7 @@ let initPivotTable = function($, window, document) {
693
694
  if (this.isKeysSortingDoneOnBackendSide) {
694
695
  this.rowKeys = opts.keysObject.row_keys;
695
696
  this.colKeys = opts.keysObject.col_keys;
696
- // TODO: add also for breakdown sort object when BE story is ready.
697
+ this.rowKeysByCols = opts.keysObject.row_keys_by_cols;
697
698
  } else {
698
699
  this.rowKeys = [];
699
700
  this.colKeys = [];
@@ -883,6 +884,10 @@ let initPivotTable = function($, window, document) {
883
884
  return this.rowKeys;
884
885
  };
885
886
 
887
+ PivotData.prototype.getRowKeysByCols = function() {
888
+ return this.rowKeysByCols;
889
+ };
890
+
886
891
  PivotData.prototype.processRecord = function(record) {
887
892
  var colKey, flatColKey, flatRowKey, l, len1, len2, n, ref, ref1, ref2, ref3, rowKey, x;
888
893
  colKey = [];
@@ -5521,4 +5521,134 @@ describe('highcharts_renderer', () => {
5521
5521
  expect(highchartsRenderer.getColsInFormatterContext(context, pivotData)).toEqual(name2);
5522
5522
  });
5523
5523
  });
5524
+
5525
+
5526
+ describe('Function replaceSortingKeysWithMappedValues', () => {
5527
+ it('should replace sorting keys with mapped values for Date fields', () => {
5528
+ const keysObject = {
5529
+ col_keys: [
5530
+ [1640995200],
5531
+ [1648684800],
5532
+ [1667174400]
5533
+ ],
5534
+ row_keys: [],
5535
+ row_keys_by_cols: [
5536
+ [
5537
+ ["Other Income"],
5538
+ ["Other Expense"],
5539
+ ["Income"],
5540
+ ["Expenses"],
5541
+ ["Cost of Goods Sold"]
5542
+ ]
5543
+ ]
5544
+ };
5545
+ const invertedDateStringMap = {
5546
+ 1640995200: '2022-01-01',
5547
+ 1648684800: '2022-03-29',
5548
+ 1667174400: '2023-03-01'
5549
+ };
5550
+ const widget = {
5551
+ cols: [{ type: 'Date' }],
5552
+ rows: [{ type: 'NotDate' }],
5553
+ pivot: {
5554
+ keysObject: keysObject
5555
+ }
5556
+ };
5557
+
5558
+ highchartsRenderer.replaceSortingKeysWithMappedValues(keysObject.col_keys, invertedDateStringMap, widget.cols);
5559
+ highchartsRenderer.replaceSortingKeysWithMappedValues(keysObject.row_keys, invertedDateStringMap, widget.rows);
5560
+ highchartsRenderer.replaceSortingKeysWithMappedValues(keysObject.row_keys_by_cols, invertedDateStringMap, widget.rows);
5561
+
5562
+ expect(keysObject).toEqual({
5563
+ col_keys: [
5564
+ ['2022-01-01'],
5565
+ ['2022-03-29'],
5566
+ ['2023-03-01']
5567
+ ],
5568
+ row_keys: [],
5569
+ row_keys_by_cols: [
5570
+ [
5571
+ ['Other Income'],
5572
+ ['Other Expense'],
5573
+ ['Income'],
5574
+ ['Expenses'],
5575
+ ['Cost of Goods Sold']
5576
+ ]
5577
+ ]
5578
+ });
5579
+ });
5580
+
5581
+ it('should not replace sorting keys for non-Date fields', () => {
5582
+ const keysObject = {
5583
+ col_keys: [
5584
+ [1640995200],
5585
+ [1648684800],
5586
+ [1667174400]
5587
+ ],
5588
+ row_keys: [],
5589
+ row_keys_by_cols: [
5590
+ [
5591
+ ["Other Income"],
5592
+ ["Other Expense"],
5593
+ ["Income"],
5594
+ ["Expenses"],
5595
+ ["Cost of Goods Sold"]
5596
+ ]
5597
+ ]
5598
+ };
5599
+ const invertedDateStringMap = {
5600
+ 1640995200: '2022-01-01',
5601
+ 1648684800: '2022-03-29',
5602
+ 1667174400: '2023-03-01'
5603
+ };
5604
+ const widget = {
5605
+ cols: [{ type: 'NotDate' }],
5606
+ rows: [{ type: 'NotDate' }],
5607
+ pivot: {
5608
+ keysObject: keysObject
5609
+ }
5610
+ };
5611
+
5612
+ highchartsRenderer.replaceSortingKeysWithMappedValues(keysObject.col_keys, invertedDateStringMap, widget.cols);
5613
+ highchartsRenderer.replaceSortingKeysWithMappedValues(keysObject.row_keys, invertedDateStringMap, widget.rows);
5614
+ highchartsRenderer.replaceSortingKeysWithMappedValues(keysObject.row_keys_by_cols, invertedDateStringMap, widget.rows);
5615
+
5616
+ expect(keysObject).toEqual({
5617
+ col_keys: [
5618
+ [1640995200],
5619
+ [1648684800],
5620
+ [1667174400]
5621
+ ],
5622
+ row_keys: [],
5623
+ row_keys_by_cols: [
5624
+ [
5625
+ ["Other Income"],
5626
+ ["Other Expense"],
5627
+ ["Income"],
5628
+ ["Expenses"],
5629
+ ["Cost of Goods Sold"]
5630
+ ]
5631
+ ]
5632
+ });
5633
+ });
5634
+
5635
+ it('should handle null or undefined keysObject', () => {
5636
+ const invertedDateStringMap = {
5637
+ 1640995200: '2022-01-01',
5638
+ 1648684800: '2022-03-29',
5639
+ 1667174400: '2023-03-01'
5640
+ };
5641
+ const widget = {
5642
+ cols: [{ type: 'Date' }],
5643
+ rows: [{ type: 'NotDate' }],
5644
+ pivot: {
5645
+ keysObject: null
5646
+ }
5647
+ };
5648
+
5649
+ highchartsRenderer.replaceSortingKeysWithMappedValues(null, invertedDateStringMap, widget.cols);
5650
+ highchartsRenderer.replaceSortingKeysWithMappedValues(null, invertedDateStringMap, widget.rows);
5651
+ highchartsRenderer.replaceSortingKeysWithMappedValues(null, invertedDateStringMap, widget.rows);
5652
+ });
5653
+ });
5524
5654
  });