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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Admin Navigation system (#13288)
Damian Legawiec406e1c6ed1a9
diff --git a/admin/app/helpers/spree/admin/navigation_helper.rb b/admin/app/helpers/spree/admin/navigation_helper.rbindex 569282a484..9589837bbb 100644--- a/admin/app/helpers/spree/admin/navigation_helper.rb+++ b/admin/app/helpers/spree/admin/navigation_helper.rb@@ -7,15 +7,15 @@ module Spree# @param [String, nil] icon Optional icon name to prepend to the label# @param [Boolean, nil] active Whether the link should be marked as active# @return [SafeBuffer] The navigation item HTML- def nav_item(label = nil, url, icon: nil, active: nil, data: {})+ def nav_item(label = nil, url, icon: nil, active: nil, data: {}, **options)content_tag :li, class: 'nav-item', role: 'presentation' doif block_given?- active_link_to url, class: 'nav-link', active: active, data: data do+ active_link_to url, class: 'nav-link', active: active, data: data, **options doyieldendelselabel = icon(icon) + label if icon.present? && label.present?- active_link_to label, url, class: 'nav-link', active: active, data: data+ active_link_to label, url, class: 'nav-link', active: active, data: data, **optionsendendend@@ -312,6 +312,78 @@ module Spreeicon(@breadcrumb_icon)endend++ # Renders the navigation for the given context+ # @param context [Symbol] the navigation context (:sidebar, :settings, etc.)+ # @param options [Hash] additional options for rendering+ # @return [String] the rendered navigation HTML+ def render_navigation(context = :sidebar, **options)+ return '' if Spree::Admin::RuntimeConfig.legacy_sidebar_navigation++ items = navigation_items(context)+ return '' if items.empty?++ render 'spree/admin/shared/navigation',+ items: items,+ context: context,+ **options+ end++ # Get navigation items for the given context+ # @param context [Symbol] the navigation context+ # @return [Array<Spree::Admin::Navigation::Item>] the visible navigation items+ def navigation_items(context = :sidebar)+ # Pass the view context (self) so that can? and other helpers are available+ Spree::Admin::Navigation.visible_items(context, self)+ end++ # Get the current navigation context based on the current page+ # @return [Symbol] the current navigation context+ def current_navigation_context+ settings_area? ? :settings : :sidebar+ end++ # Check if a specific navigation item is active+ # @param key [Symbol] the navigation item key+ # @param context [Symbol] the navigation context+ # @return [Boolean] whether the navigation item is active+ def navigation_item_active?(key, context = current_navigation_context)+ item = Spree::Admin::Navigation.for(context).find(key)+ item&.active?(request.path, self)+ end++ # Get the active navigation item for the current path+ # @param context [Symbol] the navigation context+ # @return [Spree::Admin::Navigation::Item, nil] the active navigation item+ def active_navigation_item(context = current_navigation_context)+ Spree::Admin::Navigation.find_active_item(request.path, context, self)+ end++ # Get breadcrumbs from navigation for current path+ # @param context [Symbol] the navigation context+ # @return [Array<Spree::Admin::Navigation::Item>] the breadcrumb trail+ def navigation_breadcrumbs(context = current_navigation_context)+ Spree::Admin::Navigation.breadcrumbs_for(request.path, context, self)+ end++ # Renders page tab navigation for the given context+ # @param context [Symbol] the navigation context (:tax_tabs, :shipping_tabs, etc.)+ # @param options [Hash] additional options for rendering+ # @return [String] the rendered tab navigation HTML wrapped in content_for(:page_tabs)+ def render_tab_navigation(context, **options)+ items = navigation_items(context)+ return '' if items.empty?++ content_for :page_tabs do+ items.map do |item|+ item_url = item.resolve_url(self)+ item_label = item.resolve_label+ is_active = item.active?(request.path, self)++ nav_item(item_label, item_url, active: is_active)+ end.join.html_safe+ end+ endendendenddiff --git a/admin/app/models/spree/admin/navigation.rb b/admin/app/models/spree/admin/navigation.rbnew file mode 100644index 0000000000..4ff38a5387--- /dev/null+++ b/admin/app/models/spree/admin/navigation.rb@@ -0,0 +1,112 @@+module Spree+ module Admin+ class Navigation+ class << self+ # Store registries for different contexts+ def registries+ @registries ||= {}+ end++ # Get or create a registry for a context+ def registry(context = :sidebar)+ registries[context.to_sym] ||= Registry.new(context.to_sym)+ end++ # Configure navigation for a specific context+ def configure(context = :sidebar, &block)+ reg = registry(context)+ builder = Builder.new(reg)+ # Support both block styles: |nav| nav.add or just add+ if block_given?+ if block.arity > 0+ # Block expects parameter: do |nav| nav.add ... end+ block.call(builder)+ else+ # Block uses implicit self: do add ... end+ builder.instance_eval(&block)+ end+ end+ reg+ end++ # Get a registry for method chaining+ def for(context)+ registry(context)+ end++ # Delegate common methods to the default (sidebar) registry+ def add(key, **options, &block)+ registry(:sidebar).add(key, **options, &block)+ end++ def remove(key)+ registry(:sidebar).remove(key)+ end++ def update(key, **options)+ registry(:sidebar).update(key, **options)+ end++ def find(key)+ registry(:sidebar).find(key)+ end++ def exists?(key)+ registry(:sidebar).exists?(key)+ end++ def insert_before(target_key, new_key, **options)+ registry(:sidebar).insert_before(target_key, new_key, **options)+ end++ def insert_after(target_key, new_key, **options)+ registry(:sidebar).insert_after(target_key, new_key, **options)+ end++ def move(key, **position_options)+ registry(:sidebar).move(key, **position_options)+ end++ def replace(key, **options, &block)+ registry(:sidebar).replace(key, **options, &block)+ end++ def visible_items(context = :sidebar, user = nil)+ registry(context).visible_items(user)+ end++ def root_items(context = :sidebar)+ registry(context).root_items+ end++ def breadcrumbs_for(current_path, context = :sidebar, view_context = nil)+ registry(context).breadcrumbs_for(current_path, view_context)+ end++ def find_active_item(current_path, context = :sidebar, view_context = nil)+ registry(context).find_active_item(current_path, view_context)+ end++ # Get all available contexts+ def contexts+ registries.keys+ end++ # Clear all registries (useful for testing)+ def clear_all!+ @registries = {}+ end++ # Clear a specific context+ def clear!(context = :sidebar)+ registry(context).clear+ end+ end+ end+ end+end++# Require the sub-classes+require_relative 'navigation/item'+require_relative 'navigation/registry'+require_relative 'navigation/builder'diff --git a/admin/app/models/spree/admin/navigation/builder.rb b/admin/app/models/spree/admin/navigation/builder.rbnew file mode 100644index 0000000000..87795e4c7f--- /dev/null+++ b/admin/app/models/spree/admin/navigation/builder.rb@@ -0,0 +1,82 @@+module Spree+ module Admin+ class Navigation+ class Builder+ attr_reader :registry, :parent_item++ def initialize(registry, parent_item = nil)+ @registry = registry+ @parent_item = parent_item+ end++ # Add a navigation item+ # If parent_item is set, the item becomes a child+ def add(key, **options, &block)+ # If we have a parent item, set it in the options+ if parent_item+ options[:parent] = parent_item.key+ # Adjust position to be relative to parent+ options[:position] ||= parent_item.children.size * 10+ end++ item = registry.add(key, **options, &block)+ item+ end++ # Add a section (group of items)+ def section(key, label: nil, &block)+ section_item = add(key, section_label: label || key.to_s.humanize)++ if block_given?+ builder = self.class.new(registry, section_item)+ # Support both block styles: |nav| nav.add or just add+ if block.arity > 0+ # Block expects parameter: do |nav| nav.add ... end+ block.call(builder)+ else+ # Block uses implicit self: do add ... end+ builder.instance_eval(&block)+ end+ end++ section_item+ end++ # Remove an item+ def remove(key)+ registry.remove(key)+ end++ # Update an item+ def update(key, **options)+ registry.update(key, **options)+ end++ # Insert before another item+ def insert_before(target_key, new_key, **options)+ registry.insert_before(target_key, new_key, **options)+ end++ # Insert after another item+ def insert_after(target_key, new_key, **options)+ registry.insert_after(target_key, new_key, **options)+ end++ # Move an item+ def move(key, **position_options)+ registry.move(key, **position_options)+ end++ # Replace an item+ def replace(key, **options, &block)+ registry.replace(key, **options, &block)+ end++ # Reorder items with a block+ def reorder(&block)+ instance_eval(&block) if block_given?+ end+ end+ end+ end+enddiff --git a/admin/app/models/spree/admin/navigation/item.rb b/admin/app/models/spree/admin/navigation/item.rbnew file mode 100644index 0000000000..ae0f4fa2b9--- /dev/null+++ b/admin/app/models/spree/admin/navigation/item.rb@@ -0,0 +1,174 @@+module Spree+ module Admin+ class Navigation+ class Item+ attr_accessor :key, :label, :url, :icon, :position, :parent_key,+ :condition, :badge, :badge_class, :tooltip, :target, :data_attributes, :children, :section_label, :active_condition++ def initialize(key, **options)+ @key = key.to_sym+ @label = options[:label]+ @url = options[:url]+ @icon = options[:icon]+ @position = options[:position] || 999+ @parent_key = options[:parent]+ @active_condition = options[:active]+ @condition = options.key?(:if) ? options[:if] : options[:condition]+ @badge = options[:badge]+ @badge_class = options[:badge_class]+ @tooltip = options[:tooltip]+ @target = options[:target]+ @data_attributes = options[:data_attributes] || {}+ @section_label = options[:section_label]+ @children = []+ end++ # Check if this item should be visible for the given user/context+ # @param user_or_context [Object] Either a user object or a view context+ def visible?(user_or_context = nil)+ return true if condition.nil?++ if condition.respond_to?(:call)+ # If we have a view context with instance_exec, use it to evaluate the condition+ # This allows access to can? and other helper methods+ if user_or_context.respond_to?(:instance_exec)+ user_or_context.instance_exec(&condition)+ else+ # Otherwise, call with the user object+ condition.call(user_or_context)+ end+ else+ condition+ end+ end++ # Check if this item is active based on current path+ # @param current_path [String] The current request path+ # @param context [Object] View context with access to route helpers+ def active?(current_path, context = nil)+ # Use custom active condition if provided (most flexible)+ if active_condition.respond_to?(:call)+ if context&.respond_to?(:instance_exec)+ return context.instance_exec(&active_condition)+ else+ return active_condition.call+ end+ end++ # Match exact path+ item_url = resolve_url(context)+ return true if item_url && current_path == item_url++ # Default: match if path starts with url (handled by active_link_to)+ if item_url+ current_path.start_with?(item_url)+ else+ false+ end+ end++ # Resolve URL (handles symbols, procs, and strings)+ # @param context [Object] View context with access to route helpers+ def resolve_url(context = nil)+ case url+ when Symbol+ # Try to call the route helper on the context (which has spree routes)+ if context&.respond_to?(url)+ context.send(url)+ elsif context&.respond_to?(:spree)+ context.spree.send(url) rescue url.to_s+ else+ url.to_s+ end+ when Proc+ # Evaluate proc in the context where route helpers are available+ if context&.respond_to?(:instance_exec)+ context.instance_exec(&url)+ else+ url.call+ end+ else+ url+ end+ end++ # Resolve label (handles i18n keys)+ def resolve_label+ return label unless label.is_a?(String) || label.is_a?(Symbol)++ # Use Spree.t for translation which handles the spree namespace+ Spree.t(label, default: label.to_s.humanize)+ end++ # Compute badge value+ # @param view_context [Object] View context with access to helper methods+ def badge_value(view_context = nil)+ return nil unless badge++ if badge.respond_to?(:call)+ # Evaluate badge in view context if available (for access to helpers)+ if view_context&.respond_to?(:instance_exec)+ view_context.instance_exec(&badge)+ else+ badge.call+ end+ else+ badge+ end+ end++ # Check if this is a section header+ def section?+ section_label.present?+ end++ # Add a child item+ def add_child(item)+ children << item+ item.parent_key = key+ sort_children!+ end++ # Remove a child item+ def remove_child(key)+ children.reject! { |child| child.key == key }+ end++ # Sort children by position+ def sort_children!+ children.sort_by! { |child| [child.position, child.key.to_s] }+ end++ # Deep clone for modifications+ def deep_clone+ cloned = self.class.new(key, to_h)+ cloned.children = children.map(&:deep_clone)+ cloned+ end++ # Convert to hash+ def to_h+ {+ label: label,+ url: url,+ icon: icon,+ position: position,+ parent: parent_key,+ active: active_condition,+ condition: condition,+ badge: badge,+ badge_class: badge_class,+ tooltip: tooltip,+ target: target,+ data_attributes: data_attributes,+ section_label: section_label+ }+ end++ def inspect+ "#<Spree::Admin::Navigation::Item key=#{key} label=#{label} children=#{children.size}>"+ end+ end+ end+ end+enddiff --git a/admin/app/models/spree/admin/navigation/registry.rb b/admin/app/models/spree/admin/navigation/registry.rbnew file mode 100644index 0000000000..afcdd089c2--- /dev/null+++ b/admin/app/models/spree/admin/navigation/registry.rb@@ -0,0 +1,220 @@+module Spree+ module Admin+ class Navigation+ class Registry+ attr_reader :items, :context++ def initialize(context)+ @context = context+ @items = {}+ end++ # Add a navigation item+ def add(key, **options, &block)+ key = key.to_sym+ item = Item.new(key, **options)++ @items[key] = item++ # If block provided, it's for children+ if block_given?+ builder = Builder.new(self, item)+ # Support both block styles: |nav| nav.add or just add+ if block.arity > 0+ # Block expects parameter: do |nav| nav.add ... end+ block.call(builder)+ else+ # Block uses implicit self: do add ... end+ builder.instance_eval(&block)+ end+ end++ sort_items!+ item+ end++ # Remove a navigation item+ def remove(key)+ key = key.to_sym+ removed = @items.delete(key)++ # Also remove from any parent's children+ @items.each_value do |item|+ item.remove_child(key)+ end++ removed+ end++ # Update an existing navigation item+ def update(key, **options)+ key = key.to_sym+ item = @items[key]++ return nil unless item++ options.each do |attr, value|+ item.send("#{attr}=", value) if item.respond_to?("#{attr}=")+ end++ sort_items!+ item+ end++ # Find a navigation item+ def find(key)+ @items[key.to_sym]+ end++ # Check if item exists+ def exists?(key)+ @items.key?(key.to_sym)+ end++ # Insert item before another item+ def insert_before(target_key, new_key, **options)+ target = find(target_key)+ return nil unless target++ new_position = target.position - 1+ add(new_key, **options.merge(position: new_position))+ end++ # Insert item after another item+ def insert_after(target_key, new_key, **options)+ target = find(target_key)+ return nil unless target++ new_position = target.position + 1+ add(new_key, **options.merge(position: new_position))+ end++ # Move item to a new position+ def move(key, position: nil, before: nil, after: nil)+ item = find(key)+ return nil unless item++ if before+ target = find(before)+ item.position = target.position - 1 if target+ elsif after+ target = find(after)+ item.position = target.position + 1 if target+ elsif position == :first+ item.position = -999+ elsif position == :last+ item.position = 999+ elsif position.is_a?(Integer)+ item.position = position+ end++ sort_items!+ item+ end++ # Replace an item+ def replace(key, **options, &block)+ remove(key)+ add(key, **options, &block)+ end++ # Get all root items (items without a parent)+ def root_items+ @items.values.select { |item| item.parent_key.nil? }.sort_by { |item| [item.position, item.key.to_s] }+ end++ # Get all items that are visible to the user+ def visible_items(user = nil, parent_key = nil)+ items_to_filter = if parent_key+ find(parent_key)&.children || []+ else+ root_items+ end++ items_to_filter.select { |item| item.visible?(user) }+ end++ # Build tree structure+ def build_tree+ # First, clear all children+ @items.each_value { |item| item.children.clear }++ # Then rebuild the tree+ @items.each_value do |item|+ if item.parent_key && (parent = @items[item.parent_key])+ parent.add_child(item)+ end+ end++ root_items+ end++ # Get breadcrumb trail for a path+ def breadcrumbs_for(current_path, context = nil)+ breadcrumbs = []++ # Find active item+ active_item = find_active_item(current_path, context)++ # Build breadcrumb trail+ while active_item+ breadcrumbs.unshift(active_item)+ active_item = active_item.parent_key ? find(active_item.parent_key) : nil+ end++ breadcrumbs+ end++ # Find the active item for current path+ def find_active_item(current_path, context = nil)+ # Check all items, deepest match wins+ active_items = @items.values.select { |item| item.active?(current_path, context) }++ # Return the one with the longest URL match+ active_items.max_by { |item| item.resolve_url(context)&.length || 0 }+ end++ # Clear all items+ def clear+ @items.clear+ end++ # Get all registered paths (for settings_area? detection)+ def registered_paths(context = nil)+ @items.values.map { |item| item.resolve_url(context) }.compact+ end++ # Add a section+ def section(key, label: nil, &block)+ # Create a section header item+ section_item = add(key, section_label: label || key.to_s.humanize, position: @items.size * 100)++ if block_given?+ builder = Builder.new(self, section_item)+ builder.instance_eval(&block)+ end++ section_item+ end++ # Deep clone the registry+ def deep_clone+ cloned = self.class.new(context)+ @items.each do |key, item|+ cloned.items[key] = item.deep_clone+ end+ cloned.build_tree+ cloned+ end++ private++ def sort_items!+ # Sort items by position, then rebuild tree+ @items = @items.sort_by { |_key, item| [item.position, item.key.to_s] }.to_h+ build_tree+ end+ end+ end+ end+enddiff --git a/admin/app/views/spree/admin/shared/_audit_nav.html.erb b/admin/app/views/spree/admin/shared/_audit_nav.html.erbindex 2498741227..8a8dc2fd61 100644--- a/admin/app/views/spree/admin/shared/_audit_nav.html.erb+++ b/admin/app/views/spree/admin/shared/_audit_nav.html.erb@@ -1,3 +1,5 @@<% content_for :page_title do %><%= Spree.t('admin.audit_log') %><% end %>++<%= render_tab_navigation(:audit_tabs) %>diff --git a/admin/app/views/spree/admin/shared/_developers_nav.html.erb b/admin/app/views/spree/admin/shared/_developers_nav.html.erbindex cde223c2ed..57636cf995 100644--- a/admin/app/views/spree/admin/shared/_developers_nav.html.erb+++ b/admin/app/views/spree/admin/shared/_developers_nav.html.erb@@ -1,7 +1,5 @@<%= content_for :page_title do %><%= Spree.t(:developers) %><% end %>-<%= content_for :page_tabs do %>- <%= nav_item(Spree.t(:api_keys), spree.admin_oauth_applications_path) if can?(:manage, Spree::OauthApplication) %>- <%= nav_item(Spree.t(:webhooks), spree.admin_webhooks_subscribers_path) if can?(:manage, Spree::Webhooks::Subscriber) %>-<% end %>++<%= render_tab_navigation(:developers_tabs) %>diff --git a/admin/app/views/spree/admin/shared/_navigation.html.erb b/admin/app/views/spree/admin/shared/_navigation.html.erbnew file mode 100644index 0000000000..d73f1c1e01--- /dev/null+++ b/admin/app/views/spree/admin/shared/_navigation.html.erb@@ -0,0 +1,5 @@+<ul class="nav flex-column">+ <% items.each do |item| %>+ <%= render 'spree/admin/shared/navigation_item', item: item, context: context %>+ <% end %>+</ul>diff --git a/admin/app/views/spree/admin/shared/_navigation_item.html.erb b/admin/app/views/spree/admin/shared/_navigation_item.html.erbnew file mode 100644index 0000000000..7b64fbc289--- /dev/null+++ b/admin/app/views/spree/admin/shared/_navigation_item.html.erb@@ -0,0 +1,53 @@+<%+ # Resolve item properties (pass self as context for route helpers)+ item_url = item.resolve_url(self)+ item_label = item.resolve_label+ badge_value = item.badge_value(self)+ is_active = item.active?(request.path, self)+ has_children = item.children.present?+ tooltip_text = item.tooltip++ # Build data attributes - only add tooltip controller if tooltip is present+ data_attrs = item.data_attributes.dup+ if tooltip_text.present?+ data_attrs[:controller] = 'tooltip'+ end++ # Build additional HTML options (like target)+ html_options = {}+ html_options[:target] = item.target if item.target.present?++ # Build complete label with badge (like old menu pattern)+ complete_label = item_label+ if badge_value.present?+ badge_class = item.badge_class.presence || 'badge-light'+ complete_label += content_tag(:span, badge_value, class: "badge ml-auto #{badge_class}")+ end+ # Add tooltip if present+ if tooltip_text.present?+ complete_label += tooltip(tooltip_text)+ end+ complete_label = complete_label.html_safe+%>++<% if item.section? %>+ <%# Section header %>+ <li class="nav-item nav-section-header mt-3">+ <span class="text-muted text-uppercase small"><%= item.section_label %></span>+ </li>+<% else %>+ <% if has_children %>+ <%# Item with children (submenu shows when parent is active) %>+ <%= nav_item(complete_label, item_url, icon: item.icon, active: is_active, data: data_attrs, **html_options) %>+ <% if is_active %>+ <ul class="nav-submenu">+ <% item.children.select { |child| child.visible?(self) }.each do |child_item| %>+ <%= render 'spree/admin/shared/navigation_item', item: child_item, context: context %>+ <% end %>+ </ul>+ <% end %>+ <% else %>+ <%# Regular item without children %>+ <%= nav_item(complete_label, item_url, icon: item.icon, active: is_active, data: data_attrs, **html_options) %>+ <% end %>+<% end %>diff --git a/admin/app/views/spree/admin/shared/_returns_and_refunds_nav.html.erb b/admin/app/views/spree/admin/shared/_returns_and_refunds_nav.html.erbindex f8293e0b9e..098fd89cce 100644--- a/admin/app/views/spree/admin/shared/_returns_and_refunds_nav.html.erb+++ b/admin/app/views/spree/admin/shared/_returns_and_refunds_nav.html.erb@@ -2,9 +2,8 @@<%= Spree.t(:returns) %> & <%= Spree.t(:refunds) %><% end %>+<%= render_tab_navigation(:returns_tabs) %>+<% content_for(:page_tabs) do %>- <%= nav_item(Spree.t(:return_authorization_reasons), spree.admin_return_authorization_reasons_path) if can?(:manage, Spree::ReturnAuthorizationReason) %>- <%= nav_item(Spree.t(:refund_reasons), spree.admin_refund_reasons_path) if can?(:manage, Spree::RefundReason) %>- <%= nav_item(Spree.t(:reimbursement_types), spree.admin_reimbursement_types_path) if can?(:manage, Spree::ReimbursementType) %><%= render_admin_partials(:returns_and_refunds_nav_partials) %><% end %>diff --git a/admin/app/views/spree/admin/shared/_shipping_nav.html.erb b/admin/app/views/spree/admin/shared/_shipping_nav.html.erbindex fc4a2cd763..56813d573d 100644--- a/admin/app/views/spree/admin/shared/_shipping_nav.html.erb+++ b/admin/app/views/spree/admin/shared/_shipping_nav.html.erb@@ -1,5 +1,6 @@+<%= render_tab_navigation(:shipping_tabs) %>+<%= content_for(:page_tabs) do %>- <%= nav_item(Spree.t(:shipping_methods), spree.admin_shipping_methods_path, active: controller_name == 'shipping_methods' && action_name == 'index') if can?(:manage, Spree::ShippingMethod) %>- <%= nav_item(Spree.t(:shipping_categories), spree.admin_shipping_categories_path) if can?(:manage, Spree::ShippingCategory) %><%= render_admin_partials(:shipping_nav_partials) %><% end %>+diff --git a/admin/app/views/spree/admin/shared/_stock_nav.html.erb b/admin/app/views/spree/admin/shared/_stock_nav.html.erbindex 56af3e7099..46a15e1583 100644--- a/admin/app/views/spree/admin/shared/_stock_nav.html.erb+++ b/admin/app/views/spree/admin/shared/_stock_nav.html.erb@@ -1,3 +1,6 @@-<%= nav_item(Spree.t(:stock_items), spree.admin_stock_items_path) if can?(:manage, Spree::StockItem) %>-<%= nav_item(Spree.t(:stock_transfers), spree.admin_stock_transfers_path) if can?(:manage, Spree::StockTransfer) %>-<%= render_admin_partials(:stock_nav_partials) %>+<%= render_tab_navigation(:stock_tabs) %>++<%= content_for(:page_tabs) do %>+ <%= render_admin_partials(:stock_nav_partials) %>+<% end %>+diff --git a/admin/app/views/spree/admin/shared/_tax_nav.html.erb b/admin/app/views/spree/admin/shared/_tax_nav.html.erbindex 2d0f0d2385..29fefdbb6f 100644--- a/admin/app/views/spree/admin/shared/_tax_nav.html.erb+++ b/admin/app/views/spree/admin/shared/_tax_nav.html.erb@@ -1,5 +1,4 @@+<%= render_tab_navigation(:tax_tabs) %><%= content_for(:page_tabs) do %>- <%= nav_item(Spree.t(:tax_rates), spree.admin_tax_rates_path) if can?(:manage, Spree::TaxRate) %>- <%= nav_item(Spree.t(:tax_categories), spree.admin_tax_categories_path) if can?(:manage, Spree::TaxCategory) %><%= render_admin_partials(:tax_nav_partials) %><% end %>diff --git a/admin/app/views/spree/admin/shared/_team_nav.html.erb b/admin/app/views/spree/admin/shared/_team_nav.html.erbindex 34770dc172..c95ba7de58 100644--- a/admin/app/views/spree/admin/shared/_team_nav.html.erb+++ b/admin/app/views/spree/admin/shared/_team_nav.html.erb@@ -1,9 +1,8 @@<% content_for :page_title, Spree.t(:users) %>+<%= render_tab_navigation(:team_tabs) %>+<%= content_for(:page_tabs) do %>- <%= nav_item(Spree.t(:users), spree.admin_admin_users_path) if can?(:manage, Spree.admin_user_class) %>- <%= nav_item(Spree.t(:invitations), spree.admin_invitations_path) if can?(:manage, Spree::Invitation) %>- <%= nav_item(Spree.t(:roles), spree.admin_roles_path) if can?(:manage, Spree::Role) %><%= render_admin_partials(:team_nav_partials) %><% end %>diff --git a/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erbindex 16d0501cf0..e8aaf54955 100644--- a/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb+++ b/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb@@ -1,4 +1,6 @@-<% if settings_area? %>+<% if Spree::Admin::RuntimeConfig.legacy_sidebar_navigation %>+ <%# Legacy navigation system %>+ <% if settings_area? %><ul class="nav flex-column"><% if can?(:manage, current_store) %><%= nav_item(Spree.t(:store_details), spree.edit_admin_store_path(section: 'general-settings'), icon: 'building-store', active: params[:section] == 'general-settings') %>@@ -114,4 +116,16 @@<% end %></ul></div>+ <% end %>+<% else %>+ <%# New navigation system %>+ <% if settings_area? %>+ <%= render_navigation(:settings) %>+ <% else %>+ <%= render_navigation(:sidebar) %>++ <div class="mt-auto d-flex flex-column">+ <%= render 'spree/admin/shared/sidebar/enterprise_edition_notice' %>+ </div>+ <% end %><% end %>diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.ymlindex 3c1b05cf70..ccb1787b21 100644--- a/admin/config/locales/en.yml+++ b/admin/config/locales/en.yml@@ -298,6 +298,8 @@ en:compare_at_price_description: This price is used to show marked down price on the product page.stock_locations_link: To add more stock locations please go to <a href="%{link}">Stock Locations</a>total_inventory_html: 'Total inventory at %{stock_location} location: %{count} available'+ vendors:+ enterprise_feature: Multi-Vendor Marketplace is available in the Enterprise Editionwebhooks_subscribers:all_events: All Eventsnew_webhooks_subscriber: New Webhooks Subscriberdiff --git a/admin/lib/spree/admin/engine.rb b/admin/lib/spree/admin/engine.rbindex 851b122118..0f9598d0fc 100644--- a/admin/lib/spree/admin/engine.rb+++ b/admin/lib/spree/admin/engine.rb@@ -182,12 +182,19 @@ module Spreeendend+ initializer 'spree.admin.navigation', before: :load_config_initializers do+ # Navigation models will be autoloaded by Rails+ end+config.after_initialize doEnvironment.new.tap do |env|env.members.each do |key|Rails.application.config.spree_admin.send("#{key}=", [])endend++ # Load default navigation configuration+ require_relative 'navigation_config'endendenddiff --git a/admin/lib/spree/admin/navigation_config.rb b/admin/lib/spree/admin/navigation_config.rbnew file mode 100644index 0000000000..641099e68f--- /dev/null+++ b/admin/lib/spree/admin/navigation_config.rb@@ -0,0 +1,510 @@+# Default Admin Navigation Configuration+# This file defines the default sidebar and settings navigation for Spree Admin++Spree::Admin::Navigation.configure(:sidebar) do |nav|+ # Getting Started (onboarding)+ nav.add :getting_started,+ label: 'admin.getting_started',+ url: :admin_getting_started_path,+ icon: 'map',+ position: 5,+ if: -> { current_store && can?(:manage, current_store) && !current_store.setup_completed? },+ badge: -> { "#{current_store.setup_tasks_done}/#{current_store.setup_tasks_total}" },+ badge_class: 'badge-info',+ active: -> { controller_name == 'dashboard' && action_name == 'getting_started' }++ # Dashboard / Home+ nav.add :home,+ label: :home,+ url: :admin_path,+ icon: 'home',+ position: 10,+ active: -> { controller_name == 'dashboard' && action_name == 'show' }++ # Orders with submenu+ nav.add :orders,+ label: :orders,+ url: :admin_orders_path,+ icon: 'inbox',+ position: 20,+ active: -> { %w[orders checkouts].include?(controller_name) || @order&.present? || @parent&.is_a?(Spree::Order) },+ if: -> { can?(:manage, Spree::Order) },+ badge: -> {+ # Evaluated in view context with access to helper methods+ ready_to_ship_orders_count if ready_to_ship_orders_count&.positive?+ } do |orders|+ # Orders to Fulfill submenu+ orders.add :orders_to_fulfill,+ label: 'admin.orders.orders_to_fulfill',+ url: -> { spree.admin_orders_path(q: {shipment_state_not_in: [:shipped, :canceled]}) },+ position: 10,+ active: -> { controller_name == 'orders' && params.dig(:q, :shipment_state_not_in).present? },+ if: -> {+ ready_to_ship_orders_count&.positive?+ },+ badge: -> {+ ready_to_ship_orders_count if ready_to_ship_orders_count&.positive?+ }++ # Draft Orders+ orders.add :draft_orders,+ label: :draft_orders,+ url: :admin_checkouts_path,+ position: 20,+ active: -> { controller_name == 'checkouts' || (@order.present? && [email protected]?) },+ if: -> { can?(:manage, :checkouts) }+ end++ # Returns with submenu+ nav.add :returns,+ label: :returns,+ url: :admin_customer_returns_path,+ icon: 'receipt-refund',+ position: 25,+ active: -> { %w[customer_returns return_authorizations].include?(controller_name) },+ if: -> { can?(:manage, Spree::CustomerReturn) || can?(:manage, Spree::ReturnAuthorization) } do |returns|+ # Return Authorizations+ returns.add :return_authorizations,+ label: :return_authorizations,+ url: :admin_return_authorizations_path,+ position: 10,+ if: -> { can?(:manage, Spree::ReturnAuthorization) }+ end++ # Products with submenu+ nav.add :products,+ label: :products,+ url: :admin_products_path,+ icon: 'package',+ position: 30,+ active: -> { %w[products external_categories taxons taxonomies option_types option_values properties stock_items stock_transfers variants digital_assets].include?(controller_name) },+ if: -> { can?(:manage, Spree::Product) } do |products|+ # Stock+ products.add :stock,+ label: :stock,+ url: :admin_stock_items_path,+ position: 10,+ active: -> { %w[stock_items stock_transfers].include?(controller_name) },+ if: -> { can?(:manage, Spree::StockItem) || can?(:manage, Spree::StockTransfer) }++ # Taxonomies+ products.add :taxonomies,+ label: :taxonomies,+ url: :admin_taxonomies_path,+ position: 20,+ active: -> { %w[taxonomies taxons].include?(controller_name) },+ if: -> { can?(:manage, Spree::Taxonomy) && can?(:manage, Spree::Taxon) }++ # Options+ products.add :options,+ label: :options,+ url: :admin_option_types_path,+ position: 30,+ active: -> { %w[option_types option_values].include?(controller_name) },+ if: -> { can?(:manage, Spree::OptionType) }++ # Properties+ products.add :properties,+ label: :properties,+ url: :admin_properties_path,+ position: 40,+ if: -> { can?(:manage, Spree::Property) && Spree::Config.product_properties_enabled }+ end++ # Vendors (Enterprise Edition)+ nav.add :vendors,+ label: :vendors,+ url: 'https://spreecommerce.org/marketplace-ecommerce/',+ icon: 'heart-handshake',+ position: 35,+ if: -> { can?(:manage, current_store) && !defined?(SpreeEnterprise) },+ badge: 'Enterprise',+ tooltip: 'Multi-Vendor Marketplace is available in the Enterprise Edition',+ target: '_blank'++ # Customers with submenu+ nav.add :customers,+ label: :customers,+ url: :admin_users_path,+ icon: 'users',+ position: 40,+ active: -> { %w[users newsletter_subscribers].include?(controller_name) },+ if: -> { can?(:manage, Spree.user_class) } do |customers|+ # Newsletter Subscribers+ customers.add :newsletter_subscribers,+ label: :newsletter_subscribers,+ url: :admin_newsletter_subscribers_path,+ position: 10+ end++ # Promotions with submenu+ nav.add :promotions,+ label: :promotions,+ url: :admin_promotions_path,+ icon: 'discount',+ position: 50,+ active: -> { %w[promotions gift_cards gift_card_batches coupon_codes].include?(controller_name) },+ if: -> { can?(:manage, Spree::Promotion) } do |promotions|+ # Gift Cards+ promotions.add :gift_cards,+ label: :gift_cards,+ url: :admin_gift_cards_path,+ position: 10,+ active: -> { %w[gift_cards gift_card_batches].include?(controller_name) }+ end++ # Reports+ nav.add :reports,+ label: :reports,+ url: :admin_reports_path,+ icon: 'chart-bar',+ position: 60,+ if: -> { can?(:manage, Spree::Report) }++ # Storefront with submenu+ nav.add :storefront,+ label: 'admin.storefront',+ url: :admin_themes_path,+ icon: 'building-store',+ position: 70,+ active: -> { %w[themes posts post_categories pages].include?(controller_name) || (controller_name == 'storefronts' && action_name == 'edit') },+ if: -> { can?(:manage, Spree::Theme) } do |storefront|+ # Themes+ storefront.add :themes,+ label: :themes,+ url: :admin_themes_path,+ position: 10,+ if: -> { can?(:manage, Spree::Theme) }++ # Pages+ storefront.add :pages,+ label: :pages,+ url: :admin_pages_path,+ position: 20,+ if: -> { can?(:manage, Spree::Page) }++ # Posts (Blog)+ storefront.add :posts,+ label: :posts,+ url: :admin_posts_path,+ position: 30,+ active: -> { %w[posts post_categories].include?(controller_name) },+ if: -> { can?(:manage, Spree::Post) }++ # Storefront Settings+ storefront.add :storefront_settings,+ label: :settings,+ url: :edit_admin_storefront_path,+ position: 40,+ if: -> { can?(:manage, current_store) }+ end++ # Integrations+ nav.add :integrations,+ label: :integrations,+ url: :admin_integrations_path,+ icon: 'plug-connected',+ position: 80,+ if: -> { can?(:manage, Spree::Integration) }++ # Settings (bottom of sidebar)+ nav.add :settings,+ label: :settings,+ url: -> { spree.edit_admin_store_path(section: 'general-settings') },+ icon: 'settings',+ position: 100,+ if: -> { can?(:manage, current_store) }++ # Admin Users (bottom of sidebar)+ nav.add :admin_users,+ label: :users,+ url: :admin_admin_users_path,+ icon: 'users',+ position: 110,+ if: -> { can?(:manage, Spree.admin_user_class) }+end++# Settings Navigation+Spree::Admin::Navigation.configure(:settings) do |nav|+ # Store Details+ nav.add :general_settings,+ label: :store_details,+ url: -> { spree.edit_admin_store_path(section: 'general-settings') },+ icon: 'building-store',+ position: 10,+ active: -> { controller_name == 'stores' && params[:section] == 'general-settings' },+ if: -> { can?(:manage, current_store) }++ # Admin Users+ nav.add :users,+ label: :users,+ url: :admin_admin_users_path,+ icon: 'users',+ position: 20,+ active: -> { %w[admin_users invitations roles].include?(controller_name) },+ if: -> { can?(:manage, Spree.admin_user_class) }++ # Emails+ nav.add :emails,+ label: :emails,+ url: -> { spree.edit_admin_store_path(section: 'emails') },+ icon: 'send',+ position: 30,+ active: -> { controller_name == 'stores' && params[:section] == 'emails' },+ if: -> { can?(:manage, current_store) }++ # Policies+ nav.add :policies,+ label: :policies,+ url: :admin_policies_path,+ icon: 'list-check',+ position: 40,+ active: -> { controller_name == 'policies' },+ if: -> { can?(:manage, Spree::Policy) }++ # Checkout+ nav.add :checkout,+ label: :checkout,+ url: -> { spree.edit_admin_store_path(section: 'checkout') },+ icon: 'shopping-cart',+ position: 50,+ active: -> { controller_name == 'stores' && params[:section] == 'checkout' },+ if: -> { can?(:manage, current_store) }++ # Domains+ nav.add :domains,+ label: :domains,+ url: :admin_custom_domains_path,+ icon: 'world-www',+ position: 60,+ active: -> { controller_name == 'custom_domains' },+ if: -> { can?(:manage, Spree::CustomDomain) }++ # Payment Methods+ nav.add :payment_methods,+ label: :payments,+ url: :admin_payment_methods_path,+ icon: 'credit-card',+ position: 70,+ active: -> { controller_name == 'payment_methods' },+ if: -> { can?(:manage, Spree::PaymentMethod) }++ # Zones+ nav.add :zones,+ label: :zones,+ url: :admin_zones_path,+ icon: 'world',+ position: 80,+ active: -> { %w[zones countries states].include?(controller_name) },+ if: -> { can?(:manage, Spree::Zone) }++ # Shipping Methods+ nav.add :shipping_methods,+ label: :shipping,+ url: :admin_shipping_methods_path,+ icon: 'truck',+ position: 90,+ active: -> { %w[shipping_methods shipping_categories].include?(controller_name) },+ if: -> { can?(:manage, Spree::ShippingMethod) }++ # Tax Settings+ nav.add :tax_rates,+ label: :tax,+ url: :admin_tax_rates_path,+ icon: 'receipt-tax',+ position: 100,+ active: -> { %w[tax_rates tax_categories stripe_tax_registrations].include?(controller_name) },+ if: -> { can?(:manage, Spree::TaxRate) }++ # Returns+ nav.add :return_settings,+ label: :returns,+ url: :admin_return_authorization_reasons_path,+ icon: 'receipt-refund',+ position: 110,+ active: -> { %w[refund_reasons reimbursement_types return_authorization_reasons].include?(controller_name) },+ if: -> { can?(:manage, Spree::ReturnAuthorizationReason) }++ # Stock Locations+ nav.add :stock_locations,+ label: :stock_locations,+ url: :admin_stock_locations_path,+ icon: 'map-pin',+ position: 120,+ active: -> { controller_name == 'stock_locations' },+ if: -> { can?(:manage, Spree::StockLocation) }++ # Metafield Definitions+ nav.add :metafield_definitions,+ label: :metafield_definitions,+ url: :admin_metafield_definitions_path,+ icon: 'list-details',+ position: 130,+ active: -> { controller_name == 'metafield_definitions' },+ if: -> { can?(:manage, Spree::MetafieldDefinition) }++ # Audit Log+ nav.add :audits,+ label: 'admin.audit_log',+ url: :admin_audits_path,+ icon: 'history',+ position: 140,+ active: -> { %w[audits exports imports].include?(controller_name) },+ if: -> {+ # Only show if audits feature exists+ can?(:manage, current_store) &&+ Spree::Core::Engine.routes.url_helpers.respond_to?(:admin_audits_path)+ }++ # Developers+ nav.add :developers,+ label: :developers,+ url: :admin_oauth_applications_path,+ icon: 'terminal',+ position: 150,+ active: -> { %w[oauth_applications webhooks_subscribers].include?(controller_name) },+ if: -> { can?(:manage, Spree::OauthApplication) }++ # Edit Profile+ nav.add :edit_profile,+ label: 'admin.edit_profile',+ url: :edit_admin_profile_path,+ icon: 'user-scan',+ position: 200,+ active: -> { controller_name == 'profiles' && action_name == 'edit' }+end++# ===============================================+# Page Tab Navigations+# ===============================================++# Tax Tab Navigation+Spree::Admin::Navigation.configure(:tax_tabs) do |nav|+ nav.add :tax_rates,+ label: :tax_rates,+ url: :admin_tax_rates_path,+ position: 10,+ if: -> { can?(:manage, Spree::TaxRate) }++ nav.add :tax_categories,+ label: :tax_categories,+ url: :admin_tax_categories_path,+ position: 20,+ if: -> { can?(:manage, Spree::TaxCategory) }+end++# Shipping Tab Navigation+Spree::Admin::Navigation.configure(:shipping_tabs) do |nav|+ nav.add :shipping_methods,+ label: :shipping_methods,+ url: :admin_shipping_methods_path,+ position: 10,+ active: -> { controller_name == 'shipping_methods' && action_name == 'index' },+ if: -> { can?(:manage, Spree::ShippingMethod) }++ nav.add :shipping_categories,+ label: :shipping_categories,+ url: :admin_shipping_categories_path,+ position: 20,+ if: -> { can?(:manage, Spree::ShippingCategory) }+end++# Team Tab Navigation+Spree::Admin::Navigation.configure(:team_tabs) do |nav|+ nav.add :admin_users,+ label: :users,+ url: :admin_admin_users_path,+ position: 10,+ if: -> { can?(:manage, Spree.admin_user_class) }++ nav.add :invitations,+ label: :invitations,+ url: :admin_invitations_path,+ position: 20,+ if: -> { can?(:manage, Spree::Invitation) }++ nav.add :roles,+ label: :roles,+ url: :admin_roles_path,+ position: 30,+ if: -> { can?(:manage, Spree::Role) }+end++# Stock Tab Navigation+Spree::Admin::Navigation.configure(:stock_tabs) do |nav|+ nav.add :stock_items,+ label: :stock_items,+ url: :admin_stock_items_path,+ position: 10,+ active: -> { controller_name == 'stock_items' },+ if: -> { can?(:manage, Spree::StockItem) }++ nav.add :stock_transfers,+ label: :stock_transfers,+ url: :admin_stock_transfers_path,+ position: 20,+ active: -> { controller_name == 'stock_transfers' },+ if: -> { can?(:manage, Spree::StockTransfer) }+end++# Returns and Refunds Tab Navigation+Spree::Admin::Navigation.configure(:returns_tabs) do |nav|+ nav.add :return_authorization_reasons,+ label: :return_authorization_reasons,+ url: :admin_return_authorization_reasons_path,+ position: 10,+ if: -> { can?(:manage, Spree::ReturnAuthorizationReason) }++ nav.add :refund_reasons,+ label: :refund_reasons,+ url: :admin_refund_reasons_path,+ position: 20,+ if: -> { can?(:manage, Spree::RefundReason) }++ nav.add :reimbursement_types,+ label: :reimbursement_types,+ url: :admin_reimbursement_types_path,+ position: 30,+ if: -> { can?(:manage, Spree::ReimbursementType) }+end++# Developers Tab Navigation+Spree::Admin::Navigation.configure(:developers_tabs) do |nav|+ nav.add :api_keys,+ label: :api_keys,+ url: :admin_oauth_applications_path,+ position: 10,+ active: -> { controller_name == 'oauth_applications' },+ if: -> { can?(:manage, Spree::OauthApplication) }++ nav.add :webhooks,+ label: :webhooks,+ url: :admin_webhooks_subscribers_path,+ position: 20,+ active: -> { controller_name == 'webhooks_subscribers' },+ if: -> { can?(:manage, Spree::Webhooks::Subscriber) }+end++# Audit Tab Navigation+Spree::Admin::Navigation.configure(:audit_tabs) do |nav|+ nav.add :audit_log,+ label: 'admin.audit_log',+ url: :admin_audits_path,+ position: 10,+ active: -> { controller_name == 'audits' },+ if: -> { can?(:manage, current_store) }++ nav.add :exports,+ label: :exports,+ url: :admin_exports_path,+ position: 20,+ active: -> { controller_name == 'exports' },+ if: -> { can?(:manage, Spree::Export) }++ nav.add :imports,+ label: :imports,+ url: :admin_imports_path,+ position: 30,+ active: -> { controller_name == 'imports' },+ if: -> { can?(:manage, Spree::Import) }+enddiff --git a/admin/lib/spree/admin/runtime_configuration.rb b/admin/lib/spree/admin/runtime_configuration.rbindex 3b6d280e01..4f41477f08 100644--- a/admin/lib/spree/admin/runtime_configuration.rb+++ b/admin/lib/spree/admin/runtime_configuration.rb@@ -12,6 +12,7 @@ module Spreepreference :admin_orders_per_page, :integer, default: Kaminari.config.default_per_pagepreference :include_application_importmap, :boolean, default: false+ preference :legacy_sidebar_navigation, :boolean, default: falseendendenddiff --git a/admin/spec/helpers/spree/admin/navigation_helper_spec.rb b/admin/spec/helpers/spree/admin/navigation_helper_spec.rbindex e853ef5047..489027d113 100644--- a/admin/spec/helpers/spree/admin/navigation_helper_spec.rb+++ b/admin/spec/helpers/spree/admin/navigation_helper_spec.rb@@ -117,4 +117,138 @@ describe Spree::Admin::NavigationHelper, type: :helper doendendend++ describe '#render_navigation' do+ before do+ Spree::Admin::Navigation.clear_all!+ allow(Spree::Admin::RuntimeConfig).to receive(:legacy_sidebar_navigation).and_return(false)+ end++ it 'returns empty string when legacy navigation is enabled' do+ allow(Spree::Admin::RuntimeConfig).to receive(:legacy_sidebar_navigation).and_return(true)++ expect(helper.render_navigation(:sidebar)).to eq('')+ end++ it 'returns empty string when no items are visible' do+ Spree::Admin::Navigation.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard', if: -> { false }+ end++ expect(helper.render_navigation(:sidebar)).to eq('')+ end++ it 'renders navigation partial when items are visible' do+ Spree::Admin::Navigation.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard', url: '/admin'+ end++ allow(helper).to receive(:render).and_return('navigation html')++ result = helper.render_navigation(:sidebar)++ expect(result).to eq('navigation html')+ end+ end++ describe '#navigation_items' do+ before do+ Spree::Admin::Navigation.clear_all!+ end++ it 'returns visible items for the given context' do+ Spree::Admin::Navigation.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard', url: '/admin'+ nav.add :products, label: 'Products', url: '/admin/products'+ end++ items = helper.navigation_items(:sidebar)++ expect(items.size).to eq(2)+ expect(items.map(&:key)).to contain_exactly(:dashboard, :products)+ end++ it 'passes view context for permission checking' do+ allow(helper).to receive(:can?).with(:manage, Spree::Product).and_return(false)++ Spree::Admin::Navigation.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard'+ nav.add :products, label: 'Products', if: -> { can?(:manage, Spree::Product) }+ end++ items = helper.navigation_items(:sidebar)++ expect(items.map(&:key)).to eq([:dashboard])+ end+ end++ describe '#current_navigation_context' do+ it 'returns :settings when in settings area' do+ allow(helper).to receive(:settings_area?).and_return(true)++ expect(helper.current_navigation_context).to eq(:settings)+ end++ it 'returns :sidebar when not in settings area' do+ allow(helper).to receive(:settings_area?).and_return(false)++ expect(helper.current_navigation_context).to eq(:sidebar)+ end+ end++ describe '#navigation_item_active?' do+ before do+ Spree::Admin::Navigation.clear_all!+ allow(helper).to receive(:request).and_return(double(path: '/admin/products'))+ end++ it 'returns true when item is active' do+ Spree::Admin::Navigation.configure(:sidebar) do |nav|+ nav.add :products, label: 'Products', url: '/admin/products'+ end++ expect(helper.navigation_item_active?(:products, :sidebar)).to be true+ end++ it 'returns false when item is not active' do+ Spree::Admin::Navigation.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard', url: '/admin/orders'+ end++ expect(helper.navigation_item_active?(:dashboard, :sidebar)).to be false+ end++ it 'returns nil when item does not exist' do+ expect(helper.navigation_item_active?(:nonexistent, :sidebar)).to be_nil+ end+ end++ describe '#active_navigation_item' do+ before do+ Spree::Admin::Navigation.clear_all!+ allow(helper).to receive(:request).and_return(double(path: '/admin/products'))+ allow(helper).to receive(:settings_area?).and_return(false)+ end++ it 'returns the active navigation item for current path' do+ Spree::Admin::Navigation.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard', url: '/admin/orders'+ nav.add :products, label: 'Products', url: '/admin/products'+ end++ active_item = helper.active_navigation_item++ expect(active_item.key).to eq(:products)+ end++ it 'returns nil when no item is active' do+ Spree::Admin::Navigation.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard', url: '/admin/orders'+ end++ active_item = helper.active_navigation_item++ expect(active_item).to be_nil+ end+ endenddiff --git a/admin/spec/models/spree/admin/navigation/item_spec.rb b/admin/spec/models/spree/admin/navigation/item_spec.rbnew file mode 100644index 0000000000..94da38214f--- /dev/null+++ b/admin/spec/models/spree/admin/navigation/item_spec.rb@@ -0,0 +1,263 @@+require 'spec_helper'++RSpec.describe Spree::Admin::Navigation::Item do+ describe '#initialize' do+ it 'creates an item with basic attributes' do+ item = described_class.new(:dashboard, label: 'Dashboard', url: '/admin', icon: 'home')++ expect(item.key).to eq(:dashboard)+ expect(item.label).to eq('Dashboard')+ expect(item.url).to eq('/admin')+ expect(item.icon).to eq('home')+ end++ it 'sets default position to 999' do+ item = described_class.new(:dashboard)++ expect(item.position).to eq(999)+ end++ it 'accepts custom position' do+ item = described_class.new(:dashboard, position: 10)++ expect(item.position).to eq(10)+ end++ it 'accepts active condition' do+ item = described_class.new(:dashboard, active: -> { true })++ expect(item.active_condition).to be_a(Proc)+ end++ it 'accepts tooltip' do+ item = described_class.new(:dashboard, tooltip: 'Dashboard page')++ expect(item.tooltip).to eq('Dashboard page')+ end++ it 'initializes empty children array' do+ item = described_class.new(:dashboard)++ expect(item.children).to eq([])+ end+ end++ describe '#visible?' do+ it 'returns true when no condition is set' do+ item = described_class.new(:dashboard)++ expect(item.visible?(nil)).to be true+ end++ it 'evaluates proc condition with view context' do+ item = described_class.new(:dashboard, if: -> { can?(:manage, :dashboard) })++ context = Object.new+ def context.can?(action, subject)+ action == :manage && subject == :dashboard+ end++ expect(item.visible?(context)).to be true+ end++ it 'evaluates boolean condition' do+ item_true = described_class.new(:dashboard, if: true)+ expect(item_true.visible?(nil)).to be true++ item_false = described_class.new(:dashboard, if: false)+ expect(item_false.visible?(nil)).to be false+ end++ it 'evaluates proc without view context' do+ item = described_class.new(:dashboard, if: -> { true })++ expect(item.visible?(nil)).to be true+ end+ end++ describe '#active?' do+ let(:item) { described_class.new(:dashboard, url: '/admin/dashboard') }++ it 'uses active condition when provided' do+ item = described_class.new(:dashboard, url: '/admin/dashboard', active: -> { controller_name == 'dashboard' })++ context = Object.new+ def context.controller_name+ 'dashboard'+ end++ expect(item.active?('/admin/dashboard', context)).to be true+ end++ it 'returns true for exact path match' do+ context = double('ViewContext')+ allow(context).to receive(:spree).and_return(double('Routes'))++ expect(item.active?('/admin/dashboard', context)).to be true+ end++ it 'returns true when path starts with item url' do+ context = double('ViewContext')+ allow(context).to receive(:spree).and_return(double('Routes'))++ expect(item.active?('/admin/dashboard/stats', context)).to be true+ end++ it 'returns false for non-matching path' do+ context = double('ViewContext')+ allow(context).to receive(:spree).and_return(double('Routes'))++ expect(item.active?('/admin/products', context)).to be false+ end++ it 'evaluates active condition in view context' do+ item = described_class.new(:orders, active: -> { %w[orders checkouts].include?(controller_name) })++ context = Object.new+ def context.controller_name+ 'orders'+ end++ expect(item.active?('/admin/orders', context)).to be true+ end+ end++ describe '#resolve_url' do+ it 'returns string url as is' do+ item = described_class.new(:dashboard, url: '/admin')++ expect(item.resolve_url(nil)).to eq('/admin')+ end++ it 'calls proc url in view context' do+ item = described_class.new(:dashboard, url: -> { spree.admin_path })++ context = Object.new+ spree_routes = Object.new+ def spree_routes.admin_path+ '/admin'+ end+ def context.spree+ @spree_routes+ end+ context.instance_variable_set(:@spree_routes, spree_routes)++ expect(item.resolve_url(context)).to eq('/admin')+ end++ it 'calls symbol url with view context' do+ item = described_class.new(:dashboard, url: :admin_path)++ context = double('ViewContext')+ spree_routes = double('Routes', admin_path: '/admin')+ allow(context).to receive(:spree).and_return(spree_routes)++ expect(item.resolve_url(context)).to eq('/admin')+ end++ it 'handles proc url without context' do+ item = described_class.new(:dashboard, url: -> { '/admin/fallback' })++ expect(item.resolve_url(nil)).to eq('/admin/fallback')+ end+ end++ describe '#resolve_label' do+ it 'uses Spree.t for translation' do+ allow(Spree).to receive(:t).with(:dashboard, default: 'Dashboard').and_return('Dashboard')++ item = described_class.new(:dashboard, label: :dashboard)++ expect(item.resolve_label).to eq('Dashboard')+ end++ it 'translates string labels' do+ allow(Spree).to receive(:t).with('admin.dashboard', default: 'Admin.dashboard').and_return('Dashboard')++ item = described_class.new(:dashboard, label: 'admin.dashboard')++ expect(item.resolve_label).to eq('Dashboard')+ end+ end++ describe '#badge_value' do+ it 'returns nil when no badge is set' do+ item = described_class.new(:dashboard)++ expect(item.badge_value(nil)).to be_nil+ end++ it 'calls proc badge with view context' do+ item = described_class.new(:orders, badge: -> { ready_to_ship_orders_count })++ context = Object.new+ def context.ready_to_ship_orders_count+ 5+ end++ expect(item.badge_value(context)).to eq(5)+ end++ it 'returns static badge value' do+ item = described_class.new(:orders, badge: 'Enterprise')++ expect(item.badge_value(nil)).to eq('Enterprise')+ end++ it 'calls proc badge without context' do+ item = described_class.new(:orders, badge: -> { 10 })++ expect(item.badge_value(nil)).to eq(10)+ end+ end++ describe '#section?' do+ it 'returns true when section_label is present' do+ item = described_class.new(:section1, section_label: 'Section 1')++ expect(item.section?).to be true+ end++ it 'returns false when section_label is not present' do+ item = described_class.new(:dashboard)++ expect(item.section?).to be false+ end+ end++ describe '#add_child' do+ it 'adds a child item' do+ parent = described_class.new(:products)+ child = described_class.new(:all_products)++ parent.add_child(child)++ expect(parent.children).to include(child)+ expect(child.parent_key).to eq(:products)+ end++ it 'sorts children by position' do+ parent = described_class.new(:products)+ child1 = described_class.new(:child1, position: 20)+ child2 = described_class.new(:child2, position: 10)++ parent.add_child(child1)+ parent.add_child(child2)++ expect(parent.children.first.key).to eq(:child2)+ expect(parent.children.last.key).to eq(:child1)+ end+ end++ describe '#remove_child' do+ it 'removes a child item by key' do+ parent = described_class.new(:products)+ child = described_class.new(:all_products)++ parent.add_child(child)+ parent.remove_child(:all_products)++ expect(parent.children).to be_empty+ end+ end+enddiff --git a/admin/spec/models/spree/admin/navigation/registry_spec.rb b/admin/spec/models/spree/admin/navigation/registry_spec.rbnew file mode 100644index 0000000000..6cb869c24d--- /dev/null+++ b/admin/spec/models/spree/admin/navigation/registry_spec.rb@@ -0,0 +1,229 @@+require 'spec_helper'++RSpec.describe Spree::Admin::Navigation::Registry do+ let(:registry) { described_class.new(:sidebar) }++ describe '#add' do+ it 'adds a navigation item' do+ item = registry.add(:dashboard, label: 'Dashboard', url: '/admin')++ expect(registry.find(:dashboard)).to eq(item)+ end++ it 'supports block for nested items' do+ registry.add(:products, label: 'Products') do |nav|+ nav.add(:all_products, label: 'All Products')+ end++ parent = registry.find(:products)+ expect(parent.children.size).to eq(1)+ expect(parent.children.first.key).to eq(:all_products)+ end+ end++ describe '#remove' do+ it 'removes a navigation item' do+ registry.add(:dashboard, label: 'Dashboard')+ registry.remove(:dashboard)++ expect(registry.find(:dashboard)).to be_nil+ end++ it 'removes item from parent children' do+ registry.add(:products, label: 'Products') do |nav|+ nav.add(:all_products, label: 'All Products')+ end++ registry.remove(:all_products)++ parent = registry.find(:products)+ expect(parent.children).to be_empty+ end+ end++ describe '#update' do+ it 'updates an existing item' do+ registry.add(:dashboard, label: 'Dashboard', icon: 'home')+ registry.update(:dashboard, label: 'Home', icon: 'house')++ item = registry.find(:dashboard)+ expect(item.label).to eq('Home')+ expect(item.icon).to eq('house')+ end++ it 'returns nil for non-existent item' do+ result = registry.update(:nonexistent, label: 'Test')++ expect(result).to be_nil+ end+ end++ describe '#find' do+ it 'finds an item by key' do+ item = registry.add(:dashboard, label: 'Dashboard')++ expect(registry.find(:dashboard)).to eq(item)+ end++ it 'returns nil for non-existent item' do+ expect(registry.find(:nonexistent)).to be_nil+ end+ end++ describe '#exists?' do+ it 'returns true when item exists' do+ registry.add(:dashboard, label: 'Dashboard')++ expect(registry.exists?(:dashboard)).to be true+ end++ it 'returns false when item does not exist' do+ expect(registry.exists?(:nonexistent)).to be false+ end+ end++ describe '#insert_before' do+ it 'inserts item before target' do+ registry.add(:products, label: 'Products', position: 20)+ registry.insert_before(:products, :orders, label: 'Orders')++ orders = registry.find(:orders)+ products = registry.find(:products)++ expect(orders.position).to be < products.position+ end+ end++ describe '#insert_after' do+ it 'inserts item after target' do+ registry.add(:products, label: 'Products', position: 20)+ registry.insert_after(:products, :customers, label: 'Customers')++ customers = registry.find(:customers)+ products = registry.find(:products)++ expect(customers.position).to be > products.position+ end+ end++ describe '#move' do+ it 'moves item to first position' do+ registry.add(:dashboard, label: 'Dashboard', position: 10)+ registry.add(:products, label: 'Products', position: 20)+ registry.move(:products, position: :first)++ products = registry.find(:products)+ expect(products.position).to eq(-999)+ end++ it 'moves item to last position' do+ registry.add(:dashboard, label: 'Dashboard', position: 10)+ registry.add(:products, label: 'Products', position: 20)+ registry.move(:dashboard, position: :last)++ dashboard = registry.find(:dashboard)+ expect(dashboard.position).to eq(999)+ end++ it 'moves item before another' do+ registry.add(:dashboard, label: 'Dashboard', position: 10)+ registry.add(:products, label: 'Products', position: 20)+ registry.move(:products, before: :dashboard)++ products = registry.find(:products)+ dashboard = registry.find(:dashboard)++ expect(products.position).to be < dashboard.position+ end++ it 'moves item after another' do+ registry.add(:dashboard, label: 'Dashboard', position: 10)+ registry.add(:products, label: 'Products', position: 20)+ registry.move(:dashboard, after: :products)++ dashboard = registry.find(:dashboard)+ products = registry.find(:products)++ expect(dashboard.position).to be > products.position+ end+ end++ describe '#root_items' do+ it 'returns items without parent' do+ registry.add(:dashboard, label: 'Dashboard')+ registry.add(:products, label: 'Products') do |nav|+ nav.add(:all_products, label: 'All Products')+ end++ root_items = registry.root_items++ expect(root_items.size).to eq(2)+ expect(root_items.map(&:key)).to contain_exactly(:dashboard, :products)+ end++ it 'returns items sorted by position' do+ registry.add(:products, label: 'Products', position: 20)+ registry.add(:dashboard, label: 'Dashboard', position: 10)++ root_items = registry.root_items++ expect(root_items.first.key).to eq(:dashboard)+ expect(root_items.last.key).to eq(:products)+ end+ end++ describe '#visible_items' do+ it 'returns all items when no conditions' do+ registry.add(:dashboard, label: 'Dashboard')+ registry.add(:products, label: 'Products')++ visible = registry.visible_items(nil)++ expect(visible.size).to eq(2)+ end++ it 'filters items based on condition with view context' do+ context = Object.new+ def context.admin?+ true+ end++ registry.add(:dashboard, label: 'Dashboard')+ registry.add(:admin_panel, label: 'Admin', if: -> { admin? })+ registry.add(:restricted, label: 'Restricted', if: -> { false })++ visible = registry.visible_items(context)++ expect(visible.map(&:key)).to contain_exactly(:dashboard, :admin_panel)+ end+ end++ describe '#section' do+ it 'creates a section header' do+ section = registry.section(:main, label: 'Main Section')++ expect(section.section?).to be true+ expect(section.section_label).to eq('Main Section')+ end++ it 'supports block for section items' do+ registry.section(:main, label: 'Main Section') do |nav|+ nav.add(:dashboard, label: 'Dashboard')+ nav.add(:products, label: 'Products')+ end++ section = registry.find(:main)+ expect(section.children.size).to eq(2)+ end+ end++ describe '#clear' do+ it 'removes all items' do+ registry.add(:dashboard, label: 'Dashboard')+ registry.add(:products, label: 'Products')+ registry.clear++ expect(registry.root_items).to be_empty+ end+ end+enddiff --git a/admin/spec/models/spree/admin/navigation_spec.rb b/admin/spec/models/spree/admin/navigation_spec.rbnew file mode 100644index 0000000000..8928af12d1--- /dev/null+++ b/admin/spec/models/spree/admin/navigation_spec.rb@@ -0,0 +1,144 @@+require 'spec_helper'++RSpec.describe Spree::Admin::Navigation do+ let(:current_store) { @default_store }++ after do+ # Clear all registries after each test+ described_class.clear_all!+ end++ describe '.configure' do+ it 'configures navigation for a context' do+ described_class.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard', url: '/admin'+ end++ expect(described_class.find(:dashboard)).not_to be_nil+ end++ it 'supports multiple contexts' do+ described_class.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard'+ end++ described_class.configure(:settings) do |nav|+ nav.add :general, label: 'General'+ end++ expect(described_class.registry(:sidebar).find(:dashboard)).not_to be_nil+ expect(described_class.registry(:settings).find(:general)).not_to be_nil+ expect(described_class.registry(:sidebar).find(:general)).to be_nil+ end+ end++ describe '.registry' do+ it 'creates a new registry for a context' do+ registry = described_class.registry(:custom)++ expect(registry).to be_a(Spree::Admin::Navigation::Registry)+ expect(registry.context).to eq(:custom)+ end++ it 'returns the same registry for the same context' do+ registry1 = described_class.registry(:sidebar)+ registry2 = described_class.registry(:sidebar)++ expect(registry1).to equal(registry2)+ end+ end++ describe '.for' do+ it 'returns registry for context' do+ registry = described_class.for(:sidebar)++ expect(registry).to be_a(Spree::Admin::Navigation::Registry)+ end+ end++ describe 'delegation to default registry' do+ it 'delegates add to sidebar registry' do+ described_class.add(:dashboard, label: 'Dashboard')++ expect(described_class.registry(:sidebar).find(:dashboard)).not_to be_nil+ end++ it 'delegates remove to sidebar registry' do+ described_class.add(:dashboard, label: 'Dashboard')+ described_class.remove(:dashboard)++ expect(described_class.find(:dashboard)).to be_nil+ end++ it 'delegates update to sidebar registry' do+ described_class.add(:dashboard, label: 'Dashboard')+ described_class.update(:dashboard, label: 'Home')++ item = described_class.find(:dashboard)+ expect(item.label).to eq('Home')+ end++ it 'delegates find to sidebar registry' do+ item = described_class.add(:dashboard, label: 'Dashboard')++ expect(described_class.find(:dashboard)).to eq(item)+ end++ it 'delegates exists? to sidebar registry' do+ described_class.add(:dashboard, label: 'Dashboard')++ expect(described_class.exists?(:dashboard)).to be true+ expect(described_class.exists?(:nonexistent)).to be false+ end+ end++ describe '.visible_items' do+ it 'returns visible items for context with view context' do+ described_class.configure(:sidebar) do |nav|+ nav.add :dashboard, label: 'Dashboard'+ nav.add :admin, label: 'Admin', if: -> { admin? }+ end++ context = Object.new+ def context.admin?+ true+ end+ items = described_class.visible_items(:sidebar, context)++ expect(items.map(&:key)).to contain_exactly(:dashboard, :admin)+ end+ end++ describe '.contexts' do+ it 'returns all registered contexts' do+ described_class.registry(:sidebar)+ described_class.registry(:settings)+ described_class.registry(:custom)++ expect(described_class.contexts).to contain_exactly(:sidebar, :settings, :custom)+ end+ end++ describe '.clear_all!' do+ it 'clears all registries' do+ described_class.add(:dashboard, label: 'Dashboard')+ described_class.for(:settings).add(:general, label: 'General')++ described_class.clear_all!++ expect(described_class.registries).to be_empty+ end+ end++ describe '.clear!' do+ it 'clears specific registry' do+ described_class.add(:dashboard, label: 'Dashboard')+ described_class.for(:settings).add(:general, label: 'General')++ described_class.clear!(:sidebar)++ expect(described_class.find(:dashboard)).to be_nil+ expect(described_class.for(:settings).find(:general)).not_to be_nil+ end+ end+end