Skip to content

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

FIX: Hashtag icon for style_type=icon not showing in rich editor (#35786)

Martin Brennana51ce45508c4
diff --git a/frontend/discourse/app/lib/hashtag-autocomplete.js b/frontend/discourse/app/lib/hashtag-autocomplete.js
index b1fd65a6689..602fb6e8f70 100644
--- a/frontend/discourse/app/lib/hashtag-autocomplete.js
+++ b/frontend/discourse/app/lib/hashtag-autocomplete.js
@@ -141,7 +141,7 @@ function _searchRequest(term, contextualHashtagConfiguration, resultFunc) {
}
const hashtagType = getHashtagTypeClassesNew()[result.type];
- result.icon = hashtagType.generateIconHTML(opts);
+ result.iconHtml = hashtagType.generateIconHTML(opts);
});
resultFunc(response.results || CANCELLED_STATUS);
})
@@ -159,7 +159,7 @@ function renderOption(option) {
return `
<li class="hashtag-autocomplete__option">
<a class="hashtag-autocomplete__link" title="${escapeExpression(option.description)}" href>
- ${option.icon}
+ ${option.iconHtml}
<span class="hashtag-autocomplete__text">
${option.text}
${metaText}
diff --git a/frontend/discourse/app/static/prosemirror/extensions/hashtag.js b/frontend/discourse/app/static/prosemirror/extensions/hashtag.js
index d1c716903f0..bd17d521b38 100644
--- a/frontend/discourse/app/static/prosemirror/extensions/hashtag.js
+++ b/frontend/discourse/app/static/prosemirror/extensions/hashtag.js
@@ -173,9 +173,9 @@ const extension = {
: displayText;
const hashtagTypeClass =
getHashtagTypeClasses()[validHashtag.type];
- const hashtagIconHTML = hashtagTypeClass
- .generateIconHTML(validHashtag)
- .trim();
+ const hashtagIconHTML =
+ validHashtag.iconHtml ||
+ hashtagTypeClass.generateIconHTML(validHashtag).trim();
domNode.innerHTML = `${hashtagIconHTML}${tagText}`;
}
diff --git a/frontend/discourse/tests/acceptance/hashtag-autocomplete-test.js b/frontend/discourse/tests/acceptance/hashtag-autocomplete-test.js
index e3e373c6e5e..28ee9762493 100644
--- a/frontend/discourse/tests/acceptance/hashtag-autocomplete-test.js
+++ b/frontend/discourse/tests/acceptance/hashtag-autocomplete-test.js
@@ -27,6 +27,30 @@ acceptance("#hashtag autocompletion in composer", function (needs) {
relative_url: "/c/other-languages/28",
ref: "other-languages",
type: "category",
+ style_type: "square",
+ },
+ {
+ id: 99,
+ text: "Fun stuff",
+ slug: "fun-stuff",
+ colors: ["55FF00"],
+ icon: "bell",
+ relative_url: "/c/fun-stuff/99",
+ ref: "fun-stuff",
+ type: "category",
+ style_type: "icon",
+ },
+ {
+ id: 123,
+ text: "organization",
+ slug: "organization",
+ colors: ["0000FF", "00FFFF"],
+ emoji: "joy",
+ icon: "folder",
+ relative_url: "/c/organization/123",
+ ref: "organization",
+ type: "category",
+ style_type: "emoji",
},
{
id: 300,
@@ -36,6 +60,7 @@ acceptance("#hashtag autocompletion in composer", function (needs) {
relative_url: "/tag/notes",
ref: "notes",
type: "tag",
+ style_type: "icon",
},
{
id: 281,
@@ -45,6 +70,7 @@ acceptance("#hashtag autocompletion in composer", function (needs) {
relative_url: "/tag/photos",
ref: "photos",
type: "tag",
+ style_type: "icon",
},
],
});
@@ -56,11 +82,39 @@ acceptance("#hashtag autocompletion in composer", function (needs) {
await click("#topic-footer-buttons .btn.create");
await simulateKeys(".d-editor-input", "abc #o");
- assert.dom(".hashtag-autocomplete__option").exists({ count: 3 });
+ assert.dom(".hashtag-autocomplete__option").exists({ count: 5 });
assert
.dom(
'.hashtag-autocomplete__option .hashtag-autocomplete__text img.emoji[title="bug"]'
)
.exists();
});
+
+ test("iconHTML is correctly generated for various hashtag types and style_type configs", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("#topic-footer-buttons .btn.create");
+ await simulateKeys(".d-editor-input", "abc #o");
+
+ assert.dom(".hashtag-autocomplete__option").exists({ count: 5 });
+ assert
+ .dom(
+ ".hashtag-autocomplete__option .d-icon.d-icon-tag.hashtag-color--tag-300"
+ )
+ .exists();
+ assert
+ .dom(
+ ".hashtag-autocomplete__option .hashtag-category-square.hashtag-color--category-28"
+ )
+ .exists();
+ assert
+ .dom(
+ ".hashtag-autocomplete__option .hashtag-category-icon.hashtag-color--category-99 svg.svg-icon.d-icon-bell"
+ )
+ .exists();
+ assert
+ .dom(
+ ".hashtag-autocomplete__option .hashtag-category-emoji.hashtag-color--category-123 img.emoji[title='joy']"
+ )
+ .exists();
+ });
});
diff --git a/plugins/chat/spec/system/hashtag_autocomplete_spec.rb b/plugins/chat/spec/system/hashtag_autocomplete_spec.rb
index d30f0d30595..01ebb2f4591 100644
--- a/plugins/chat/spec/system/hashtag_autocomplete_spec.rb
+++ b/plugins/chat/spec/system/hashtag_autocomplete_spec.rb
@@ -167,4 +167,52 @@ describe "Using #hashtag autocompletion to search for and lookup channels", type
expect(find("#hashtag-css-generator", visible: false).text(:all)).not_to include(css_class)
end
end
+
+ describe "using channel hashtags in the topic composer" do
+ it "renders the selected channel hashtag correctly in the topic composer preview" do
+ topic_page.visit_topic_and_open_composer(topic)
+ expect(topic_page).to have_expanded_composer
+ topic_page.type_in_composer("something #rando")
+ expect(page).to have_css(
+ ".hashtag-autocomplete .hashtag-autocomplete__option .hashtag-autocomplete__link",
+ count: 1,
+ )
+ find(".d-icon-comment.hashtag-color--channel-#{channel2.id}").find(:xpath, "..").click
+ expect(topic_page.composer.preview).to have_css(
+ ".hashtag-cooked .d-icon-comment.hashtag-color--channel-#{channel2.id}",
+ )
+ end
+
+ it "renders the selected channel hashtag correctly in the topic rich composer" do
+ topic_page.visit_topic_and_open_composer(topic)
+ expect(topic_page).to have_expanded_composer
+ topic_page.composer.toggle_rich_editor
+ topic_page.type_in_composer("something #rando")
+ expect(page).to have_css(
+ ".hashtag-autocomplete .hashtag-autocomplete__option .hashtag-autocomplete__link",
+ count: 1,
+ )
+ find(".d-icon-comment.hashtag-color--channel-#{channel2.id}").find(:xpath, "..").click
+ expect(topic_page.composer.rich_editor).to have_css(
+ ".hashtag-cooked .d-icon-comment.hashtag-color--channel-#{channel2.id}",
+ )
+ expect(topic_page.composer.rich_editor).to have_css(
+ ".hashtag-cooked svg use[href=\"#comment\"]",
+ )
+ end
+
+ it "cooks the post with the channel hashtag on submit" do
+ topic_page.visit_topic_and_open_composer(topic)
+ expect(topic_page).to have_expanded_composer
+ topic_page.type_in_composer("something #random is what i am typing")
+ topic_page.send_reply
+
+ expect(topic_page).to have_post_number(2)
+ topic_page.within_post(2) do
+ expect(page).to have_css(
+ ".hashtag-cooked .d-icon-comment.hashtag-color--channel-#{channel2.id}",
+ )
+ end
+ end
+ end
end
diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rb
index 1adb82ef382..46368415f08 100644
--- a/spec/system/composer/prosemirror_editor_spec.rb
+++ b/spec/system/composer/prosemirror_editor_spec.rb
@@ -1548,6 +1548,59 @@ describe "Composer - ProseMirror editor", type: :system do
end
end
+ describe "with hashtags" do
+ fab!(:category_with_icon) { Fabricate(:category, icon: "bell", style_type: "icon") }
+ fab!(:catgeory_without_icon, :category)
+
+ it "correctly renders category with emoji hashtags after selecting from autocomplete" do
+ open_composer
+
+ composer.type_content("here is the ##{category_with_emoji.slug[0..1]}")
+ expect(composer).to have_hashtag_autocomplete
+
+ # the xpath here is to get the parent element, which is the actual hashtag-autocomplete__option
+ find(".hashtag-color--category-#{category_with_emoji.id}").find(:xpath, "..").click
+ expect(rich).to have_css(
+ ".hashtag-cooked .hashtag-category-emoji.hashtag-color--category-#{category_with_emoji.id} img.emoji[title='cat']",
+ )
+ end
+
+ it "correctly renders category with icon hashtags after selecting from autocomplete" do
+ open_composer
+
+ composer.type_content("here is the ##{category_with_icon.slug[0..1]}")
+ expect(composer).to have_hashtag_autocomplete
+
+ find(".hashtag-color--category-#{category_with_icon.id}").find(:xpath, "..").click
+ expect(rich).to have_css(
+ ".hashtag-cooked .hashtag-category-icon.hashtag-color--category-#{category_with_icon.id} svg.d-icon.d-icon-bell",
+ )
+ expect(rich).to have_css(".hashtag-cooked svg use[href='#bell']")
+ end
+
+ it "correctly renders category with square hashtags after selecting from autocomplete" do
+ open_composer
+
+ composer.type_content("here is the ##{catgeory_without_icon.slug[0..1]}")
+ expect(composer).to have_hashtag_autocomplete
+
+ find(".hashtag-color--category-#{catgeory_without_icon.id}").find(:xpath, "..").click
+ expect(rich).to have_css(
+ ".hashtag-cooked .hashtag-category-square.hashtag-color--category-#{catgeory_without_icon.id}",
+ )
+ end
+
+ it "correctly renders tag hashtags after selecting from autocomplete" do
+ open_composer
+
+ composer.type_content("##{tag.name[0..2]}")
+ expect(composer).to have_hashtag_autocomplete
+
+ find(".hashtag-color--tag-#{tag.id}").find(:xpath, "..").click
+ expect(rich).to have_css(".hashtag-cooked .d-icon.d-icon-tag.hashtag-color--tag-#{tag.id}")
+ end
+ end
+
describe "link toolbar" do
let(:upsert_hyperlink_modal) { PageObjects::Modals::UpsertHyperlink.new }
diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb
index 10ef4f651ec..e1d8452ab2b 100644
--- a/spec/system/page_objects/pages/topic.rb
+++ b/spec/system/page_objects/pages/topic.rb
@@ -196,6 +196,10 @@ module PageObjects
has_css?("#reply-control.open")
end
+ def composer
+ @composer_component
+ end
+
def type_in_composer(input)
@composer_component.type_content(input)
end
@@ -320,12 +324,12 @@ module PageObjects
find(".flag-topic").click
end
- private
-
def within_post(post)
within(post_by_number(post)) { yield }
end
+ private
+
def within_topic_footer_buttons
within("#topic-footer-buttons") { yield }
end