Skip to content

Commit

Permalink
Include pagination in payment_methods/index component table
Browse files Browse the repository at this point in the history
  • Loading branch information
rainerdema committed Dec 21, 2023
1 parent f1c4920 commit 4290d31
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
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

0 comments on commit 4290d31

Please sign in to comment.