dtable-statistic 4.1.6 → 4.1.7

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.
@@ -438,7 +438,7 @@ var BasicChartCalculator = /*#__PURE__*/function (_BaseCalculator) {
438
438
  }
439
439
  var color;
440
440
  if (columnGroupbyColumn.type === CellType.SINGLE_SELECT) {
441
- var tempValue = StatUtils.getGroupLabel(item[columnGroupbyColumn.key], {}, columnGroupbyColumn, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, _this2.value);
441
+ var tempValue = StatUtils.getGroupLabel(item[columnGroupbyColumn.key], item, columnGroupbyColumn, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, _this2.value);
442
442
  color = getColorFromSingleSelectColumn(columnGroupbyColumn, tempValue);
443
443
  }
444
444
  var groupLabel = _this2.getLabel(columnGroupbyColumn, columnGroupbyColumnName, item, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity);
@@ -564,7 +564,7 @@ var BasicChartCalculator = /*#__PURE__*/function (_BaseCalculator) {
564
564
  label = item[groupName];
565
565
  } else {
566
566
  var currentGroupLabel = item[groupColumn.key];
567
- label = StatUtils.getGroupLabel(currentGroupLabel, {}, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
567
+ label = StatUtils.getGroupLabel(currentGroupLabel, item, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
568
568
  label = getFormattedLabel(groupColumn, label, this.value.collaborators);
569
569
  }
570
570
  return label;
@@ -310,7 +310,7 @@ var CombinationCalculator = /*#__PURE__*/function (_BaseCalculator) {
310
310
  label = item[groupName];
311
311
  } else {
312
312
  var currentGroupLabel = item[groupColumn.key];
313
- label = StatUtils.getGroupLabel(currentGroupLabel, {}, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
313
+ label = StatUtils.getGroupLabel(currentGroupLabel, item, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
314
314
  label = getFormattedLabel(groupColumn, label);
315
315
  }
316
316
  return label;
@@ -147,7 +147,7 @@ var CompareBarCalculator = /*#__PURE__*/function (_BaseCalculator) {
147
147
  valueKey = isAdvanced ? "".concat(method, "(").concat(summaryColumnName, ")") : "".concat(method, "(").concat(selectedColumn.name, ")");
148
148
  result.data.results.forEach(function (item) {
149
149
  var name = item[groupName];
150
- var label = StatUtils.getGroupLabel(name, {}, selectedColumn, x_axis_date_granularity, '', _this.value);
150
+ var label = StatUtils.getGroupLabel(name, item, selectedColumn, x_axis_date_granularity, '', _this.value);
151
151
  var value = item[valueKey];
152
152
  if (name >= x_axis_date_range_start && name <= x_axis_date_range_end) {
153
153
  var currentValue = dateRangeResult.get(label);
@@ -150,7 +150,7 @@ var CompletenessCalculator = /*#__PURE__*/function (_BaseCalculator) {
150
150
  var name = item[selectedColumn.key];
151
151
  var label;
152
152
  if (name || Number.isFinite(name)) {
153
- label = StatUtils.getGroupLabel(name, {}, selectedColumn, '', '', _this.value);
153
+ label = StatUtils.getGroupLabel(name, item, selectedColumn, '', '', _this.value);
154
154
  if (isColumnDataAsAnArray) {
155
155
  label = label[0];
156
156
  }
@@ -226,7 +226,7 @@ var CompletenessCalculator = /*#__PURE__*/function (_BaseCalculator) {
226
226
 
227
227
  // get and format name
228
228
  if (name || Number.isFinite(name)) {
229
- label = StatUtils.getGroupLabel(name, {}, selectedColumn, '', '', _this.value);
229
+ label = StatUtils.getGroupLabel(name, item, selectedColumn, '', '', _this.value);
230
230
  if (isColumnDataAsAnArray) {
231
231
  label = label[0];
232
232
  }
@@ -236,7 +236,7 @@ var CompletenessCalculator = /*#__PURE__*/function (_BaseCalculator) {
236
236
  // get and format group name
237
237
  if (!isTimeGroupColumn) {
238
238
  groupLabel = item[groupColumn.key];
239
- groupLabel = StatUtils.getGroupLabel(groupLabel, {}, groupColumn, '', '', _this.value);
239
+ groupLabel = StatUtils.getGroupLabel(groupLabel, item, groupColumn, '', '', _this.value);
240
240
  if (groupLabel && isGroupColumnDataAsAnArray) {
241
241
  groupLabel = groupLabel[0];
242
242
  }
@@ -127,7 +127,7 @@ var MirrorCalculator = /*#__PURE__*/function (_BaseCalculator) {
127
127
  _context2.next = 22;
128
128
  break;
129
129
  case 21:
130
- sqlString = "select `".concat(columnName, "`, `").concat(groupColumnName, "`, ").concat(method, "(").concat(columnName, ") from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by `").concat(columnName, "`, `").concat(groupColumnName, "` limit 5000");
130
+ sqlString = "select `".concat(columnName, "`, `").concat(groupColumnName, "`, ").concat(method, "(`").concat(columnName, "`) from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by `").concat(columnName, "`, `").concat(groupColumnName, "` limit 5000");
131
131
  case 22:
132
132
  _context2.next = 24;
133
133
  return this.sqlQuery(sqlString);
@@ -152,7 +152,7 @@ var MirrorCalculator = /*#__PURE__*/function (_BaseCalculator) {
152
152
  groupData0 = groupData[0] || {};
153
153
  groupData1 = groupData[1] || {};
154
154
  data.results.forEach(function (item) {
155
- var label = StatUtils.getGroupLabel(item[column], {}, selectedColumn, '', '', _this.value);
155
+ var label = StatUtils.getGroupLabel(item[column], item, selectedColumn, '', '', _this.value);
156
156
  var groupValue = item[group_column];
157
157
  var equal2GroupData0 = groupData0.id === groupValue;
158
158
  var equal2GroupData1 = groupData1.id === groupValue;
@@ -369,7 +369,8 @@ var PivotTableCalculator = /*#__PURE__*/function (_BaseCalculator) {
369
369
  var groupbyColumn = columnMap.groupbyColumn;
370
370
  var summary_type = chart.summary_type,
371
371
  groupby_geolocation_granularity = chart.groupby_geolocation_granularity,
372
- groupby_date_granularity = chart.groupby_date_granularity;
372
+ groupby_date_granularity = chart.groupby_date_granularity,
373
+ groupby_include_empty_cells = chart.groupby_include_empty_cells;
373
374
  var pivot_columns = [];
374
375
  var pivot_rows = [];
375
376
  var isCount = summary_type === SUMMARY_TYPE.COUNT;
@@ -378,11 +379,14 @@ var PivotTableCalculator = /*#__PURE__*/function (_BaseCalculator) {
378
379
  sqlSummaryColumnKey = statisticSQLMap.sqlSummaryColumnKey;
379
380
  var _allTotal = 0;
380
381
  sqlRows.forEach(function (row) {
381
- var total = row[sqlSummaryColumnKey] || 0;
382
- _allTotal += total;
383
382
  var originalLabel = _this3.getOriginalLabel(groupbyColumn, _sqlGroupbyColumnKey, row, groupby_geolocation_granularity, groupby_date_granularity);
384
383
  var name = _this3.getLabel(groupbyColumn, originalLabel);
385
384
  var original_name = _this3.getOriginalName(groupbyColumn, originalLabel);
385
+ if (!groupby_include_empty_cells && !name) {
386
+ return;
387
+ }
388
+ var total = row[sqlSummaryColumnKey] || 0;
389
+ _allTotal += total;
386
390
  pivot_rows.push({
387
391
  name: name,
388
392
  original_name: original_name,
@@ -653,7 +657,7 @@ var PivotTableCalculator = /*#__PURE__*/function (_BaseCalculator) {
653
657
  return statRow[groupName];
654
658
  }
655
659
  var currentGroupLabel = statRow[groupColumn.key];
656
- return StatUtils.getGroupLabel(currentGroupLabel, {}, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
660
+ return StatUtils.getGroupLabel(currentGroupLabel, statRow, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
657
661
  }
658
662
  }, {
659
663
  key: "getOriginalName",
@@ -663,7 +667,7 @@ var PivotTableCalculator = /*#__PURE__*/function (_BaseCalculator) {
663
667
  return originalLabel;
664
668
  }
665
669
  var columnType = groupColumn.type;
666
- if (columnType === CellType.MULTIPLE_SELECT || columnType === CellType.COLLABORATOR || columnType === CellType.LINK) {
670
+ if (columnType === CellType.MULTIPLE_SELECT || columnType === CellType.COLLABORATOR) {
667
671
  return Array.isArray(originalLabel) ? originalLabel[0] : null;
668
672
  }
669
673
  return originalLabel;
@@ -141,7 +141,7 @@ var ScatterCalculator = /*#__PURE__*/function (_BaseCalculator) {
141
141
  key: "getColumnValue",
142
142
  value: function getColumnValue(data, column) {
143
143
  var tempValue = data[column.key];
144
- var value = StatUtils.getGroupLabel(tempValue, {}, column, DATE_GRANULARITY.DAY, '', this.value);
144
+ var value = StatUtils.getGroupLabel(tempValue, data, column, DATE_GRANULARITY.DAY, '', this.value);
145
145
  return getFormattedLabel(column, value, this.value.collaborators);
146
146
  }
147
147
  }]);
@@ -114,3 +114,7 @@
114
114
  .statistic-records-dialog .statistic-records-container .records-list .records-container {
115
115
  height: auto;
116
116
  }
117
+
118
+ .statistic-records-dialog .row-card-item-content .grid-cell-type-button .grid-cell-type-button-inner {
119
+ justify-content: flex-start;
120
+ }
@@ -1,19 +1,19 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
5
  import _inherits from "@babel/runtime/helpers/esm/inherits";
5
6
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
7
  import React, { Fragment } from 'react';
7
8
  import intl from 'react-intl-universal';
8
9
  import { Modal, ModalBody } from 'reactstrap';
9
- import { CellType, Views } from 'dtable-store';
10
+ import { Views } from 'dtable-store';
10
11
  import dtableDbAPI from '../../../api/dtable-db-api';
11
12
  import { DtableSearchInput, Loading } from '../../index';
12
13
  import { searchRows } from '../../../utils';
13
14
  import { getSqlString } from '../../../utils/sql-utils';
14
15
  import { CommonEventTypes } from '../../../constants';
15
16
  import './index.css';
16
- export var UNSHOWN_COLUMN_TYPES = [CellType.LINK, CellType.LONG_TEXT, CellType.FORMULA, CellType.LINK_FORMULA];
17
17
  var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
18
18
  _inherits(StatisticRecordDialog, _React$Component);
19
19
  var _super = _createSuper(StatisticRecordDialog);
@@ -37,6 +37,8 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
37
37
  _this.table = getTableById(table_id);
38
38
  _this.view = Views.getViewById(_this.table.views, view_id);
39
39
  _this.isArchiveView = Views.isArchiveView(_this.view);
40
+ _this.unShowColumnKeyList = _this.getUnShowColumnKeyList(_this.view);
41
+ _this.renderedColumns = _this.getRenderedColumns(_this.table);
40
42
  if (_this.isArchiveView || !records) {
41
43
  var sqlString = getSqlString(chart, statisticRecord, {
42
44
  isColumn: isColumn,
@@ -60,6 +62,7 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
60
62
  drilledRows.forEach(function (row) {
61
63
  idRowMap[row._id] = row;
62
64
  });
65
+ _this.initComputedProperties(drilledRows);
63
66
  _this.setState({
64
67
  loading: false,
65
68
  title: name,
@@ -68,6 +71,25 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
68
71
  searchedRowsIds: searchedRowsIds
69
72
  });
70
73
  };
74
+ _this.initComputedProperties = function (drilledRows) {
75
+ if (_this.isArchiveView) {
76
+ var formulaColumns = Views.getFormulaColumnsContainLinks(_this.table);
77
+ if (formulaColumns.length === 0) return {};
78
+ var _formulaRows = {};
79
+ drilledRows.forEach(function (row) {
80
+ var rowId = row._id;
81
+ _formulaRows[rowId] = {};
82
+ formulaColumns.forEach(function (column) {
83
+ return _formulaRows[rowId][column.key] = row[column.key];
84
+ });
85
+ });
86
+ _this.formulaRows = _formulaRows;
87
+ return;
88
+ }
89
+ var _this$getTableViewFor = _this.getTableViewFormulaRows(),
90
+ formulaRows = _this$getTableViewFor.formulaRows;
91
+ _this.formulaRows = formulaRows;
92
+ };
71
93
  _this.onSearch = function (searchVal) {
72
94
  var rows = _this.state.rows;
73
95
  var searchedRowsIds = _this.getSearchedRows(rows, searchVal);
@@ -176,22 +198,49 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
176
198
  searchedRowsIds: updatedSearchedRowsIds
177
199
  });
178
200
  };
201
+ _this.getUnShowColumnKeyList = function (view) {
202
+ var firstColumnKey = '0000';
203
+ var _view$hidden_columns = view.hidden_columns,
204
+ hidden_columns = _view$hidden_columns === void 0 ? [] : _view$hidden_columns;
205
+ return [firstColumnKey].concat(_toConsumableArray(hidden_columns));
206
+ };
207
+ _this.getRenderedColumns = function (table) {
208
+ var columns = table.columns;
209
+ return columns.filter(function (column) {
210
+ return !_this.unShowColumnKeyList.includes(column.key);
211
+ });
212
+ };
213
+ _this.getTableViewFormulaRows = function () {
214
+ var _assertThisInitialize = _assertThisInitialized(_this),
215
+ table = _assertThisInitialize.table,
216
+ view = _assertThisInitialize.view;
217
+ var value = _this.props.getValue();
218
+ if (view.formula_rows && Object.keys(view.formula_rows).length > 0) {
219
+ return {
220
+ formulaRows: view.formula_rows
221
+ };
222
+ }
223
+ Views.cacheFormulaResults(table.rows, {
224
+ targetViewId: view._id,
225
+ table: table,
226
+ value: value
227
+ });
228
+ return {
229
+ formulaRows: view.formula_rows
230
+ };
231
+ };
179
232
  _this.renderRowsCards = function () {
180
233
  var searchedRowsIds = _this.state.searchedRowsIds;
181
234
  var searchedRows = _this.getRowsByIds(searchedRowsIds);
182
235
  if (searchedRows.length === 0) return null;
183
- var unShowColumnKeyList = ['0000'];
184
- var allColumns = _this.table.columns;
185
- var renderedColumns = allColumns.filter(function (column) {
186
- return !unShowColumnKeyList.includes(column.key) && !UNSHOWN_COLUMN_TYPES.includes(column.type);
187
- });
188
236
  if (!window.app || !window.app.renderRowsCards) return null;
189
237
  return window.app.renderRowsCards({
190
238
  table: _this.table,
191
- renderedColumns: renderedColumns,
192
- unShowColumnKeyList: unShowColumnKeyList,
239
+ renderedColumns: _this.renderedColumns,
240
+ unShowColumnKeyList: _this.unShowColumnKeyList,
193
241
  isShowRowCardHeader: true,
194
- columns: allColumns,
242
+ formulaRows: _this.formulaRows,
243
+ columns: _this.renderedColumns,
195
244
  rows: searchedRows,
196
245
  rowCardType: 'statistic'
197
246
  });
@@ -208,6 +257,9 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
208
257
  _this.view = null;
209
258
  _this.isArchiveView = false;
210
259
  _this.valueChanged = false;
260
+ _this.renderedColumns = [];
261
+ _this.formulaRows = null;
262
+ _this.unShowColumnKeyList = null;
211
263
  return _this;
212
264
  }
213
265
  _createClass(StatisticRecordDialog, [{
package/es/dashboard.js CHANGED
@@ -378,6 +378,9 @@ var DashBoard = /*#__PURE__*/function (_Component) {
378
378
  _this.getViews = function (table) {
379
379
  return table.views;
380
380
  };
381
+ _this.getValue = function () {
382
+ return _this.value;
383
+ };
381
384
  _this.isTableReadOnly = function () {
382
385
  if (window.dtable.modulePermission) {
383
386
  return window.dtable.modulePermission.isTableReadOnly;
@@ -484,6 +487,7 @@ var DashBoard = /*#__PURE__*/function (_Component) {
484
487
  getTableById: this.getTableById,
485
488
  getTables: this.getTables,
486
489
  getViews: this.getViews,
490
+ getValue: this.getValue,
487
491
  queryMapJson: this.queryMapJson,
488
492
  getInitChart: this.getInitChart,
489
493
  getConvertedChart: this.getConvertedChart,
@@ -145,6 +145,7 @@ var DesktopDashboard = /*#__PURE__*/function (_Component) {
145
145
  value: function render() {
146
146
  var _this$props4 = this.props,
147
147
  getTableById = _this$props4.getTableById,
148
+ getValue = _this$props4.getValue,
148
149
  isTableReadOnly = _this$props4.isTableReadOnly,
149
150
  dtableChangedTime = _this$props4.dtableChangedTime,
150
151
  colorThemeName = _this$props4.colorThemeName,
@@ -271,6 +272,7 @@ var DesktopDashboard = /*#__PURE__*/function (_Component) {
271
272
  eventBus: this.props.eventBus,
272
273
  chartRecordsParams: chartRecordsParams,
273
274
  getTableById: getTableById,
275
+ getValue: getValue,
274
276
  toggleStatisticRecordsDialog: this.toggleStatisticRecordsDialog
275
277
  }));
276
278
  }
@@ -99,9 +99,12 @@ var PivotTableDisplayName = /*#__PURE__*/function (_React$Component) {
99
99
  }
100
100
  case CellType.LINK:
101
101
  {
102
- var _displayValue = getClientFormulaDisplayString([value], data, {
102
+ var _displayValue = getClientFormulaDisplayString(Array.isArray(value) ? value : [value], data, {
103
103
  collaborators: collaborators
104
104
  }) || null;
105
+ if (!_displayValue) {
106
+ break;
107
+ }
105
108
  displayName = /*#__PURE__*/React.createElement("div", {
106
109
  title: _displayValue,
107
110
  "aria-label": _displayValue
@@ -177,7 +180,10 @@ var PivotTableDisplayName = /*#__PURE__*/function (_React$Component) {
177
180
  var _this$props2 = this.props,
178
181
  value = _this$props2.value,
179
182
  column = _this$props2.column;
180
- var displayName = value ? this.getDisplayName(value, column) : /*#__PURE__*/React.createElement("div", null, "(".concat(intl.get(EMPTY_NAME), ")"));
183
+ var displayName = value && this.getDisplayName(value, column);
184
+ if (!displayName) {
185
+ return /*#__PURE__*/React.createElement("div", null, "(".concat(intl.get(EMPTY_NAME), ")"));
186
+ }
181
187
  return /*#__PURE__*/React.createElement(Fragment, null, displayName);
182
188
  }
183
189
  }]);
@@ -1,4 +1,4 @@
1
- import { CellType, isDateColumn, FORMULA_RESULT_TYPE, FORMULA_COLUMN_TYPES } from 'dtable-store';
1
+ import { CellType, isDateColumn, FORMULA_RESULT_TYPE, FORMULA_COLUMN_TYPES, Views } from 'dtable-store';
2
2
  import { MIRROR_COLUMN_LIST } from '../constants';
3
3
  export function getColorFromSingleSelectColumn(column, target) {
4
4
  var columnType = column.type,
@@ -227,7 +227,11 @@ var getPieColor = function getPieColor(color_option, column, index, data, curren
227
227
  };
228
228
  export function formatPieChartData(data, statItem, table, currentTheme) {
229
229
  var groupby_column_key = statItem.groupby_column_key,
230
- color_option = statItem.color_option;
230
+ color_option = statItem.color_option,
231
+ summary_column_key = statItem.summary_column_key,
232
+ summaryMethod = statItem.summary_method,
233
+ summary_type = statItem.summary_type;
234
+ var isAdvanced = summary_type === 'advanced';
231
235
  var column = TableUtils.getTableColumnByKey(table, groupby_column_key);
232
236
  var sum = data.reduce(function (total, currentValue) {
233
237
  return total += currentValue.value;
@@ -257,6 +261,11 @@ export function formatPieChartData(data, statItem, table, currentTheme) {
257
261
  var filteredSum = filteredItems.reduce(function (total, currentValue) {
258
262
  return total += currentValue.value;
259
263
  }, 0);
264
+ var formattedValueSum = filteredSum;
265
+ if (isAdvanced) {
266
+ var summaryColumn = TableUtils.getTableColumnByKey(table, summary_column_key);
267
+ formattedValueSum = StatUtils.getFormattedValue(filteredSum, summaryColumn, summaryMethod);
268
+ }
260
269
  var original_name_list = [];
261
270
  var name_list = [];
262
271
  var rows = [];
@@ -277,6 +286,7 @@ export function formatPieChartData(data, statItem, table, currentTheme) {
277
286
  original_name_list: original_name_list,
278
287
  name: intl.get('Others'),
279
288
  value: filteredSum,
289
+ formatted_value: formattedValueSum,
280
290
  color: '#dbdbdb',
281
291
  original_name: 'Others',
282
292
  percent: String(Number.parseFloat(filteredSum / sum * 100).toFixed(1)) + '%'
@@ -64,7 +64,7 @@ export var getFormattedLabel = function getFormattedLabel(column, name, collabor
64
64
  }
65
65
  }
66
66
  } else if (columnType === CellType.LINK) {
67
- return getClientFormulaDisplayString([name], columnData, {
67
+ return getClientFormulaDisplayString(Array.isArray(name) ? name : [name], columnData, {
68
68
  collaborators: collaborators
69
69
  });
70
70
  } else if (columnType === CellType.CHECKBOX) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-statistic",
3
- "version": "4.1.6",
3
+ "version": "4.1.7",
4
4
  "description": "statistics",
5
5
  "main": "dist/dtable-statistic.js",
6
6
  "author": "seafile",
@@ -12,7 +12,7 @@
12
12
  "@seafile/seafile-calendar": "0.0.24",
13
13
  "comlink": "^4.3.1",
14
14
  "dayjs": "1.10.7",
15
- "dtable-store": "4.1.2",
15
+ "dtable-store": "4.1.5",
16
16
  "dtable-web-api": "4.0.11",
17
17
  "glamor": "^2.20.40",
18
18
  "html2canvas": "^1.4.1",