Skip to content
Open
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
8 changes: 8 additions & 0 deletions admin/app/controllers/solidus_admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@

private

def set_page_and_extract_portion_from(records, per_page: self.per_page, **options)
super(records, per_page:, **options)

Check failure on line 29 in admin/app/controllers/solidus_admin/base_controller.rb

View workflow job for this annotation

GitHub Actions / Check Ruby

Style/SuperArguments: Call `super` without arguments and parentheses when the signature is identical.
end

def per_page
SolidusAdmin::Config.per_page
end

def set_layout
if turbo_frame_request?
"turbo_rails/frame"
Expand Down
5 changes: 0 additions & 5 deletions admin/app/controllers/solidus_admin/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

module SolidusAdmin
class ResourcesController < SolidusAdmin::BaseController
DEFAULT_PER_PAGE = 20

Check failure on line 5 in admin/app/controllers/solidus_admin/resources_controller.rb

View workflow job for this annotation

GitHub Actions / Check Ruby

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body beginning.
include SolidusAdmin::ControllerHelpers::Search

helper_method :search_filter_params
Expand Down Expand Up @@ -88,10 +87,6 @@
{id: :desc}
end

def per_page
DEFAULT_PER_PAGE
end

def resources_collection
resource_class.all
end
Expand Down
19 changes: 19 additions & 0 deletions admin/docs/index_pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ def index
# ...
```

By default, `set_page_and_extract_portion_from` uses the global `SolidusAdmin::Config.per_page` setting (default: 20).

You can configure the global per page count in an initializer:

```ruby
SolidusAdmin::Config.per_page = 50
```

Alternatively, you can customize the per page count for a specific controller by overriding the `per_page` method or passing `per_page:` explicitly:

```ruby
class SolidusAdmin::UsersController < SolidusAdmin::BaseController
# ...
def per_page
10
end
end
Comment on lines +43 to +48
```

Finally, the index action should render the `index` component passing the `@page` instance variable as the `collection` prop.

```ruby
Expand Down
5 changes: 5 additions & 0 deletions admin/lib/solidus_admin/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Configuration < Spree::Preferences::Configuration
# Default: false
preference :enable_alpha_features, :boolean, default: false

# @!attribute [rw] per_page
# @return [Integer] Default number of resources shown per page on admin index pages.
# Default: 20
preference :per_page, :integer, default: 20

alias_method :enable_alpha_features?, :enable_alpha_features

preference :storefront_product_path_proc, :proc, default: ->(_version) {
Expand Down
16 changes: 16 additions & 0 deletions admin/spec/controllers/solidus_admin/base_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,20 @@ def index
end
end
end

describe "#per_page" do
it "returns SolidusAdmin::Config.per_page" do
allow(SolidusAdmin::Config).to receive(:per_page).and_return(35)
expect(controller.send(:per_page)).to eq(35)
end
end

describe "#set_page_and_extract_portion_from" do
it "passes per_page to geared_pagination" do
records = Spree::Order.all
allow(SolidusAdmin::Config).to receive(:per_page).and_return(15)
controller.send(:set_page_and_extract_portion_from, records)
expect(controller.instance_variable_get(:@page).recordset.ratios.fixed).to eq(15)
end
end
end
13 changes: 13 additions & 0 deletions admin/spec/solidus_admin/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@
end
end

describe "#per_page" do
it "defaults to 20" do
config = described_class.new
expect(config.per_page).to eq(20)
end

it "can be configured" do
config = described_class.new
config.per_page = 50
expect(config.per_page).to eq(50)
end
end

describe "#import_menu_items_from_backend!" do
it "imports the menu items from the backend" do
allow(Spree::Backend::Config).to receive(:menu_items).and_return([
Expand Down
Loading