A platform for community discussion. Free, open, simple.
FEATURE: Add descriptions on hover for hashtag search results (#19162)
Martin Brennanc9ab270abd8e
diff --git a/app/assets/javascripts/discourse/app/templates/hashtag-autocomplete.hbr b/app/assets/javascripts/discourse/app/templates/hashtag-autocomplete.hbrindex 2b52969887c..3c5979d51d3 100644--- a/app/assets/javascripts/discourse/app/templates/hashtag-autocomplete.hbr+++ b/app/assets/javascripts/discourse/app/templates/hashtag-autocomplete.hbr@@ -2,7 +2,7 @@<ul>{{#each options as |option|}}<li class="hashtag-autocomplete__option">- <a class="hashtag-autocomplete__link" href>{{d-icon option.icon}}<span class="hashtag-autocomplete__text">{{option.text}}</span></a>+ <a class="hashtag-autocomplete__link" title="{{option.description}}" href>{{d-icon option.icon}}<span class="hashtag-autocomplete__text">{{option.text}}</span></a></li>{{/each}}</ul>diff --git a/app/services/category_hashtag_data_source.rb b/app/services/category_hashtag_data_source.rbindex 40c37ba4955..8869d7703b1 100644--- a/app/services/category_hashtag_data_source.rb+++ b/app/services/category_hashtag_data_source.rb@@ -9,11 +9,13 @@ class CategoryHashtagDataSourceenddef self.category_to_hashtag_item(guardian_categories, category)- category = Category.new(category.slice(:id, :slug, :name, :parent_category_id))+ category =+ Category.new(category.slice(:id, :slug, :name, :parent_category_id, :description))HashtagAutocompleteService::HashtagItem.new.tap do |item|item.text = category.nameitem.slug = category.slug+ item.description = category.description_textitem.icon = iconitem.relative_url = category.urldiff --git a/app/services/hashtag_autocomplete_service.rb b/app/services/hashtag_autocomplete_service.rbindex 838d5de4f19..3af74922c05 100644--- a/app/services/hashtag_autocomplete_service.rb+++ b/app/services/hashtag_autocomplete_service.rb@@ -46,6 +46,10 @@ class HashtagAutocompleteService# The text to display in the UI autocomplete menu for the item.attr_accessor :text+ # The description text to display in the UI autocomplete menu on hover.+ # This will be things like e.g. category description.+ attr_accessor :description+# Canonical slug for the item. Different from the ref, which can# have the type as a suffix to distinguish between conflicts.attr_accessor :slug@@ -69,6 +73,7 @@ class HashtagAutocompleteService{relative_url: self.relative_url,text: self.text,+ description: self.description,icon: self.icon,type: self.type,ref: self.ref,diff --git a/app/services/tag_hashtag_data_source.rb b/app/services/tag_hashtag_data_source.rbindex dde1ccbbdb4..33e95f020ce 100644--- a/app/services/tag_hashtag_data_source.rb+++ b/app/services/tag_hashtag_data_source.rb@@ -9,7 +9,9 @@ class TagHashtagDataSourceenddef self.tag_to_hashtag_item(tag, include_count: false)- tag = Tag.new(tag.slice(:id, :name).merge(topic_count: tag[:count])) if tag.is_a?(Hash)+ tag = Tag.new(tag.slice(:id, :name, :description).merge(topic_count: tag[:count])) if tag.is_a?(+ Hash,+ )HashtagAutocompleteService::HashtagItem.new.tap do |item|if include_count@@ -17,6 +19,7 @@ class TagHashtagDataSourceelseitem.text = tag.nameend+ item.description = tag.descriptionitem.slug = tag.nameitem.relative_url = tag.urlitem.icon = icondiff --git a/plugins/chat/lib/chat_channel_hashtag_data_source.rb b/plugins/chat/lib/chat_channel_hashtag_data_source.rbindex fac5d3bf2aa..8c824ac4b0f 100644--- a/plugins/chat/lib/chat_channel_hashtag_data_source.rb+++ b/plugins/chat/lib/chat_channel_hashtag_data_source.rb@@ -8,6 +8,7 @@ class Chat::ChatChannelHashtagDataSourcedef self.channel_to_hashtag_item(guardian, channel)HashtagAutocompleteService::HashtagItem.new.tap do |item|item.text = channel.title(guardian.user)+ item.description = channel.descriptionitem.slug = channel.slugitem.icon = iconitem.relative_url = channel.relative_urldiff --git a/plugins/chat/spec/lib/chat_channel_hashtag_data_source_spec.rb b/plugins/chat/spec/lib/chat_channel_hashtag_data_source_spec.rbindex b46157d00d7..b00948be7b0 100644--- a/plugins/chat/spec/lib/chat_channel_hashtag_data_source_spec.rb+++ b/plugins/chat/spec/lib/chat_channel_hashtag_data_source_spec.rb@@ -5,7 +5,7 @@ RSpec.describe Chat::ChatChannelHashtagDataSource dofab!(:category) { Fabricate(:category) }fab!(:group) { Fabricate(:group) }fab!(:private_category) { Fabricate(:private_category, group: group) }- fab!(:channel1) { Fabricate(:chat_channel, slug: "random", name: "Zany Things", chatable: category) }+ fab!(:channel1) { Fabricate(:chat_channel, slug: "random", name: "Zany Things", chatable: category, description: "Just weird stuff") }fab!(:channel2) doFabricate(:chat_channel, slug: "secret", name: "Secret Stuff", chatable: private_category)end@@ -20,6 +20,7 @@ RSpec.describe Chat::ChatChannelHashtagDataSource do{relative_url: channel1.relative_url,text: "Zany Things",+ description: "Just weird stuff",icon: "comment",type: "channel",ref: nil,@@ -38,6 +39,7 @@ RSpec.describe Chat::ChatChannelHashtagDataSource do{relative_url: channel2.relative_url,text: "Secret Stuff",+ description: nil,icon: "comment",type: "channel",ref: nil,@@ -60,6 +62,7 @@ RSpec.describe Chat::ChatChannelHashtagDataSource do{relative_url: channel1.relative_url,text: "Zany Things",+ description: "Just weird stuff",icon: "comment",type: "channel",ref: nil,@@ -74,6 +77,7 @@ RSpec.describe Chat::ChatChannelHashtagDataSource do{relative_url: channel1.relative_url,text: "Zany Things",+ description: "Just weird stuff",icon: "comment",type: "channel",ref: nil,@@ -88,6 +92,7 @@ RSpec.describe Chat::ChatChannelHashtagDataSource do{relative_url: channel1.relative_url,text: "Zany Things",+ description: "Just weird stuff",icon: "comment",type: "channel",ref: nil,@@ -105,6 +110,7 @@ RSpec.describe Chat::ChatChannelHashtagDataSource do{relative_url: channel2.relative_url,text: "Secret Stuff",+ description: nil,icon: "comment",type: "channel",ref: nil,diff --git a/spec/lib/pretty_text/helpers_spec.rb b/spec/lib/pretty_text/helpers_spec.rbindex ecb944b0654..34d478789f1 100644--- a/spec/lib/pretty_text/helpers_spec.rb+++ b/spec/lib/pretty_text/helpers_spec.rb@@ -48,9 +48,9 @@ RSpec.describe PrettyText::Helpers doenddescribe ".hashtag_lookup" do- fab!(:tag) { Fabricate(:tag, name: "somecooltag") }+ fab!(:tag) { Fabricate(:tag, name: "somecooltag", description: "Coolest things ever") }fab!(:category) do- Fabricate(:category, name: "Some Awesome Category", slug: "someawesomecategory")+ Fabricate(:category, name: "Some Awesome Category", slug: "someawesomecategory", description: "Really great stuff here")endfab!(:user) { Fabricate(:user) }@@ -59,6 +59,7 @@ RSpec.describe PrettyText::Helpers do{relative_url: tag.url,text: "somecooltag",+ description: "Coolest things ever",icon: "tag",slug: "somecooltag",ref: "somecooltag",@@ -69,6 +70,7 @@ RSpec.describe PrettyText::Helpers do{relative_url: category.url,text: "Some Awesome Category",+ description: "Really great stuff here",icon: "folder",slug: "someawesomecategory",ref: "someawesomecategory",@@ -84,6 +86,7 @@ RSpec.describe PrettyText::Helpers do{relative_url: category.url,text: "Some Awesome Category",+ description: "Really great stuff here",icon: "folder",slug: "someawesomecategory",ref: "someawesomecategory",@@ -97,6 +100,7 @@ RSpec.describe PrettyText::Helpers do{relative_url: tag.url,text: "somecooltag",+ description: "Coolest things ever",icon: "tag",slug: "somecooltag",ref: "somecooltag",@@ -107,6 +111,7 @@ RSpec.describe PrettyText::Helpers do{relative_url: category.url,text: "Some Awesome Category",+ description: "Really great stuff here",icon: "folder",slug: "someawesomecategory",ref: "someawesomecategory",@@ -125,6 +130,7 @@ RSpec.describe PrettyText::Helpers do{relative_url: private_category.url,text: "Manager Hideout",+ description: nil,icon: "folder",slug: "secretcategory",ref: "secretcategory",