FIX: makes mini-tag-chooser search more efficient

This commit is contained in:
Joffrey JAFFEUX 2018-02-15 15:01:19 +01:00 committed by GitHub
parent 585fc26f8e
commit 2cf40096d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 26 deletions

View File

@ -3,7 +3,7 @@ import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { default as computed } from "ember-addons/ember-computed-decorators";
import renderTag from "discourse/lib/render-tag";
const { get, isEmpty, isPresent, run } = Ember;
const { get, isEmpty, isPresent, run, makeArray } = Ember;
export default ComboBox.extend({
allowContentReplacement: true,
@ -18,6 +18,20 @@ export default ComboBox.extend({
caretUpIcon: Ember.computed.alias("caretIcon"),
caretDownIcon: Ember.computed.alias("caretIcon"),
init() {
this._super();
this.set("termMatchesForbidden", false);
this.set("templateForRow", (rowComponent) => {
const tag = rowComponent.get("computedContent");
return renderTag(get(tag, "value"), {
count: get(tag, "originalContent.count"),
noHref: true
});
});
},
@computed("limitReached", "maximumSelectionSize")
maxContentRow(limitReached, count) {
if (limitReached) {
@ -43,23 +57,9 @@ export default ComboBox.extend({
return false;
},
init() {
this._super();
this.set("termMatchesForbidden", false);
this.set("templateForRow", (rowComponent) => {
const tag = rowComponent.get("computedContent");
return renderTag(get(tag, "value"), {
count: get(tag, "originalContent.count"),
noHref: true
});
});
},
@computed("tags")
computedTags(tags) {
return Ember.makeArray(tags);
return makeArray(tags);
},
validateCreate(term) {
@ -146,7 +146,7 @@ export default ComboBox.extend({
@computed("tags.[]", "filter")
collectionHeader(tags, filter) {
if (!Ember.isEmpty(tags)) {
if (!isEmpty(tags)) {
let output = "";
if (tags.length >= 20) {
@ -186,39 +186,38 @@ export default ComboBox.extend({
delete tags[tags.indexOf(tag)];
this.set("tags", tags.filter(t => t));
this.set("content", []);
this.set("searchDebounce", run.debounce(this, this._searchTags, 200));
this.set("searchDebounce", run.debounce(this, this._searchTags, this.get("filter"), 250));
},
onExpand() {
this.set("searchDebounce", run.debounce(this, this._searchTags, 200));
if (isEmpty(this.get("content"))) {
this.set("searchDebounce", run.debounce(this, this._searchTags, this.get("filter"), 250));
}
},
onFilter(filter) {
filter = isEmpty(filter) ? null : filter;
this.set("searchDebounce", run.debounce(this, this._searchTags, filter, 200));
this.set("searchDebounce", run.debounce(this, this._searchTags, filter, 250));
},
onSelect(tag) {
if (isEmpty(this.get("computedTags"))) {
this.set("tags", Ember.makeArray(tag));
this.set("tags", makeArray(tag));
} else {
this.set("tags", this.get("computedTags").concat(tag));
}
this.set("content", []);
this.set("searchDebounce", run.debounce(this, this._searchTags, 200));
this.set("searchDebounce", run.debounce(this, this._searchTags, this.get("filter"), 250));
}
},
_searchTags(query) {
this.startLoading();
const selectedTags = Ember.makeArray(this.get("computedTags")).filter(t => t);
const self = this;
const selectedTags = makeArray(this.get("computedTags")).filter(t => t);
const sortTags = this.siteSettings.tags_sort_alphabetically;
const data = {
q: query,
limit: this.siteSettings.max_tag_search_results,