oa-componentbook 0.18.253 → 0.18.254

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.
@@ -53,14 +53,12 @@ function AddSparePartCollapseWidget(_ref) {
53
53
  const [formValues, setFormValues] = (0, _react.useState)({});
54
54
  const [searchValue, setSearchValue] = (0, _react.useState)('');
55
55
  const notificationRef = (0, _react.useRef)(null);
56
- const itemRefs = (0, _react.useRef)({}); // Create a ref to store references to item panels
57
-
56
+ const itemRefs = (0, _react.useRef)({});
58
57
  const openNotification = parameters => {
59
58
  var _notificationRef$curr;
60
59
  return notificationRef === null || notificationRef === void 0 || (_notificationRef$curr = notificationRef.current) === null || _notificationRef$curr === void 0 ? void 0 : _notificationRef$curr.openNotification(parameters);
61
60
  };
62
61
  (0, _react.useEffect)(() => {
63
- // Pre-fill form values and select the items that are already selected
64
62
  const initialFormValues = {};
65
63
  const initialSelectedItems = new Set();
66
64
  selectedItems.forEach(item => {
@@ -75,12 +73,10 @@ function AddSparePartCollapseWidget(_ref) {
75
73
  setSelectedItemIds(initialSelectedItems);
76
74
  }, [selectedItems]);
77
75
  (0, _react.useEffect)(() => {
78
- // Combine selected items at the top followed by other items
79
76
  const sortedItems = [...selectedItems.map(item => items.find(i => i.id === item.scopeId)).filter(Boolean), ...items.filter(item => !selectedItems.some(selected => selected.scopeId === item.id))];
80
77
  setFilteredItems(sortedItems);
81
78
  }, [items, selectedItems]);
82
79
  (0, _react.useEffect)(() => {
83
- // Uncheck item if any required field is empty
84
80
  const newSelectedItemIds = new Set(selectedItemIds);
85
81
  selectedItemIds.forEach(itemId => {
86
82
  const fields = formValues[itemId];
@@ -135,16 +131,18 @@ function AddSparePartCollapseWidget(_ref) {
135
131
  newSelectedItems.add(itemId);
136
132
  }
137
133
  setSelectedItemIds(newSelectedItems);
138
- if (itemRefs.current[itemId]) {
139
- itemRefs.current[itemId].scrollIntoView({
140
- behavior: 'smooth',
141
- block: 'center'
142
- });
143
- }
144
134
  setSearchValue(''); // Clear search value on item selection
145
- // Reset the filtered items to show all items with selected items at the top
135
+
146
136
  const sortedItems = [...selectedItems.map(item => items.find(i => i.id === item.scopeId)).filter(Boolean), ...items.filter(item => !selectedItems.some(selected => selected.scopeId === item.id))];
147
137
  setFilteredItems(sortedItems);
138
+ setTimeout(() => {
139
+ if (itemRefs.current[itemId]) {
140
+ itemRefs.current[itemId].scrollIntoView({
141
+ behavior: 'smooth',
142
+ block: 'center'
143
+ });
144
+ }
145
+ }, 0);
148
146
  };
149
147
  const isNumeric = value => /^\d*$/.test(value); // Regular expression to check if the value is numeric
150
148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oa-componentbook",
3
- "version": "0.18.253",
3
+ "version": "0.18.254",
4
4
  "private": false,
5
5
  "description": "Reusable components",
6
6
  "main": "build/index.js",