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

Transform the quick add menu into a Primer menu

Henriette Darge9b37bcba24c2
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index 56ae1031ae8..8072c10c93f 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -82,8 +82,7 @@ Redmine::MenuManager.map :quick_add_menu do |menu|
caption: ->(_) { Project.model_name.human },
icon: "plus",
html: {
- aria: { label: I18n.t(:label_project_new) },
- title: I18n.t(:label_project_new)
+ aria: { label: I18n.t(:label_project_new) }
},
if: ->(project) {
User.current.allowed_globally?(:add_project) ||
diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.html b/frontend/src/app/core/global_search/input/global-search-input.component.html
index dd0d63e9aa2..3b65e2b4eef 100644
--- a/frontend/src/app/core/global_search/input/global-search-input.component.html
+++ b/frontend/src/app/core/global_search/input/global-search-input.component.html
@@ -33,7 +33,7 @@
[placeholder]="placeholder"
[ariaLabel]="placeholder"
[dropdownPosition]="'bottom'"
- [classes]="{'top-menu-search--input': true, '-markable': markable, '-expanded': expanded }"
+ [classes]="{'top-menu-search--input': true, '-markable': markable, '-expanded': expanded, 'ng-select--primerized': true }"
[inputAttrs]="{ 'class': 'global-search--input', 'name': 'global-search--input', autocomplete: 'off'}"
[openOnEnter]="true"
[labelRequired]="false"
diff --git a/frontend/src/app/core/setup/globals/onboarding/tours/menu_tour.ts b/frontend/src/app/core/setup/globals/onboarding/tours/menu_tour.ts
index eefddf82040..057a2d5d13d 100644
--- a/frontend/src/app/core/setup/globals/onboarding/tours/menu_tour.ts
+++ b/frontend/src/app/core/setup/globals/onboarding/tours/menu_tour.ts
@@ -15,10 +15,10 @@ export function menuTourSteps():OnboardingStep[] {
condition: () => document.getElementsByClassName('wiki-menu--main-item').length !== 0,
},
{
- 'next .op-quick-add-menu': I18n.t('js.onboarding.steps.quick_add_button'),
+ 'next #op-app-header--quick-add-menu-button': I18n.t('js.onboarding.steps.quick_add_button'),
showSkip: false,
nextButton: { text: I18n.t('js.onboarding.buttons.next') },
- condition: () => document.getElementsByClassName('op-quick-add-menu--icon').length !== 0,
+ condition: () => document.getElementById('op-app-header--quick-add-menu-button') !== undefined,
},
{
'next .op-app-help': I18n.t('js.onboarding.steps.help_menu'),
diff --git a/frontend/src/global_styles/common/header/index.sass b/frontend/src/global_styles/common/header/index.sass
index a312650c7f3..83c3610a31b 100644
--- a/frontend/src/global_styles/common/header/index.sass
+++ b/frontend/src/global_styles/common/header/index.sass
@@ -2,4 +2,3 @@
@import './logo'
@import './app-menu'
@import './app-search'
-@import './quick-add-menu'
diff --git a/frontend/src/global_styles/common/header/quick-add-menu.sass b/frontend/src/global_styles/common/header/quick-add-menu.sass
deleted file mode 100644
index 3ec06586836..00000000000
--- a/frontend/src/global_styles/common/header/quick-add-menu.sass
+++ /dev/null
@@ -1,23 +0,0 @@
-.op-quick-add-menu
- $background: var(--button--primary-background-color)
- $background-hover: var(--button--primary-background-hover-color)
- $color: var(--button--primary-font-color)
- flex-shrink: 0
-
- &--button
- padding-left: 8px
- padding-right: 8px
-
- &--icon::before
- display: flex
- justify-content: center
- align-items: center
- border-radius: 50%
- width: 26px
- height: 26px
- padding: 1px 8px 0 8px
- @include button-style($background, $background-hover, $color)
-
- &:hover &
- &--icon::before
- background: var(--button--primary-background-hover-color)
diff --git a/frontend/src/global_styles/primer/_overrides.sass b/frontend/src/global_styles/primer/_overrides.sass
index bb47bd45618..719538e12ac 100644
--- a/frontend/src/global_styles/primer/_overrides.sass
+++ b/frontend/src/global_styles/primer/_overrides.sass
@@ -86,11 +86,10 @@ ul.SegmentedControl,
.Button.op-app-header--primer-button,
.Button.op-app-header--primer-button .Button-visual
+ align-self: center
color: var(--header-item-font-color)
- width: auto
&:hover
- background: var(--header-item-bg-hover-color)
color: var(--header-item-font-hover-color)
// Prototypical CKEditor adjustments to better match Primer styles
diff --git a/lib/redmine/menu_manager/top_menu/quick_add_menu.rb b/lib/redmine/menu_manager/top_menu/quick_add_menu.rb
index bd04963b91b..7c45d621aca 100644
--- a/lib/redmine/menu_manager/top_menu/quick_add_menu.rb
+++ b/lib/redmine/menu_manager/top_menu/quick_add_menu.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -38,45 +40,63 @@ module Redmine::MenuManager::TopMenu::QuickAddMenu
private
def render_quick_add_dropdown
- render_menu_dropdown_with_items(
- label: "",
- label_options: {
- title: I18n.t("menus.quick_add.label"),
- icon: "icon-add op-quick-add-menu--icon",
- class: "op-quick-add-menu--button"
- },
- items: first_level_menu_items_for(:quick_add_menu, @project),
- options: {
- drop_down_id: "quick-add-menu",
- menu_item_class: "op-quick-add-menu"
- },
- project: @project
- ) do
- work_package_quick_add_items
- # Return nil as the yield result is concat as well
- nil
+ render Primer::Alpha::ActionMenu.new(classes: "op-app-menu--item",
+ menu_id: "op-app-header--quick-add-menu",
+ anchor_align: :end) do |menu|
+ menu.with_show_button(icon: :plus,
+ scheme: :primary,
+ classes: "op-app-header--primer-button",
+ test_selector: "quick-add-menu-button",
+ "aria-label": I18n.t("menus.quick_add.label"))
+
+ add_first_level_items(menu)
+ add_second_level_items(menu)
+ end
+ end
+
+ def add_first_level_items(menu)
+ first_level_menu_items_for(:quick_add_menu, @project).each do |item|
+ menu.with_item(
+ href: item.url.present? ? url_for(item.url) : "#",
+ content_arguments: {
+ target: "_top",
+ **item.html_options,
+ test_selector: "quick-add-menu-item"
+ },
+ label: item.caption,
+ test_selector: "op-menu--item-action"
+ ) do |menu_item|
+ menu_item.with_leading_visual_icon(icon: :plus)
+ end
+ end
+ end
+
+ def add_second_level_items(menu)
+ if work_package_quick_add_items.present?
+ menu.with_group do |menu_group|
+ menu_group.with_heading(title: I18n.t(:label_work_package_plural), align_items: :flex_start)
+
+ work_package_quick_add_items.each do |item|
+ menu_group.with_item(
+ href: item[:href],
+ label: item[:caption],
+ content_arguments: { target: "_top" },
+ label_arguments: { classes: item[:classes] },
+ test_selector: "op-menu--item-action"
+ )
+ end
+ end
end
end
def work_package_quick_add_items
return unless any_types?
- concat content_tag(:hr, "", class: "op-menu--separator")
- concat work_package_type_heading
-
visible_types
.pluck(:id, :name)
.uniq
- .each do |id, name|
- concat work_package_create_link(id, name)
- end
- end
-
- def work_package_type_heading
- content_tag(:li, class: "op-menu--item") do
- content_tag :span,
- I18n.t(:label_work_package_plural),
- class: "op-menu--headline"
+ .map do |id, name|
+ work_package_create_link(id, name)
end
end
@@ -91,16 +111,14 @@ module Redmine::MenuManager::TopMenu::QuickAddMenu
end
def work_package_create_link(type_id, type_name)
- content_tag(:li, class: "op-menu--item") do
- if in_project_context?
- link_to type_name,
- new_project_work_packages_path(project_id: @project.identifier, type: type_id),
- class: "__hl_inline_type_#{type_id} op-menu--item-action"
- else
- link_to type_name,
- new_work_packages_path(type: type_id),
- class: "__hl_inline_type_#{type_id} op-menu--item-action"
- end
+ if in_project_context?
+ { caption: type_name,
+ href: new_project_work_packages_path(project_id: @project.identifier, type: type_id),
+ classes: "__hl_inline_type_#{type_id}" }
+ else
+ { caption: type_name,
+ href: new_work_packages_path(type: type_id),
+ classes: "__hl_inline_type_#{type_id}" }
end
end
diff --git a/lib/redmine/menu_manager/top_menu_helper.rb b/lib/redmine/menu_manager/top_menu_helper.rb
index c9d97dda131..8a909fbf858 100644
--- a/lib/redmine/menu_manager/top_menu_helper.rb
+++ b/lib/redmine/menu_manager/top_menu_helper.rb
@@ -40,7 +40,7 @@ module Redmine::MenuManager::TopMenuHelper
def top_menu_left_menu_items
[render_module_top_menu_node,
render_logo,
- render_main_top_menu_nodes]
+ render_main_top_menu_nodes] # ToDo: Check wether render_main_top_menu_nodes can be removed
end
def render_top_menu_center
@@ -179,7 +179,7 @@ module Redmine::MenuManager::TopMenuHelper
anchor_align: :end) do |menu|
menu.with_show_button(icon: "op-grid-menu",
scheme: :invisible,
- classes: "op-app-menu--item-action op-app-header--primer-button",
+ classes: "op-app-header--primer-button",
title: I18n.t("label_modules"),
test_selector: "op-app-header--modules-menu-button",
"aria-label": I18n.t("label_modules"))
diff --git a/spec/features/users/invite_user_modal/invite_user_modal_spec.rb b/spec/features/users/invite_user_modal/invite_user_modal_spec.rb
index 2cb5b5790b4..ac32e75580f 100644
--- a/spec/features/users/invite_user_modal/invite_user_modal_spec.rb
+++ b/spec/features/users/invite_user_modal/invite_user_modal_spec.rb
@@ -111,8 +111,8 @@ RSpec.describe "Invite user modal", :js do
before do
wp_page.visit!
- find(".op-app-menu--item-action.op-quick-add-menu--button").click
- find(".invite-user-menu-item.op-menu--item-action", text: "Invite user", wait: 5).click
+ page.find_test_selector("quick-add-menu-button").click
+ page.find_test_selector("quick-add-menu-item", text: "Invite user", wait: 5).click
end
it "does show you all users email address" do
diff --git a/spec/support/components/menu/quick_add_menu.rb b/spec/support/components/menu/quick_add_menu.rb
index c79d807057f..6f746e9b05f 100644
--- a/spec/support/components/menu/quick_add_menu.rb
+++ b/spec/support/components/menu/quick_add_menu.rb
@@ -49,7 +49,7 @@ module Components
def expect_work_package_type(*names, present: true)
within_dropdown do
- expect(page).to have_text "WORK PACKAGES"
+ expect(page).to have_text "Work Packages"
end
names.each do |name|
@@ -80,7 +80,7 @@ module Components
end
def trigger_element
- page.find('a[title="Open quick add menu"]')
+ page.find_test_selector("quick-add-menu-button")
end
end
end