Skip to content

Commit

Permalink
[#149] Fix query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dedenbangkit committed Apr 23, 2024
1 parent e88154b commit c52d05a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
14 changes: 13 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36474,6 +36474,15 @@ var PlusSquareFilled$1 = function PlusSquareFilled$1(props, ref) {
PlusSquareFilled$1.displayName = 'PlusSquareFilled';
var PlusSquareFilled$2 = /*#__PURE__*/React.forwardRef(PlusSquareFilled$1);

var correctUrl = function correctUrl(url) {
if (!url.includes('?')) {
var firstAmp = url.indexOf('&');
if (firstAmp !== -1) {
url = url.substring(0, firstAmp) + '?' + url.substring(firstAmp + 1);
}
}
return url;
};
var TypeCascadeApi = function TypeCascadeApi(_ref) {
var id = _ref.id,
name = _ref.name,
Expand Down Expand Up @@ -36540,7 +36549,7 @@ var TypeCascadeApi = function TypeCascadeApi(_ref) {
React.useEffect(function () {
var ep = typeof initial !== 'undefined' ? endpoint + "/" + initial : "" + endpoint;
if (query_params) {
ep = "" + ep + query_params;
ep = correctUrl("" + ep + query_params);
}
axios.get(ep).then(function (res) {
var _res$data;
Expand All @@ -36555,6 +36564,7 @@ var TypeCascadeApi = function TypeCascadeApi(_ref) {
if (query_params) {
ep = "" + ep + query_params;
}
ep = correctUrl(ep);
var initCall = new Promise(function (resolve, reject) {
axios.get(ep).then(function (res) {
var _res$data2;
Expand All @@ -36572,6 +36582,7 @@ var TypeCascadeApi = function TypeCascadeApi(_ref) {
if (query_params) {
ep = "" + ep + query_params;
}
ep = correctUrl(ep);
axios.get(ep).then(function (res) {
var _res$data3;
var data = list ? (_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : _res$data3[list] : res.data;
Expand Down Expand Up @@ -36609,6 +36620,7 @@ var TypeCascadeApi = function TypeCascadeApi(_ref) {
if (query_params) {
ep = "" + ep + query_params;
}
ep = correctUrl(ep);
axios.get(ep).then(function (res) {
var _res$data4;
var data = list ? (_res$data4 = res.data) === null || _res$data4 === void 0 ? void 0 : _res$data4[list] : res.data;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion dist/index.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -36471,6 +36471,15 @@ var PlusSquareFilled$1 = function PlusSquareFilled$1(props, ref) {
PlusSquareFilled$1.displayName = 'PlusSquareFilled';
var PlusSquareFilled$2 = /*#__PURE__*/forwardRef(PlusSquareFilled$1);

var correctUrl = function correctUrl(url) {
if (!url.includes('?')) {
var firstAmp = url.indexOf('&');
if (firstAmp !== -1) {
url = url.substring(0, firstAmp) + '?' + url.substring(firstAmp + 1);
}
}
return url;
};
var TypeCascadeApi = function TypeCascadeApi(_ref) {
var id = _ref.id,
name = _ref.name,
Expand Down Expand Up @@ -36537,7 +36546,7 @@ var TypeCascadeApi = function TypeCascadeApi(_ref) {
useEffect(function () {
var ep = typeof initial !== 'undefined' ? endpoint + "/" + initial : "" + endpoint;
if (query_params) {
ep = "" + ep + query_params;
ep = correctUrl("" + ep + query_params);
}
axios.get(ep).then(function (res) {
var _res$data;
Expand All @@ -36552,6 +36561,7 @@ var TypeCascadeApi = function TypeCascadeApi(_ref) {
if (query_params) {
ep = "" + ep + query_params;
}
ep = correctUrl(ep);
var initCall = new Promise(function (resolve, reject) {
axios.get(ep).then(function (res) {
var _res$data2;
Expand All @@ -36569,6 +36579,7 @@ var TypeCascadeApi = function TypeCascadeApi(_ref) {
if (query_params) {
ep = "" + ep + query_params;
}
ep = correctUrl(ep);
axios.get(ep).then(function (res) {
var _res$data3;
var data = list ? (_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : _res$data3[list] : res.data;
Expand Down Expand Up @@ -36606,6 +36617,7 @@ var TypeCascadeApi = function TypeCascadeApi(_ref) {
if (query_params) {
ep = "" + ep + query_params;
}
ep = correctUrl(ep);
axios.get(ep).then(function (res) {
var _res$data4;
var data = list ? (_res$data4 = res.data) === null || _res$data4 === void 0 ? void 0 : _res$data4[list] : res.data;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.modern.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9930,6 +9930,11 @@ uuid@^8.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuid@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==

v8-to-istanbul@^8.1.0:
version "8.1.1"
resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-8.1.1.tgz#77b752fd3975e31bbcef938f85e9bd1c7a8d60ed"
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "akvo-react-form",
"version": "2.4.5",
"version": "2.4.6",
"description": "Simple react component for building webforms",
"license": "AGPL-3.0",
"repository": "akvo/akvo-react-form",
Expand Down Expand Up @@ -79,9 +79,7 @@
"react-dom": "^16.13.1",
"react-scripts": "^5.0.1"
},
"files": [
"dist"
],
"files": ["dist"],
"dependencies": {
"@react-leaflet/core": ">=1.0.0 <1.1.0 || ^1.1.1",
"antd": "^4.20.0",
Expand Down
15 changes: 14 additions & 1 deletion src/fields/TypeCascade.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import { Extra, FieldLabel, DataApiUrl } from '../support';
import ds from '../lib/db';
import GlobalStore from '../lib/store';

const correctUrl = (url) => {
if (!url.includes('?')) {
const firstAmp = url.indexOf('&');
if (firstAmp !== -1) {
url = url.substring(0, firstAmp) + '?' + url.substring(firstAmp + 1);
}
}
return url;
};

const TypeCascadeApi = ({
id,
name,
Expand Down Expand Up @@ -62,7 +72,7 @@ const TypeCascadeApi = ({
let ep =
typeof initial !== 'undefined' ? `${endpoint}/${initial}` : `${endpoint}`;
if (query_params) {
ep = `${ep}${query_params}`;
ep = correctUrl(`${ep}${query_params}`);
}
axios.get(ep).then((res) => {
const data = list ? res.data?.[list] : res.data;
Expand All @@ -80,6 +90,7 @@ const TypeCascadeApi = ({
if (query_params) {
ep = `${ep}${query_params}`;
}
ep = correctUrl(ep);
const initCall = new Promise((resolve, reject) => {
axios
.get(ep)
Expand All @@ -98,6 +109,7 @@ const TypeCascadeApi = ({
if (query_params) {
ep = `${ep}${query_params}`;
}
ep = correctUrl(ep);
axios
.get(ep)
.then((res) => {
Expand Down Expand Up @@ -131,6 +143,7 @@ const TypeCascadeApi = ({
if (query_params) {
ep = `${ep}${query_params}`;
}
ep = correctUrl(ep);
axios.get(ep).then((res) => {
const data = list ? res.data?.[list] : res.data;
if (data.length) {
Expand Down

0 comments on commit c52d05a

Please sign in to comment.