@datarailsshared/dr_renderer 1.2.365 → 1.2.366

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.
@@ -20,7 +20,7 @@ jobs:
20
20
  name: Prepare publish version
21
21
  command: |
22
22
  postfix=""
23
- if [[ "${CIRCLE_BRANCH}" != prod ]] ; then
23
+ if [[ "${CIRCLE_BRANCH}" != master ]] ; then
24
24
  postfix="-$CIRCLE_BRANCH"
25
25
  fi
26
26
 
@@ -70,7 +70,7 @@ workflows:
70
70
  filters:
71
71
  branches:
72
72
  only:
73
- - /prod.*/
73
+ - /master/
74
74
  - /tigers/
75
75
  - /bratans/
76
76
  - /dragons/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.365",
3
+ "version": "1.2.366",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -0,0 +1,7 @@
1
+ function backendSortingKeysAreNotEmpty(keys) {
2
+ return !!keys && (!!keys.row_keys && !!keys.row_keys.length || !!keys.col_keys && !!keys.col_keys.length);
3
+ }
4
+
5
+ module.exports = {
6
+ backendSortingKeysAreNotEmpty: backendSortingKeysAreNotEmpty,
7
+ }
@@ -12,6 +12,10 @@ let initDRPivotTable = function($, window, document) {
12
12
  document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
13
13
  // const numberOfRows = 500; // change to activate the handsontable when num of rows bigger then this.
14
14
 
15
+ const isFlatKeyInPivotKeys = function(keys, flatKey) {
16
+ return keys.some(key => key.join(delim) === flatKey);
17
+ };
18
+
15
19
  DRPivotData = (function(superClass) {
16
20
  extend(DRPivotData, superClass);
17
21
 
@@ -91,6 +95,7 @@ let initDRPivotTable = function($, window, document) {
91
95
 
92
96
  DRPivotData.prototype.arrSort = function(attrs) {
93
97
  var a, sortersArr;
98
+ const sortByValueAttrs = this.sortByValueAttrs;
94
99
  sortersArr = (function() {
95
100
  var l, len1, results;
96
101
  results = [];
@@ -100,11 +105,21 @@ let initDRPivotTable = function($, window, document) {
100
105
  }
101
106
  return results;
102
107
  }).call(this);
108
+
103
109
  return function(a, b) {
104
110
  var comparison, i, sorter;
105
111
  for (i in sortersArr) {
106
- sorter = sortersArr[i];
107
- comparison = sorter(a[i], b[i]);
112
+ const index = parseInt(i);
113
+ sorter = sortersArr[index];
114
+ if (sortByValueAttrs.indexOf(attrs[index]) !== -1) {
115
+
116
+ // For case current Field attrs[index] is sorted by value we are concatenating values passed to sorter function
117
+ // Concatenation is done from first field in a block (first axis or first series) until current field index.
118
+ // Cause for this case sorting will be as list of these concatenated strings (which is prepared in getSortingByValueOrderList)
119
+ comparison = sorter(a.slice(0, index + 1).join(','), b.slice(0, index + 1).join(','));
120
+ } else {
121
+ comparison = sorter(a[index], b[index]);
122
+ }
108
123
  if (comparison !== 0) {
109
124
  return comparison;
110
125
  }
@@ -143,7 +158,15 @@ let initDRPivotTable = function($, window, document) {
143
158
  return key;
144
159
  };
145
160
 
161
+ DRPivotData.prototype.getInsight = function(colKey, rowKey) {
162
+ const insightInfo = _.find(this.insights, insight => insight.colKey === colKey && insight.rowKey === rowKey);
163
+ return _.get(insightInfo, 'insight', null);
164
+ }
165
+
146
166
  DRPivotData.prototype.processRecord = function(record, useTotalsCalculation) {
167
+ const insight = record.insight;
168
+ delete record.insight;
169
+
147
170
  if (useTotalsCalculation) {
148
171
  if (!this.notFirst) {
149
172
  this.keysLength = _.filter(_.keys(record), key => !_.includes(['data_types', 'formats', 'values_formats'], key)).length - 1;
@@ -180,10 +203,10 @@ let initDRPivotTable = function($, window, document) {
180
203
  let flatColKey = colKey.join(delim);
181
204
 
182
205
  if (this.keysLength === rowKey.length + colKey.length) {
183
- if (!this.rowKeys.some(rKey => rKey.join(delim) === flatRowKey)) {
206
+ if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.rowKeys, flatRowKey)) {
184
207
  this.rowKeys.push(rowKey);
185
208
  }
186
- if (!this.colKeys.some(cKey => cKey.join(delim) === flatColKey)) {
209
+ if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.colKeys, flatColKey)) {
187
210
  this.colKeys.push(colKey);
188
211
  }
189
212
  }
@@ -207,6 +230,14 @@ let initDRPivotTable = function($, window, document) {
207
230
  this.tree[flatRowKey][flatColKey] = this.aggregator(this, rowKey, colKey);
208
231
  this.tree[flatRowKey][flatColKey].push(record);
209
232
  }
233
+
234
+ if (insight && (flatRowKey || flatColKey)) {
235
+ this.insights.push({
236
+ colKey: flatColKey,
237
+ rowKey: flatRowKey,
238
+ insight: insight,
239
+ });
240
+ }
210
241
  return;
211
242
  }
212
243
 
@@ -230,6 +261,19 @@ let initDRPivotTable = function($, window, document) {
230
261
  };
231
262
  })(this));
232
263
 
264
+ if (insight) {
265
+ const flatRowKeyForInsight = rowKey.join(delim);
266
+ const flatColKeyForInsight = colKey.join(delim);
267
+
268
+ if (flatRowKeyForInsight || flatColKeyForInsight) {
269
+ this.insights.push({
270
+ colKey: flatColKeyForInsight,
271
+ rowKey: flatRowKeyForInsight,
272
+ insight: insight,
273
+ });
274
+ }
275
+ }
276
+
233
277
  m = rowKey.length - 1;
234
278
  n = colKey.length - 1;
235
279
  if (m < 0 || n < 0) {
@@ -471,8 +515,11 @@ let initDRPivotTable = function($, window, document) {
471
515
  return resultsArr;
472
516
  } else {
473
517
  let tooMuch = false;
474
- if (pvtData && (pvtData.rowKeys.length > 1000 || pvtData.colKeys.length > 500) &&
475
- (!opts.show_more_function_cols || !opts.show_more_function_cols)) {
518
+ const show_more_than_thousand_rows = _.get(opts, 'chartOptions.table_options.show_more_than_thousand_rows', false);
519
+ if (pvtData &&
520
+ (pvtData.rowKeys.length > 1000 || pvtData.colKeys.length > 500) &&
521
+ (!opts.show_more_function_cols || !opts.show_more_function_cols) &&
522
+ !show_more_than_thousand_rows) {
476
523
  pvtData.rowKeys = [];
477
524
  pvtData.colKeys = [];
478
525
  tooMuch = true;
@@ -876,7 +923,7 @@ let initDRPivotTable = function($, window, document) {
876
923
  return string_val;
877
924
  };
878
925
 
879
- processKeys = function(keysArr, className, dimention, attrs) {
926
+ processKeys = function(keysArr, className, dimention, attrs, formattedKeys) {
880
927
  for (let i = 0; i < keysArr.length; i++) {
881
928
  const additionalField = _.find(additionalFieldsList, {key: keysArr[i][0]})
882
929
 
@@ -897,7 +944,7 @@ let initDRPivotTable = function($, window, document) {
897
944
  lastCol = 0;
898
945
  }
899
946
  rMark = [];
900
- th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[0][0]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, 0)));
947
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(formattedKeys[0][0]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, 0)));
901
948
  key = [];
902
949
  key.push(keysArr[0][0]);
903
950
  nodePos = 0;
@@ -917,7 +964,7 @@ let initDRPivotTable = function($, window, document) {
917
964
  rMark[0] = node;
918
965
  c = 1;
919
966
  while (c <= lastCol) {
920
- th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[0][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, c)));
967
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(formattedKeys[0][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, c)));
921
968
  key = key.slice();
922
969
  key.push(keysArr[0][c]);
923
970
  ++nodePos;
@@ -983,7 +1030,7 @@ let initDRPivotTable = function($, window, document) {
983
1030
  }
984
1031
 
985
1032
 
986
- th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[r][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, r, c)));
1033
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(formattedKeys[r][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, r, c)));
987
1034
  ++nodePos;
988
1035
  node = {
989
1036
  node: nodePos,
@@ -2407,7 +2454,7 @@ let initDRPivotTable = function($, window, document) {
2407
2454
  return Array.from(wrapper.querySelectorAll(selectString));
2408
2455
  }
2409
2456
 
2410
- main = function(rowAttrs, rowKeys, colAttrs, colKeys) {
2457
+ main = function(rowAttrs, rowKeys, colAttrs, colKeys, pivotData) {
2411
2458
  var c,rowspan, colHeaderCols, colHeaderHeaders, colHeaders, h, k, l, len, len1, result, rowHeaderHeaders, rowHeaderRows, rowHeaders, tbody, thead, tr;
2412
2459
  rowHeaders = [];
2413
2460
  colHeaders = [];
@@ -2416,10 +2463,12 @@ let initDRPivotTable = function($, window, document) {
2416
2463
  colHeaderHeaders = [];
2417
2464
  colHeaderCols = [];
2418
2465
  if (rowAttrs.length > 0 && rowKeys.length > 0) {
2419
- rowHeaders = processKeys(rowKeys, "pvtRowLabel", 'rows', rowAttrs);
2466
+ const formattedKeys = pivotData.getFormattedRowKeys(rowKeys);
2467
+ rowHeaders = processKeys(rowKeys, "pvtRowLabel", 'rows', rowAttrs, formattedKeys);
2420
2468
  }
2421
2469
  if (colAttrs.length > 0 && colKeys.length > 0) {
2422
- colHeaders = processKeys(colKeys, "pvtColLabel", 'cols', colAttrs);
2470
+ const formattedKeys = pivotData.getFormattedColKeys(colKeys);
2471
+ colHeaders = processKeys(colKeys, "pvtColLabel", 'cols', colAttrs, formattedKeys);
2423
2472
  }
2424
2473
  var tableClasses = ['pvtTable'];
2425
2474
  if (opts.chartOptions.table_options.use_new_table_design) {
@@ -2564,7 +2613,7 @@ let initDRPivotTable = function($, window, document) {
2564
2613
 
2565
2614
  return wrapper;
2566
2615
  };
2567
- return main(rowAttrs, rowKeys, colAttrs, colKeys);
2616
+ return main(rowAttrs, rowKeys, colAttrs, colKeys, pivotData);
2568
2617
  };
2569
2618
  // $.pivotUtilities.subtotal_renderers = SubtotalRenderer;
2570
2619
  $.pivotUtilities.subtotal_renderers = NovixRenderer;