-
-
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.
[wip] Add
stores/index
component with dedicated actions
- Loading branch information
1 parent
946a49e
commit 9f4b6f7
Showing
7 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
admin/app/components/solidus_admin/stores/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,32 @@ | ||
<%= page do %> | ||
<%= page_header do %> | ||
<%= page_header_title title %> | ||
<%= page_header_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.add'), | ||
href: spree.new_admin_store_path, | ||
icon: "add-line", | ||
) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: Spree::Store, | ||
rows: @stores, | ||
url: ->(store) { spree.edit_admin_store_path(store) }, | ||
columns: columns, | ||
batch_actions: batch_actions, | ||
}, | ||
search: { | ||
name: :q, | ||
value: params[:q], | ||
url: solidus_admin.stores_path, | ||
searchbar_key: nil, | ||
filters: filters, | ||
scopes: scopes, | ||
}, | ||
) %> | ||
<% end %> |
36 changes: 36 additions & 0 deletions
36
admin/app/components/solidus_admin/stores/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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Stores::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(stores:) | ||
@stores = stores | ||
end | ||
|
||
def title | ||
Spree::Store.model_name.human.pluralize | ||
end | ||
|
||
def batch_actions | ||
[ | ||
{ | ||
display_name: t('.batch_actions.delete'), | ||
action: solidus_admin.stores_path, | ||
method: :delete, | ||
icon: 'delete-bin-7-line', | ||
}, | ||
] | ||
end | ||
|
||
def filters | ||
[] | ||
end | ||
|
||
def scopes | ||
[] | ||
end | ||
|
||
def columns | ||
[] | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
admin/app/components/solidus_admin/stores/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,2 @@ | ||
en: | ||
add: 'Add new' |
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin | ||
class StoresController < SolidusAdmin::BaseController | ||
include SolidusAdmin::ControllerHelpers::Search | ||
|
||
def index | ||
stores = apply_search_to( | ||
Spree::Store.order(created_at: :desc, id: :desc), | ||
param: :q, | ||
) | ||
|
||
respond_to do |format| | ||
format.html { render component('stores/index').new(stores: @stores) } | ||
end | ||
end | ||
|
||
def destroy | ||
@stores = Spree::Store.where(id: params[:id]) | ||
|
||
Spree::Store.transaction { @stores.destroy_all } | ||
|
||
flash[:notice] = t('.success') | ||
redirect_back_or_to stores_path, status: :see_other | ||
end | ||
end | ||
end |
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,6 @@ | ||
en: | ||
solidus_admin: | ||
stors: | ||
title: "Stores" | ||
destroy: | ||
success: "Stores were successfully removed." |
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe "Stores", :js, type: :feature do | ||
before { sign_in create(:admin_user, email: '[email protected]') } | ||
|
||
it "lists stores and allows deleting them" do | ||
visit "/admin/stores" | ||
expect(page).to be_axe_clean | ||
end | ||
end |