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
- queryKey,
658
- axiosFn
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
- const data = query.data;
663
- return (_a2 = data == null ? void 0 : data.map((item) => {
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: (_b2 = (_a3 = item.id) == null ? void 0 : _a3.toString()) != null ? _b2 : "",
667
- label: labelWithCode ? `${item.code} - ${item.name}` : (_c = item.name) != null ? _c : ""
672
+ value: (_b3 = (_a3 = item.id) == null ? void 0 : _a3.toString()) != null ? _b3 : "",
673
+ label: getLabel(item)
668
674
  };
669
- })) != null ? _a2 : [];
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 && query.data && query.data.length > 0 && (value === void 0 || value === null || value === "")) {
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 val = (_b2 = (_a2 = firstItem.id) == null ? void 0 : _a2.toString()) != null ? _b2 : "";
688
- const label = labelWithCode ? `${firstItem.code} - ${firstItem.name}` : (_c = firstItem.name) != null ? _c : "";
689
- onChange == null ? void 0 : onChange(val, { value: val, label });
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, labelWithCode, onChange, setObjectData, value]);
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: (value2, option) => handleChange(value2, option),
705
+ onChange: handleChange,
701
706
  value
702
707
  }, rest)
703
708
  );
@@ -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;
@@ -13,7 +13,7 @@ import {
13
13
  MyStatsCard,
14
14
  MyTextInput,
15
15
  MyWeeklySessionSchedulerPicker
16
- } from "../chunk-OF6YLTFJ.mjs";
16
+ } from "../chunk-7AGWTSJE.mjs";
17
17
  import "../chunk-RZBHPPQT.mjs";
18
18
  import "../chunk-GFEMKKFH.mjs";
19
19
  import "../chunk-OMJJAHOC.mjs";
@@ -42,7 +42,7 @@ import {
42
42
  MyButton as MyButton2,
43
43
  MyDataTableSelectOne,
44
44
  MyTextInput as MyTextInput2
45
- } from "../chunk-OF6YLTFJ.mjs";
45
+ } from "../chunk-7AGWTSJE.mjs";
46
46
  import {
47
47
  MyDataTable,
48
48
  MyFlexColumn,
package/package.json CHANGED
@@ -42,7 +42,7 @@
42
42
  "types": "./dist/columns/index.d.mts"
43
43
  }
44
44
  },
45
- "version": "0.1.430",
45
+ "version": "0.1.431",
46
46
  "private": false,
47
47
  "files": [
48
48
  "dist"