Skip to content
Snippets Groups Projects
Verified Commit 9aafca2e authored by David Gunnarsson's avatar David Gunnarsson
Browse files

Upgrade custom sidebar component

since I wanted to remove the bottom user section I had to customize the full sidebar. In there some deprecated code made the main_menu disappear

nowadays we can use the normal sidebar and simply eject the sidebar profile component, and keeping it empty since we don't want it
parent 0ac14711
No related branches found
No related tags found
No related merge requests found
<div
class="avo-sidebar fixed z-[60] t-0 application-sidebar w-64 flex-1 border-r lg:border-none bg-none h-[calc(100dvh-4rem)] bg-application lg:bg-transparent <%= 'print:hidden' if Avo.configuration.hide_layout_when_printing %> <%= 'hidden' unless @sidebar_open %>"
data-sidebar-target="<%= stimulus_target %>"
>
<div class="flex flex-col w-full h-full">
<div class="flex-1 flex flex-col justify-between overflow-auto h-full pt-3 mac-styled-scrollbar">
<%= render Avo::Sidebar::LinkComponent.new label: 'Get started', path: helpers.avo.root_path, active: :exclusive if Rails.env.development? && Avo.configuration.home_path.nil? %>
<% if Avo.plugin_manager.installed?(:avo_menu) && Avo.has_main_menu? %>
<% Avo.main_menu.items.each do |item| %>
<%= render Avo::Sidebar::ItemSwitcherComponent.new item: item %>
<% end %>
<% else %>
<% if dashboards.present? %>
<div>
<%= render Avo::Sidebar::HeadingComponent.new label: t('avo.dashboards'), icon: helpers.svg("avo/dashboards", class: 'h-4') %>
<div class="w-full space-y-1">
<% dashboards.sort_by { |r| r.navigation_label }.each do |dashboard| %>
<%= render Avo::Sidebar::LinkComponent.new label: dashboard.navigation_label, path: helpers.avo_dashboards.dashboard_path(dashboard) %>
<% end %>
</div>
</div>
<% end %>
<div>
<%= render Avo::Sidebar::HeadingComponent.new label: t('avo.resources'), icon: helpers.svg("avo/resources", class: 'h-4') %>
<div class="w-full space-y-1">
<% resources.sort_by { |r| r.navigation_label }.each do |resource| %>
<%= render Avo::Sidebar::LinkComponent.new label: resource.navigation_label, path: helpers.resources_path(resource: resource) %>
<% end %>
</div>
</div>
<% if tools.present? %>
<div>
<%= render Avo::Sidebar::HeadingComponent.new label: t('avo.tools'), icon: helpers.svg("avo/tools", class: 'h-4') %>
<div class="w-full space-y-1">
<% tools.each do |partial| %>
<%= render partial: "/avo/sidebar/items/#{partial}" %>
<% end %>
</div>
</div>
<% end %>
<% end %>
<%= render partial: "/avo/partials/sidebar_extra" %>
</div>
</div>
</div>
# frozen_string_literal: true
class Avo::SidebarComponent < Avo::BaseComponent
prop :sidebar_open, default: false
prop :for_mobile, default: false
def dashboards
return [] unless Avo.plugin_manager.installed?(:avo_dashboards)
Avo::Dashboards.dashboard_manager.dashboards_for_navigation
end
def resources
Avo.resource_manager.resources_for_navigation helpers._current_user
end
def tools
Avo.tool_manager.tools_for_navigation
end
def stimulus_target
@for_mobile ? "mobileSidebar" : "sidebar"
end
end
# frozen_string_literal: true
class Avo::SidebarProfileComponent < Avo::BaseComponent
prop :user
delegate :main_app, to: :helpers
def avatar
if @user.respond_to?(:avatar) && @user.avatar.present?
@user.avatar
else
""
end
end
def name
if @user.respond_to?(:name) && @user.name.present?
@user.name
elsif @user.respond_to?(:email) && @user.email.present?
@user.email
elsif @user.respond_to?(:email_address) && @user.email_address.present?
@user.email_address
else
"Avo user"
end
end
def title
if @user.respond_to?(:avo_title) && @user.avo_title.present?
@user.avo_title
else
""
end
end
def sign_out_method
:delete
end
def sign_out_path
return Avo.configuration.sign_out_path_name if Avo.configuration.sign_out_path_name.present?
return :session_path if helpers.possibly_rails_authentication?
default_sign_out_path
end
def default_sign_out_path
default_path = :"destroy_#{Avo.configuration.current_user_resource_name}_session_path"
default_path if main_app.respond_to?(default_path)
end
def can_sign_out_user?
sign_out_path.present? && main_app.respond_to?(sign_out_path&.to_sym)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment