ui-soxo-bootstrap-core 2.6.22 → 2.6.24

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.
@@ -22,6 +22,7 @@ export default function AdvancedSearchSelect({ reportId, onReset, field, value,
22
22
 
23
23
  const [searchResults, setSearchResults] = useState([]);
24
24
  const [displayOptions, setDisplayOptions] = useState([]);
25
+ const [optionLabels, setOptionLabels] = useState({});
25
26
  const [loading, setLoading] = useState(false);
26
27
  const debounceRef = useRef(null);
27
28
 
@@ -37,14 +38,24 @@ export default function AdvancedSearchSelect({ reportId, onReset, field, value,
37
38
 
38
39
  const res = await CoreScripts.getQuerySeacch(formBody);
39
40
  const data = Array.isArray(res.data) ? res.data : [];
40
- const apiValues = data?.map((r) => r[fieldName]) || [];
41
+ const apiValues = data.map((item) => item.search_value);
41
42
 
42
43
  setSearchResults(apiValues);
44
+ setDisplayOptions(data);
45
+ setOptionLabels((prev) => ({
46
+ ...prev,
47
+ ...data.reduce((acc, item) => {
48
+ acc[item.search_value] = item.display_value;
49
+ return acc;
50
+ }, {}),
51
+ }));
52
+
43
53
  // Refresh display options only when new search results arrive to keep the list stable during interaction
44
- setDisplayOptions([
45
- ...safeValue,
46
- ...apiValues.filter((item) => !safeValue.includes(item)),
47
- ]);
54
+ // setDisplayOptions([
55
+ // ...safeValue,
56
+ // ...apiValues
57
+ // // ...apiValues.filter((item) => !safeValue.includes(item)),
58
+ // ]);
48
59
  } catch (error) {
49
60
  console.error("Search API error", error);
50
61
  } finally {
@@ -58,6 +69,16 @@ export default function AdvancedSearchSelect({ reportId, onReset, field, value,
58
69
  setSearchResults([]);
59
70
  }, [fieldName, finalReportId]);
60
71
 
72
+ useEffect(() => {
73
+ // FormCreator can remount this field after submit with only search_value(s).
74
+ // If any selected value is missing a label, fetch the option list once to recover display_value.
75
+ const hasMissingLabels = safeValue.some((item) => !optionLabels[item]);
76
+
77
+ if (isSearchQuery && safeValue.length > 0 && hasMissingLabels) {
78
+ loadOptions("");
79
+ }
80
+ }, [isSearchQuery, safeValue, optionLabels]);
81
+
61
82
  const handleSearch = (text) => {
62
83
  if (debounceRef.current) clearTimeout(debounceRef.current);
63
84
  debounceRef.current = setTimeout(() => loadOptions(text), 400);
@@ -80,6 +101,18 @@ export default function AdvancedSearchSelect({ reportId, onReset, field, value,
80
101
  };
81
102
 
82
103
  const isActive = safeValue.length > 0;
104
+ const selectOptions = [
105
+ ...safeValue
106
+ .filter((item) => optionLabels[item])
107
+ .map((item) => ({
108
+ value: item,
109
+ label: optionLabels[item],
110
+ })),
111
+ ...displayOptions.map((item) => ({
112
+ value: item.search_value,
113
+ label: item.display_value,
114
+ })),
115
+ ].filter((item, index, array) => array.findIndex((entry) => entry.value === item.value) === index);
83
116
 
84
117
  // -------- INPUT MODE --------
85
118
  if (!isSearchQuery) {
@@ -111,16 +144,17 @@ export default function AdvancedSearchSelect({ reportId, onReset, field, value,
111
144
  style={style}
112
145
  mode="multiple"
113
146
  value={safeValue}
147
+ options={selectOptions}
114
148
  placeholder={caption}
115
149
  onDropdownVisibleChange={(open) => {
116
150
  if (open) {
117
151
  loadOptions("");
118
152
  } else {
119
153
  // When closing, re-sort selected items to the top so they are visible next time it opens
120
- const currentResults = searchResults.length > 0 ? searchResults : displayOptions;
154
+ const currentResults = displayOptions.length > 0 ? displayOptions : [];
121
155
  setDisplayOptions([
122
- ...safeValue,
123
- ...currentResults.filter((item) => !safeValue.includes(item)),
156
+ ...currentResults.filter((item) => safeValue.includes(item.search_value)),
157
+ ...currentResults.filter((item) => !safeValue.includes(item.search_value)),
124
158
  ]);
125
159
  }
126
160
  }}
@@ -145,17 +179,17 @@ export default function AdvancedSearchSelect({ reportId, onReset, field, value,
145
179
  ) : (
146
180
  displayOptions.map((item, idx) => (
147
181
  <div
148
- key={`${item}-${idx}`}
182
+ key={`${item.search_value}-${idx}`}
149
183
  className="dropdown-option-item"
150
- onClick={() => toggleValue(!safeValue.includes(item), item)}
184
+ onClick={() => toggleValue(!safeValue.includes(item.search_value), item.search_value)}
151
185
  style={{ cursor: 'pointer' }}
152
186
  >
153
187
  <Checkbox
154
- checked={safeValue.includes(item)}
188
+ checked={safeValue.includes(item.search_value)}
155
189
  onClick={(e) => e.stopPropagation()} // Prevent double trigger when clicking the checkbox box specifically
156
- onChange={(e) => toggleValue(e.target.checked, item)}
190
+ onChange={(e) => toggleValue(e.target.checked, item.search_value)}
157
191
  >
158
- {item}
192
+ {item.display_value}
159
193
  </Checkbox>
160
194
  </div>
161
195
  ))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-soxo-bootstrap-core",
3
- "version": "2.6.22",
3
+ "version": "2.6.24",
4
4
  "description": "All the Core Components for you to start",
5
5
  "keywords": [
6
6
  "all in one"