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.

Rename RecordList to just Table

Damian Legawiec63e46a365144
diff --git a/admin/app/controllers/concerns/spree/admin/record_list_concern.rb b/admin/app/controllers/concerns/spree/admin/record_list_concern.rb
deleted file mode 100644
index 95864ade6a..0000000000
--- a/admin/app/controllers/concerns/spree/admin/record_list_concern.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-module Spree
- module Admin
- module RecordListConcern
- extend ActiveSupport::Concern
-
- included do
- class_attribute :_record_list_key, instance_writer: false
- end
-
- class_methods do
- # Override the record list key for this controller
- # By default, the key is derived from controller_name (e.g., ProductsController -> :products)
- # @param key [Symbol] the record list key (e.g., :products)
- def use_record_list(key)
- self._record_list_key = key
- end
- end
-
- # Get the record list key for this controller
- # Uses explicitly set key or derives from controller_name
- # @return [Symbol]
- def record_list_key
- _record_list_key || controller_name.to_sym
- end
-
- # Get the record list for this controller
- # @return [Spree::Admin::RecordList, nil]
- def record_list
- @record_list ||= Spree.admin.record_lists.get(record_list_key)
- end
-
- # Apply custom sort scopes if the record list has them configured
- # Should be called after ransack result is obtained
- # @param collection [ActiveRecord::Relation] the collection to sort
- # @return [ActiveRecord::Relation] sorted collection
- def apply_record_list_sort(collection)
- return collection unless record_list
-
- sort_param = params.dig(:q, :s)
- column = record_list.find_custom_sort_column(sort_param)
-
- return collection unless column
-
- # Remove sort from ransack params since we'll apply it manually
- record_list.apply_custom_sort(collection.reorder(nil), sort_param)
- end
-
- # Check if current sort uses a custom scope
- # @return [Boolean]
- def custom_sort_active?
- return false unless record_list
-
- sort_param = params.dig(:q, :s)
- record_list.find_custom_sort_column(sort_param).present?
- end
- end
- end
-end
diff --git a/admin/app/controllers/concerns/spree/admin/table_concern.rb b/admin/app/controllers/concerns/spree/admin/table_concern.rb
new file mode 100644
index 0000000000..a913a5155d
--- /dev/null
+++ b/admin/app/controllers/concerns/spree/admin/table_concern.rb
@@ -0,0 +1,82 @@
+module Spree
+ module Admin
+ module TableConcern
+ extend ActiveSupport::Concern
+
+ included do
+ class_attribute :_table_key, instance_writer: false
+ end
+
+ class_methods do
+ # Override the table key for this controller
+ # By default, the key is derived from controller_name (e.g., ProductsController -> :products)
+ # @param key [Symbol] the table key (e.g., :products)
+ def use_table(key)
+ self._table_key = key
+ end
+ end
+
+ # Get the table key for this controller
+ # Uses explicitly set key or derives from controller_name
+ # @return [Symbol]
+ def table_key
+ _table_key || controller_name.to_sym
+ end
+
+ # Get the table for this controller
+ # @return [Spree::Admin::Table, nil]
+ def table
+ @table ||= Spree.admin.tables.get(table_key)
+ end
+
+ # Check if a table is registered for this controller
+ # @return [Boolean]
+ def table_registered?
+ Spree.admin.tables.registered?(table_key)
+ end
+
+ # Apply custom sort scopes if the table has them configured
+ # Should be called after ransack result is obtained
+ # @param collection [ActiveRecord::Relation] the collection to sort
+ # @return [ActiveRecord::Relation] sorted collection
+ def apply_table_sort(collection)
+ return collection unless table
+ return collection unless params[:q].respond_to?(:dig)
+
+ sort_param = params.dig(:q, :s)
+ column = table.find_custom_sort_column(sort_param)
+
+ return collection unless column
+
+ # Remove sort from ransack params since we'll apply it manually
+ table.apply_custom_sort(collection.reorder(nil), sort_param)
+ end
+
+ # Check if current sort uses a custom scope
+ # @return [Boolean]
+ def custom_sort_active?
+ return false unless table
+ return false unless params[:q].respond_to?(:dig)
+
+ sort_param = params.dig(:q, :s)
+ table.find_custom_sort_column(sort_param).present?
+ end
+
+ # Process query_state parameter from table query builder
+ # and merge it into params[:q] for ransack
+ # @return [void]
+ def process_table_query_state
+ return unless params[:query_state].present?
+
+ query_builder = Spree::Admin::Table::QueryBuilder.new(table)
+ query_builder.load_from_json(params[:query_state])
+
+ ransack_params = query_builder.to_ransack_params
+ return if ransack_params.blank?
+
+ params[:q] ||= {}
+ params[:q].merge!(ransack_params)
+ end
+ end
+ end
+end
diff --git a/admin/app/controllers/spree/admin/products_controller.rb b/admin/app/controllers/spree/admin/products_controller.rb
index 751709c784..5a96beaf73 100644
--- a/admin/app/controllers/spree/admin/products_controller.rb
+++ b/admin/app/controllers/spree/admin/products_controller.rb
@@ -281,7 +281,7 @@ module Spree
per(params[:per_page] || Spree::Admin::RuntimeConfig.admin_products_per_page)
# Apply custom sort scope if configured (e.g., for price sorting)
- @collection = apply_record_list_sort(@collection) if custom_sort
+ @collection = apply_table_sort(@collection) if custom_sort
@collection
end
diff --git a/admin/app/controllers/spree/admin/resource_controller.rb b/admin/app/controllers/spree/admin/resource_controller.rb
index 12a2df4fc5..2b17103250 100644
--- a/admin/app/controllers/spree/admin/resource_controller.rb
+++ b/admin/app/controllers/spree/admin/resource_controller.rb
@@ -1,6 +1,6 @@
class Spree::Admin::ResourceController < Spree::Admin::BaseController
include Spree::Admin::Callbacks
- include Spree::Admin::RecordListConcern
+ include Spree::Admin::TableConcern
helper_method :new_object_url, :edit_object_url, :object_url, :collection_url, :model_class
before_action :load_resource
diff --git a/admin/app/controllers/spree/admin/record_list_columns_controller.rb b/admin/app/controllers/spree/admin/table_columns_controller.rb
similarity index 55%
rename from admin/app/controllers/spree/admin/record_list_columns_controller.rb
rename to admin/app/controllers/spree/admin/table_columns_controller.rb
index 5120bb9db6..d47021ce09 100644
--- a/admin/app/controllers/spree/admin/record_list_columns_controller.rb
+++ b/admin/app/controllers/spree/admin/table_columns_controller.rb
@@ -1,20 +1,20 @@
module Spree
module Admin
- class RecordListColumnsController < Spree::Admin::BaseController
- # POST /admin/record_list_columns
- # Updates the selected columns for a record list in the session
+ class TableColumnsController < Spree::Admin::BaseController
+ # POST /admin/table_columns
+ # Updates the selected columns for a table in the session
def update
- list_key = params[:list_key]
+ table_key = params[:table_key]
columns = params[:columns]
- if list_key.present?
+ if table_key.present?
if columns.present?
# Filter to only include valid column keys
column_keys = Array(columns).map(&:to_sym)
- session["record_list_columns_#{list_key}"] = column_keys.join(',')
+ session["table_columns_#{table_key}"] = column_keys.join(',')
else
# Clear selection to use defaults
- session.delete("record_list_columns_#{list_key}")
+ session.delete("table_columns_#{table_key}")
end
end
diff --git a/admin/app/helpers/spree/admin/record_list_helper.rb b/admin/app/helpers/spree/admin/table_helper.rb
similarity index 80%
rename from admin/app/helpers/spree/admin/record_list_helper.rb
rename to admin/app/helpers/spree/admin/table_helper.rb
index 825f1cd0e7..f0523438b9 100644
--- a/admin/app/helpers/spree/admin/record_list_helper.rb
+++ b/admin/app/helpers/spree/admin/table_helper.rb
@@ -1,49 +1,50 @@
module Spree
module Admin
- module RecordListHelper
- # Main helper to render a record list
+ module TableHelper
+ # Main helper to render a table
# @param collection [ActiveRecord::Relation] the collection to render
- # @param list_key [Symbol] the record list registry key (e.g., :products)
+ # @param table_key [Symbol] the table registry key (e.g., :products)
# @param options [Hash] additional options
# @option options [Boolean] :bulk_operations enable bulk operations
# @option options [Boolean] :sortable enable drag-and-drop sorting
# @option options [String] :frame_name custom turbo frame name
+ # @option options [Class] :export_type export class (e.g., Spree::Exports::Customers)
# @return [String] rendered HTML
- def render_record_list(collection, list_key, **options)
- record_list = Spree.admin.record_lists.get(list_key)
- selected_columns = session_selected_columns(list_key)
+ def render_table(collection, table_key, **options)
+ table = Spree.admin.tables.get(table_key)
+ selected_columns = session_selected_columns(table_key)
- render 'spree/admin/record_lists/record_list',
+ render 'spree/admin/tables/table',
collection: collection,
- record_list: record_list,
- list_key: list_key,
+ table: table,
+ table_key: table_key,
selected_columns: selected_columns,
**options
end
# Get selected column keys from session
- # @param list_key [Symbol] record list key
+ # @param table_key [Symbol] table key
# @return [Array<Symbol>, nil]
- def session_selected_columns(list_key)
- keys = session["record_list_columns_#{list_key}"]
+ def session_selected_columns(table_key)
+ keys = session["table_columns_#{table_key}"]
return nil if keys.blank?
keys.split(',').map(&:to_sym)
end
# Save selected columns to session
- # @param list_key [Symbol] record list key
+ # @param table_key [Symbol] table key
# @param column_keys [Array<Symbol>] selected column keys
- def save_selected_columns(list_key, column_keys)
- session["record_list_columns_#{list_key}"] = column_keys.join(',')
+ def save_selected_columns(table_key, column_keys)
+ session["table_columns_#{table_key}"] = column_keys.join(',')
end
# Render a single column value based on its type
# @param record [Object] the record
- # @param column [Spree::Admin::RecordList::Column] the column definition
- # @param record_list [Spree::Admin::RecordList] the record list
+ # @param column [Spree::Admin::Table::Column] the column definition
+ # @param table [Spree::Admin::Table] the table
# @return [String] rendered HTML
- def render_column_value(record, column, record_list)
+ def render_column_value(record, column, table)
value = column.resolve_value(record, self)
case column.type
@@ -62,7 +63,9 @@ module Spree
when :image
render_image_column(record, value, column)
when :custom
- render partial: column.partial, locals: { record: record, column: column, value: value }
+ extra_locals = column.partial_locals.is_a?(Proc) ? column.partial_locals.call(record) : column.partial_locals
+ locals = { record: record, column: column, value: value }.merge(extra_locals)
+ render partial: column.partial, locals: locals
when :association
render_association_column(value, column)
else
@@ -72,7 +75,7 @@ module Spree
# Render currency column
# @param value [Object] the value
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_currency_column(value, column)
return content_tag(:span, '-', class: 'text-gray-400') if value.blank?
@@ -86,7 +89,7 @@ module Spree
# Render date column
# @param value [Object] the value
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_date_column(value, column)
return content_tag(:span, '-', class: 'text-gray-400') if value.blank?
@@ -100,7 +103,7 @@ module Spree
# Render datetime column
# @param value [Object] the value
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_datetime_column(value, column)
return content_tag(:span, '-', class: 'text-gray-400') if value.blank?
@@ -114,7 +117,7 @@ module Spree
# Render status column as badge
# @param value [Object] the value
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_status_column(value, column)
return content_tag(:span, '-', class: 'text-gray-400') if value.blank?
@@ -135,7 +138,7 @@ module Spree
# Render boolean column
# @param value [Object] the value
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_boolean_column(value, column)
active_badge(value)
@@ -144,7 +147,7 @@ module Spree
# Render link column
# @param record [Object] the record
# @param value [Object] the value
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_link_column(record, value, column)
return content_tag(:span, '-', class: 'text-gray-400') if value.blank?
@@ -155,7 +158,7 @@ module Spree
# Render image column
# @param record [Object] the record
# @param value [Object] the value
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_image_column(record, value, column)
return content_tag(:span, '-', class: 'text-gray-400') if value.blank?
@@ -171,7 +174,7 @@ module Spree
# Render string column
# @param value [Object] the value
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_string_column(value, column)
return content_tag(:span, '-', class: 'text-gray-400') if value.blank?
@@ -185,7 +188,7 @@ module Spree
# Render association column (e.g., taxons, tags)
# @param value [Object] the value (expected to be a string from method lambda)
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def render_association_column(value, column)
return content_tag(:span, '-', class: 'text-gray-400') if value.blank?
@@ -194,11 +197,11 @@ module Spree
end
# Render sort dropdown for sortable columns
- # @param record_list [Spree::Admin::RecordList] the record list
+ # @param table [Spree::Admin::Table] the table
# @param current_sort [String, nil] current sort value (e.g., "name asc")
# @return [String]
- def record_list_sort_dropdown(record_list, current_sort)
- sortable = record_list.sortable_columns
+ def table_sort_dropdown(table, current_sort)
+ sortable = table.sortable_columns
return '' if sortable.empty?
current_label = find_sort_label(sortable, current_sort)
@@ -227,7 +230,7 @@ module Spree
end
# Get column header CSS class
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def column_header_class(column)
classes = []
@@ -237,7 +240,7 @@ module Spree
end
# Get column cell CSS class
- # @param column [Spree::Admin::RecordList::Column] column definition
+ # @param column [Spree::Admin::Table::Column] column definition
# @return [String]
def column_cell_class(column)
classes = []
@@ -246,17 +249,17 @@ module Spree
end
# Build query builder fields JSON for Stimulus controller
- # @param record_list [Spree::Admin::RecordList] the record list
+ # @param table [Spree::Admin::Table] the table
# @return [String] JSON string
- def query_builder_fields_json(record_list)
- query_builder = Spree::Admin::RecordList::QueryBuilder.new(record_list)
+ def query_builder_fields_json(table)
+ query_builder = Spree::Admin::Table::QueryBuilder.new(table)
query_builder.available_fields.to_json
end
# Build available operators JSON for Stimulus controller
# @return [String] JSON string
def query_builder_operators_json
- Spree::Admin::RecordList::Filter.operators_for_select.to_json
+ Spree::Admin::Table::Filter.operators_for_select.to_json
end
# Count the number of applied filters from query_state parameter
@@ -274,7 +277,7 @@ module Spree
end
# Render a single bulk action button or link
- # @param action [Spree::Admin::RecordList::BulkAction] the bulk action
+ # @param action [Spree::Admin::Table::BulkAction] the bulk action
# @param options [Hash] additional options for the link
# @return [String] rendered HTML
def render_bulk_action(action, **options)
@@ -300,12 +303,12 @@ module Spree
link_to content, action.modal_path, link_options
end
- # Render bulk actions panel for a record list
- # @param record_list [Spree::Admin::RecordList] the record list
+ # Render bulk actions panel for a table
+ # @param table [Spree::Admin::Table] the table
# @param options [Hash] additional options
# @return [String] rendered HTML
- def render_bulk_actions_panel(record_list)
- actions = record_list.visible_bulk_actions(self)
+ def render_bulk_actions_panel(table)
+ actions = table.visible_bulk_actions(self)
return if actions.empty?
# Split actions into primary (first 2) and secondary (rest in dropdown)
@@ -332,7 +335,7 @@ module Spree
end
# Render dropdown for secondary bulk actions
- # @param actions [Array<Spree::Admin::RecordList::BulkAction>] the actions
+ # @param actions [Array<Spree::Admin::Table::BulkAction>] the actions
# @return [String] rendered HTML
def render_bulk_actions_dropdown(actions)
dropdown(direction: 'top', portal: false) do
@@ -354,7 +357,7 @@ module Spree
private
def find_sort_label(sortable, current_sort)
- return Spree.t('admin.record_lists.sort_by') if current_sort.blank?
+ return Spree.t('admin.tables.sort_by') if current_sort.blank?
field, direction = current_sort.split(' ')
column = sortable.find { |c| c.ransack_attribute == field }
@@ -363,7 +366,7 @@ module Spree
dir_label = direction == 'asc' ? 'ASC' : 'DESC'
"#{column.resolve_label} (#{dir_label})"
else
- Spree.t('admin.record_lists.sort_by')
+ Spree.t('admin.tables.sort_by')
end
end
diff --git a/admin/app/javascript/spree/admin/application.js b/admin/app/javascript/spree/admin/application.js
index e34a30b349..0191fb52ad 100644
--- a/admin/app/javascript/spree/admin/application.js
+++ b/admin/app/javascript/spree/admin/application.js
@@ -68,7 +68,7 @@ import PasswordToggle from 'spree/admin/controllers/password_toggle_controller'
import ProductFormController from 'spree/admin/controllers/product_form_controller'
import QueryBuilderController from 'spree/admin/controllers/query_builder_controller'
import RangeInputController from 'spree/admin/controllers/range_input_controller'
-import RecordListController from 'spree/admin/controllers/record_list_controller'
+import TableController from 'spree/admin/controllers/table_controller'
import ReturnItemsController from 'spree/admin/controllers/return_items_controller'
import ReplaceController from 'spree/admin/controllers/replace_controller'
import RowLinkController from 'spree/admin/controllers/row_link_controller'
@@ -136,7 +136,7 @@ application.register('password-visibility', PasswordVisibility)
application.register('product-form', ProductFormController)
application.register('query-builder', QueryBuilderController)
application.register('range-input', RangeInputController)
-application.register('record-list', RecordListController)
+application.register('table', TableController)
application.register('replace', ReplaceController)
application.register('return-items', ReturnItemsController)
application.register('reveal', Reveal)
diff --git a/admin/app/javascript/spree/admin/controllers/record_list_controller.js b/admin/app/javascript/spree/admin/controllers/table_controller.js
similarity index 100%
rename from admin/app/javascript/spree/admin/controllers/record_list_controller.js
rename to admin/app/javascript/spree/admin/controllers/table_controller.js
diff --git a/admin/app/models/spree/admin/record_list.rb b/admin/app/models/spree/admin/table.rb
similarity index 89%
rename from admin/app/models/spree/admin/record_list.rb
rename to admin/app/models/spree/admin/table.rb
index f3202b6b05..9c7715a05c 100644
--- a/admin/app/models/spree/admin/record_list.rb
+++ b/admin/app/models/spree/admin/table.rb
@@ -1,10 +1,10 @@
module Spree
module Admin
- class RecordList
+ class Table
attr_reader :columns, :bulk_actions, :context, :model_class
- attr_accessor :search_param, :search_placeholder, :row_actions
+ attr_accessor :search_param, :search_placeholder, :row_actions, :row_actions_edit, :row_actions_delete
- def initialize(context, model_class: nil, search_param: :name_cont, search_placeholder: nil, row_actions: true)
+ def initialize(context, model_class: nil, search_param: :name_cont, search_placeholder: nil, row_actions: true, row_actions_edit: true, row_actions_delete: false)
@context = context
@model_class = model_class
@columns = {}
@@ -12,6 +12,8 @@ module Spree
@search_param = search_param
@search_placeholder = search_placeholder
@row_actions = row_actions
+ @row_actions_edit = row_actions_edit
+ @row_actions_delete = row_actions_delete
end
# Check if row actions are enabled
@@ -20,6 +22,18 @@ module Spree
@row_actions
end
+ # Check if edit row action is enabled
+ # @return [Boolean]
+ def row_actions_edit?
+ @row_actions_edit
+ end
+
+ # Check if delete row action is enabled
+ # @return [Boolean]
+ def row_actions_delete?
+ @row_actions_delete
+ end
+
# Add a column definition
# @param key [Symbol] unique column identifier
# @param options [Hash] column options (label, type, sortable, filterable, default, position, etc.)
@@ -219,9 +233,17 @@ module Spree
end
# Deep clone the registry
- # @return [RecordList]
+ # @return [Table]
def deep_clone
- cloned = self.class.new(context, model_class: model_class, search_param: search_param, search_placeholder: search_placeholder, row_actions: row_actions)
+ cloned = self.class.new(
+ context,
+ model_class: model_class,
+ search_param: search_param,
+ search_placeholder: search_placeholder,
+ row_actions: row_actions,
+ row_actions_edit: row_actions_edit,
+ row_actions_delete: row_actions_delete
+ )
@columns.each do |key, column|
cloned.columns[key] = column.deep_clone
end
@@ -242,7 +264,7 @@ module Spree
end
def inspect
- "#<Spree::Admin::RecordList context=#{context} columns=#{@columns.size} bulk_actions=#{@bulk_actions.size}>"
+ "#<Spree::Admin::Table context=#{context} columns=#{@columns.size} bulk_actions=#{@bulk_actions.size}>"
end
private
diff --git a/admin/app/models/spree/admin/record_list/builder.rb b/admin/app/models/spree/admin/table/builder.rb
similarity index 98%
rename from admin/app/models/spree/admin/record_list/builder.rb
rename to admin/app/models/spree/admin/table/builder.rb
index 1be6baa5e5..52ef24bb2e 100644
--- a/admin/app/models/spree/admin/record_list/builder.rb
+++ b/admin/app/models/spree/admin/table/builder.rb
@@ -1,6 +1,6 @@
module Spree
module Admin
- class RecordList
+ class Table
class Builder
attr_reader :registry, :parent_column
diff --git a/admin/app/models/spree/admin/record_list/bulk_action.rb b/admin/app/models/spree/admin/table/bulk_action.rb
similarity index 96%
rename from admin/app/models/spree/admin/record_list/bulk_action.rb
rename to admin/app/models/spree/admin/table/bulk_action.rb
index 1f6d096c78..6b6acaf31c 100644
--- a/admin/app/models/spree/admin/record_list/bulk_action.rb
+++ b/admin/app/models/spree/admin/table/bulk_action.rb
@@ -1,6 +1,6 @@
module Spree
module Admin
- class RecordList
+ class Table
class BulkAction
attr_accessor :key, :label, :label_options, :icon, :modal_path, :action_path, :position, :condition, :confirm, :method
@@ -71,7 +71,7 @@ module Spree
end
def inspect
- "#<Spree::Admin::RecordList::BulkAction key=#{key}>"
+ "#<Spree::Admin::Table::BulkAction key=#{key}>"
end
end
end
diff --git a/admin/app/models/spree/admin/record_list/column.rb b/admin/app/models/spree/admin/table/column.rb
similarity index 95%
rename from admin/app/models/spree/admin/record_list/column.rb
rename to admin/app/models/spree/admin/table/column.rb
index d6b40ff2d7..650ba9f762 100644
--- a/admin/app/models/spree/admin/record_list/column.rb
+++ b/admin/app/models/spree/admin/table/column.rb
@@ -1,12 +1,12 @@
module Spree
module Admin
- class RecordList
+ class Table
class Column
TYPES = %i[string number date datetime currency status link boolean image custom].freeze
FILTER_TYPES = %i[string number date datetime currency status boolean autocomplete].freeze
attr_accessor :key, :label, :type, :filter_type, :sortable, :filterable, :displayable, :default, :position,
- :partial, :method, :width, :align, :format, :condition,
+ :partial, :partial_locals, :method, :width, :align, :format, :condition,
:ransack_attribute, :operators, :value_options, :search_url,
:sort_scope_asc, :sort_scope_desc
@@ -21,6 +21,7 @@ module Spree
@default = options.fetch(:default, false)
@position = options[:position] || 999
@partial = options[:partial]
+ @partial_locals = options[:partial_locals] || {}
@method = options[:method] || key
@width = options[:width]
@align = options[:align] || :left
@@ -155,7 +156,7 @@ module Spree
end
def inspect
- "#<Spree::Admin::RecordList::Column key=#{key} type=#{type} default=#{default}>"
+ "#<Spree::Admin::Table::Column key=#{key} type=#{type} default=#{default}>"
end
end
end
diff --git a/admin/app/models/spree/admin/record_list/filter.rb b/admin/app/models/spree/admin/table/filter.rb
similarity index 85%
rename from admin/app/models/spree/admin/record_list/filter.rb
rename to admin/app/models/spree/admin/table/filter.rb
index af9159ca5f..f9b2f839fa 100644
--- a/admin/app/models/spree/admin/record_list/filter.rb
+++ b/admin/app/models/spree/admin/table/filter.rb
@@ -1,6 +1,6 @@
module Spree
module Admin
- class RecordList
+ class Table
class Filter
OPERATORS = {
eq: { label: 'equals', predicate: '_eq' },
@@ -53,11 +53,18 @@ module Spree
def extract_ransack_value
return value unless value.is_a?(Array)
- # If array contains hashes with 'id' key, extract the IDs
- if value.first.is_a?(Hash) && (value.first.key?('id') || value.first.key?(:id))
- value.map { |item| item['id'] || item[:id] }
+ # Extract IDs if array contains hashes with 'id' key (from autocomplete)
+ extracted = if value.first.is_a?(Hash) && (value.first.key?('id') || value.first.key?(:id))
+ value.map { |item| item['id'] || item[:id] }
+ else
+ value
+ end
+
+ # For eq/not_eq operators, use single value instead of array
+ if %i[eq not_eq].include?(@operator) && extracted.is_a?(Array) && extracted.size == 1
+ extracted.first
else
- value
+ extracted
end
end
diff --git a/admin/app/models/spree/admin/record_list/filter_group.rb b/admin/app/models/spree/admin/table/filter_group.rb
similarity index 99%
rename from admin/app/models/spree/admin/record_list/filter_group.rb
rename to admin/app/models/spree/admin/table/filter_group.rb
index 51bd668d1f..93539305a8 100644
--- a/admin/app/models/spree/admin/record_list/filter_group.rb
+++ b/admin/app/models/spree/admin/table/filter_group.rb
@@ -1,6 +1,6 @@
module Spree
module Admin
- class RecordList
+ class Table
class FilterGroup
COMBINATORS = %i[and or].freeze
diff --git a/admin/app/models/spree/admin/record_list/query_builder.rb b/admin/app/models/spree/admin/table/query_builder.rb
similarity index 91%
rename from admin/app/models/spree/admin/record_list/query_builder.rb
rename to admin/app/models/spree/admin/table/query_builder.rb
index 5dc05c4799..1ec883bb1e 100644
--- a/admin/app/models/spree/admin/record_list/query_builder.rb
+++ b/admin/app/models/spree/admin/table/query_builder.rb
@@ -1,11 +1,11 @@
module Spree
module Admin
- class RecordList
+ class Table
class QueryBuilder
- attr_reader :root_group, :record_list
+ attr_reader :root_group, :table
- def initialize(record_list)
- @record_list = record_list
+ def initialize(table)
+ @table = table
@root_group = FilterGroup.new(combinator: :and)
end
@@ -69,10 +69,10 @@ module Spree
@root_group = FilterGroup.new(combinator: :and)
end
- # Get available fields for filtering based on record_list configuration
+ # Get available fields for filtering based on table configuration
# @return [Array<Hash>]
def available_fields
- @record_list.filterable_columns.map do |column|
+ @table.filterable_columns.map do |column|
{
key: column.ransack_attribute,
label: column.resolve_label,
diff --git a/admin/app/views/spree/admin/products/index.html.erb b/admin/app/views/spree/admin/products/index.html.erb
index 662933f13a..9ed15bfd51 100644
--- a/admin/app/views/spree/admin/products/index.html.erb
+++ b/admin/app/views/spree/admin/products/index.html.erb
@@ -11,7 +11,7 @@
<%= render_admin_partials(:products_header_partials) %>
-<%= render_record_list @collection, :products, bulk_operations: true %>
+<%= render_table @collection, :products, bulk_operations: true, export_type: Spree::Exports::Products %>
<p class="documentation-link-container">
Learn more about
diff --git a/admin/app/views/spree/admin/record_lists/_column_selector.html.erb b/admin/app/views/spree/admin/tables/_column_selector.html.erb
similarity index 78%
rename from admin/app/views/spree/admin/record_lists/_column_selector.html.erb
rename to admin/app/views/spree/admin/tables/_column_selector.html.erb
index 48604ac358..b0496a09af 100644
--- a/admin/app/views/spree/admin/record_lists/_column_selector.html.erb
+++ b/admin/app/views/spree/admin/tables/_column_selector.html.erb
@@ -1,25 +1,25 @@
-<%# locals: (record_list:, list_key:, selected_columns:, frame_name:) %>
+<%# locals: (table:, table_key:, selected_columns:, frame_name:) %>
<div data-controller="column-selector">
- <%= form_with url: spree.admin_record_list_columns_path,
+ <%= form_with url: spree.admin_table_columns_path,
method: :post,
data: { turbo_frame: frame_name } do |f| %>
- <%= hidden_field_tag :list_key, list_key %>
+ <%= hidden_field_tag :table_key, table_key %>
<%= hidden_field_tag :redirect_url, request.fullpath %>
<%= dropdown(portal: false) do %>
<%= dropdown_toggle(class: 'btn-light btn-sm flex items-center gap-1') do %>
<%= icon 'columns-3', class: 'w-4 h-4' %>
- <span><%= Spree.t('admin.record_lists.columns') %></span>
+ <span><%= Spree.t('admin.tables.columns') %></span>
<%= icon 'chevron-down', class: 'w-3 h-3' %>
<% end %>
<%= dropdown_menu(class: 'min-w-[250px]') do %>
<h6 class="font-semibold text-gray-700 text-sm p-3">
- <%= Spree.t('admin.record_lists.visible_columns') %>
+ <%= Spree.t('admin.tables.visible_columns') %>
</h6>
<div class="space-y-2 max-h-[300px] overflow-y-auto mb-4">
- <% record_list.available_columns.each do |column| %>
+ <% table.available_columns.each do |column| %>
<% next unless column.visible?(self) %>
<% is_selected = selected_columns.nil? ? column.default? : selected_columns.include?(column.key) %>
<label class="flex items-center gap-2 cursor-pointer hover:bg-gray-50 p-1.5 rounded">
@@ -41,9 +41,9 @@
<button type="button"
class="btn btn-sm btn-light flex-1"
data-action="column-selector#reset">
- <%= Spree.t('admin.record_lists.reset_to_default') %>
+ <%= Spree.t('admin.tables.reset_to_default') %>
</button>
- <%= f.submit Spree.t('admin.record_lists.apply'),
+ <%= f.submit Spree.t('admin.tables.apply'),
class: 'btn btn-sm btn-primary flex-1 cursor-pointer' %>
</div>
<% end %>
diff --git a/admin/app/views/spree/admin/record_lists/_filter_group.html.erb b/admin/app/views/spree/admin/tables/_filter_group.html.erb
similarity index 82%
rename from admin/app/views/spree/admin/record_lists/_filter_group.html.erb
rename to admin/app/views/spree/admin/tables/_filter_group.html.erb
index 8b96d78da1..b0843b6040 100644
--- a/admin/app/views/spree/admin/record_lists/_filter_group.html.erb
+++ b/admin/app/views/spree/admin/tables/_filter_group.html.erb
@@ -4,13 +4,13 @@
data-combinator="or">
<div class="flex items-center justify-between mb-3">
<div class="flex items-center gap-2">
- <span class="text-sm text-gray-600"><%= Spree.t('admin.record_lists.match') %></span>
+ <span class="text-sm text-gray-600"><%= Spree.t('admin.tables.match') %></span>
<button type="button"
class="btn btn-sm btn-outline-secondary px-2 py-1"
data-action="query-builder#toggleGroupCombinator">
<span data-group-combinator-label>OR</span>
</button>
- <span class="text-sm text-gray-600"><%= Spree.t('admin.record_lists.of_the_following') %></span>
+ <span class="text-sm text-gray-600"><%= Spree.t('admin.tables.of_the_following') %></span>
</div>
<button type="button"
class="btn btn-sm btn-light text-red-600 hover:text-red-700 hover:bg-red-50 p-1.5"
@@ -28,6 +28,6 @@
class="btn btn-sm btn-light flex items-center gap-1"
data-action="query-builder#addFilterToGroup">
<%= icon 'plus', class: 'w-4 h-4' %>
- <%= Spree.t('admin.record_lists.add_filter') %>
+ <%= Spree.t('admin.tables.add_filter') %>
</button>
</div>
diff --git a/admin/app/views/spree/admin/record_lists/_filter_row.html.erb b/admin/app/views/spree/admin/tables/_filter_row.html.erb
similarity index 79%
rename from admin/app/views/spree/admin/record_lists/_filter_row.html.erb
rename to admin/app/views/spree/admin/tables/_filter_row.html.erb
index 84418647b7..b7ed6d2a08 100644
--- a/admin/app/views/spree/admin/record_lists/_filter_row.html.erb
+++ b/admin/app/views/spree/admin/tables/_filter_row.html.erb
@@ -3,19 +3,19 @@
<select class="form-select flex-1 text-sm"
data-field-select
data-action="change->query-builder#onFieldChange">
- <option value=""><%= Spree.t('admin.record_lists.select_field') %></option>
+ <option value=""><%= Spree.t('admin.tables.select_field') %></option>
</select>
<select class="form-select flex-shrink-0 w-[160px] text-sm"
data-operator-select
data-action="change->query-builder#onOperatorChange">
- <option value="eq"><%= Spree.t('admin.record_lists.operators.equals') %></option>
+ <option value="eq"><%= Spree.t('admin.tables.operators.equals') %></option>
</select>
<div data-value-container class="flex-1">
<input type="text"
class="form-input text-sm"
- placeholder="<%= Spree.t('admin.record_lists.enter_value') %>"
+ placeholder="<%= Spree.t('admin.tables.enter_value') %>"
data-value-input
data-action="input->query-builder#onValueChange">
</div>
diff --git a/admin/app/views/spree/admin/record_lists/_query_builder.html.erb b/admin/app/views/spree/admin/tables/_query_builder.html.erb
similarity index 79%
rename from admin/app/views/spree/admin/record_lists/_query_builder.html.erb
rename to admin/app/views/spree/admin/tables/_query_builder.html.erb
index 9652a8c983..4ac31b3977 100644
--- a/admin/app/views/spree/admin/record_lists/_query_builder.html.erb
+++ b/admin/app/views/spree/admin/tables/_query_builder.html.erb
@@ -1,5 +1,5 @@
-<%# locals: (record_list:, list_key:, frame_name:) %>
-<% fields_json = query_builder_fields_json(record_list) %>
+<%# locals: (table:, table_key:, frame_name:) %>
+<% fields_json = query_builder_fields_json(table) %>
<% operators_json = query_builder_operators_json %>
<% current_state = params[:query_state] || '{}' %>
<% filter_count = count_applied_filters(current_state) %>
@@ -9,7 +9,7 @@
class="btn btn-light btn-sm flex items-center gap-1 h-full"
data-action="dialog#open">
<%= icon 'filter', class: 'w-4 h-4' %>
- <span><%= Spree.t('admin.record_lists.filters') %></span>
+ <span><%= Spree.t('admin.tables.filters') %></span>
<% if filter_count > 0 %>
<span class="badge badge-primary rounded-full text-xs px-1.5 py-0.5 min-w-[1.25rem]"><%= filter_count %></span>
<% end %>
@@ -17,8 +17,8 @@
<dialog class="drawer"
data-dialog-target="dialog"
- id="query-builder-drawer-<%= list_key %>">
- <%= drawer_header(Spree.t('admin.record_lists.filter_builder'), 'dialog') %>
+ id="query-builder-drawer-<%= table_key %>">
+ <%= drawer_header(Spree.t('admin.tables.filter_builder'), 'dialog') %>
<div data-controller="query-builder"
data-query-builder-fields-value="<%= fields_json %>"
@@ -28,7 +28,7 @@
<div class="drawer-body">
<div class="mb-4 flex items-center gap-2 flex-wrap">
<span class="text-sm text-gray-600">
- <%= Spree.t('admin.record_lists.match') %>
+ <%= Spree.t('admin.tables.match') %>
</span>
<button type="button"
class="btn btn-sm btn-outline-secondary px-2 py-1"
@@ -37,7 +37,7 @@
<span data-query-builder-target="combinatorLabel">AND</span>
</button>
<span class="text-sm text-gray-600">
- <%= Spree.t('admin.record_lists.of_the_following') %>
+ <%= Spree.t('admin.tables.of_the_following') %>
</span>
</div>
@@ -54,13 +54,13 @@
class="btn btn-sm btn-light flex items-center gap-1"
data-action="query-builder#addFilter">
<%= icon 'plus', class: 'w-4 h-4' %>
- <%= Spree.t('admin.record_lists.add_filter') %>
+ <%= Spree.t('admin.tables.add_filter') %>
</button>
<button type="button"
class="btn btn-sm btn-light flex items-center gap-1"
data-action="query-builder#addOrGroup">
<%= icon 'brackets', class: 'w-4 h-4' %>
- <%= Spree.t('admin.record_lists.add_or_group') %>
+ <%= Spree.t('admin.tables.add_or_group') %>
</button>
</div>
@@ -75,21 +75,21 @@
<button type="button"
class="btn btn-light"
data-action="query-builder#clear">
- <%= Spree.t('admin.record_lists.clear_all') %>
+ <%= Spree.t('admin.tables.clear_all') %>
</button>
- <%= f.submit Spree.t('admin.record_lists.apply_filters'),
+ <%= f.submit Spree.t('admin.tables.apply_filters'),
class: 'btn btn-primary cursor-pointer' %>
</div>
<% end %>
<%# Filter row template %>
<template data-query-builder-target="filterTemplate">
- <%= render 'spree/admin/record_lists/filter_row' %>
+ <%= render 'spree/admin/tables/filter_row' %>
</template>
<%# Filter group template %>
<template data-query-builder-target="groupTemplate">
- <%= render 'spree/admin/record_lists/filter_group' %>
+ <%= render 'spree/admin/tables/filter_group' %>
</template>
</div>
</dialog>
diff --git a/admin/app/views/spree/admin/record_lists/_row_actions.html.erb b/admin/app/views/spree/admin/tables/_row_actions.html.erb
similarity index 51%
rename from admin/app/views/spree/admin/record_lists/_row_actions.html.erb
rename to admin/app/views/spree/admin/tables/_row_actions.html.erb
index 1048177a39..79dd92605a 100644
--- a/admin/app/views/spree/admin/record_lists/_row_actions.html.erb
+++ b/admin/app/views/spree/admin/tables/_row_actions.html.erb
@@ -1,6 +1,6 @@
-<%# locals: (record:) %>
+<%# locals: (record:, table:) %>
<div class="flex items-center justify-end gap-1">
- <% if respond_to?(:edit_object_url) && can?(:update, record) %>
+ <% if table.row_actions_edit? && respond_to?(:edit_object_url) && can?(:update, record) %>
<%= link_to edit_object_url(record),
class: 'btn btn-sm btn-light',
title: Spree.t(:edit),
@@ -8,4 +8,8 @@
<%= icon 'pencil', class: 'w-4 h-4' %>
<% end %>
<% end %>
+
+ <% if table.row_actions_delete? && can?(:destroy, record) %>
+ <%= link_to_delete(record, no_text: true, class: 'btn btn-sm btn-light text-danger') %>
+ <% end %>
</div>
diff --git a/admin/app/views/spree/admin/record_lists/_record_list.html.erb b/admin/app/views/spree/admin/tables/_table.html.erb
similarity index 61%
rename from admin/app/views/spree/admin/record_lists/_record_list.html.erb
rename to admin/app/views/spree/admin/tables/_table.html.erb
index c30ff645cf..0c618b4178 100644
--- a/admin/app/views/spree/admin/record_lists/_record_list.html.erb
+++ b/admin/app/views/spree/admin/tables/_table.html.erb
@@ -1,12 +1,16 @@
-<%# locals: (collection:, record_list:, list_key:, selected_columns: nil, frame_name: nil, bulk_operations: false, sortable: false) %>
+<%# locals: (collection:, table:, table_key:, selected_columns: nil, frame_name: nil, bulk_operations: false, sortable: false, export_type: nil) %>
<% frame_name ||= controller_name %>
-<% columns = record_list.visible_columns(selected_columns, self) %>
+<% columns = table.visible_columns(selected_columns, self) %>
<% current_sort = params.dig(:q, :s) %>
-<% search_param = record_list.respond_to?(:search_param) ? record_list.search_param : :name_cont %>
-<% search_placeholder = (record_list.respond_to?(:search_placeholder) && record_list.search_placeholder) || [Spree.t(:search), controller_name.humanize.downcase].join(' ') %>
+<% search_param = table.respond_to?(:search_param) ? table.search_param : :name_cont %>
+<% search_placeholder = (table.respond_to?(:search_placeholder) && table.search_placeholder) || [Spree.t(:search), controller_name.humanize.downcase].join(' ') %>
+
+<% if export_type.present? %>
+ <%= render 'spree/admin/shared/export_modal', export_type: export_type %>
+<% end %>
<%= turbo_frame_tag frame_name, autoscroll: true, data: { autoscroll_block: :start, turbo_action: 'advance' } do %>
- <div class="card-lg" data-controller="record-list" data-record-list-url-value="<%= request.path %>">
+ <div class="card-lg" data-controller="table" data-table-url-value="<%= request.path %>">
<div class="p-2 border-b border-gray-200">
<div class="flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between">
<div class="flex gap-2 items-center flex-wrap">
@@ -22,11 +26,11 @@
</div>
<div class="flex gap-2 items-center h-full">
- <%= render 'spree/admin/record_lists/query_builder', record_list: record_list, list_key: list_key, frame_name: frame_name %>
- <%= record_list_sort_dropdown(record_list, current_sort) %>
- <%= render 'spree/admin/record_lists/column_selector',
- record_list: record_list,
- list_key: list_key,
+ <%= render 'spree/admin/tables/query_builder', table: table, table_key: table_key, frame_name: frame_name %>
+ <%= table_sort_dropdown(table, current_sort) %>
+ <%= render 'spree/admin/tables/column_selector',
+ table: table,
+ table_key: table_key,
selected_columns: selected_columns,
frame_name: frame_name %>
</div>
@@ -34,17 +38,17 @@
</div>
<% if collection.any? %>
- <%= render 'spree/admin/record_lists/table',
+ <%= render 'spree/admin/tables/table_body',
collection: collection,
columns: columns,
- record_list: record_list,
+ table: table,
bulk_operations: bulk_operations,
sortable: sortable %>
<%= render 'spree/admin/shared/index_table_options', collection: collection %>
<% else %>
<%= render 'spree/admin/shared/no_resource_found',
- new_object_url: (new_object_url if respond_to?(:new_object_url) && can?(:create, record_list.model_class)) %>
+ new_object_url: (new_object_url if respond_to?(:new_object_url) && can?(:create, table.model_class)) %>
<% end %>
</div>
<% end %>
diff --git a/admin/app/views/spree/admin/record_lists/_table.html.erb b/admin/app/views/spree/admin/tables/_table_body.html.erb
similarity index 85%
rename from admin/app/views/spree/admin/record_lists/_table.html.erb
rename to admin/app/views/spree/admin/tables/_table_body.html.erb
index e709c7873e..2240761117 100644
--- a/admin/app/views/spree/admin/record_lists/_table.html.erb
+++ b/admin/app/views/spree/admin/tables/_table_body.html.erb
@@ -1,11 +1,11 @@
-<%# locals: (collection:, columns:, record_list:, bulk_operations: false, sortable: false) %>
-<% has_bulk_actions = bulk_operations && record_list.bulk_operations_enabled? %>
-<% has_row_actions = record_list.row_actions? %>
+<%# locals: (collection:, columns:, table:, bulk_operations: false, sortable: false) %>
+<% has_bulk_actions = bulk_operations && table.bulk_operations_enabled? %>
+<% has_row_actions = table.row_actions? %>
<% if has_bulk_actions %>
<div data-controller="bulk-operation bulk-dialog" data-action="keydown.esc->bulk-operation#cancel" tabindex="0">
<%= form_tag url_for(action: :index), method: :put, data: { 'bulk-operation-target': 'form' } do %>
<%= render 'spree/admin/shared/bulk_modal' %>
- <%= render_bulk_actions_panel(record_list) %>
+ <%= render_bulk_actions_panel(table) %>
<div class="table-responsive">
<table class="table" id="listing_<%= controller_name %>">
@@ -38,12 +38,12 @@
data-sortable-response-kind-value="turbo-stream"
<% end %>
>
- <%= render partial: 'spree/admin/record_lists/table_row',
+ <%= render partial: 'spree/admin/tables/table_row',
collection: collection,
as: :record,
locals: {
columns: columns,
- record_list: record_list,
+ table: table,
bulk_operations: has_bulk_actions,
sortable: sortable,
row_actions: has_row_actions
@@ -81,12 +81,12 @@
data-sortable-response-kind-value="turbo-stream"
<% end %>
>
- <%= render partial: 'spree/admin/record_lists/table_row',
+ <%= render partial: 'spree/admin/tables/table_row',
collection: collection,
as: :record,
locals: {
columns: columns,
- record_list: record_list,
+ table: table,
bulk_operations: false,
sortable: sortable,
row_actions: has_row_actions
diff --git a/admin/app/views/spree/admin/record_lists/_table_row.html.erb b/admin/app/views/spree/admin/tables/_table_row.html.erb
similarity index 75%
rename from admin/app/views/spree/admin/record_lists/_table_row.html.erb
rename to admin/app/views/spree/admin/tables/_table_row.html.erb
index fe0d72943c..8247ad5d3c 100644
--- a/admin/app/views/spree/admin/record_lists/_table_row.html.erb
+++ b/admin/app/views/spree/admin/tables/_table_row.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (record:, columns:, record_list:, bulk_operations: false, sortable: false, row_actions: true) %>
+<%# locals: (record:, columns:, table:, bulk_operations: false, sortable: false, row_actions: true) %>
<tr id="<%= dom_id record %>" class="group"<% if sortable %> data-sortable-update-url="<%= edit_object_url(record) %>"<% end %>>
<% if sortable %>
<td class="w-5 move-handle text-center">
@@ -18,17 +18,17 @@
<%= link_to edit_object_url(record),
class: 'flex items-center w-full no-underline hover:text-primary',
data: { 'turbo-frame': '_top' } do %>
- <%= render_column_value(record, column, record_list) %>
+ <%= render_column_value(record, column, table) %>
<% end %>
<% else %>
- <%= render_column_value(record, column, record_list) %>
+ <%= render_column_value(record, column, table) %>
<% end %>
</td>
<% end %>
<% if row_actions %>
<td class="w-10 text-right">
- <%= render 'spree/admin/record_lists/row_actions', record: record %>
+ <%= render 'spree/admin/tables/row_actions', record: record, table: table %>
</td>
<% end %>
</tr>
diff --git a/admin/app/views/spree/admin/record_lists/columns/_product_inventory.html.erb b/admin/app/views/spree/admin/tables/columns/_product_inventory.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/record_lists/columns/_product_inventory.html.erb
rename to admin/app/views/spree/admin/tables/columns/_product_inventory.html.erb
diff --git a/admin/app/views/spree/admin/record_lists/columns/_product_name.html.erb b/admin/app/views/spree/admin/tables/columns/_product_name.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/record_lists/columns/_product_name.html.erb
rename to admin/app/views/spree/admin/tables/columns/_product_name.html.erb
diff --git a/admin/app/views/spree/admin/record_lists/columns/_product_status.html.erb b/admin/app/views/spree/admin/tables/columns/_product_status.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/record_lists/columns/_product_status.html.erb
rename to admin/app/views/spree/admin/tables/columns/_product_status.html.erb
diff --git a/admin/config/initializers/record_lists.rb b/admin/config/initializers/record_lists.rb
deleted file mode 100644
index a57aa897db..0000000000
--- a/admin/config/initializers/record_lists.rb
+++ /dev/null
@@ -1,410 +0,0 @@
-# Default column configurations for Spree Admin Record Lists
-#
-# This initializer registers the default record lists and their columns.
-# Developers can extend these in their own initializers by:
-#
-# Rails.application.config.after_initialize do
-# Spree.admin.record_lists.products.add :custom_column, type: :string, default: true
-# Spree.admin.record_lists.products.remove :sku
-# Spree.admin.record_lists.products.update :name, position: 5
-# Spree.admin.record_lists.products.insert_after :name, :vendor, type: :string
-# end
-
-Rails.application.config.after_initialize do
- # Register Products record list
- Spree.admin.record_lists.register(:products, model_class: Spree::Product, search_param: :multi_search)
-
- # Product name with image (custom partial)
- Spree.admin.record_lists.products.add :name,
- label: :name,
- type: :custom,
- sortable: true,
- filterable: true,
- default: true,
- position: 10,
- partial: 'spree/admin/record_lists/columns/product_name'
-
- # Product status with help bubble (custom partial)
- Spree.admin.record_lists.products.add :status,
- label: :status,
- type: :custom,
- filter_type: :status,
- sortable: true,
- filterable: true,
- default: true,
- position: 20,
- partial: 'spree/admin/record_lists/columns/product_status',
- value_options: [
- { value: 'draft', label: 'Draft' },
- { value: 'active', label: 'Active' },
- { value: 'archived', label: 'Archived' }
- ]
-
- # Inventory display (custom partial)
- Spree.admin.record_lists.products.add :inventory,
- label: :inventory,
- type: :custom,
- sortable: false,
- filterable: false,
- default: true,
- position: 25,
- partial: 'spree/admin/record_lists/columns/product_inventory'
-
- Spree.admin.record_lists.products.add :sku,
- label: :sku,
- type: :string,
- sortable: true,
- filterable: true,
- default: false,
- position: 30,
- ransack_attribute: 'master_sku',
- method: ->(product) { product.sku }
-
- Spree.admin.record_lists.products.add :price,
- label: :price,
- type: :currency,
- sortable: true,
- filterable: true,
- default: true,
- position: 40,
- ransack_attribute: 'master_price',
- sort_scope_asc: :ascend_by_price,
- sort_scope_desc: :descend_by_price,
- method: ->(product) { product.price }
-
- Spree.admin.record_lists.products.add :created_at,
- label: :created_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: false,
- position: 50
-
- Spree.admin.record_lists.products.add :updated_at,
- label: :updated_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: false,
- position: 60
-
- # Stock filter (filter-only, not displayed as column)
- Spree.admin.record_lists.products.add :in_stock,
- label: 'In Stock',
- type: :boolean,
- filter_type: :boolean,
- sortable: false,
- filterable: true,
- displayable: false,
- default: false,
- position: 70,
- ransack_attribute: 'in_stock_items'
-
- # Taxons - displayed as comma-separated list, filtered via autocomplete
- Spree.admin.record_lists.products.add :taxons,
- label: :taxons,
- type: :association,
- filter_type: :autocomplete,
- sortable: false,
- filterable: true,
- default: false,
- position: 80,
- ransack_attribute: 'taxons_id',
- operators: %i[in],
- search_url: '/admin/taxons/select_options.json',
- method: ->(product) { product.taxons.map(&:pretty_name).join(', ') }
-
- # Tags - displayed as comma-separated list, filtered via autocomplete
- Spree.admin.record_lists.products.add :tags,
- label: :tags,
- type: :association,
- filter_type: :autocomplete,
- sortable: false,
- filterable: true,
- default: false,
- position: 85,
- ransack_attribute: 'tags_name',
- operators: %i[in],
- search_url: '/admin/tags/select_options.json?taggable_type=Spree::Product',
- method: ->(product) { product.tag_list.join(', ') }
-
- # Products bulk actions
- Spree.admin.record_lists.products.add_bulk_action :set_active,
- label: 'admin.bulk_ops.products.title.set_status',
- label_options: { status: :active },
- icon: 'circle-check',
- modal_path: '/admin/products/bulk_modal?kind=set_status&status=active',
- action_path: '/admin/products/bulk_status_update?status=active',
- position: 10,
- condition: -> { can?(:activate, Spree::Product) }
-
- Spree.admin.record_lists.products.add_bulk_action :set_draft,
- label: 'admin.bulk_ops.products.title.set_status',
- label_options: { status: :draft },
- icon: 'circle-dotted',
- modal_path: '/admin/products/bulk_modal?kind=set_status&status=draft',
- action_path: '/admin/products/bulk_status_update?status=draft',
- position: 20
-
- Spree.admin.record_lists.products.add_bulk_action :set_archived,
- label: 'admin.bulk_ops.products.title.set_status',
- label_options: { status: :archived },
- icon: 'archive',
- modal_path: '/admin/products/bulk_modal?kind=set_status&status=archived',
- action_path: '/admin/products/bulk_status_update?status=archived',
- position: 30
-
- Spree.admin.record_lists.products.add_bulk_action :add_to_taxons,
- label: 'admin.bulk_ops.products.title.add_to_taxons',
- icon: 'category-plus',
- modal_path: '/admin/products/bulk_modal?kind=add_to_taxons',
- action_path: '/admin/products/bulk_add_to_taxons',
- position: 40,
- condition: -> { can?(:manage, Spree::Classification) }
-
- Spree.admin.record_lists.products.add_bulk_action :remove_from_taxons,
- label: 'admin.bulk_ops.products.title.remove_from_taxons',
- icon: 'category-minus',
- modal_path: '/admin/products/bulk_modal?kind=remove_from_taxons',
- action_path: '/admin/products/bulk_remove_from_taxons',
- position: 50,
- condition: -> { can?(:manage, Spree::Classification) }
-
- Spree.admin.record_lists.products.add_bulk_action :add_tags,
- label: 'admin.bulk_ops.products.title.add_tags',
- icon: 'tag-plus',
- modal_path: '/admin/products/bulk_modal?kind=add_tags',
- action_path: '/admin/products/bulk_add_tags',
- position: 60,
- condition: -> { can?(:manage_tags, Spree::Product) }
-
- Spree.admin.record_lists.products.add_bulk_action :remove_tags,
- label: 'admin.bulk_ops.products.title.remove_tags',
- icon: 'tag-minus',
- modal_path: '/admin/products/bulk_modal?kind=remove_tags',
- action_path: '/admin/products/bulk_remove_tags',
- position: 70,
- condition: -> { can?(:manage_tags, Spree::Product) }
-
- # Register Orders record list
- Spree.admin.record_lists.register(:orders, model_class: Spree::Order, search_param: :number_or_email_cont)
-
- Spree.admin.record_lists.orders.add :number,
- label: :order_number,
- type: :link,
- sortable: true,
- filterable: true,
- default: true,
- position: 10
-
- Spree.admin.record_lists.orders.add :state,
- label: :state,
- type: :status,
- sortable: true,
- filterable: true,
- default: true,
- position: 20,
- value_options: [
- { value: 'cart', label: 'Cart' },
- { value: 'address', label: 'Address' },
- { value: 'delivery', label: 'Delivery' },
- { value: 'payment', label: 'Payment' },
- { value: 'confirm', label: 'Confirm' },
- { value: 'complete', label: 'Complete' },
- { value: 'canceled', label: 'Canceled' }
- ]
-
- Spree.admin.record_lists.orders.add :payment_state,
- label: :payment_state,
- type: :status,
- sortable: true,
- filterable: true,
- default: true,
- position: 30,
- value_options: [
- { value: 'balance_due', label: 'Balance Due' },
- { value: 'credit_owed', label: 'Credit Owed' },
- { value: 'failed', label: 'Failed' },
- { value: 'paid', label: 'Paid' },
- { value: 'void', label: 'Void' }
- ]
-
- Spree.admin.record_lists.orders.add :shipment_state,
- label: :shipment_state,
- type: :status,
- sortable: true,
- filterable: true,
- default: false,
- position: 35,
- value_options: [
- { value: 'backorder', label: 'Backorder' },
- { value: 'canceled', label: 'Canceled' },
- { value: 'partial', label: 'Partial' },
- { value: 'pending', label: 'Pending' },
- { value: 'ready', label: 'Ready' },
- { value: 'shipped', label: 'Shipped' }
- ]
-
- Spree.admin.record_lists.orders.add :total,
- label: :total,
- type: :currency,
- sortable: true,
- filterable: true,
- default: true,
- position: 40,
- method: ->(order) { order.display_total }
-
- Spree.admin.record_lists.orders.add :email,
- label: :email,
- type: :string,
- sortable: true,
- filterable: true,
- default: false,
- position: 45
-
- Spree.admin.record_lists.orders.add :completed_at,
- label: :completed_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: true,
- position: 50
-
- Spree.admin.record_lists.orders.add :created_at,
- label: :created_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: false,
- position: 60
-
- # Register Users record list
- Spree.admin.record_lists.register(:users, model_class: Spree.user_class, search_param: :email_cont)
-
- Spree.admin.record_lists.users.add :email,
- label: :email,
- type: :link,
- sortable: true,
- filterable: true,
- default: true,
- position: 10
-
- Spree.admin.record_lists.users.add :first_name,
- label: :first_name,
- type: :string,
- sortable: true,
- filterable: true,
- default: true,
- position: 20,
- ransack_attribute: 'bill_address_firstname'
-
- Spree.admin.record_lists.users.add :last_name,
- label: :last_name,
- type: :string,
- sortable: true,
- filterable: true,
- default: true,
- position: 30,
- ransack_attribute: 'bill_address_lastname'
-
- Spree.admin.record_lists.users.add :created_at,
- label: :created_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: true,
- position: 40
-
- # Users bulk actions
- Spree.admin.record_lists.users.add_bulk_action :add_tags,
- label: 'admin.bulk_ops.users.title.add_tags',
- icon: 'tag-plus',
- modal_path: '/admin/users/bulk_modal?kind=add_tags',
- action_path: '/admin/users/bulk_add_tags',
- method: :post,
- position: 10,
- condition: -> { can?(:manage_tags, Spree.user_class) }
-
- Spree.admin.record_lists.users.add_bulk_action :remove_tags,
- label: 'admin.bulk_ops.users.title.remove_tags',
- icon: 'tag-minus',
- modal_path: '/admin/users/bulk_modal?kind=remove_tags',
- action_path: '/admin/users/bulk_remove_tags',
- method: :post,
- position: 20,
- condition: -> { can?(:manage_tags, Spree.user_class) }
-
- # Register Promotions record list
- Spree.admin.record_lists.register(:promotions, model_class: Spree::Promotion, search_param: :name_cont)
-
- Spree.admin.record_lists.promotions.add :name,
- label: :name,
- type: :link,
- sortable: true,
- filterable: true,
- default: true,
- position: 10
-
- Spree.admin.record_lists.promotions.add :code,
- label: :code,
- type: :string,
- sortable: true,
- filterable: true,
- default: true,
- position: 20
-
- Spree.admin.record_lists.promotions.add :starts_at,
- label: :starts_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: true,
- position: 30
-
- Spree.admin.record_lists.promotions.add :expires_at,
- label: :expires_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: true,
- position: 40
-
- # Register Posts record list
- Spree.admin.record_lists.register(:posts, model_class: Spree::Post, search_param: :title_cont)
-
- Spree.admin.record_lists.posts.add :title,
- label: :title,
- type: :link,
- sortable: true,
- filterable: true,
- default: true,
- position: 10
-
- Spree.admin.record_lists.posts.add :status,
- label: :status,
- type: :status,
- sortable: true,
- filterable: true,
- default: true,
- position: 20,
- value_options: [
- { value: 'draft', label: 'Draft' },
- { value: 'published', label: 'Published' }
- ]
-
- Spree.admin.record_lists.posts.add :published_at,
- label: :published_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: true,
- position: 30
-
- Spree.admin.record_lists.posts.add :created_at,
- label: :created_at,
- type: :datetime,
- sortable: true,
- filterable: true,
- default: false,
- position: 40
-end
diff --git a/admin/config/initializers/spree_admin_tables.rb b/admin/config/initializers/spree_admin_tables.rb
new file mode 100644
index 0000000000..e6d4f81269
--- /dev/null
+++ b/admin/config/initializers/spree_admin_tables.rb
@@ -0,0 +1,885 @@
+# Default column configurations for Spree Admin Tables
+#
+# This initializer registers the default tables and their columns.
+# Developers can extend these in their own initializers by:
+#
+# Rails.application.config.after_initialize do
+# Spree.admin.tables.products.add :custom_column, type: :string, default: true
+# Spree.admin.tables.products.remove :sku
+# Spree.admin.tables.products.update :name, position: 5
+# Spree.admin.tables.products.insert_after :name, :vendor, type: :string
+# end
+
+Rails.application.config.after_initialize do
+ # Register Products table
+ Spree.admin.tables.register(:products, model_class: Spree::Product, search_param: :multi_search)
+
+ # Product name with image (custom partial)
+ Spree.admin.tables.products.add :name,
+ label: :name,
+ type: :custom,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10,
+ partial: 'spree/admin/tables/columns/product_name'
+
+ # Product status with help bubble (custom partial)
+ Spree.admin.tables.products.add :status,
+ label: :status,
+ type: :custom,
+ filter_type: :status,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20,
+ partial: 'spree/admin/tables/columns/product_status',
+ value_options: [
+ { value: 'draft', label: 'Draft' },
+ { value: 'active', label: 'Active' },
+ { value: 'archived', label: 'Archived' }
+ ]
+
+ # Inventory display (custom partial)
+ Spree.admin.tables.products.add :inventory,
+ label: :inventory,
+ type: :custom,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 25,
+ partial: 'spree/admin/tables/columns/product_inventory'
+
+ Spree.admin.tables.products.add :sku,
+ label: :sku,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 30,
+ ransack_attribute: 'master_sku',
+ method: ->(product) { product.sku }
+
+ Spree.admin.tables.products.add :price,
+ label: :price,
+ type: :currency,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 40,
+ ransack_attribute: 'master_price',
+ sort_scope_asc: :ascend_by_price,
+ sort_scope_desc: :descend_by_price,
+ method: ->(product) { product.price }
+
+ Spree.admin.tables.products.add :created_at,
+ label: :created_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 50
+
+ Spree.admin.tables.products.add :updated_at,
+ label: :updated_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 60
+
+ # Stock filter (filter-only, not displayed as column)
+ Spree.admin.tables.products.add :in_stock,
+ label: 'In Stock',
+ type: :boolean,
+ filter_type: :boolean,
+ sortable: false,
+ filterable: true,
+ displayable: false,
+ default: false,
+ position: 70,
+ ransack_attribute: 'in_stock_items'
+
+ # Taxons - displayed as comma-separated list, filtered via autocomplete
+ Spree.admin.tables.products.add :taxons,
+ label: :taxons,
+ type: :association,
+ filter_type: :autocomplete,
+ sortable: false,
+ filterable: true,
+ default: false,
+ position: 80,
+ ransack_attribute: 'taxons_id',
+ operators: %i[in],
+ search_url: '/admin/taxons/select_options.json',
+ method: ->(product) { product.taxons.map(&:pretty_name).join(', ') }
+
+ # Tags - displayed as comma-separated list, filtered via autocomplete
+ Spree.admin.tables.products.add :tags,
+ label: :tags,
+ type: :association,
+ filter_type: :autocomplete,
+ sortable: false,
+ filterable: true,
+ default: false,
+ position: 85,
+ ransack_attribute: 'tags_name',
+ operators: %i[in],
+ search_url: '/admin/tags/select_options.json?taggable_type=Spree::Product',
+ method: ->(product) { product.tag_list.join(', ') }
+
+ # Products bulk actions
+ Spree.admin.tables.products.add_bulk_action :set_active,
+ label: 'admin.bulk_ops.products.title.set_status',
+ label_options: { status: :active },
+ icon: 'circle-check',
+ modal_path: '/admin/products/bulk_modal?kind=set_status&status=active',
+ action_path: '/admin/products/bulk_status_update?status=active',
+ position: 10,
+ condition: -> { can?(:activate, Spree::Product) }
+
+ Spree.admin.tables.products.add_bulk_action :set_draft,
+ label: 'admin.bulk_ops.products.title.set_status',
+ label_options: { status: :draft },
+ icon: 'circle-dotted',
+ modal_path: '/admin/products/bulk_modal?kind=set_status&status=draft',
+ action_path: '/admin/products/bulk_status_update?status=draft',
+ position: 20
+
+ Spree.admin.tables.products.add_bulk_action :set_archived,
+ label: 'admin.bulk_ops.products.title.set_status',
+ label_options: { status: :archived },
+ icon: 'archive',
+ modal_path: '/admin/products/bulk_modal?kind=set_status&status=archived',
+ action_path: '/admin/products/bulk_status_update?status=archived',
+ position: 30
+
+ Spree.admin.tables.products.add_bulk_action :add_to_taxons,
+ label: 'admin.bulk_ops.products.title.add_to_taxons',
+ icon: 'category-plus',
+ modal_path: '/admin/products/bulk_modal?kind=add_to_taxons',
+ action_path: '/admin/products/bulk_add_to_taxons',
+ position: 40,
+ condition: -> { can?(:manage, Spree::Classification) }
+
+ Spree.admin.tables.products.add_bulk_action :remove_from_taxons,
+ label: 'admin.bulk_ops.products.title.remove_from_taxons',
+ icon: 'category-minus',
+ modal_path: '/admin/products/bulk_modal?kind=remove_from_taxons',
+ action_path: '/admin/products/bulk_remove_from_taxons',
+ position: 50,
+ condition: -> { can?(:manage, Spree::Classification) }
+
+ Spree.admin.tables.products.add_bulk_action :add_tags,
+ label: 'admin.bulk_ops.products.title.add_tags',
+ icon: 'tag-plus',
+ modal_path: '/admin/products/bulk_modal?kind=add_tags',
+ action_path: '/admin/products/bulk_add_tags',
+ position: 60,
+ condition: -> { can?(:manage_tags, Spree::Product) }
+
+ Spree.admin.tables.products.add_bulk_action :remove_tags,
+ label: 'admin.bulk_ops.products.title.remove_tags',
+ icon: 'tag-minus',
+ modal_path: '/admin/products/bulk_modal?kind=remove_tags',
+ action_path: '/admin/products/bulk_remove_tags',
+ position: 70,
+ condition: -> { can?(:manage_tags, Spree::Product) }
+
+ # Register Orders table
+ Spree.admin.tables.register(:orders, model_class: Spree::Order, search_param: :number_or_email_cont)
+
+ Spree.admin.tables.orders.add :number,
+ label: :order_number,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10
+
+ Spree.admin.tables.orders.add :state,
+ label: :state,
+ type: :status,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20,
+ value_options: [
+ { value: 'cart', label: 'Cart' },
+ { value: 'address', label: 'Address' },
+ { value: 'delivery', label: 'Delivery' },
+ { value: 'payment', label: 'Payment' },
+ { value: 'confirm', label: 'Confirm' },
+ { value: 'complete', label: 'Complete' },
+ { value: 'canceled', label: 'Canceled' }
+ ]
+
+ Spree.admin.tables.orders.add :payment_state,
+ label: :payment_state,
+ type: :status,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 30,
+ value_options: [
+ { value: 'balance_due', label: 'Balance Due' },
+ { value: 'credit_owed', label: 'Credit Owed' },
+ { value: 'failed', label: 'Failed' },
+ { value: 'paid', label: 'Paid' },
+ { value: 'void', label: 'Void' }
+ ]
+
+ Spree.admin.tables.orders.add :shipment_state,
+ label: :shipment_state,
+ type: :status,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 35,
+ value_options: [
+ { value: 'backorder', label: 'Backorder' },
+ { value: 'canceled', label: 'Canceled' },
+ { value: 'partial', label: 'Partial' },
+ { value: 'pending', label: 'Pending' },
+ { value: 'ready', label: 'Ready' },
+ { value: 'shipped', label: 'Shipped' }
+ ]
+
+ Spree.admin.tables.orders.add :total,
+ label: :total,
+ type: :currency,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 40,
+ method: ->(order) { order.display_total }
+
+ Spree.admin.tables.orders.add :email,
+ label: :email,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 45
+
+ Spree.admin.tables.orders.add :completed_at,
+ label: :completed_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 50
+
+ Spree.admin.tables.orders.add :created_at,
+ label: :created_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 60
+
+ # Register Users table
+ Spree.admin.tables.register(:users, model_class: Spree.user_class, search_param: :multi_search, row_actions: false)
+
+ # User name with avatar
+ Spree.admin.tables.users.add :name,
+ label: :name,
+ type: :custom,
+ sortable: true,
+ filterable: false,
+ default: true,
+ position: 10,
+ ransack_attribute: 'first_name',
+ partial: 'spree/admin/shared/user',
+ partial_locals: ->(record) { { user: record } }
+
+ # Email marketing status
+ Spree.admin.tables.users.add :accepts_email_marketing,
+ label: :email_marketing,
+ type: :boolean,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20,
+ method: ->(user) { user.accepts_email_marketing? }
+
+ # Location (custom partial with flag)
+ Spree.admin.tables.users.add :location,
+ label: :location,
+ type: :custom,
+ filter_type: :autocomplete,
+ sortable: false,
+ filterable: true,
+ default: true,
+ position: 30,
+ ransack_attribute: 'addresses_country_name',
+ operators: %i[eq],
+ search_url: '/admin/countries/select_options.json',
+ partial: 'spree/admin/tables/columns/user_location'
+
+ # Number of orders
+ Spree.admin.tables.users.add :orders_count,
+ label: 'admin.num_orders',
+ type: :number,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 40,
+ method: ->(user) { user.completed_orders_for_store(Spree::Current.store).count }
+
+ # Amount spent
+ Spree.admin.tables.users.add :amount_spent,
+ label: 'admin.amount_spent',
+ type: :currency,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 50,
+ method: ->(user) { user.display_amount_spent_in(Spree::Current.currency) }
+
+ Spree.admin.tables.users.add :created_at,
+ label: :created_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 60
+
+ # Filter-only fields (not displayed as columns)
+ Spree.admin.tables.users.add :first_name,
+ label: :first_name,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ displayable: false,
+ default: false,
+ position: 70,
+ ransack_attribute: 'bill_address_firstname'
+
+ Spree.admin.tables.users.add :last_name,
+ label: :last_name,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ displayable: false,
+ default: false,
+ position: 80,
+ ransack_attribute: 'bill_address_lastname'
+
+ Spree.admin.tables.users.add :tags,
+ label: :tags,
+ type: :association,
+ filter_type: :autocomplete,
+ sortable: false,
+ filterable: true,
+ displayable: false,
+ default: false,
+ position: 90,
+ ransack_attribute: 'tags_name',
+ operators: %i[in],
+ search_url: '/admin/tags/select_options.json?taggable_type=Spree::User'
+
+ # Users bulk actions
+ Spree.admin.tables.users.add_bulk_action :add_tags,
+ label: 'admin.bulk_ops.users.title.add_tags',
+ icon: 'tag-plus',
+ modal_path: '/admin/users/bulk_modal?kind=add_tags',
+ action_path: '/admin/users/bulk_add_tags',
+ method: :post,
+ position: 10,
+ condition: -> { can?(:manage_tags, Spree.user_class) }
+
+ Spree.admin.tables.users.add_bulk_action :remove_tags,
+ label: 'admin.bulk_ops.users.title.remove_tags',
+ icon: 'tag-minus',
+ modal_path: '/admin/users/bulk_modal?kind=remove_tags',
+ action_path: '/admin/users/bulk_remove_tags',
+ method: :post,
+ position: 20,
+ condition: -> { can?(:manage_tags, Spree.user_class) }
+
+ # Register Promotions table
+ Spree.admin.tables.register(:promotions, model_class: Spree::Promotion, search_param: :name_cont)
+
+ Spree.admin.tables.promotions.add :name,
+ label: :name,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10
+
+ Spree.admin.tables.promotions.add :code,
+ label: :code,
+ type: :custom,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20,
+ partial: 'spree/admin/tables/columns/promotion_code'
+
+ Spree.admin.tables.promotions.add :kind,
+ label: :kind,
+ type: :custom,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 25,
+ partial: 'spree/admin/tables/columns/promotion_kind'
+
+ Spree.admin.tables.promotions.add :usage_limit,
+ label: :usage_limit,
+ type: :custom,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 30,
+ partial: 'spree/admin/promotions/usage_limit',
+ partial_locals: ->(record) { { promotion: record } }
+
+ Spree.admin.tables.promotions.add :status,
+ label: :status,
+ type: :custom,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 35,
+ partial: 'spree/admin/promotions/status',
+ partial_locals: ->(record) { { promotion: record } }
+
+ Spree.admin.tables.promotions.add :starts_at,
+ label: :starts_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 40
+
+ Spree.admin.tables.promotions.add :expires_at,
+ label: :expires_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 50
+
+ # Register Posts table
+ Spree.admin.tables.register(:posts, model_class: Spree::Post, search_param: :title_cont)
+
+ Spree.admin.tables.posts.add :title,
+ label: :title,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10
+
+ Spree.admin.tables.posts.add :status,
+ label: :status,
+ type: :status,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20,
+ value_options: [
+ { value: 'draft', label: 'Draft' },
+ { value: 'published', label: 'Published' }
+ ]
+
+ Spree.admin.tables.posts.add :published_at,
+ label: :published_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 30
+
+ Spree.admin.tables.posts.add :created_at,
+ label: :created_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: false,
+ position: 40
+
+ # Register Customer Returns table
+ Spree.admin.tables.register(:customer_returns, model_class: Spree::CustomerReturn, search_param: :number_cont, row_actions: false)
+
+ Spree.admin.tables.customer_returns.add :number,
+ label: :number,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10
+
+ Spree.admin.tables.customer_returns.add :created_at,
+ label: :created_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20
+
+ Spree.admin.tables.customer_returns.add :customer,
+ label: :customer,
+ type: :custom,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 30,
+ partial: 'spree/admin/orders/customer_summary',
+ partial_locals: ->(record) { { order: record.order } }
+
+ Spree.admin.tables.customer_returns.add :order,
+ label: :order,
+ type: :string,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 40,
+ method: ->(cr) { cr.order&.number }
+
+ Spree.admin.tables.customer_returns.add :reimbursement_status,
+ label: :reimbursement_status,
+ type: :status,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 50,
+ method: ->(cr) { cr.fully_reimbursed? ? 'reimbursed' : 'incomplete' }
+
+ Spree.admin.tables.customer_returns.add :pre_tax_total,
+ label: :pre_tax_total,
+ type: :currency,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 60,
+ method: ->(cr) { cr.display_pre_tax_total }
+
+ # Register Option Types table
+ Spree.admin.tables.register(:option_types, model_class: Spree::OptionType, search_param: :name_cont)
+
+ Spree.admin.tables.option_types.add :name,
+ label: :internal_name,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10,
+ method: ->(ot) { ot.name }
+
+ Spree.admin.tables.option_types.add :presentation,
+ label: :presentation,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20
+
+ Spree.admin.tables.option_types.add :filterable,
+ label: :filterable,
+ type: :boolean,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 30
+
+ Spree.admin.tables.option_types.add :option_values_count,
+ label: :option_values,
+ type: :number,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 40,
+ method: ->(ot) { ot.option_values.count }
+
+ Spree.admin.tables.option_types.add :products_count,
+ label: :products,
+ type: :number,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 50,
+ method: ->(ot) { ot.products.count }
+
+ # Register Newsletter Subscribers table
+ Spree.admin.tables.register(:newsletter_subscribers, model_class: Spree::NewsletterSubscriber, search_param: :email_cont, row_actions_edit: false, row_actions_delete: true)
+
+ Spree.admin.tables.newsletter_subscribers.add :email,
+ label: :email,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10
+
+ Spree.admin.tables.newsletter_subscribers.add :customer,
+ label: :customer,
+ type: :custom,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 20,
+ partial: 'spree/admin/shared/user',
+ partial_locals: ->(record) { { user: record.user } }
+
+ Spree.admin.tables.newsletter_subscribers.add :verified,
+ label: :verified,
+ type: :boolean,
+ sortable: false,
+ filterable: true,
+ default: true,
+ position: 30,
+ method: ->(ns) { ns.verified? }
+
+ Spree.admin.tables.newsletter_subscribers.add :verified_at,
+ label: :verified_at,
+ type: :date,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 40
+
+ Spree.admin.tables.newsletter_subscribers.add :created_at,
+ label: :created_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 50
+
+ # Register Policies table
+ Spree.admin.tables.register(:policies, model_class: Spree::Policy, search_param: :name_cont)
+
+ Spree.admin.tables.policies.add :name,
+ label: :name,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10
+
+ Spree.admin.tables.policies.add :slug,
+ label: :slug,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20
+
+ Spree.admin.tables.policies.add :filled,
+ label: :filled,
+ type: :boolean,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 30,
+ method: ->(policy) { policy.with_body? }
+
+ Spree.admin.tables.policies.add :updated_at,
+ label: :updated_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 40
+
+ Spree.admin.tables.policies.add :owner,
+ label: 'activerecord.attributes.spree/policy.owner',
+ type: :string,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 50,
+ method: ->(policy) { policy.owner.name }
+
+ # Register Stock Transfers table
+ Spree.admin.tables.register(:stock_transfers, model_class: Spree::StockTransfer, search_param: :number_or_reference_cont)
+
+ Spree.admin.tables.stock_transfers.add :number,
+ label: :number,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10
+
+ Spree.admin.tables.stock_transfers.add :reference,
+ label: :reference,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20
+
+ Spree.admin.tables.stock_transfers.add :source,
+ label: :source,
+ type: :string,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 30,
+ method: ->(st) { st.source_location&.display_name.presence || Spree.t(:none) }
+
+ Spree.admin.tables.stock_transfers.add :destination,
+ label: :destination,
+ type: :string,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 40,
+ method: ->(st) { st.destination_location.display_name }
+
+ Spree.admin.tables.stock_transfers.add :variants_count,
+ label: :variants_count,
+ type: :number,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 50,
+ method: ->(st) { st.destination_movements.size }
+
+ Spree.admin.tables.stock_transfers.add :created_at,
+ label: :created_at,
+ type: :datetime,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 60
+
+ # Register Metafield Definitions table
+ Spree.admin.tables.register(:metafield_definitions, model_class: Spree::MetafieldDefinition, search_param: :multi_search)
+
+ Spree.admin.tables.metafield_definitions.add :key,
+ label: :key,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10,
+ method: ->(md) { md.full_key }
+
+ Spree.admin.tables.metafield_definitions.add :name,
+ label: :name,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20
+
+ Spree.admin.tables.metafield_definitions.add :resource,
+ label: :resource,
+ type: :string,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 30,
+ ransack_attribute: 'resource_type',
+ method: ->(md) { md.resource_type.demodulize.titleize }
+
+ Spree.admin.tables.metafield_definitions.add :type,
+ label: :type,
+ type: :status,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 40,
+ method: ->(md) { md.metafield_type.demodulize.titleize }
+
+ Spree.admin.tables.metafield_definitions.add :display_on,
+ label: :display_on,
+ type: :custom,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 50,
+ partial: 'spree/admin/tables/columns/metafield_definition_display_on'
+
+ Spree.admin.tables.metafield_definitions.add :used_in,
+ label: 'admin.metafield_definitions.used_in',
+ type: :string,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 60,
+ method: ->(md) {
+ count = md.metafields.count
+ if count.positive?
+ "#{count} #{Spree.t(md.resource_type.demodulize.pluralize.to_sym)}"
+ else
+ Spree.t(:not_available)
+ end
+ }
+
+ # Register Gift Cards table
+ Spree.admin.tables.register(:gift_cards, model_class: Spree::GiftCard, search_param: :code_i_cont, row_actions: false)
+
+ Spree.admin.tables.gift_cards.add :code,
+ label: :code,
+ type: :link,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 10,
+ method: ->(gc) { gc.code.upcase }
+
+ Spree.admin.tables.gift_cards.add :amount,
+ label: :amount,
+ type: :currency,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 20,
+ method: ->(gc) { gc.display_amount }
+
+ Spree.admin.tables.gift_cards.add :used,
+ label: :used,
+ type: :currency,
+ sortable: false,
+ filterable: false,
+ default: true,
+ position: 30,
+ method: ->(gc) { gc.display_amount_used }
+
+ Spree.admin.tables.gift_cards.add :currency,
+ label: :currency,
+ type: :string,
+ sortable: true,
+ filterable: false,
+ default: true,
+ position: 40,
+ method: ->(gc) { gc.currency.upcase }
+
+ Spree.admin.tables.gift_cards.add :status,
+ label: :status,
+ type: :custom,
+ sortable: false,
+ filterable: true,
+ default: true,
+ position: 50,
+ ransack_attribute: 'state',
+ partial: 'spree/admin/tables/columns/gift_card_status'
+
+ Spree.admin.tables.gift_cards.add :expires_at,
+ label: :expires_at,
+ type: :date,
+ sortable: true,
+ filterable: true,
+ default: true,
+ position: 60
+
+ Spree.admin.tables.gift_cards.add :customer,
+ label: :customer,
+ type: :string,
+ filter_type: :autocomplete,
+ sortable: false,
+ filterable: true,
+ default: true,
+ position: 70,
+ ransack_attribute: 'user_id',
+ operators: %i[eq],
+ search_url: '/admin/users/select_options.json',
+ method: ->(gc) { gc.user&.email }
+end
diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.yml
index bdee044f42..fde73bf504 100644
--- a/admin/config/locales/en.yml
+++ b/admin/config/locales/en.yml
@@ -338,7 +338,7 @@ en:
subscriptions: Subscriptions
time_of_last_event: Time of Last Event
webhooks_events: Webhooks Events
- record_lists:
+ tables:
add_filter: Add filter
add_or_group: Add OR group
apply: Apply
diff --git a/admin/config/routes.rb b/admin/config/routes.rb
index 56e1e9161e..b441971486 100644
--- a/admin/config/routes.rb
+++ b/admin/config/routes.rb
@@ -233,8 +233,8 @@ Spree::Core::Engine.add_routes do
get '/errors/:path', to: 'errors#show', as: :pathed_errors
end
- # record list columns (for session-based column selection)
- post 'record_list_columns', to: 'record_list_columns#update', as: :record_list_columns
+ # table columns (for session-based column selection)
+ post 'table_columns', to: 'table_columns#update', as: :table_columns
# dashboard
resource :dashboard, controller: 'dashboard'
diff --git a/admin/lib/spree/admin.rb b/admin/lib/spree/admin.rb
index cb57e17cdb..8cb23f71e4 100644
--- a/admin/lib/spree/admin.rb
+++ b/admin/lib/spree/admin.rb
@@ -38,8 +38,8 @@ module Spree
Rails.application.config.spree_admin.navigation
end
- def record_lists
- Rails.application.config.spree_admin.record_lists
+ def tables
+ Rails.application.config.spree_admin.tables
end
end
end
diff --git a/admin/lib/spree/admin/engine.rb b/admin/lib/spree/admin/engine.rb
index d9a95ccea1..c70c0aefe5 100644
--- a/admin/lib/spree/admin/engine.rb
+++ b/admin/lib/spree/admin/engine.rb
@@ -127,7 +127,7 @@ module Spree
:zones_actions_partials,
:zones_header_partials,
:navigation,
- :record_lists
+ :tables
)
class NavigationEnvironment
@@ -179,45 +179,56 @@ module Spree
end
end
- class RecordListsEnvironment
+ class TablesEnvironment
def initialize
@registries = {}
end
- # Register a new record list
- # @param name [Symbol] The name of the record list (e.g., :products, :orders)
- # @param model_class [Class, nil] The model class for this list
+ # Register a new table
+ # @param name [Symbol] The name of the table (e.g., :products, :orders)
+ # @param model_class [Class, nil] The model class for this table
# @param search_param [Symbol] The ransack parameter for text search (default: :name_cont)
# @param search_placeholder [String, nil] Custom placeholder for search field
- # @return [Spree::Admin::RecordList] The record list instance
- def register(name, model_class: nil, search_param: :name_cont, search_placeholder: nil)
+ # @param row_actions [Boolean] Whether to show row actions (default: true)
+ # @param row_actions_edit [Boolean] Whether to show edit button in row actions (default: true)
+ # @param row_actions_delete [Boolean] Whether to show delete button in row actions (default: false)
+ # @return [Spree::Admin::Table] The table instance
+ def register(name, model_class: nil, search_param: :name_cont, search_placeholder: nil, row_actions: true, row_actions_edit: true, row_actions_delete: false)
name = name.to_sym
- @registries[name] ||= Spree::Admin::RecordList.new(name, model_class: model_class, search_param: search_param, search_placeholder: search_placeholder)
+ @registries[name] ||= Spree::Admin::Table.new(
+ name,
+ model_class: model_class,
+ search_param: search_param,
+ search_placeholder: search_placeholder,
+ row_actions: row_actions,
+ row_actions_edit: row_actions_edit,
+ row_actions_delete: row_actions_delete
+ )
end
- # Get a registered record list
- # @param name [Symbol] The name of the record list
- # @return [Spree::Admin::RecordList] The record list instance
- # @raise [NoMethodError] if the record list hasn't been registered
+ # Get a registered table
+ # @param name [Symbol] The name of the table
+ # @return [Spree::Admin::Table] The table instance
+ # @raise [NoMethodError] if the table hasn't been registered
def get(name)
name = name.to_sym
- @registries[name] || raise(NoMethodError, "Record list '#{name}' has not been registered. Use Spree.admin.record_lists.register(:#{name}) first.")
+ @registries[name] || raise(NoMethodError, "Table '#{name}' has not been registered. Use Spree.admin.tables.register(:#{name}) first.")
end
- # Check if a record list is registered
- # @param name [Symbol] The record list name
+ # Check if a table is registered
+ # @param name [Symbol] The table name
# @return [Boolean]
def registered?(name)
@registries.key?(name.to_sym)
end
- # List all registered record lists
+ # List all registered tables
# @return [Array<Symbol>]
def registries
@registries.keys
end
- # Define accessor methods for registered record lists
+ # Define accessor methods for registered tables
def method_missing(method_name, *args)
if method_name.to_s.end_with?('=')
super
@@ -308,8 +319,8 @@ module Spree
app.config.spree_admin.navigation.register_context(:developers_tabs)
app.config.spree_admin.navigation.register_context(:audit_tabs)
- # Register record lists environment
- app.config.spree_admin.record_lists = RecordListsEnvironment.new
+ # Register tables environment
+ app.config.spree_admin.tables = TablesEnvironment.new
end
# Add admin event subscribers