summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-11-13 15:24:09 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-11-14 10:39:49 +0000
commit1ca97bf8af8974200b8759ec6114d878460f62e6 (patch)
treebe5bf221e59768e45def1bb29f2b81dc4ece7b2c
parentdf5891b531d7422fa88dad92a82bbf8685625057 (diff)
downloadgitlab-ce-32098-pipelines-navigation.tar.gz
Puts back documentation of setParamInUrl32098-pipelines-navigation
Changes after review
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js34
-rw-r--r--spec/javascripts/lib/utils/poll_spec.js6
2 files changed, 17 insertions, 23 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index 72fd4e9d278..ef68bb63dc0 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -278,7 +278,8 @@ export const parseIntPagination = paginationInformation => ({
* If there are params but not for the given one, we'll add it at the end.
* Returns the new search parameters.
*
- * @param {Array} params
+ * @param {String} param
+ * @param {Number|String|Undefined|Null} value
* @return {String}
*/
export const setParamInURL = (param, value) => {
@@ -310,7 +311,7 @@ export const setParamInURL = (param, value) => {
};
/**
- * Given a string of query parameters created an object with key value.
+ * Given a string of query parameters creates an object.
*
* @example
* `scope=all&page=2` -> { scope: 'all', page: '2'}
@@ -320,24 +321,17 @@ export const setParamInURL = (param, value) => {
* @returns {Object}
*/
export const parseQueryStringIntoObject = (query = '') => {
- if (query.indexOf('&') !== -1) {
- return query
- .split('&')
- .reduce((acc, element) => {
- const val = element.split('=');
- // eslint-disable-next-line no-param-reassign
- acc[val[0]] = decodeURIComponent(val[1]);
- return acc;
- }, {});
- } else if (query.indexOf('=') !== -1) {
- const splitParam = query.split('=');
- const parsed = {};
- parsed[splitParam[0]] = splitParam[1];
-
- return parsed;
- }
-
- return {};
+ if (query === '') return {};
+
+ return query
+ .split('&')
+ .reduce((acc, element) => {
+ const val = element.split('=');
+ Object.assign(acc, {
+ [val[0]]: decodeURIComponent(val[1]),
+ });
+ return acc;
+ }, {});
};
export const buildUrlWithCurrentLocation = param => (param ? `${window.location.pathname}${param}` : window.location.pathname);
diff --git a/spec/javascripts/lib/utils/poll_spec.js b/spec/javascripts/lib/utils/poll_spec.js
index 2aa7011ca51..9b8f68f1676 100644
--- a/spec/javascripts/lib/utils/poll_spec.js
+++ b/spec/javascripts/lib/utils/poll_spec.js
@@ -155,7 +155,7 @@ describe('Poll', () => {
successCallback: () => {
Polling.stop();
setTimeout(() => {
- Polling.restart();
+ Polling.restart({ data: { page: 4 } });
}, 0);
},
errorCallback: callbacks.error,
@@ -170,10 +170,10 @@ describe('Poll', () => {
Polling.stop();
expect(service.fetch.calls.count()).toEqual(2);
- expect(service.fetch).toHaveBeenCalledWith({ page: 1 });
+ expect(service.fetch).toHaveBeenCalledWith({ page: 4 });
expect(Polling.stop).toHaveBeenCalled();
expect(Polling.restart).toHaveBeenCalled();
-
+ expect(Polling.options.data).toEqual({ page: 4 });
done();
});
});