FIX: add "in:first" to user summary category search (#28688)

* FIX: add "in:first" to user summary category search

The "in:first" parameter was added to the search parameters for the topic count in the user summary category search.

This ensures that the search results focus specifically on the first posts in each topic, so only topics are returned.
Meta topic: https://meta.discourse.org/t/summary-page-by-category-topic-links/215848

* add tests

Provided by @natsw
This commit is contained in:
moin-Jana 2024-09-10 07:55:32 +02:00 committed by GitHub
parent 0332be0b34
commit cd7aa53521
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 2 deletions

View File

@ -6,6 +6,10 @@ import discourseComputed from "discourse-common/utils/decorators";
export default class UserSummaryCategorySearch extends Component {
@discourseComputed("user", "category")
searchParams() {
return `@${this.get("user.username")} #${this.get("category.slug")}`;
let query = `@${this.get("user.username")} #${this.get("category.slug")}`;
if (this.searchOnlyFirstPosts) {
query += " in:first";
}
return query;
}
}

View File

@ -291,6 +291,7 @@
<UserSummaryCategorySearch
@user={{this.user}}
@category={{category}}
@searchOnlyFirstPosts={{true}}
@count={{category.topic_count}}
/>
</td>
@ -298,6 +299,7 @@
<UserSummaryCategorySearch
@user={{this.user}}
@category={{category}}
@searchOnlyFirstPosts={{false}}
@count={{category.post_count}}
/>
</td>

View File

@ -1,4 +1,4 @@
import { click, visit } from "@ember/test-helpers";
import { click, currentURL, visit } from "@ember/test-helpers";
import { test } from "qunit";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
import {
@ -29,6 +29,21 @@ acceptance("User Profile - Summary", function (needs) {
"top categories"
);
});
test("Top Categories Search", async function (assert) {
await visit("/u/eviltrout/summary");
await click(".top-categories-section .reply-count a");
assert.strictEqual(currentURL(), "/search?q=%40eviltrout%20%23bug");
await visit("/u/eviltrout/summary");
await click(".top-categories-section .topic-count a");
assert.strictEqual(
currentURL(),
"/search?q=%40eviltrout%20%23bug%20in%3Afirst"
);
});
});
acceptance("User Profile - Summary - User Status", function (needs) {