iguazio.dashboard-react-controls 1.8.9 → 1.8.11
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/dist/components/FormChipCell/FormChipCell.js +8 -2
- package/dist/components/FormChipCell/FormChipCellView.js +5 -1
- package/dist/components/FormInput/FormInput.js +8 -2
- package/dist/components/FormKeyValueTable/FormKeyValueTable.js +40 -25
- package/dist/components/FormTextarea/FormTextarea.js +3 -1
- package/dist/components/Wizard/Wizard.js +1 -1
- package/dist/components/Wizard/Wizard.scss +9 -1
- package/dist/hooks/useFormTable.hook.js +57 -57
- package/dist/scss/mixins.scss +2 -0
- package/dist/scss/variables.scss +5 -0
- package/dist/utils/validation.util.js +71 -19
- package/package.json +1 -1
|
@@ -61,6 +61,7 @@ var FormChipCell = function FormChipCell(_ref) {
|
|
|
61
61
|
shortChips = _ref.shortChips,
|
|
62
62
|
validationRules = _ref.validationRules,
|
|
63
63
|
validator = _ref.validator,
|
|
64
|
+
onExitEditModeCallback = _ref.onExitEditModeCallback,
|
|
64
65
|
visibleChipsMaxLength = _ref.visibleChipsMaxLength;
|
|
65
66
|
var chipsClassName = (0, _classnames.default)('chips', className);
|
|
66
67
|
var _useChipCell = (0, _hooks.useChipCell)(isEditable, visibleChipsMaxLength),
|
|
@@ -129,8 +130,9 @@ var FormChipCell = function FormChipCell(_ref) {
|
|
|
129
130
|
return index !== chipIndex;
|
|
130
131
|
}).value());
|
|
131
132
|
fields.remove(chipIndex);
|
|
133
|
+
onExitEditModeCallback && onExitEditModeCallback();
|
|
132
134
|
event && event.stopPropagation();
|
|
133
|
-
}, [checkChipsList, formState, name]);
|
|
135
|
+
}, [checkChipsList, formState, name, onExitEditModeCallback]);
|
|
134
136
|
var handleEditChip = (0, _react.useCallback)(function (event, fields, nameEvent) {
|
|
135
137
|
var _fields$value$editCon = fields.value[editConfig.chipIndex],
|
|
136
138
|
key = _fields$value$editCon.key,
|
|
@@ -147,12 +149,14 @@ var FormChipCell = function FormChipCell(_ref) {
|
|
|
147
149
|
isValueFocused: false,
|
|
148
150
|
isNewChip: false
|
|
149
151
|
});
|
|
152
|
+
isChipNotEmpty && onExitEditModeCallback && onExitEditModeCallback();
|
|
150
153
|
} else if (nameEvent === _constants.TAB) {
|
|
151
154
|
if (!isChipNotEmpty) {
|
|
152
155
|
handleRemoveChip(event, fields, editConfig.chipIndex);
|
|
153
156
|
}
|
|
154
157
|
setEditConfig(function (prevState) {
|
|
155
158
|
var lastChipSelected = prevState.chipIndex + 1 > fields.value.length - 1;
|
|
159
|
+
isChipNotEmpty && lastChipSelected && onExitEditModeCallback && onExitEditModeCallback();
|
|
156
160
|
return {
|
|
157
161
|
chipIndex: lastChipSelected ? null : prevState.chipIndex + 1,
|
|
158
162
|
isEdit: !lastChipSelected,
|
|
@@ -167,6 +171,7 @@ var FormChipCell = function FormChipCell(_ref) {
|
|
|
167
171
|
}
|
|
168
172
|
setEditConfig(function (prevState) {
|
|
169
173
|
var isPrevChipIndexExists = prevState.chipIndex - 1 < 0;
|
|
174
|
+
isChipNotEmpty && isPrevChipIndexExists && onExitEditModeCallback && onExitEditModeCallback();
|
|
170
175
|
return {
|
|
171
176
|
chipIndex: isPrevChipIndexExists ? null : prevState.chipIndex - 1,
|
|
172
177
|
isEdit: !isPrevChipIndexExists,
|
|
@@ -178,7 +183,7 @@ var FormChipCell = function FormChipCell(_ref) {
|
|
|
178
183
|
}
|
|
179
184
|
checkChipsList((0, _lodash.get)(formState.values, name));
|
|
180
185
|
event && event.preventDefault();
|
|
181
|
-
}, [editConfig.chipIndex,
|
|
186
|
+
}, [editConfig.chipIndex, checkChipsList, formState.values, name, onExitEditModeCallback, handleRemoveChip]);
|
|
182
187
|
var handleToEditMode = (0, _react.useCallback)(function (event, index) {
|
|
183
188
|
if (isEditable) {
|
|
184
189
|
event.stopPropagation();
|
|
@@ -278,6 +283,7 @@ var FormChipCell = function FormChipCell(_ref) {
|
|
|
278
283
|
chipOptions: chipOptions,
|
|
279
284
|
chips: chips,
|
|
280
285
|
editConfig: editConfig,
|
|
286
|
+
formState: formState,
|
|
281
287
|
handleAddNewChip: handleAddNewChip,
|
|
282
288
|
handleEditChip: handleEditChip,
|
|
283
289
|
handleRemoveChip: handleRemoveChip,
|
|
@@ -40,6 +40,7 @@ var FormChipCellView = /*#__PURE__*/_react.default.forwardRef(function (_ref, _r
|
|
|
40
40
|
var chipOptions = _ref.chipOptions,
|
|
41
41
|
chips = _ref.chips,
|
|
42
42
|
editConfig = _ref.editConfig,
|
|
43
|
+
formState = _ref.formState,
|
|
43
44
|
handleAddNewChip = _ref.handleAddNewChip,
|
|
44
45
|
_handleEditChip = _ref.handleEditChip,
|
|
45
46
|
_handleRemoveChip = _ref.handleRemoveChip,
|
|
@@ -63,6 +64,7 @@ var FormChipCellView = /*#__PURE__*/_react.default.forwardRef(function (_ref, _r
|
|
|
63
64
|
var chipClassNames = (0, _classnames.default)('chip', 'chip__content', isEditable && 'data-ellipsis', shortChips && 'chip_short', chips.hiddenChips && 'chip_hidden', chipOptions.density && "chip-density_".concat(chipOptions.density), chipOptions.borderRadius && "chip-border_".concat(chipOptions.borderRadius), chipOptions.background && "chip-background_".concat(chipOptions.background), chipOptions.borderColor && "chip-border_".concat(chipOptions.borderColor), chipOptions.font && "chip-font_".concat(chipOptions.font), isEditable && 'editable', (showChips || isEditable) && 'chip_visible');
|
|
64
65
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalFormArrays.FieldArray, {
|
|
65
66
|
name: name,
|
|
67
|
+
initialValue: formState.initialValues[name],
|
|
66
68
|
validate: validateFields,
|
|
67
69
|
children: function children(_ref3) {
|
|
68
70
|
var fields = _ref3.fields,
|
|
@@ -79,8 +81,9 @@ var FormChipCellView = /*#__PURE__*/_react.default.forwardRef(function (_ref, _r
|
|
|
79
81
|
className: wrapperClassNames,
|
|
80
82
|
ref: chipsWrapperRef,
|
|
81
83
|
children: [fields.map(function (contentItem, index) {
|
|
84
|
+
var _chips$visibleChips;
|
|
82
85
|
var chipData = fields.value[index];
|
|
83
|
-
return index < chips.visibleChips.length && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
86
|
+
return index < ((_chips$visibleChips = chips.visibleChips) === null || _chips$visibleChips === void 0 ? void 0 : _chips$visibleChips.length) && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
84
87
|
className: "chip-block",
|
|
85
88
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
86
89
|
hidden: editConfig.isEdit,
|
|
@@ -166,6 +169,7 @@ FormChipCellView.propTypes = {
|
|
|
166
169
|
chipOptions: _types.CHIP_OPTIONS,
|
|
167
170
|
chips: _propTypes.default.object.isRequired,
|
|
168
171
|
editConfig: _propTypes.default.object.isRequired,
|
|
172
|
+
formState: _propTypes.default.object.isRequired,
|
|
169
173
|
handleAddNewChip: _propTypes.default.func.isRequired,
|
|
170
174
|
handleEditChip: _propTypes.default.func.isRequired,
|
|
171
175
|
handleRemoveChip: _propTypes.default.func.isRequired,
|
|
@@ -22,7 +22,7 @@ var _popout = require("../../images/popout.svg");
|
|
|
22
22
|
var _warning = require("../../images/warning.svg");
|
|
23
23
|
require("./formInput.scss");
|
|
24
24
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
|
-
var _excluded = ["async", "className", "customRequiredLabel", "density", "disabled", "focused", "iconClass", "iconClick", "inputIcon", "invalidText", "label", "link", "name", "onBlur", "onChange", "onFocus", "pattern", "required", "suggestionList", "tip", "validationRules", "validator", "withoutBorder"];
|
|
25
|
+
var _excluded = ["async", "className", "customRequiredLabel", "density", "disabled", "focused", "iconClass", "iconClick", "inputIcon", "invalidText", "label", "link", "name", "onBlur", "onChange", "onFocus", "onKeyDown", "pattern", "required", "suggestionList", "tip", "validationRules", "validator", "withoutBorder"];
|
|
26
26
|
/*
|
|
27
27
|
Copyright 2022 Iguazio Systems Ltd.
|
|
28
28
|
Licensed under the Apache License, Version 2.0 (the "License") with
|
|
@@ -76,6 +76,7 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
76
76
|
onBlur = _ref.onBlur,
|
|
77
77
|
onChange = _ref.onChange,
|
|
78
78
|
onFocus = _ref.onFocus,
|
|
79
|
+
onKeyDown = _ref.onKeyDown,
|
|
79
80
|
pattern = _ref.pattern,
|
|
80
81
|
required = _ref.required,
|
|
81
82
|
suggestionList = _ref.suggestionList,
|
|
@@ -183,9 +184,13 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
183
184
|
};
|
|
184
185
|
var handleInputFocus = function handleInputFocus(event) {
|
|
185
186
|
input.onFocus && input.onFocus(event);
|
|
186
|
-
onFocus && onFocus();
|
|
187
|
+
onFocus && onFocus(event);
|
|
187
188
|
setIsFocused(true);
|
|
188
189
|
};
|
|
190
|
+
var handleInputKeyDown = function handleInputKeyDown(event) {
|
|
191
|
+
input.onKeyDown && input.onKeyDown(event);
|
|
192
|
+
onKeyDown && onKeyDown(event);
|
|
193
|
+
};
|
|
189
194
|
var handleScroll = function handleScroll(event) {
|
|
190
195
|
if (inputRef.current && inputRef.current.contains(event.target)) return;
|
|
191
196
|
if (!event.target.closest('.options-menu') && !event.target.classList.contains('form-field-input')) {
|
|
@@ -368,6 +373,7 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
368
373
|
}, inputProps), input)), {}, {
|
|
369
374
|
autoComplete: (_inputProps$autocompl = inputProps.autocomplete) !== null && _inputProps$autocompl !== void 0 ? _inputProps$autocompl : 'off',
|
|
370
375
|
onBlur: handleInputBlur,
|
|
376
|
+
onKeyDown: handleInputKeyDown,
|
|
371
377
|
onFocus: handleInputFocus
|
|
372
378
|
}))
|
|
373
379
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
@@ -11,25 +11,30 @@ var _reactFinalFormArrays = require("react-final-form-arrays");
|
|
|
11
11
|
var _components = require("../../components");
|
|
12
12
|
var _elements = require("../../elements");
|
|
13
13
|
var _hooks = require("../../hooks");
|
|
14
|
+
var _types = require("../../types");
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
18
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
21
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
22
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /*
|
|
23
|
+
Copyright 2022 Iguazio Systems Ltd.
|
|
24
|
+
Licensed under the Apache License, Version 2.0 (the "License") with
|
|
25
|
+
an addition restriction as set forth herein. You may not use this
|
|
26
|
+
file except in compliance with the License. You may obtain a copy of
|
|
27
|
+
the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
28
|
+
Unless required by applicable law or agreed to in writing, software
|
|
29
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
30
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
31
|
+
implied. See the License for the specific language governing
|
|
32
|
+
permissions and limitations under the License.
|
|
33
|
+
In addition, you may not use the software for any purposes that are
|
|
34
|
+
illegal under applicable law, and the grant of the foregoing license
|
|
35
|
+
under the Apache 2.0 license is conditioned upon your compliance with
|
|
36
|
+
such restriction.
|
|
37
|
+
*/
|
|
33
38
|
var FormKeyValueTable = function FormKeyValueTable(_ref) {
|
|
34
39
|
var actionButtonId = _ref.actionButtonId,
|
|
35
40
|
addNewItemLabel = _ref.addNewItemLabel,
|
|
@@ -44,10 +49,13 @@ var FormKeyValueTable = function FormKeyValueTable(_ref) {
|
|
|
44
49
|
keyHeader = _ref.keyHeader,
|
|
45
50
|
keyLabel = _ref.keyLabel,
|
|
46
51
|
keyOptions = _ref.keyOptions,
|
|
52
|
+
keyValidationRules = _ref.keyValidationRules,
|
|
53
|
+
onExitEditModeCallback = _ref.onExitEditModeCallback,
|
|
47
54
|
valueHeader = _ref.valueHeader,
|
|
48
|
-
valueLabel = _ref.valueLabel
|
|
55
|
+
valueLabel = _ref.valueLabel,
|
|
56
|
+
valueValidationRules = _ref.valueValidationRules;
|
|
49
57
|
var tableClassNames = (0, _classnames.default)('form-table form-key-value-table', className);
|
|
50
|
-
var _useFormTable = (0, _hooks.useFormTable)(formState, exitEditModeTriggerItem),
|
|
58
|
+
var _useFormTable = (0, _hooks.useFormTable)(formState, exitEditModeTriggerItem, onExitEditModeCallback),
|
|
51
59
|
addNewRow = _useFormTable.addNewRow,
|
|
52
60
|
applyChanges = _useFormTable.applyChanges,
|
|
53
61
|
bottomScrollRef = _useFormTable.bottomScrollRef,
|
|
@@ -59,7 +67,7 @@ var FormKeyValueTable = function FormKeyValueTable(_ref) {
|
|
|
59
67
|
var uniquenessValidator = function uniquenessValidator(fields, newValue) {
|
|
60
68
|
return !fields.value.some(function (_ref2, index) {
|
|
61
69
|
var key = _ref2.data.key;
|
|
62
|
-
return newValue.trim() === key && index !== editingItem.ui.index;
|
|
70
|
+
return newValue.trim() === key.trim() && index !== editingItem.ui.index;
|
|
63
71
|
});
|
|
64
72
|
};
|
|
65
73
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
@@ -98,13 +106,13 @@ var FormKeyValueTable = function FormKeyValueTable(_ref) {
|
|
|
98
106
|
density: "normal",
|
|
99
107
|
name: "".concat(rowPath, ".data.key"),
|
|
100
108
|
required: isKeyRequired,
|
|
101
|
-
validationRules: [{
|
|
109
|
+
validationRules: [].concat(_toConsumableArray(keyValidationRules), [{
|
|
102
110
|
name: 'uniqueness',
|
|
103
111
|
label: 'Name must be unique',
|
|
104
112
|
pattern: function pattern(newValue) {
|
|
105
113
|
return uniquenessValidator(fields, newValue);
|
|
106
114
|
}
|
|
107
|
-
}]
|
|
115
|
+
}])
|
|
108
116
|
})
|
|
109
117
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
110
118
|
className: "form-table__cell form-table__cell_1",
|
|
@@ -113,7 +121,8 @@ var FormKeyValueTable = function FormKeyValueTable(_ref) {
|
|
|
113
121
|
placeholder: valueLabel,
|
|
114
122
|
density: "normal",
|
|
115
123
|
name: "".concat(rowPath, ".data.value"),
|
|
116
|
-
required: isValueRequired
|
|
124
|
+
required: isValueRequired,
|
|
125
|
+
validationRules: valueValidationRules
|
|
117
126
|
})
|
|
118
127
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_elements.FormRowActions, {
|
|
119
128
|
applyChanges: applyChanges,
|
|
@@ -190,8 +199,11 @@ FormKeyValueTable.defaultProps = {
|
|
|
190
199
|
keyHeader: 'Key',
|
|
191
200
|
keyLabel: 'Key',
|
|
192
201
|
keyOptions: null,
|
|
202
|
+
keyValidationRules: [],
|
|
203
|
+
onExitEditModeCallback: function onExitEditModeCallback() {},
|
|
193
204
|
valueHeader: 'Value',
|
|
194
|
-
valueLabel: 'Value'
|
|
205
|
+
valueLabel: 'Value',
|
|
206
|
+
valueValidationRules: []
|
|
195
207
|
};
|
|
196
208
|
FormKeyValueTable.propTypes = {
|
|
197
209
|
actionButtonId: _propTypes.default.string,
|
|
@@ -210,8 +222,11 @@ FormKeyValueTable.propTypes = {
|
|
|
210
222
|
label: _propTypes.default.string.isRequired,
|
|
211
223
|
id: _propTypes.default.string.isRequired
|
|
212
224
|
})),
|
|
225
|
+
keyValidationRules: _types.INPUT_VALIDATION_RULES,
|
|
226
|
+
onExitEditModeCallback: _propTypes.default.func,
|
|
213
227
|
valueHeader: _propTypes.default.string,
|
|
214
|
-
valueLabel: _propTypes.default.string
|
|
228
|
+
valueLabel: _propTypes.default.string,
|
|
229
|
+
valueValidationRules: _types.INPUT_VALIDATION_RULES
|
|
215
230
|
};
|
|
216
231
|
var _default = FormKeyValueTable;
|
|
217
232
|
exports.default = _default;
|
|
@@ -79,6 +79,9 @@ var FormTextarea = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
79
79
|
var formFieldClassNames = (0, _classnames.default)('form-field-textarea', className);
|
|
80
80
|
var labelClassNames = (0, _classnames.default)('form-field__label', disabled && 'form-field__label-disabled');
|
|
81
81
|
var textAreaClassNames = (0, _classnames.default)('form-field__wrapper', disabled && 'form-field__wrapper-disabled', isInvalid && 'form-field__wrapper-invalid', withoutBorder && 'without-border');
|
|
82
|
+
(0, _react.useLayoutEffect)(function () {
|
|
83
|
+
setTextAreaCount(input.value.length);
|
|
84
|
+
}, [input.value.length]);
|
|
82
85
|
(0, _react.useEffect)(function () {
|
|
83
86
|
if (focused) {
|
|
84
87
|
textAreaRef.current.focus();
|
|
@@ -93,7 +96,6 @@ var FormTextarea = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
93
96
|
};
|
|
94
97
|
var handleInputChange = function handleInputChange(event) {
|
|
95
98
|
input.onChange(event);
|
|
96
|
-
setTextAreaCount(event.target.value.length);
|
|
97
99
|
onChange && onChange(event.target.value);
|
|
98
100
|
};
|
|
99
101
|
var handleInputFocus = function handleInputFocus(event) {
|
|
@@ -108,7 +108,7 @@ var Wizard = function Wizard(_ref) {
|
|
|
108
108
|
stepIsActive: stepIsActive
|
|
109
109
|
}) : null;
|
|
110
110
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
111
|
-
className: !stepIsActive ? 'wizard-form__hidden-content-item' : '',
|
|
111
|
+
className: !stepIsActive ? 'wizard-form__hidden-content-item' : 'wizard-form__visible-content-item',
|
|
112
112
|
children: newChild
|
|
113
113
|
}, idx);
|
|
114
114
|
});
|
|
@@ -26,7 +26,15 @@
|
|
|
26
26
|
height: 100%;
|
|
27
27
|
|
|
28
28
|
.wizard-form__hidden-content-item {
|
|
29
|
-
|
|
29
|
+
position: absolute;
|
|
30
|
+
visibility: hidden;
|
|
31
|
+
height: 0;
|
|
32
|
+
opacity: 0;
|
|
33
|
+
pointer-events: none;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.wizard-form__visible-content-item {
|
|
37
|
+
height: 100%;
|
|
30
38
|
}
|
|
31
39
|
}
|
|
32
40
|
}
|
|
@@ -37,7 +37,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /*
|
|
|
37
37
|
under the Apache 2.0 license is conditioned upon your compliance with
|
|
38
38
|
such restriction.
|
|
39
39
|
*/
|
|
40
|
-
var useFormTable = function useFormTable(formState, exitEditModeTriggerItem) {
|
|
40
|
+
var useFormTable = function useFormTable(formState, exitEditModeTriggerItem, onExitEditModeCallback) {
|
|
41
41
|
// `editingItem` should contain the `data` object with all fields that are used in the `formState`.
|
|
42
42
|
// Properties that aren't used in the `formState` should be placed directly in the `editingItem` object
|
|
43
43
|
// `editingItem` also has an `ui` property which is used internally in this hook
|
|
@@ -63,6 +63,7 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem) {
|
|
|
63
63
|
var editingItemErrorsRef = (0, _react.useRef)(null);
|
|
64
64
|
var formStateRef = (0, _react.useRef)(null);
|
|
65
65
|
var bottomScrollRef = (0, _react.useRef)(null);
|
|
66
|
+
var onExitEditModeCallbackRef = (0, _react.useRef)(onExitEditModeCallback);
|
|
66
67
|
(0, _react.useLayoutEffect)(function () {
|
|
67
68
|
var tableErrors = (0, _lodash.get)(formState === null || formState === void 0 ? void 0 : formState.errors, editingItem === null || editingItem === void 0 ? void 0 : editingItem.ui.fieldsPath, []);
|
|
68
69
|
editingItemErrorsRef.current = (0, _lodash.get)(tableErrors, editingItem === null || editingItem === void 0 ? void 0 : editingItem.ui.index, null);
|
|
@@ -70,40 +71,55 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem) {
|
|
|
70
71
|
(0, _react.useLayoutEffect)(function () {
|
|
71
72
|
formStateRef.current = formState;
|
|
72
73
|
}, [formState]);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
(0, _react.useLayoutEffect)(function () {
|
|
75
|
+
onExitEditModeCallbackRef.current = onExitEditModeCallback;
|
|
76
|
+
}, [onExitEditModeCallback]);
|
|
77
|
+
var exitEditMode = function exitEditMode() {
|
|
78
|
+
var _editingItemRef$curre;
|
|
79
|
+
if ((_editingItemRef$curre = editingItemRef.current) !== null && _editingItemRef$curre !== void 0 && _editingItemRef$curre.data) {
|
|
80
|
+
var _editingItemRef$curre2;
|
|
81
|
+
Object.entries((_editingItemRef$curre2 = editingItemRef.current) === null || _editingItemRef$curre2 === void 0 ? void 0 : _editingItemRef$curre2.data).forEach(function (_ref) {
|
|
82
|
+
var _formStateRef$current, _editingItemRef$curre3, _editingItemRef$curre4;
|
|
83
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
84
|
+
fieldName = _ref2[0];
|
|
85
|
+
(_formStateRef$current = formStateRef.current) === null || _formStateRef$current === void 0 ? void 0 : _formStateRef$current.form.mutators.setFieldState("".concat((_editingItemRef$curre3 = editingItemRef.current) === null || _editingItemRef$curre3 === void 0 ? void 0 : _editingItemRef$curre3.ui.fieldsPath, "[").concat((_editingItemRef$curre4 = editingItemRef.current) === null || _editingItemRef$curre4 === void 0 ? void 0 : _editingItemRef$curre4.ui.index, "].data.").concat(fieldName), {
|
|
86
|
+
modified: false
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
editingItemRef.current = null;
|
|
91
|
+
setEditingItem(null);
|
|
92
|
+
(onExitEditModeCallbackRef === null || onExitEditModeCallbackRef === void 0 ? void 0 : onExitEditModeCallbackRef.current) && onExitEditModeCallbackRef.current();
|
|
93
|
+
};
|
|
94
|
+
(0, _react.useEffect)(function () {
|
|
95
|
+
var applyOrDiscardOrDeleteInEffect = function applyOrDiscardOrDeleteInEffect() {
|
|
96
|
+
if (editingItemRef !== null && editingItemRef !== void 0 && editingItemRef.current) {
|
|
97
|
+
if (!editingItemErrorsRef.current) {
|
|
98
|
+
exitEditMode();
|
|
99
|
+
} else {
|
|
100
|
+
var _editingItemRef$curre5, _editingItemRef$curre6;
|
|
101
|
+
if ((_editingItemRef$curre5 = editingItemRef.current) !== null && _editingItemRef$curre5 !== void 0 && (_editingItemRef$curre6 = _editingItemRef$curre5.ui) !== null && _editingItemRef$curre6 !== void 0 && _editingItemRef$curre6.isNew) {
|
|
102
|
+
var _editingItemRef$curre7;
|
|
103
|
+
var values = (0, _lodash.get)(formStateRef.current.values, (_editingItemRef$curre7 = editingItemRef.current) === null || _editingItemRef$curre7 === void 0 ? void 0 : _editingItemRef$curre7.ui.fieldsPath);
|
|
104
|
+
if ((values === null || values === void 0 ? void 0 : values.length) > 1) {
|
|
105
|
+
var _editingItemRef$curre8, _editingItemRef$curre9;
|
|
106
|
+
formStateRef.current.form.mutators.remove((_editingItemRef$curre8 = editingItemRef.current) === null || _editingItemRef$curre8 === void 0 ? void 0 : _editingItemRef$curre8.ui.fieldsPath, (_editingItemRef$curre9 = editingItemRef.current) === null || _editingItemRef$curre9 === void 0 ? void 0 : _editingItemRef$curre9.ui.index);
|
|
107
|
+
} else {
|
|
108
|
+
var _editingItemRef$curre10;
|
|
109
|
+
formStateRef.current.form.change((_editingItemRef$curre10 = editingItemRef.current) === null || _editingItemRef$curre10 === void 0 ? void 0 : _editingItemRef$curre10.ui.fieldsPath, []);
|
|
110
|
+
}
|
|
85
111
|
} else {
|
|
86
|
-
var _editingItemRef$
|
|
87
|
-
formStateRef.current.form.
|
|
112
|
+
var _editingItemRef$curre11, _editingItemRef$curre12;
|
|
113
|
+
formStateRef.current.form.mutators.update((_editingItemRef$curre11 = editingItemRef.current) === null || _editingItemRef$curre11 === void 0 ? void 0 : _editingItemRef$curre11.ui.fieldsPath, (_editingItemRef$curre12 = editingItemRef.current) === null || _editingItemRef$curre12 === void 0 ? void 0 : _editingItemRef$curre12.ui.index, (0, _lodash.omit)(editingItemRef.current, ['ui']));
|
|
88
114
|
}
|
|
89
|
-
|
|
90
|
-
var _editingItemRef$curre7, _editingItemRef$curre8;
|
|
91
|
-
formStateRef.current.form.mutators.update((_editingItemRef$curre7 = editingItemRef.current) === null || _editingItemRef$curre7 === void 0 ? void 0 : _editingItemRef$curre7.ui.fieldsPath, (_editingItemRef$curre8 = editingItemRef.current) === null || _editingItemRef$curre8 === void 0 ? void 0 : _editingItemRef$curre8.ui.index, (0, _lodash.omit)(editingItemRef.current, ['ui']));
|
|
115
|
+
exitEditMode();
|
|
92
116
|
}
|
|
93
|
-
exitEditMode();
|
|
94
117
|
}
|
|
95
|
-
}
|
|
96
|
-
}, []);
|
|
97
|
-
(0, _react.useEffect)(function () {
|
|
98
|
-
if (editingItemRef !== null && editingItemRef !== void 0 && editingItemRef.current) {
|
|
99
|
-
applyOrDiscardOrDeleteInEffect();
|
|
100
|
-
}
|
|
101
|
-
}, [applyOrDiscardOrDeleteInEffect, exitEditModeTriggerItem]);
|
|
102
|
-
(0, _react.useEffect)(function () {
|
|
118
|
+
};
|
|
103
119
|
return function () {
|
|
104
120
|
applyOrDiscardOrDeleteInEffect();
|
|
105
121
|
};
|
|
106
|
-
}, [
|
|
122
|
+
}, [exitEditModeTriggerItem]);
|
|
107
123
|
var addNewRow = function addNewRow(event, fields, fieldsPath, newItem) {
|
|
108
124
|
applyOrDiscardOrDelete(event);
|
|
109
125
|
formStateRef.current.form.mutators.push(fieldsPath, newItem);
|
|
@@ -124,19 +140,19 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem) {
|
|
|
124
140
|
var applyChanges = function applyChanges(event, index) {
|
|
125
141
|
if (editingItemRef.current) {
|
|
126
142
|
if (!editingItemErrorsRef.current) {
|
|
127
|
-
var _editingItemRef$
|
|
128
|
-
if ((_editingItemRef$
|
|
143
|
+
var _editingItemRef$curre13;
|
|
144
|
+
if ((_editingItemRef$curre13 = editingItemRef.current) !== null && _editingItemRef$curre13 !== void 0 && _editingItemRef$curre13.ui.isNew) {
|
|
129
145
|
scrollIntoView();
|
|
130
146
|
}
|
|
131
147
|
exitEditMode();
|
|
132
148
|
} else {
|
|
133
149
|
var _editingItemErrorsRef;
|
|
134
150
|
// Mark all empty fields as `modified` in order to highlight the error if the field is invalid
|
|
135
|
-
Object.entries((_editingItemErrorsRef = editingItemErrorsRef.current) === null || _editingItemErrorsRef === void 0 ? void 0 : _editingItemErrorsRef.data).forEach(function (
|
|
136
|
-
var _formStateRef$
|
|
137
|
-
var
|
|
138
|
-
fieldName =
|
|
139
|
-
(_formStateRef$
|
|
151
|
+
Object.entries((_editingItemErrorsRef = editingItemErrorsRef.current) === null || _editingItemErrorsRef === void 0 ? void 0 : _editingItemErrorsRef.data).forEach(function (_ref3) {
|
|
152
|
+
var _formStateRef$current2, _editingItemRef$curre14;
|
|
153
|
+
var _ref4 = _slicedToArray(_ref3, 1),
|
|
154
|
+
fieldName = _ref4[0];
|
|
155
|
+
(_formStateRef$current2 = formStateRef.current) === null || _formStateRef$current2 === void 0 ? void 0 : _formStateRef$current2.form.mutators.setFieldState("".concat((_editingItemRef$curre14 = editingItemRef.current) === null || _editingItemRef$curre14 === void 0 ? void 0 : _editingItemRef$curre14.ui.fieldsPath, "[").concat(index, "].data.").concat(fieldName), {
|
|
140
156
|
modified: true
|
|
141
157
|
});
|
|
142
158
|
});
|
|
@@ -162,8 +178,8 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem) {
|
|
|
162
178
|
event && event.stopPropagation();
|
|
163
179
|
};
|
|
164
180
|
var discardOrDelete = function discardOrDelete(event, fieldsPath, index) {
|
|
165
|
-
var _editingItemRef$
|
|
166
|
-
if (!editingItemRef.current || (_editingItemRef$
|
|
181
|
+
var _editingItemRef$curre15, _editingItemRef$curre16;
|
|
182
|
+
if (!editingItemRef.current || (_editingItemRef$curre15 = editingItemRef.current) !== null && _editingItemRef$curre15 !== void 0 && (_editingItemRef$curre16 = _editingItemRef$curre15.ui) !== null && _editingItemRef$curre16 !== void 0 && _editingItemRef$curre16.isNew) {
|
|
167
183
|
deleteRow(event, fieldsPath, index);
|
|
168
184
|
} else {
|
|
169
185
|
discardChanges(event, fieldsPath, index);
|
|
@@ -173,11 +189,11 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem) {
|
|
|
173
189
|
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
174
190
|
if (editingItemRef !== null && editingItemRef !== void 0 && editingItemRef.current) {
|
|
175
191
|
if (!editingItemErrorsRef.current) {
|
|
176
|
-
var _editingItemRef$
|
|
177
|
-
applyChanges(event, (_editingItemRef$
|
|
192
|
+
var _editingItemRef$curre17;
|
|
193
|
+
applyChanges(event, (_editingItemRef$curre17 = editingItemRef.current) === null || _editingItemRef$curre17 === void 0 ? void 0 : _editingItemRef$curre17.ui.index);
|
|
178
194
|
} else {
|
|
179
|
-
var _editingItemRef$
|
|
180
|
-
discardOrDelete(event, (_editingItemRef$
|
|
195
|
+
var _editingItemRef$curre18, _editingItemRef$curre19;
|
|
196
|
+
discardOrDelete(event, (_editingItemRef$curre18 = editingItemRef.current) === null || _editingItemRef$curre18 === void 0 ? void 0 : _editingItemRef$curre18.ui.fieldsPath, (_editingItemRef$curre19 = editingItemRef.current) === null || _editingItemRef$curre19 === void 0 ? void 0 : _editingItemRef$curre19.ui.index);
|
|
181
197
|
}
|
|
182
198
|
}
|
|
183
199
|
};
|
|
@@ -197,22 +213,6 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem) {
|
|
|
197
213
|
});
|
|
198
214
|
});
|
|
199
215
|
};
|
|
200
|
-
var exitEditMode = function exitEditMode() {
|
|
201
|
-
var _editingItemRef$curre16;
|
|
202
|
-
if ((_editingItemRef$curre16 = editingItemRef.current) !== null && _editingItemRef$curre16 !== void 0 && _editingItemRef$curre16.data) {
|
|
203
|
-
var _editingItemRef$curre17;
|
|
204
|
-
Object.entries((_editingItemRef$curre17 = editingItemRef.current) === null || _editingItemRef$curre17 === void 0 ? void 0 : _editingItemRef$curre17.data).forEach(function (_ref3) {
|
|
205
|
-
var _formStateRef$current2, _editingItemRef$curre18, _editingItemRef$curre19;
|
|
206
|
-
var _ref4 = _slicedToArray(_ref3, 1),
|
|
207
|
-
fieldName = _ref4[0];
|
|
208
|
-
(_formStateRef$current2 = formStateRef.current) === null || _formStateRef$current2 === void 0 ? void 0 : _formStateRef$current2.form.mutators.setFieldState("".concat((_editingItemRef$curre18 = editingItemRef.current) === null || _editingItemRef$curre18 === void 0 ? void 0 : _editingItemRef$curre18.ui.fieldsPath, "[").concat((_editingItemRef$curre19 = editingItemRef.current) === null || _editingItemRef$curre19 === void 0 ? void 0 : _editingItemRef$curre19.ui.index, "].data.").concat(fieldName), {
|
|
209
|
-
modified: false
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
editingItemRef.current = null;
|
|
214
|
-
setEditingItem(null);
|
|
215
|
-
};
|
|
216
216
|
var scrollIntoView = function scrollIntoView() {
|
|
217
217
|
if (bottomScrollRef.current) {
|
|
218
218
|
setTimeout(function () {
|
package/dist/scss/mixins.scss
CHANGED
package/dist/scss/variables.scss
CHANGED
|
@@ -50,7 +50,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
50
50
|
* // => 'a–z, A–Z, –, _, *'
|
|
51
51
|
*/
|
|
52
52
|
var convertToLabel = function convertToLabel(chars) {
|
|
53
|
-
return chars.replace(/-/g, '–').replace(/\s/g, ', ').replace(/\bs\b
|
|
53
|
+
return chars.replace(/-/g, '–').replace(/\s/g, ', ').replace(/\bs\b/, 'spaces');
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
/**
|
|
@@ -58,8 +58,7 @@ var convertToLabel = function convertToLabel(chars) {
|
|
|
58
58
|
* @param {string} chars - characters to convert
|
|
59
59
|
* @returns {string} - converted string
|
|
60
60
|
* @example
|
|
61
|
-
* convertToPattern('a-z A-Z - _ *')
|
|
62
|
-
* // => 'a-zA-Z\-\_\*'
|
|
61
|
+
* convertToPattern('a-z A-Z - _ *') => 'a-zA-Z\-\_\*'
|
|
63
62
|
*/
|
|
64
63
|
var convertToPattern = function convertToPattern(chars) {
|
|
65
64
|
return chars.split(' ').map(function (patternItem) {
|
|
@@ -283,22 +282,67 @@ var generateRule = {
|
|
|
283
282
|
};
|
|
284
283
|
}
|
|
285
284
|
};
|
|
285
|
+
var commonRules = {
|
|
286
|
+
prefixedQualifiedName: [{
|
|
287
|
+
name: 'nameValidCharacters',
|
|
288
|
+
label: "[Name] ".concat(_constants.validation.VALID_CHARACTERS, " : a\u2013z, A\u2013Z, 0\u20139, \u2013, _, ."),
|
|
289
|
+
pattern: /^([^/]+\/)?[\w.-]+$/
|
|
290
|
+
}, {
|
|
291
|
+
name: 'nameBeginEnd',
|
|
292
|
+
label: "[Name] ".concat(_constants.validation.BEGIN_END_WITH, ": a\u2013z, A\u2013Z, 0\u20139"),
|
|
293
|
+
pattern: /^([^/]+\/)?([A-Za-z0-9][^/]*)?[A-Za-z0-9]$/
|
|
294
|
+
}, {
|
|
295
|
+
name: 'nameMaxLength',
|
|
296
|
+
label: '[Name] Max length - 63 characters',
|
|
297
|
+
pattern: /^([^/]+\/)?[^/]{1,63}$/
|
|
298
|
+
}, {
|
|
299
|
+
name: 'prefixValidCharacters',
|
|
300
|
+
label: "[Prefix] ".concat(_constants.validation.VALID_CHARACTERS, ": a\u2013z, 0\u20139, \u2013, ."),
|
|
301
|
+
pattern: /^([a-z0-9.-]+\/)?[^/]+$/
|
|
302
|
+
}, {
|
|
303
|
+
name: 'prefixBeginEnd',
|
|
304
|
+
label: "[Prefix] ".concat(_constants.validation.BEGIN_END_WITH, ": a\u2013z, 0\u20139"),
|
|
305
|
+
pattern: /^([a-z0-9]([^/]*[a-z0-9])?\/)?[^/]+$/
|
|
306
|
+
}, {
|
|
307
|
+
name: 'prefixMaxLength',
|
|
308
|
+
label: '[Prefix] Max length - 253 characters',
|
|
309
|
+
pattern: /^(?![^/]{254,}\/)/
|
|
310
|
+
}],
|
|
311
|
+
k8sLabels: {
|
|
312
|
+
value: [{
|
|
313
|
+
name: 'valueBeginEnd',
|
|
314
|
+
label: "[Value] ".concat(_constants.validation.BEGIN_END_WITH, " : a\u2013z, A\u2013Z, 0\u20139"),
|
|
315
|
+
pattern: /^([^/]+\/)?([A-Za-z0-9][^/]*)?[A-Za-z0-9]$/
|
|
316
|
+
}, {
|
|
317
|
+
name: 'valueMaxLength',
|
|
318
|
+
label: '[Value] Max length - 63 characters',
|
|
319
|
+
pattern: /^([^/]+\/)?[^/]{1,63}$/
|
|
320
|
+
}, {
|
|
321
|
+
name: 'valueValidCharacters',
|
|
322
|
+
label: "[Value] ".concat(_constants.validation.VALID_CHARACTERS, ": a\u2013z, A\u2013Z, 0\u20139, \u2013, _, ."),
|
|
323
|
+
pattern: /^[a-zA-Z0-9\-_.]+$/
|
|
324
|
+
}]
|
|
325
|
+
}
|
|
326
|
+
// email: [
|
|
327
|
+
// generateRule.beginEndNotWith('@ .'),
|
|
328
|
+
// {
|
|
329
|
+
// name: 'exactlyOne',
|
|
330
|
+
// label: ValidationConstants.MUST_CONTAIN_EXACTLY_ONE + ': @',
|
|
331
|
+
// pattern: /^[^@]+@[^@]+$/
|
|
332
|
+
// },
|
|
333
|
+
// {
|
|
334
|
+
// name: 'dotAfterAt',
|
|
335
|
+
// label: ValidationConstants.MUST_HAVE_DOT_AFTER_AT,
|
|
336
|
+
// pattern: /@.+\..+$/
|
|
337
|
+
// }
|
|
338
|
+
// ]
|
|
339
|
+
};
|
|
286
340
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// label: ValidationConstants.MUST_CONTAIN_EXACTLY_ONE + ': @',
|
|
293
|
-
// pattern: /^[^@]+@[^@]+$/
|
|
294
|
-
// },
|
|
295
|
-
// {
|
|
296
|
-
// name: 'dotAfterAt',
|
|
297
|
-
// label: ValidationConstants.MUST_HAVE_DOT_AFTER_AT,
|
|
298
|
-
// pattern: /@.+\..+$/
|
|
299
|
-
// }
|
|
300
|
-
// ]
|
|
301
|
-
//}
|
|
341
|
+
commonRules.k8sLabels.key = commonRules.prefixedQualifiedName.concat({
|
|
342
|
+
name: 'prefixNotStart',
|
|
343
|
+
label: "[Prefix] Must not start with 'kubernetes.io', 'k8s.io'",
|
|
344
|
+
pattern: /^(?!kubernetes\.io\/)(?!k8s\.io\/)/
|
|
345
|
+
});
|
|
302
346
|
var validationRules = {
|
|
303
347
|
artifact: {
|
|
304
348
|
name: [generateRule.validCharacters('a-z A-Z 0-9 - _ .'), generateRule.beginEndWith('a-z A-Z 0-9'), generateRule.length({
|
|
@@ -334,7 +378,15 @@ var validationRules = {
|
|
|
334
378
|
project: {
|
|
335
379
|
name: [generateRule.validCharacters('a-z 0-9 -'), generateRule.beginWith('a-z'), generateRule.endWith('a-z 0-9'), generateRule.length({
|
|
336
380
|
max: 63
|
|
337
|
-
}), generateRule.required()]
|
|
381
|
+
}), generateRule.required()],
|
|
382
|
+
labels: {
|
|
383
|
+
key: commonRules.k8sLabels.key,
|
|
384
|
+
value: commonRules.k8sLabels.value
|
|
385
|
+
},
|
|
386
|
+
params: {
|
|
387
|
+
key: [generateRule.beginEndNotWith('s')],
|
|
388
|
+
value: [generateRule.beginEndNotWith('s')]
|
|
389
|
+
}
|
|
338
390
|
},
|
|
339
391
|
environmentVariables: {
|
|
340
392
|
secretName: [generateRule.validCharacters('a-z A-Z 0-9 - _ .'), generateRule.beginEndWith('a-z A-Z 0-9'), generateRule.noConsecutiveCharacters('.., .–, –.'), generateRule.maxLengthBetweenDelimiters(/[\.\-\_]/, 63, 'periods'), generateRule.length({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iguazio.dashboard-react-controls",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.11",
|
|
4
4
|
"description": "Collection of resources (such as CSS styles, fonts and images) and ReactJS 17.x components to share among different Iguazio React repos.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|