mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Move helper function to component
It's only used in the component so there is no need to keep it as an helper.
This commit is contained in:
@@ -1,20 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TagRuleFormComponent < ViewComponent::Base
|
||||
def initialize(rule:, rule_data:, index:, customer_tags: "",
|
||||
def initialize(rule:, index:, customer_tags: "",
|
||||
hidden_field_customer_tag_options: {})
|
||||
@rule = rule
|
||||
@rule_data = rule_data
|
||||
@index = index
|
||||
@customer_tags = customer_tags
|
||||
@hidden_field_customer_tag_options = hidden_field_customer_tag_options
|
||||
end
|
||||
|
||||
attr_reader :rule, :index, :rule_data, :customer_tags, :hidden_field_customer_tag_options
|
||||
attr_reader :rule, :index, :customer_tags, :hidden_field_customer_tag_options
|
||||
|
||||
private
|
||||
|
||||
def element_name(name)
|
||||
"enterprise[tag_rules_attributes][#{index}][#{name}]"
|
||||
end
|
||||
|
||||
def rule_data # rubocop:disable Metrics/MethodLength
|
||||
case rule.type
|
||||
when "TagRule::FilterShippingMethods"
|
||||
{
|
||||
text_top: t('components.tag_rule_form.tag_rules.shipping_method_tagged_top'),
|
||||
text_bottom: t('components.tag_rule_form.tag_rules.shipping_method_tagged_bottom'),
|
||||
taggable: "shipping_method",
|
||||
visibility_field: "shipping_methods",
|
||||
}
|
||||
when "TagRule::FilterPaymentMethods"
|
||||
{
|
||||
text_top: t('components.tag_rule_form.tag_rules.payment_method_tagged_top'),
|
||||
text_bottom: t('components.tag_rule_form.tag_rules.payment_method_tagged_bottom'),
|
||||
taggable: "payment_method",
|
||||
visibility_field: "payment_methods",
|
||||
}
|
||||
when "TagRule::FilterOrderCycles"
|
||||
{
|
||||
text_top: t('components.tag_rule_form.tag_rules.order_cycle_tagged_top'),
|
||||
text_bottom: t('components.tag_rule_form.tag_rules.order_cycle_tagged_bottom'),
|
||||
taggable: "exchange",
|
||||
visibility_field: "order_cycles",
|
||||
}
|
||||
when "TagRule::FilterProducts"
|
||||
{
|
||||
text_top: t('components.tag_rule_form.tag_rules.inventory_tagged_top'),
|
||||
text_bottom: t('components.tag_rule_form.tag_rules.inventory_tagged_bottom'),
|
||||
taggable: "variant",
|
||||
visibility_field: "variants",
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
- group[:rules].each do |rule|
|
||||
-rule_index += 1
|
||||
= render(TagRuleFormComponent.new(rule: rule,
|
||||
rule_data: helpers.rule_data(rule),
|
||||
index: rule_index,
|
||||
customer_tags: group[:tags],
|
||||
hidden_field_customer_tag_options: { "data-tag-rule-group-form-component--tag-rule-group-form-target": "ruleCustomerTag" }))
|
||||
|
||||
@@ -76,38 +76,6 @@ module Admin
|
||||
Enterprise::SELLS.map { |s| [I18n.t(s, scope:), s] }
|
||||
end
|
||||
|
||||
def rule_data(rule) # rubocop:disable Metrics/MethodLength
|
||||
case rule.type
|
||||
when "TagRule::FilterShippingMethods"
|
||||
{
|
||||
text_top: t('js.admin.tag_rules.shipping_method_tagged_top'),
|
||||
text_bottom: t('js.admin.tag_rules.shipping_method_tagged_bottom'),
|
||||
taggable: "shipping_method",
|
||||
visibility_field: "shipping_methods",
|
||||
}
|
||||
when "TagRule::FilterPaymentMethods"
|
||||
{
|
||||
text_top: t('js.admin.tag_rules.payment_method_tagged_top'),
|
||||
text_bottom: t('js.admin.tag_rules.payment_method_tagged_bottom'),
|
||||
taggable: "payment_method",
|
||||
visibility_field: "payment_methods",
|
||||
}
|
||||
when "TagRule::FilterOrderCycles"
|
||||
{
|
||||
text_top: t('js.admin.tag_rules.order_cycle_tagged_top'),
|
||||
text_bottom: t('js.admin.tag_rules.order_cycle_tagged_bottom'),
|
||||
taggable: "exchange",
|
||||
visibility_field: "order_cycles",
|
||||
}
|
||||
when "TagRule::FilterProducts"
|
||||
{
|
||||
text_top: t('js.admin.tag_rules.inventory_tagged_top'),
|
||||
text_bottom: t('js.admin.tag_rules.inventory_tagged_bottom'),
|
||||
taggable: "variant",
|
||||
visibility_field: "variants",
|
||||
}
|
||||
end
|
||||
|
||||
# Group tag rules per rule.preferred_customer_tags
|
||||
def tag_groups(tag_rules)
|
||||
tag_rules.each_with_object([]) do |tag_rule, tag_groups|
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
- else
|
||||
- default_rules.each_with_index do |default_rule, index|
|
||||
- current_rule_index = index + 1
|
||||
= render TagRuleFormComponent.new(rule: default_rule, rule_data: rule_data(default_rule), index: index)
|
||||
= render TagRuleFormComponent.new(rule: default_rule, index: index)
|
||||
%hr
|
||||
|
||||
.add_rule.text-center
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
- else
|
||||
= turbo_stream.append @div_id do
|
||||
= render(TagRuleFormComponent.new(rule: @default_rule,
|
||||
rule_data: rule_data(@default_rule),
|
||||
index: @index, customer_tags: @customer_tags,
|
||||
index: @index,
|
||||
customer_tags: @customer_tags,
|
||||
hidden_field_customer_tag_options: { "data-tag-rule-group-form-component--tag-rule-group-form-target": "ruleCustomerTag" }))
|
||||
= turbo_stream.remove_all ".no_rules"
|
||||
|
||||
@@ -3668,15 +3668,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
loading_variants: "Loading Variants"
|
||||
no_variants: "No variant available for this product (hidden via inventory settings)."
|
||||
some_variants_hidden: "(Some variants might be hidden via inventory settings)"
|
||||
tag_rules:
|
||||
shipping_method_tagged_top: "Shipping methods tagged"
|
||||
shipping_method_tagged_bottom: "are:"
|
||||
payment_method_tagged_top: "Payment methods tagged"
|
||||
payment_method_tagged_bottom: "are:"
|
||||
order_cycle_tagged_top: "Order Cycles tagged"
|
||||
order_cycle_tagged_bottom: "are:"
|
||||
inventory_tagged_top: "Inventory variants tagged"
|
||||
inventory_tagged_bottom: "are:"
|
||||
enterprise_fees:
|
||||
inherit_from_product: "Inherit From Product"
|
||||
orders:
|
||||
@@ -5072,6 +5063,16 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
previous: Previous
|
||||
tag_list_input:
|
||||
default_placeholder: Add a tag
|
||||
tag_rule_form:
|
||||
tag_rules:
|
||||
shipping_method_tagged_top: "Shipping methods tagged"
|
||||
shipping_method_tagged_bottom: "are:"
|
||||
payment_method_tagged_top: "Payment methods tagged"
|
||||
payment_method_tagged_bottom: "are:"
|
||||
order_cycle_tagged_top: "Order Cycles tagged"
|
||||
order_cycle_tagged_bottom: "are:"
|
||||
inventory_tagged_top: "Inventory variants tagged"
|
||||
inventory_tagged_bottom: "are:"
|
||||
tag_rule_group_form:
|
||||
for_customers_tagged: 'For customers tagged:'
|
||||
add_new_rule: '+ Add A New Rule'
|
||||
|
||||
Reference in New Issue
Block a user