FIX: Update user results page when no users found (#18363)

The page was not updated if the server did not return any results. This
caused the page to be either empty or display the previous result set.
This commit is contained in:
Bianca Nenciu 2022-09-26 16:37:56 +03:00 committed by GitHub
parent f64e7233e5
commit b81afa0756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -59,10 +59,10 @@ export default Controller.extend(CanCheckEmails, {
page, page,
}) })
.then((result) => { .then((result) => {
if (result && result.length > 0) {
this._results[page] = result; this._results[page] = result;
this.set("model", this._results.flat()); this.set("model", this._results.flat());
} else {
if (result.length === 0) {
this._canLoadMore = false; this._canLoadMore = false;
} }
}) })

View File

@ -3,7 +3,7 @@ import {
exists, exists,
query, query,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers"; import { click, fillIn, visit } from "@ember/test-helpers";
import I18n from "I18n"; import I18n from "I18n";
import { test } from "qunit"; import { test } from "qunit";
@ -17,6 +17,17 @@ acceptance("Admin - Users List", function (needs) {
assert.ok(!exists(".user:nth-of-type(1) .email small"), "escapes email"); assert.ok(!exists(".user:nth-of-type(1) .email small"), "escapes email");
}); });
test("searching users with no matches", async function (assert) {
await visit("/admin/users/list/active");
await fillIn(".controls.username input", "doesntexist");
assert.equal(
query(".users-list-container").innerText,
I18n.t("search.no_results")
);
});
test("sorts users", async function (assert) { test("sorts users", async function (assert) {
await visit("/admin/users/list/active"); await visit("/admin/users/list/active");

View File

@ -670,6 +670,12 @@ export function applyDefaultHandlers(pretender) {
}, },
]; ];
if (request.queryParams.filter) {
store = store.filter((user) =>
user.username.includes(request.queryParams.filter)
);
}
const showEmails = request.queryParams.show_emails; const showEmails = request.queryParams.show_emails;
if (showEmails === "false") { if (showEmails === "false") {