tenjin-ui-kit 0.3.72-dev-1 → 0.3.73
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/common/hooks/apiHooks.js +91 -199
- package/common/hooks/newApiHook.js +127 -258
- package/common/utils/security/index.js +2 -2
- package/common/utils/security/securityConfig.js +1 -2
- package/components/Canvas.js +172 -101
- package/components/DragBox/index.js +21 -31
- package/components/InputWithChip/index.js +178 -83
- package/components/RightContext/index.js +17 -41
- package/components/WorkFlow.js +19 -29
- package/components/WorkFlowBuilder.js +32 -56
- package/components/alert/Style.js +11 -14
- package/components/alert/index.js +8 -14
- package/components/attachment/index.js +26 -31
- package/components/authenticationProvider/AuthError.js +3 -4
- package/components/authenticationProvider/AuthLoader.js +3 -4
- package/components/authenticationProvider/index.js +58 -130
- package/components/avatar/index.js +24 -23
- package/components/avatar/styles.js +76 -77
- package/components/breadCrumbs/index.js +64 -89
- package/components/breadCrumbs/style.js +1 -4
- package/components/browsingTestCaseLayout/DetailsViewLayout/DetailsViewContent/index.js +7 -6
- package/components/browsingTestCaseLayout/DetailsViewLayout/DetailsViewContent/style.js +5 -8
- package/components/browsingTestCaseLayout/DetailsViewLayout/DetailsViewHeader/index.js +7 -6
- package/components/browsingTestCaseLayout/TreeViewLayout/TreeViewContent/Index.js +8 -7
- package/components/browsingTestCaseLayout/TreeViewLayout/TreeViewHeader/Index.js +8 -7
- package/components/browsingTestCaseLayout/TreeViewLayout/TreeViewHeader/style.js +16 -19
- package/components/browsingTestCaseLayout/index.js +30 -46
- package/components/button/index.js +47 -58
- package/components/chatBotModal/index.js +40 -61
- package/components/checkBox/index.js +8 -10
- package/components/combobox/index.js +66 -100
- package/components/divider/index.js +9 -18
- package/components/editableField/index.js +19 -46
- package/components/error/index.js +6 -12
- package/components/errorBoundary/index.js +74 -98
- package/components/fileUploader/index.js +46 -58
- package/components/fileUploader/style.js +46 -49
- package/components/filter/ValueSelector.js +149 -245
- package/components/filter/index.js +45 -71
- package/components/iconButton/index.js +3 -4
- package/components/input/index.js +60 -74
- package/components/layout/index.js +36 -49
- package/components/layout/main/index.js +13 -14
- package/components/layout/main/style.js +11 -14
- package/components/layout/pageContent/index.js +8 -7
- package/components/layout/sidebar/FlatMenu.js +51 -47
- package/components/layout/sidebar/GroupedIconMenu.js +169 -194
- package/components/layout/sidebar/GroupedMenu.js +45 -50
- package/components/layout/sidebar/ProjectMenu.js +165 -185
- package/components/layout/sidebar/index.js +27 -26
- package/components/layout/sidebar/style.js +138 -143
- package/components/layout/topBar/ProjectTopbar.js +91 -208
- package/components/layout/topBar/UserAvatar.js +53 -69
- package/components/layout/topBar/index.js +23 -41
- package/components/loader/index.js +9 -12
- package/components/menu/index.js +23 -42
- package/components/modal/Modal.js +5 -6
- package/components/modal/index.js +16 -20
- package/components/modal/style.js +53 -56
- package/components/optionMenu/index.js +32 -47
- package/components/pagination/index.js +23 -43
- package/components/pagination/style.js +25 -28
- package/components/paginationUpdated/index.js +22 -29
- package/components/paper/index.js +20 -22
- package/components/paper/style.js +24 -27
- package/components/reactSelect/index.js +64 -97
- package/components/reactSelect/style.js +131 -151
- package/components/richTextEditor/index.js +24 -48
- package/components/select/GroupedSelect.js +96 -99
- package/components/select/SimpleSelect.js +61 -103
- package/components/select/index.js +56 -69
- package/components/simpleSelect/index.js +18 -22
- package/components/sort/index.js +23 -36
- package/components/switch/index.js +14 -15
- package/components/switch/style.js +29 -32
- package/components/switch/switch.js +30 -47
- package/components/table/ReactTable.js +59 -83
- package/components/table/SimpleTable.js +67 -91
- package/components/table/index.js +300 -206
- package/components/text/index.js +22 -30
- package/components/timeStamp/index.js +4 -9
- package/components/timeStamp/style.js +12 -15
- package/components/topBar/index.js +86 -102
- package/components/tree/index.js +30 -58
- package/components/tree/style.js +20 -23
- package/components/valuePicker/ValueSelector.js +78 -160
- package/components/valuePicker/index.js +30 -50
- package/components/wrapperLayout/layout/index.js +8 -7
- package/components/wrapperLayout/main/index.js +8 -7
- package/components/wrapperLayout/main/pageContainer/index.js +6 -5
- package/components/wrapperLayout/main/sideBar/index.js +171 -175
- package/components/wrapperLayout/main/sideBar/style.js +177 -183
- package/components/wrapperLayout/topBar/UserAvatar.js +6 -5
- package/components/wrapperLayout/topBar/avatar.js +15 -18
- package/components/wrapperLayout/topBar/index.js +115 -107
- package/components/wrapperLayout/topBar/menuIcon.js +6 -5
- package/components/wrapperLayout/topBar/style.js +63 -64
- package/http/index.js +92 -188
- package/index.js +53 -55
- package/package.json +3 -3
- package/templates/listPage/index.js +168 -196
- package/themes/default.js +5 -7
- package/themes/defaultSmall.js +2 -3
- package/themes/responsiveTheme.js +6 -8
|
@@ -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
|
});
|
|
@@ -10,90 +9,95 @@ var _FormControl = _interopRequireDefault(require("@mui/material/FormControl"));
|
|
|
10
9
|
var _fa = require("react-icons/fa");
|
|
11
10
|
var _reactDom = require("react-dom");
|
|
12
11
|
var _text = _interopRequireDefault(require("../text"));
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
37
|
-
searchTerm = _React$useState2[0],
|
|
38
|
-
setSearchTerm = _React$useState2[1];
|
|
39
|
-
var _React$useState3 = React.useState(false),
|
|
40
|
-
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
41
|
-
isDropdownOpen = _React$useState4[0],
|
|
42
|
-
setIsDropdownOpen = _React$useState4[1];
|
|
43
|
-
var _React$useState5 = React.useState(propValue || defaultValue),
|
|
44
|
-
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
45
|
-
value = _React$useState6[0],
|
|
46
|
-
setValue = _React$useState6[1];
|
|
47
|
-
var _React$useState7 = React.useState(null),
|
|
48
|
-
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
|
49
|
-
hoveredOption = _React$useState8[0],
|
|
50
|
-
setHoveredOption = _React$useState8[1];
|
|
51
|
-
var groupOptionsByPageTitle = function groupOptionsByPageTitle(options) {
|
|
52
|
-
var grouped = {};
|
|
53
|
-
options.forEach(function (option) {
|
|
54
|
-
var _grouped$option$pageT;
|
|
55
|
-
if (!grouped[option === null || option === void 0 ? void 0 : option.pageTitle]) {
|
|
56
|
-
grouped[option === null || option === void 0 ? void 0 : option.pageTitle] = [];
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
15
|
+
const GroupedSelect = _ref => {
|
|
16
|
+
let {
|
|
17
|
+
options = [],
|
|
18
|
+
onChange,
|
|
19
|
+
value: propValue,
|
|
20
|
+
defaultValue,
|
|
21
|
+
fullWidth,
|
|
22
|
+
...rest
|
|
23
|
+
} = _ref;
|
|
24
|
+
const triggerRef = React.useRef(null);
|
|
25
|
+
const dropdownRef = React.useRef(null);
|
|
26
|
+
const [searchTerm, setSearchTerm] = React.useState("");
|
|
27
|
+
const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);
|
|
28
|
+
const [value, setValue] = React.useState(propValue ?? defaultValue);
|
|
29
|
+
const [hoveredOption, setHoveredOption] = React.useState(null);
|
|
30
|
+
const groupOptionsByPageTitle = React.useCallback(options => {
|
|
31
|
+
return options.reduce((grouped, option) => {
|
|
32
|
+
const pageTitle = option?.pageTitle;
|
|
33
|
+
if (!grouped[pageTitle]) {
|
|
34
|
+
grouped[pageTitle] = [];
|
|
57
35
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
|
|
36
|
+
grouped[pageTitle].push(option);
|
|
37
|
+
return grouped;
|
|
38
|
+
}, {});
|
|
39
|
+
}, []);
|
|
40
|
+
const handleSearchChange = event => {
|
|
63
41
|
setSearchTerm(event.target.value);
|
|
64
42
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return (option
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
setIsDropdownOpen(
|
|
72
|
-
return !prev;
|
|
73
|
-
});
|
|
43
|
+
const filteredOptions = React.useMemo(() => {
|
|
44
|
+
const search = searchTerm.toLowerCase();
|
|
45
|
+
return options.filter(option => option?.label?.toLowerCase().includes(search) || option?.pageTitle?.toLowerCase().includes(search));
|
|
46
|
+
}, [options, searchTerm]);
|
|
47
|
+
const groupedOptions = React.useMemo(() => groupOptionsByPageTitle(filteredOptions), [filteredOptions, groupOptionsByPageTitle]);
|
|
48
|
+
const toggleDropdown = () => {
|
|
49
|
+
setIsDropdownOpen(prev => !prev);
|
|
74
50
|
};
|
|
75
|
-
|
|
51
|
+
const handleOptionClick = selectedValue => {
|
|
76
52
|
setValue(selectedValue);
|
|
77
53
|
setIsDropdownOpen(false);
|
|
78
|
-
|
|
54
|
+
setSearchTerm("");
|
|
55
|
+
onChange?.({
|
|
79
56
|
target: {
|
|
80
57
|
value: selectedValue
|
|
81
58
|
}
|
|
82
59
|
});
|
|
83
60
|
};
|
|
84
|
-
|
|
61
|
+
const handleCloseDropdown = () => {
|
|
85
62
|
setIsDropdownOpen(false);
|
|
86
63
|
};
|
|
64
|
+
|
|
65
|
+
// Keep internal value in sync if component is used as a controlled component
|
|
66
|
+
React.useEffect(() => {
|
|
67
|
+
if (propValue !== undefined) {
|
|
68
|
+
setValue(propValue);
|
|
69
|
+
}
|
|
70
|
+
}, [propValue]);
|
|
71
|
+
|
|
72
|
+
// Close dropdown when clicking outside
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
if (!isDropdownOpen) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const handleOutsideClick = event => {
|
|
78
|
+
const target = event.target;
|
|
79
|
+
const clickedInsideTrigger = triggerRef.current?.contains(target);
|
|
80
|
+
const clickedInsideDropdown = dropdownRef.current?.contains(target);
|
|
81
|
+
if (clickedInsideTrigger || clickedInsideDropdown) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
handleCloseDropdown();
|
|
85
|
+
};
|
|
86
|
+
document.addEventListener("mousedown", handleOutsideClick);
|
|
87
|
+
return () => {
|
|
88
|
+
document.removeEventListener("mousedown", handleOutsideClick);
|
|
89
|
+
};
|
|
90
|
+
}, [isDropdownOpen]);
|
|
87
91
|
return /*#__PURE__*/React.createElement(_FormControl.default, _extends({
|
|
88
92
|
sx: {
|
|
89
93
|
width: fullWidth ? "100%" : 200
|
|
90
94
|
}
|
|
91
95
|
}, rest), /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
ref: triggerRef,
|
|
92
97
|
style: {
|
|
93
98
|
position: "relative",
|
|
94
99
|
width: "100%"
|
|
95
|
-
}
|
|
96
|
-
ref: triggerRef
|
|
100
|
+
}
|
|
97
101
|
}, /*#__PURE__*/React.createElement("div", {
|
|
98
102
|
onClick: toggleDropdown,
|
|
99
103
|
style: {
|
|
@@ -109,14 +113,13 @@ var GroupedSelect = function GroupedSelect(_ref) {
|
|
|
109
113
|
style: {
|
|
110
114
|
flexGrow: 1
|
|
111
115
|
}
|
|
112
|
-
}, value ? options ===
|
|
113
|
-
|
|
114
|
-
})) === null || _options$find === void 0 ? void 0 : _options$find.label : "Select Option"), /*#__PURE__*/React.createElement("div", null, isDropdownOpen ? /*#__PURE__*/React.createElement(_fa.FaCaretUp, null) : /*#__PURE__*/React.createElement(_fa.FaCaretDown, null)))), isDropdownOpen && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/React.createElement("div", {
|
|
116
|
+
}, value ? options?.find(option => option?.id === value)?.label : "Select Option"), /*#__PURE__*/React.createElement("div", null, isDropdownOpen ? /*#__PURE__*/React.createElement(_fa.FaCaretUp, null) : /*#__PURE__*/React.createElement(_fa.FaCaretDown, null)))), isDropdownOpen && /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/React.createElement("div", {
|
|
117
|
+
ref: dropdownRef,
|
|
115
118
|
style: {
|
|
116
119
|
position: "absolute",
|
|
117
|
-
top:
|
|
118
|
-
left:
|
|
119
|
-
width:
|
|
120
|
+
top: `${triggerRef.current?.getBoundingClientRect().bottom + 8}px`,
|
|
121
|
+
left: `${triggerRef.current?.getBoundingClientRect().left}px`,
|
|
122
|
+
width: `${triggerRef.current?.offsetWidth}px`,
|
|
120
123
|
backgroundColor: "#fff",
|
|
121
124
|
border: "1px solid #ccc",
|
|
122
125
|
borderRadius: "4px",
|
|
@@ -143,41 +146,35 @@ var GroupedSelect = function GroupedSelect(_ref) {
|
|
|
143
146
|
margin: 0,
|
|
144
147
|
width: "100%",
|
|
145
148
|
border: "1px solid #949494",
|
|
146
|
-
borderRadius: "4px"
|
|
149
|
+
borderRadius: "4px",
|
|
150
|
+
boxSizing: "border-box"
|
|
147
151
|
}
|
|
148
|
-
}),
|
|
149
|
-
|
|
150
|
-
pageTitle = _ref3[0],
|
|
151
|
-
options = _ref3[1];
|
|
152
|
+
}), Object.entries(groupedOptions).map(_ref2 => {
|
|
153
|
+
let [pageTitle, groupedPageOptions] = _ref2;
|
|
152
154
|
return /*#__PURE__*/React.createElement("div", {
|
|
153
155
|
key: pageTitle
|
|
154
156
|
}, /*#__PURE__*/React.createElement(_text.default, {
|
|
155
157
|
style: {
|
|
156
158
|
padding: "5px 10px"
|
|
157
|
-
// backgroundColor: "#f5f5f5",
|
|
158
159
|
},
|
|
159
|
-
|
|
160
160
|
semibold: true
|
|
161
|
-
}, pageTitle
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}));
|
|
180
|
-
}))), document.body));
|
|
161
|
+
}, pageTitle || "N/A"), groupedPageOptions.map(option => /*#__PURE__*/React.createElement("div", {
|
|
162
|
+
key: option?.id,
|
|
163
|
+
onClick: () => handleOptionClick(option.id),
|
|
164
|
+
onMouseEnter: () => setHoveredOption(option.id),
|
|
165
|
+
onMouseLeave: () => setHoveredOption(null),
|
|
166
|
+
style: {
|
|
167
|
+
padding: "8px 24px",
|
|
168
|
+
cursor: "pointer",
|
|
169
|
+
backgroundColor: value === option?.id ? "#f0f0f7" : hoveredOption === option?.id ? "#f5f5f5" : "transparent"
|
|
170
|
+
}
|
|
171
|
+
}, option?.label)));
|
|
172
|
+
}), Object.keys(groupedOptions).length === 0 && /*#__PURE__*/React.createElement("div", {
|
|
173
|
+
style: {
|
|
174
|
+
padding: "10px",
|
|
175
|
+
textAlign: "center",
|
|
176
|
+
color: "#666"
|
|
177
|
+
}
|
|
178
|
+
}, "No options found"))), document.body));
|
|
181
179
|
};
|
|
182
|
-
var _default = GroupedSelect;
|
|
183
|
-
exports.default = _default;
|
|
180
|
+
var _default = exports.default = GroupedSelect;
|
|
@@ -7,125 +7,90 @@ exports.default = void 0;
|
|
|
7
7
|
var _material = require("@mui/material");
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _text = _interopRequireDefault(require("../text"));
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
helperText = _ref.helperText,
|
|
35
|
-
isSearch = _ref.isSearch,
|
|
36
|
-
isClearOption = _ref.isClearOption,
|
|
37
|
-
loading = _ref.loading,
|
|
38
|
-
isSort = _ref.isSort,
|
|
39
|
-
placeholder = _ref.placeholder,
|
|
40
|
-
placeholderText = _ref.placeholderText,
|
|
41
|
-
clearOptionText = _ref.clearOptionText,
|
|
42
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
43
|
-
isSort = (_isSort = isSort) !== null && _isSort !== void 0 ? _isSort : true; //by default true
|
|
44
|
-
isSearch = (_isSearch = isSearch) !== null && _isSearch !== void 0 ? _isSearch : true; //by default true
|
|
45
|
-
isClearOption = (_isClearOption = isClearOption) !== null && _isClearOption !== void 0 ? _isClearOption : true; //by default true
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
13
|
+
const SimpleSelect = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
options,
|
|
16
|
+
errorMessage,
|
|
17
|
+
error,
|
|
18
|
+
fullWidth,
|
|
19
|
+
isDisabled,
|
|
20
|
+
label,
|
|
21
|
+
isRequired,
|
|
22
|
+
helperText,
|
|
23
|
+
isSearch,
|
|
24
|
+
isClearOption,
|
|
25
|
+
loading,
|
|
26
|
+
isSort,
|
|
27
|
+
placeholder,
|
|
28
|
+
// Add placeholder prop
|
|
29
|
+
...rest
|
|
30
|
+
} = _ref;
|
|
31
|
+
isSort = isSort ?? true; //by default true
|
|
32
|
+
isSearch = isSearch ?? true; //by default true
|
|
33
|
+
isClearOption = isClearOption ?? true; //by default true
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var _useState3 = (0, _react.useState)(false),
|
|
52
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
53
|
-
noDataAvailable = _useState4[0],
|
|
54
|
-
setNoDataAvailable = _useState4[1];
|
|
55
|
-
var validateChildren = function validateChildren(type, searchText) {
|
|
56
|
-
if (_typeof(type) !== "object") {
|
|
35
|
+
const [searchText, setSearchText] = (0, _react.useState)("");
|
|
36
|
+
const [noDataAvailable, setNoDataAvailable] = (0, _react.useState)(false);
|
|
37
|
+
const validateChildren = (type, searchText) => {
|
|
38
|
+
if (typeof type !== "object") {
|
|
57
39
|
return typeof type === "string" && type.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
|
|
58
40
|
}
|
|
59
|
-
if (
|
|
60
|
-
return type.props.children.some(
|
|
61
|
-
return validateChildren(data, searchText);
|
|
62
|
-
});
|
|
41
|
+
if (typeof type.props === "object" && Array.isArray(type.props.children)) {
|
|
42
|
+
return type.props.children.some(data => validateChildren(data, searchText));
|
|
63
43
|
}
|
|
64
44
|
return false;
|
|
65
45
|
};
|
|
66
|
-
|
|
46
|
+
const containsText = (text, searchText) => {
|
|
67
47
|
if (typeof text === "string" && typeof searchText === "string") {
|
|
68
48
|
return text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
|
|
69
49
|
}
|
|
70
|
-
if (
|
|
71
|
-
return text.props.children.some(
|
|
72
|
-
return validateChildren(data, searchText);
|
|
73
|
-
});
|
|
50
|
+
if (typeof text === "object" && text.props && Array.isArray(text.props.children)) {
|
|
51
|
+
return text.props.children.some(data => validateChildren(data, searchText));
|
|
74
52
|
}
|
|
75
53
|
return false;
|
|
76
54
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return containsText(option === null || option === void 0 ? void 0 : option.label, searchText);
|
|
80
|
-
});
|
|
55
|
+
const displayedOptions = (0, _react.useMemo)(() => {
|
|
56
|
+
const filteredOptions = options?.filter(option => containsText(option?.label, searchText));
|
|
81
57
|
if (isSearch) {
|
|
82
|
-
setNoDataAvailable(
|
|
58
|
+
setNoDataAvailable(filteredOptions?.length === 0);
|
|
83
59
|
}
|
|
84
60
|
|
|
85
61
|
// const sortedOptions = filteredOptions?.sort((a, b) =>
|
|
86
62
|
// a?.label?.localeCompare(b.label)
|
|
87
63
|
// );
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
64
|
+
const sortedOptions = filteredOptions?.slice().sort((a, b) => {
|
|
65
|
+
const labelA = typeof a.label === "string" ? a.label : findStringInChildren(a.label.props.children);
|
|
66
|
+
const labelB = typeof b.label === "string" ? b.label : findStringInChildren(b.label.props.children);
|
|
91
67
|
return labelA.localeCompare(labelB);
|
|
92
68
|
});
|
|
93
69
|
function findStringInChildren(children) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (typeof child === "string") {
|
|
100
|
-
return child;
|
|
101
|
-
} else if (child.props && typeof child.props.children === "string") {
|
|
102
|
-
return child.props.children;
|
|
103
|
-
}
|
|
70
|
+
for (const child of children) {
|
|
71
|
+
if (typeof child === "string") {
|
|
72
|
+
return child;
|
|
73
|
+
} else if (child.props && typeof child.props.children === "string") {
|
|
74
|
+
return child.props.children;
|
|
104
75
|
}
|
|
105
|
-
} catch (err) {
|
|
106
|
-
_iterator.e(err);
|
|
107
|
-
} finally {
|
|
108
|
-
_iterator.f();
|
|
109
76
|
}
|
|
110
77
|
return "";
|
|
111
78
|
}
|
|
112
|
-
return (isSort ? sortedOptions : filteredOptions).map(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
117
|
-
});
|
|
79
|
+
return (isSort ? sortedOptions : filteredOptions).map(option => ({
|
|
80
|
+
label: option?.label,
|
|
81
|
+
value: option?.value
|
|
82
|
+
}));
|
|
118
83
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
119
84
|
}, [options, searchText, isSearch]);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
85
|
+
const recommendedOptions = isSearch ? displayedOptions : options;
|
|
86
|
+
let typingTimer;
|
|
87
|
+
const handleKeyDown = e => {
|
|
123
88
|
clearTimeout(typingTimer);
|
|
124
89
|
if (e.key !== "Escape") {
|
|
125
90
|
if (e.key !== "ArrowDown" && e.key !== "ArrowUp") {
|
|
126
91
|
e.stopPropagation();
|
|
127
92
|
}
|
|
128
|
-
typingTimer = setTimeout(
|
|
93
|
+
typingTimer = setTimeout(() => {
|
|
129
94
|
clearTimeout(typingTimer);
|
|
130
95
|
}, 500);
|
|
131
96
|
}
|
|
@@ -153,9 +118,7 @@ var SimpleSelect = function SimpleSelect(_ref) {
|
|
|
153
118
|
}
|
|
154
119
|
}, " * ") : "")), /*#__PURE__*/_react.default.createElement(_material.Select, _extends({}, rest, {
|
|
155
120
|
fullWidth: true,
|
|
156
|
-
onClose:
|
|
157
|
-
return setSearchText("");
|
|
158
|
-
},
|
|
121
|
+
onClose: () => setSearchText(""),
|
|
159
122
|
MenuProps: {
|
|
160
123
|
PaperProps: {
|
|
161
124
|
style: {
|
|
@@ -182,10 +145,8 @@ var SimpleSelect = function SimpleSelect(_ref) {
|
|
|
182
145
|
border: "1px solid #949494",
|
|
183
146
|
borderRadius: "4px"
|
|
184
147
|
},
|
|
185
|
-
placeholder:
|
|
186
|
-
onChange:
|
|
187
|
-
return setSearchText(e.target.value);
|
|
188
|
-
},
|
|
148
|
+
placeholder: "Type to search...",
|
|
149
|
+
onChange: e => setSearchText(e.target.value),
|
|
189
150
|
onKeyDown: handleKeyDown
|
|
190
151
|
}), isClearOption && !loading && /*#__PURE__*/_react.default.createElement(_material.MenuItem, {
|
|
191
152
|
value: ""
|
|
@@ -193,7 +154,7 @@ var SimpleSelect = function SimpleSelect(_ref) {
|
|
|
193
154
|
style: {
|
|
194
155
|
color: "#888"
|
|
195
156
|
}
|
|
196
|
-
},
|
|
157
|
+
}, "Clear the option")), loading ? /*#__PURE__*/_react.default.createElement(_text.default, {
|
|
197
158
|
variant: "span",
|
|
198
159
|
color: "secondary",
|
|
199
160
|
sx: {
|
|
@@ -203,12 +164,9 @@ var SimpleSelect = function SimpleSelect(_ref) {
|
|
|
203
164
|
}
|
|
204
165
|
}, "Fetching Options...") : noDataAvailable ? /*#__PURE__*/_react.default.createElement(_material.MenuItem, {
|
|
205
166
|
disabled: true
|
|
206
|
-
}, "No Data Available") : recommendedOptions
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}, option.label);
|
|
211
|
-
})), error && /*#__PURE__*/_react.default.createElement(_material.FormHelperText, null, errorMessage), helperText && /*#__PURE__*/_react.default.createElement(_material.FormHelperText, null, helperText)));
|
|
167
|
+
}, "No Data Available") : recommendedOptions?.map(option => /*#__PURE__*/_react.default.createElement(_material.MenuItem, {
|
|
168
|
+
key: option.value,
|
|
169
|
+
value: option.value
|
|
170
|
+
}, option.label))), error && /*#__PURE__*/_react.default.createElement(_material.FormHelperText, null, errorMessage), helperText && /*#__PURE__*/_react.default.createElement(_material.FormHelperText, null, helperText)));
|
|
212
171
|
};
|
|
213
|
-
var _default = SimpleSelect;
|
|
214
|
-
exports.default = _default;
|
|
172
|
+
var _default = exports.default = SimpleSelect;
|