A platform for community discussion. Free, open, simple.
FIX: Pass filter category into topic-list-item transformer context (#39258)
Régis HANOL30864615cfbb
diff --git a/frontend/discourse/app/components/topic-list/item.gjs b/frontend/discourse/app/components/topic-list/item.gjsindex 5db05ed39c4..2e093f88a58 100644--- a/frontend/discourse/app/components/topic-list/item.gjs+++ b/frontend/discourse/app/components/topic-list/item.gjs@@ -67,6 +67,15 @@ export default class Item extends Component {});}+ get #transformerContext() {+ return {+ topic: this.args.topic,+ index: this.args.index,+ listContext: this.args.listContext,+ category: this.args.category,+ };+ }+get expandPinned() {let expandPinned;if (@@ -84,7 +93,7 @@ export default class Item extends Component {return applyValueTransformer("topic-list-item-expand-pinned",expandPinned,- { topic: this.args.topic, mobileView: this.useMobileLayout }+ { ...this.#transformerContext, mobileView: this.useMobileLayout });}@@ -236,24 +245,24 @@ export default class Item extends Component {return applyValueTransformer("topic-list-item-mobile-layout",this.site.mobileView,- { topic: this.args.topic, listContext: this.args.listContext }+ this.#transformerContext);}get additionalClasses() {- return applyValueTransformer("topic-list-item-class", [], {- topic: this.args.topic,- index: this.args.index,- listContext: this.args.listContext,- });+ return applyValueTransformer(+ "topic-list-item-class",+ [],+ this.#transformerContext+ );}get style() {- const parts = applyValueTransformer("topic-list-item-style", [], {- topic: this.args.topic,- index: this.args.index,- listContext: this.args.listContext,- });+ const parts = applyValueTransformer(+ "topic-list-item-style",+ [],+ this.#transformerContext+ );const safeParts = parts.filter(Boolean).filter((part) => {if (isHTMLSafe(part)) {diff --git a/frontend/discourse/app/components/topic-list/list.gjs b/frontend/discourse/app/components/topic-list/list.gjsindex 0bcff205d82..db173b9fc77 100644--- a/frontend/discourse/app/components/topic-list/list.gjs+++ b/frontend/discourse/app/components/topic-list/list.gjs@@ -244,6 +244,7 @@ export default class TopicList extends Component {@focusLastVisitedTopic={{@focusLastVisitedTopic}}@index={{index}}@listContext={{@listContext}}+ @category={{this.topicTrackingState.filterCategory}}/>{{#if (eq topic this.lastVisitedTopic)}}diff --git a/frontend/discourse/tests/integration/components/topic-list-item-test.gjs b/frontend/discourse/tests/integration/components/topic-list-item-test.gjsindex 66516434064..40f02f2ff7e 100644--- a/frontend/discourse/tests/integration/components/topic-list-item-test.gjs+++ b/frontend/discourse/tests/integration/components/topic-list-item-test.gjs@@ -61,6 +61,27 @@ module("Integration | Component | topic-list-item", function (hooks) {.doesNotHaveClass("bar");});+ test("topic-list-item-class transformer receives category context", async function (assert) {+ withPluginApi((api) => {+ api.registerValueTransformer(+ "topic-list-item-class",+ ({ value, context }) => {+ value.push(`cat-${context.category?.id ?? "none"}`);+ return value;+ }+ );+ });++ const store = this.owner.lookup("service:store");+ this.owner.lookup("service:topic-tracking-state").filterCategory =+ store.createRecord("category", { id: 42 });+ const topics = [store.createRecord("topic", { id: 2024 })];++ await render(<template><TopicList @topics={{topics}} /></template>);++ assert.dom(".topic-list-item[data-topic-id='2024']").hasClass("cat-42");+ });+test("shows unread-by-group-member indicator", async function (assert) {const store = this.owner.lookup("service:store");const topics = [