mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Add new component to provide tag autocomplete for variant tag
It uses composition and inject the TagListInputComponent as a depency, which should be more flexible that creating a sub class. This new component could potentially be made more generic if needed
This commit is contained in:
24
app/components/variant_tag_list_input_component.rb
Normal file
24
app/components/variant_tag_list_input_component.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class VariantTagListInputComponent < ViewComponent::Base
|
||||
def initialize(name:, variant:, tag_list_input_component: TagListInputComponent,
|
||||
placeholder: I18n.t("components.tag_list_input.default_placeholder"),
|
||||
aria_label: nil)
|
||||
@tag_list_input_component = tag_list_input_component
|
||||
@variant = variant
|
||||
@name = name
|
||||
@tags = variant.tag_list
|
||||
@placeholder = placeholder
|
||||
@only_one = false
|
||||
@aria_label = aria_label
|
||||
end
|
||||
|
||||
attr_reader :tag_list_input_component, :variant, :name, :tags, :placeholder, :only_one,
|
||||
:aria_label
|
||||
|
||||
private
|
||||
|
||||
def autocomplete_url
|
||||
"/admin/tag_rules/variant_tag_rules?enterprise_id=#{variant.supplier_id}"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
%div{ "data-controller": "autocomplete", "data-autocomplete-url-value": autocomplete_url }
|
||||
= render tag_list_input_component.new(name: , tags: , placeholder: , aria_label: , only_one: , input_field_data_options: {"data-autocomplete-target": "input"}) do
|
||||
.autocomplete
|
||||
%ul.suggestion-list{ "data-autocomplete-target": "results" }
|
||||
@@ -80,7 +80,7 @@
|
||||
= error_message_on variant, :tax_category
|
||||
- if feature?(:variant_tag, spree_current_user)
|
||||
%td.col-tags.field.naked_inputs
|
||||
= render TagListInputComponent.new(name: f.field_name(:tag_list), tags: variant.tag_list, placeholder: t('.add_a_tag'), aria_label: t('admin.products_page.columns.tags'))
|
||||
= render VariantTagListInputComponent.new(name: f.field_name(:tag_list), variant:, placeholder: t('.add_a_tag'), aria_label: t('admin.products_page.columns.tags'))
|
||||
%td.col-inherits_properties.align-left
|
||||
-# empty
|
||||
%td.align-right
|
||||
|
||||
Reference in New Issue
Block a user