From c2e54104d012208724ff8494348abc9f52f2a3f6 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 20 Feb 2025 10:56:53 +1100 Subject: [PATCH] Add select/deselect all checkbox There's A Controller For That. (But I think it makes the HTML ugly..) --- app/views/admin/dfc_product_imports/index.html.haml | 9 +++++++-- config/locales/en.yml | 1 + spec/system/admin/dfc_product_import_spec.rb | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/views/admin/dfc_product_imports/index.html.haml b/app/views/admin/dfc_product_imports/index.html.haml index f647ab75c4..b3b38cbe69 100644 --- a/app/views/admin/dfc_product_imports/index.html.haml +++ b/app/views/admin/dfc_product_imports/index.html.haml @@ -12,13 +12,18 @@ = form.hidden_field :enterprise_id, value: @enterprise.id = form.hidden_field :catalog_json, value: @catalog_json - %table + %table{"data-controller": "checked" } + %thead + %tr + %th + %input{ type: 'checkbox', title: t('.select_all'), 'aria-label': t('.select_all'), data: { "checked-target": "all", action: "change->checked#toggleAll" } } + %th %tbody - @items.each do |supplied_product, existing_product| %tr{id: supplied_product.semanticId } %td %label - = form.check_box 'semanticIds[]', { checked: true }, supplied_product.semanticId, "" + = form.check_box 'semanticIds[]', { checked: true, data: { "action" => "change->checked#toggleCheckbox", "checked-target" => "checkbox" } }, supplied_product.semanticId, "" = supplied_product.name %td - if existing_product.present? diff --git a/config/locales/en.yml b/config/locales/en.yml index 70b26fc6e6..0a739cb660 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -851,6 +851,7 @@ en: title: "DFC product catalog" catalog_url: "%{count} products to be imported from: %{catalog_url}" enterprise: "Import to enterprise: %{enterprise_name}" + select_all: "Select/deselect all" update: Update new: New import: Import diff --git a/spec/system/admin/dfc_product_import_spec.rb b/spec/system/admin/dfc_product_import_spec.rb index 8f4d3f2487..860013ff58 100644 --- a/spec/system/admin/dfc_product_import_spec.rb +++ b/spec/system/admin/dfc_product_import_spec.rb @@ -65,7 +65,13 @@ RSpec.describe "DFC Product Import" do expect(page).to have_content "Beans - Case, 12 x 400g (can) New" expect(page).to have_content "Chia Seed, Organic - Retail pack, 300g" - uncheck "Chia Seed, Organic - Case, 8 x 300g" # don't import this one + # I can select all + uncheck "Chia Seed, Organic - Case, 8 x 300g" + check "Select/deselect all" + expect(page).to have_checked_field "Chia Seed, Organic - Case, 8 x 300g" + + # And deselect one + uncheck "Chia Seed, Organic - Case, 8 x 300g" expect { click_button "Import"