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
This commit is contained in:
Kris 2025-02-10 16:48:11 -05:00 committed by GitHub
parent 088ac0331e
commit 08b8439e21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import { buildCategoryPanel } from "discourse/components/edit-category-panel";
import { setting } from "discourse/lib/computed"; import { setting } from "discourse/lib/computed";
import { SEARCH_PRIORITIES } from "discourse/lib/constants"; import { SEARCH_PRIORITIES } from "discourse/lib/constants";
import discourseComputed from "discourse/lib/decorators"; import discourseComputed from "discourse/lib/decorators";
import { applyMutableValueTransformer } from "discourse/lib/transformer";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
const categorySortCriteria = []; const categorySortCriteria = [];
@ -49,12 +50,23 @@ export default class EditCategorySettings extends buildCategoryPanel(
]; ];
} }
@discourseComputed @discourseComputed("category.id", "category.custom_fields")
availableViews() { availableViews(categoryId, customFields) {
return [ const views = [
{ name: i18n("filters.latest.title"), value: "latest" }, { name: i18n("filters.latest.title"), value: "latest" },
{ name: i18n("filters.top.title"), value: "top" }, { name: i18n("filters.top.title"), value: "top" },
]; ];
const context = {
categoryId,
customFields,
};
return applyMutableValueTransformer(
"category-available-views",
views,
context
);
} }
@discourseComputed @discourseComputed

View File

@ -7,6 +7,7 @@ export const BEHAVIOR_TRANSFORMERS = Object.freeze([
export const VALUE_TRANSFORMERS = Object.freeze([ export const VALUE_TRANSFORMERS = Object.freeze([
// use only lowercase names // use only lowercase names
"category-available-views",
"category-description-text", "category-description-text",
"category-display-name", "category-display-name",
"composer-service-cannot-submit-post", "composer-service-cannot-submit-post",