From 87a80d3efe7ddf90d03698254fc000c0a489e12d Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 11 Mar 2025 16:18:22 +1100 Subject: [PATCH] Add Tags collumn Currently display the list of tags, no fancy UI. Updating works --- app/services/permitted_attributes/variant.rb | 2 +- app/views/admin/products_v3/_product_row.html.haml | 3 +++ .../admin/products_v3/_product_variant_row.html.haml | 3 ++- app/views/admin/products_v3/_table.html.haml | 7 ++++++- app/views/admin/products_v3/_variant_row.html.haml | 3 +++ .../controllers/column_preferences_controller.js | 1 + app/webpacker/css/admin/products_v3.scss | 2 +- config/locales/en.yml | 1 + lib/open_food_network/column_preference_defaults.rb | 10 ++++++++-- 9 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/services/permitted_attributes/variant.rb b/app/services/permitted_attributes/variant.rb index e333eded25..a538092699 100644 --- a/app/services/permitted_attributes/variant.rb +++ b/app/services/permitted_attributes/variant.rb @@ -8,7 +8,7 @@ module PermittedAttributes :shipping_category_id, :price, :unit_value, :unit_description, :variant_unit, :variant_unit_name, :variant_unit_scale, :display_name, :display_as, :tax_category_id, :weight, :height, :width, :depth, :taxon_ids, - :primary_taxon_id, :supplier_id + :primary_taxon_id, :supplier_id, :variant_tag_list ] end end diff --git a/app/views/admin/products_v3/_product_row.html.haml b/app/views/admin/products_v3/_product_row.html.haml index 707a7192ba..980b9980d8 100644 --- a/app/views/admin/products_v3/_product_row.html.haml +++ b/app/views/admin/products_v3/_product_row.html.haml @@ -18,6 +18,9 @@ %td.col-category.align-left -# empty %td.col-tax_category.align-left +- if feature?(:variant_tag, spree_current_user) + %td.col-tags.align-left + -# empty %td.col-inherits_properties.align-left .content= product.inherits_properties ? 'YES' : 'NO' #TODO: consider using https://github.com/RST-J/human_attribute_values, else use I18n.t (also below) %td.align-right diff --git a/app/views/admin/products_v3/_product_variant_row.html.haml b/app/views/admin/products_v3/_product_variant_row.html.haml index 12b6702cba..f5144fe7d7 100644 --- a/app/views/admin/products_v3/_product_variant_row.html.haml +++ b/app/views/admin/products_v3/_product_variant_row.html.haml @@ -19,7 +19,8 @@ %tr{ 'data-nested-form-target': "target" } %tr.condensed %td - %td{ colspan: 11 } + - colspan = feature?(:variant_tag, spree_current_user) ? 12 : 11 + %td{ colspan: "#{colspan}" } %button.secondary.condensed.naked.icon-plus{ 'data-action': "nested-form#add", 'aria-label': t('.new_variant') } =t('.new_variant') diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index 5f30291408..5226461c94 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -26,11 +26,14 @@ %col.col-producer{ style:"min-width: 6em" }= # (grow to fill) %col.col-category{ width:"8%" } %col.col-tax_category{ width:"8%" } + - if feature?(:variant_tag, spree_current_user) + %col.col-tags{ width:"8%" } %col.col-inherits_properties{ width:"5%" } %col{ width:"5%", style:"min-width: 3em"}= # Actions %thead %tr - %td.form-actions-wrapper{ colspan: 12 } + - colspan = feature?(:variant_tag, spree_current_user) ? 13 : 12 + %td.form-actions-wrapper{ colspan: "#{colspan}" } .form-actions-wrapper2 %fieldset.form-actions{ class: ("hidden" unless defined?(@error_counts)), 'data-bulk-form-target': "actions" } .container @@ -60,6 +63,8 @@ %th.align-left.col-producer= t('admin.products_page.columns.producer') %th.align-left.col-category= t('admin.products_page.columns.category') %th.align-left.col-tax_category= t('admin.products_page.columns.tax_category') + - if feature?(:variant_tag, spree_current_user) + %th.align-left.col-tags= t('admin.products_page.columns.tags') %th.align-left.col-inherits_properties= t('admin.products_page.columns.inherits_properties') %th.align-right= t('admin.products_page.columns.actions') - products.each_with_index do |product, product_index| diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index d87763e42f..e347cb1d07 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -74,6 +74,9 @@ aria_label: t('.tax_category_field_name'), placeholder_value: t('.search_for_tax_categories'))) = error_message_on variant, :tax_category +- if feature?(:variant_tag, spree_current_user) + %td.col-tags.field.naked_inputs + = f.text_field :variant_tag_list, 'aria-label': t('admin.products_page.columns.tags'), value: variant.variant_tag_list.join(",") %td.col-inherits_properties.align-left -# empty %td.align-right diff --git a/app/webpacker/controllers/column_preferences_controller.js b/app/webpacker/controllers/column_preferences_controller.js index 65202920f4..1d314fc4be 100644 --- a/app/webpacker/controllers/column_preferences_controller.js +++ b/app/webpacker/controllers/column_preferences_controller.js @@ -29,6 +29,7 @@ export default class ColumnPreferencesController extends Controller { const element = e.target || e; const name = element.dataset.columnName; + // Css defined in app/webpacker/css/admin/products_v3.scss this.table.classList.toggle(`hide-${name}`, !element.checked); // Reset cell colspans diff --git a/app/webpacker/css/admin/products_v3.scss b/app/webpacker/css/admin/products_v3.scss index bb144cd6e8..4dd6331775 100644 --- a/app/webpacker/css/admin/products_v3.scss +++ b/app/webpacker/css/admin/products_v3.scss @@ -186,7 +186,7 @@ // Hide columns $columns: "image", "name", "sku", "unit_scale", "unit", "price", "on_hand", "producer", "category", - "tax_category", "inherits_properties"; + "tax_category", "tags", "inherits_properties"; @each $col in $columns { &.hide-#{$col} { .col-#{$col} { diff --git a/config/locales/en.yml b/config/locales/en.yml index 7945ba1a25..9b735dca1d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -636,6 +636,7 @@ en: inherits_properties: "Inherits Properties?" import_date: "Import Date" actions: Actions + tags: Tags columns_selector: unit: Unit price: Price diff --git a/lib/open_food_network/column_preference_defaults.rb b/lib/open_food_network/column_preference_defaults.rb index 9da9ef36e9..9eca6be307 100644 --- a/lib/open_food_network/column_preference_defaults.rb +++ b/lib/open_food_network/column_preference_defaults.rb @@ -81,7 +81,7 @@ module OpenFoodNetwork producer_visibility = display_producer_column?(user) I18n.with_options scope: 'admin.products_page.columns' do - { + columns = { image: { name: t(:image), visible: true }, name: { name: t(:name), visible: true }, sku: { name: t(:sku), visible: true }, @@ -92,8 +92,14 @@ module OpenFoodNetwork producer: { name: t(:producer), visible: producer_visibility }, category: { name: t(:category), visible: true }, tax_category: { name: t(:tax_category), visible: true }, - inherits_properties: { name: t(:inherits_properties), visible: true }, } + if OpenFoodNetwork::FeatureToggle.enabled?(:variant_tag, user) + columns[:tags] = { name: t(:tags), visible: true } + end + + columns[:inherits_properties] = { name: t(:inherits_properties), visible: true } + + columns end end