@gridsuite/commons-ui 0.29.2 → 0.30.0

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.
@@ -5,31 +5,31 @@ exports["default"] = exports.DEFAULT_ROW_HEIGHT = exports.DEFAULT_HEADER_HEIGHT
5
5
 
6
6
  var _react = _interopRequireWildcard(require("react"));
7
7
 
8
+ var _reactIntl = require("react-intl");
9
+
8
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
11
 
10
12
  var _clsx3 = _interopRequireDefault(require("clsx"));
11
13
 
12
- var _TableCell = _interopRequireDefault(require("@mui/material/TableCell"));
13
-
14
- var _reactVirtualized = require("react-virtualized");
14
+ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
15
15
 
16
- var _TableSortLabel = _interopRequireDefault(require("@mui/material/TableSortLabel"));
16
+ var _material = require("@mui/material");
17
17
 
18
- var _memoizeOne = _interopRequireDefault(require("memoize-one"));
18
+ var _withStyles = _interopRequireDefault(require("@mui/styles/withStyles"));
19
19
 
20
20
  var _GetApp = _interopRequireDefault(require("@mui/icons-material/GetApp"));
21
21
 
22
- var _reactCsvDownloader = _interopRequireDefault(require("react-csv-downloader"));
22
+ var _reactVirtualized = require("react-virtualized");
23
23
 
24
- var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
24
+ var _reactCsvDownloader = _interopRequireDefault(require("react-csv-downloader"));
25
25
 
26
- var _reactIntl = require("react-intl");
26
+ var _overflowableText = _interopRequireDefault(require("../OverflowableText/overflowable-text"));
27
27
 
28
- var _withStyles = _interopRequireDefault(require("@mui/styles/withStyles"));
28
+ var _KeyedColumnsRowIndexer = require("./KeyedColumnsRowIndexer");
29
29
 
30
- var _overflowableText = _interopRequireDefault(require("../OverflowableText/overflowable-text"));
30
+ var _ColumnHeader = _interopRequireDefault(require("./ColumnHeader"));
31
31
 
32
- var _excluded = ["name", "classes", "rows", "columns", "rowHeight", "headerHeight", "rowCount", "sortable", "enableExportCSV"],
32
+ var _excluded = ["sort"],
33
33
  _excluded2 = ["dataKey"];
34
34
 
35
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -38,10 +38,14 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
38
38
 
39
39
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
40
40
 
41
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
42
-
43
41
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
44
42
 
43
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
44
+
45
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
46
+
47
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
48
+
45
49
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
46
50
 
47
51
  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
@@ -50,6 +54,8 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec
50
54
 
51
55
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
52
56
 
57
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
58
+
53
59
  function getTextWidth(text) {
54
60
  // re-use canvas object for better performance
55
61
  var canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement('canvas'));
@@ -102,48 +108,132 @@ var defaultStyles = {
102
108
  }
103
109
  };
104
110
 
111
+ var AmongChooser = function AmongChooser(props) {
112
+ var options = props.options,
113
+ value = props.value,
114
+ setValue = props.setValue,
115
+ id = props.id;
116
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", null, props.label), /*#__PURE__*/_react["default"].createElement(_material.Autocomplete, {
117
+ id: id,
118
+ value: value !== null && value !== void 0 ? value : [],
119
+ multiple: true,
120
+ onChange: function onChange(evt, newVal) {
121
+ setValue(newVal);
122
+ },
123
+ options: options // getOptionLabel={(code) => options.get(code)}
124
+ ,
125
+ renderInput: function renderInput(props) {
126
+ return /*#__PURE__*/_react["default"].createElement(_material.TextField // label={<FormattedMessage id={titleMessage} />}
127
+ , props);
128
+ },
129
+ renderTags: function renderTags(val, getTagsProps) {
130
+ return val.map(function (code, index) {
131
+ return /*#__PURE__*/_react["default"].createElement(_material.Chip, _extends({
132
+ id: 'chip_' + code,
133
+ size: 'small',
134
+ label: code
135
+ }, getTagsProps({
136
+ index: index
137
+ })));
138
+ });
139
+ }
140
+ }));
141
+ };
142
+
143
+ var initIndexer = function initIndexer(props, oldProps, versionSetter) {
144
+ if (!props.sortable) {
145
+ return null;
146
+ }
147
+
148
+ if (props.indexer) {
149
+ return props.indexer;
150
+ } else if (!props.sort) {
151
+ return new _KeyedColumnsRowIndexer.KeyedColumnsRowIndexer(true, true, null, versionSetter);
152
+ } else if (typeof props.sort === 'function') {
153
+ return new _KeyedColumnsRowIndexer.KeyedColumnsRowIndexer(true, true, function (cbfgs, done_cb) {
154
+ console.debug('dummy func, now :-/');
155
+ done_cb(true);
156
+ }, versionSetter);
157
+ } else if (typeof props.sort === 'object') {
158
+ return props.sort;
159
+ } else {
160
+ console.warn('unknown type of sort', props.sort);
161
+ }
162
+
163
+ return new _KeyedColumnsRowIndexer.KeyedColumnsRowIndexer(true, true, null, versionSetter);
164
+ };
165
+
105
166
  var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
106
167
  _inheritsLoose(MuiVirtualizedTable, _React$PureComponent);
107
168
 
108
- function MuiVirtualizedTable(props, context) {
169
+ function MuiVirtualizedTable(_props, context) {
109
170
  var _this;
110
171
 
111
- _this = _React$PureComponent.call(this, props, context) || this;
172
+ _this = _React$PureComponent.call(this, _props, context) || this;
112
173
 
113
- _defineProperty(_assertThisInitialized(_this), "state", {
114
- key: undefined,
115
- direction: 'asc',
116
- headerHeight: _this.props.headerHeight
174
+ _defineProperty(_assertThisInitialized(_this), "setVersion", function (v) {
175
+ _this.setState({
176
+ indirectionVersion: v
177
+ });
117
178
  });
118
179
 
119
- _defineProperty(_assertThisInitialized(_this), "reorderIndex", (0, _memoizeOne["default"])(function (key, direction, filter, rows) {
120
- if (!rows) return [];
121
- var indexedArray = [];
180
+ _defineProperty(_assertThisInitialized(_this), "preFilterData", (0, _memoizeOne["default"])(function (columns, rows) {
181
+ return _this.state.indexer.preFilterRowMapping(columns, rows);
182
+ }));
122
183
 
123
- for (var i = 0; i < rows.length; i++) {
124
- var row = rows[i];
125
- if (!filter || filter(row)) indexedArray.push([row, i]);
126
- }
184
+ _defineProperty(_assertThisInitialized(_this), "reorderIndex", (0, _memoizeOne["default"])(function (indirectorVersion, rows, columns) {
185
+ var indexer = _this.state.indexer;
186
+ if (!rows) return {
187
+ viewIndexToModel: [],
188
+ rowGetter: function rowGetter(viewIndex) {
189
+ return viewIndex;
190
+ }
191
+ };
192
+ var props = _this.props;
193
+
194
+ if (indexer && props.sort) {
195
+ var highestCodedColumn = indexer.highestCodedColumn(props.columns);
196
+
197
+ if (highestCodedColumn !== 0) {
198
+ var colIdx = Math.abs(highestCodedColumn) - 1;
199
+ var ret = props.sort(props.columns[colIdx].dataKey, highestCodedColumn > 0, !!props.columns[colIdx].numeric);
200
+ return {
201
+ viewIndexToModel: ret,
202
+ rowGetter: function rowGetter(viewIndex) {
203
+ if (viewIndex >= ret.length || viewIndex < 0) {
204
+ return {};
205
+ }
206
+
207
+ var modelIndex = ret[viewIndex];
208
+ return rows[modelIndex];
209
+ }
210
+ };
211
+ }
212
+ } else if (indexer) {
213
+ var prefiltered = _this.preFilterData(columns, rows);
127
214
 
128
- function compareValue(a, b, isNumeric, reverse) {
129
- var mult = reverse ? 1 : -1;
130
- if (a === undefined && b === undefined) return 0;else if (a === undefined) return mult;else if (b === undefined) return -mult;
131
- return isNumeric ? (Number(a) < Number(b) ? 1 : -1) * mult : ('' + a).localeCompare(b) * mult;
132
- }
215
+ var reorderedIndex = indexer.makeGroupAndSortIndirector(prefiltered, columns);
216
+ return {
217
+ viewIndexToModel: reorderedIndex,
218
+ rowGetter: function rowGetter(viewIndex) {
219
+ if (reorderedIndex === null) return rows[viewIndex];
133
220
 
134
- if (key !== undefined) {
135
- var reverse = direction === 'asc';
136
- var isNumeric = _this.props.columns[key].numeric;
137
- var dataKey = _this.props.columns[key].dataKey;
138
- if (dataKey && dataKey !== '' && _this.state.direction !== '') if (_this.props.sort) return _this.props.sort(dataKey, reverse, isNumeric);
139
- indexedArray.sort(function (a, b) {
140
- return compareValue(a[0][dataKey], b[0][dataKey], isNumeric, reverse);
141
- });
221
+ if (viewIndex >= reorderedIndex.length || viewIndex < 0) {
222
+ return {};
223
+ }
224
+
225
+ var modelIndex = reorderedIndex[viewIndex];
226
+ return rows[modelIndex];
227
+ }
228
+ };
142
229
  }
143
230
 
144
- return indexedArray.map(function (k) {
145
- return k[1];
146
- });
231
+ return {
232
+ viewIndexToModel: null,
233
+ rowGetter: function rowGetter(viewIndex) {
234
+ return rows[viewIndex];
235
+ }
236
+ };
147
237
  }));
148
238
 
149
239
  _defineProperty(_assertThisInitialized(_this), "computeDataWidth", function (text) {
@@ -156,14 +246,16 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
156
246
  if (col.width) {
157
247
  sizes[col.dataKey] = col.width;
158
248
  } else {
159
- /* calculate the header (and min size if exists) */
249
+ /* calculate the header (and min size if exists)
250
+ * NB : ignores the possible icons
251
+ */
160
252
  var size = Math.max(col.minWidth || 0, _this.computeDataWidth(col.label));
161
253
  /* calculate for each row the width, and keep the max */
162
254
 
163
255
  for (var i = 0; i < rows.length; ++i) {
164
- var text = _this.getDisplayValue(col, rowGetter({
165
- index: i
166
- })[col.dataKey]);
256
+ var gotRow = rowGetter(i);
257
+
258
+ var text = _this.getDisplayValue(col, gotRow[col.dataKey]);
167
259
 
168
260
  size = Math.max(size, _this.computeDataWidth(text));
169
261
  }
@@ -175,52 +267,200 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
175
267
  return sizes;
176
268
  }));
177
269
 
270
+ _defineProperty(_assertThisInitialized(_this), "openPopover", function (popoverTarget, colKey) {
271
+ if (_this.state.indexer.delegatorCallback) {
272
+ return; // retro compatibility stops here ;-)
273
+ }
274
+
275
+ var col = _this.props.columns.find(function (c) {
276
+ return c.dataKey === colKey;
277
+ });
278
+
279
+ if ((0, _KeyedColumnsRowIndexer.getHelper)(col) !== _KeyedColumnsRowIndexer.collectibleHelper) {
280
+ return;
281
+ }
282
+
283
+ _this.setState({
284
+ popoverAnchorEl: popoverTarget,
285
+ popoverColKey: colKey
286
+ });
287
+ });
288
+
289
+ _defineProperty(_assertThisInitialized(_this), "closePopover", function (evt, reason) {
290
+ var bumpsVersion = false;
291
+
292
+ if (reason === 'backdropClick') {
293
+ bumpsVersion = _this._commitFilterChange();
294
+ }
295
+
296
+ _this.setState({
297
+ popoverAnchorEl: null,
298
+ popoverColKey: null,
299
+ deferredFilterChange: null,
300
+ indirectionVersion: _this.state.indirectionVersion + (bumpsVersion ? 1 : 0)
301
+ });
302
+ });
303
+
304
+ _defineProperty(_assertThisInitialized(_this), "makeColumnFilterEditor", function () {
305
+ var _prefiltered$colsStat, _col$label;
306
+
307
+ var colKey = _this.state.popoverColKey;
308
+
309
+ var outerParams = _this.state.indexer.getColFilterOuterParams(colKey);
310
+
311
+ var userParams = !_this.props.defersFilterChanges || !_this.state.deferredFilterChange ? _this.state.indexer.getColFilterUserParams(colKey) : _this.state.deferredFilterChange.newVal;
312
+
313
+ var prefiltered = _this.preFilterData(_this.props.columns, _this.props.rows);
314
+
315
+ var options = [];
316
+
317
+ if (outerParams) {
318
+ options.push.apply(options, outerParams);
319
+ }
320
+
321
+ var colStat = prefiltered === null || prefiltered === void 0 ? void 0 : (_prefiltered$colsStat = prefiltered.colsStats) === null || _prefiltered$colsStat === void 0 ? void 0 : _prefiltered$colsStat[colKey];
322
+
323
+ if (colStat === null || colStat === void 0 ? void 0 : colStat.seen) {
324
+ var _loop = function _loop() {
325
+ var key = _step.value;
326
+
327
+ if (options.findIndex(function (o) {
328
+ return o === key;
329
+ }) < 0) {
330
+ options.push(key);
331
+ }
332
+ };
333
+
334
+ for (var _iterator = _createForOfIteratorHelperLoose(Object.getOwnPropertyNames(colStat.seen)), _step; !(_step = _iterator()).done;) {
335
+ _loop();
336
+ }
337
+ }
338
+
339
+ var col = _this.props.columns.find(function (c) {
340
+ return c.dataKey === colKey;
341
+ });
342
+
343
+ return /*#__PURE__*/_react["default"].createElement(AmongChooser, {
344
+ options: options,
345
+ value: userParams,
346
+ id: 'fielt' + colKey,
347
+ label: (_col$label = col === null || col === void 0 ? void 0 : col.label) !== null && _col$label !== void 0 ? _col$label : "\u2208",
348
+ setValue: function setValue(newVal) {
349
+ _this.onFilterParamsChange(newVal, colKey);
350
+ }
351
+ });
352
+ });
353
+
354
+ _defineProperty(_assertThisInitialized(_this), "_commitFilterChange", function () {
355
+ if (_this.state.deferredFilterChange) {
356
+ var _newVal;
357
+
358
+ var colKey = _this.state.deferredFilterChange.colKey;
359
+ var newVal = _this.state.deferredFilterChange.newVal;
360
+
361
+ if (((_newVal = newVal) === null || _newVal === void 0 ? void 0 : _newVal.length) === 0) {
362
+ newVal = null;
363
+ }
364
+
365
+ if (_this.state.indexer.setColFilterUserParams(colKey, newVal)) {
366
+ return true;
367
+ }
368
+ }
369
+
370
+ return false;
371
+ });
372
+
373
+ _defineProperty(_assertThisInitialized(_this), "sortClickHandler", function (evt, name, columnIndex) {
374
+ var colKey = _this.props.columns[columnIndex].dataKey;
375
+
376
+ if (evt.altKey) {
377
+ _this.openPopover(evt.target, colKey);
378
+
379
+ return;
380
+ }
381
+
382
+ var way = _KeyedColumnsRowIndexer.CHANGE_WAYS.SIMPLE;
383
+
384
+ if (evt.ctrlKey && evt.shiftKey) {
385
+ way = _KeyedColumnsRowIndexer.CHANGE_WAYS.AMEND;
386
+ } else if (evt.ctrlKey) {
387
+ way = _KeyedColumnsRowIndexer.CHANGE_WAYS.REMOVE;
388
+ } else if (evt.shiftKey) {
389
+ way = _KeyedColumnsRowIndexer.CHANGE_WAYS.TAIL;
390
+ }
391
+
392
+ if (_this.state.indexer.updateSortingFromUser(colKey, way)) {
393
+ _this.setState({
394
+ indirectionVersion: _this.state.indirectionVersion + 1
395
+ });
396
+ }
397
+ });
398
+
399
+ _defineProperty(_assertThisInitialized(_this), "filterClickHandler", function (evt, retargeted, columnIndex) {
400
+ var colKey = _this.props.columns[columnIndex].dataKey;
401
+
402
+ _this.openPopover(retargeted, colKey);
403
+ });
404
+
178
405
  _defineProperty(_assertThisInitialized(_this), "sortableHeader", function (_ref) {
406
+ var _prefiltered$colsStat2;
407
+
179
408
  var label = _ref.label,
180
- columnIndex = _ref.columnIndex,
181
- width = _ref.width;
409
+ columnIndex = _ref.columnIndex;
182
410
  var _this$props = _this.props,
183
411
  columns = _this$props.columns,
184
412
  classes = _this$props.classes;
185
- return /*#__PURE__*/_react["default"].createElement(_TableSortLabel["default"], {
186
- component: "div",
187
- className: (0, _clsx3["default"])(classes.tableCell, classes.flexContainer, classes.header),
188
- active: columnIndex === _this.state.key,
189
- style: {
190
- justifyContent: columns[columnIndex].numeric ? 'flex-end' : 'baseline',
191
- height: _this.state.headerHeight
192
- },
193
- direction: _this.state.direction,
194
- onClick: function onClick() {
195
- var _this$state = _this.state,
196
- key = _this$state.key,
197
- direction = _this$state.direction;
198
- if (key === undefined) key = columnIndex;else if (direction === 'asc') direction = 'desc';else {
199
- key = undefined;
200
- direction = 'asc';
201
- }
413
+ var indexer = _this.state.indexer;
414
+ var colKey = columns[columnIndex].dataKey;
415
+ var signedRank = indexer.columnSortingSignedRank(colKey);
416
+ var userParams = indexer.getColFilterUserParams(colKey);
417
+ var numeric = columns[columnIndex].numeric;
418
+
419
+ var prefiltered = _this.preFilterData(columns, _this.props.rows);
420
+
421
+ var colStat = prefiltered === null || prefiltered === void 0 ? void 0 : (_prefiltered$colsStat2 = prefiltered.colsStats) === null || _prefiltered$colsStat2 === void 0 ? void 0 : _prefiltered$colsStat2[colKey];
422
+ var filterLevel = 0;
423
+
424
+ if (colStat === null || colStat === void 0 ? void 0 : colStat.seen) {
425
+ var countSeen = Object.getOwnPropertyNames(colStat.seen).length;
426
+ var userSelectedCount = userParams === null || userParams === void 0 ? void 0 : userParams.length;
427
+ filterLevel += userSelectedCount ? 1 : 0;
428
+ filterLevel += userSelectedCount >= countSeen ? 2 : 0;
429
+ }
202
430
 
203
- _this.setState({
204
- key: key,
205
- direction: direction
206
- });
207
- },
208
- width: width,
431
+ var onFilterClick = numeric || _this.props.sort ? undefined : function (ev, retargeted) {
432
+ _this.filterClickHandler(ev, retargeted, columnIndex);
433
+ };
434
+ return /*#__PURE__*/_react["default"].createElement(_ColumnHeader["default"], {
435
+ label: label,
209
436
  ref: function ref(e) {
210
- return _this._registerObserver(e);
211
- }
212
- }, /*#__PURE__*/_react["default"].createElement("div", {
437
+ return _this._registerHeader(label, e);
438
+ },
439
+ className: (0, _clsx3["default"])(classes.tableCell, classes.header),
440
+ sortSignedRank: signedRank,
441
+ filterLevel: filterLevel,
442
+ numeric: numeric,
443
+ onSortClick: function onSortClick(ev, name) {
444
+ _this.sortClickHandler(ev, name, columnIndex);
445
+ },
446
+ onFilterClick: onFilterClick
447
+ });
448
+ });
449
+
450
+ _defineProperty(_assertThisInitialized(_this), "simpleHeaderRenderer", function (_ref2) {
451
+ var label = _ref2.label;
452
+ return /*#__PURE__*/_react["default"].createElement("div", {
213
453
  ref: function ref(element) {
214
454
  _this._registerHeader(label, element);
215
455
  }
216
- }, label));
456
+ }, label);
217
457
  });
218
458
 
219
- _defineProperty(_assertThisInitialized(_this), "getRowClassName", function (_ref2) {
459
+ _defineProperty(_assertThisInitialized(_this), "getRowClassName", function (_ref3) {
220
460
  var _rowGetter, _rowGetter2, _clsx;
221
461
 
222
- var index = _ref2.index,
223
- rowGetter = _ref2.rowGetter;
462
+ var index = _ref3.index,
463
+ rowGetter = _ref3.rowGetter;
224
464
  var _this$props2 = _this.props,
225
465
  classes = _this$props2.classes,
226
466
  onRowClick = _this$props2.onRowClick;
@@ -235,12 +475,12 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
235
475
  }
236
476
  });
237
477
 
238
- _defineProperty(_assertThisInitialized(_this), "cellRenderer", function (_ref3) {
478
+ _defineProperty(_assertThisInitialized(_this), "cellRenderer", function (_ref4) {
239
479
  var _rows$rowIndex, _rows$rowIndex2, _clsx2;
240
480
 
241
- var cellData = _ref3.cellData,
242
- columnIndex = _ref3.columnIndex,
243
- rowIndex = _ref3.rowIndex;
481
+ var cellData = _ref4.cellData,
482
+ columnIndex = _ref4.columnIndex,
483
+ rowIndex = _ref4.rowIndex;
244
484
  var _this$props3 = _this.props,
245
485
  columns = _this$props3.columns,
246
486
  classes = _this$props3.classes,
@@ -250,7 +490,7 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
250
490
 
251
491
  var displayedValue = _this.getDisplayValue(columns[columnIndex], cellData);
252
492
 
253
- return /*#__PURE__*/_react["default"].createElement(_TableCell["default"], {
493
+ return /*#__PURE__*/_react["default"].createElement(_material.TableCell, {
254
494
  component: "div",
255
495
  className: (0, _clsx3["default"])(classes.tableCell, classes.flexContainer, (_clsx2 = {}, _clsx2[classes.noClick] = displayedValue === undefined || ((_rows$rowIndex = rows[rowIndex]) === null || _rows$rowIndex === void 0 ? void 0 : _rows$rowIndex.notClickable) === true || onCellClick == null || columns[columnIndex].clickable === undefined || !columns[columnIndex].clickable, _clsx2[classes.tableCellColor] = displayedValue === undefined || onCellClick !== null && !((_rows$rowIndex2 = rows[rowIndex]) === null || _rows$rowIndex2 === void 0 ? void 0 : _rows$rowIndex2.notClickable) === true && columns[columnIndex].clickable !== undefined && columns[columnIndex].clickable, _clsx2)),
256
496
  variant: "body",
@@ -272,55 +512,81 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
272
512
  }));
273
513
  });
274
514
 
275
- _defineProperty(_assertThisInitialized(_this), "headerRenderer", function (_ref4) {
276
- var label = _ref4.label,
277
- columnIndex = _ref4.columnIndex;
515
+ _defineProperty(_assertThisInitialized(_this), "makeSizedTable", function (height, width, sizes, reorderedIndex, _rowGetter3) {
516
+ var _reorderedIndex$lengt;
517
+
278
518
  var _this$props4 = _this.props,
279
- columns = _this$props4.columns,
280
- classes = _this$props4.classes;
281
- return /*#__PURE__*/_react["default"].createElement(_TableCell["default"], {
282
- component: "div",
283
- className: (0, _clsx3["default"])(classes.tableCell, classes.flexContainer, classes.noClick, classes.header),
284
- variant: "head",
285
- style: {
286
- height: _this.state.headerHeight
519
+ sort = _this$props4.sort,
520
+ otherProps = _objectWithoutPropertiesLoose(_this$props4, _excluded);
521
+
522
+ return /*#__PURE__*/_react["default"].createElement(_reactVirtualized.Table, _extends({}, otherProps, {
523
+ height: height,
524
+ width: width,
525
+ rowHeight: otherProps.rowHeight,
526
+ gridStyle: {
527
+ direction: 'inherit'
287
528
  },
288
- align: columns[columnIndex].numeric || false ? 'right' : 'left',
289
- ref: function ref(e) {
290
- return _this._registerObserver(e);
291
- }
292
- }, /*#__PURE__*/_react["default"].createElement("div", {
293
- ref: function ref(element) {
294
- _this._registerHeader(label, element);
529
+ headerHeight: _this.state.headerHeight,
530
+ className: otherProps.classes.table,
531
+ onRowClick: _this.props.onRowClick &&
532
+ /* The {...otherProps} just above would hold the slot onRowClick */
533
+ _this.onClickableRowClick,
534
+ rowCount: (_reorderedIndex$lengt = reorderedIndex === null || reorderedIndex === void 0 ? void 0 : reorderedIndex.length) !== null && _reorderedIndex$lengt !== void 0 ? _reorderedIndex$lengt : otherProps.rows.length,
535
+ rowClassName: function rowClassName(_ref5) {
536
+ var index = _ref5.index;
537
+ return _this.getRowClassName({
538
+ index: index,
539
+ rowGetter: _rowGetter3
540
+ });
541
+ },
542
+ rowGetter: function rowGetter(_ref6) {
543
+ var index = _ref6.index;
544
+ return _rowGetter3(index);
295
545
  }
296
- }, label));
546
+ }), otherProps.columns.map(function (_ref7, index) {
547
+ var dataKey = _ref7.dataKey,
548
+ other = _objectWithoutPropertiesLoose(_ref7, _excluded2);
549
+
550
+ return /*#__PURE__*/_react["default"].createElement(_reactVirtualized.Column, _extends({
551
+ key: dataKey,
552
+ headerRenderer: _this.makeHeaderRenderer(dataKey, index),
553
+ className: otherProps.classes.flexContainer,
554
+ cellRenderer: _this.cellRenderer,
555
+ dataKey: dataKey,
556
+ flexGrow: 1,
557
+ width: sizes[dataKey]
558
+ }, other));
559
+ }));
297
560
  });
298
561
 
299
562
  _defineProperty(_assertThisInitialized(_this), "getCSVFilename", function () {
300
- if (_this.props.name && _this.props.name.length > 0) {
563
+ var _this$props$name;
564
+
565
+ if (((_this$props$name = _this.props.name) === null || _this$props$name === void 0 ? void 0 : _this$props$name.length) > 0) {
301
566
  return _this.props.name.replace(/\s/g, '_');
302
567
  } else {
303
- var filename = '';
304
-
305
- _this.props.columns.forEach(function (col, idx) {
306
- filename += col.label;
307
- if (idx !== _this.props.columns.length - 1) filename += '_';
308
- });
309
-
568
+ var filename = Object.entries(_this.props.columns).map(function (p) {
569
+ return p[1].label;
570
+ }).join('_');
310
571
  return filename;
311
572
  }
312
573
  });
313
574
 
314
575
  _defineProperty(_assertThisInitialized(_this), "getCSVData", function () {
315
- var reorderedIndex = _this.reorderIndex(_this.state.key, _this.state.direction, _this.props.filter, _this.props.rows);
576
+ var _reorderedIndex$viewI, _reorderedIndex$viewI2;
316
577
 
578
+ var reorderedIndex = _this.reorderIndex(_this.state.indirectionVersion, _this.props.rows, _this.props.columns);
579
+
580
+ var rowsCount = (_reorderedIndex$viewI = (_reorderedIndex$viewI2 = reorderedIndex.viewIndexToModel) === null || _reorderedIndex$viewI2 === void 0 ? void 0 : _reorderedIndex$viewI2.length) !== null && _reorderedIndex$viewI !== void 0 ? _reorderedIndex$viewI : _this.props.rows.length;
317
581
  var csvData = [];
318
- reorderedIndex.forEach(function (index) {
582
+
583
+ var _loop2 = function _loop2(index) {
319
584
  var myobj = {};
320
- var sortedRow = _this.props.rows[index];
585
+ var sortedRow = reorderedIndex.rowGetter(index);
586
+ var exportedKeys = _this.props.exportCSVDataKeys;
321
587
 
322
588
  _this.props.columns.forEach(function (col) {
323
- if (_this.props.exportCSVDataKeys !== undefined && _this.props.exportCSVDataKeys.find(function (el) {
589
+ if (exportedKeys === null || exportedKeys === void 0 ? void 0 : exportedKeys.find(function (el) {
324
590
  return el === col.dataKey;
325
591
  })) {
326
592
  myobj[col.dataKey] = sortedRow[col.dataKey];
@@ -328,7 +594,12 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
328
594
  });
329
595
 
330
596
  csvData.push(myobj);
331
- });
597
+ };
598
+
599
+ for (var index = 0; index < rowsCount; ++index) {
600
+ _loop2(index);
601
+ }
602
+
332
603
  return Promise.resolve(csvData);
333
604
  });
334
605
 
@@ -352,17 +623,43 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
352
623
  _this._registerObserver = _this._registerObserver.bind(_assertThisInitialized(_this));
353
624
  _this.headers = (0, _react.createRef)();
354
625
  _this.headers.current = {};
355
- var options = {
626
+ var _options = {
356
627
  root: null,
357
628
  rootMargin: '0px',
358
629
  threshold: 0.1
359
630
  };
360
- _this.observer = new IntersectionObserver(_this._computeHeaderSize, options);
631
+ _this.observer = new IntersectionObserver(_this._computeHeaderSize, _options);
632
+ _this.state = {
633
+ headerHeight: _this.props.headerHeight,
634
+ indexer: initIndexer(_props, null, _this.setVersion),
635
+ indirectionVersion: 0,
636
+ reorderIndex: null,
637
+ popoverAnchorEl: null,
638
+ popoverColKey: null,
639
+ deferredFilterChange: null
640
+ };
361
641
  return _this;
362
642
  }
363
643
 
364
644
  var _proto = MuiVirtualizedTable.prototype;
365
645
 
646
+ _proto.componentDidUpdate = function componentDidUpdate(oldProps) {
647
+ if (oldProps.data !== this.props.data) {
648
+ this.setState({
649
+ indexer: initIndexer(this.props, oldProps)
650
+ });
651
+ }
652
+ };
653
+
654
+ _proto.componentDidMount = function componentDidMount() {
655
+ window.addEventListener('resize', this._computeHeaderSize);
656
+ };
657
+
658
+ _proto.componentWillUnmount = function componentWillUnmount() {
659
+ window.removeEventListener('resize', this._computeHeaderSize);
660
+ this.observer.disconnect();
661
+ };
662
+
366
663
  _proto._registerHeader = function _registerHeader(label, header) {
367
664
  if (header !== null) {
368
665
  this.headers.current[label] = header;
@@ -375,21 +672,34 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
375
672
  }
376
673
  };
377
674
 
675
+ _proto.onFilterParamsChange = function onFilterParamsChange(newVal, colKey) {
676
+ var nonEmpty = newVal.length === 0 ? null : newVal;
677
+
678
+ if (this.props.defersFilterChanges) {
679
+ this.setState({
680
+ deferredFilterChange: {
681
+ newVal: newVal,
682
+ colKey: colKey
683
+ }
684
+ });
685
+ } else if (this.state.indexer.setColFilterUserParams(colKey, nonEmpty)) {
686
+ this.setState({
687
+ indirectionVersion: this.state.indirectionVersion + 1
688
+ });
689
+ }
690
+ };
691
+
378
692
  _proto.getDisplayValue = function getDisplayValue(column, cellData) {
379
693
  var displayedValue;
380
694
 
381
- if (column.numeric) {
382
- if (!isNaN(cellData)) {
383
- if (column.fractionDigits !== undefined && column.fractionDigits !== 0) {
384
- displayedValue = Number(cellData).toFixed(column.fractionDigits);
385
- } else {
386
- displayedValue = Math.round(cellData);
387
- }
388
- } else {
389
- displayedValue = '';
390
- }
391
- } else {
695
+ if (!column.numeric) {
392
696
  displayedValue = cellData;
697
+ } else if (isNaN(cellData)) {
698
+ displayedValue = '';
699
+ } else if (column.fractionDigits === undefined || column.fractionDigits === 0) {
700
+ displayedValue = Math.round(cellData);
701
+ } else {
702
+ displayedValue = Number(cellData).toFixed(column.fractionDigits);
393
703
  }
394
704
 
395
705
  if (column.unit !== undefined) {
@@ -401,17 +711,16 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
401
711
  };
402
712
 
403
713
  _proto._computeHeaderSize = function _computeHeaderSize() {
404
- console.debug('recompute header size');
405
714
  var headers = Object.values(this.headers.current);
406
- if (headers.length === 0) return;
407
- var headerHeight = this.props.headerHeight;
408
- headers.forEach(function (h) {
409
- // https://developer.mozilla.org/fr/docs/Web/API/Element/scrollHeight
410
- // The scrollHeight value is equal to the minimum height the element
411
- // would require in order to fit all the content in the viewport
412
- // without using a vertical scrollbar.
413
- headerHeight = Math.max(h.scrollHeight + DEFAULT_CELL_PADDING, headerHeight);
715
+ if (headers.length === 0) return; // for now keep 'historical' use of scrollHeight,
716
+ // though it can not make a difference from clientHeight,
717
+ // as overflow-y as no scroll value
718
+
719
+ var scrollHeights = headers.map(function (header) {
720
+ return header.scrollHeight;
414
721
  });
722
+ var headerHeight = Math.max(Math.max.apply(Math, scrollHeights) + DEFAULT_CELL_PADDING, this.props.headerHeight // hides (most often) padding override by forcing height
723
+ );
415
724
 
416
725
  if (headerHeight !== this.state.headerHeight) {
417
726
  this.setState({
@@ -420,45 +729,41 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
420
729
  }
421
730
  };
422
731
 
423
- _proto.componentDidMount = function componentDidMount() {
424
- window.addEventListener('resize', this._computeHeaderSize);
425
- };
426
-
427
- _proto.componentWillUnmount = function componentWillUnmount() {
428
- window.removeEventListener('resize', this._computeHeaderSize);
429
- this.observer.disconnect();
430
- };
431
-
432
- _proto.render = function render() {
732
+ _proto.makeHeaderRenderer = function makeHeaderRenderer(dataKey, columnIndex) {
433
733
  var _this2 = this;
434
734
 
435
735
  var _this$props5 = this.props,
436
- name = _this$props5.name,
437
- classes = _this$props5.classes,
438
- rows = _this$props5.rows,
439
736
  columns = _this$props5.columns,
440
- rowHeight = _this$props5.rowHeight,
441
- headerHeight = _this$props5.headerHeight,
442
- rowCount = _this$props5.rowCount,
443
- sortable = _this$props5.sortable,
444
- enableExportCSV = _this$props5.enableExportCSV,
445
- tableProps = _objectWithoutPropertiesLoose(_this$props5, _excluded);
446
-
447
- if (tableProps.onRowClick) {
448
- tableProps.onRowClick = this.onClickableRowClick;
449
- }
450
-
451
- var reorderedIndex = this.reorderIndex(this.state.key, this.state.direction, this.props.filter, this.props.rows);
452
-
453
- var getIndexFor = function getIndexFor(index) {
454
- return index < reorderedIndex.length ? reorderedIndex[index] : 0;
737
+ classes = _this$props5.classes;
738
+ return function (headerProps) {
739
+ return /*#__PURE__*/_react["default"].createElement(_material.TableCell, {
740
+ component: "div",
741
+ className: (0, _clsx3["default"])(classes.tableCell, classes.flexContainer, classes.noClick, classes.header),
742
+ variant: "head",
743
+ style: {
744
+ height: _this2.state.headerHeight
745
+ },
746
+ align: columns[columnIndex].numeric || false ? 'right' : 'left',
747
+ ref: function ref(e) {
748
+ return _this2._registerObserver(e);
749
+ }
750
+ }, _this2.props.sortable ? _this2.sortableHeader(_extends({}, headerProps, {
751
+ columnIndex: columnIndex,
752
+ key: {
753
+ dataKey: dataKey
754
+ }
755
+ })) : _this2.simpleHeaderRenderer(_extends({}, headerProps)));
455
756
  };
757
+ };
456
758
 
457
- var _rowGetter3 = function rowGetter(index) {
458
- return _this2.props.rows[getIndexFor(index)];
459
- };
759
+ _proto.render = function render() {
760
+ var _this3 = this;
761
+
762
+ var _this$reorderIndex = this.reorderIndex(this.state.indirectionVersion, this.props.rows, this.props.columns),
763
+ viewIndexToModel = _this$reorderIndex.viewIndexToModel,
764
+ rowGetter = _this$reorderIndex.rowGetter;
460
765
 
461
- var sizes = this.sizes(this.props.columns, this.props.rows, _rowGetter3);
766
+ var sizes = this.sizes(this.props.columns, this.props.rows, rowGetter);
462
767
  var csvHeaders = this.csvHeaders(this.props.columns, this.props.exportCSVDataKeys);
463
768
  return /*#__PURE__*/_react["default"].createElement("div", {
464
769
  style: {
@@ -466,7 +771,7 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
466
771
  flexDirection: 'column',
467
772
  height: '100%'
468
773
  }
469
- }, enableExportCSV && /*#__PURE__*/_react["default"].createElement("div", {
774
+ }, this.props.enableExportCSV && /*#__PURE__*/_react["default"].createElement("div", {
470
775
  style: {
471
776
  display: 'flex',
472
777
  justifyContent: 'flex-end',
@@ -478,67 +783,30 @@ var MuiVirtualizedTable = /*#__PURE__*/function (_React$PureComponent) {
478
783
  datas: this.getCSVData,
479
784
  columns: csvHeaders,
480
785
  filename: this.getCSVFilename()
481
- }, /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
786
+ }, /*#__PURE__*/_react["default"].createElement(_material.IconButton, {
482
787
  "aria-label": "exportCSVButton",
483
788
  size: "large"
484
789
  }, /*#__PURE__*/_react["default"].createElement(_GetApp["default"], null)))), /*#__PURE__*/_react["default"].createElement("div", {
485
790
  style: {
486
791
  flexGrow: 1
487
792
  }
488
- }, /*#__PURE__*/_react["default"].createElement(_reactVirtualized.AutoSizer, null, function (_ref5) {
489
- var height = _ref5.height,
490
- width = _ref5.width;
491
- return /*#__PURE__*/_react["default"].createElement(_reactVirtualized.Table, _extends({
492
- height: height,
493
- width: width,
494
- rowHeight: rowHeight,
495
- gridStyle: {
496
- direction: 'inherit'
497
- },
498
- headerHeight: _this2.state.headerHeight,
499
- className: classes.table
500
- }, tableProps, {
501
- rowCount: reorderedIndex.length,
502
- rowClassName: function rowClassName(_ref6) {
503
- var index = _ref6.index;
504
- return _this2.getRowClassName({
505
- index: index,
506
- rowGetter: _rowGetter3
507
- });
508
- },
509
- rowGetter: function rowGetter(_ref7) {
510
- var index = _ref7.index;
511
- return _rowGetter3(index);
512
- }
513
- }), columns.map(function (_ref8, index) {
514
- var dataKey = _ref8.dataKey,
515
- other = _objectWithoutPropertiesLoose(_ref8, _excluded2);
516
-
517
- return /*#__PURE__*/_react["default"].createElement(_reactVirtualized.Column, _extends({
518
- key: dataKey,
519
- headerRenderer: function headerRenderer(headerProps) {
520
- if (sortable) {
521
- return _this2.sortableHeader(_extends({}, headerProps, {
522
- width: sizes[dataKey],
523
- columnIndex: index,
524
- key: {
525
- dataKey: dataKey
526
- }
527
- }));
528
- } else {
529
- return _this2.headerRenderer(_extends({}, headerProps, {
530
- columnIndex: index
531
- }));
532
- }
533
- },
534
- className: classes.flexContainer,
535
- cellRenderer: _this2.cellRenderer,
536
- dataKey: dataKey,
537
- flexGrow: 1,
538
- width: sizes[dataKey]
539
- }, other));
540
- }));
541
- })));
793
+ }, /*#__PURE__*/_react["default"].createElement(_reactVirtualized.AutoSizer, null, function (_ref8) {
794
+ var height = _ref8.height,
795
+ width = _ref8.width;
796
+ return _this3.makeSizedTable(height, width, sizes, viewIndexToModel, rowGetter);
797
+ })), this.state.popoverAnchorEl && /*#__PURE__*/_react["default"].createElement(_material.Popover, {
798
+ anchorEl: this.state.popoverAnchorEl,
799
+ anchorOrigin: {
800
+ vertical: 'center',
801
+ horizontal: 'center'
802
+ },
803
+ transformOrigin: {
804
+ vertical: 'center',
805
+ horizontal: 'center'
806
+ },
807
+ onClose: this.closePopover,
808
+ open: !!this.state.popoverAnchorEl
809
+ }, this.makeColumnFilterEditor()));
542
810
  };
543
811
 
544
812
  return MuiVirtualizedTable;
@@ -566,13 +834,14 @@ MuiVirtualizedTable.propTypes = process.env.NODE_ENV !== "production" ? {
566
834
  })).isRequired,
567
835
  enableExportCSV: _propTypes["default"].bool,
568
836
  exportCSVDataKeys: _propTypes["default"].array,
837
+ sort: _propTypes["default"].func,
569
838
  sortable: _propTypes["default"].bool,
839
+ indexer: _propTypes["default"].object,
570
840
  headerHeight: _propTypes["default"].number,
571
841
  onRowClick: _propTypes["default"].func,
572
842
  onCellClick: _propTypes["default"].func,
573
843
  rowHeight: _propTypes["default"].number,
574
- filter: _propTypes["default"].func,
575
- sort: _propTypes["default"].func
844
+ filter: _propTypes["default"].func
576
845
  } : {};
577
846
 
578
847
  var _default = (0, _withStyles["default"])(defaultStyles)(MuiVirtualizedTable);