Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Improve / simplify code for admin pages management (#13220)

Damian Legawiec1762c44d648b
diff --git a/admin/app/controllers/spree/admin/pages_controller.rb b/admin/app/controllers/spree/admin/pages_controller.rb
index 81db90a844..f1d2c91d51 100644
--- a/admin/app/controllers/spree/admin/pages_controller.rb
+++ b/admin/app/controllers/spree/admin/pages_controller.rb
@@ -28,15 +28,7 @@ module Spree
end
def collection
- return @collection if @collection.present?
-
- @collection = current_store.pages.custom
-
- params[:q] ||= {}
- params[:q][:s] ||= 'created_at desc'
-
- @search = @collection.ransack(params[:q])
- @collection = @search.result.page(params[:page]).per(params[:per_page])
+ super.custom.without_previews
end
def permitted_resource_params
diff --git a/admin/app/views/spree/admin/page_builder/_header.html.erb b/admin/app/views/spree/admin/page_builder/_header.html.erb
index afd55876d9..f1e92dac38 100644
--- a/admin/app/views/spree/admin/page_builder/_header.html.erb
+++ b/admin/app/views/spree/admin/page_builder/_header.html.erb
@@ -1,7 +1,8 @@
<header id="page-builder-header" class="fixed-top">
<nav class="navbar navbar-expand-lg">
<div data-controller="tooltip">
- <%= link_to spree.admin_themes_path, class: 'btn hover-gray px-2' do %>
+ <% back_url = @page.custom? ? spree.admin_pages_path : spree.admin_themes_path %>
+ <%= link_to back_url, class: 'btn hover-gray px-2' do %>
<%= icon('x', class: 'mr-0') %>
<% end %>
<%= tooltip(Spree.t('admin.back_to_dashboard')) %>
diff --git a/admin/app/views/spree/admin/pages/_table_header.html.erb b/admin/app/views/spree/admin/pages/_table_header.html.erb
index d3a16708c3..d34e8bbdd7 100644
--- a/admin/app/views/spree/admin/pages/_table_header.html.erb
+++ b/admin/app/views/spree/admin/pages/_table_header.html.erb
@@ -1,6 +1,6 @@
<tr>
- <th scope="col"><%= sort_link @search, :name, Spree.t(:name) %></th>
- <th scope="col"><%= sort_link @search, :created_at, Spree.t(:created_at) %></th>
- <th scope="col"><%= sort_link @search, :updated_at, Spree.t(:updated_at) %></th>
+ <th scope="col"><%= sort_link search_collection, :name, Spree.t(:name) %></th>
+ <th scope="col"><%= sort_link search_collection, :created_at, Spree.t(:created_at) %></th>
+ <th scope="col"><%= sort_link search_collection, :updated_at, Spree.t(:updated_at) %></th>
<th scope="col"></th>
</tr>
\ No newline at end of file