iguazio.dashboard-react-controls 1.9.2 → 2.0.0
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/Backdrop/Backdrop.js +7 -7
- package/dist/components/Button/Button.js +20 -26
- package/dist/components/ConfirmDialog/ConfirmDialog.js +18 -17
- package/dist/components/FormCheckBox/FormCheckBox.js +28 -32
- package/dist/components/FormChipCell/FormChip/FormChip.js +46 -50
- package/dist/components/FormChipCell/FormChipCell.js +122 -142
- package/dist/components/FormChipCell/FormChipCellView.js +44 -47
- package/dist/components/FormChipCell/HiddenChipsBlock/HiddenChipsBlock.js +23 -20
- package/dist/components/FormChipCell/NewChipForm/NewChipForm.js +129 -152
- package/dist/components/FormChipCell/NewChipInput/NewChipInput.js +24 -27
- package/dist/components/FormChipCell/formChipCell.util.js +6 -16
- package/dist/components/FormCombobox/FormCombobox.js +134 -195
- package/dist/components/FormInput/FormInput.js +134 -212
- package/dist/components/FormInput/InputNumberButtons/InputNumberButtons.js +15 -14
- package/dist/components/FormKeyValueTable/FormKeyValueTable.js +72 -72
- package/dist/components/FormRadio/FormRadio.js +21 -25
- package/dist/components/FormSelect/FormSelect.js +98 -126
- package/dist/components/FormSelect/FormSelect.test.js +56 -60
- package/dist/components/FormTextarea/FormTextarea.js +55 -71
- package/dist/components/FormToggle/FormToggle.js +25 -29
- package/dist/components/Modal/Modal.js +17 -18
- package/dist/components/PopUpDialog/PopUpDialog.js +53 -63
- package/dist/components/RoundedIcon/RoundedIcon.js +14 -13
- package/dist/components/Tip/Tip.js +58 -64
- package/dist/components/Tip/Tip.test.js +41 -64
- package/dist/components/Tooltip/Tooltip.js +75 -89
- package/dist/components/TooltipTemplate/ProducerTooltipTemplate.js +6 -5
- package/dist/components/TooltipTemplate/TextTooltipTemplate.js +10 -10
- package/dist/components/Wizard/Wizard.js +73 -107
- package/dist/components/Wizard/WizardSteps/WizardSteps.js +19 -20
- package/dist/components/index.js +18 -18
- package/dist/constants.js +26 -44
- package/dist/elements/FormActionButton/FormActionButton.js +12 -13
- package/dist/elements/FormRowActions/FormRowActions.js +19 -22
- package/dist/elements/OptionsMenu/OptionsMenu.js +10 -8
- package/dist/elements/SelectOption/SelectOption.js +14 -13
- package/dist/elements/SelectOption/SelectOption.test.js +39 -47
- package/dist/elements/ValidationTemplate/ValidationTemplate.js +7 -6
- package/dist/elements/index.js +5 -5
- package/dist/hooks/index.js +5 -5
- package/dist/hooks/useChipCell.hook.js +66 -85
- package/dist/hooks/useDebounce.hook.js +22 -24
- package/dist/hooks/useDetectOutsideClick.hook.js +4 -4
- package/dist/hooks/useFormTable.hook.js +99 -112
- package/dist/hooks/useHiddenChipsBlock.hook.js +40 -55
- package/dist/index.js +2 -3
- package/dist/scss/borders.scss +6 -0
- package/dist/scss/mixins.scss +32 -0
- package/dist/types.js +43 -67
- package/dist/utils/common.util.js +19 -23
- package/dist/utils/form.util.js +33 -39
- package/dist/utils/generateChipsList.util.js +7 -7
- package/dist/utils/getFirstScrollableParent.util.js +4 -10
- package/dist/utils/math.util.js +3 -3
- package/dist/utils/validation.util.js +74 -131
- package/package.json +34 -34
|
@@ -22,31 +22,29 @@ under the Apache 2.0 license is conditioned upon your compliance with
|
|
|
22
22
|
such restriction.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
lastResult.current = validate(value);
|
|
39
|
-
resolve(lastResult.current);
|
|
40
|
-
}, time);
|
|
41
|
-
timeout.current = function () {
|
|
42
|
-
clearTimeout(timerId);
|
|
43
|
-
resolve(true);
|
|
44
|
-
};
|
|
45
|
-
} else {
|
|
25
|
+
const useDebounce = () => (validate, time) => {
|
|
26
|
+
const timeout = (0, _react.useRef)(null);
|
|
27
|
+
const lastValue = (0, _react.useRef)(null);
|
|
28
|
+
const lastResult = (0, _react.useRef)(null);
|
|
29
|
+
return function (value) {
|
|
30
|
+
return new Promise(resolve => {
|
|
31
|
+
if (timeout.current) {
|
|
32
|
+
timeout.current();
|
|
33
|
+
}
|
|
34
|
+
if (value !== lastValue.current) {
|
|
35
|
+
const timerId = setTimeout(() => {
|
|
36
|
+
lastValue.current = value;
|
|
37
|
+
lastResult.current = validate(value);
|
|
46
38
|
resolve(lastResult.current);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
}, time);
|
|
40
|
+
timeout.current = () => {
|
|
41
|
+
clearTimeout(timerId);
|
|
42
|
+
resolve(true);
|
|
43
|
+
};
|
|
44
|
+
} else {
|
|
45
|
+
resolve(lastResult.current);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
50
48
|
};
|
|
51
49
|
};
|
|
52
50
|
exports.useDebounce = useDebounce;
|
|
@@ -28,9 +28,9 @@ such restriction.
|
|
|
28
28
|
* @param {React.node} ref
|
|
29
29
|
* @param {function} handler A callback function to use on outside click
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
|
-
(0, _react.useEffect)(
|
|
33
|
-
|
|
31
|
+
const useDetectOutsideClick = (ref, handler) => {
|
|
32
|
+
(0, _react.useEffect)(() => {
|
|
33
|
+
const onClick = e => {
|
|
34
34
|
e.stopPropagation();
|
|
35
35
|
// If the active element exists and is clicked outside of
|
|
36
36
|
if (ref.current !== null && !ref.current.contains(e.target)) {
|
|
@@ -39,7 +39,7 @@ var useDetectOutsideClick = function useDetectOutsideClick(ref, handler) {
|
|
|
39
39
|
};
|
|
40
40
|
// If the item is active (ie open) then listen for clicks outside
|
|
41
41
|
window.addEventListener('click', onClick);
|
|
42
|
-
return
|
|
42
|
+
return () => {
|
|
43
43
|
window.removeEventListener('click', onClick);
|
|
44
44
|
};
|
|
45
45
|
}, [ref, handler]);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,36 +7,27 @@ exports.useFormTable = void 0;
|
|
|
8
7
|
var _react = require("react");
|
|
9
8
|
var _lodash = require("lodash");
|
|
10
9
|
var _finalForm = require("final-form");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
implied. See the License for the specific language governing
|
|
33
|
-
permissions and limitations under the License.
|
|
34
|
-
|
|
35
|
-
In addition, you may not use the software for any purposes that are
|
|
36
|
-
illegal under applicable law, and the grant of the foregoing license
|
|
37
|
-
under the Apache 2.0 license is conditioned upon your compliance with
|
|
38
|
-
such restriction.
|
|
39
|
-
*/
|
|
40
|
-
var useFormTable = function useFormTable(formState, exitEditModeTriggerItem, onExitEditModeCallback) {
|
|
10
|
+
/*
|
|
11
|
+
Copyright 2019 Iguazio Systems Ltd.
|
|
12
|
+
|
|
13
|
+
Licensed under the Apache License, Version 2.0 (the "License") with
|
|
14
|
+
an addition restriction as set forth herein. You may not use this
|
|
15
|
+
file except in compliance with the License. You may obtain a copy of
|
|
16
|
+
the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
17
|
+
|
|
18
|
+
Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
21
|
+
implied. See the License for the specific language governing
|
|
22
|
+
permissions and limitations under the License.
|
|
23
|
+
|
|
24
|
+
In addition, you may not use the software for any purposes that are
|
|
25
|
+
illegal under applicable law, and the grant of the foregoing license
|
|
26
|
+
under the Apache 2.0 license is conditioned upon your compliance with
|
|
27
|
+
such restriction.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const useFormTable = (formState, exitEditModeTriggerItem, onExitEditModeCallback) => {
|
|
41
31
|
// `editingItem` should contain the `data` object with all fields that are used in the `formState`.
|
|
42
32
|
// Properties that aren't used in the `formState` should be placed directly in the `editingItem` object
|
|
43
33
|
// `editingItem` also has an `ui` property which is used internally in this hook
|
|
@@ -55,34 +45,30 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem, onE
|
|
|
55
45
|
// index: <0|1|...> // index of the editing row
|
|
56
46
|
// }
|
|
57
47
|
// }
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var onExitEditModeCallbackRef = (0, _react.useRef)(onExitEditModeCallback);
|
|
67
|
-
(0, _react.useLayoutEffect)(function () {
|
|
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, []);
|
|
48
|
+
const [editingItem, setEditingItem] = (0, _react.useState)(null);
|
|
49
|
+
const editingItemRef = (0, _react.useRef)(null);
|
|
50
|
+
const editingItemErrorsRef = (0, _react.useRef)(null);
|
|
51
|
+
const formStateRef = (0, _react.useRef)(null);
|
|
52
|
+
const bottomScrollRef = (0, _react.useRef)(null);
|
|
53
|
+
const onExitEditModeCallbackRef = (0, _react.useRef)(onExitEditModeCallback);
|
|
54
|
+
(0, _react.useLayoutEffect)(() => {
|
|
55
|
+
const tableErrors = (0, _lodash.get)(formState === null || formState === void 0 ? void 0 : formState.errors, editingItem === null || editingItem === void 0 ? void 0 : editingItem.ui.fieldsPath, []);
|
|
69
56
|
editingItemErrorsRef.current = (0, _lodash.get)(tableErrors, editingItem === null || editingItem === void 0 ? void 0 : editingItem.ui.index, null);
|
|
70
57
|
}, [editingItem === null || editingItem === void 0 ? void 0 : editingItem.ui.fieldsPath, editingItem === null || editingItem === void 0 ? void 0 : editingItem.ui.index, formState === null || formState === void 0 ? void 0 : formState.errors]);
|
|
71
|
-
(0, _react.useLayoutEffect)(
|
|
58
|
+
(0, _react.useLayoutEffect)(() => {
|
|
72
59
|
formStateRef.current = formState;
|
|
73
60
|
}, [formState]);
|
|
74
|
-
(0, _react.useLayoutEffect)(
|
|
61
|
+
(0, _react.useLayoutEffect)(() => {
|
|
75
62
|
onExitEditModeCallbackRef.current = onExitEditModeCallback;
|
|
76
63
|
}, [onExitEditModeCallback]);
|
|
77
|
-
|
|
64
|
+
const exitEditMode = () => {
|
|
78
65
|
var _editingItemRef$curre;
|
|
79
66
|
if ((_editingItemRef$curre = editingItemRef.current) !== null && _editingItemRef$curre !== void 0 && _editingItemRef$curre.data) {
|
|
80
67
|
var _editingItemRef$curre2;
|
|
81
|
-
Object.entries((_editingItemRef$curre2 = editingItemRef.current) === null || _editingItemRef$curre2 === void 0 ? void 0 : _editingItemRef$curre2.data).forEach(
|
|
68
|
+
Object.entries((_editingItemRef$curre2 = editingItemRef.current) === null || _editingItemRef$curre2 === void 0 ? void 0 : _editingItemRef$curre2.data).forEach(_ref => {
|
|
82
69
|
var _formStateRef$current, _editingItemRef$curre3, _editingItemRef$curre4;
|
|
83
|
-
|
|
84
|
-
|
|
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), {
|
|
70
|
+
let [fieldName] = _ref;
|
|
71
|
+
(_formStateRef$current = formStateRef.current) === null || _formStateRef$current === 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
72
|
modified: false
|
|
87
73
|
});
|
|
88
74
|
});
|
|
@@ -91,79 +77,79 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem, onE
|
|
|
91
77
|
setEditingItem(null);
|
|
92
78
|
(onExitEditModeCallbackRef === null || onExitEditModeCallbackRef === void 0 ? void 0 : onExitEditModeCallbackRef.current) && onExitEditModeCallbackRef.current();
|
|
93
79
|
};
|
|
94
|
-
(0, _react.useEffect)(
|
|
95
|
-
|
|
80
|
+
(0, _react.useEffect)(() => {
|
|
81
|
+
const applyOrDiscardOrDeleteInEffect = () => {
|
|
96
82
|
if (editingItemRef !== null && editingItemRef !== void 0 && editingItemRef.current) {
|
|
97
83
|
if (!editingItemErrorsRef.current) {
|
|
98
84
|
exitEditMode();
|
|
99
85
|
} else {
|
|
100
|
-
var _editingItemRef$curre5
|
|
101
|
-
if ((_editingItemRef$curre5 = editingItemRef.current) !== null && _editingItemRef$curre5 !== void 0 && (_editingItemRef$
|
|
102
|
-
var _editingItemRef$
|
|
103
|
-
|
|
86
|
+
var _editingItemRef$curre5;
|
|
87
|
+
if ((_editingItemRef$curre5 = editingItemRef.current) !== null && _editingItemRef$curre5 !== void 0 && (_editingItemRef$curre5 = _editingItemRef$curre5.ui) !== null && _editingItemRef$curre5 !== void 0 && _editingItemRef$curre5.isNew) {
|
|
88
|
+
var _editingItemRef$curre6;
|
|
89
|
+
const values = (0, _lodash.get)(formStateRef.current.values, (_editingItemRef$curre6 = editingItemRef.current) === null || _editingItemRef$curre6 === void 0 ? void 0 : _editingItemRef$curre6.ui.fieldsPath);
|
|
104
90
|
if ((values === null || values === void 0 ? void 0 : values.length) > 1) {
|
|
105
|
-
var _editingItemRef$
|
|
106
|
-
formStateRef.current.form.mutators.remove((_editingItemRef$
|
|
91
|
+
var _editingItemRef$curre7, _editingItemRef$curre8;
|
|
92
|
+
formStateRef.current.form.mutators.remove((_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);
|
|
107
93
|
} else {
|
|
108
|
-
var _editingItemRef$
|
|
109
|
-
formStateRef.current.form.change((_editingItemRef$
|
|
94
|
+
var _editingItemRef$curre9;
|
|
95
|
+
formStateRef.current.form.change((_editingItemRef$curre9 = editingItemRef.current) === null || _editingItemRef$curre9 === void 0 ? void 0 : _editingItemRef$curre9.ui.fieldsPath, []);
|
|
110
96
|
}
|
|
111
97
|
} else {
|
|
112
|
-
var _editingItemRef$
|
|
113
|
-
formStateRef.current.form.mutators.update((_editingItemRef$
|
|
98
|
+
var _editingItemRef$curre10, _editingItemRef$curre11;
|
|
99
|
+
formStateRef.current.form.mutators.update((_editingItemRef$curre10 = editingItemRef.current) === null || _editingItemRef$curre10 === void 0 ? void 0 : _editingItemRef$curre10.ui.fieldsPath, (_editingItemRef$curre11 = editingItemRef.current) === null || _editingItemRef$curre11 === void 0 ? void 0 : _editingItemRef$curre11.ui.index, (0, _lodash.omit)(editingItemRef.current, ['ui']));
|
|
114
100
|
}
|
|
115
101
|
exitEditMode();
|
|
116
102
|
}
|
|
117
103
|
}
|
|
118
104
|
};
|
|
119
|
-
return
|
|
105
|
+
return () => {
|
|
120
106
|
applyOrDiscardOrDeleteInEffect();
|
|
121
107
|
};
|
|
122
108
|
}, [exitEditModeTriggerItem]);
|
|
123
|
-
|
|
109
|
+
const addNewRow = (event, fields, fieldsPath, newItem) => {
|
|
124
110
|
applyOrDiscardOrDelete(event);
|
|
125
111
|
formStateRef.current.form.mutators.push(fieldsPath, newItem);
|
|
126
|
-
setEditingItem(
|
|
112
|
+
setEditingItem(() => {
|
|
127
113
|
var _fields$value;
|
|
128
|
-
|
|
114
|
+
const newEditingItem = {
|
|
115
|
+
...newItem,
|
|
129
116
|
ui: {
|
|
130
117
|
isNew: true,
|
|
131
|
-
fieldsPath
|
|
118
|
+
fieldsPath,
|
|
132
119
|
index: ((_fields$value = fields.value) === null || _fields$value === void 0 ? void 0 : _fields$value.length) || 0
|
|
133
120
|
}
|
|
134
|
-
}
|
|
121
|
+
};
|
|
135
122
|
editingItemRef.current = newEditingItem;
|
|
136
123
|
return newEditingItem;
|
|
137
124
|
});
|
|
138
125
|
scrollIntoView();
|
|
139
126
|
};
|
|
140
|
-
|
|
127
|
+
const applyChanges = (event, index) => {
|
|
141
128
|
if (editingItemRef.current) {
|
|
142
129
|
if (!editingItemErrorsRef.current) {
|
|
143
|
-
var _editingItemRef$
|
|
144
|
-
if ((_editingItemRef$
|
|
130
|
+
var _editingItemRef$curre12;
|
|
131
|
+
if ((_editingItemRef$curre12 = editingItemRef.current) !== null && _editingItemRef$curre12 !== void 0 && _editingItemRef$curre12.ui.isNew) {
|
|
145
132
|
scrollIntoView();
|
|
146
133
|
}
|
|
147
134
|
exitEditMode();
|
|
148
135
|
} else {
|
|
149
136
|
var _editingItemErrorsRef;
|
|
150
137
|
// Mark all empty fields as `modified` in order to highlight the error if the field is invalid
|
|
151
|
-
Object.entries((_editingItemErrorsRef = editingItemErrorsRef.current) === null || _editingItemErrorsRef === void 0 ? void 0 : _editingItemErrorsRef.data).forEach(
|
|
152
|
-
var _formStateRef$current2, _editingItemRef$
|
|
153
|
-
|
|
154
|
-
|
|
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), {
|
|
138
|
+
Object.entries((_editingItemErrorsRef = editingItemErrorsRef.current) === null || _editingItemErrorsRef === void 0 ? void 0 : _editingItemErrorsRef.data).forEach(_ref2 => {
|
|
139
|
+
var _formStateRef$current2, _editingItemRef$curre13;
|
|
140
|
+
let [fieldName] = _ref2;
|
|
141
|
+
(_formStateRef$current2 = formStateRef.current) === null || _formStateRef$current2 === void 0 || _formStateRef$current2.form.mutators.setFieldState("".concat((_editingItemRef$curre13 = editingItemRef.current) === null || _editingItemRef$curre13 === void 0 ? void 0 : _editingItemRef$curre13.ui.fieldsPath, "[").concat(index, "].data.").concat(fieldName), {
|
|
156
142
|
modified: true
|
|
157
143
|
});
|
|
158
144
|
});
|
|
159
145
|
}
|
|
160
146
|
}
|
|
161
147
|
};
|
|
162
|
-
|
|
148
|
+
const deleteRow = (event, fieldsPath, index) => {
|
|
163
149
|
if (editingItemRef.current && index !== editingItemRef.current.ui.index) {
|
|
164
150
|
applyOrDiscardOrDelete(event);
|
|
165
151
|
}
|
|
166
|
-
|
|
152
|
+
const values = (0, _lodash.get)(formStateRef.current.values, fieldsPath);
|
|
167
153
|
if ((values === null || values === void 0 ? void 0 : values.length) > 1) {
|
|
168
154
|
formStateRef.current.form.mutators.remove(fieldsPath, index);
|
|
169
155
|
} else {
|
|
@@ -172,50 +158,51 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem, onE
|
|
|
172
158
|
exitEditMode();
|
|
173
159
|
event && event.stopPropagation();
|
|
174
160
|
};
|
|
175
|
-
|
|
161
|
+
const discardChanges = (event, fieldsPath, index) => {
|
|
176
162
|
formStateRef.current.form.mutators.update(fieldsPath, index, (0, _lodash.omit)(editingItemRef.current, ['ui']));
|
|
177
163
|
exitEditMode();
|
|
178
164
|
event && event.stopPropagation();
|
|
179
165
|
};
|
|
180
|
-
|
|
181
|
-
var _editingItemRef$
|
|
182
|
-
if (!editingItemRef.current || (_editingItemRef$
|
|
166
|
+
const discardOrDelete = (event, fieldsPath, index) => {
|
|
167
|
+
var _editingItemRef$curre14;
|
|
168
|
+
if (!editingItemRef.current || (_editingItemRef$curre14 = editingItemRef.current) !== null && _editingItemRef$curre14 !== void 0 && (_editingItemRef$curre14 = _editingItemRef$curre14.ui) !== null && _editingItemRef$curre14 !== void 0 && _editingItemRef$curre14.isNew) {
|
|
183
169
|
deleteRow(event, fieldsPath, index);
|
|
184
170
|
} else {
|
|
185
171
|
discardChanges(event, fieldsPath, index);
|
|
186
172
|
}
|
|
187
173
|
};
|
|
188
|
-
|
|
189
|
-
|
|
174
|
+
const applyOrDiscardOrDelete = function () {
|
|
175
|
+
let event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
190
176
|
if (editingItemRef !== null && editingItemRef !== void 0 && editingItemRef.current) {
|
|
191
177
|
if (!editingItemErrorsRef.current) {
|
|
192
|
-
var _editingItemRef$
|
|
193
|
-
applyChanges(event, (_editingItemRef$
|
|
178
|
+
var _editingItemRef$curre15;
|
|
179
|
+
applyChanges(event, (_editingItemRef$curre15 = editingItemRef.current) === null || _editingItemRef$curre15 === void 0 ? void 0 : _editingItemRef$curre15.ui.index);
|
|
194
180
|
} else {
|
|
195
|
-
var _editingItemRef$
|
|
196
|
-
discardOrDelete(event, (_editingItemRef$
|
|
181
|
+
var _editingItemRef$curre16, _editingItemRef$curre17;
|
|
182
|
+
discardOrDelete(event, (_editingItemRef$curre16 = editingItemRef.current) === null || _editingItemRef$curre16 === void 0 ? void 0 : _editingItemRef$curre16.ui.fieldsPath, (_editingItemRef$curre17 = editingItemRef.current) === null || _editingItemRef$curre17 === void 0 ? void 0 : _editingItemRef$curre17.ui.index);
|
|
197
183
|
}
|
|
198
184
|
}
|
|
199
185
|
};
|
|
200
|
-
|
|
186
|
+
const enterEditMode = (event, fields, fieldsPath, index) => {
|
|
201
187
|
applyOrDiscardOrDelete(event);
|
|
202
|
-
setTimeout(
|
|
203
|
-
|
|
204
|
-
setEditingItem(
|
|
205
|
-
|
|
188
|
+
setTimeout(() => {
|
|
189
|
+
const editItem = fields.value[index];
|
|
190
|
+
setEditingItem(() => {
|
|
191
|
+
const newEditingItem = {
|
|
192
|
+
...editItem,
|
|
206
193
|
ui: {
|
|
207
|
-
fieldsPath
|
|
208
|
-
index
|
|
194
|
+
fieldsPath,
|
|
195
|
+
index
|
|
209
196
|
}
|
|
210
|
-
}
|
|
197
|
+
};
|
|
211
198
|
editingItemRef.current = newEditingItem;
|
|
212
199
|
return newEditingItem;
|
|
213
200
|
});
|
|
214
201
|
});
|
|
215
202
|
};
|
|
216
|
-
|
|
203
|
+
const scrollIntoView = () => {
|
|
217
204
|
if (bottomScrollRef.current) {
|
|
218
|
-
setTimeout(
|
|
205
|
+
setTimeout(() => {
|
|
219
206
|
bottomScrollRef.current.scrollIntoView({
|
|
220
207
|
behavior: 'smooth',
|
|
221
208
|
block: 'nearest'
|
|
@@ -223,10 +210,10 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem, onE
|
|
|
223
210
|
});
|
|
224
211
|
}
|
|
225
212
|
};
|
|
226
|
-
|
|
213
|
+
const isCurrentRowEditing = rowPath => {
|
|
227
214
|
return (editingItemRef === null || editingItemRef === void 0 ? void 0 : editingItemRef.current) && "".concat(editingItemRef.current.ui.fieldsPath, "[").concat(editingItemRef.current.ui.index, "]") === rowPath;
|
|
228
215
|
};
|
|
229
|
-
|
|
216
|
+
const getTableArrayErrors = fieldsPath => {
|
|
230
217
|
if (formState.submitFailed && formState.invalid) {
|
|
231
218
|
return (0, _lodash.get)(formState, "errors.".concat(fieldsPath, ".").concat(_finalForm.ARRAY_ERROR), []);
|
|
232
219
|
} else {
|
|
@@ -234,19 +221,19 @@ var useFormTable = function useFormTable(formState, exitEditModeTriggerItem, onE
|
|
|
234
221
|
}
|
|
235
222
|
};
|
|
236
223
|
return {
|
|
237
|
-
addNewRow
|
|
238
|
-
applyChanges
|
|
239
|
-
applyOrDiscardOrDelete
|
|
240
|
-
bottomScrollRef
|
|
241
|
-
deleteRow
|
|
242
|
-
discardChanges
|
|
243
|
-
discardOrDelete
|
|
244
|
-
editingItem
|
|
245
|
-
editingItemRef
|
|
246
|
-
enterEditMode
|
|
247
|
-
exitEditMode
|
|
248
|
-
getTableArrayErrors
|
|
249
|
-
isCurrentRowEditing
|
|
224
|
+
addNewRow,
|
|
225
|
+
applyChanges,
|
|
226
|
+
applyOrDiscardOrDelete,
|
|
227
|
+
bottomScrollRef,
|
|
228
|
+
deleteRow,
|
|
229
|
+
discardChanges,
|
|
230
|
+
discardOrDelete,
|
|
231
|
+
editingItem,
|
|
232
|
+
editingItemRef,
|
|
233
|
+
enterEditMode,
|
|
234
|
+
exitEditMode,
|
|
235
|
+
getTableArrayErrors,
|
|
236
|
+
isCurrentRowEditing
|
|
250
237
|
};
|
|
251
238
|
};
|
|
252
239
|
exports.useFormTable = useFormTable;
|
|
@@ -8,60 +8,45 @@ var _react = require("react");
|
|
|
8
8
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
9
|
var _common = require("../utils/common.util");
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
isTop = _useState2[0],
|
|
39
|
-
setIsTop = _useState2[1];
|
|
40
|
-
var _useState3 = (0, _react.useState)(false),
|
|
41
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
42
|
-
isLeft = _useState4[0],
|
|
43
|
-
setIsLeft = _useState4[1];
|
|
44
|
-
var _useState5 = (0, _react.useState)(false),
|
|
45
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
46
|
-
isVisible = _useState6[0],
|
|
47
|
-
setIsVisible = _useState6[1];
|
|
48
|
-
var transitionEndEventName = (0, _react.useMemo)(function () {
|
|
49
|
-
return (0, _common.getTransitionEndEventName)();
|
|
50
|
-
}, []);
|
|
51
|
-
var hiddenChipsBlockClassNames = (0, _classnames.default)('chip-block-hidden', isTop ? 'chip-block-hidden_top' : 'chip-block-hidden_bottom', isLeft ? 'chip-block-hidden_left' : 'chip-block-hidden_right', isVisible && 'chip-block-hidden_visible');
|
|
52
|
-
var resizePopUp = (0, _react.useCallback)(function () {
|
|
11
|
+
/*
|
|
12
|
+
Copyright 2019 Iguazio Systems Ltd.
|
|
13
|
+
|
|
14
|
+
Licensed under the Apache License, Version 2.0 (the "License") with
|
|
15
|
+
an addition restriction as set forth herein. You may not use this
|
|
16
|
+
file except in compliance with the License. You may obtain a copy of
|
|
17
|
+
the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
18
|
+
|
|
19
|
+
Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
22
|
+
implied. See the License for the specific language governing
|
|
23
|
+
permissions and limitations under the License.
|
|
24
|
+
|
|
25
|
+
In addition, you may not use the software for any purposes that are
|
|
26
|
+
illegal under applicable law, and the grant of the foregoing license
|
|
27
|
+
under the Apache 2.0 license is conditioned upon your compliance with
|
|
28
|
+
such restriction.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const useHiddenChipsBlock = (hiddenChipsCounterRef, hiddenChipsPopUpRef) => {
|
|
32
|
+
const [isTop, setIsTop] = (0, _react.useState)(false);
|
|
33
|
+
const [isLeft, setIsLeft] = (0, _react.useState)(false);
|
|
34
|
+
const [isVisible, setIsVisible] = (0, _react.useState)(false);
|
|
35
|
+
const transitionEndEventName = (0, _react.useMemo)(() => (0, _common.getTransitionEndEventName)(), []);
|
|
36
|
+
const hiddenChipsBlockClassNames = (0, _classnames.default)('chip-block-hidden', isTop ? 'chip-block-hidden_top' : 'chip-block-hidden_bottom', isLeft ? 'chip-block-hidden_left' : 'chip-block-hidden_right', isVisible && 'chip-block-hidden_visible');
|
|
37
|
+
const resizePopUp = (0, _react.useCallback)(() => {
|
|
53
38
|
if (hiddenChipsPopUpRef !== null && hiddenChipsPopUpRef !== void 0 && hiddenChipsPopUpRef.current && hiddenChipsCounterRef !== null && hiddenChipsCounterRef !== void 0 && hiddenChipsCounterRef.current) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
const offset = 10;
|
|
40
|
+
const offsetMargin = 20;
|
|
41
|
+
const elementRect = hiddenChipsCounterRef.current.getBoundingClientRect();
|
|
57
42
|
|
|
58
43
|
// Calculate the distance from the right edge of the window to the element's right edge
|
|
59
|
-
|
|
44
|
+
const elementRectRight = Math.floor(window.innerWidth - elementRect.left - elementRect.width);
|
|
60
45
|
|
|
61
46
|
// Calculate the distance from the bottom edge of the window to the element's bottom edge
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
47
|
+
const elementRectBottom = Math.floor(window.innerHeight - elementRect.top - elementRect.height);
|
|
48
|
+
let isLeftPosition = false;
|
|
49
|
+
let isTopPosition = false;
|
|
65
50
|
hiddenChipsPopUpRef.current.style.maxWidth = '100%';
|
|
66
51
|
hiddenChipsPopUpRef.current.style.maxHeight = '100%';
|
|
67
52
|
|
|
@@ -73,7 +58,7 @@ var useHiddenChipsBlock = function useHiddenChipsBlock(hiddenChipsCounterRef, hi
|
|
|
73
58
|
} else {
|
|
74
59
|
// Compare elementRect.left and elementRectRight to choose the larger value as the max width
|
|
75
60
|
isLeftPosition = elementRect.left > elementRectRight;
|
|
76
|
-
|
|
61
|
+
const popUpMaxWidth = Math.max(elementRect.left, elementRectRight);
|
|
77
62
|
hiddenChipsPopUpRef.current.style.maxWidth = "".concat(popUpMaxWidth, "px");
|
|
78
63
|
}
|
|
79
64
|
hiddenChipsPopUpRef.current.style.right = isLeftPosition ? "".concat(elementRectRight, "px") : 'unset';
|
|
@@ -87,7 +72,7 @@ var useHiddenChipsBlock = function useHiddenChipsBlock(hiddenChipsCounterRef, hi
|
|
|
87
72
|
} else {
|
|
88
73
|
// Compare elementRect.top and elementRectBottom to choose the larger value as the max height
|
|
89
74
|
isTopPosition = elementRect.top > elementRectBottom + offset;
|
|
90
|
-
|
|
75
|
+
const popUpMaxHeight = Math.max(elementRect.top, elementRectBottom) - offset - offsetMargin;
|
|
91
76
|
hiddenChipsPopUpRef.current.style.maxHeight = "".concat(popUpMaxHeight, "px");
|
|
92
77
|
}
|
|
93
78
|
hiddenChipsPopUpRef.current.style.bottom = isTopPosition ? "".concat(elementRectBottom + elementRect.height + offset, "px") : 'unset';
|
|
@@ -97,21 +82,21 @@ var useHiddenChipsBlock = function useHiddenChipsBlock(hiddenChipsCounterRef, hi
|
|
|
97
82
|
setIsVisible(true);
|
|
98
83
|
}
|
|
99
84
|
}, [hiddenChipsCounterRef, hiddenChipsPopUpRef]);
|
|
100
|
-
(0, _react.useEffect)(
|
|
85
|
+
(0, _react.useEffect)(() => {
|
|
101
86
|
if (hiddenChipsPopUpRef !== null && hiddenChipsPopUpRef !== void 0 && hiddenChipsPopUpRef.current && hiddenChipsCounterRef !== null && hiddenChipsCounterRef !== void 0 && hiddenChipsCounterRef.current) {
|
|
102
87
|
window.addEventListener('resize', resizePopUp);
|
|
103
88
|
window.addEventListener(transitionEndEventName, resizePopUp);
|
|
104
|
-
return
|
|
89
|
+
return () => {
|
|
105
90
|
window.removeEventListener('resize', resizePopUp);
|
|
106
91
|
window.removeEventListener(transitionEndEventName, resizePopUp);
|
|
107
92
|
};
|
|
108
93
|
}
|
|
109
94
|
}, [hiddenChipsPopUpRef, hiddenChipsCounterRef, resizePopUp, transitionEndEventName]);
|
|
110
|
-
(0, _react.useEffect)(
|
|
95
|
+
(0, _react.useEffect)(() => {
|
|
111
96
|
resizePopUp();
|
|
112
97
|
}, [resizePopUp]);
|
|
113
98
|
return {
|
|
114
|
-
hiddenChipsBlockClassNames
|
|
99
|
+
hiddenChipsBlockClassNames
|
|
115
100
|
};
|
|
116
101
|
};
|
|
117
102
|
exports.useHiddenChipsBlock = useHiddenChipsBlock;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -15,5 +14,5 @@ var hooks = _interopRequireWildcard(require("./hooks"));
|
|
|
15
14
|
exports.hooks = hooks;
|
|
16
15
|
var types = _interopRequireWildcard(require("./types"));
|
|
17
16
|
exports.types = types;
|
|
18
|
-
function _getRequireWildcardCache(
|
|
19
|
-
function _interopRequireWildcard(
|
|
17
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
18
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
package/dist/scss/borders.scss
CHANGED
|
@@ -18,3 +18,9 @@ $labelEditBorder: 1px solid rgba($amethyst, 0.34);
|
|
|
18
18
|
$applyBtnBorder: 4px solid $brightTurquoise;
|
|
19
19
|
$focusBorder: 1px solid $topaz;
|
|
20
20
|
$tableRowBorder: 1px solid $titanWhite;
|
|
21
|
+
|
|
22
|
+
// stats borders
|
|
23
|
+
$runningBorder: 2px solid $pictonBlue;
|
|
24
|
+
$totalBorder: 2px solid rgba($black, 0.2);
|
|
25
|
+
$failedBorder: 2px solid $amaranth;
|
|
26
|
+
$completedBorder: 2px solid $brightTurquoise;
|