summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2017-04-03 11:07:28 +0000
committerFatih Acet <acetfatih@gmail.com>2017-04-03 11:07:28 +0000
commitcfbbdde3e5485454ca9dc14449787ceb8d0a09df (patch)
tree59ae2768cf93e47b8943a6abd61768c20e848672 /app
parent8a6104d054b36984615c7c6b93c849100c6d6f91 (diff)
parent670e1d7477b7eb9a6c9e495830ede248674ba55a (diff)
downloadgitlab-ce-cfbbdde3e5485454ca9dc14449787ceb8d0a09df.tar.gz
Merge branch '30264-fix-vue-pagination' into 'master'
Fixes method not replacing URL parameters correctly Closes #30264 See merge request !10351
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index 4aad0128aef..46b80c04e20 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -263,7 +263,7 @@
});
/**
- * Updates the search parameter of a URL given the parameter and values provided.
+ * Updates the search parameter of a URL given the parameter and value provided.
*
* If no search params are present we'll add it.
* If param for page is already present, we'll update it
@@ -278,17 +278,24 @@
let search;
const locationSearch = window.location.search;
- if (locationSearch.length === 0) {
- search = `?${param}=${value}`;
- }
+ if (locationSearch.length) {
+ const parameters = locationSearch.substring(1, locationSearch.length)
+ .split('&')
+ .reduce((acc, element) => {
+ const val = element.split('=');
+ acc[val[0]] = decodeURIComponent(val[1]);
+ return acc;
+ }, {});
- if (locationSearch.indexOf(param) !== -1) {
- const regex = new RegExp(param + '=\\d');
- search = locationSearch.replace(regex, `${param}=${value}`);
- }
+ parameters[param] = value;
- if (locationSearch.length && locationSearch.indexOf(param) === -1) {
- search = `${locationSearch}&${param}=${value}`;
+ const toString = Object.keys(parameters)
+ .map(val => `${val}=${encodeURIComponent(parameters[val])}`)
+ .join('&');
+
+ search = `?${toString}`;
+ } else {
+ search = `?${param}=${value}`;
}
return search;