Bug 1623589 - Make filter URL handling more resilient (#6164)

This commit is contained in:
Cameron Dawson 2020-03-23 11:20:09 -07:00 коммит произвёл GitHub
Родитель 1ff6e16cdd
Коммит 1c8759f89f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 19 добавлений и 6 удалений

Просмотреть файл

@ -2,7 +2,7 @@ import pick from 'lodash/pick';
import isEqual from 'lodash/isEqual';
import { thFailureResults } from './constants';
import { parseQueryParams } from './url';
import { extractSearchString, parseQueryParams } from './url';
// used with field-filters to determine how to match the value against the
// job field.
@ -100,11 +100,11 @@ export const hasUrlFilterChanges = function hasUrlFilterChanges(
newURL,
) {
const oldFilters = pick(
parseQueryParams(oldURL.split('?')[1]),
parseQueryParams(extractSearchString(oldURL)),
allFilterParams,
);
const newFilters = pick(
parseQueryParams(newURL.split('?')[1]),
parseQueryParams(extractSearchString(newURL)),
allFilterParams,
);

Просмотреть файл

@ -1,8 +1,13 @@
import { thDefaultRepo } from './constants';
import { createQueryParams, getApiUrl, uiJobsUrlBase } from './url';
import {
createQueryParams,
extractSearchString,
getApiUrl,
uiJobsUrlBase,
} from './url';
export const getQueryString = function getQueryString() {
return window.location.hash.split('?')[1];
return extractSearchString(window.location.hash);
};
export const getAllUrlParams = function getAllUrlParams() {

Просмотреть файл

@ -120,6 +120,12 @@ export const parseQueryParams = function parseQueryParams(search) {
);
};
export const extractSearchString = function getQueryString(url) {
const parts = url.split('?');
return parts[parts.length - 1];
};
// `api` requires a preceding forward slash
export const createApiUrl = function createApiUrl(api, params) {
const apiUrl = getApiUrl(api);

Просмотреть файл

@ -113,7 +113,9 @@ export default class FilterModel {
* will get updates.
*/
push = () => {
window.location.hash = `#/jobs?${this.getFilterQueryString()}`;
const { origin } = window.location;
window.location.href = `${origin}/#/jobs?${this.getFilterQueryString()}`;
};
setOnlySuperseded = () => {