mirror of
https://github.com/discourse/discourse.git
synced 2025-02-05 19:11:13 +00:00
Why this change? This is a follow-up to 86b2e3aa3e8be30a308f1bff3664d76c5d56057a. Basically, we want to allow people to select more than 1 category as well. What does this change do? 1. Change `type: category` to `type: categories` and support `min` and `max` validations for `type: categories`. 2. Fix the `<SchemaThemeSetting::Types::Categories>` component to support the `min` and `max` validations and switch it to use the `<CategorySelector>` component instead of the `<CategoryChooser>` component which only supports selecting one category.
28 lines
736 B
Ruby
28 lines
736 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ThemeObjectsSettingMetadataSerializer < ApplicationSerializer
|
|
attributes :categories, :property_descriptions
|
|
|
|
def categories
|
|
object
|
|
.categories(scope)
|
|
.reduce({}) do |acc, category|
|
|
acc[category.id] = BasicCategorySerializer.new(category, scope: scope, root: false).as_json
|
|
acc
|
|
end
|
|
end
|
|
|
|
def property_descriptions
|
|
locales = {}
|
|
key = "theme_metadata.settings.#{object.name}.schema.properties."
|
|
|
|
object.theme.internal_translations.each do |internal_translation|
|
|
if internal_translation.key.start_with?(key)
|
|
locales[internal_translation.key.delete_prefix(key)] = internal_translation.value
|
|
end
|
|
end
|
|
|
|
locales
|
|
end
|
|
end
|