DEV: Change category type to categories type for theme object schema (#26339)

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.
This commit is contained in:
Alan Guo Xiang Tan
2024-03-27 10:54:30 +08:00
committed by GitHub
parent 0df50a7e5d
commit 476d91d233
19 changed files with 387 additions and 100 deletions

View File

@ -16,4 +16,21 @@ class ThemeSettingsManager::Objects < ThemeSettingsManager
def schema
@opts[:schema]
end
def categories(guardian)
category_ids = Set.new
value.each do |theme_setting_object|
category_ids.merge(
ThemeSettingsObjectValidator.new(
schema:,
object: theme_setting_object,
).property_values_of_type("categories"),
)
end
return [] if category_ids.empty?
Category.secured(guardian).where(id: category_ids)
end
end