You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2017/12/13 08:02:16 UTC

[GitHub] garrensmith closed pull request #1035: Remove usage of query-string

garrensmith closed pull request #1035: Remove usage of query-string
URL: https://github.com/apache/couchdb-fauxton/pull/1035
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/app/addons/documents/__tests__/fetch-actions.test.js b/app/addons/documents/__tests__/fetch-actions.test.js
index 1c45bf014..2e1059f36 100644
--- a/app/addons/documents/__tests__/fetch-actions.test.js
+++ b/app/addons/documents/__tests__/fetch-actions.test.js
@@ -18,7 +18,7 @@ import {
 } from '../index-results/actions/fetch';
 import {queryAllDocs, postToBulkDocs} from '../index-results/api';
 import fetchMock from 'fetch-mock';
-import queryString from 'query-string';
+import app from '../../../app';
 import sinon from 'sinon';
 import SidebarActions from '../sidebar/actions';
 import FauxtonAPI from '../../../core/api';
@@ -208,7 +208,7 @@ describe('Docs Fetch API', () => {
 
     it('queries _all_docs with default params', () => {
       const fetchUrl = '/testdb/_all_docs';
-      const query = queryString.stringify(params);
+      const query = app.utils.queryString(params);
       const url = `${fetchUrl}?${query}`;
       fetchMock.getOnce(url, docs);
 
diff --git a/app/addons/documents/index-results/api.js b/app/addons/documents/index-results/api.js
index 7f93811ff..23eb7b598 100644
--- a/app/addons/documents/index-results/api.js
+++ b/app/addons/documents/index-results/api.js
@@ -12,14 +12,14 @@
 
 import 'url-polyfill';
 import 'whatwg-fetch';
-import queryString from 'query-string';
+import app from '../../../app';
 import Constants from '../constants';
 import FauxtonAPI from '../../../core/api';
 
 export const queryAllDocs = (fetchUrl, params) => {
   // Exclude params 'group', 'reduce' and 'group_level' if present since they not allowed for '_all_docs'
   Object.assign(params, {reduce: undefined, group: undefined, group_level: undefined});
-  const query = queryString.stringify(params);
+  const query = app.utils.queryString(params);
   const url = `${fetchUrl}${fetchUrl.includes('?') ? '&' : '?'}${query}`;
   return fetch(url, {
     credentials: 'include',
@@ -50,7 +50,7 @@ export const queryMapReduceView = (fetchUrl, params) => {
     params.group = undefined;
     params.group_level = undefined;
   }
-  const query = queryString.stringify(params);
+  const query = app.utils.queryString(params);
   const url = `${fetchUrl}${fetchUrl.includes('?') ? '&' : '?'}${query}`;
   return fetch(url, {
     credentials: 'include',
diff --git a/app/addons/documents/index-results/containers/ApiBarContainer.js b/app/addons/documents/index-results/containers/ApiBarContainer.js
index d5d514a63..a65e06311 100644
--- a/app/addons/documents/index-results/containers/ApiBarContainer.js
+++ b/app/addons/documents/index-results/containers/ApiBarContainer.js
@@ -14,7 +14,7 @@ import { connect } from 'react-redux';
 
 import PropTypes from 'prop-types';
 
-import queryString from 'query-string';
+import app from '../../../../app';
 import { ApiBarWrapper } from '../../../components/layouts';
 import { getQueryOptionsParams } from '../reducers';
 import FauxtonAPI from '../../../../core/api';
@@ -25,7 +25,7 @@ const mapStateToProps = ({indexResults}, {docUrl, endpoint, endpointAddQueryOpti
   }
 
   if (endpoint && endpointAddQueryOptions) {
-    const query = queryString.stringify(getQueryOptionsParams(indexResults));
+    const query = app.utils.queryString(getQueryOptionsParams(indexResults));
     if (query) {
       endpoint = endpoint.indexOf('?') == -1 ? `${endpoint}?${query}` : `${endpoint}&${query}`;
     }
diff --git a/app/addons/documents/mango/mango.api.js b/app/addons/documents/mango/mango.api.js
index 5d4353c81..2ae90ca29 100644
--- a/app/addons/documents/mango/mango.api.js
+++ b/app/addons/documents/mango/mango.api.js
@@ -11,7 +11,6 @@
 // the License.
 
 import 'whatwg-fetch';
-import queryString from 'query-string';
 import app from "../../../app";
 import FauxtonAPI from "../../../core/api";
 import Constants from '../constants';
@@ -60,7 +59,7 @@ export const createIndex = (databaseName, indexCode) => {
 };
 
 export const fetchIndexes = (databaseName, params) => {
-  const query = queryString.stringify(params);
+  const query = app.utils.queryString(params);
   let url = FauxtonAPI.urls('mango', 'index-server', app.utils.safeURLName(databaseName));
   url = `${url}${url.includes('?') ? '&' : '?'}${query}`;
 
diff --git a/app/core/utils.js b/app/core/utils.js
index 83b83648c..11a0adae3 100644
--- a/app/core/utils.js
+++ b/app/core/utils.js
@@ -63,6 +63,18 @@ const utils = {
   },
 
   queryParams: function (obj) {
+    //Simulates jQuery.param()
+    return param(obj);
+  },
+
+  queryString: function (obj) {
+    //Similar to queryParams() but skips object properties
+    //that are undefined
+    Object.keys(obj).forEach((key) => {
+      if (obj[key] === undefined) {
+        delete obj[key];
+      }
+    });
     return param(obj);
   },
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services