diff options
author | Paul Slaughter <pslaughter@gitlab.com> | 2018-05-23 08:13:49 -0500 |
---|---|---|
committer | Paul Slaughter <pslaughter@gitlab.com> | 2018-05-23 08:59:25 -0500 |
commit | 479fc3f8ff0e3435be168672632534e805aa8ffa (patch) | |
tree | 52c762ca2829fef4373db17c891a3a67ffd54659 | |
parent | 168060f4ddd2dbe993585319bca5c4894446f632 (diff) | |
download | gitlab-ce-38919/wiki-empty-states.tar.gz |
Remove "mergeCurrentUrlParams" function38919/wiki-empty-states
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 22 | ||||
-rw-r--r-- | app/assets/javascripts/pages/projects/wikis/wikis.js | 7 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/common_utils_spec.js | 34 |
3 files changed, 5 insertions, 58 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index 516a382d738..9ff2042475b 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -1,7 +1,7 @@ import $ from 'jquery'; import Cookies from 'js-cookie'; import axios from './axios_utils'; -import { getLocationHash, mergeUrlParams } from './url_utility'; +import { getLocationHash } from './url_utility'; import { convertToCamelCase } from './text_utility'; export const getPagePath = (index = 0) => $('body').attr('data-page').split(':')[index]; @@ -448,26 +448,6 @@ export const addSelectOnFocusBehaviour = (selector = '.js-select-on-focus') => { }); }; -/** - * Merge the current URL params (from `window.location.href`) into the given url. - * - * Notes: - * - When two of the same params exist, the current URL param overrides the - * given one. - * - * @param {String} url This is the destination url. - * @param {Object} [_window=window] This parameter can be used to inject a mock - * `window`, which is helpful for testing. - * @returns {String} - */ -export function mergeCurrentUrlParams(url, _window = window) { - const source = _window.location.href || ''; - const sourceQuery = source.split('?')[1]; - const sourceParams = parseQueryStringIntoObject(sourceQuery, true); - - return mergeUrlParams(sourceParams, url); -} - window.gl = window.gl || {}; window.gl.utils = { ...(window.gl.utils || {}), diff --git a/app/assets/javascripts/pages/projects/wikis/wikis.js b/app/assets/javascripts/pages/projects/wikis/wikis.js index 9a286dae258..dcd0b9a76ce 100644 --- a/app/assets/javascripts/pages/projects/wikis/wikis.js +++ b/app/assets/javascripts/pages/projects/wikis/wikis.js @@ -1,7 +1,7 @@ import bp from '../../../breakpoints'; import { slugify } from '../../../lib/utils/text_utility'; -import { mergeCurrentUrlParams } from '../../../lib/utils/common_utils'; -import { redirectTo } from '../../../lib/utils/url_utility'; +import { parseQueryStringIntoObject } from '../../../lib/utils/common_utils'; +import { mergeUrlParams, redirectTo } from '../../../lib/utils/url_utility'; export default class Wikis { constructor() { @@ -32,7 +32,8 @@ export default class Wikis { const wikisPath = slugInput.getAttribute('data-wikis-path'); // If the wiki is empty, we need to merge the current URL params to keep the "create" view. - const url = mergeCurrentUrlParams(`${wikisPath}/${slug}`); + const params = parseQueryStringIntoObject(window.location.search.substr(1)); + const url = mergeUrlParams(params, `${wikisPath}/${slug}`); redirectTo(url); e.preventDefault(); diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index 14cb281fb94..27f06573432 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -1,7 +1,6 @@ /* eslint-disable promise/catch-or-return */ import axios from '~/lib/utils/axios_utils'; import * as commonUtils from '~/lib/utils/common_utils'; -import { TEST_HOST } from 'spec/test_constants'; import MockAdapter from 'axios-mock-adapter'; describe('common_utils', () => { @@ -525,37 +524,4 @@ describe('common_utils', () => { expect(Object.keys(commonUtils.convertObjectPropsToCamelCase({})).length).toBe(0); }); }); - - describe('mergeCurrentUrlParams', () => { - [ - [ - 'with happy path', - 'home/b?q=Elephants&count=10', 'dest/c?name=sholmes', 'dest/c?name=sholmes&q=Elephants&count=10', - ], - [ - 'with no query in location.href', - 'home/b-acd#q=abc&count=10', 'dest/c?name=sholmes', 'dest/c?name=sholmes', - ], - [ - 'with no query in destination', - 'home/b?q=Elephants&count=10', 'dest/c', 'dest/c?q=Elephants&count=10', - ], - [ - 'with no query', - 'home/b', 'dest/c', 'dest/c', - ], - [ - 'with overriding query values', - 'home/b?q=Walruses&count=100', 'dest/c?q=Carpenters', 'dest/c?q=Walruses&count=100', - ], - ].forEach(([message, origUrl, newUrl, expected]) => { - it(`${message} merges params from location.href and the url`, () => { - const mockWindow = { location: { href: `${TEST_HOST}/${origUrl}` } }; - - const actual = commonUtils.mergeCurrentUrlParams(`${TEST_HOST}/${newUrl}`, mockWindow); - - expect(actual).toEqual(`${TEST_HOST}/${expected}`); - }); - }); - }); }); |