FIX: add decorated html to edit sidebar categories (#37169)

Fixes a display issue in the edit sidebar category modal where
categories contain hashtags for either tags, categories etc.

This change adds decorated html to allow hashtag decoration on category
descriptions.

### Before

<img width="510" height="210" alt="Before change"
src="https://github.com/user-attachments/assets/58673ed6-fb6a-4bbb-986e-ec3f8759a619"
/>


### After

<img width="500" height="209" alt="After change"
src="https://github.com/user-attachments/assets/2e665829-b6bb-45da-9762-9eb0ba87ef45"
/>
This commit is contained in:
David Battersby
2026-01-16 15:49:16 +04:00
committed by GitHub
parent d7de0f6735
commit f252e0498b
3 changed files with 52 additions and 4 deletions
@@ -7,6 +7,7 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { service } from "@ember/service";
import { TrackedSet } from "@ember-compat/tracked-built-ins";
import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
import DecoratedHtml from "discourse/components/decorated-html";
import EditNavigationMenuModal from "discourse/components/sidebar/edit-navigation-menu/modal";
import borderColor from "discourse/helpers/border-color";
import categoryBadge from "discourse/helpers/category-badge";
@@ -299,10 +300,12 @@ export default class SidebarEditNavigationMenuCategoriesModal extends Component
<div
class="sidebar-categories-form__category-description"
>
{{dirSpan
category.description_excerpt
htmlSafe="true"
}}
<DecoratedHtml
@html={{dirSpan
category.description_excerpt
htmlSafe="true"
}}
/>
</div>
{{/unless}}
</div>
@@ -184,6 +184,33 @@ RSpec.describe "Editing sidebar categories navigation", type: :system do
)
end
describe "hashtag decoration in category descriptions" do
fab!(:tag) { Fabricate(:tag, name: "test-tag") }
fab!(:icon_category) { Fabricate(:category, name: "icon category", icon: "wrench") }
fab!(:emoji_category) { Fabricate(:category, name: "emoji category", emoji: "rocket") }
fab!(:category_with_hashtags) do
Fabricate(:category, name: "category with hashtags", description: <<~HTML)
Discussion about
and <a class="hashtag-cooked" href="/tag/#{tag.name}" data-type="tag" data-slug="#{tag.name}" data-id="#{tag.id}"><span class="hashtag-icon-placeholder"></span><span>#{tag.name}</span></a>
and <a class="hashtag-cooked" href="/c/#{icon_category.slug}/#{icon_category.id}" data-type="category" data-slug="#{icon_category.slug}" data-id="#{icon_category.id}" data-style-type="icon" data-icon="wrench"><span class="hashtag-icon-placeholder"></span><span>#{icon_category.name}</span></a>
and <a class="hashtag-cooked" href="/c/#{emoji_category.slug}/#{emoji_category.id}" data-type="category" data-slug="#{emoji_category.slug}" data-id="#{emoji_category.id}" data-style-type="emoji" data-emoji="rocket"><span class="hashtag-icon-placeholder"></span><span>#{emoji_category.name}</span></a>
HTML
end
it "decorates hashtags for tags, icons and emojis in the description" do
visit "/latest"
expect(sidebar).to have_categories_section
modal = sidebar.click_edit_categories_button
expect(modal).to have_tag_in_description(category_with_hashtags)
expect(modal).to have_icon_in_description(category_with_hashtags)
expect(modal).to have_emoji_in_description(category_with_hashtags)
end
end
describe "when max_category_nesting has been set to 3" do
before_all { SiteSetting.max_category_nesting = 3 }
@@ -82,6 +82,24 @@ module PageObjects
).click
self
end
def has_tag_in_description?(category)
has_css?(
".sidebar-categories-form__category-row[data-category-id='#{category.id}'] .sidebar-categories-form__category-description a.hashtag-cooked[data-type='tag']",
)
end
def has_icon_in_description?(category)
has_css?(
".sidebar-categories-form__category-row[data-category-id='#{category.id}'] .sidebar-categories-form__category-description a.hashtag-cooked .hashtag-category-icon",
)
end
def has_emoji_in_description?(category)
has_css?(
".sidebar-categories-form__category-row[data-category-id='#{category.id}'] .sidebar-categories-form__category-description a.hashtag-cooked .hashtag-category-emoji",
)
end
end
end
end