diff --git a/admin/app/components/solidus_admin/taxonomies/index/component.html.erb b/admin/app/components/solidus_admin/taxonomies/index/component.html.erb new file mode 100644 index 00000000000..26c1addd8f2 --- /dev/null +++ b/admin/app/components/solidus_admin/taxonomies/index/component.html.erb @@ -0,0 +1,28 @@ +<%= page do %> + <%= page_header do %> + <%= page_header_title title %> + <%= page_header_actions do %> + <%= render component("ui/button").new( + tag: :a, + text: t('.create_taxonomy'), + href: spree.new_admin_taxonomy_path, + icon: "add-line", + ) %> + <% end %> + <% end %> + + <%= render component('ui/table').new( + id: 'taxonomies-list', + data: { + class: Spree::Taxonomy, + rows: @taxonomies, + url: ->(taxonomy) { spree.edit_admin_taxonomy_path(taxonomy) }, + columns: columns, + batch_actions: batch_actions, + }, + sortable: { + url: ->(taxonomy) { solidus_admin.move_taxonomy_path(taxonomy) }, + param: 'position', + }, + ) %> +<% end %> diff --git a/admin/app/components/solidus_admin/taxonomies/index/component.rb b/admin/app/components/solidus_admin/taxonomies/index/component.rb new file mode 100644 index 00000000000..d7ce3c48f75 --- /dev/null +++ b/admin/app/components/solidus_admin/taxonomies/index/component.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class SolidusAdmin::Taxonomies::Index::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(taxonomies:) + @taxonomies = taxonomies + end + + def title + Spree::Taxonomy.model_name.human.pluralize + end + + def columns + [ + name_column, + ] + end + + def name_column + { + header: :name, + data: ->(taxonomy) do + content_tag :div, taxonomy.name + end + } + end + + def batch_actions + [ + { + display_name: t('.batch_actions.delete'), + action: solidus_admin.taxonomies_path, + method: :delete, + icon: 'delete-bin-7-line', + }, + ] + end +end diff --git a/admin/app/components/solidus_admin/taxonomies/index/component.yml b/admin/app/components/solidus_admin/taxonomies/index/component.yml new file mode 100644 index 00000000000..80341dbf5b5 --- /dev/null +++ b/admin/app/components/solidus_admin/taxonomies/index/component.yml @@ -0,0 +1,4 @@ +en: + batch_actions: + delete: 'Delete' + create_taxonomy: Create Taxonomy diff --git a/admin/app/controllers/solidus_admin/taxonomies_controller.rb b/admin/app/controllers/solidus_admin/taxonomies_controller.rb index dfa82f8e993..c3e87055158 100644 --- a/admin/app/controllers/solidus_admin/taxonomies_controller.rb +++ b/admin/app/controllers/solidus_admin/taxonomies_controller.rb @@ -4,6 +4,14 @@ module SolidusAdmin class TaxonomiesController < SolidusAdmin::BaseController before_action :load_taxonomy, only: [:move] + def index + @taxonomies = Spree::Taxonomy.all + + respond_to do |format| + format.html { render component('taxonomies/index').new(taxonomies: @taxonomies) } + end + end + def move @taxonomy.insert_at(params[:position].to_i) diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 115f4ecd86b..0b29994fb2c 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -43,7 +43,7 @@ end end - resources :taxonomies do + resources :taxonomies, only: [:index] do collection do delete :destroy end diff --git a/admin/spec/features/taxonomies_spec.rb b/admin/spec/features/taxonomies_spec.rb new file mode 100644 index 00000000000..88cb0ec782a --- /dev/null +++ b/admin/spec/features/taxonomies_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Taxonomies", :js, type: :feature do + before { sign_in create(:admin_user, email: 'admin@example.com') } + + it "lists taxonomies and allows deleting them" do + create(:taxonomy, name: "Categories") + create(:taxonomy, name: "Brand") + + visit "/admin/taxonomies" + expect(page).to have_content("Categories") + expect(page).to have_content("Brand") + + expect(page).to be_axe_clean + + select_row("Categories") + click_on "Delete" + expect(page).to have_content("Taxonomies were successfully removed.") + expect(page).not_to have_content("Categories") + expect(Spree::Taxonomy.count).to eq(1) + end +end