Skip to content

A platform for community discussion. Free, open, simple.

FIX: Edit sidebar tags navigation model "selected" filter not working (#36765)

Alan Guo Xiang Tan4023187af8b9
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 18767d8723f..11465c5a895 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -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:
diff --git a/frontend/discourse/app/components/sidebar/edit-navigation-menu/tags-modal.gjs b/frontend/discourse/app/components/sidebar/edit-navigation-menu/tags-modal.gjs
index 310040c7f93..359bf6ca91d 100644
--- a/frontend/discourse/app/components/sidebar/edit-navigation-menu/tags-modal.gjs
+++ b/frontend/discourse/app/components/sidebar/edit-navigation-menu/tags-modal.gjs
@@ -35,25 +35,32 @@ export default class SidebarEditNavigationMenuTagsModal extends Component {
}
async #loadTags() {
- this.tagsLoading = true;
+ try {
+ this.tagsLoading = true;
- const findArgs = {};
+ const findArgs = {};
- if (this.filter) {
- findArgs.filter = this.filter;
- }
+ 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(",");
- }
+ if (this.onlySelected) {
+ if (this.selectedTags.size === 0) {
+ this.tags = [];
+ return;
+ }
- try {
- const tags = await this.store.findAll("listTag", findArgs);
- this.tags = tags;
- } catch (error) {
- popupAjaxError(error);
+ 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;
diff --git a/spec/system/editing_sidebar_tags_navigation_spec.rb b/spec/system/editing_sidebar_tags_navigation_spec.rb
index 0dc6459b8f8..f7658274a23 100644
--- a/spec/system/editing_sidebar_tags_navigation_spec.rb
+++ b/spec/system/editing_sidebar_tags_navigation_spec.rb
@@ -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