From 08b8439e21d6bff762e6998f93eee2e39a1635f4 Mon Sep 17 00:00:00 2001 From: Kris Date: Mon, 10 Feb 2025 16:48:11 -0500 Subject: [PATCH] DEV: add transformer for default category view setting (#31264) This allows us to set custom values here, like "Voting" from the topic voting plugin: https://github.com/discourse/discourse-topic-voting/pull/232 --- .../app/components/edit-category-settings.js | 18 +++++++++++++++--- .../discourse/app/lib/transformer/registry.js | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/edit-category-settings.js b/app/assets/javascripts/discourse/app/components/edit-category-settings.js index d43f7c72491..93a541de08b 100644 --- a/app/assets/javascripts/discourse/app/components/edit-category-settings.js +++ b/app/assets/javascripts/discourse/app/components/edit-category-settings.js @@ -4,6 +4,7 @@ import { buildCategoryPanel } from "discourse/components/edit-category-panel"; import { setting } from "discourse/lib/computed"; import { SEARCH_PRIORITIES } from "discourse/lib/constants"; import discourseComputed from "discourse/lib/decorators"; +import { applyMutableValueTransformer } from "discourse/lib/transformer"; import { i18n } from "discourse-i18n"; const categorySortCriteria = []; @@ -49,12 +50,23 @@ export default class EditCategorySettings extends buildCategoryPanel( ]; } - @discourseComputed - availableViews() { - return [ + @discourseComputed("category.id", "category.custom_fields") + availableViews(categoryId, customFields) { + const views = [ { name: i18n("filters.latest.title"), value: "latest" }, { name: i18n("filters.top.title"), value: "top" }, ]; + + const context = { + categoryId, + customFields, + }; + + return applyMutableValueTransformer( + "category-available-views", + views, + context + ); } @discourseComputed diff --git a/app/assets/javascripts/discourse/app/lib/transformer/registry.js b/app/assets/javascripts/discourse/app/lib/transformer/registry.js index 1dd1e17a9ee..5195d8cf733 100644 --- a/app/assets/javascripts/discourse/app/lib/transformer/registry.js +++ b/app/assets/javascripts/discourse/app/lib/transformer/registry.js @@ -7,6 +7,7 @@ export const BEHAVIOR_TRANSFORMERS = Object.freeze([ export const VALUE_TRANSFORMERS = Object.freeze([ // use only lowercase names + "category-available-views", "category-description-text", "category-display-name", "composer-service-cannot-submit-post",