mirror of
https://github.com/discourse/discourse.git
synced 2026-08-09 12:38:21 -05:00
FIX: Edit sidebar tags navigation model "selected" filter not working (#36765)
What is the problem? When a user does not have any tags configured to be displayed in the sidebar, selecting the "selected" filter in the edit sidebar tags navigation model was not displaying an empty state. Instead, it displayed all the tags even though those tags were unselected. The above behaviour is due to the fact that the client side was not properly setting the `only_tags` param for the request to the `/tags/list.json` endpoint when the user has not selected any tags in the modal. As a result, the endpoint ended up returning all the tags that are visible to the user. What is the fix? On the client side, we just have to avoid fetching tags when we already know that the user has not selected any tags.
This commit is contained in:
@@ -5373,7 +5373,7 @@ en:
|
||||
tags_form_modal:
|
||||
title: "Edit tags navigation"
|
||||
filter_placeholder: "Filter tags"
|
||||
no_tags: "There are no tags matching the given term."
|
||||
no_tags: "There are no tags matching the current filters."
|
||||
subtitle:
|
||||
text: "and we'll automatically show this site's top tags"
|
||||
edit_navigation_modal_form:
|
||||
|
||||
@@ -35,25 +35,32 @@ export default class SidebarEditNavigationMenuTagsModal extends Component {
|
||||
}
|
||||
|
||||
async #loadTags() {
|
||||
this.tagsLoading = true;
|
||||
|
||||
const findArgs = {};
|
||||
|
||||
if (this.filter) {
|
||||
findArgs.filter = this.filter;
|
||||
}
|
||||
|
||||
if (this.onlySelected) {
|
||||
findArgs.only_tags = [...this.selectedTags].join(",");
|
||||
} else if (this.onlyUnselected) {
|
||||
findArgs.exclude_tags = [...this.selectedTags].join(",");
|
||||
}
|
||||
|
||||
try {
|
||||
const tags = await this.store.findAll("listTag", findArgs);
|
||||
this.tags = tags;
|
||||
} catch (error) {
|
||||
popupAjaxError(error);
|
||||
this.tagsLoading = true;
|
||||
|
||||
const findArgs = {};
|
||||
|
||||
if (this.filter) {
|
||||
findArgs.filter = this.filter;
|
||||
}
|
||||
|
||||
if (this.onlySelected) {
|
||||
if (this.selectedTags.size === 0) {
|
||||
this.tags = [];
|
||||
return;
|
||||
}
|
||||
|
||||
findArgs.only_tags = [...this.selectedTags].join(",");
|
||||
} else if (this.onlyUnselected) {
|
||||
findArgs.exclude_tags = [...this.selectedTags].join(",");
|
||||
}
|
||||
|
||||
try {
|
||||
const tags = await this.store.findAll("listTag", findArgs);
|
||||
this.tags = tags;
|
||||
} catch (error) {
|
||||
popupAjaxError(error);
|
||||
}
|
||||
} finally {
|
||||
this.tagsLoading = false;
|
||||
this.disableFiltering = false;
|
||||
|
||||
@@ -177,6 +177,20 @@ RSpec.describe "Editing sidebar tags navigation", type: :system do
|
||||
expect(modal).to have_tag_checkboxes([tag1, tag2, tag3, tag4])
|
||||
end
|
||||
|
||||
it "displays empty state when filtering by selected with no tags selected" do
|
||||
visit "/latest"
|
||||
|
||||
expect(sidebar).to have_tags_section
|
||||
|
||||
modal = sidebar.click_edit_tags_button
|
||||
|
||||
expect(modal).to have_tag_checkboxes([tag1, tag2, tag3, tag4])
|
||||
|
||||
modal.filter_by_selected
|
||||
|
||||
expect(modal).to have_no_tag_checkboxes
|
||||
end
|
||||
|
||||
it "loads more tags when the user scrolls views the last tag in the modal and there is more tags to load" do
|
||||
Tag.delete_all
|
||||
|
||||
|
||||
Reference in New Issue
Block a user