You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2017/12/13 08:02:15 UTC

[couchdb-fauxton] branch master updated: Remove usage of query-string

This is an automated email from the ASF dual-hosted git repository.

garren pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-fauxton.git


The following commit(s) were added to refs/heads/master by this push:
     new 5e3f592  Remove usage of query-string
5e3f592 is described below

commit 5e3f5921f4b1bccc5b3b9662ed36d43a185df6f3
Author: Antonio Maranhao <an...@gmail.com>
AuthorDate: Tue Dec 12 16:27:13 2017 -0500

    Remove usage of query-string
---
 app/addons/documents/__tests__/fetch-actions.test.js         |  4 ++--
 app/addons/documents/index-results/api.js                    |  6 +++---
 .../documents/index-results/containers/ApiBarContainer.js    |  4 ++--
 app/addons/documents/mango/mango.api.js                      |  3 +--
 app/core/utils.js                                            | 12 ++++++++++++
 5 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/app/addons/documents/__tests__/fetch-actions.test.js b/app/addons/documents/__tests__/fetch-actions.test.js
index 1c45bf0..2e1059f 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 7f93811..23eb7b5 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 d5d514a..a65e063 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 5d4353c..2ae90ca 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 83b8364..11a0ada 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);
   },
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].