Move logic from key definition to views

Before this change, two important things depend on the format of each key,
where to render it in the administration panel and which kind of interface
to use for each setting. Following this strategy led us to a very complex
code, very difficult to maintain or modify. So, we do not want to depend
on the setting key structure anymore to decide how or where to render each
setting.

With this commit, we get rid of the key format-based rules. Now we render
each setting explicitly passing to it the type and the tab where it belongs.
This commit is contained in:
Senén Rodero Rodríguez
2023-12-07 17:06:42 +01:00
committed by Javi Martín
parent 91c3bde36b
commit f8835debae
19 changed files with 157 additions and 150 deletions

View File

@@ -1,11 +1,9 @@
class Admin::Settings::TableComponent < ApplicationComponent
attr_reader :settings, :setting_name, :tab
delegate :dom_id, to: :helpers
attr_reader :setting_name, :table_class
def initialize(settings:, setting_name:, tab: nil)
@settings = settings
def initialize(setting_name:, table_class: "mixed-settings-table")
@setting_name = setting_name
@tab = tab
@table_class = table_class
end
def key_header
@@ -25,12 +23,4 @@ class Admin::Settings::TableComponent < ApplicationComponent
t("admin.settings.setting_value")
end
end
def table_class
if settings.all?(&:feature?)
"featured-settings-table"
else
"mixed-settings-table"
end
end
end