dtable-statistic 4.0.11 → 4.0.12

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.
@@ -6,11 +6,16 @@ import { isCellValueChanged } from './cell-value';
6
6
  import { getSelectColumnOptions, getDateColumnFormat } from './column';
7
7
  import { getKnownCreatorByEmail } from './collaborator';
8
8
  import { EMPTY_NAME } from '../constants';
9
+ var isEmptyName = function isEmptyName(title) {
10
+ return title === null || title === '';
11
+ };
9
12
  var isSummaryDateColumn = function isSummaryDateColumn(summaryColumn) {
10
13
  if (!summaryColumn) return false;
11
14
  var type = summaryColumn.type;
12
15
  return type !== CellType.LINK && isDateColumn(summaryColumn);
13
16
  };
17
+
18
+ // eslint-disable-next-line
14
19
  var getTableValueDisplayName = function getTableValueDisplayName(value, column) {
15
20
  var _ref = column || {},
16
21
  type = _ref.type,
@@ -93,8 +98,7 @@ var getValidValueForColumn = function getValidValueForColumn(column, value) {
93
98
  };
94
99
  var getUpdatedOneDimensionStatisticTableResultToTable = function getUpdatedOneDimensionStatisticTableResultToTable(_ref3) {
95
100
  var updateTable = _ref3.updateTable,
96
- statisticalResult = _ref3.statisticalResult,
97
- t = _ref3.t;
101
+ statisticalResult = _ref3.statisticalResult;
98
102
  var pivotResult = statisticalResult.pivotResult,
99
103
  groupbyColumn = statisticalResult.groupbyColumn,
100
104
  statisticTableColumns = statisticalResult.statisticTableColumns;
@@ -117,8 +121,9 @@ var getUpdatedOneDimensionStatisticTableResultToTable = function getUpdatedOneDi
117
121
  // updated rows
118
122
  pivot_rows.forEach(function (item) {
119
123
  var name = item.name,
124
+ original_name = item.original_name,
120
125
  total = item.total;
121
- var groupName = name === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(name, groupbyColumn);
126
+ var groupName = isEmptyName(original_name) ? intl.get(EMPTY_NAME) : name;
122
127
  var row = tableRows.find(function (row) {
123
128
  return row[nameColumn.key] === groupName;
124
129
  });
@@ -171,10 +176,11 @@ var getUpdatedOneDimensionStatisticTableResultToTable = function getUpdatedOneDi
171
176
  var nameColumnKey = nameColumn.key;
172
177
  pivot_rows.forEach(function (item) {
173
178
  var name = item.name,
179
+ original_name = item.original_name,
174
180
  total = item.total;
175
- var groupName = name === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(name, groupbyColumn);
181
+ var groupName = isEmptyName(original_name) ? intl.get(EMPTY_NAME) : name;
176
182
  var row = tableRows.find(function (row) {
177
- return row[nameColumnKey] === name;
183
+ return row[nameColumnKey] === groupName;
178
184
  });
179
185
  if (row) {
180
186
  var updateRow = {};
@@ -216,11 +222,9 @@ var getUpdatedOneDimensionStatisticTableResultToTable = function getUpdatedOneDi
216
222
  };
217
223
  var getUpdatedTwoDimensionStatisticTableResultToTable = function getUpdatedTwoDimensionStatisticTableResultToTable(_ref4) {
218
224
  var updateTable = _ref4.updateTable,
219
- statisticalResult = _ref4.statisticalResult,
220
- t = _ref4.t;
225
+ statisticalResult = _ref4.statisticalResult;
221
226
  var pivotResult = statisticalResult.pivotResult,
222
- groupbyColumn = statisticalResult.groupbyColumn,
223
- columnGroupbyColumn = statisticalResult.columnGroupbyColumn;
227
+ groupbyColumn = statisticalResult.groupbyColumn;
224
228
  var nameColumn = TableUtils.getTableColumnByName(updateTable, groupbyColumn.name);
225
229
  if (!nameColumn) return {};
226
230
  var pivot_rows = pivotResult.pivot_rows,
@@ -234,8 +238,9 @@ var getUpdatedTwoDimensionStatisticTableResultToTable = function getUpdatedTwoDi
234
238
 
235
239
  // updated columns
236
240
  Array.isArray(pivot_columns) && pivot_columns.forEach(function (item) {
237
- var key = item.key;
238
- var columnName = key === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(key, columnGroupbyColumn);
241
+ var key = item.key,
242
+ original_key = item.original_key;
243
+ var columnName = isEmptyName(original_key) ? intl.get(EMPTY_NAME) : key;
239
244
  columnMap[columnName] = TableUtils.getTableColumnByName(updateTable, columnName);
240
245
  });
241
246
  columnMap['total'] = TableUtils.getTableColumnByName(updateTable, intl.get('Total'));
@@ -244,9 +249,12 @@ var getUpdatedTwoDimensionStatisticTableResultToTable = function getUpdatedTwoDi
244
249
  var _loop = function _loop(i) {
245
250
  var pivotRow = pivot_rows[i];
246
251
  var name = pivotRow.name,
252
+ original_name = pivotRow.original_name,
247
253
  cells = pivotRow.cells,
248
254
  total = pivotRow.total;
249
- name = name === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(name, groupbyColumn);
255
+ if (isEmptyName(original_name)) {
256
+ name = intl.get(EMPTY_NAME);
257
+ }
250
258
  var nameColumnKey = nameColumn.key;
251
259
  var row = tableRows.find(function (row) {
252
260
  return row[nameColumnKey] === name;
@@ -259,15 +267,15 @@ var getUpdatedTwoDimensionStatisticTableResultToTable = function getUpdatedTwoDi
259
267
  var validTotalCellValue = getValidValueForColumn(totalColumn, total);
260
268
  if (totalColumn && isCellValueChanged(row[totalColumn.key], validTotalCellValue, totalColumn.type)) {
261
269
  updatedRow[totalColumn.key] = validTotalCellValue;
262
- oldRow = row[totalColumn.key];
270
+ oldRow[totalColumn.key] = row[totalColumn.key];
263
271
  }
264
272
  Object.keys(cells).forEach(function (key) {
265
- var columnName = key === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(key, columnGroupbyColumn);
273
+ var columnName = isEmptyName(key) ? intl.get(EMPTY_NAME) : key;
266
274
  var column = columnMap[columnName];
267
275
  var validCellValue = getValidValueForColumn(column, cells[key].total);
268
276
  if (column && isCellValueChanged(row[column.key], validCellValue, column.type)) {
269
277
  updatedRow[column.key] = validCellValue;
270
- oldRow = row[column.key];
278
+ oldRow[column.key] = row[column.key];
271
279
  }
272
280
  });
273
281
  if (Object.keys(updatedRow).length > 0) {
@@ -284,7 +292,7 @@ var getUpdatedTwoDimensionStatisticTableResultToTable = function getUpdatedTwoDi
284
292
  newRow[totalColumn.key] = getValidValueForColumn(totalColumn, name);
285
293
  }
286
294
  Object.keys(cells).forEach(function (key) {
287
- var columnName = key === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(key, columnGroupbyColumn);
295
+ var columnName = isEmptyName(key) ? intl.get(EMPTY_NAME) : key;
288
296
  var column = columnMap[columnName];
289
297
  if (column) {
290
298
  newRow[column.key] = getValidValueForColumn(column, cells[key].total);
@@ -307,6 +315,19 @@ var getUpdatedTwoDimensionStatisticTableResultToTable = function getUpdatedTwoDi
307
315
  };
308
316
 
309
317
  /**
318
+ * statisticalResult: {
319
+ * columnGroupbyColumn: null,
320
+ * groupbyColumn: null,
321
+ * pivotResult: {
322
+ * pivot_columns: [],
323
+ * pivot_rows: [
324
+ * { name: 'xxx', original_name: 'xxx', total }
325
+ * ]
326
+ * },
327
+ * statisticTableColumns: null,
328
+ * summaryColumn: null,
329
+ * }
330
+ *
310
331
  * @return {
311
332
  * columns: [
312
333
  * {
@@ -325,8 +346,7 @@ var getUpdatedTwoDimensionStatisticTableResultToTable = function getUpdatedTwoDi
325
346
  * }
326
347
  */
327
348
  export var exportStatisticToTable = function exportStatisticToTable(_ref5) {
328
- var statisticalResult = _ref5.statisticalResult,
329
- t = _ref5.t;
349
+ var statisticalResult = _ref5.statisticalResult;
330
350
  var pivotResult = statisticalResult.pivotResult,
331
351
  groupbyColumn = statisticalResult.groupbyColumn,
332
352
  columnGroupbyColumn = statisticalResult.columnGroupbyColumn;
@@ -336,19 +356,16 @@ export var exportStatisticToTable = function exportStatisticToTable(_ref5) {
336
356
  // two dimension table
337
357
  if (columnGroupbyColumn) {
338
358
  return getTwoDimensionStatisticTableResultToTable({
339
- statisticalResult: statisticalResult,
340
- t: t
359
+ statisticalResult: statisticalResult
341
360
  });
342
361
  }
343
362
  if (!Array.isArray(pivot_columns)) return {};
344
363
  return getOneDimensionStatisticTableResultToTable({
345
- statisticalResult: statisticalResult,
346
- t: t
364
+ statisticalResult: statisticalResult
347
365
  });
348
366
  };
349
367
  export var getOneDimensionStatisticTableResultToTable = function getOneDimensionStatisticTableResultToTable(_ref6) {
350
- var statisticalResult = _ref6.statisticalResult,
351
- t = _ref6.t;
368
+ var statisticalResult = _ref6.statisticalResult;
352
369
  var pivotResult = statisticalResult.pivotResult,
353
370
  groupbyColumn = statisticalResult.groupbyColumn,
354
371
  statisticTableColumns = statisticalResult.statisticTableColumns,
@@ -417,8 +434,9 @@ export var getOneDimensionStatisticTableResultToTable = function getOneDimension
417
434
  pivot_rows.forEach(function (item) {
418
435
  var _newRow2;
419
436
  var name = item.name,
437
+ original_name = item.original_name,
420
438
  total = item.total;
421
- var groupName = name === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(name, groupbyColumn);
439
+ var groupName = isEmptyName(original_name) ? intl.get(EMPTY_NAME) : name;
422
440
  var cellValue = total.total;
423
441
  if (_isDateSummaryColumn && cellValue) {
424
442
  cellValue = isIncludeHour ? dayjs(cellValue).format('YYYY-MM-DD HH:mm') : dayjs(cellValue).format('YYYY-MM-DD');
@@ -482,8 +500,9 @@ export var getOneDimensionStatisticTableResultToTable = function getOneDimension
482
500
  // generator rows
483
501
  pivot_rows.forEach(function (item) {
484
502
  var name = item.name,
503
+ original_name = item.original_name,
485
504
  total = item.total;
486
- var groupName = name === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(name, groupbyColumn);
505
+ var groupName = isEmptyName(original_name) ? intl.get(EMPTY_NAME) : name;
487
506
  var newRow = _defineProperty({}, groupbyColumn.name, groupName);
488
507
  Array.isArray(pivot_columns) && pivot_columns.forEach(function (item) {
489
508
  var key = item.key;
@@ -506,11 +525,9 @@ export var getOneDimensionStatisticTableResultToTable = function getOneDimension
506
525
  };
507
526
  };
508
527
  export var getTwoDimensionStatisticTableResultToTable = function getTwoDimensionStatisticTableResultToTable(_ref11) {
509
- var statisticalResult = _ref11.statisticalResult,
510
- t = _ref11.t;
528
+ var statisticalResult = _ref11.statisticalResult;
511
529
  var pivotResult = statisticalResult.pivotResult,
512
530
  groupbyColumn = statisticalResult.groupbyColumn,
513
- columnGroupbyColumn = statisticalResult.columnGroupbyColumn,
514
531
  summaryColumn = statisticalResult.summaryColumn;
515
532
  var pivot_rows = pivotResult.pivot_rows,
516
533
  pivot_columns = pivotResult.pivot_columns;
@@ -561,8 +578,9 @@ export var getTwoDimensionStatisticTableResultToTable = function getTwoDimension
561
578
  }
562
579
  }
563
580
  Array.isArray(pivot_columns) && pivot_columns.forEach(function (item) {
564
- var key = item.key;
565
- var columnName = key === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(key, columnGroupbyColumn);
581
+ var key = item.key,
582
+ original_key = item.original_key;
583
+ var columnName = isEmptyName(original_key) ? intl.get(EMPTY_NAME) : key;
566
584
  var newColumn = {
567
585
  type: _isDateSummaryColumn ? CellType.DATE : CellType.NUMBER,
568
586
  name: columnName,
@@ -584,9 +602,12 @@ export var getTwoDimensionStatisticTableResultToTable = function getTwoDimension
584
602
  var dateFormat = isIncludeHour ? 'YYYY-MM-DD HH:mm' : 'YYYY-MM-DD';
585
603
  pivot_rows.forEach(function (item) {
586
604
  var name = item.name,
605
+ original_name = item.original_name,
587
606
  cells = item.cells,
588
607
  total = item.total;
589
- name = name === null ? intl.get(EMPTY_NAME) : getTableValueDisplayName(name, groupbyColumn);
608
+ if (isEmptyName(original_name)) {
609
+ name = intl.get(EMPTY_NAME);
610
+ }
590
611
  var newRow = _defineProperty({}, groupbyColumn.name, name);
591
612
  var cellValue = total;
592
613
  if (_isDateSummaryColumn && cellValue) {
@@ -609,8 +630,7 @@ export var getTwoDimensionStatisticTableResultToTable = function getTwoDimension
609
630
  };
610
631
  export var updateStatisticToTable = function updateStatisticToTable(_ref14) {
611
632
  var updateTable = _ref14.updateTable,
612
- statisticalResult = _ref14.statisticalResult,
613
- t = _ref14.t;
633
+ statisticalResult = _ref14.statisticalResult;
614
634
  var groupbyColumn = statisticalResult.groupbyColumn,
615
635
  columnGroupbyColumn = statisticalResult.columnGroupbyColumn;
616
636
  if (!groupbyColumn) return {};
@@ -619,15 +639,13 @@ export var updateStatisticToTable = function updateStatisticToTable(_ref14) {
619
639
  if (columnGroupbyColumn) {
620
640
  return getUpdatedTwoDimensionStatisticTableResultToTable({
621
641
  updateTable: updateTable,
622
- statisticalResult: statisticalResult,
623
- t: t
642
+ statisticalResult: statisticalResult
624
643
  });
625
644
  }
626
645
 
627
646
  // one dimension table
628
647
  return getUpdatedOneDimensionStatisticTableResultToTable({
629
648
  updateTable: updateTable,
630
- statisticalResult: statisticalResult,
631
- t: t
649
+ statisticalResult: statisticalResult
632
650
  });
633
651
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-statistic",
3
- "version": "4.0.11",
3
+ "version": "4.0.12",
4
4
  "description": "statistics",
5
5
  "main": "dist/dtable-statistic.js",
6
6
  "author": "seafile",