mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Improved tag suggestion handling
- Aligned prefix-type filtering with back-end. - Increased suggestion search cut-off from 3 to 4. - Increased amount of suggestions shown. - Ordered suggestions to be name asc, as you'd expect on search. - Updated front-end filtering to use full search query, instead of truncated version, for further front-end filtering capability. Related to #3720
This commit is contained in:
@ -88,14 +88,12 @@ class AutoSuggest {
|
||||
}
|
||||
|
||||
const nameFilter = this.getNameFilterIfNeeded();
|
||||
const search = this.input.value.slice(0, 3).toLowerCase();
|
||||
const search = this.input.value.toLowerCase();
|
||||
const suggestions = await this.loadSuggestions(search, nameFilter);
|
||||
let toShow = suggestions.slice(0, 6);
|
||||
if (search.length > 0) {
|
||||
toShow = suggestions.filter(val => {
|
||||
return val.toLowerCase().includes(search);
|
||||
}).slice(0, 6);
|
||||
}
|
||||
|
||||
const toShow = suggestions.filter(val => {
|
||||
return search === '' || val.toLowerCase().startsWith(search);
|
||||
}).slice(0, 10);
|
||||
|
||||
this.displaySuggestions(toShow);
|
||||
}
|
||||
@ -111,6 +109,9 @@ class AutoSuggest {
|
||||
* @returns {Promise<Object|String|*>}
|
||||
*/
|
||||
async loadSuggestions(search, nameFilter = null) {
|
||||
// Truncate search to prevent over numerous lookups
|
||||
search = search.slice(0, 4);
|
||||
|
||||
const params = {search, name: nameFilter};
|
||||
const cacheKey = `${this.url}:${JSON.stringify(params)}`;
|
||||
|
||||
|
Reference in New Issue
Block a user