FIX: Shows all_results if current settings category has no results (#10358)

Searching for a specific setting only showed results from the current selected category. Before fixing fd02856, it automatically redirected the user to all_results. This was a problem because the redirect always happened and there was no way to share a link to a specific category.

The fix to this bug is to simply redirect the user to all_results if there are no results to be displayed.
This commit is contained in:
Bianca Nenciu 2020-08-05 10:39:54 +03:00 committed by GitHub
parent 850d5696f2
commit 42f62a9e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -93,6 +93,14 @@ export default Controller.extend({
all.hasMore = matches.length > 30;
all.count = all.hasMore ? "30+" : matches.length;
const categoryMatches = matchesGroupedByCategory.findBy(
"nameKey",
category
);
if (!categoryMatches || categoryMatches.count === 0) {
category = "all_results";
}
this.set("visibleSiteSettings", matchesGroupedByCategory);
this.transitionToRoute(
"adminSiteSettingsCategory",

View File

@ -119,3 +119,19 @@ QUnit.test("category name is preserved", async assert => {
await visit("admin/site_settings/category/login?filter=test");
assert.equal(currentURL(), "admin/site_settings/category/login?filter=test");
});
QUnit.test("shows all_results if current category has none", async assert => {
await visit("admin/site_settings");
await click(".admin-nav .basic a");
assert.equal(currentURL(), "/admin/site_settings/category/basic");
await fillIn("#setting-filter", "menu");
assert.equal(currentURL(), "/admin/site_settings/category/basic?filter=menu");
await fillIn("#setting-filter", "contact");
assert.equal(
currentURL(),
"/admin/site_settings/category/all_results?filter=contact"
);
});