Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add options for a create button in the submenu component

Henriette Dargeac168fef2e0c
diff --git a/app/components/open_project/common/submenu_component.html.erb b/app/components/open_project/common/submenu_component.html.erb
index 659a2f60a49..35e4f8e2a95 100644
--- a/app/components/open_project/common/submenu_component.html.erb
+++ b/app/components/open_project/common/submenu_component.html.erb
@@ -3,6 +3,7 @@
<div class="op-sidebar--search">
<%= render Primer::Alpha::TextField.new(name: "search",
label: I18n.t("label_search"),
+ placeholder: I18n.t("label_search"),
leading_visual: { icon: :search },
visually_hide_label: true,
classes: "op-sidebar--search-input",
@@ -68,4 +69,16 @@
</div>
<% end %>
</div>
+
+ <% if @create_btn_options.present? %>
+ <div class="op-sidebar--footer">
+ <%= render Primer::Beta::Button.new(scheme: :primary,
+ tag: :a,
+ href: @create_btn_options[:href],
+ classes: "op-sidebar--footer-action") do |button|
+ button.with_leading_visual_icon(icon: "plus")
+ @create_btn_options[:text]
+ end %>
+ </div>
+ <% end %>
</div>
diff --git a/app/components/open_project/common/submenu_component.rb b/app/components/open_project/common/submenu_component.rb
index d786f62c1ad..e0cdcf88ea1 100644
--- a/app/components/open_project/common/submenu_component.rb
+++ b/app/components/open_project/common/submenu_component.rb
@@ -31,10 +31,11 @@
module OpenProject
module Common
class SubmenuComponent < ApplicationComponent
- def initialize(sidebar_menu_items: nil, searchable: false)
+ def initialize(sidebar_menu_items: nil, searchable: false, create_btn_options: nil)
super()
@sidebar_menu_items = sidebar_menu_items
@searchable = searchable
+ @create_btn_options = create_btn_options
end
def render?
diff --git a/frontend/src/global_styles/layout/_main_menu.sass b/frontend/src/global_styles/layout/_main_menu.sass
index ccd16383f44..6bb12990f9e 100644
--- a/frontend/src/global_styles/layout/_main_menu.sass
+++ b/frontend/src/global_styles/layout/_main_menu.sass
@@ -71,7 +71,7 @@ $arrow-left-width: 40px
overflow: auto
@include styled-scroll-bar
- a:focus
+ a:not(.Button):focus
color: var(--main-menu-font-color)
ul
@@ -105,11 +105,11 @@ $arrow-left-width: 40px
// explicitly reset to zero to avoid selector precedence problems
padding-left: 0
- .main-menu--children li a
+ .main-menu--children li a:not(.Button)
// children have no icon so we need to push them right.
padding-left: 24px
- a
+ a:not(.Button)
text-decoration: none
line-height: var(--main-menu-item-height)
position: relative
@@ -143,7 +143,7 @@ $arrow-left-width: 40px
.toggler:hover
@include main-menu-hover
- a
+ a:not(.Button)
border: 1px solid transparent
&.selected, &.selected + a
@@ -158,10 +158,10 @@ $arrow-left-width: 40px
& ~ .toggler
@include main-menu-hover
- a:not(.toggler)
+ a:not(.Button):not(.toggler)
@extend .small-12
- a:not(:only-child):first-of-type
+ a:not(.Button):not(:only-child):first-of-type
flex: 0 0 calc(100% - 40px)
max-width: calc(100% - 40px)
@@ -259,7 +259,7 @@ a.main-menu--parent-node
&.menu_root
> li
.main-item-wrapper
- a:not(:only-child)
+ a:not(.Button):not(:only-child)
@extend .small-12
.ellipsis
@@ -284,7 +284,7 @@ a.main-menu--parent-node
font-family: var(--body-font-family)
font-style: normal
- a, a:link
+ a:not(.Button), a:not(.Button):link
&:not(.searchable-menu--item-link):not(.searchable-menu--category-icon)
color: var(--main-menu-font-color)
display: inline
diff --git a/lookbook/previews/open_project/common/submenu_component_preview.rb b/lookbook/previews/open_project/common/submenu_component_preview.rb
index bda7c923905..b8d4bce36f2 100644
--- a/lookbook/previews/open_project/common/submenu_component_preview.rb
+++ b/lookbook/previews/open_project/common/submenu_component_preview.rb
@@ -5,7 +5,7 @@ module OpenProject
# @label Default
def default
render_with_template(template: "open_project/common/submenu_preview/playground",
- locals: { sidebar_menu_items: menu_items, searchable: false })
+ locals: { sidebar_menu_items: menu_items, searchable: false, create_btn_options: nil })
end
# @label Searchable
@@ -13,7 +13,15 @@ module OpenProject
# It will be fine in production.
def searchable
render_with_template(template: "open_project/common/submenu_preview/playground",
- locals: { sidebar_menu_items: menu_items, searchable: true })
+ locals: { sidebar_menu_items: menu_items, searchable: true, create_btn_options: nil })
+ end
+
+ # @label With create Button
+ # `create_btn_options: { href: "/#", text: "User"}`
+ def with_create_button
+ render_with_template(template: "open_project/common/submenu_preview/playground",
+ locals: { sidebar_menu_items: menu_items, searchable: true,
+ create_btn_options: { href: "/#", text: "User" } })
end
private
diff --git a/lookbook/previews/open_project/common/submenu_preview/playground.html.erb b/lookbook/previews/open_project/common/submenu_preview/playground.html.erb
index ccdbaaa2788..2aead4a5728 100644
--- a/lookbook/previews/open_project/common/submenu_preview/playground.html.erb
+++ b/lookbook/previews/open_project/common/submenu_preview/playground.html.erb
@@ -1,6 +1,8 @@
<div class="main-menu"> <!-- Meant to be rendered inside the left-handed sidebar and is currently depending on that -->
<%= render OpenProject::Common::SubmenuComponent.new(
sidebar_menu_items: sidebar_menu_items,
- searchable: searchable)
+ searchable: searchable,
+ create_btn_options: create_btn_options
+ )
%>
</div>
diff --git a/modules/calendar/app/controllers/calendar/menus_controller.rb b/modules/calendar/app/controllers/calendar/menus_controller.rb
index d500883d311..a0219a1db6d 100644
--- a/modules/calendar/app/controllers/calendar/menus_controller.rb
+++ b/modules/calendar/app/controllers/calendar/menus_controller.rb
@@ -32,6 +32,9 @@ module ::Calendar
def show
@submenu_menu_items = ::Calendar::Menu.new(project: @project, params:).menu_items
+ @create_btn_options = if User.current.allowed_in_any_project?(:manage_calendars)
+ { href: new_project_calendars_path(@project), text: I18n.t("label_calendar") }
+ end
render layout: nil
end
diff --git a/modules/calendar/app/views/calendar/menus/show.html.erb b/modules/calendar/app/views/calendar/menus/show.html.erb
index a65dd2af4a4..a7e71e26a21 100644
--- a/modules/calendar/app/views/calendar/menus/show.html.erb
+++ b/modules/calendar/app/views/calendar/menus/show.html.erb
@@ -1,3 +1,5 @@
<%= turbo_frame_tag "calendar_sidemenu" do %>
- <%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @submenu_menu_items, searchable: true) %>
+ <%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @submenu_menu_items,
+ searchable: true,
+ create_btn_options: @create_btn_options) %>
<% end %>