Skip to content

Commit 17589d9

Browse files
committed
Make naming consistent for MainMenuToggleComponent and add a component test
1 parent 36a9b19 commit 17589d9

File tree

9 files changed

+138
-59
lines changed

9 files changed

+138
-59
lines changed

app/components/_index.sass

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@import "open_project/common/attribute_help_text_component"
77
@import "open_project/common/attribute_label_component"
88
@import "open_project/common/submenu_component"
9-
@import "open_project/common/main_menu_toggler_component"
9+
@import "open_project/common/main_menu_toggle_component"
1010
@import "projects/row_component"
1111
@import "projects/phases/hover_card_component"
1212
@import "shares/invite_user_form_component"

app/components/open_project/common/main_menu_toggler_component.rb renamed to app/components/open_project/common/main_menu_toggle_component.rb

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,49 @@
3030
#
3131
module OpenProject
3232
module Common
33-
class MainMenuTogglerComponent < ApplicationComponent
34-
def initialize(opened:)
35-
super
33+
class MainMenuToggleComponent < ApplicationComponent
34+
def initialize(expanded:)
35+
super()
3636

37-
@opened = opened
37+
@expanded = expanded
3838
end
3939

40+
def call
41+
render(Primer::Beta::IconButton.new(icon:,
42+
id:,
43+
aria: { label: aria_label },
44+
scheme:,
45+
size:,
46+
data:))
47+
end
48+
49+
private
50+
4051
def icon
41-
@opened ? "sidebar-expand" : :"sidebar-collapse"
52+
@expanded ? "sidebar-expand" : :"sidebar-collapse"
4253
end
4354

4455
def id
45-
"menu-toggler--#{@opened ? 'opener' : 'closer'}"
56+
"menu-toggle--#{@expanded ? 'collapse-button' : 'expand-button'}"
4657
end
4758

4859
def aria_label
49-
@opened ? I18n.t("js.label_hide_project_menu") : I18n.t("js.label_expand_project_menu")
60+
@expanded ? I18n.t("js.label_hide_project_menu") : I18n.t("js.label_expand_project_menu")
5061
end
5162

5263
def scheme
5364
:invisible
5465
end
5566

5667
def size
57-
@opened ? :medium : :small
68+
@expanded ? :medium : :small
5869
end
5970

6071
def data
6172
{
62-
action: "click->menus--main-toggler#toggleNavigation"
73+
action: "click->menus--main-toggle#toggleNavigation"
6374
}
6475
end
65-
66-
def call
67-
render(Primer::Beta::IconButton.new(icon:,
68-
id:,
69-
aria: { label: aria_label },
70-
scheme:,
71-
size:,
72-
data:))
73-
end
7476
end
7577
end
7678
end

app/components/open_project/common/main_menu_toggler_component.sass renamed to app/components/open_project/common/main_menu_toggle_component.sass

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
// See COPYRIGHT and LICENSE files for more details.
2727
//++
2828
29-
#menu-toggler--closer
29+
#menu-toggle--expand-button
3030
position: absolute
3131
top: 18px
3232
left: 11px
3333

3434
@media screen and (max-width: $breakpoint-sm)
3535
top: 11px
3636

37-
#menu-toggler--opener
37+
#menu-toggle--collapse-button
3838
margin-right: 5px
3939

4040
.Button-visual
@@ -47,5 +47,5 @@
4747
margin-left: 30px
4848

4949
&:not(.hidden-navigation)
50-
#menu-toggler--closer
50+
#menu-toggle--expand-button
5151
display: none

app/views/layouts/base.html.erb

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ See COPYRIGHT and LICENSE files for more details.
3030
<html xmlns="http://www.w3.org/1999/xhtml"
3131
lang="<%= I18n.locale.to_s %>"
3232
xml:lang="<%= I18n.locale.to_s %>"
33-
class="<%= 'in_modal' unless show_decoration %>">
33+
class="<%= "in_modal" unless show_decoration %>">
3434
<head>
35-
<%= render partial: 'layouts/common_head' %>
35+
<%= render partial: "layouts/common_head" %>
3636
<!-- project specific tags -->
3737
<%= call_hook :view_layouts_base_html_head %>
3838
<!-- page specific tags -->
@@ -43,13 +43,13 @@ See COPYRIGHT and LICENSE files for more details.
4343
</head>
4444
<%= content_tag :body,
4545
class: "#{body_css_classes} __overflowing_element_container __overflowing_body",
46-
data: body_data_attributes(local_assigns) do %>
47-
<%= render partial: 'warning_bar/warning_bar' %>
46+
data: body_data_attributes(local_assigns) do %>
47+
<%= render partial: "warning_bar/warning_bar" %>
4848
<noscript>
4949
<div class="top-shelf">
5050
<p>
5151
<span>
52-
<%= op_icon 'icon3 icon-warning' %>
52+
<%= op_icon "icon3 icon-warning" %>
5353
<strong><%= t(:noscript_heading) %></strong>
5454
</span>
5555
<%= t(:noscript_description) %>
@@ -69,15 +69,15 @@ See COPYRIGHT and LICENSE files for more details.
6969
<% initial_classes = initial_menu_classes(side_displayed, show_decoration) %>
7070
<div id="wrapper" style="<%= initial_menu_styles(side_displayed) %>" class="<%= initial_classes %>">
7171
<% if show_decoration %>
72-
<header class="op-app-header<%= ' op-app-header_development' if OpenProject::Configuration.development_highlight_enabled? %>">
72+
<header class="op-app-header<%= " op-app-header_development" if OpenProject::Configuration.development_highlight_enabled? %>">
7373
<div class="op-app-header--start">
7474
<h1 class="hidden-for-sighted">
7575
<%= t(:label_top_menu) %>
7676
</h1>
7777
<a href="" class="hidden-for-sighted skip-navigation-link"
7878
id="skip-navigation--content"
79-
aria-label="<%= I18n.t('js.work_packages.jump_marks.label_content') %>">
80-
<%= I18n.t('js.work_packages.jump_marks.content') %>
79+
aria-label="<%= I18n.t("js.work_packages.jump_marks.label_content") %>">
80+
<%= I18n.t("js.work_packages.jump_marks.content") %>
8181
</a>
8282
<%= render_top_menu_left %>
8383
</div>
@@ -92,32 +92,34 @@ See COPYRIGHT and LICENSE files for more details.
9292
<% end %>
9393
<div id="main"
9494
class="<%= initial_classes %>"
95-
data-controller="menus--main-toggler"
96-
data-application-target="dynamic">
95+
data-controller="menus--main-toggle">
9796
<% if (side_displayed && show_decoration) %>
9897
<div
9998
id="main-menu"
10099
class="main-menu"
101-
data-controller="menus--main"
102-
>
100+
data-controller="menus--main">
103101
<h1 class="hidden-for-sighted"><%= t(:label_main_menu) %></h1>
104102
<opce-main-menu-resizer></opce-main-menu-resizer>
105103
<div id="menu-sidebar">
106104
<%= render(Primer::OpenProject::FlexLayout.new(align_items: :center, mt: 3)) do |flex|
107-
flex.with_column(overflow: :hidden, ml: 2) do
108-
render_projects_top_menu_node
109-
end
110-
flex.with_column(text_align: :right, flex: :auto) do
111-
render(OpenProject::Common::MainMenuTogglerComponent.new(opened: true))
112-
end
113-
end %>
105+
flex.with_column(overflow: :hidden, ml: 2) do
106+
render_projects_top_menu_node
107+
end
108+
flex.with_column(text_align: :right, flex: :auto) do
109+
render(OpenProject::Common::MainMenuToggleComponent.new(expanded: true))
110+
end
111+
end %>
114112

115-
<%= render(Primer::BaseComponent.new(tag: :hr,
116-
classes: "main-menu--projects-divider",
117-
role: :presentation,
118-
aria: {
119-
hidden: true
120-
})) %>
113+
<%= render(
114+
Primer::BaseComponent.new(
115+
tag: :hr,
116+
classes: "main-menu--projects-divider",
117+
role: :presentation,
118+
aria: {
119+
hidden: true
120+
}
121+
)
122+
) %>
121123
<%= main_menu %>
122124
<%= content_for :main_menu %>
123125
<%= call_hook :view_layouts_base_main_menu %>
@@ -136,11 +138,11 @@ See COPYRIGHT and LICENSE files for more details.
136138
<section data-augmented-model-wrapper
137139
data-modal-initialize-now="true"
138140
data-modal-class-name="onboarding-modal">
139-
<%= render partial: '/onboarding/configuration_modal' %>
141+
<%= render partial: "/onboarding/configuration_modal" %>
140142
</section>
141143
<% end %>
142144
<%= content_tag :div,
143-
id: 'content',
145+
id: "content",
144146
class: "#{initial_classes} #{'content--split' if content_for?(:content_body_right)}" do %>
145147
<h1 class="hidden-for-sighted accessibility-helper"><%= t(:label_content) %></h1>
146148
<% if content_for?(:content_header) %>
@@ -150,7 +152,7 @@ See COPYRIGHT and LICENSE files for more details.
150152
<% end %>
151153

152154
<div id="content-body">
153-
<%= render(OpenProject::Common::MainMenuTogglerComponent.new(opened: false)) %>
155+
<%= render(OpenProject::Common::MainMenuToggleComponent.new(expanded: false)) %>
154156
<%= content_for :content_body %>
155157
<% unless local_assigns[:no_layout_yield] %>
156158
<%= yield %>

frontend/src/app/shared/components/resizer/resizer/main-menu-resizer.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import {
6262
export class MainMenuResizerComponent extends UntilDestroyedMixin implements OnInit {
6363
public toggleTitle:string;
6464

65-
private resizeEvent:string;
65+
private resizeEvent:string = 'main-menu-resize';
6666

6767
private elementWidth:number;
6868

@@ -81,8 +81,6 @@ export class MainMenuResizerComponent extends UntilDestroyedMixin implements OnI
8181
}
8282

8383
ngOnInit() {
84-
this.resizeEvent = 'main-menu-resize';
85-
8684
this.isOpen = this.toggleService.showNavigation;
8785

8886
// Listen on sidebar changes and toggle resizer classes, if necessary

frontend/src/stimulus/controllers/dynamic/menus/main-toggler.controller.ts renamed to frontend/src/stimulus/controllers/dynamic/menus/main-toggle.controller.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { Controller } from '@hotwired/stimulus';
22
import { MainMenuToggleService } from 'core-app/core/main-menu/main-menu-toggle.service';
33

4-
export default class MainTogglerController extends Controller {
4+
export default class MainToggleController extends Controller {
55
mainMenuService:MainMenuToggleService;
66

77
initialize() {
8-
void window.OpenProject.getPluginContext()
8+
console.count("INIT");
9+
10+
}
11+
12+
async connect() {
13+
console.count("CONNECT");
14+
await window.OpenProject.getPluginContext()
915
.then((pluginContext) => pluginContext.injector.get(MainMenuToggleService))
1016
.then((service) => {
1117
this.mainMenuService = service;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
require "rails_helper"
32+
33+
RSpec.describe OpenProject::Common::MainMenuToggleComponent, type: :component do
34+
let(:expanded) { true }
35+
36+
subject do
37+
render_inline(described_class.new(expanded:)) do
38+
content
39+
end
40+
41+
page
42+
end
43+
44+
context "in expended state" do
45+
it "does render the expanded icon" do
46+
expect(subject).to have_element class: "octicon-sidebar-expand"
47+
expect(subject).to have_no_element class: "octicon-sidebar-collapse"
48+
expect(subject).to have_element id: "menu-toggle--collapse-button"
49+
expect(subject).to have_element "tool-tip",
50+
text: "Collapse project menu",
51+
for: "menu-toggle--collapse-button",
52+
popover: "manual",
53+
"data-type": "label"
54+
end
55+
end
56+
57+
context "in collapsed state" do
58+
let(:expanded) { false }
59+
60+
it "does render the collapsed icon" do
61+
expect(subject).to have_element class: "octicon-sidebar-collapse"
62+
expect(subject).to have_no_element class: "octicon-sidebar-expand"
63+
expect(subject).to have_element id: "menu-toggle--expand-button"
64+
expect(subject).to have_element "tool-tip",
65+
text: "Expand project menu",
66+
for: "menu-toggle--expand-button",
67+
popover: "manual",
68+
"data-type": "label"
69+
end
70+
end
71+
end

spec/support/edit_fields/edit_field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def activate!(expect_open: true)
110110
retry_block(args: { tries: 2 }) do
111111
unless active?
112112
SeleniumHubWaiter.wait unless using_cuprite?
113-
scroll_to_and_click(display_trigger_element)
113+
scroll_to_and_click(display_trigger_element, block: :nearest)
114114
SeleniumHubWaiter.wait unless using_cuprite?
115115
end
116116

spec/support/shared/scroll_into_view_helpers.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# One of `:start`, `:center`, `:end`, or `:nearest`. Defaults to `:start`.
3535
# @param inline [Symbol] (optional) Defines horizontal alignment.
3636
# One of `:start`, `:center`, `:end`, or `:nearest`. Defaults to `:nearest`..
37-
def scroll_to_element(element, block: :nearest, inline: :nearest)
37+
def scroll_to_element(element, block: :start, inline: :nearest)
3838
script = <<-JS
3939
arguments[0].scrollIntoView({block: "#{block}", inline: "#{inline}"});
4040
JS
@@ -45,9 +45,9 @@ def scroll_to_element(element, block: :nearest, inline: :nearest)
4545
end
4646
end
4747

48-
def scroll_to_and_click(element)
48+
def scroll_to_and_click(element, block: :start, inline: :nearest)
4949
retry_block do
50-
scroll_to_element(element)
50+
scroll_to_element(element, block:, inline:)
5151
element.click
5252
end
5353
end

0 commit comments

Comments
 (0)