FIX: Make sure user list is complete and sorted (#17616)

Sometimes the user list was incomplete when multiple requests were
created to fetch next pages. If the responses did not arrive in the
same order as the requests then only the last response was parsed.

This is a follow up commit to a0f4c7fe88.
This commit is contained in:
Bianca Nenciu 2022-07-26 17:54:52 +03:00 committed by GitHub
parent 47917c0be4
commit 171789f47a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,6 @@ export default Controller.extend(CanCheckEmails, {
listFilter: null,
selectAll: false,
searchHint: i18n("search_hint"),
_searchIndex: 0,
init() {
this._super(...arguments);
@ -49,8 +48,7 @@ export default Controller.extend(CanCheckEmails, {
return;
}
this._searchIndex++;
const searchIndex = this._searchIndex;
const page = this._page;
this.set("refreshing", true);
AdminUser.findAll(this.query, {
@ -58,34 +56,21 @@ export default Controller.extend(CanCheckEmails, {
show_emails: this.showEmails,
order: this.order,
asc: this.asc,
page: this._page,
page,
})
.then((result) => {
if (this.ignoreResponse(searchIndex)) {
return;
}
if (!result || result.length === 0) {
if (result && result.length > 0) {
this._results[page] = result;
this.set("model", this._results.flat());
} else {
this._canLoadMore = false;
}
this._results = this._results.concat(result);
this.set("model", this._results);
})
.finally(() => {
if (this.ignoreResponse(searchIndex)) {
return;
}
this.set("refreshing", false);
});
},
ignoreResponse(searchIndex) {
return (
searchIndex !== this._searchIndex || this.isDestroyed || this.isDestroying
);
},
actions: {
loadMore() {
this._page += 1;