Add escape quotations for selected labels from dropdown
This commit is contained in:
parent
60c9240bc2
commit
da8ab2bc08
2 changed files with 22 additions and 3 deletions
|
@ -12,8 +12,22 @@
|
|||
const dataValueSet = this.setDataValueIfSelected(e.detail.selected);
|
||||
|
||||
if (!dataValueSet) {
|
||||
const labelName = `~${e.detail.selected.querySelector('.label-title').innerText.trim()}`;
|
||||
gl.FilteredSearchManager.addWordToInput(this.getSelectedText(labelName));
|
||||
let labelTitle = e.detail.selected.querySelector('.label-title').innerText.trim();
|
||||
|
||||
// Encapsulate label with quotes if it has spaces
|
||||
if (labelTitle.indexOf(' ') !== -1) {
|
||||
if (labelTitle.indexOf('"') !== -1) {
|
||||
// Use single quotes if label title contains double quotes
|
||||
labelTitle = `'${labelTitle}'`;
|
||||
} else {
|
||||
// Known side effect: Label's with both single and double quotes
|
||||
// won't escape properly
|
||||
labelTitle = `"${labelTitle}"`;
|
||||
}
|
||||
}
|
||||
|
||||
const labelName = `~${labelTitle}`;
|
||||
gl.FilteredSearchManager.addWordToInput(labelName);
|
||||
}
|
||||
|
||||
this.dismissDropdown();
|
||||
|
|
|
@ -97,7 +97,12 @@
|
|||
|
||||
const { lastToken } = gl.FilteredSearchTokenizer.processTokens(filteredSearchValue);
|
||||
if (lastToken.hasOwnProperty('key')) {
|
||||
document.querySelector('.filtered-search').value = filteredSearchValue.slice(0, -1 * (lastToken.value.length));
|
||||
console.log(lastToken);
|
||||
// Spaces inside the token means that the token value will be escaped by quotes
|
||||
const hasQuotes = lastToken.value.indexOf(' ') !== -1;
|
||||
|
||||
const lengthToRemove = hasQuotes ? lastToken.value.length + 2 : lastToken.value.length;
|
||||
document.querySelector('.filtered-search').value = filteredSearchValue.slice(0, -1 * (lengthToRemove));
|
||||
}
|
||||
|
||||
document.querySelector('.filtered-search').value += hasExistingValue && addSpace ? ` ${word}` : word;
|
||||
|
|
Loading…
Reference in a new issue