From cab700c735519898bd16dc714fa55f80289e1c08 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 24 Nov 2023 18:35:00 +0100 Subject: [PATCH 1/2] Align the style of the new admin menu --- .../layout/navigation/account/component.html.erb | 2 +- .../layout/navigation/component.html.erb | 6 +++--- .../layout/navigation/item/component.html.erb | 4 ++-- .../backend/components/_navigation_solidus_admin.scss | 11 ++++++++--- .../admin/shared/_navigation_solidus_admin.html.erb | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/admin/app/components/solidus_admin/layout/navigation/account/component.html.erb b/admin/app/components/solidus_admin/layout/navigation/account/component.html.erb index 84b59dfe07e..20c470861ba 100644 --- a/admin/app/components/solidus_admin/layout/navigation/account/component.html.erb +++ b/admin/app/components/solidus_admin/layout/navigation/account/component.html.erb @@ -14,7 +14,7 @@ cursor-pointer "> <%= icon_tag("user-smile-fill", class: "inline-block align-text-bottom shrink-0 w-6 h-6 rounded-[4.81rem] body-small fill-yellow bg-black") %> - + <%= @user_label %> diff --git a/admin/app/components/solidus_admin/layout/navigation/component.html.erb b/admin/app/components/solidus_admin/layout/navigation/component.html.erb index 1d91983404a..a3322432a68 100644 --- a/admin/app/components/solidus_admin/layout/navigation/component.html.erb +++ b/admin/app/components/solidus_admin/layout/navigation/component.html.erb @@ -9,14 +9,14 @@ <% end %> <%= link_to @store_url, target: :_blank, class: "flex mb-4 px-2 py-1.5 border border-gray-100 rounded-sm shadow-sm" do %> -
+

<%= @store.name %>

-

<%= @store_url %>

+

<%= @store.url %>

<%= render component("ui/icon").new(name: 'arrow-right-up-line', class: 'w-4 h-4 fill-gray-400') %> <% end %> -
    +
      <%= render component("layout/navigation/item").with_collection(items, fullpath: request.fullpath) %>
    diff --git a/admin/app/components/solidus_admin/layout/navigation/item/component.html.erb b/admin/app/components/solidus_admin/layout/navigation/item/component.html.erb index 1b2d9f096ba..cb5118b26e9 100644 --- a/admin/app/components/solidus_admin/layout/navigation/item/component.html.erb +++ b/admin/app/components/solidus_admin/layout/navigation/item/component.html.erb @@ -4,7 +4,7 @@ aria-current="<%= @item.current?(@url_helpers, @fullpath) ? "page" : "false" %>" class=" flex gap-3 items-center - py-0.5 px-3 mb-0.5 rounded + py-1 px-3 rounded hover:text-red-500 hover:bg-gray-50 <%= "text-red-500 bg-gray-50" if active? %> <%= @item.top_level ? "body-small-bold text-black" : "body-small text-gray-600" %> @@ -19,7 +19,7 @@ <% if @item.children? %> -
      "> +
        "> <%= render self.class.with_collection(@item.children, url_helpers: @url_helpers, fullpath: @fullpath) %>
      <% end %> diff --git a/backend/app/assets/stylesheets/spree/backend/components/_navigation_solidus_admin.scss b/backend/app/assets/stylesheets/spree/backend/components/_navigation_solidus_admin.scss index ae54248ec34..564fae1aa57 100644 --- a/backend/app/assets/stylesheets/spree/backend/components/_navigation_solidus_admin.scss +++ b/backend/app/assets/stylesheets/spree/backend/components/_navigation_solidus_admin.scss @@ -4,7 +4,7 @@ $color-navbar-hover: $color-navbar !default; @import "spree/backend/components/switch_solidus_admin"; .solidus-admin--nav { - background-color: $color-light; + background-color: $solidus-admin-gray-15; position: sticky; top: 0; bottom: 0; @@ -93,7 +93,7 @@ $color-navbar-hover: $color-navbar !default; } &--name { - line-height: 24px; + line-height: 20px; font-size: 14px; font-weight: 600; color: $color-dark; @@ -101,7 +101,7 @@ $color-navbar-hover: $color-navbar !default; } &--url { - line-height: 20px; + line-height: 16px; font-size: 12px; font-weight: 400; color: $color-dark-light; @@ -120,6 +120,7 @@ $color-navbar-hover: $color-navbar !default; padding: 0; list-style: none; text-align: left; + margin-bottom: 12px; li { padding: 0; @@ -152,6 +153,10 @@ $color-navbar-hover: $color-navbar !default; } } + li > label > span { + line-height: 20px; + } + li.selected > a { background: $color-navbar-active-bg; color: $color-navbar-active; diff --git a/backend/app/views/spree/admin/shared/_navigation_solidus_admin.html.erb b/backend/app/views/spree/admin/shared/_navigation_solidus_admin.html.erb index 44af1123fff..f73c798e4f7 100644 --- a/backend/app/views/spree/admin/shared/_navigation_solidus_admin.html.erb +++ b/backend/app/views/spree/admin/shared/_navigation_solidus_admin.html.erb @@ -8,7 +8,7 @@ <%- end %> <%= link_to "//#{default_store.url}", target: '_blank', class: 'solidus-admin--nav--store-link' do %> -
      +
      <%= default_store.name %> <%= default_store.url %>
      From 597211c3974b56b6d8cf67ef6f21766c93d1b7cd Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 27 Nov 2023 11:55:08 +0100 Subject: [PATCH 2/2] Add a config option for importing menu items from backend --- .../install/install_generator.rb | 2 +- .../{solidus_admin.rb => solidus_admin.rb.tt} | 9 +++++ admin/lib/solidus_admin/configuration.rb | 35 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) rename admin/lib/generators/solidus_admin/install/templates/config/initializers/{solidus_admin.rb => solidus_admin.rb.tt} (81%) diff --git a/admin/lib/generators/solidus_admin/install/install_generator.rb b/admin/lib/generators/solidus_admin/install/install_generator.rb index 83d84161c79..2b21b505e7b 100644 --- a/admin/lib/generators/solidus_admin/install/install_generator.rb +++ b/admin/lib/generators/solidus_admin/install/install_generator.rb @@ -17,7 +17,7 @@ def install_solidus_core_support end def copy_initializer - copy_file "config/initializers/solidus_admin.rb" + template 'config/initializers/solidus_admin.rb.tt', 'config/initializers/solidus_admin.rb' end def ignore_tailwind_build_files diff --git a/admin/lib/generators/solidus_admin/install/templates/config/initializers/solidus_admin.rb b/admin/lib/generators/solidus_admin/install/templates/config/initializers/solidus_admin.rb.tt similarity index 81% rename from admin/lib/generators/solidus_admin/install/templates/config/initializers/solidus_admin.rb rename to admin/lib/generators/solidus_admin/install/templates/config/initializers/solidus_admin.rb.tt index 18d26fd06ec..5a376d3508e 100644 --- a/admin/lib/generators/solidus_admin/install/templates/config/initializers/solidus_admin.rb +++ b/admin/lib/generators/solidus_admin/install/templates/config/initializers/solidus_admin.rb.tt @@ -23,6 +23,15 @@ # regeneration of the importmap. # config.importmap_cache_sweepers << Rails.root.join("app/javascript/my_admin_components") + # If you want to avoid defining menu_item customizations twice while migrating to SolidusAdmin + # you can import menu_items from the backend by uncommenting the following line, + # but you will need to + <%- if defined? Spree::Backend -%> + config.import_menu_items_from_backend! + <%- else -%> + # config.import_menu_items_from_backend! + <%- end -%> + # Add custom paths to importmap files to be loaded. # config.importmap_paths << Rails.root.join("config/solidus_admin_importmap.rb") # diff --git a/admin/lib/solidus_admin/configuration.rb b/admin/lib/solidus_admin/configuration.rb index 4a03a5d84de..4e1d87f0f61 100644 --- a/admin/lib/solidus_admin/configuration.rb +++ b/admin/lib/solidus_admin/configuration.rb @@ -186,6 +186,41 @@ def menu_items ] end + def import_menu_items_from_backend! + menu_item_to_hash = ->(item, index) do + route = + if item.url.is_a?(Symbol) + -> { solidus_admin.public_send(item.url) } + elsif item.url.is_a?(String) + -> { item.url } + elsif item.url.is_a?(Proc) + item.url + elsif item.url.nil? + -> { spree.public_send(:"admin_#{item.label}_path") } + else + raise ArgumentError, "Unknown url type #{item.url.class}" + end + + icon = + case item.icon + when /^ri-/ + item.icon.delete_prefix("ri-") + when String + 'record-circle-line' # fallback on a generic icon + end + + { + position: index, + key: item.label, + icon: icon, + route: route, + children: item.children.map.with_index(&menu_item_to_hash) + } + end + + @menu_items = Spree::Backend::Config.menu_items.map.with_index(&menu_item_to_hash) + end + def components @components ||= Hash.new do |_h, k| const_name = "solidus_admin/#{k}/component".classify