aq-fe-framework 0.1.430 → 0.1.431
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.
@@ -633,13 +633,14 @@ function MySelect(_a) {
|
|
633
633
|
}
|
634
634
|
|
635
635
|
// src/core/input/MySelectFromAPI.tsx
|
636
|
-
import { useEffect as useEffect3, useMemo as useMemo2, useRef } from "react";
|
636
|
+
import { useCallback, useEffect as useEffect3, useMemo as useMemo2, useRef } from "react";
|
637
637
|
import { jsx as jsx12 } from "react/jsx-runtime";
|
638
638
|
function MySelectFromAPI(_a) {
|
639
639
|
var _b = _a, {
|
640
640
|
queryKey,
|
641
641
|
axiosFn,
|
642
642
|
labelWithCode,
|
643
|
+
getOptionLabel,
|
643
644
|
onChange,
|
644
645
|
value,
|
645
646
|
setObjectData,
|
@@ -648,27 +649,31 @@ function MySelectFromAPI(_a) {
|
|
648
649
|
"queryKey",
|
649
650
|
"axiosFn",
|
650
651
|
"labelWithCode",
|
652
|
+
"getOptionLabel",
|
651
653
|
"onChange",
|
652
654
|
"value",
|
653
655
|
"setObjectData",
|
654
656
|
"autoSelectFirstItem"
|
655
657
|
]);
|
656
|
-
const query = useMyReactQuery({
|
657
|
-
|
658
|
-
|
659
|
-
|
658
|
+
const query = useMyReactQuery({ queryKey, axiosFn });
|
659
|
+
const hasAutoSelected = useRef(false);
|
660
|
+
const getLabel = useCallback(
|
661
|
+
(item) => {
|
662
|
+
var _a2, _b2;
|
663
|
+
return (_b2 = getOptionLabel == null ? void 0 : getOptionLabel(item)) != null ? _b2 : labelWithCode ? `${item.code} - ${item.name}` : (_a2 = item.name) != null ? _a2 : "";
|
664
|
+
},
|
665
|
+
[getOptionLabel, labelWithCode]
|
666
|
+
);
|
660
667
|
const options = useMemo2(() => {
|
661
|
-
var _a2;
|
662
|
-
|
663
|
-
|
664
|
-
var _a3, _b2, _c;
|
668
|
+
var _a2, _b2;
|
669
|
+
return (_b2 = (_a2 = query.data) == null ? void 0 : _a2.map((item) => {
|
670
|
+
var _a3, _b3;
|
665
671
|
return {
|
666
|
-
value: (
|
667
|
-
label:
|
672
|
+
value: (_b3 = (_a3 = item.id) == null ? void 0 : _a3.toString()) != null ? _b3 : "",
|
673
|
+
label: getLabel(item)
|
668
674
|
};
|
669
|
-
})) != null ?
|
670
|
-
}, [query.data]);
|
671
|
-
const hasAutoSelected = useRef(false);
|
675
|
+
})) != null ? _b2 : [];
|
676
|
+
}, [query.data, getLabel]);
|
672
677
|
const handleChange = (value2, option) => {
|
673
678
|
var _a2;
|
674
679
|
onChange == null ? void 0 : onChange(value2, option);
|
@@ -682,22 +687,22 @@ function MySelectFromAPI(_a) {
|
|
682
687
|
};
|
683
688
|
useEffect3(() => {
|
684
689
|
var _a2, _b2, _c;
|
685
|
-
if (autoSelectFirstItem && !hasAutoSelected.current &&
|
690
|
+
if (autoSelectFirstItem && !hasAutoSelected.current && ((_a2 = query.data) == null ? void 0 : _a2.length) && (value === void 0 || value === null || value === "")) {
|
686
691
|
const firstItem = query.data[0];
|
687
|
-
const
|
688
|
-
const
|
689
|
-
onChange == null ? void 0 : onChange(
|
692
|
+
const firstValue = (_c = (_b2 = firstItem.id) == null ? void 0 : _b2.toString()) != null ? _c : "";
|
693
|
+
const firstLabel = getLabel(firstItem);
|
694
|
+
onChange == null ? void 0 : onChange(firstValue, { value: firstValue, label: firstLabel });
|
690
695
|
setObjectData == null ? void 0 : setObjectData(firstItem);
|
691
696
|
hasAutoSelected.current = true;
|
692
697
|
}
|
693
|
-
}, [autoSelectFirstItem, query.data,
|
698
|
+
}, [autoSelectFirstItem, query.data, value, getLabel, onChange, setObjectData]);
|
694
699
|
return /* @__PURE__ */ jsx12(
|
695
700
|
MySelect,
|
696
701
|
__spreadValues({
|
697
702
|
isLoading: query.isLoading,
|
698
703
|
isError: query.isError,
|
699
704
|
data: options,
|
700
|
-
onChange:
|
705
|
+
onChange: handleChange,
|
701
706
|
value
|
702
707
|
}, rest)
|
703
708
|
);
|
package/dist/core/index.d.mts
CHANGED
@@ -109,10 +109,11 @@ interface MySelectFromAPIProps<IRes extends IBaseEntity, IBody = any> extends Om
|
|
109
109
|
queryKey: QueryKey;
|
110
110
|
axiosFn: () => Promise<AxiosResponse<MyApiResponse<IRes[]>, IBody>>;
|
111
111
|
labelWithCode?: boolean;
|
112
|
+
getOptionLabel?: (item: IRes) => string;
|
112
113
|
setObjectData?: (item: IRes | undefined) => void;
|
113
114
|
autoSelectFirstItem?: boolean;
|
114
115
|
}
|
115
|
-
declare function MySelectFromAPI<IRes extends IBaseEntity, IBody = any>({ queryKey, axiosFn, labelWithCode, onChange, value, setObjectData, autoSelectFirstItem, ...rest }: MySelectFromAPIProps<IRes, IBody>): react_jsx_runtime.JSX.Element;
|
116
|
+
declare function MySelectFromAPI<IRes extends IBaseEntity, IBody = any>({ queryKey, axiosFn, labelWithCode, getOptionLabel, onChange, value, setObjectData, autoSelectFirstItem, ...rest }: MySelectFromAPIProps<IRes, IBody>): react_jsx_runtime.JSX.Element;
|
116
117
|
|
117
118
|
interface CoreTextInputProps extends TextInputProps {
|
118
119
|
label?: string;
|
package/dist/core/index.mjs
CHANGED