From 8bd631fbb74e08549df2dce1b9e3a0d9054b55f8 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Wed, 27 Aug 2025 14:10:06 +1000 Subject: [PATCH] Clean up tag rule form component template Consolidate everything in one template and move visibility options to the component. --- app/components/tag_rule_form_component.rb | 15 +++++++++++---- .../tag_rule_form_component.html.haml | 9 +++++++-- app/controllers/admin/enterprises_controller.rb | 4 ---- app/controllers/admin/tag_rules_controller.rb | 4 +--- app/views/admin/tag_rules/_filter_input.html.haml | 8 -------- config/locales/en.yml | 5 ++--- 6 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 app/views/admin/tag_rules/_filter_input.html.haml diff --git a/app/components/tag_rule_form_component.rb b/app/components/tag_rule_form_component.rb index 2ec9b78da1..8771bd2a64 100644 --- a/app/components/tag_rule_form_component.rb +++ b/app/components/tag_rule_form_component.rb @@ -24,29 +24,36 @@ class TagRuleFormComponent < ViewComponent::Base 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", + visibility_field: "preferred_matched_shipping_methods_visibility", } 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", + visibility_field: "preferred_matched_payment_methods_visibility", } 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", + visibility_field: "preferred_matched_order_cycles_visibility", } 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", + visibility_field: "preferred_matched_variants_visibility", } end end + + def visibility_options + [ + [t('components.tag_rule_form.tag_rules.visible'), "visible"], + [t('components.tag_rule_form.tag_rules.not_visible'), "hidden"] + ] + end end diff --git a/app/components/tag_rule_form_component/tag_rule_form_component.html.haml b/app/components/tag_rule_form_component/tag_rule_form_component.html.haml index 1deec6be81..69638c5338 100644 --- a/app/components/tag_rule_form_component/tag_rule_form_component.html.haml +++ b/app/components/tag_rule_form_component/tag_rule_form_component.html.haml @@ -26,5 +26,10 @@ = rule_data[:text_bottom] %td %div - = render partial: "admin/tag_rules/filter_input" , locals: { rule: rule, index: index, field_name: rule_data[:visibility_field] } - + %div + - if rule.is_default + = hidden_field_tag "enterprise[tag_rules_attributes][#{index}][#{rule_data[:visibility_field]}]", "hidden" + %span.text-normal + = t(:not_visible) + - else + = select_tag "enterprise[tag_rules_attributes][#{index}][#{rule_data[:visibility_field]}]", options_for_select(visibility_options, rule.public_send(rule_data[:visibility_field].to_sym) ), { "data-controller": "tom-select", class: "primary no-search" } diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index e5351081a9..0d5740b212 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -50,10 +50,6 @@ module Admin @object.build_custom_tab if @object.custom_tab.nil? load_tag_rule_types - # TODO translation - @visibility_options = [ - [t('js.tag_rules.visible'), "visible"], [t('js.tag_rules.not_visible'), "hidden"] - ] return unless params[:stimulus] diff --git a/app/controllers/admin/tag_rules_controller.rb b/app/controllers/admin/tag_rules_controller.rb index 6764dd6c16..98cd9f34bd 100644 --- a/app/controllers/admin/tag_rules_controller.rb +++ b/app/controllers/admin/tag_rules_controller.rb @@ -9,9 +9,7 @@ module Admin @div_id = params[:div_id] is_default = params[:is_default] @customer_tags = params[:customer_tags] - # TODO translation - @visibility_options = [[t('js.tag_rules.visible'), "visible"], - [t('js.tag_rules.not_visible'), "hidden"]] + status = :ok if permitted_tag_rule_type.include?(params[:rule_type]) @default_rule = "TagRule::#{params[:rule_type]}".constantize.new(is_default:) diff --git a/app/views/admin/tag_rules/_filter_input.html.haml b/app/views/admin/tag_rules/_filter_input.html.haml deleted file mode 100644 index 4e7f2c73d8..0000000000 --- a/app/views/admin/tag_rules/_filter_input.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -%div - - visibility_field_name = "preferred_matched_#{field_name}_visibility" - - if rule.is_default - = hidden_field_tag "enterprise[tag_rules_attributes][#{index}][#{visibility_field_name}]", "hidden" - %span.text-normal - = t(:not_visible) - - else - = select_tag "enterprise[tag_rules_attributes][#{index}][#{visibility_field_name}]", options_for_select(@visibility_options, rule.public_send(visibility_field_name.to_sym) ), { "data-controller": "tom-select", class: "primary no-search" } diff --git a/config/locales/en.yml b/config/locales/en.yml index b462f300cb..6f42255ba1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3796,9 +3796,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using some_trouble: "I had some trouble saving: %{errors}" changing_on_hand_stock: Changing on hand stock levels... stock_reset: Stocks reset to defaults. - tag_rules: - visible: VISIBLE - not_visible: NOT VISIBLE services: unsaved_changes_message: Unsaved changes currently exist, save now or ignore? save: SAVE @@ -5073,6 +5070,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using order_cycle_tagged_bottom: "are:" inventory_tagged_top: "Inventory variants tagged" inventory_tagged_bottom: "are:" + visible: VISIBLE + not_visible: NOT VISIBLE tag_rule_group_form: for_customers_tagged: 'For customers tagged:' add_new_rule: '+ Add A New Rule'