-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
taxonomies/index
component with dedicated index action
- Loading branch information
1 parent
f48bc8d
commit 7c5c272
Showing
6 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
admin/app/components/solidus_admin/taxonomies/index/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div class="px-4"> | ||
<header class="py-6 flex items-center"> | ||
<h1 class="body-title"> | ||
<%= title %> | ||
</h1> | ||
|
||
<div class="ml-auto flex gap-2 items-center"> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.create_taxonomy'), | ||
href: spree.new_admin_taxonomy_path, | ||
icon: "add-line", | ||
) %> | ||
</div> | ||
</header> | ||
|
||
<%= 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', | ||
}, | ||
) %> | ||
</div> |
37 changes: 37 additions & 0 deletions
37
admin/app/components/solidus_admin/taxonomies/index/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Taxonomies::Index::Component < SolidusAdmin::BaseComponent | ||
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 |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/taxonomies/index/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
en: | ||
batch_actions: | ||
delete: 'Delete' | ||
create_taxonomy: Create Taxonomy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe "Taxonomies", :js, type: :feature do | ||
before { sign_in create(:admin_user, email: '[email protected]') } | ||
|
||
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 |