Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin] Include pagination in payment_methods/index component #5562

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
id: stimulus_id,
data: {
class: Spree::PaymentMethod,
rows: @payment_methods,
rows: @page.records,
prev: prev_page_path,
next: next_page_path,
url: ->(payment_method) { spree.edit_admin_payment_method_path(payment_method) },
columns: columns,
batch_actions: batch_actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
class SolidusAdmin::PaymentMethods::Index::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers

def initialize(payment_methods:)
@payment_methods = payment_methods
def initialize(page:)
@page = page
end

def title
Spree::PaymentMethod.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
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class PaymentMethodsController < SolidusAdmin::BaseController
search_scope(:admin, &:available_to_admin)

def index
@payment_methods = apply_search_to(
payment_methods = apply_search_to(
Spree::PaymentMethod.ordered_by_position,
param: :q,
)

set_page_and_extract_portion_from(payment_methods)

respond_to do |format|
format.html { render component('payment_methods/index').new(payment_methods: @payment_methods) }
format.html { render component('payment_methods/index').new(page: @page) }
end
end

Expand Down