aq-fe-framework 0.1.425 → 0.1.426
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.
@@ -625,7 +625,7 @@ function MySelect(_a) {
|
|
625
625
|
}
|
626
626
|
|
627
627
|
// src/core/input/MySelectFromAPI.tsx
|
628
|
-
import { useEffect as useEffect3, useMemo as useMemo2 } from "react";
|
628
|
+
import { useEffect as useEffect3, useMemo as useMemo2, useRef } from "react";
|
629
629
|
import { jsx as jsx12 } from "react/jsx-runtime";
|
630
630
|
function MySelectFromAPI(_a) {
|
631
631
|
var _b = _a, {
|
@@ -660,9 +660,10 @@ function MySelectFromAPI(_a) {
|
|
660
660
|
};
|
661
661
|
})) != null ? _a2 : [];
|
662
662
|
}, [query.data]);
|
663
|
-
const
|
663
|
+
const hasAutoSelected = useRef(false);
|
664
|
+
const handleChange = (value2, option) => {
|
664
665
|
var _a2;
|
665
|
-
onChange == null ? void 0 : onChange(value2,
|
666
|
+
onChange == null ? void 0 : onChange(value2, option);
|
666
667
|
if (setObjectData) {
|
667
668
|
const selected = (_a2 = query.data) == null ? void 0 : _a2.find((item) => {
|
668
669
|
var _a3;
|
@@ -673,30 +674,22 @@ function MySelectFromAPI(_a) {
|
|
673
674
|
};
|
674
675
|
useEffect3(() => {
|
675
676
|
var _a2, _b2, _c;
|
676
|
-
if (autoSelectFirstItem && query.data && query.data.length > 0) {
|
677
|
+
if (autoSelectFirstItem && !hasAutoSelected.current && query.data && query.data.length > 0 && (value === void 0 || value === null || value === "")) {
|
677
678
|
const firstItem = query.data[0];
|
678
|
-
const
|
679
|
+
const val = (_b2 = (_a2 = firstItem.id) == null ? void 0 : _a2.toString()) != null ? _b2 : "";
|
679
680
|
const label = labelWithCode ? `${firstItem.code} - ${firstItem.name}` : (_c = firstItem.name) != null ? _c : "";
|
680
|
-
onChange == null ? void 0 : onChange(
|
681
|
+
onChange == null ? void 0 : onChange(val, { value: val, label });
|
681
682
|
setObjectData == null ? void 0 : setObjectData(firstItem);
|
683
|
+
hasAutoSelected.current = true;
|
682
684
|
}
|
683
|
-
}, [query.data,
|
684
|
-
useEffect3(() => {
|
685
|
-
if (value && setObjectData && query.data) {
|
686
|
-
const selected = query.data.find((item) => {
|
687
|
-
var _a2;
|
688
|
-
return ((_a2 = item.id) == null ? void 0 : _a2.toString()) === value;
|
689
|
-
});
|
690
|
-
setObjectData(selected);
|
691
|
-
}
|
692
|
-
}, [value, query.data]);
|
685
|
+
}, [autoSelectFirstItem, query.data, labelWithCode, onChange, setObjectData, value]);
|
693
686
|
return /* @__PURE__ */ jsx12(
|
694
687
|
MySelect,
|
695
688
|
__spreadValues({
|
696
689
|
isLoading: query.isLoading,
|
697
690
|
isError: query.isError,
|
698
691
|
data: options,
|
699
|
-
onChange: (value2,
|
692
|
+
onChange: (value2, option) => handleChange(value2, option),
|
700
693
|
value
|
701
694
|
}, rest)
|
702
695
|
);
|
package/dist/core/index.mjs
CHANGED