Fix bug where search terms would not work after switching to another state tab
This commit is contained in:
parent
53b4d1b3a7
commit
3ce7f23a85
1 changed files with 15 additions and 7 deletions
|
@ -55,12 +55,13 @@
|
||||||
|
|
||||||
loadSearchParamsFromURL() {
|
loadSearchParamsFromURL() {
|
||||||
// We can trust that each param has one & since values containing & will be encoded
|
// We can trust that each param has one & since values containing & will be encoded
|
||||||
const params = window.location.search.split('&');
|
// Remove the first character of search as it is always ?
|
||||||
|
const params = window.location.search.slice(1).split('&');
|
||||||
let inputValue = '';
|
let inputValue = '';
|
||||||
|
|
||||||
params.forEach((p) => {
|
params.forEach((p) => {
|
||||||
const split = p.split('=');
|
const split = p.split('=');
|
||||||
const key = split[0];
|
const key = decodeURIComponent(split[0]);
|
||||||
const value = decodeURIComponent(split[1]);
|
const value = decodeURIComponent(split[1]);
|
||||||
|
|
||||||
const match = validTokenKeys.find((t) => {
|
const match = validTokenKeys.find((t) => {
|
||||||
|
@ -69,17 +70,24 @@
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
const sanitizedKey = key.slice(0, key.indexOf('_'));
|
const sanitizedKey = key.slice(0, key.indexOf('_'));
|
||||||
let sanitizedValue = value;
|
const valueHasSpace = value.indexOf(' ') !== -1;
|
||||||
|
|
||||||
if (match && sanitizedKey === 'label') {
|
const preferredQuotations = '"';
|
||||||
sanitizedValue = sanitizedValue.replace(/%20/g, ' ');
|
let quotationsToUse = preferredQuotations;
|
||||||
|
|
||||||
|
if (valueHasSpace) {
|
||||||
|
// Prefer ", but use ' if required
|
||||||
|
quotationsToUse = value.indexOf(preferredQuotations) === -1 ? preferredQuotations : '\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
inputValue += `${sanitizedKey}:${sanitizedValue} `;
|
inputValue += valueHasSpace ? `${sanitizedKey}:${quotationsToUse}${value}${quotationsToUse}` : `${sanitizedKey}:${value}`;
|
||||||
|
inputValue += ' ';
|
||||||
|
|
||||||
} else if (!match && key === 'search') {
|
} else if (!match && key === 'search') {
|
||||||
// Sanitize value as URL converts spaces into +
|
// Sanitize value as URL converts spaces into +
|
||||||
const sanitizedValue = value.replace(/[+]/g, ' ');
|
const sanitizedValue = value.replace(/[+]/g, ' ');
|
||||||
inputValue += `${sanitizedValue} `;
|
inputValue += sanitizedValue;
|
||||||
|
inputValue += ' ';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue