@visns-studio/visns-components 5.7.1 → 5.7.3
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/package.json +3 -1
- package/src/utils/fetchUtil.js +21 -19
package/package.json
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
"dependencies": {
|
|
3
3
|
"@emotion/is-prop-valid": "^1.3.1",
|
|
4
4
|
"@fontsource/barlow": "^5.2.5",
|
|
5
|
+
"@inovua/reactdatagrid-community": "^5.10.2",
|
|
6
|
+
"@inovua/reactdatagrid-enterprise": "^5.10.2",
|
|
5
7
|
"@nivo/bar": "^0.88.0",
|
|
6
8
|
"@nivo/core": "^0.88.0",
|
|
7
9
|
"@nivo/line": "^0.88.0",
|
|
@@ -80,7 +82,7 @@
|
|
|
80
82
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
81
83
|
},
|
|
82
84
|
"name": "@visns-studio/visns-components",
|
|
83
|
-
"version": "5.7.
|
|
85
|
+
"version": "5.7.3",
|
|
84
86
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
85
87
|
"main": "src/index.js",
|
|
86
88
|
"files": [
|
package/src/utils/fetchUtil.js
CHANGED
|
@@ -47,25 +47,27 @@ const fetchUtil = async (config) => {
|
|
|
47
47
|
// Build request URL with query parameters
|
|
48
48
|
let requestUrl = url;
|
|
49
49
|
|
|
50
|
+
// Create local copies that we can modify
|
|
51
|
+
let paramsObj = params ? { ...params } : {};
|
|
52
|
+
let dataObj = data;
|
|
53
|
+
|
|
50
54
|
// For GET and HEAD requests, convert data to query parameters if it exists
|
|
51
55
|
if (
|
|
52
56
|
(method.toUpperCase() === 'GET' || method.toUpperCase() === 'HEAD') &&
|
|
53
|
-
|
|
54
|
-
typeof
|
|
55
|
-
!(
|
|
57
|
+
dataObj &&
|
|
58
|
+
typeof dataObj === 'object' &&
|
|
59
|
+
!(dataObj instanceof FormData)
|
|
56
60
|
) {
|
|
57
|
-
// Create params object if it doesn't exist
|
|
58
|
-
params = params || {};
|
|
59
61
|
// Merge data into params
|
|
60
|
-
Object.assign(
|
|
62
|
+
Object.assign(paramsObj, dataObj);
|
|
61
63
|
// Remove data since we've moved it to params
|
|
62
|
-
|
|
64
|
+
dataObj = undefined;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
// Add params to URL
|
|
66
|
-
if (
|
|
68
|
+
if (Object.keys(paramsObj).length > 0) {
|
|
67
69
|
const queryParams = new URLSearchParams();
|
|
68
|
-
Object.entries(
|
|
70
|
+
Object.entries(paramsObj).forEach(([key, value]) => {
|
|
69
71
|
if (value !== undefined && value !== null) {
|
|
70
72
|
queryParams.append(key, value);
|
|
71
73
|
}
|
|
@@ -83,9 +85,9 @@ const fetchUtil = async (config) => {
|
|
|
83
85
|
|
|
84
86
|
// If not explicitly set and sending data, default to JSON
|
|
85
87
|
if (
|
|
86
|
-
|
|
88
|
+
dataObj &&
|
|
87
89
|
!requestHeaders.has('Content-Type') &&
|
|
88
|
-
!(
|
|
90
|
+
!(dataObj instanceof FormData)
|
|
89
91
|
) {
|
|
90
92
|
requestHeaders.set('Content-Type', 'application/json');
|
|
91
93
|
}
|
|
@@ -123,12 +125,12 @@ const fetchUtil = async (config) => {
|
|
|
123
125
|
if (method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'HEAD') {
|
|
124
126
|
// Handle Laravel's _method for PUT/PATCH/DELETE
|
|
125
127
|
if (['PUT', 'PATCH', 'DELETE'].includes(method.toUpperCase())) {
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
+
if (dataObj instanceof FormData) {
|
|
129
|
+
dataObj.append('_method', method.toUpperCase());
|
|
128
130
|
requestOptions.method = 'POST';
|
|
129
|
-
} else if (
|
|
131
|
+
} else if (dataObj && typeof dataObj === 'object') {
|
|
130
132
|
requestOptions.body = JSON.stringify({
|
|
131
|
-
...
|
|
133
|
+
...dataObj,
|
|
132
134
|
_method: method.toUpperCase(),
|
|
133
135
|
});
|
|
134
136
|
requestOptions.method = 'POST';
|
|
@@ -141,10 +143,10 @@ const fetchUtil = async (config) => {
|
|
|
141
143
|
}
|
|
142
144
|
} else {
|
|
143
145
|
// For regular POST
|
|
144
|
-
if (
|
|
145
|
-
requestOptions.body =
|
|
146
|
-
} else if (
|
|
147
|
-
requestOptions.body = JSON.stringify(
|
|
146
|
+
if (dataObj instanceof FormData) {
|
|
147
|
+
requestOptions.body = dataObj;
|
|
148
|
+
} else if (dataObj !== undefined) {
|
|
149
|
+
requestOptions.body = JSON.stringify(dataObj);
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
}
|