UX: caches icon picker full icon's list (#8862)

This commit is contained in:
Joffrey JAFFEUX 2020-02-05 09:22:11 +01:00 committed by GitHub
parent a9f1652131
commit d7dffbb13c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 3 deletions

View File

@ -8,14 +8,34 @@ export default MultiSelectComponent.extend({
pluginApiIdentifiers: ["icon-picker"],
classNames: ["icon-picker"],
init() {
this._super(...arguments);
this._cachedIconsList = null;
},
content: computed("value.[]", function() {
return makeArray(this.value).map(this._processIcon);
}),
search(filter = "") {
return ajax("/svg-sprite/picker-search", { data: { filter } }).then(icons =>
icons.map(this._processIcon)
);
if (
filter === "" &&
this._cachedIconsList &&
this._cachedIconsList.length
) {
return this._cachedIconsList;
} else {
return ajax("/svg-sprite/picker-search", {
data: { filter }
}).then(icons => {
icons = icons.map(this._processIcon);
if (filter === "") {
this._cachedIconsList = icons;
}
return icons;
});
}
},
_processIcon(icon) {
@ -48,6 +68,8 @@ export default MultiSelectComponent.extend({
willDestroyElement() {
$("#svg-sprites .ajax-icon-holder").remove();
this._super(...arguments);
this._cachedIconsList = null;
},
actions: {