Skip to content

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

FIX: Incorrect title and chevron when filtering by post number. (#14985)

Alan Guo Xiang Tandb24c9b94e73
diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.js
index 3f3a0ceadc8..0e6a904509a 100644
--- a/app/assets/javascripts/discourse/app/widgets/post.js
+++ b/app/assets/javascripts/discourse/app/widgets/post.js
@@ -388,8 +388,20 @@ createWidget("post-group-request", {
createWidget("post-contents", {
buildKey: (attrs) => `post-contents-${attrs.id}`,
- defaultState() {
- return { expandedFirstPost: false, repliesBelow: [] };
+ defaultState(attrs) {
+ const defaultState = {
+ expandedFirstPost: false,
+ repliesBelow: [],
+ };
+
+ if (this.siteSettings.enable_filtered_replies_view) {
+ const topicController = this.register.lookup("controller:topic");
+
+ defaultState.filteredRepliesShown =
+ topicController.replies_to_post_number === attrs.post_number.toString();
+ }
+
+ return defaultState;
},
buildClasses(attrs) {
diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
index 525695f1745..cbe8c5c7393 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
@@ -546,3 +546,28 @@ acceptance("Topic last visit line", function (needs) {
);
});
});
+
+acceptance("Topic filter replies to post number", function (needs) {
+ needs.settings({
+ enable_filtered_replies_view: true,
+ });
+
+ test("visit topic", async function (assert) {
+ await visit("/t/-/280");
+
+ assert.equal(
+ query("#post_3 .show-replies").title,
+ I18n.t("post.filtered_replies_hint", { count: 3 }),
+ "it displays the right title for filtering by replies"
+ );
+
+ await visit("/");
+ await visit("/t/-/280?replies_to_post_number=3");
+
+ assert.equal(
+ query("#post_3 .show-replies").title,
+ I18n.t("post.view_all_posts"),
+ "it displays the right title when filtered by replies"
+ );
+ });
+});