@algorithm-shift/design-system 1.2.970 → 1.2.971
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.
- package/dist/index.js +45 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -27792,14 +27792,46 @@ function useLazyDropdown(config) {
|
|
|
27792
27792
|
};
|
|
27793
27793
|
});
|
|
27794
27794
|
}, []);
|
|
27795
|
+
function extractAndEnforceUrlParams(apiUrl, enforceStrict) {
|
|
27796
|
+
const urlObj = new URL(
|
|
27797
|
+
apiUrl,
|
|
27798
|
+
typeof window !== "undefined" ? window.location.origin : "http://localhost"
|
|
27799
|
+
);
|
|
27800
|
+
const cleaned = {};
|
|
27801
|
+
let hasEmpty = false;
|
|
27802
|
+
const baseUrl = urlObj.origin + urlObj.pathname;
|
|
27803
|
+
urlObj.searchParams.forEach((value, key) => {
|
|
27804
|
+
const isEmpty = value === "" || value === void 0 || value === null;
|
|
27805
|
+
if (isEmpty) {
|
|
27806
|
+
hasEmpty = true;
|
|
27807
|
+
if (enforceStrict) return;
|
|
27808
|
+
return;
|
|
27809
|
+
}
|
|
27810
|
+
cleaned[key] = value;
|
|
27811
|
+
});
|
|
27812
|
+
return {
|
|
27813
|
+
baseUrl,
|
|
27814
|
+
shouldAbort: enforceStrict && hasEmpty,
|
|
27815
|
+
params: cleaned
|
|
27816
|
+
};
|
|
27817
|
+
}
|
|
27795
27818
|
const fetchApiData = useCallback2(async (pageNum, term) => {
|
|
27796
27819
|
if (!configRef.current.apiUrl) return [];
|
|
27797
27820
|
const limit = PAGE_SIZE;
|
|
27798
27821
|
const params = { page: pageNum, limit };
|
|
27799
27822
|
if (term) params[configRef.current.dataLabel ? `${configRef.current.dataLabel}[ilike]` : "search[ilike]"] = term;
|
|
27823
|
+
const { baseUrl, shouldAbort, params: urlParams } = extractAndEnforceUrlParams(
|
|
27824
|
+
configRef.current.apiUrl,
|
|
27825
|
+
configRef.current.enforceStrictQueryParams ?? false
|
|
27826
|
+
);
|
|
27827
|
+
if (shouldAbort) {
|
|
27828
|
+
setLoading(false);
|
|
27829
|
+
return [];
|
|
27830
|
+
}
|
|
27831
|
+
const finalParams = { ...urlParams, ...params };
|
|
27800
27832
|
const axiosClient = configRef.current.axiosInstance ?? axios;
|
|
27801
|
-
const res = await axiosClient.get(
|
|
27802
|
-
params,
|
|
27833
|
+
const res = await axiosClient.get(baseUrl, {
|
|
27834
|
+
params: finalParams,
|
|
27803
27835
|
withCredentials: true
|
|
27804
27836
|
});
|
|
27805
27837
|
if (res.data?.success && Array.isArray(res.data.data)) {
|
|
@@ -27862,8 +27894,17 @@ function useLazyDropdown(config) {
|
|
|
27862
27894
|
[`${configRef.current.dataKey}[in]`]: configRef.current.value.join(",")
|
|
27863
27895
|
};
|
|
27864
27896
|
}
|
|
27865
|
-
const
|
|
27866
|
-
|
|
27897
|
+
const { baseUrl, shouldAbort, params: urlParams } = extractAndEnforceUrlParams(
|
|
27898
|
+
configRef.current.apiUrl,
|
|
27899
|
+
configRef.current.enforceStrictQueryParams ?? false
|
|
27900
|
+
);
|
|
27901
|
+
if (shouldAbort) {
|
|
27902
|
+
setLoading(false);
|
|
27903
|
+
return;
|
|
27904
|
+
}
|
|
27905
|
+
const finalParams = { ...urlParams, ...params };
|
|
27906
|
+
const res = await axiosClient.get(baseUrl, {
|
|
27907
|
+
params: finalParams,
|
|
27867
27908
|
withCredentials: true
|
|
27868
27909
|
});
|
|
27869
27910
|
if (res.data?.success && Array.isArray(res.data.data) && res.data.data.length > 0) {
|