BigW Consortium Gitlab

Commit da8ab2bc by Clement Ho

Add escape quotations for selected labels from dropdown

parent 60c9240b
...@@ -12,8 +12,22 @@ ...@@ -12,8 +12,22 @@
const dataValueSet = this.setDataValueIfSelected(e.detail.selected); const dataValueSet = this.setDataValueIfSelected(e.detail.selected);
if (!dataValueSet) { if (!dataValueSet) {
const labelName = `~${e.detail.selected.querySelector('.label-title').innerText.trim()}`; let labelTitle = e.detail.selected.querySelector('.label-title').innerText.trim();
gl.FilteredSearchManager.addWordToInput(this.getSelectedText(labelName));
// 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(); this.dismissDropdown();
......
...@@ -97,7 +97,12 @@ ...@@ -97,7 +97,12 @@
const { lastToken } = gl.FilteredSearchTokenizer.processTokens(filteredSearchValue); const { lastToken } = gl.FilteredSearchTokenizer.processTokens(filteredSearchValue);
if (lastToken.hasOwnProperty('key')) { 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; document.querySelector('.filtered-search').value += hasExistingValue && addSpace ? ` ${word}` : word;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment