linear-react-components-ui 0.4.75-beta.5 → 0.4.75-beta.9

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.
@@ -93,7 +93,9 @@ var TreeNode = /*#__PURE__*/function (_Component) {
93
93
  tabIndex: 0,
94
94
  role: "button",
95
95
  className: "opencloseicon",
96
- onClick: _this.openCloseTree
96
+ onClick: function onClick() {
97
+ return _this.openCloseTree(node);
98
+ }
97
99
  }, /*#__PURE__*/_react["default"].createElement(_icons["default"], {
98
100
  name: _this.state.isVisible ? 'up' : 'down',
99
101
  size: 10
@@ -107,10 +109,23 @@ var TreeNode = /*#__PURE__*/function (_Component) {
107
109
  configurable: true,
108
110
  enumerable: true,
109
111
  writable: true,
110
- value: function value() {
111
- _this.setState({
112
- isVisible: !_this.state.isVisible
113
- });
112
+ value: function value(node) {
113
+ var _this$state = _this.state,
114
+ isVisible = _this$state.isVisible,
115
+ wasOpened = _this$state.wasOpened;
116
+ var onNodeOpen = _this.props.onNodeOpen;
117
+ var nextState = {
118
+ isVisible: !isVisible
119
+ };
120
+
121
+ if (!wasOpened && onNodeOpen) {
122
+ nextState = _extends({}, nextState, {
123
+ wasOpened: true
124
+ });
125
+ onNodeOpen(node);
126
+ }
127
+
128
+ _this.setState(nextState);
114
129
  }
115
130
  });
116
131
  Object.defineProperty(_assertThisInitialized(_this), "handleShowNodeElements", {
@@ -118,9 +133,9 @@ var TreeNode = /*#__PURE__*/function (_Component) {
118
133
  enumerable: true,
119
134
  writable: true,
120
135
  value: function value() {
121
- var _this$state = _this.state,
122
- showNodeElements = _this$state.showNodeElements,
123
- keepMenuOpened = _this$state.keepMenuOpened;
136
+ var _this$state2 = _this.state,
137
+ showNodeElements = _this$state2.showNodeElements,
138
+ keepMenuOpened = _this$state2.keepMenuOpened;
124
139
  if (!showNodeElements) _this.setState({
125
140
  showNodeElements: true
126
141
  });else if (showNodeElements && !keepMenuOpened) {
@@ -155,8 +170,9 @@ var TreeNode = /*#__PURE__*/function (_Component) {
155
170
 
156
171
  if (onNodeElementClick) {
157
172
  newProps = _extends({}, newProps, {
158
- onClick: function onClick() {
159
- return onNodeElementClick(node);
173
+ onClick: function onClick(e) {
174
+ onNodeElementClick(node);
175
+ if (e.stopPropagation) e.stopPropagation();
160
176
  },
161
177
  onNodeElementClick: null
162
178
  });
@@ -246,6 +262,7 @@ var TreeNode = /*#__PURE__*/function (_Component) {
246
262
  _this.labelRef = /*#__PURE__*/_react["default"].createRef();
247
263
  _this.state = {
248
264
  isVisible: context.startNodesOpened,
265
+ wasOpened: context.startNodesOpened,
249
266
  showNodeElements: false,
250
267
  keepMenuOpened: false
251
268
  };
@@ -381,6 +398,7 @@ TreeNode.propTypes = {
381
398
  nodeToolbarElements: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].object), _propTypes["default"].element, _propTypes["default"].object]),
382
399
  nodeMenuButtonSize: _propTypes["default"].oneOf(['mini', 'small', 'medium', 'large', 'default']),
383
400
  onNodeClick: _propTypes["default"].func,
401
+ onNodeOpen: _propTypes["default"].func,
384
402
  nodeElementsValidations: _propTypes["default"].object
385
403
  };
386
404
  TreeNode.defaultProps = {
@@ -392,6 +410,7 @@ TreeNode.defaultProps = {
392
410
  nodeToolbarElements: undefined,
393
411
  nodeMenuButtonSize: 'small',
394
412
  onNodeClick: undefined,
413
+ onNodeOpen: undefined,
395
414
  nodeElementsValidations: undefined
396
415
  };
397
416
  TreeNode.contextType = _constants.TreeviewContext;
@@ -95,6 +95,28 @@ var TreeView = /*#__PURE__*/function (_Component) {
95
95
  });
96
96
  }
97
97
  });
98
+ Object.defineProperty(_assertThisInitialized(_this), "handleNewSelectedIds", {
99
+ configurable: true,
100
+ enumerable: true,
101
+ writable: true,
102
+ value: function value(selectedIds) {
103
+ var requiredIds = [];
104
+ var newSelectedIds = [];
105
+ selectedIds.forEach(function (id) {
106
+ var _this$checkAllAncestr = _this.checkAllAncestry(id, [], true, false),
107
+ requiredParentsIds = _this$checkAllAncestr.requiredParentsIds,
108
+ updatedIdsWithAncestryIds = _this$checkAllAncestr.updatedIdsWithAncestryIds;
109
+
110
+ newSelectedIds = [].concat(_toConsumableArray(newSelectedIds), _toConsumableArray(updatedIdsWithAncestryIds));
111
+ requiredIds = [].concat(_toConsumableArray(requiredIds), _toConsumableArray(requiredParentsIds));
112
+ });
113
+
114
+ _this.setState({
115
+ requiredParentsIds: _lodash["default"].uniq(requiredIds),
116
+ selectedIds: _lodash["default"].uniq(newSelectedIds)
117
+ });
118
+ }
119
+ });
98
120
  Object.defineProperty(_assertThisInitialized(_this), "returnParentId", {
99
121
  configurable: true,
100
122
  enumerable: true,
@@ -149,14 +171,14 @@ var TreeView = /*#__PURE__*/function (_Component) {
149
171
  } : nodeChildrenIds;
150
172
  }
151
173
  });
152
- Object.defineProperty(_assertThisInitialized(_this), "returnAncestryIdsAllowedToUncheck", {
174
+ Object.defineProperty(_assertThisInitialized(_this), "returnRequiredAncestryIds", {
153
175
  configurable: true,
154
176
  enumerable: true,
155
177
  writable: true,
156
178
  value: function value(nodeId) {
157
- var parentsIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
179
+ var requiredAncestryIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
158
180
  var previousParentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
159
- var selectedSiblingsIds;
181
+ var selectedSiblingsIds = [];
160
182
  var selectedIds = _this.state.selectedIds;
161
183
 
162
184
  var parentId = _this.returnParentId(nodeId);
@@ -166,20 +188,22 @@ var TreeView = /*#__PURE__*/function (_Component) {
166
188
  return childId !== nodeId;
167
189
  });
168
190
 
191
+ var isPreviousParentSelected = selectedIds.includes(previousParentId);
192
+
169
193
  if (nodeSiblingsIds && nodeSiblingsIds.length > 0) {
170
194
  selectedSiblingsIds = selectedIds.filter(function (id) {
171
195
  return nodeSiblingsIds.includes(id);
172
196
  });
173
197
  }
174
198
 
175
- var result = selectedSiblingsIds && selectedSiblingsIds.length > 0 ? _toConsumableArray(parentsIds) : [].concat(_toConsumableArray(parentsIds), [parentId]);
199
+ var requiredIds = isPreviousParentSelected || selectedSiblingsIds.length > 0 ? _toConsumableArray(requiredAncestryIds) : [].concat(_toConsumableArray(requiredAncestryIds), [parentId]);
176
200
 
177
- if (!selectedSiblingsIds || selectedSiblingsIds && selectedSiblingsIds.length === 0 && !selectedIds.includes(previousParentId)) {
178
- return _this.returnAncestryIdsAllowedToUncheck(parentId, result, parentId);
201
+ if (selectedSiblingsIds.length === 0 && !isPreviousParentSelected) {
202
+ return _this.returnRequiredAncestryIds(parentId, requiredIds, parentId);
179
203
  }
180
204
  }
181
205
 
182
- return parentsIds;
206
+ return requiredAncestryIds;
183
207
  }
184
208
  });
185
209
  Object.defineProperty(_assertThisInitialized(_this), "toggleCheckChildren", {
@@ -202,6 +226,7 @@ var TreeView = /*#__PURE__*/function (_Component) {
202
226
  writable: true,
203
227
  value: function value(nodeId, codigos) {
204
228
  var returnRequiredParentsIds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
229
+ var updateState = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
205
230
  var selectedIds = _this.state.selectedIds;
206
231
  var requiredParentsIds = _this.state.requiredParentsIds;
207
232
 
@@ -215,11 +240,9 @@ var TreeView = /*#__PURE__*/function (_Component) {
215
240
  });
216
241
  selectedIds = [].concat(_toConsumableArray(selectedIds), _toConsumableArray(codigos), _toConsumableArray(notSelectedAncestryIds));
217
242
  requiredParentsIds = [].concat(_toConsumableArray(requiredParentsIds), _toConsumableArray(notRequiredAncestryIds));
218
-
219
- _this.setState({
243
+ if (updateState) _this.setState({
220
244
  requiredParentsIds: requiredParentsIds
221
245
  });
222
-
223
246
  return !returnRequiredParentsIds ? selectedIds : {
224
247
  updatedIdsWithAncestryIds: selectedIds,
225
248
  requiredParentsIds: requiredParentsIds
@@ -233,7 +256,7 @@ var TreeView = /*#__PURE__*/function (_Component) {
233
256
  value: function value(nodeId, codigos, requiredParentsIds) {
234
257
  var selectedIds = _this.state.selectedIds;
235
258
 
236
- var ancestryIds = _this.returnAncestryIdsAllowedToUncheck(nodeId);
259
+ var ancestryIds = _this.returnRequiredAncestryIds(nodeId);
237
260
 
238
261
  var remainRequiredParentsIds = requiredParentsIds.filter(function (id) {
239
262
  return !ancestryIds.includes(id);
@@ -340,9 +363,9 @@ var TreeView = /*#__PURE__*/function (_Component) {
340
363
 
341
364
  if (isParent && isHandlingSelectedIds && allowCheckAllChildren) {
342
365
  if (allowCheckAllAncestry) {
343
- var _this$checkAllAncestr = _this.checkAllAncestry(nodeId, codigos, true),
344
- updatedIdsWithAncestryIds = _this$checkAllAncestr.updatedIdsWithAncestryIds,
345
- requiredParentsIds = _this$checkAllAncestr.requiredParentsIds;
366
+ var _this$checkAllAncestr2 = _this.checkAllAncestry(nodeId, codigos, true),
367
+ updatedIdsWithAncestryIds = _this$checkAllAncestr2.updatedIdsWithAncestryIds,
368
+ requiredParentsIds = _this$checkAllAncestr2.requiredParentsIds;
346
369
 
347
370
  var updatedIdsWithChidlrenIds = _this.checkAllChildren(nodeId, true, requiredParentsIds);
348
371
 
@@ -419,7 +442,8 @@ var TreeView = /*#__PURE__*/function (_Component) {
419
442
  onNodeClick = _this$props3.onNodeClick,
420
443
  nodeElementsValidations = _this$props3.nodeElementsValidations,
421
444
  nodeToolbarElements = _this$props3.nodeToolbarElements,
422
- nodeMenuButtonSize = _this$props3.nodeMenuButtonSize;
445
+ nodeMenuButtonSize = _this$props3.nodeMenuButtonSize,
446
+ onNodeOpen = _this$props3.onNodeOpen;
423
447
  var childrenIds = [];
424
448
 
425
449
  if (node.itens && node.itens.length > 0) {
@@ -444,7 +468,8 @@ var TreeView = /*#__PURE__*/function (_Component) {
444
468
  nodeToolbarElements: nodeToolbarElements,
445
469
  nodeElementsValidations: nodeElementsValidations,
446
470
  nodeMenuButtonSize: nodeMenuButtonSize,
447
- onNodeClick: onNodeClick
471
+ onNodeClick: onNodeClick,
472
+ onNodeOpen: onNodeOpen
448
473
  }, childrenIds.length > 0 && node.itens.map(function (nodeitem) {
449
474
  return _this.buildTree(nodeitem, node.id, ids);
450
475
  }));
@@ -453,6 +478,7 @@ var TreeView = /*#__PURE__*/function (_Component) {
453
478
  _this.idsWithChildren = {};
454
479
  _this.state = {
455
480
  data: _this.props.data,
481
+ propSelectedIds: _this.props.selectedIds,
456
482
  selectedIds: _this.props.selectedIds,
457
483
  isHandlingSelectedIds: false,
458
484
  requiredParentsIds: []
@@ -465,6 +491,18 @@ var TreeView = /*#__PURE__*/function (_Component) {
465
491
  value: function componentDidMount() {
466
492
  this.buildTree(this.state.data, undefined, this.idsWithChildren);
467
493
  }
494
+ }, {
495
+ key: "componentDidUpdate",
496
+ value: function componentDidUpdate(prevProps, prevState) {
497
+ var _this$state3 = this.state,
498
+ selectedIds = _this$state3.selectedIds,
499
+ propSelectedIds = _this$state3.propSelectedIds;
500
+ var allowCheckAllAncestry = this.props.allowCheckAllAncestry;
501
+
502
+ var isSameSelectedIds = _lodash["default"].isEqual(propSelectedIds.sort(), prevState.propSelectedIds.sort());
503
+
504
+ if (allowCheckAllAncestry && !isSameSelectedIds) this.handleNewSelectedIds(selectedIds);
505
+ }
468
506
  }, {
469
507
  key: "render",
470
508
  value: function render() {
@@ -486,10 +524,20 @@ var TreeView = /*#__PURE__*/function (_Component) {
486
524
  }], [{
487
525
  key: "getDerivedStateFromProps",
488
526
  value: function getDerivedStateFromProps(props, state) {
489
- var data = props.data;
490
- if (data !== state.data) return {
491
- data: data
492
- };
527
+ var data = props.data,
528
+ selectedIds = props.selectedIds;
529
+ var propSelectedIds = state.propSelectedIds;
530
+
531
+ var isSameSelectedIds = _lodash["default"].isEqual(propSelectedIds.sort(), selectedIds.sort());
532
+
533
+ if (data !== state.data || !isSameSelectedIds) {
534
+ return {
535
+ data: data,
536
+ selectedIds: selectedIds,
537
+ propSelectedIds: selectedIds
538
+ };
539
+ }
540
+
493
541
  return null;
494
542
  }
495
543
  }]);
@@ -518,6 +566,7 @@ TreeView.propTypes = {
518
566
  nodeToolbarElements: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].object), _propTypes["default"].element, _propTypes["default"].object]),
519
567
  nodeMenuButtonSize: _propTypes["default"].oneOf(['mini', 'small', 'medium', 'large', 'default']),
520
568
  onNodeClick: _propTypes["default"].func,
569
+ onNodeOpen: _propTypes["default"].func,
521
570
  nodeElementsValidations: _propTypes["default"].object
522
571
  };
523
572
  TreeView.defaultProps = {
@@ -537,6 +586,7 @@ TreeView.defaultProps = {
537
586
  nodeToolbarElements: undefined,
538
587
  nodeMenuButtonSize: 'small',
539
588
  onNodeClick: undefined,
589
+ onNodeOpen: undefined,
540
590
  nodeElementsValidations: undefined
541
591
  };
542
592
  var _default = TreeView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linear-react-components-ui",
3
- "version": "0.4.75-beta.5",
3
+ "version": "0.4.75-beta.9",
4
4
  "description": "Linear Sistemas ReactJs Components",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {