@sis-cc/dotstatsuite-visions 7.20.9 → 7.20.10

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.
@@ -2,7 +2,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
2
2
 
3
3
  function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
4
4
 
5
- import React, { useEffect, useState, Fragment } from 'react';
5
+ import React, { useState, Fragment } from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import * as R from 'ramda';
8
8
  import cx from 'classnames';
@@ -23,6 +23,7 @@ import HintIcon from '@material-ui/icons/EmojiObjects';
23
23
  import Draggable from 'react-draggable';
24
24
  import { Button, Spotlight, VirtualizedTree } from '..';
25
25
  import { withExpansionTree } from '../VirtualizedTree/withExpansionTree';
26
+ import { withSpotlight } from '../VirtualizedTree/withSpotlight';
26
27
  import { makeStyles } from '@material-ui/core/styles';
27
28
  import singleImg from './images/single-selection.png';
28
29
  import childrenImg from './images/children-selection.png';
@@ -268,67 +269,41 @@ var AdvancedFilterDialog = function AdvancedFilterDialog(props) {
268
269
  disableAccessor = props.disableAccessor,
269
270
  expandAll = props.expandAll,
270
271
  collapseAll = props.collapseAll,
271
- defaultSpotlight = props.defaultSpotlight,
272
+ spotlight = props.spotlight,
273
+ setSpotlight = props.setSpotlight,
272
274
  expandedIds = props.expandedIds,
273
- rest = _objectWithoutProperties(props, ['id', 'title', 'items', 'labelRenderer', 'onClose', 'changeSelection', 'isOpen', 'isNarrow', 'labels', 'disableAccessor', 'expandAll', 'collapseAll', 'defaultSpotlight', 'expandedIds']);
275
+ rest = _objectWithoutProperties(props, ['id', 'title', 'items', 'labelRenderer', 'onClose', 'changeSelection', 'isOpen', 'isNarrow', 'labels', 'disableAccessor', 'expandAll', 'collapseAll', 'spotlight', 'setSpotlight', 'expandedIds']);
274
276
 
275
- var _useState = useState({ term: '' }),
276
- term = _useState[0].term,
277
- setSpotlight = _useState[1];
277
+ var _useState = useState('single'),
278
+ selectionMode = _useState[0],
279
+ setSelectionMode = _useState[1];
278
280
 
279
- var _useState2 = useState('single'),
280
- selectionMode = _useState2[0],
281
- setSelectionMode = _useState2[1];
281
+ var _useState2 = useState(false),
282
+ isOpenSelectionMenu = _useState2[0],
283
+ setIsOpenSelectionMenu = _useState2[1];
282
284
 
283
- var _useState3 = useState(false),
284
- isOpenSelectionMenu = _useState3[0],
285
- setIsOpenSelectionMenu = _useState3[1];
286
-
287
- var _useState4 = useState({}),
288
- selection = _useState4[0],
289
- setSelection = _useState4[1];
285
+ var _useState3 = useState({}),
286
+ selection = _useState3[0],
287
+ setSelection = _useState3[1];
290
288
 
291
289
  var classes = useStyles();
292
290
 
293
- var _useState5 = useState(0),
294
- height = _useState5[0],
295
- setHeight = _useState5[1];
291
+ var _useState4 = useState(0),
292
+ height = _useState4[0],
293
+ setHeight = _useState4[1];
296
294
 
297
295
  var measureRef = React.useCallback(function (node) {
298
296
  if (node !== null) {
299
297
  setHeight(node.getBoundingClientRect().height * 75 / 100);
300
298
  }
301
299
  });
302
- useEffect(function () {
303
- if (!R.isNil(defaultSpotlight) && !R.isEmpty(defaultSpotlight)) {
304
- setSpotlight(defaultSpotlight);
305
- }
306
- }, [defaultSpotlight]);
307
300
 
308
301
  var listHeight = height - 170;
309
-
310
- var groupedItemsByParentId = R.groupBy(R.propOr('#ROOT', 'parentId'), items);
311
-
312
- var recurse = R.filter(function (item) {
313
- var isValidItem = R.isEmpty(term) || R.isNil(term) ? true : R.includes(R.toLower(term), R.toLower(labelRenderer(item)));
314
- if (isValidItem) {
315
- return true;
316
- }
317
- if (R.has(getHierarchicalId(item), groupedItemsByParentId)) {
318
- var filtered = recurse(R.prop(getHierarchicalId(item), groupedItemsByParentId));
319
- if (!R.isEmpty(filtered)) {
320
- return true;
321
- }
322
- }
323
- return false;
324
- });
325
-
326
- var filteredItems = R.isEmpty(term) || R.isNil(term) ? items : recurse(items);
327
302
  var selectionItems = R.map(function (item) {
328
303
  return _extends({}, item, {
329
304
  isSelected: R.has(item.id, selection) ? !item.isSelected : !!item.isSelected
330
305
  });
331
- }, filteredItems);
306
+ }, items);
332
307
  var groupedFilteredItems = R.groupBy(R.propOr('#ROOT', 'parentId'), selectionItems);
333
308
 
334
309
  var selectionOptions = [{
@@ -366,7 +341,7 @@ var AdvancedFilterDialog = function AdvancedFilterDialog(props) {
366
341
  };
367
342
 
368
343
  var handleSubmit = function handleSubmit() {
369
- changeSelection(id, R.values(selection), { expandedIds: expandedIds, spotlight: { term: term } });
344
+ changeSelection(id, R.values(selection), { expandedIds: expandedIds, spotlight: spotlight });
370
345
  setSelection({});
371
346
  setSpotlight({ term: '' });
372
347
  };
@@ -415,7 +390,7 @@ var AdvancedFilterDialog = function AdvancedFilterDialog(props) {
415
390
  React.createElement(Spotlight, {
416
391
  hasClearAll: true,
417
392
  placeholder: R.prop('placeholder', labels),
418
- term: term,
393
+ term: spotlight.term,
419
394
  hasCommit: false,
420
395
  spotlight: { fields: {} },
421
396
  action: setSpotlight
@@ -557,8 +532,9 @@ AdvancedFilterDialog.propTypes = process.env.NODE_ENV !== "production" ? {
557
532
  title: PropTypes.string,
558
533
  expandAll: PropTypes.func,
559
534
  collapseAll: PropTypes.func,
560
- defaultSpotlight: PropTypes.object,
535
+ spotlight: PropTypes.object,
536
+ setSpotlight: PropTypes.func,
561
537
  expandedIds: PropTypes.object
562
538
  } : {};
563
539
 
564
- export default withExpansionTree(AdvancedFilterDialog);
540
+ export default withSpotlight(withExpansionTree(AdvancedFilterDialog));
@@ -1,16 +1,16 @@
1
1
  var _extends = Object.assign || 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; };
2
2
 
3
- import React, { useState, Fragment } from 'react';
3
+ import React, { Fragment } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import * as R from 'ramda';
6
6
  import Container from '@material-ui/core/Container';
7
7
  import PlaylistAddCheckIcon from '@material-ui/icons/PlaylistAddCheck';
8
8
  import { ExpansionPanel, Tag as InternalTag, VerticalButton, Spotlight, VirtualizedTree } from '../';
9
9
  import { withExpansionTree } from '../VirtualizedTree/withExpansionTree';
10
+ import { withSpotlight } from '../VirtualizedTree/withSpotlight';
10
11
  import { useStyles } from '../ScopeList/styles';
11
12
  import { useTheme } from '@material-ui/core';
12
13
  import { getIsRtl } from '../utils';
13
- import { useEffect } from 'react';
14
14
 
15
15
  var getCounter = function getCounter(items, displayAccessor, tagAccessor) {
16
16
  var count = R.pipe(R.filter(R.prop('isSelected')), R.length)(items);
@@ -40,48 +40,23 @@ var HierarchicalFilter = function HierarchicalFilter(props) {
40
40
  tagAccessor = props.tagAccessor,
41
41
  displayAccessor = props.displayAccessor,
42
42
  expandedIds = props.expandedIds,
43
- defaultSpotlight = props.defaultSpotlight;
43
+ spotlight = props.spotlight,
44
+ setSpotlight = props.setSpotlight,
45
+ hasSpotlight = props.hasSpotlight;
44
46
 
45
- var _useState = useState({ term: '' }),
46
- term = _useState[0].term,
47
- setSpotlight = _useState[1];
48
-
49
- useEffect(function () {
50
- if (!R.isNil(defaultSpotlight) && !R.isEmpty(defaultSpotlight)) {
51
- setSpotlight(defaultSpotlight);
52
- }
53
- }, [defaultSpotlight]);
54
47
  var classes = useStyles({ accessibility: accessibility });
55
48
  var theme = useTheme();
56
49
  var isRtl = getIsRtl(theme);
57
50
  var Chip = R.isNil(Tag) ? InternalTag : Tag;
58
51
  var tagValue = getCounter(items, displayAccessor, tagAccessor);
59
- var groupedItemsByParentId = R.groupBy(R.propOr('#ROOT', 'parentId'), items);
60
- var hasSpotligt = R.length(items) >= 8;
61
- var recurse = R.filter(function (item) {
62
- var isValidItem = R.isEmpty(term) || R.isNil(term) ? true : R.includes(R.toLower(term), R.toLower(labelRenderer(item)));
63
- if (isValidItem) {
64
- return true;
65
- }
66
- if (R.has(item.id, groupedItemsByParentId)) {
67
- var filtered = recurse(R.prop(item.id, groupedItemsByParentId));
68
- if (!R.isEmpty(filtered)) {
69
- return true;
70
- }
71
- }
72
- return false;
73
- });
74
-
75
- var filteredItems = R.isEmpty(term) || R.isNil(term) ? items : recurse(items);
76
52
 
77
53
  var onSelect = function onSelect(values) {
78
54
  changeSelection(id, values);
79
55
  };
80
56
 
81
57
  var onAdvancedToggle = function onAdvancedToggle() {
82
- toggleBulk({ expandedIds: expandedIds, spotlight: { term: term } });
58
+ toggleBulk({ expandedIds: expandedIds, spotlight: spotlight });
83
59
  };
84
-
85
60
  return React.createElement(
86
61
  ExpansionPanel,
87
62
  _extends({
@@ -97,17 +72,17 @@ var HierarchicalFilter = function HierarchicalFilter(props) {
97
72
  React.createElement(
98
73
  Container,
99
74
  { disableGutters: true, className: classes.spotlightContainer },
100
- hasSpotligt && React.createElement(Spotlight, {
75
+ hasSpotlight && React.createElement(Spotlight, {
101
76
  className: { container: classes.middle },
102
77
  fullWidth: true,
103
78
  hasClearAll: true,
104
79
  placeholder: R.prop('placeholder', labels),
105
- term: term,
80
+ term: spotlight.term,
106
81
  hasCommit: false,
107
82
  spotlight: { fields: {} },
108
83
  action: setSpotlight
109
84
  }),
110
- R.is(Function, toggleBulk) && hasSpotligt && React.createElement(
85
+ R.is(Function, toggleBulk) && hasSpotlight && React.createElement(
111
86
  VerticalButton,
112
87
  {
113
88
  'aria-label': R.prop('advancedSelection')(labels),
@@ -122,10 +97,9 @@ var HierarchicalFilter = function HierarchicalFilter(props) {
122
97
  Chip,
123
98
  { items: items },
124
99
  tagValue
125
- ),
126
- isBlank: R.isEmpty(items)
100
+ )
127
101
  }, expansionPanelProps),
128
- React.createElement(VirtualizedTree, _extends({}, props, { items: filteredItems, changeSelection: onSelect, isRtl: isRtl }))
102
+ React.createElement(VirtualizedTree, _extends({}, props, { items: items, changeSelection: onSelect, isRtl: isRtl }))
129
103
  );
130
104
  };
131
105
 
@@ -152,7 +126,9 @@ HierarchicalFilter.propTypes = process.env.NODE_ENV !== "production" ? {
152
126
  toggleBulk: PropTypes.func,
153
127
  tagAccessor: PropTypes.func,
154
128
  expandedIds: PropTypes.object,
155
- defaultSpotlight: PropTypes.object
129
+ spotlight: PropTypes.object,
130
+ setSpotlight: PropTypes.func,
131
+ hasSpotlight: PropTypes.bool
156
132
  } : {};
157
133
 
158
- export default withExpansionTree(HierarchicalFilter);
134
+ export default withSpotlight(withExpansionTree(HierarchicalFilter));
@@ -87,6 +87,10 @@ var VirtualizedTree = function VirtualizedTree(props) {
87
87
  isMouseDown = _useState4[0],
88
88
  setIsMouseDown = _useState4[1];
89
89
 
90
+ var _useState5 = useState(null),
91
+ lastItemId = _useState5[0],
92
+ setLastItemId = _useState5[1];
93
+
90
94
  var _useMemo = useMemo(function () {
91
95
  var indexedItemsById = R.indexBy(getHierarchicalId, items);
92
96
  var groupedItemsByParentId = R.groupBy(R.propOr('#ROOT', 'parentId'), items);
@@ -107,13 +111,33 @@ var VirtualizedTree = function VirtualizedTree(props) {
107
111
  setSelectIds(R.omit(ids, selectIds));
108
112
  } else {
109
113
  setSelectIds(_extends({}, selectIds, R.indexBy(R.identity, ids)));
114
+ setLastItemId(id);
110
115
  }
111
116
  };
112
117
  var shiftSelect = function shiftSelect(index) {
118
+ var selectRange = function selectRange(indexes, isSelected) {
119
+ var _selectIds = R.pipe(R.slice(Math.min.apply(Math, indexes), Math.max.apply(Math, indexes) + 1), function (ids) {
120
+ return R.props(ids, indexedItemsById);
121
+ }, R.map(getItemScope), R.unnest, R.filter(function (v) {
122
+ return v.isSelected === isSelected;
123
+ }), R.map(getHierarchicalId), R.indexBy(R.identity))(list);
124
+ setShiftIndexes(indexes);
125
+ setSelectIds(_selectIds);
126
+ };
113
127
  if (R.isEmpty(shiftIndexes)) {
114
128
  var item = R.pipe(R.nth(index), function (id) {
115
129
  return R.prop(id, indexedItemsById);
116
130
  })(list);
131
+ if (!R.isNil(lastItemId)) {
132
+ var lastItem = R.prop(lastItemId, indexedItemsById);
133
+ var lastItemIndex = R.findIndex(function (v) {
134
+ return v === lastItem.id;
135
+ }, list);
136
+ if (lastItem.isSelected !== item.isSelected && lastItemIndex !== -1) {
137
+ selectRange([lastItemIndex, index], item.isSelected);
138
+ return;
139
+ }
140
+ }
117
141
  var ids = R.pipe(getItemScope, R.filter(function (v) {
118
142
  return v.isSelected === item.isSelected;
119
143
  }), R.map(getHierarchicalId), R.indexBy(R.identity))(item);
@@ -123,18 +147,10 @@ var VirtualizedTree = function VirtualizedTree(props) {
123
147
  setShiftIndexes([]);
124
148
  setSelectIds({});
125
149
  } else {
126
- var indexes = [R.head(shiftIndexes), index];
127
- var isSelected = void 0;
128
- var _selectIds = R.pipe(R.slice(Math.min.apply(Math, indexes), Math.max.apply(Math, indexes) + 1), function (ids) {
129
- return R.props(ids, indexedItemsById);
130
- }, function (items) {
131
- isSelected = R.pipe(R.head, R.prop('isSelected'))(items);
132
- return items;
133
- }, R.map(getItemScope), R.unnest, R.filter(function (v) {
134
- return v.isSelected === isSelected;
135
- }), R.map(getHierarchicalId), R.indexBy(R.identity))(list);
136
- setShiftIndexes(indexes);
137
- setSelectIds(_selectIds);
150
+ var firstItem = R.pipe(R.nth(R.head(shiftIndexes)), function (id) {
151
+ return R.prop(id, indexedItemsById);
152
+ })(list);
153
+ selectRange([R.head(shiftIndexes), index], firstItem.isSelected);
138
154
  }
139
155
  };
140
156
  var apply = function apply() {
@@ -151,6 +167,9 @@ var VirtualizedTree = function VirtualizedTree(props) {
151
167
  return {
152
168
  onMouseUp: isMouseDown ? function () {
153
169
  apply();
170
+ if (!R.isEmpty(selectIds)) {
171
+ setLastItemId(id);
172
+ }
154
173
  } : null,
155
174
  onMouseDown: function onMouseDown(e) {
156
175
  if (e.ctrlKey || e.shiftKey) {
@@ -182,10 +201,7 @@ var VirtualizedTree = function VirtualizedTree(props) {
182
201
  apply();
183
202
  }
184
203
  };
185
- var isItemSelected = function isItemSelected(item, index) {
186
- if (!R.isEmpty(shiftIndexes) && index >= Math.min.apply(Math, shiftIndexes) && index <= Math.max.apply(Math, shiftIndexes)) {
187
- return !item.isSelected;
188
- }
204
+ var isItemSelected = function isItemSelected(item) {
189
205
  if (!R.isEmpty(selectIds) && R.has(getHierarchicalId(item), selectIds)) {
190
206
  return !item.isSelected;
191
207
  }
@@ -273,7 +289,7 @@ var VirtualizedTree = function VirtualizedTree(props) {
273
289
  isRtl: isRtl,
274
290
  isDisabled: R.is(Function, disableAccessor) ? disableAccessor(item) : false,
275
291
  eventsCallbacks: eventsCallbacks,
276
- isSelected: isItemSelected(item, index),
292
+ isSelected: isItemSelected(item),
277
293
  HTMLRenderer: HTMLRenderer,
278
294
  classes: classes,
279
295
  labels: labels,
@@ -17,14 +17,24 @@ var withExpansionTree = function withExpansionTree(Component) {
17
17
  expandedIds = _useState[0],
18
18
  setExpandedIds = _useState[1];
19
19
 
20
+ var _useState2 = useState([]),
21
+ itemsIds = _useState2[0],
22
+ setItemsIds = _useState2[1];
23
+
24
+ useEffect(function () {
25
+ var ids = R.map(getHierarchicalId, items);
26
+ if (!R.isEmpty(R.symmetricDifference(ids, itemsIds))) setItemsIds(ids);
27
+ }, [items]);
28
+
29
+ useEffect(function () {
30
+ setExpandedIds(R.indexBy(R.identity, itemsIds));
31
+ }, [itemsIds]);
32
+
20
33
  useEffect(function () {
21
34
  if (!R.isNil(defaultExpandedIds)) {
22
35
  setExpandedIds(defaultExpandedIds);
23
- } else {
24
- var ids = R.pipe(R.map(getHierarchicalId), R.indexBy(R.identity))(items);
25
- setExpandedIds(ids);
26
36
  }
27
- }, [items, defaultExpandedIds]);
37
+ }, [defaultExpandedIds]);
28
38
 
29
39
  var expand = function expand(id) {
30
40
  setExpandedIds(R.assoc(id, id, expandedIds));
@@ -35,8 +45,7 @@ var withExpansionTree = function withExpansionTree(Component) {
35
45
  };
36
46
 
37
47
  var expandAll = function expandAll() {
38
- var ids = R.pipe(R.map(getHierarchicalId), R.indexBy(R.identity))(items);
39
- setExpandedIds(ids);
48
+ setExpandedIds(R.indexBy(R.identity, itemsIds));
40
49
  };
41
50
 
42
51
  var collapseAll = function collapseAll() {
@@ -0,0 +1,66 @@
1
+ var _extends = Object.assign || 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; };
2
+
3
+ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
4
+
5
+ /* eslint react/prop-types: 0 */
6
+ import * as R from 'ramda';
7
+ import React, { useEffect, useMemo, useState } from 'react';
8
+ import { getHierarchicalId } from './VirtualizedTree';
9
+
10
+ export var spotlightFilter = function spotlightFilter(term) {
11
+ var labelRenderer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : R.prop('label');
12
+ return function (items) {
13
+ if (R.isEmpty(term) || R.isNil(term)) {
14
+ return items;
15
+ }
16
+
17
+ var groupedItemsByParentId = R.groupBy(R.propOr('#ROOT', 'parentId'), items);
18
+ var recurse = R.filter(function (item) {
19
+ var isValidItem = R.isEmpty(term) || R.isNil(term) ? true : R.includes(R.toLower(term), R.toLower(labelRenderer(item)));
20
+ if (isValidItem) {
21
+ return true;
22
+ }
23
+ if (R.has(getHierarchicalId(item), groupedItemsByParentId)) {
24
+ var filtered = recurse(R.prop(getHierarchicalId(item), groupedItemsByParentId));
25
+ if (!R.isEmpty(filtered)) {
26
+ return true;
27
+ }
28
+ }
29
+ return false;
30
+ });
31
+
32
+ return recurse(items);
33
+ };
34
+ };
35
+
36
+ var withSpotlight = function withSpotlight(Component) {
37
+ return function (_ref) {
38
+ var items = _ref.items,
39
+ defaultSpotlight = _ref.defaultSpotlight,
40
+ labelRenderer = _ref.labelRenderer,
41
+ rest = _objectWithoutProperties(_ref, ['items', 'defaultSpotlight', 'labelRenderer']);
42
+
43
+ var _useState = useState({ term: '' }),
44
+ term = _useState[0].term,
45
+ setSpotlight = _useState[1];
46
+
47
+ useEffect(function () {
48
+ if (!R.isNil(defaultSpotlight) && !R.isEmpty(defaultSpotlight)) {
49
+ setSpotlight(defaultSpotlight);
50
+ }
51
+ }, [defaultSpotlight]);
52
+
53
+ var filteredItems = useMemo(function () {
54
+ return spotlightFilter(term, labelRenderer)(items);
55
+ }, [term, items]);
56
+
57
+ return React.createElement(Component, _extends({}, rest, {
58
+ items: filteredItems,
59
+ labelRenderer: labelRenderer,
60
+ hasSpotlight: R.length(items) >= 8,
61
+ spotlight: { term: term },
62
+ setSpotlight: setSpotlight
63
+ }));
64
+ };
65
+ };
66
+ export { withSpotlight };
@@ -83,6 +83,8 @@ var _ = require('..');
83
83
 
84
84
  var _withExpansionTree = require('../VirtualizedTree/withExpansionTree');
85
85
 
86
+ var _withSpotlight = require('../VirtualizedTree/withSpotlight');
87
+
86
88
  var _styles = require('@material-ui/core/styles');
87
89
 
88
90
  var _singleSelection = require('./images/single-selection.png');
@@ -363,67 +365,41 @@ var AdvancedFilterDialog = function AdvancedFilterDialog(props) {
363
365
  disableAccessor = props.disableAccessor,
364
366
  expandAll = props.expandAll,
365
367
  collapseAll = props.collapseAll,
366
- defaultSpotlight = props.defaultSpotlight,
368
+ spotlight = props.spotlight,
369
+ setSpotlight = props.setSpotlight,
367
370
  expandedIds = props.expandedIds,
368
- rest = _objectWithoutProperties(props, ['id', 'title', 'items', 'labelRenderer', 'onClose', 'changeSelection', 'isOpen', 'isNarrow', 'labels', 'disableAccessor', 'expandAll', 'collapseAll', 'defaultSpotlight', 'expandedIds']);
369
-
370
- var _useState = (0, _react.useState)({ term: '' }),
371
- term = _useState[0].term,
372
- setSpotlight = _useState[1];
371
+ rest = _objectWithoutProperties(props, ['id', 'title', 'items', 'labelRenderer', 'onClose', 'changeSelection', 'isOpen', 'isNarrow', 'labels', 'disableAccessor', 'expandAll', 'collapseAll', 'spotlight', 'setSpotlight', 'expandedIds']);
373
372
 
374
- var _useState2 = (0, _react.useState)('single'),
375
- selectionMode = _useState2[0],
376
- setSelectionMode = _useState2[1];
373
+ var _useState = (0, _react.useState)('single'),
374
+ selectionMode = _useState[0],
375
+ setSelectionMode = _useState[1];
377
376
 
378
- var _useState3 = (0, _react.useState)(false),
379
- isOpenSelectionMenu = _useState3[0],
380
- setIsOpenSelectionMenu = _useState3[1];
377
+ var _useState2 = (0, _react.useState)(false),
378
+ isOpenSelectionMenu = _useState2[0],
379
+ setIsOpenSelectionMenu = _useState2[1];
381
380
 
382
- var _useState4 = (0, _react.useState)({}),
383
- selection = _useState4[0],
384
- setSelection = _useState4[1];
381
+ var _useState3 = (0, _react.useState)({}),
382
+ selection = _useState3[0],
383
+ setSelection = _useState3[1];
385
384
 
386
385
  var classes = useStyles();
387
386
 
388
- var _useState5 = (0, _react.useState)(0),
389
- height = _useState5[0],
390
- setHeight = _useState5[1];
387
+ var _useState4 = (0, _react.useState)(0),
388
+ height = _useState4[0],
389
+ setHeight = _useState4[1];
391
390
 
392
391
  var measureRef = _react2.default.useCallback(function (node) {
393
392
  if (node !== null) {
394
393
  setHeight(node.getBoundingClientRect().height * 75 / 100);
395
394
  }
396
395
  });
397
- (0, _react.useEffect)(function () {
398
- if (!R.isNil(defaultSpotlight) && !R.isEmpty(defaultSpotlight)) {
399
- setSpotlight(defaultSpotlight);
400
- }
401
- }, [defaultSpotlight]);
402
396
 
403
397
  var listHeight = height - 170;
404
-
405
- var groupedItemsByParentId = R.groupBy(R.propOr('#ROOT', 'parentId'), items);
406
-
407
- var recurse = R.filter(function (item) {
408
- var isValidItem = R.isEmpty(term) || R.isNil(term) ? true : R.includes(R.toLower(term), R.toLower(labelRenderer(item)));
409
- if (isValidItem) {
410
- return true;
411
- }
412
- if (R.has((0, _VirtualizedTree.getHierarchicalId)(item), groupedItemsByParentId)) {
413
- var filtered = recurse(R.prop((0, _VirtualizedTree.getHierarchicalId)(item), groupedItemsByParentId));
414
- if (!R.isEmpty(filtered)) {
415
- return true;
416
- }
417
- }
418
- return false;
419
- });
420
-
421
- var filteredItems = R.isEmpty(term) || R.isNil(term) ? items : recurse(items);
422
398
  var selectionItems = R.map(function (item) {
423
399
  return _extends({}, item, {
424
400
  isSelected: R.has(item.id, selection) ? !item.isSelected : !!item.isSelected
425
401
  });
426
- }, filteredItems);
402
+ }, items);
427
403
  var groupedFilteredItems = R.groupBy(R.propOr('#ROOT', 'parentId'), selectionItems);
428
404
 
429
405
  var selectionOptions = [{
@@ -461,7 +437,7 @@ var AdvancedFilterDialog = function AdvancedFilterDialog(props) {
461
437
  };
462
438
 
463
439
  var handleSubmit = function handleSubmit() {
464
- changeSelection(id, R.values(selection), { expandedIds: expandedIds, spotlight: { term: term } });
440
+ changeSelection(id, R.values(selection), { expandedIds: expandedIds, spotlight: spotlight });
465
441
  setSelection({});
466
442
  setSpotlight({ term: '' });
467
443
  };
@@ -510,7 +486,7 @@ var AdvancedFilterDialog = function AdvancedFilterDialog(props) {
510
486
  _react2.default.createElement(_.Spotlight, {
511
487
  hasClearAll: true,
512
488
  placeholder: R.prop('placeholder', labels),
513
- term: term,
489
+ term: spotlight.term,
514
490
  hasCommit: false,
515
491
  spotlight: { fields: {} },
516
492
  action: setSpotlight
@@ -652,8 +628,9 @@ AdvancedFilterDialog.propTypes = process.env.NODE_ENV !== "production" ? {
652
628
  title: _propTypes2.default.string,
653
629
  expandAll: _propTypes2.default.func,
654
630
  collapseAll: _propTypes2.default.func,
655
- defaultSpotlight: _propTypes2.default.object,
631
+ spotlight: _propTypes2.default.object,
632
+ setSpotlight: _propTypes2.default.func,
656
633
  expandedIds: _propTypes2.default.object
657
634
  } : {};
658
635
 
659
- exports.default = (0, _withExpansionTree.withExpansionTree)(AdvancedFilterDialog);
636
+ exports.default = (0, _withSpotlight.withSpotlight)((0, _withExpansionTree.withExpansionTree)(AdvancedFilterDialog));
@@ -28,6 +28,8 @@ var _ = require('../');
28
28
 
29
29
  var _withExpansionTree = require('../VirtualizedTree/withExpansionTree');
30
30
 
31
+ var _withSpotlight = require('../VirtualizedTree/withSpotlight');
32
+
31
33
  var _styles = require('../ScopeList/styles');
32
34
 
33
35
  var _core = require('@material-ui/core');
@@ -66,48 +68,23 @@ var HierarchicalFilter = function HierarchicalFilter(props) {
66
68
  tagAccessor = props.tagAccessor,
67
69
  displayAccessor = props.displayAccessor,
68
70
  expandedIds = props.expandedIds,
69
- defaultSpotlight = props.defaultSpotlight;
70
-
71
- var _useState = (0, _react.useState)({ term: '' }),
72
- term = _useState[0].term,
73
- setSpotlight = _useState[1];
71
+ spotlight = props.spotlight,
72
+ setSpotlight = props.setSpotlight,
73
+ hasSpotlight = props.hasSpotlight;
74
74
 
75
- (0, _react.useEffect)(function () {
76
- if (!R.isNil(defaultSpotlight) && !R.isEmpty(defaultSpotlight)) {
77
- setSpotlight(defaultSpotlight);
78
- }
79
- }, [defaultSpotlight]);
80
75
  var classes = (0, _styles.useStyles)({ accessibility: accessibility });
81
76
  var theme = (0, _core.useTheme)();
82
77
  var isRtl = (0, _utils.getIsRtl)(theme);
83
78
  var Chip = R.isNil(Tag) ? _.Tag : Tag;
84
79
  var tagValue = getCounter(items, displayAccessor, tagAccessor);
85
- var groupedItemsByParentId = R.groupBy(R.propOr('#ROOT', 'parentId'), items);
86
- var hasSpotligt = R.length(items) >= 8;
87
- var recurse = R.filter(function (item) {
88
- var isValidItem = R.isEmpty(term) || R.isNil(term) ? true : R.includes(R.toLower(term), R.toLower(labelRenderer(item)));
89
- if (isValidItem) {
90
- return true;
91
- }
92
- if (R.has(item.id, groupedItemsByParentId)) {
93
- var filtered = recurse(R.prop(item.id, groupedItemsByParentId));
94
- if (!R.isEmpty(filtered)) {
95
- return true;
96
- }
97
- }
98
- return false;
99
- });
100
-
101
- var filteredItems = R.isEmpty(term) || R.isNil(term) ? items : recurse(items);
102
80
 
103
81
  var onSelect = function onSelect(values) {
104
82
  changeSelection(id, values);
105
83
  };
106
84
 
107
85
  var onAdvancedToggle = function onAdvancedToggle() {
108
- toggleBulk({ expandedIds: expandedIds, spotlight: { term: term } });
86
+ toggleBulk({ expandedIds: expandedIds, spotlight: spotlight });
109
87
  };
110
-
111
88
  return _react2.default.createElement(
112
89
  _.ExpansionPanel,
113
90
  _extends({
@@ -123,17 +100,17 @@ var HierarchicalFilter = function HierarchicalFilter(props) {
123
100
  _react2.default.createElement(
124
101
  _Container2.default,
125
102
  { disableGutters: true, className: classes.spotlightContainer },
126
- hasSpotligt && _react2.default.createElement(_.Spotlight, {
103
+ hasSpotlight && _react2.default.createElement(_.Spotlight, {
127
104
  className: { container: classes.middle },
128
105
  fullWidth: true,
129
106
  hasClearAll: true,
130
107
  placeholder: R.prop('placeholder', labels),
131
- term: term,
108
+ term: spotlight.term,
132
109
  hasCommit: false,
133
110
  spotlight: { fields: {} },
134
111
  action: setSpotlight
135
112
  }),
136
- R.is(Function, toggleBulk) && hasSpotligt && _react2.default.createElement(
113
+ R.is(Function, toggleBulk) && hasSpotlight && _react2.default.createElement(
137
114
  _.VerticalButton,
138
115
  {
139
116
  'aria-label': R.prop('advancedSelection')(labels),
@@ -148,10 +125,9 @@ var HierarchicalFilter = function HierarchicalFilter(props) {
148
125
  Chip,
149
126
  { items: items },
150
127
  tagValue
151
- ),
152
- isBlank: R.isEmpty(items)
128
+ )
153
129
  }, expansionPanelProps),
154
- _react2.default.createElement(_.VirtualizedTree, _extends({}, props, { items: filteredItems, changeSelection: onSelect, isRtl: isRtl }))
130
+ _react2.default.createElement(_.VirtualizedTree, _extends({}, props, { items: items, changeSelection: onSelect, isRtl: isRtl }))
155
131
  );
156
132
  };
157
133
 
@@ -178,8 +154,10 @@ HierarchicalFilter.propTypes = process.env.NODE_ENV !== "production" ? {
178
154
  toggleBulk: _propTypes2.default.func,
179
155
  tagAccessor: _propTypes2.default.func,
180
156
  expandedIds: _propTypes2.default.object,
181
- defaultSpotlight: _propTypes2.default.object
157
+ spotlight: _propTypes2.default.object,
158
+ setSpotlight: _propTypes2.default.func,
159
+ hasSpotlight: _propTypes2.default.bool
182
160
  } : {};
183
161
 
184
- exports.default = (0, _withExpansionTree.withExpansionTree)(HierarchicalFilter);
162
+ exports.default = (0, _withSpotlight.withSpotlight)((0, _withExpansionTree.withExpansionTree)(HierarchicalFilter));
185
163
  module.exports = exports['default'];
@@ -125,6 +125,10 @@ var VirtualizedTree = function VirtualizedTree(props) {
125
125
  isMouseDown = _useState4[0],
126
126
  setIsMouseDown = _useState4[1];
127
127
 
128
+ var _useState5 = (0, _react.useState)(null),
129
+ lastItemId = _useState5[0],
130
+ setLastItemId = _useState5[1];
131
+
128
132
  var _useMemo = (0, _react.useMemo)(function () {
129
133
  var indexedItemsById = R.indexBy(getHierarchicalId, items);
130
134
  var groupedItemsByParentId = R.groupBy(R.propOr('#ROOT', 'parentId'), items);
@@ -145,13 +149,33 @@ var VirtualizedTree = function VirtualizedTree(props) {
145
149
  setSelectIds(R.omit(ids, selectIds));
146
150
  } else {
147
151
  setSelectIds(_extends({}, selectIds, R.indexBy(R.identity, ids)));
152
+ setLastItemId(id);
148
153
  }
149
154
  };
150
155
  var shiftSelect = function shiftSelect(index) {
156
+ var selectRange = function selectRange(indexes, isSelected) {
157
+ var _selectIds = R.pipe(R.slice(Math.min.apply(Math, indexes), Math.max.apply(Math, indexes) + 1), function (ids) {
158
+ return R.props(ids, indexedItemsById);
159
+ }, R.map(getItemScope), R.unnest, R.filter(function (v) {
160
+ return v.isSelected === isSelected;
161
+ }), R.map(getHierarchicalId), R.indexBy(R.identity))(list);
162
+ setShiftIndexes(indexes);
163
+ setSelectIds(_selectIds);
164
+ };
151
165
  if (R.isEmpty(shiftIndexes)) {
152
166
  var item = R.pipe(R.nth(index), function (id) {
153
167
  return R.prop(id, indexedItemsById);
154
168
  })(list);
169
+ if (!R.isNil(lastItemId)) {
170
+ var lastItem = R.prop(lastItemId, indexedItemsById);
171
+ var lastItemIndex = R.findIndex(function (v) {
172
+ return v === lastItem.id;
173
+ }, list);
174
+ if (lastItem.isSelected !== item.isSelected && lastItemIndex !== -1) {
175
+ selectRange([lastItemIndex, index], item.isSelected);
176
+ return;
177
+ }
178
+ }
155
179
  var ids = R.pipe(getItemScope, R.filter(function (v) {
156
180
  return v.isSelected === item.isSelected;
157
181
  }), R.map(getHierarchicalId), R.indexBy(R.identity))(item);
@@ -161,18 +185,10 @@ var VirtualizedTree = function VirtualizedTree(props) {
161
185
  setShiftIndexes([]);
162
186
  setSelectIds({});
163
187
  } else {
164
- var indexes = [R.head(shiftIndexes), index];
165
- var isSelected = void 0;
166
- var _selectIds = R.pipe(R.slice(Math.min.apply(Math, indexes), Math.max.apply(Math, indexes) + 1), function (ids) {
167
- return R.props(ids, indexedItemsById);
168
- }, function (items) {
169
- isSelected = R.pipe(R.head, R.prop('isSelected'))(items);
170
- return items;
171
- }, R.map(getItemScope), R.unnest, R.filter(function (v) {
172
- return v.isSelected === isSelected;
173
- }), R.map(getHierarchicalId), R.indexBy(R.identity))(list);
174
- setShiftIndexes(indexes);
175
- setSelectIds(_selectIds);
188
+ var firstItem = R.pipe(R.nth(R.head(shiftIndexes)), function (id) {
189
+ return R.prop(id, indexedItemsById);
190
+ })(list);
191
+ selectRange([R.head(shiftIndexes), index], firstItem.isSelected);
176
192
  }
177
193
  };
178
194
  var apply = function apply() {
@@ -189,6 +205,9 @@ var VirtualizedTree = function VirtualizedTree(props) {
189
205
  return {
190
206
  onMouseUp: isMouseDown ? function () {
191
207
  apply();
208
+ if (!R.isEmpty(selectIds)) {
209
+ setLastItemId(id);
210
+ }
192
211
  } : null,
193
212
  onMouseDown: function onMouseDown(e) {
194
213
  if (e.ctrlKey || e.shiftKey) {
@@ -220,10 +239,7 @@ var VirtualizedTree = function VirtualizedTree(props) {
220
239
  apply();
221
240
  }
222
241
  };
223
- var isItemSelected = function isItemSelected(item, index) {
224
- if (!R.isEmpty(shiftIndexes) && index >= Math.min.apply(Math, shiftIndexes) && index <= Math.max.apply(Math, shiftIndexes)) {
225
- return !item.isSelected;
226
- }
242
+ var isItemSelected = function isItemSelected(item) {
227
243
  if (!R.isEmpty(selectIds) && R.has(getHierarchicalId(item), selectIds)) {
228
244
  return !item.isSelected;
229
245
  }
@@ -311,7 +327,7 @@ var VirtualizedTree = function VirtualizedTree(props) {
311
327
  isRtl: isRtl,
312
328
  isDisabled: R.is(Function, disableAccessor) ? disableAccessor(item) : false,
313
329
  eventsCallbacks: eventsCallbacks,
314
- isSelected: isItemSelected(item, index),
330
+ isSelected: isItemSelected(item),
315
331
  HTMLRenderer: HTMLRenderer,
316
332
  classes: classes,
317
333
  labels: labels,
@@ -32,14 +32,24 @@ var withExpansionTree = function withExpansionTree(Component) {
32
32
  expandedIds = _useState[0],
33
33
  setExpandedIds = _useState[1];
34
34
 
35
+ var _useState2 = (0, _react.useState)([]),
36
+ itemsIds = _useState2[0],
37
+ setItemsIds = _useState2[1];
38
+
39
+ (0, _react.useEffect)(function () {
40
+ var ids = R.map(_VirtualizedTree.getHierarchicalId, items);
41
+ if (!R.isEmpty(R.symmetricDifference(ids, itemsIds))) setItemsIds(ids);
42
+ }, [items]);
43
+
44
+ (0, _react.useEffect)(function () {
45
+ setExpandedIds(R.indexBy(R.identity, itemsIds));
46
+ }, [itemsIds]);
47
+
35
48
  (0, _react.useEffect)(function () {
36
49
  if (!R.isNil(defaultExpandedIds)) {
37
50
  setExpandedIds(defaultExpandedIds);
38
- } else {
39
- var ids = R.pipe(R.map(_VirtualizedTree.getHierarchicalId), R.indexBy(R.identity))(items);
40
- setExpandedIds(ids);
41
51
  }
42
- }, [items, defaultExpandedIds]);
52
+ }, [defaultExpandedIds]);
43
53
 
44
54
  var expand = function expand(id) {
45
55
  setExpandedIds(R.assoc(id, id, expandedIds));
@@ -50,8 +60,7 @@ var withExpansionTree = function withExpansionTree(Component) {
50
60
  };
51
61
 
52
62
  var expandAll = function expandAll() {
53
- var ids = R.pipe(R.map(_VirtualizedTree.getHierarchicalId), R.indexBy(R.identity))(items);
54
- setExpandedIds(ids);
63
+ setExpandedIds(R.indexBy(R.identity, itemsIds));
55
64
  };
56
65
 
57
66
  var collapseAll = function collapseAll() {
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+ exports.withSpotlight = exports.spotlightFilter = undefined;
5
+
6
+ var _extends = Object.assign || 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; };
7
+
8
+ var _ramda = require('ramda');
9
+
10
+ var R = _interopRequireWildcard(_ramda);
11
+
12
+ var _react = require('react');
13
+
14
+ var _react2 = _interopRequireDefault(_react);
15
+
16
+ var _VirtualizedTree = require('./VirtualizedTree');
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
21
+
22
+ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } /* eslint react/prop-types: 0 */
23
+
24
+
25
+ var spotlightFilter = exports.spotlightFilter = function spotlightFilter(term) {
26
+ var labelRenderer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : R.prop('label');
27
+ return function (items) {
28
+ if (R.isEmpty(term) || R.isNil(term)) {
29
+ return items;
30
+ }
31
+
32
+ var groupedItemsByParentId = R.groupBy(R.propOr('#ROOT', 'parentId'), items);
33
+ var recurse = R.filter(function (item) {
34
+ var isValidItem = R.isEmpty(term) || R.isNil(term) ? true : R.includes(R.toLower(term), R.toLower(labelRenderer(item)));
35
+ if (isValidItem) {
36
+ return true;
37
+ }
38
+ if (R.has((0, _VirtualizedTree.getHierarchicalId)(item), groupedItemsByParentId)) {
39
+ var filtered = recurse(R.prop((0, _VirtualizedTree.getHierarchicalId)(item), groupedItemsByParentId));
40
+ if (!R.isEmpty(filtered)) {
41
+ return true;
42
+ }
43
+ }
44
+ return false;
45
+ });
46
+
47
+ return recurse(items);
48
+ };
49
+ };
50
+
51
+ var withSpotlight = function withSpotlight(Component) {
52
+ return function (_ref) {
53
+ var items = _ref.items,
54
+ defaultSpotlight = _ref.defaultSpotlight,
55
+ labelRenderer = _ref.labelRenderer,
56
+ rest = _objectWithoutProperties(_ref, ['items', 'defaultSpotlight', 'labelRenderer']);
57
+
58
+ var _useState = (0, _react.useState)({ term: '' }),
59
+ term = _useState[0].term,
60
+ setSpotlight = _useState[1];
61
+
62
+ (0, _react.useEffect)(function () {
63
+ if (!R.isNil(defaultSpotlight) && !R.isEmpty(defaultSpotlight)) {
64
+ setSpotlight(defaultSpotlight);
65
+ }
66
+ }, [defaultSpotlight]);
67
+
68
+ var filteredItems = (0, _react.useMemo)(function () {
69
+ return spotlightFilter(term, labelRenderer)(items);
70
+ }, [term, items]);
71
+
72
+ return _react2.default.createElement(Component, _extends({}, rest, {
73
+ items: filteredItems,
74
+ labelRenderer: labelRenderer,
75
+ hasSpotlight: R.length(items) >= 8,
76
+ spotlight: { term: term },
77
+ setSpotlight: setSpotlight
78
+ }));
79
+ };
80
+ };
81
+ exports.withSpotlight = withSpotlight;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sis-cc/dotstatsuite-visions",
3
- "version": "7.20.9",
3
+ "version": "7.20.10",
4
4
  "description": "Library of visual components",
5
5
  "author": "OECD",
6
6
  "homepage": "https://visions-qa.siscc.org/#o",