DEV: Remove enable_experimental_hashtag_autocomplete logic (#22820)

This commit removes any logic in the app and in specs around
enable_experimental_hashtag_autocomplete and deletes some
old category hashtag code that is no longer necessary.

It also adds a `slug_ref` category instance method, which
will generate a reference like `parent:child` for a category,
with an optional depth, which hashtags use. Also refactors
PostRevisor which was using CategoryHashtagDataSource directly
which is a no-no.

Deletes the old hashtag markdown rule as well.
This commit is contained in:
Martin Brennan
2023-08-08 11:18:55 +10:00
committed by GitHub
parent 0c88bf341a
commit 09223e5ae7
43 changed files with 310 additions and 1001 deletions

View File

@ -400,18 +400,8 @@ en:
instructions: |-
Did you know that you can refer to categories and tags in your post? For example, have you seen the %{category} category?
Type `#` in the middle of a sentence and select any category or tag.
instructions_experimental: |-
Did you know that you can refer to categories and tags in your post? For example, have you seen the %{category} category?
Type `#` anywhere in a sentence and select any category or tag.
not_found: |-
Hmm, I don’t see a category in there anywhere. Note that `#` can't be the first character. Can you copy this in your next reply?
```text
I can create a category link via #
```
not_found_experimental: |-
Hmm, I don’t see a category in there anywhere. Can you copy this in your next reply?
```text

View File

@ -39,27 +39,11 @@ module DiscourseNarrativeBot
next_state: :tutorial_category_hashtag,
next_instructions:
Proc.new do
category = Category.secured(Guardian.new(@user)).last
slug = category.slug
if parent_category = category.parent_category
slug = "#{parent_category.slug}#{CategoryHashtag::SEPARATOR}#{slug}"
end
# TODO (martin) When enable_experimental_hashtag_autocomplete is the only option
# update the instructions and remove instructions_experimental, as well as the
# not_found translation
if SiteSetting.enable_experimental_hashtag_autocomplete
I18n.t(
"#{I18N_KEY}.category_hashtag.instructions_experimental",
i18n_post_args(category: "##{slug}"),
)
else
I18n.t(
"#{I18N_KEY}.category_hashtag.instructions",
i18n_post_args(category: "##{slug}"),
)
end
category = Category.secured(@user.guardian).last
I18n.t(
"#{I18N_KEY}.category_hashtag.instructions",
i18n_post_args(category: "##{category.slug_ref}"),
)
end,
recover: {
action: :reply_to_recover,
@ -298,9 +282,7 @@ module DiscourseNarrativeBot
topic_id = @post.topic_id
return unless valid_topic?(topic_id)
hashtag_css_class =
SiteSetting.enable_experimental_hashtag_autocomplete ? ".hashtag-cooked" : ".hashtag"
if Nokogiri::HTML5.fragment(@post.cooked).css(hashtag_css_class).size > 0
if Nokogiri::HTML5.fragment(@post.cooked).css(".hashtag-cooked").size > 0
raw = <<~MD
#{I18n.t("#{I18N_KEY}.category_hashtag.reply", i18n_post_args)}
@ -312,14 +294,7 @@ module DiscourseNarrativeBot
else
fake_delay
unless @data[:attempted]
if SiteSetting.enable_experimental_hashtag_autocomplete
reply_to(
@post,
I18n.t("#{I18N_KEY}.category_hashtag.not_found_experimental", i18n_post_args),
)
else
reply_to(@post, I18n.t("#{I18N_KEY}.category_hashtag.not_found", i18n_post_args))
end
reply_to(@post, I18n.t("#{I18N_KEY}.category_hashtag.not_found", i18n_post_args))
end
enqueue_timeout_job(@user)
false

View File

@ -377,9 +377,6 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
context "when reply contains the skip trigger" do
it "should create the right reply" do
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
parent_category = Fabricate(:category, name: "a")
_category = Fabricate(:category, parent_category: parent_category, name: "b")
@ -417,9 +414,6 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
context "when user recovers a post in the right topic" do
it "should create the right reply" do
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
parent_category = Fabricate(:category, name: "a")
_category = Fabricate(:category, parent_category: parent_category, name: "b")
post
@ -448,9 +442,6 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
topic_id: topic.id,
track: described_class.to_s,
)
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
end
context "when post is not in the right topic" do
@ -509,37 +500,15 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
narrative.input(:reply, user, post: post)
expected_raw = <<~RAW
#{I18n.t("discourse_narrative_bot.advanced_user_narrative.category_hashtag.reply", base_uri: "")}
#{I18n.t("discourse_narrative_bot.advanced_user_narrative.change_topic_notification_level.instructions", base_uri: "")}
RAW
expect(Post.last.raw).to eq(expected_raw.chomp)
expect(narrative.get_data(user)[:state].to_sym).to eq(
:tutorial_change_topic_notification_level,
)
end
context "when enable_experimental_hashtag_autocomplete is true" do
before { SiteSetting.enable_experimental_hashtag_autocomplete = true }
it "should create the right reply" do
category = Fabricate(:category)
post.update!(raw: "Check out this ##{category.slug}")
narrative.input(:reply, user, post: post)
expected_raw = <<~RAW
#{I18n.t("discourse_narrative_bot.advanced_user_narrative.category_hashtag.reply", base_uri: "")}
#{I18n.t("discourse_narrative_bot.advanced_user_narrative.change_topic_notification_level.instructions", base_uri: "")}
RAW
expect(Post.last.raw).to eq(expected_raw.chomp)
expect(narrative.get_data(user)[:state].to_sym).to eq(
:tutorial_change_topic_notification_level,
)
end
expect(Post.last.raw).to eq(expected_raw.chomp)
expect(narrative.get_data(user)[:state].to_sym).to eq(
:tutorial_change_topic_notification_level,
)
end
end