-
-
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
store credit reasons
index page with dedicated actions
- Loading branch information
1 parent
bbb692c
commit a3ce980
Showing
8 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
admin/app/components/solidus_admin/store_credit_reasons/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 @@ | ||
<%= render component('refunds_and_returns').new(current_class: Spree::StoreCreditReason) do |layout| %> | ||
<% layout.with_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.add'), | ||
href: spree.new_admin_store_credit_reason_path, | ||
icon: "add-line", | ||
class: "align-self-end w-full", | ||
) %> | ||
<% end %> | ||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: Spree::StoreCreditReason, | ||
rows: @page.records, | ||
url: ->(store_credit_reason) { spree.edit_admin_store_credit_reason_path(store_credit_reason) }, | ||
prev: prev_page_path, | ||
next: next_page_path, | ||
columns: columns, | ||
batch_actions: batch_actions, | ||
}, | ||
search: { | ||
name: :q, | ||
value: params[:q], | ||
url: solidus_admin.store_credit_reasons_path, | ||
searchbar_key: :name_cont, | ||
filters: filters, | ||
scopes: scopes, | ||
}, | ||
) %> | ||
<% end %> |
52 changes: 52 additions & 0 deletions
52
admin/app/components/solidus_admin/store_credit_reasons/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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::StoreCreditReasons::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(page:) | ||
@page = page | ||
end | ||
|
||
def title | ||
Spree::StoreCreditReason.model_name.human.pluralize | ||
end | ||
|
||
def prev_page_path | ||
solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? | ||
end | ||
|
||
def next_page_path | ||
solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? | ||
end | ||
|
||
def batch_actions | ||
[ | ||
{ | ||
display_name: t('.batch_actions.delete'), | ||
action: solidus_admin.store_credit_reasons_path, | ||
method: :delete, | ||
icon: 'delete-bin-7-line', | ||
}, | ||
] | ||
end | ||
|
||
def filters | ||
[] | ||
end | ||
|
||
def scopes | ||
[] | ||
end | ||
|
||
def columns | ||
[ | ||
:name, | ||
{ | ||
header: :active, | ||
data: ->(store_credit_reason) do | ||
store_credit_reason.active? ? component('ui/badge').yes : component('ui/badge').no | ||
end | ||
}, | ||
] | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/store_credit_reasons/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: | ||
add: 'Add new' | ||
batch_actions: | ||
delete: 'Delete' |
40 changes: 40 additions & 0 deletions
40
admin/app/controllers/solidus_admin/store_credit_reasons_controller.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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin | ||
class StoreCreditReasonsController < SolidusAdmin::BaseController | ||
include SolidusAdmin::ControllerHelpers::Search | ||
|
||
def index | ||
store_credit_reasons = apply_search_to( | ||
Spree::StoreCreditReason.order(id: :desc), | ||
param: :q, | ||
) | ||
|
||
set_page_and_extract_portion_from(store_credit_reasons) | ||
|
||
respond_to do |format| | ||
format.html { render component('store_credit_reasons/index').new(page: @page) } | ||
end | ||
end | ||
|
||
def destroy | ||
@store_credit_reason = Spree::StoreCreditReason.find_by!(id: params[:id]) | ||
|
||
Spree::StoreCreditReason.transaction { @store_credit_reason.destroy } | ||
|
||
flash[:notice] = t('.success') | ||
redirect_back_or_to store_credit_reasons_path, status: :see_other | ||
end | ||
|
||
private | ||
|
||
def load_store_credit_reason | ||
@store_credit_reason = Spree::StoreCreditReason.find_by!(id: params[:id]) | ||
authorize! action_name, @store_credit_reason | ||
end | ||
|
||
def store_credit_reason_params | ||
params.require(:store_credit_reason).permit(:store_credit_reason_id, permitted_store_credit_reason_attributes) | ||
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: | ||
store_credit_reasons: | ||
title: "Store Credit Reasons" | ||
destroy: | ||
success: "Store Credit Reasons 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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe "Store Credit Reasons", :js, type: :feature do | ||
before { sign_in create(:admin_user, email: '[email protected]') } | ||
|
||
it "lists Store Credit Reasons and allows deleting them" do | ||
create(:store_credit_reason, name: "Default-store-credit-reason") | ||
|
||
visit "/admin/store_credit_reasons" | ||
expect(page).to have_content("Default-store-credit-reason") | ||
expect(page).to be_axe_clean | ||
|
||
select_row("Default-store-credit-reason") | ||
click_on "Delete" | ||
expect(page).to have_content("Store Credit Reasons were successfully removed.") | ||
expect(page).not_to have_content("Default-store-credit-reason") | ||
expect(Spree::StoreCreditReason.count).to eq(0) | ||
expect(page).to be_axe_clean | ||
end | ||
end |