linear-react-components-ui 0.4.75-beta.1 → 0.4.75-beta.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.
- package/lib/permissionValidations.js +1 -1
- package/lib/treeview/Node.js +35 -11
- package/lib/treeview/index.js +94 -16
- package/package.json +1 -1
|
@@ -59,7 +59,7 @@ var actionsOnPermissionDenied = function actionsOnPermissionDenied(permissionAtt
|
|
|
59
59
|
|
|
60
60
|
var result = {};
|
|
61
61
|
options.forEach(function (option) {
|
|
62
|
-
result[option] = hasPermission ? false : option ===
|
|
62
|
+
result[option] = hasPermission ? false : option === permissionsAttr[0].onDenied;
|
|
63
63
|
});
|
|
64
64
|
return result;
|
|
65
65
|
};
|
package/lib/treeview/Node.js
CHANGED
|
@@ -13,6 +13,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
13
13
|
|
|
14
14
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
15
15
|
|
|
16
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
17
|
+
|
|
16
18
|
var _checkbox = _interopRequireDefault(require("../checkbox"));
|
|
17
19
|
|
|
18
20
|
var _icons = _interopRequireDefault(require("../icons"));
|
|
@@ -91,7 +93,9 @@ var TreeNode = /*#__PURE__*/function (_Component) {
|
|
|
91
93
|
tabIndex: 0,
|
|
92
94
|
role: "button",
|
|
93
95
|
className: "opencloseicon",
|
|
94
|
-
onClick:
|
|
96
|
+
onClick: function onClick() {
|
|
97
|
+
return _this.openCloseTree(node);
|
|
98
|
+
}
|
|
95
99
|
}, /*#__PURE__*/_react["default"].createElement(_icons["default"], {
|
|
96
100
|
name: _this.state.isVisible ? 'up' : 'down',
|
|
97
101
|
size: 10
|
|
@@ -105,10 +109,23 @@ var TreeNode = /*#__PURE__*/function (_Component) {
|
|
|
105
109
|
configurable: true,
|
|
106
110
|
enumerable: true,
|
|
107
111
|
writable: true,
|
|
108
|
-
value: function value() {
|
|
109
|
-
_this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
value: function value(node) {
|
|
113
|
+
var _this$state = _this.state,
|
|
114
|
+
isVisible = _this$state.isVisible,
|
|
115
|
+
wasOpened = _this$state.wasOpened;
|
|
116
|
+
var handlerOnNodeOpen = _this.props.handlerOnNodeOpen;
|
|
117
|
+
var nextState = {
|
|
118
|
+
isVisible: !isVisible
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (!wasOpened && handlerOnNodeOpen) {
|
|
122
|
+
nextState = _extends({}, nextState, {
|
|
123
|
+
wasOpened: true
|
|
124
|
+
});
|
|
125
|
+
handlerOnNodeOpen(node);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_this.setState(nextState);
|
|
112
129
|
}
|
|
113
130
|
});
|
|
114
131
|
Object.defineProperty(_assertThisInitialized(_this), "handleShowNodeElements", {
|
|
@@ -116,9 +133,9 @@ var TreeNode = /*#__PURE__*/function (_Component) {
|
|
|
116
133
|
enumerable: true,
|
|
117
134
|
writable: true,
|
|
118
135
|
value: function value() {
|
|
119
|
-
var _this$
|
|
120
|
-
showNodeElements = _this$
|
|
121
|
-
keepMenuOpened = _this$
|
|
136
|
+
var _this$state2 = _this.state,
|
|
137
|
+
showNodeElements = _this$state2.showNodeElements,
|
|
138
|
+
keepMenuOpened = _this$state2.keepMenuOpened;
|
|
122
139
|
if (!showNodeElements) _this.setState({
|
|
123
140
|
showNodeElements: true
|
|
124
141
|
});else if (showNodeElements && !keepMenuOpened) {
|
|
@@ -153,8 +170,9 @@ var TreeNode = /*#__PURE__*/function (_Component) {
|
|
|
153
170
|
|
|
154
171
|
if (onNodeElementClick) {
|
|
155
172
|
newProps = _extends({}, newProps, {
|
|
156
|
-
onClick: function onClick() {
|
|
157
|
-
|
|
173
|
+
onClick: function onClick(e) {
|
|
174
|
+
onNodeElementClick(node);
|
|
175
|
+
if (e.stopPropagation) e.stopPropagation();
|
|
158
176
|
},
|
|
159
177
|
onNodeElementClick: null
|
|
160
178
|
});
|
|
@@ -231,7 +249,10 @@ var TreeNode = /*#__PURE__*/function (_Component) {
|
|
|
231
249
|
validations.forEach(function (validation) {
|
|
232
250
|
var validator = validation.validator,
|
|
233
251
|
applyBehavior = validation.applyBehavior;
|
|
234
|
-
|
|
252
|
+
|
|
253
|
+
if (_lodash["default"].isEmpty(elementBehavior) && validator && validator(node)) {
|
|
254
|
+
elementBehavior = options[applyBehavior] || options.unvisible;
|
|
255
|
+
}
|
|
235
256
|
});
|
|
236
257
|
}
|
|
237
258
|
|
|
@@ -241,6 +262,7 @@ var TreeNode = /*#__PURE__*/function (_Component) {
|
|
|
241
262
|
_this.labelRef = /*#__PURE__*/_react["default"].createRef();
|
|
242
263
|
_this.state = {
|
|
243
264
|
isVisible: context.startNodesOpened,
|
|
265
|
+
wasOpened: context.startNodesOpened,
|
|
244
266
|
showNodeElements: false,
|
|
245
267
|
keepMenuOpened: false
|
|
246
268
|
};
|
|
@@ -376,6 +398,7 @@ TreeNode.propTypes = {
|
|
|
376
398
|
nodeToolbarElements: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].object), _propTypes["default"].element, _propTypes["default"].object]),
|
|
377
399
|
nodeMenuButtonSize: _propTypes["default"].oneOf(['mini', 'small', 'medium', 'large', 'default']),
|
|
378
400
|
onNodeClick: _propTypes["default"].func,
|
|
401
|
+
handlerOnNodeOpen: _propTypes["default"].func,
|
|
379
402
|
nodeElementsValidations: _propTypes["default"].object
|
|
380
403
|
};
|
|
381
404
|
TreeNode.defaultProps = {
|
|
@@ -387,6 +410,7 @@ TreeNode.defaultProps = {
|
|
|
387
410
|
nodeToolbarElements: undefined,
|
|
388
411
|
nodeMenuButtonSize: 'small',
|
|
389
412
|
onNodeClick: undefined,
|
|
413
|
+
handlerOnNodeOpen: undefined,
|
|
390
414
|
nodeElementsValidations: undefined
|
|
391
415
|
};
|
|
392
416
|
TreeNode.contextType = _constants.TreeviewContext;
|
package/lib/treeview/index.js
CHANGED
|
@@ -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), "
|
|
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
|
|
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
|
|
199
|
+
var requiredIds = isPreviousParentSelected || selectedSiblingsIds.length > 0 ? _toConsumableArray(requiredAncestryIds) : [].concat(_toConsumableArray(requiredAncestryIds), [parentId]);
|
|
176
200
|
|
|
177
|
-
if (
|
|
178
|
-
return _this.
|
|
201
|
+
if (selectedSiblingsIds.length === 0 && !isPreviousParentSelected) {
|
|
202
|
+
return _this.returnRequiredAncestryIds(parentId, requiredIds, parentId);
|
|
179
203
|
}
|
|
180
204
|
}
|
|
181
205
|
|
|
182
|
-
return
|
|
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.
|
|
259
|
+
var ancestryIds = _this.returnRequiredAncestryIds(nodeId);
|
|
237
260
|
|
|
238
261
|
var remainRequiredParentsIds = requiredParentsIds.filter(function (id) {
|
|
239
262
|
return !ancestryIds.includes(id);
|
|
@@ -325,6 +348,25 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
325
348
|
});
|
|
326
349
|
}
|
|
327
350
|
});
|
|
351
|
+
Object.defineProperty(_assertThisInitialized(_this), "handleOnNodeOpen", {
|
|
352
|
+
configurable: true,
|
|
353
|
+
enumerable: true,
|
|
354
|
+
writable: true,
|
|
355
|
+
value: function value(node) {
|
|
356
|
+
var id = node.id;
|
|
357
|
+
var onNodeOpen = _this.props.onNodeOpen;
|
|
358
|
+
var alreadyOpenedIds = _this.state.alreadyOpenedIds;
|
|
359
|
+
|
|
360
|
+
if (!alreadyOpenedIds.includes(id) && onNodeOpen) {
|
|
361
|
+
alreadyOpenedIds = [].concat(_toConsumableArray(alreadyOpenedIds), [id]);
|
|
362
|
+
onNodeOpen(node);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
_this.setState({
|
|
366
|
+
alreadyOpenedIds: alreadyOpenedIds
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
});
|
|
328
370
|
Object.defineProperty(_assertThisInitialized(_this), "handleCheck", {
|
|
329
371
|
configurable: true,
|
|
330
372
|
enumerable: true,
|
|
@@ -340,9 +382,9 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
340
382
|
|
|
341
383
|
if (isParent && isHandlingSelectedIds && allowCheckAllChildren) {
|
|
342
384
|
if (allowCheckAllAncestry) {
|
|
343
|
-
var _this$
|
|
344
|
-
updatedIdsWithAncestryIds = _this$
|
|
345
|
-
requiredParentsIds = _this$
|
|
385
|
+
var _this$checkAllAncestr2 = _this.checkAllAncestry(nodeId, codigos, true),
|
|
386
|
+
updatedIdsWithAncestryIds = _this$checkAllAncestr2.updatedIdsWithAncestryIds,
|
|
387
|
+
requiredParentsIds = _this$checkAllAncestr2.requiredParentsIds;
|
|
346
388
|
|
|
347
389
|
var updatedIdsWithChidlrenIds = _this.checkAllChildren(nodeId, true, requiredParentsIds);
|
|
348
390
|
|
|
@@ -444,7 +486,8 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
444
486
|
nodeToolbarElements: nodeToolbarElements,
|
|
445
487
|
nodeElementsValidations: nodeElementsValidations,
|
|
446
488
|
nodeMenuButtonSize: nodeMenuButtonSize,
|
|
447
|
-
onNodeClick: onNodeClick
|
|
489
|
+
onNodeClick: onNodeClick,
|
|
490
|
+
handlerOnNodeOpen: _this.handleOnNodeOpen
|
|
448
491
|
}, childrenIds.length > 0 && node.itens.map(function (nodeitem) {
|
|
449
492
|
return _this.buildTree(nodeitem, node.id, ids);
|
|
450
493
|
}));
|
|
@@ -453,9 +496,11 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
453
496
|
_this.idsWithChildren = {};
|
|
454
497
|
_this.state = {
|
|
455
498
|
data: _this.props.data,
|
|
499
|
+
propSelectedIds: _this.props.selectedIds,
|
|
456
500
|
selectedIds: _this.props.selectedIds,
|
|
457
501
|
isHandlingSelectedIds: false,
|
|
458
|
-
requiredParentsIds: []
|
|
502
|
+
requiredParentsIds: [],
|
|
503
|
+
alreadyOpenedIds: []
|
|
459
504
|
};
|
|
460
505
|
return _this;
|
|
461
506
|
}
|
|
@@ -465,6 +510,18 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
465
510
|
value: function componentDidMount() {
|
|
466
511
|
this.buildTree(this.state.data, undefined, this.idsWithChildren);
|
|
467
512
|
}
|
|
513
|
+
}, {
|
|
514
|
+
key: "componentDidUpdate",
|
|
515
|
+
value: function componentDidUpdate(prevProps, prevState) {
|
|
516
|
+
var _this$state3 = this.state,
|
|
517
|
+
selectedIds = _this$state3.selectedIds,
|
|
518
|
+
propSelectedIds = _this$state3.propSelectedIds;
|
|
519
|
+
var allowCheckAllAncestry = this.props.allowCheckAllAncestry;
|
|
520
|
+
|
|
521
|
+
var isSameSelectedIds = _lodash["default"].isEqual(propSelectedIds.sort(), prevState.propSelectedIds.sort());
|
|
522
|
+
|
|
523
|
+
if (allowCheckAllAncestry && !isSameSelectedIds) this.handleNewSelectedIds(selectedIds);
|
|
524
|
+
}
|
|
468
525
|
}, {
|
|
469
526
|
key: "render",
|
|
470
527
|
value: function render() {
|
|
@@ -483,6 +540,25 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
483
540
|
className: "treeviewcontainer ".concat(bordered && '-bordered')
|
|
484
541
|
}, this.buildTree(data))));
|
|
485
542
|
}
|
|
543
|
+
}], [{
|
|
544
|
+
key: "getDerivedStateFromProps",
|
|
545
|
+
value: function getDerivedStateFromProps(props, state) {
|
|
546
|
+
var data = props.data,
|
|
547
|
+
selectedIds = props.selectedIds;
|
|
548
|
+
var propSelectedIds = state.propSelectedIds;
|
|
549
|
+
|
|
550
|
+
var isSameSelectedIds = _lodash["default"].isEqual(propSelectedIds.sort(), selectedIds.sort());
|
|
551
|
+
|
|
552
|
+
if (data !== state.data || !isSameSelectedIds) {
|
|
553
|
+
return {
|
|
554
|
+
data: data,
|
|
555
|
+
selectedIds: selectedIds,
|
|
556
|
+
propSelectedIds: selectedIds
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
486
562
|
}]);
|
|
487
563
|
|
|
488
564
|
return TreeView;
|
|
@@ -509,6 +585,7 @@ TreeView.propTypes = {
|
|
|
509
585
|
nodeToolbarElements: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].object), _propTypes["default"].element, _propTypes["default"].object]),
|
|
510
586
|
nodeMenuButtonSize: _propTypes["default"].oneOf(['mini', 'small', 'medium', 'large', 'default']),
|
|
511
587
|
onNodeClick: _propTypes["default"].func,
|
|
588
|
+
onNodeOpen: _propTypes["default"].func,
|
|
512
589
|
nodeElementsValidations: _propTypes["default"].object
|
|
513
590
|
};
|
|
514
591
|
TreeView.defaultProps = {
|
|
@@ -528,6 +605,7 @@ TreeView.defaultProps = {
|
|
|
528
605
|
nodeToolbarElements: undefined,
|
|
529
606
|
nodeMenuButtonSize: 'small',
|
|
530
607
|
onNodeClick: undefined,
|
|
608
|
+
onNodeOpen: undefined,
|
|
531
609
|
nodeElementsValidations: undefined
|
|
532
610
|
};
|
|
533
611
|
var _default = TreeView;
|