Skip to content

Commit

Permalink
Merge pull request #5381 from solidusio/elia/admin/general-fixes
Browse files Browse the repository at this point in the history
[admin] general fixes/improvements to the SolidusAdmin harness
  • Loading branch information
elia authored Sep 13, 2023
2 parents a04acdb + 0d1e81b commit 9aba822
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 10 deletions.
4 changes: 4 additions & 0 deletions admin/app/controllers/solidus_admin/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def index
orders,
per_page: SolidusAdmin::Config[:orders_per_page]
)

respond_to do |format|
format.html { render component('orders/index').new(page: @page) }
end
end
end
end
4 changes: 4 additions & 0 deletions admin/app/controllers/solidus_admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def index
products,
per_page: SolidusAdmin::Config[:products_per_page]
)

respond_to do |format|
format.html { render component('products/index').new(page: @page) }
end
end

def destroy
Expand Down
1 change: 0 additions & 1 deletion admin/app/views/solidus_admin/orders/index.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion admin/app/views/solidus_admin/products/index.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class InstallGenerator < Rails::Generators::Base
def install_solidus_core_support
route <<~RUBY
mount SolidusAdmin::Engine, at: '/admin', constraints: ->(req) {
req.cookies['solidus_admin'] != 'false'
req.cookies['solidus_admin'] != 'false' &&
req.params['solidus_admin'] != 'false'
}
RUBY
end
Expand Down
11 changes: 6 additions & 5 deletions admin/lib/solidus_admin/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class Configuration < Spree::Preferences::Configuration
SolidusAdmin::Engine.root.join("app/components/**/*.{rb,erb,js}"),
SolidusAdmin::Engine.root.join("spec/components/previews/**/*.{erb,rb}"),

Rails.root.join("public/solidus_admin/*.html"),
Rails.root.join("app/helpers/solidus_admin/**/*.rb"),
Rails.root.join("app/assets/javascripts/solidus_admin/**/*.js"),
Rails.root.join("app/views/solidus_admin/**/*.{erb,haml,html,slim}"),
Rails.root.join("app/components/solidus_admin/**/*.{rb,erb,haml,html,slim,js}")
Rails.root&.join("public/solidus_admin/*.html"),
Rails.root&.join("app/helpers/solidus_admin/**/*.rb"),
Rails.root&.join("app/assets/javascripts/solidus_admin/**/*.js"),
Rails.root&.join("app/views/solidus_admin/**/*.{erb,haml,html,slim}"),
Rails.root&.join("app/components/solidus_admin/**/*.{rb,erb,haml,html,slim,js}")
]

# List of Tailwind CSS files to be combined into the final stylesheet.
Expand Down Expand Up @@ -121,6 +121,7 @@ def menu_items
{
key: "products",
route: -> { solidus_admin.products_path },
match_path: -> { _1.start_with?("/admin/products/") },
position: 0
},
{
Expand Down
12 changes: 11 additions & 1 deletion admin/lib/solidus_admin/main_nav_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ class MainNavItem
# @api private
attr_reader :children, :top_level

def initialize(key:, position:, route:, icon: nil, children: [], top_level: true)
def initialize(
key:,
position:,
route:,
match_path: nil,
icon: nil,
children: [],
top_level: true
)
@key = key
@icon = icon
@position = position
@children = children
@top_level = top_level
@route = route
@match_path = match_path
end

def name
Expand Down Expand Up @@ -81,6 +90,7 @@ def current?(url_helpers, fullpath)
# @see #current?
def active?(url_helpers, fullpath)
current?(url_helpers, fullpath) ||
@match_path&.call(fullpath) ||
children.any? { |child| child.active?(url_helpers, fullpath) }
end
end
Expand Down
9 changes: 9 additions & 0 deletions admin/spec/solidus_admin/main_nav_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ def url_helpers(solidus_admin: {}, spree: {})
).to be(true)
end

it "returns true when the match_path proc is present and matches" do
url_helpers = url_helpers(solidus_admin: { foo_path: "/foo" })
item = described_class.new(
key: "foo", route: :foo_path, position: 1, match_path: ->(path) { path.start_with?("/bar") }
)

expect(item.active?(url_helpers, "/bar")).to be(true)
end

it "returns false otherwise" do
item = described_class.new(key: "foo", route: :foo_path, position: 1)
url_helpers = url_helpers(solidus_admin: { foo_path: "/foo" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
<ul class="solidus-admin--nav--menu">
<li class="tab-with-icon">
<label class="icon_link with-tip">
<span id="solidus-admin-switch-label" class="text" <%= tag.attributes('data-legacy-label': t('solidus_admin.main_nav.legacy_label'), 'data-admin-label': t('solidus_admin.main_nav.admin_label')) %>></span>
<span
id="solidus-admin-switch-label"
class="text"
data-legacy-label="<%= 'solidus_admin.main_nav.legacy_label'.then { t(_1, default: t(_1, locale: :en)) } %>"
data-admin-label="<%= 'solidus_admin.main_nav.admin_label'.then { t(_1, default: t(_1, locale: :en)) } %>"
></span>
<span><input type="checkbox" id="solidus-admin-switch" class="solidus-admin--nav--switch"/></span>
</label>
</li>
Expand Down
1 change: 1 addition & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ en:
price: Master Price
promotionable: Promotable
shipping_category: Shipping Category
sku: Master SKU
slug: Slug
tax_category: Tax Category
weight: Weight
Expand Down

0 comments on commit 9aba822

Please sign in to comment.