From c2c2a9503c7fe0966ec7942d8a830953174ed7ff Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 22 Sep 2025 15:29:36 +1000 Subject: [PATCH] Rename stimulus controller based on the new shorter naming --- .../add_tag_rule_modal_component.html.haml | 22 ++++++------- .../tag_rule_group_form_component.html.haml | 8 ++--- .../admin/tag_rules/new.turbo_stream.haml | 2 +- .../tag_list_input_controller_test.js | 33 ++++++++++--------- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/app/components/add_tag_rule_modal_component/add_tag_rule_modal_component.html.haml b/app/components/add_tag_rule_modal_component/add_tag_rule_modal_component.html.haml index 48600bd86d..80800abd99 100644 --- a/app/components/add_tag_rule_modal_component/add_tag_rule_modal_component.html.haml +++ b/app/components/add_tag_rule_modal_component/add_tag_rule_modal_component.html.haml @@ -6,26 +6,26 @@ %div{ id: @id, "data-controller": @data_controller, "data-action": @data_action, "data-modal-instant-value": @instant, **@options } .reveal-modal-bg.fade{ "data-modal-target": "background", "data-action": "click->modal#close" } .reveal-modal.fade.modal-component{ "data-modal-target": "modal", class: @modal_class } - #new-tag-rule-dialog{ "data-controller": "add-tag-rule-modal-component--add-tag-rule-modal", - "data-add-tag-rule-modal-component--add-tag-rule-modal-index-value": current_index } + #new-tag-rule-dialog{ "data-controller": "add-tag-rule-modal", + "data-add-tag-rule-modal-index-value": current_index } -# Ideally we would use event to communicate the update of customer tag, but we would need - -# the element with "data-controller": "add-tag-rule-modal-component--add-tag-rule-modal" - -# to be parent of the element with "data-controller": "tag-rule-group-form-component--tag-rule-group-form" - -# so it could respond to event generated by "tag-rule-group-form-component--tag-rule-group-form". + -# the element with "data-controller": "add-tag-rule-modal" + -# to be parent of the element with "data-controller": "tag-rule-group-form" + -# so it could respond to event generated by "tag-rule-group-form". -# Here we are in the opposite situation so we use a hidden field to store the value of - -# the customer tag, so it can be updated by "tag-rule-group-form-component--tag-rule-group-form" - = hidden_field_tag "customer_tag", customer_tag, { "data-add-tag-rule-modal-component--add-tag-rule-modal-target": "ruleCustomerTag" }.merge(hidden_field_customer_tag_options) + -# the customer tag, so it can be updated by "tag-rule-group-form" + = hidden_field_tag "customer_tag", customer_tag, { "data-add-tag-rule-modal-target": "ruleCustomerTag" }.merge(hidden_field_customer_tag_options) .text-normal.margin-bottom-30.text-center = t('components.add_tag_rule_modal.select_rule_type') .text-center.margin-bottom-30 - = select_tag :rule_type_selector, options_for_select(tag_rule_types), { "data-controller": "tom-select", "data-add-tag-rule-modal-component--add-tag-rule-modal-target": "rule", class: "primary no-search" } + = select_tag :rule_type_selector, options_for_select(tag_rule_types), { "data-controller": "tom-select", "data-add-tag-rule-modal-target": "rule", class: "primary no-search" } .text-center %input.button.red.icon-plus{ type: 'button', value: "#{t('components.add_tag_rule_modal.add_rule')}", - "data-action": "click->add-tag-rule-modal-component--add-tag-rule-modal#add click->modal#close", - "data-add-tag-rule-modal-component--add-tag-rule-modal-div-id-param": div_id, - "data-add-tag-rule-modal-component--add-tag-rule-modal-is-default-param": "#{is_default}"} + "data-action": "click->add-tag-rule-modal#add click->modal#close", + "data-add-tag-rule-modal-div-id-param": div_id, + "data-add-tag-rule-modal-is-default-param": "#{is_default}"} - if close_button? .text-center diff --git a/app/components/tag_rule_group_form_component/tag_rule_group_form_component.html.haml b/app/components/tag_rule_group_form_component/tag_rule_group_form_component.html.haml index 1a6afd9b9c..d8908f5ee2 100644 --- a/app/components/tag_rule_group_form_component/tag_rule_group_form_component.html.haml +++ b/app/components/tag_rule_group_form_component/tag_rule_group_form_component.html.haml @@ -1,4 +1,4 @@ -%div{ id: form_id, "data-controller": "tag-rule-group-form-component--tag-rule-group-form"} +%div{ id: form_id, "data-controller": "tag-rule-group-form" } - rule_index = customer_rule_index .customer_tag .header @@ -14,7 +14,7 @@ = render(TagListInputComponent.new(name: tag_list_input_name, tags: group[:tags], only_one: true, - hidden_field_data_options: { "data-action": "input->tag-rule-group-form-component--tag-rule-group-form#updatePreferredCustomerTag", "data-tag-rule-group-form-component--tag-rule-group-form-target": "customerTag" })) + hidden_field_data_options: { "data-action": "input->tag-rule-group-form#updatePreferredCustomerTag", "data-tag-rule-group-form-target": "customerTag" })) %div{ id: customer_tag_rule_div_id } - if group[:rules].empty? .no_rules @@ -25,7 +25,7 @@ = render(TagRuleFormComponent.new(rule: 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" })) + hidden_field_customer_tag_options: { "data-tag-rule-group-form-target": "ruleCustomerTag" })) %hr .add_rule.text-center @@ -36,4 +36,4 @@ current_index: (rule_index + 1), div_id: customer_tag_rule_div_id, customer_tag: group[:tags], - hidden_field_customer_tag_options: { "data-tag-rule-group-form-component--tag-rule-group-form-target": "ruleCustomerTag" }) + hidden_field_customer_tag_options: { "data-tag-rule-group-form-target": "ruleCustomerTag" }) diff --git a/app/views/admin/tag_rules/new.turbo_stream.haml b/app/views/admin/tag_rules/new.turbo_stream.haml index 2190634063..594ffc5fc8 100644 --- a/app/views/admin/tag_rules/new.turbo_stream.haml +++ b/app/views/admin/tag_rules/new.turbo_stream.haml @@ -6,5 +6,5 @@ = render(TagRuleFormComponent.new(rule: @default_rule, index: @index, customer_tags: @customer_tags, - hidden_field_customer_tag_options: { "data-tag-rule-group-form-component--tag-rule-group-form-target": "ruleCustomerTag" })) + hidden_field_customer_tag_options: { "data-tag-rule-group-form-target": "ruleCustomerTag" })) = turbo_stream.remove_all ".no_rules" diff --git a/spec/javascripts/stimulus/tag_list_input_controller_test.js b/spec/javascripts/stimulus/tag_list_input_controller_test.js index 6408a9ada2..1f72bcf22c 100644 --- a/spec/javascripts/stimulus/tag_list_input_controller_test.js +++ b/spec/javascripts/stimulus/tag_list_input_controller_test.js @@ -69,7 +69,8 @@ describe("TagListInputController", () => { id="variant_add_tag" placeholder="Add a tag" data-action="keydown.enter->tag-list-input#addTag keyup->tag-list-input#filterInput" data-tag-list-input-target="newTag" - > + style="display: block;" + > `; @@ -144,25 +145,25 @@ describe("TagListInputController", () => { // Tag input with non existing tag document.body.innerHTML = `
-
    -