iguazio.dashboard-react-controls 0.0.18 → 0.0.20

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.
Files changed (32) hide show
  1. package/dist/components/Backdrop/Backdrop.js +16 -0
  2. package/dist/components/ConfirmDialog/ConfirmDialog.js +16 -0
  3. package/dist/components/FormChipCell/FormChip/FormChip.js +25 -51
  4. package/dist/components/FormChipCell/FormChip/formChip.scss +0 -12
  5. package/dist/components/FormChipCell/FormChipCell.js +174 -53
  6. package/dist/components/FormChipCell/FormChipCellView.js +99 -87
  7. package/dist/components/FormChipCell/NewChipForm/NewChipForm.js +153 -45
  8. package/dist/components/FormChipCell/NewChipForm/newChipForm.scss +3 -0
  9. package/dist/components/FormChipCell/formChipCell.scss +11 -0
  10. package/dist/components/FormChipCell/formChipCell.util.js +11 -0
  11. package/dist/components/FormInput/InputNumberButtons/InputNumberButtons.js +16 -0
  12. package/dist/components/FormTextarea/FormTextarea.js +4 -4
  13. package/dist/components/FormTextarea/formTextarea.scss +1 -0
  14. package/dist/components/Modal/Modal.js +17 -33
  15. package/dist/components/RoundedIcon/RoundedIcon.js +16 -0
  16. package/dist/components/Tip/Tip.js +5 -3
  17. package/dist/components/Tooltip/Tooltip.test.js +16 -0
  18. package/dist/components/TooltipTemplate/ProducerTooltipTemplate.js +16 -0
  19. package/dist/components/TooltipTemplate/TextTooltipTemplate.js +16 -0
  20. package/dist/components/Wizard/WizardSteps/WizardSteps.js +16 -0
  21. package/dist/constants.js +17 -0
  22. package/dist/elements/HiddenChipsBlock/HiddenChipsBlock.js +25 -45
  23. package/dist/elements/OptionsMenu/OptionsMenu.js +16 -0
  24. package/dist/elements/SelectOption/SelectOption.js +16 -0
  25. package/dist/elements/ValidationTemplate/ValidationTemplate.js +16 -0
  26. package/dist/hooks/useDetectOutsideClick.js +17 -0
  27. package/dist/types.js +16 -0
  28. package/dist/utils/common.util.js +31 -2
  29. package/dist/utils/form.util.js +32 -2
  30. package/dist/utils/generateChipsList.util.js +18 -1
  31. package/dist/utils/getFirstScrollableParent.util.js +17 -0
  32. package/package.json +1 -1
@@ -17,6 +17,22 @@ var _jsxRuntime = require("react/jsx-runtime");
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
+ /*
21
+ Copyright 2022 Iguazio Systems Ltd.
22
+ Licensed under the Apache License, Version 2.0 (the "License") with
23
+ an addition restriction as set forth herein. You may not use this
24
+ file except in compliance with the License. You may obtain a copy of
25
+ the License at http://www.apache.org/licenses/LICENSE-2.0.
26
+ Unless required by applicable law or agreed to in writing, software
27
+ distributed under the License is distributed on an "AS IS" BASIS,
28
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
29
+ implied. See the License for the specific language governing
30
+ permissions and limitations under the License.
31
+ In addition, you may not use the software for any purposes that are
32
+ illegal under applicable law, and the grant of the foregoing license
33
+ under the Apache 2.0 license is conditioned upon your compliance with
34
+ such restriction.
35
+ */
20
36
  var Backdrop = function Backdrop(_ref) {
21
37
  var _ref$duration = _ref.duration,
22
38
  duration = _ref$duration === void 0 ? 300 : _ref$duration,
@@ -23,6 +23,22 @@ var _jsxRuntime = require("react/jsx-runtime");
23
23
 
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
26
+ /*
27
+ Copyright 2022 Iguazio Systems Ltd.
28
+ Licensed under the Apache License, Version 2.0 (the "License") with
29
+ an addition restriction as set forth herein. You may not use this
30
+ file except in compliance with the License. You may obtain a copy of
31
+ the License at http://www.apache.org/licenses/LICENSE-2.0.
32
+ Unless required by applicable law or agreed to in writing, software
33
+ distributed under the License is distributed on an "AS IS" BASIS,
34
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
35
+ implied. See the License for the specific language governing
36
+ permissions and limitations under the License.
37
+ In addition, you may not use the software for any purposes that are
38
+ illegal under applicable law, and the grant of the foregoing license
39
+ under the Apache 2.0 license is conditioned upon your compliance with
40
+ such restriction.
41
+ */
26
42
  var ConfirmDialog = function ConfirmDialog(_ref) {
27
43
  var cancelButton = _ref.cancelButton,
28
44
  className = _ref.className,
@@ -11,14 +11,10 @@ var _react = _interopRequireWildcard(require("react"));
11
11
 
12
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
- var _classnames = _interopRequireDefault(require("classnames"));
15
-
16
14
  var _NewChipForm = _interopRequireDefault(require("../NewChipForm/NewChipForm"));
17
15
 
18
16
  var _types = require("../../../types");
19
17
 
20
- var _close = require("../../../images/close.svg");
21
-
22
18
  require("./formChip.scss");
23
19
 
24
20
  var _jsxRuntime = require("react/jsx-runtime");
@@ -36,30 +32,24 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
36
32
  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; }
37
33
 
38
34
  var FormChip = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
39
- var _chip$delimiter;
40
-
41
35
  var chip = _ref.chip,
42
- chipClassNames = _ref.chipClassNames,
43
36
  chipIndex = _ref.chipIndex,
44
37
  chipOptions = _ref.chipOptions,
45
- className = _ref.className,
46
38
  editConfig = _ref.editConfig,
47
39
  handleEditChip = _ref.handleEditChip,
48
- handleIsEdit = _ref.handleIsEdit,
49
40
  handleRemoveChip = _ref.handleRemoveChip,
41
+ handleToEditMode = _ref.handleToEditMode,
50
42
  isDeleteMode = _ref.isDeleteMode,
51
43
  isEditMode = _ref.isEditMode,
52
44
  keyName = _ref.keyName,
53
- onClick = _ref.onClick,
45
+ meta = _ref.meta,
54
46
  setChipsSizes = _ref.setChipsSizes,
55
47
  setEditConfig = _ref.setEditConfig,
56
- textOverflowEllipsis = _ref.textOverflowEllipsis,
48
+ validationRules = _ref.validationRules,
57
49
  valueName = _ref.valueName;
58
50
 
59
51
  var chipRef = _react.default.useRef();
60
52
 
61
- var chipLabelClassNames = (0, _classnames.default)('chip__label', (textOverflowEllipsis || isEditMode) && 'data-ellipsis');
62
- var chipValueClassNames = (0, _classnames.default)('chip__value', (textOverflowEllipsis || isEditMode) && 'data-ellipsis', chipOptions.boldValue && 'chip-value_bold');
63
53
  (0, _react.useEffect)(function () {
64
54
  if (chipRef.current && setChipsSizes) {
65
55
  setChipsSizes(function (state) {
@@ -67,40 +57,27 @@ var FormChip = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
67
57
  });
68
58
  }
69
59
  }, [chipIndex, setChipsSizes]);
70
- return isEditMode && chipIndex === editConfig.chipIndex ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_NewChipForm.default, {
71
- chip: chip,
72
- chipOptions: chipOptions,
73
- className: "input-label-key",
74
- editConfig: editConfig,
75
- keyName: keyName,
76
- onChange: handleEditChip,
77
- ref: ref,
78
- setEditConfig: setEditConfig,
79
- valueName: valueName
80
- }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
81
- className: chipClassNames,
60
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
82
61
  onClick: function onClick(event) {
83
- return handleIsEdit(event, chipIndex);
62
+ return handleToEditMode(event, chipIndex);
84
63
  },
85
64
  ref: chipRef,
86
- children: [chip.key && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
87
- className: chipLabelClassNames,
88
- children: chip.key
89
- }), chip.value && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
90
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
91
- className: "chip__delimiter",
92
- children: (_chip$delimiter = chip.delimiter) !== null && _chip$delimiter !== void 0 ? _chip$delimiter : ':'
93
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
94
- className: chipValueClassNames,
95
- children: chip.value
96
- })]
97
- }), (isEditMode || isDeleteMode) && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
98
- className: "item-icon-close",
99
- onClick: function onClick(event) {
100
- return handleRemoveChip(event, chipIndex);
101
- },
102
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_close.ReactComponent, {})
103
- })]
65
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_NewChipForm.default, {
66
+ chip: chip,
67
+ chipIndex: chipIndex,
68
+ chipOptions: chipOptions,
69
+ className: "input-label-key",
70
+ editConfig: editConfig,
71
+ handleRemoveChip: handleRemoveChip,
72
+ isEditMode: isEditMode,
73
+ keyName: keyName,
74
+ meta: meta,
75
+ onChange: handleEditChip,
76
+ ref: ref,
77
+ setEditConfig: setEditConfig,
78
+ validationRules: validationRules,
79
+ valueName: valueName
80
+ })
104
81
  });
105
82
  });
106
83
 
@@ -116,27 +93,24 @@ FormChip.defaultProps = {
116
93
  isDeleteMode: false,
117
94
  isEditMode: false,
118
95
  keyName: '',
119
- onClick: function onClick() {},
120
- textOverflowEllipsis: false,
96
+ validationRules: {},
121
97
  valueName: ''
122
98
  };
123
99
  FormChip.propTypes = {
124
100
  chip: _propTypes.default.object.isRequired,
125
- chipClassNames: _propTypes.default.string.isRequired,
126
101
  chipIndex: _propTypes.default.number.isRequired,
127
102
  chipOptions: _types.CHIP_OPTIONS,
128
- className: _propTypes.default.string,
129
103
  editConfig: _propTypes.default.object.isRequired,
130
104
  handleEditChip: _propTypes.default.func.isRequired,
131
- handleIsEdit: _propTypes.default.func.isRequired,
132
105
  handleRemoveChip: _propTypes.default.func.isRequired,
106
+ handleToEditMode: _propTypes.default.func.isRequired,
133
107
  isDeleteMode: _propTypes.default.bool,
134
108
  isEditMode: _propTypes.default.bool,
135
109
  keyName: _propTypes.default.string,
136
- onClick: _propTypes.default.func,
110
+ meta: _propTypes.default.object.isRequired,
137
111
  setChipsSizes: _propTypes.default.func.isRequired,
138
112
  setEditConfig: _propTypes.default.func.isRequired,
139
- textOverflowEllipsis: _propTypes.default.bool,
113
+ validationRules: _propTypes.default.object,
140
114
  valueName: _propTypes.default.string
141
115
  };
142
116
  var _default = FormChip;
@@ -39,18 +39,6 @@
39
39
  padding: 8px 7px;
40
40
  }
41
41
 
42
- .item-icon-close {
43
- display: flex;
44
- align-items: center;
45
- justify-content: center;
46
- margin-left: 5px;
47
- padding: 0;
48
-
49
- svg {
50
- transform: scale(0.7);
51
- }
52
- }
53
-
54
42
  &-background {
55
43
  @include chipBackground(false);
56
44
  }
@@ -9,9 +9,9 @@ exports.default = void 0;
9
9
 
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
 
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _lodash = _interopRequireWildcard(require("lodash"));
13
13
 
14
- var _lodash = require("lodash");
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
15
 
16
16
  var _FormChipCellView = _interopRequireDefault(require("./FormChipCellView"));
17
17
 
@@ -19,10 +19,16 @@ var _common = require("../../utils/common.util");
19
19
 
20
20
  var _generateChipsList = require("../../utils/generateChipsList.util");
21
21
 
22
+ var _validation = require("../../utils/validation.util");
23
+
24
+ var _formChipCell = require("./formChipCell.util");
25
+
22
26
  var _types = require("../../types");
23
27
 
24
28
  var _constants = require("../../constants");
25
29
 
30
+ require("./formChipCell.scss");
31
+
26
32
  var _jsxRuntime = require("react/jsx-runtime");
27
33
 
28
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -31,6 +37,12 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
31
37
 
32
38
  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; }
33
39
 
40
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
41
+
42
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
43
+
44
+ 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; }
45
+
34
46
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
35
47
 
36
48
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -45,14 +57,16 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
45
57
 
46
58
  var FormChipCell = function FormChipCell(_ref) {
47
59
  var chipOptions = _ref.chipOptions,
48
- className = _ref.className,
49
60
  delimiter = _ref.delimiter,
50
61
  formState = _ref.formState,
51
62
  initialValues = _ref.initialValues,
52
63
  isEditMode = _ref.isEditMode,
64
+ label = _ref.label,
53
65
  name = _ref.name,
54
66
  onClick = _ref.onClick,
55
67
  shortChips = _ref.shortChips,
68
+ validationRules = _ref.validationRules,
69
+ validator = _ref.validator,
56
70
  visibleChipsMaxLength = _ref.visibleChipsMaxLength;
57
71
 
58
72
  var _useState = (0, _react.useState)({}),
@@ -68,7 +82,7 @@ var FormChipCell = function FormChipCell(_ref) {
68
82
  var _useState5 = (0, _react.useState)({
69
83
  chipIndex: null,
70
84
  isEdit: false,
71
- isKeyFocused: true,
85
+ isKeyFocused: false,
72
86
  isValueFocused: false,
73
87
  isNewChip: false
74
88
  }),
@@ -97,9 +111,10 @@ var FormChipCell = function FormChipCell(_ref) {
97
111
  }, [isEditMode, visibleChipsMaxLength]);
98
112
  var chips = (0, _react.useMemo)(function () {
99
113
  return isEditMode || visibleChipsMaxLength === 'all' ? {
100
- visibleChips: formState.values[name]
101
- } : (0, _generateChipsList.generateChipsList)(formState.values[name], visibleChipsMaxLength ? visibleChipsMaxLength : visibleChipsCount, delimiter);
102
- }, [visibleChipsMaxLength, isEditMode, formState.values, name, visibleChipsCount, delimiter]);
114
+ visibleChips: (0, _lodash.get)(formState.values, name),
115
+ hiddenChips: []
116
+ } : (0, _generateChipsList.generateChipsList)((0, _lodash.get)(formState.values, name), visibleChipsMaxLength ? visibleChipsMaxLength : visibleChipsCount, delimiter);
117
+ }, [visibleChipsMaxLength, isEditMode, visibleChipsCount, delimiter, formState.values, name]);
103
118
  var handleResize = (0, _react.useCallback)(function () {
104
119
  if (!isEditMode && !(0, _common.isEveryObjectValueEmpty)(chipsSizes)) {
105
120
  var _chipsCellRef$current;
@@ -152,8 +167,8 @@ var FormChipCell = function FormChipCell(_ref) {
152
167
  }
153
168
  }, [showHiddenChips, handleShowElements]);
154
169
  var checkChipsList = (0, _react.useCallback)(function (currentChipsList) {
155
- if ((0, _lodash.isEqual)(initialValues[name], currentChipsList)) {
156
- formState.initialValues[name] = currentChipsList;
170
+ if ((0, _common.areArraysEqual)((0, _lodash.get)(initialValues, name), currentChipsList, ['id'])) {
171
+ (0, _lodash.set)(formState.initialValues, name, currentChipsList);
157
172
  }
158
173
 
159
174
  formState.form.mutators.setFieldState(name, {
@@ -166,6 +181,7 @@ var FormChipCell = function FormChipCell(_ref) {
166
181
  var handleAddNewChip = (0, _react.useCallback)(function (event, fields) {
167
182
  if (!editConfig.isEdit && !editConfig.chipIndex) {
168
183
  formState.form.mutators.push(name, {
184
+ id: fields.value.length + new Date(),
169
185
  key: '',
170
186
  value: '',
171
187
  delimiter: delimiter
@@ -176,7 +192,6 @@ var FormChipCell = function FormChipCell(_ref) {
176
192
  setShowHiddenChips(false);
177
193
  }
178
194
 
179
- event && event.preventDefault();
180
195
  setEditConfig({
181
196
  chipIndex: fields.value.length,
182
197
  isEdit: true,
@@ -184,32 +199,35 @@ var FormChipCell = function FormChipCell(_ref) {
184
199
  isValueFocused: false,
185
200
  isNewChip: true
186
201
  });
202
+ event && event.preventDefault();
187
203
  }, [editConfig.isEdit, editConfig.chipIndex, showHiddenChips, formState, name, delimiter]);
188
204
  var handleRemoveChip = (0, _react.useCallback)(function (event, fields, chipIndex) {
189
- checkChipsList(formState.values[name].filter(function (_, index) {
205
+ checkChipsList(_lodash.default.chain(formState).get(['values', name]).filter(function (_, index) {
190
206
  return index !== chipIndex;
191
- }));
207
+ }).value());
192
208
  fields.remove(chipIndex);
193
209
  event && event.stopPropagation();
194
- }, [checkChipsList, formState.values, name]);
210
+ }, [checkChipsList, formState, name]);
195
211
  var handleEditChip = (0, _react.useCallback)(function (event, fields, nameEvent) {
196
- var chip = formState.values[name][editConfig.chipIndex];
197
- var isChipNotEmpty = !!(chip.key && chip.value);
212
+ var _fields$value$editCon = fields.value[editConfig.chipIndex],
213
+ key = _fields$value$editCon.key,
214
+ value = _fields$value$editCon.value;
215
+ var isChipNotEmpty = !!(key !== null && key !== void 0 && key.trim() && value !== null && value !== void 0 && value.trim());
198
216
 
199
217
  if (nameEvent === _constants.CLICK) {
200
- if (editConfig.isNewChip && !isChipNotEmpty) {
218
+ if (!isChipNotEmpty) {
201
219
  handleRemoveChip(event, fields, editConfig.chipIndex);
202
220
  }
203
221
 
204
222
  setEditConfig({
205
223
  chipIndex: null,
206
224
  isEdit: false,
207
- isKeyFocused: true,
225
+ isKeyFocused: false,
208
226
  isValueFocused: false,
209
227
  isNewChip: false
210
228
  });
211
229
  } else if (nameEvent === _constants.TAB) {
212
- if (editConfig.isNewChip && !isChipNotEmpty) {
230
+ if (!isChipNotEmpty) {
213
231
  handleRemoveChip(event, fields, editConfig.chipIndex);
214
232
  }
215
233
 
@@ -224,7 +242,7 @@ var FormChipCell = function FormChipCell(_ref) {
224
242
  };
225
243
  });
226
244
  } else if (nameEvent === _constants.TAB_SHIFT) {
227
- if (editConfig.isNewChip && !isChipNotEmpty) {
245
+ if (!isChipNotEmpty) {
228
246
  handleRemoveChip(event, fields, editConfig.chipIndex);
229
247
  }
230
248
 
@@ -240,43 +258,141 @@ var FormChipCell = function FormChipCell(_ref) {
240
258
  });
241
259
  }
242
260
 
261
+ checkChipsList((0, _lodash.get)(formState.values, name));
243
262
  event && event.preventDefault();
244
- checkChipsList(formState.values[name]);
245
- }, [editConfig.chipIndex, editConfig.isNewChip, handleRemoveChip, name, formState, checkChipsList]);
246
- var handleIsEdit = (0, _react.useCallback)(function (event, index) {
263
+ }, [editConfig.chipIndex, handleRemoveChip, checkChipsList, formState.values, name]);
264
+ var handleToEditMode = (0, _react.useCallback)(function (event, index) {
247
265
  if (isEditMode) {
248
266
  event.stopPropagation();
249
- setEditConfig({
250
- chipIndex: index,
251
- isEdit: true,
252
- isKeyFocused: true,
253
- isValueFocused: false
267
+ setEditConfig(function (preState) {
268
+ return _objectSpread(_objectSpread({}, preState), {}, {
269
+ chipIndex: index,
270
+ isEdit: true,
271
+ isKeyFocused: true,
272
+ isValueFocused: false
273
+ });
254
274
  });
255
275
  }
256
276
 
257
277
  onClick && onClick();
258
278
  }, [isEditMode, onClick]);
259
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormChipCellView.default, {
260
- chipOptions: chipOptions,
261
- chips: chips,
262
- className: className,
263
- editConfig: editConfig,
264
- handleAddNewChip: handleAddNewChip,
265
- handleEditChip: handleEditChip,
266
- handleIsEdit: handleIsEdit,
267
- handleRemoveChip: handleRemoveChip,
268
- handleShowElements: handleShowElements,
269
- isEditMode: isEditMode,
270
- name: name,
271
- ref: {
272
- chipsCellRef: chipsCellRef,
273
- chipsWrapperRef: chipsWrapperRef
274
- },
275
- setChipsSizes: setChipsSizes,
276
- setEditConfig: setEditConfig,
277
- shortChips: shortChips,
278
- showChips: showChips,
279
- showHiddenChips: showHiddenChips
279
+
280
+ var validateFields = function validateFields(fieldsArray) {
281
+ var uniquenessValidator = function uniquenessValidator(newValue, idx) {
282
+ return !fieldsArray.some(function (_ref2, index) {
283
+ var key = _ref2.key;
284
+ return newValue === key && index !== idx;
285
+ });
286
+ };
287
+
288
+ var errorData = [];
289
+ if (!fieldsArray) return [];
290
+
291
+ if (!(0, _lodash.isEmpty)(validationRules)) {
292
+ errorData = fieldsArray.map(function (chip) {
293
+ var _validateChip = validateChip(chip),
294
+ _validateChip2 = _slicedToArray(_validateChip, 2),
295
+ keyValidation = _validateChip2[0],
296
+ valueValidation = _validateChip2[1];
297
+
298
+ if (keyValidation && valueValidation) return {
299
+ key: keyValidation,
300
+ value: valueValidation
301
+ };
302
+ if (keyValidation) return {
303
+ key: keyValidation
304
+ };
305
+ if (valueValidation) return {
306
+ value: valueValidation
307
+ };
308
+ return null;
309
+ });
310
+ } // uniqueness
311
+
312
+
313
+ fieldsArray.forEach(function (chip, index) {
314
+ var isUnique = uniquenessValidator(chip.key, index);
315
+
316
+ if (!isUnique) {
317
+ if ((0, _lodash.get)(errorData, [index, 'key'], false)) {
318
+ errorData.at(index).key.push(_formChipCell.uniquenessError);
319
+ } else {
320
+ (0, _lodash.set)(errorData, [index, 'key'], [_formChipCell.uniquenessError]);
321
+ }
322
+ }
323
+ });
324
+
325
+ if (!errorData && validator) {
326
+ errorData = validator(fieldsArray);
327
+ }
328
+
329
+ if (errorData.every(function (label) {
330
+ return (0, _lodash.isNil)(label);
331
+ })) {
332
+ return [];
333
+ }
334
+
335
+ return errorData;
336
+ };
337
+
338
+ var validateChip = function validateChip(_ref3) {
339
+ var key = _ref3.key,
340
+ value = _ref3.value;
341
+
342
+ var validateField = function validateField(value, field) {
343
+ var _checkPatternsValidit = (0, _validation.checkPatternsValidity)(validationRules[field].filter(function (rule) {
344
+ return rule.pattern;
345
+ }), value),
346
+ _checkPatternsValidit2 = _slicedToArray(_checkPatternsValidit, 2),
347
+ newRules = _checkPatternsValidit2[0],
348
+ isValidField = _checkPatternsValidit2[1];
349
+
350
+ if (isValidField) return null;
351
+ var invalidRules = newRules.filter(function (rule) {
352
+ return !rule.isValid;
353
+ });
354
+ return invalidRules.map(function (rule) {
355
+ return {
356
+ name: rule.name,
357
+ label: rule.label
358
+ };
359
+ });
360
+ };
361
+
362
+ return [validateField(key, 'key'), validateField(value, 'value')];
363
+ };
364
+
365
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
366
+ className: "chips",
367
+ children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
368
+ className: "chips__label",
369
+ children: label
370
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
371
+ className: label ? 'chips__wrapper' : '',
372
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormChipCellView.default, {
373
+ chipOptions: chipOptions,
374
+ chips: chips,
375
+ editConfig: editConfig,
376
+ handleAddNewChip: handleAddNewChip,
377
+ handleEditChip: handleEditChip,
378
+ handleRemoveChip: handleRemoveChip,
379
+ handleShowElements: handleShowElements,
380
+ handleToEditMode: handleToEditMode,
381
+ isEditMode: isEditMode,
382
+ name: name,
383
+ ref: {
384
+ chipsCellRef: chipsCellRef,
385
+ chipsWrapperRef: chipsWrapperRef
386
+ },
387
+ setChipsSizes: setChipsSizes,
388
+ setEditConfig: setEditConfig,
389
+ shortChips: shortChips,
390
+ showChips: showChips,
391
+ showHiddenChips: showHiddenChips,
392
+ validateFields: validateFields,
393
+ validationRules: validationRules
394
+ })
395
+ })]
280
396
  });
281
397
  };
282
398
 
@@ -290,21 +406,26 @@ FormChipCell.defaultProps = {
290
406
  font: 'purple'
291
407
  },
292
408
  delimiter: null,
409
+ isEditMode: false,
410
+ label: null,
293
411
  onClick: function onClick() {},
294
412
  shortChips: false,
295
- isEditMode: false,
413
+ validationRules: {},
414
+ validator: function validator() {},
296
415
  visibleChipsMaxLength: 'all'
297
416
  };
298
417
  FormChipCell.propTypes = {
299
418
  chipOptions: _types.CHIP_OPTIONS,
300
- className: _propTypes.default.string,
301
419
  delimiter: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.element]),
302
- onClick: _propTypes.default.func,
303
- shortChips: _propTypes.default.bool,
304
- name: _propTypes.default.string.isRequired,
305
420
  formState: _propTypes.default.shape({}).isRequired,
306
421
  initialValues: _propTypes.default.object.isRequired,
307
422
  isEditMode: _propTypes.default.bool,
423
+ label: _propTypes.default.string,
424
+ name: _propTypes.default.string.isRequired,
425
+ onClick: _propTypes.default.func,
426
+ shortChips: _propTypes.default.bool,
427
+ validationRules: _propTypes.default.object,
428
+ validator: _propTypes.default.func,
308
429
  visibleChipsMaxLength: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
309
430
  };
310
431