From 7fa58b895a3ef2db16623d60e3b55e93862038ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Thu, 6 Jul 2023 12:50:56 +0200 Subject: [PATCH] Add the preview for the sidebar admin component We inject a tweaked item component to avoid rendering actual links in the embedded preview. We'll leave the preview of active state of the main navigation to the item component preview. Ref. #5221 --- .../sidebar/component_preview.rb | 33 +++++++++++++++++++ .../component_preview/overview.html.erb | 7 ++++ .../solidus_admin/sidebar/component_spec.rb | 4 +++ 3 files changed, 44 insertions(+) create mode 100644 admin/spec/components/previews/solidus_admin/sidebar/component_preview.rb create mode 100644 admin/spec/components/previews/solidus_admin/sidebar/component_preview/overview.html.erb diff --git a/admin/spec/components/previews/solidus_admin/sidebar/component_preview.rb b/admin/spec/components/previews/solidus_admin/sidebar/component_preview.rb new file mode 100644 index 00000000000..4949fdefcf6 --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/sidebar/component_preview.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require "solidus_admin/main_nav_item" + +# @component "sidebar" +class SolidusAdmin::Sidebar::ComponentPreview < ViewComponent::Preview + include SolidusAdmin::Preview + + class ItemComponent < SolidusAdmin::Sidebar::Item::Component + def path + "#" + end + + def active? + false + end + end + + # @param store_name text + # @param store_url url + # @param logo_path text { description: "Asset path to the store logo" } + def overview(store_name: "Solidus store", store_url: "https://example.com", logo_path: SolidusAdmin::Config.logo_path) + store = Struct.new(:name, :url).new(store_name, store_url) + + render_with_template( + locals: { + logo_path: logo_path, + store: store, + item_component: ItemComponent + } + ) + end +end diff --git a/admin/spec/components/previews/solidus_admin/sidebar/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/sidebar/component_preview/overview.html.erb new file mode 100644 index 00000000000..842b631f0c4 --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/sidebar/component_preview/overview.html.erb @@ -0,0 +1,7 @@ +
+ <%= render current_component.new( + store: store, + logo_path: logo_path, + item_component: item_component + ) %> +
diff --git a/admin/spec/components/solidus_admin/sidebar/component_spec.rb b/admin/spec/components/solidus_admin/sidebar/component_spec.rb index 091b3a79441..bd711e67bf6 100644 --- a/admin/spec/components/solidus_admin/sidebar/component_spec.rb +++ b/admin/spec/components/solidus_admin/sidebar/component_spec.rb @@ -3,6 +3,10 @@ require "spec_helper" RSpec.describe SolidusAdmin::Sidebar::Component, type: :component do + it "renders the overview preview" do + render_preview(:overview) + end + it "renders the solidus logo" do component = described_class.new( store: build(:store),