Comment on page

Admin Panel

Starting with Spree 4.7, we've introduced a new way of customizing the admin panel, that enables extensions to modify the admin panel UI without depending on the Deface gem. For Spree 4.6 and earlier, please see how to use Deface overrides.

Customizing the main menu

When extending Spree with custom features, it's common to add new options to the menu on the left-hand side.
Additionally, there are two builder classes Spree::Admin::MainMenu::SectionBuilder and Spree::Admin::MainMenu::ItemBuilder that make it easier to build more complex sections.
The menu is available under Rails.application.config.spree_backend.main_menu and can be modified by both extensions as well as the Rails application code.

Example: adding an additional section to the admin panel:

Rails.application.config.after_initialize do
Rails.application.config.spree_backend.main_menu.add('subscriptions', 'inbox-fill.svg').
with_items('active', Spree::Core::Engine.routes.url_helpers.admin_active_subsciptions_path).build,'expired', Spree::Core::Engine.routes.url_helpers.admin_expired_subsciptions_path).build
For a more extensive example, take a look at how the default menu is built.

Customizing tabs

In some cases you may need to add a new tab to a page for editing Orders, Products or Users.
Product Tabs
These tabs are built with Spree::Admin::Tabs::Tab. You can also use Spree::Admin::Tabs::TabBuilder class to construct new Tab objects. The tabs are attached to Rails.application.config.spree_backend.tabs and can be modified via an initializer.

Example: adding an additional tab to the product edit admin page

Rails.application.config.after_initialize do
Rails.application.config.spree_backend.tabs[:product].add('discounts', ->(resource) { admin_product_discounts_path(product) }).

Customizing actions

A common case for extensions is to add a new action button in the admin panel.
Action buttons are built with Spree::Admin::Actions::Action or with a dedicated Spree::Admin::Actions::ActionBuilder class. The action buttons are attached to Rails.application.config.spree_backend.actions and can be modified with an initializer.
Example: adding a new button to the order page
Rails.application.config.after_initialize do
Rails.application.config.spree_backend.actions[:order].add('generate_export', admin_export_orders_path).

Customizing existing views and partials

If you need a more extensive customization of any of the admin panel pages, you can just copy their .erb file from the spree_backend gem to your app/views/ directory and modify it there. This allows you to fully override default views provided by the spree_backend gem.
Note: This approach is not recommended for Spree extensions, as it may conflict with other extensions that modify the same view.