Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[53809] Update PageHeaders & SubHeaders in the (rails) global index pages (fix issues) #16882

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions app/components/add_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<a href="<%= dynamic_path %>"
id="<%= id %>"
title="<%= title %>"
arial-label="<%= aria_label %>"
class="<%= link_css_class %>">
<%= icon %>
<%= label %>
</a>

<%= render(Primer::ButtonComponent.new(scheme: :primary,
aria: { label: aria_label },
title: aria_label,
data: { "test-selector": test_selector},
tag: :a,
href: href) ) do |button|
button.with_leading_visual_icon(icon: :plus)
label_text
end
%>
44 changes: 1 addition & 43 deletions app/components/add_button_component.rb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't you just change this component to use a Primer Button? Now, you duplicated a lot of code in the individual modules. The SubHeader can deal with custom components on the right side, so that should not be a problem.

Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,5 @@
#

class AddButtonComponent < ApplicationComponent
options :current_project

def render?
raise "Implement the conditions for which the component should render or not"
end

def dynamic_path
raise "Implement the path for this component's href"
end

def id
raise "Implement the id for this component"
end

def title
accessibility_label_text
end

def label
content_tag(:span,
label_text,
class: "button--text")
end

def aria_label
accessibility_label_text
end

def accessibility_label_text
raise "Specify the aria label and title text to be used for this component"
end

def label_text
raise "Specify the label text to be used for this component"
end

def link_css_class
"button -primary"
end

def icon
helpers.op_icon("button--icon icon-add")
end
options :test_selector, :href, :aria_label, :label_text
end
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def breadcrumb_items
end

def parent_element
{ href: home_path, text: I18n.t(:label_home) }
{ href: home_path, text: helpers.organization_name }
end
end
end
1 change: 1 addition & 0 deletions app/components/projects/index_page_header_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def currently_favored? = query.favored_by?(current_user)

def breadcrumb_items
[
{ href: home_path, text: helpers.organization_name },
{ href: projects_path, text: t(:label_project_plural) },
current_breadcrumb_element
]
Expand Down
5 changes: 0 additions & 5 deletions app/views/homescreen/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ See COPYRIGHT and LICENSE files for more details.
end
%>

<h2 class="headline--application">
<span><%= organization_icon %></span>
<%= organization_name %>
</h2>

<%= render partial: 'announcements/show' %>

<% if @homescreen[:blocks].any? %>
Expand Down
58 changes: 0 additions & 58 deletions modules/boards/app/components/boards/add_button_component.rb

This file was deleted.

9 changes: 9 additions & 0 deletions modules/boards/app/controllers/boards/boards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ class BoardsController < BaseController
menu_item :boards

def index
@show_create_button = show_create_button
render "index", locals: { menu_name: project_or_global_menu }
end

def show
render layout: "angular/angular"
end

def show_create_button
if @project
User.current.allowed_in_project?(:manage_board_views, @project)
else
User.current.allowed_in_any_project?(:manage_board_views)
end
end

def default_breadcrumb; end

def show_local_breadcrumb
Expand Down
23 changes: 16 additions & 7 deletions modules/boards/app/views/boards/boards/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,28 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render Primer::OpenProject::PageHeader.new do |header|
header.with_title { t("boards.label_boards") }
header.with_breadcrumbs([{ href: home_path, text: organization_name},
header.with_breadcrumbs([{ href: home_path, text: organization_name },
*([href: project_overview_path(@project.id), text: @project.name] if @project),
t("boards.label_boards")])
end
%>

<%=
render Primer::OpenProject::SubHeader.new do |subheader|
subheader.with_action_component(data: { "test-selector": "add-board-button"}) do
render Boards::AddButtonComponent.new(current_project: @project)
<% if @show_create_button %>
<%=
render Primer::OpenProject::SubHeader.new do |subheader|
subheader.with_action_button(scheme: :primary,
aria: { label: I18n.t("boards.label_create_new_board") },
title: I18n.t("boards.label_board"),
tag: :a,
id: "add-board-button",
href: polymorphic_path([:new, @project, :work_package_board]),
data: { "test-selector": "add-board-button"}) do |button|
button.with_leading_visual_icon(icon: :plus)
I18n.t("boards.label_board")
end
end
end
%>
%>
<% end %>

<% if @board_grids.empty? -%>
<%= no_results_box %>
Expand Down
26 changes: 24 additions & 2 deletions modules/boards/app/views/boards/boards/overview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,30 @@ See COPYRIGHT and LICENSE files for more details.

<% html_title(t('boards.label_boards')) -%>

<%= toolbar title: t('boards.label_boards') do %>
<%= render Boards::AddButtonComponent.new %>
<%=
render Primer::OpenProject::PageHeader.new do |header|
header.with_title { t("boards.label_boards") }
header.with_breadcrumbs([{ href: home_path, text: organization_name},
*([href: project_overview_path(@project.id), text: @project.name] if @project),
t("boards.label_boards")])
end
%>

<% if @show_create_button %>
<%=
render Primer::OpenProject::SubHeader.new do |subheader|
subheader.with_action_button(scheme: :primary,
aria: { label: I18n.t("boards.label_create_new_board") },
title: I18n.t("boards.label_board"),
tag: :a,
id: "add-board-button",
href: polymorphic_path([:new, @project, :work_package_board]),
data: { "test-selector": "add-board-button"}) do |button|
button.with_leading_visual_icon(icon: :plus)
I18n.t("boards.label_board")
end
end
%>
<% end %>

<% if @board_grids.empty? -%>
Expand Down
4 changes: 1 addition & 3 deletions modules/boards/spec/features/support/board_index_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def expect_board(name, present: true)

def create_board(action: "Basic", title: "#{action} Board", expect_empty: false, via_toolbar: true)
if via_toolbar
within '[data-test-selector="add-board-button"]' do
click_link "Board"
end
find('[data-test-selector="add-board-button"]').click
else
find('[data-test-selector="boards--create-button"]').click
end
Expand Down
8 changes: 2 additions & 6 deletions modules/boards/spec/features/support/board_list_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ def visit!
end

def expect_create_button
within '[data-test-selector="add-board-button"]' do
expect(page).to have_link "Board"
end
expect(page).to have_css('[data-test-selector="add-board-button"]', text: "Board")
end

def expect_no_create_button
within '[data-test-selector="add-board-button"]' do
expect(page).to have_no_link "Board"
end
expect(page).to have_no_css('[data-test-selector="add-board-button"]', text: "Board")
end

def expect_delete_buttons(*boards)
Expand Down
4 changes: 1 addition & 3 deletions modules/boards/spec/features/support/board_new_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def visit!
def navigate_by_create_button
visit work_package_boards_path unless page.current_path == work_package_boards_path

within '[data-test-selector="add-board-button"]' do
click_link "Board"
end
find('[data-test-selector="add-board-button"]').click
end

def set_title(title)
Expand Down

This file was deleted.

62 changes: 0 additions & 62 deletions modules/calendar/app/components/calendar/add_button_component.rb

This file was deleted.

18 changes: 18 additions & 0 deletions modules/calendar/app/controllers/calendar/calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CalendarsController < ApplicationController

def index
@views = visible_views
@show_create_button = show_create_button?
@dynamic_path = dynamic_path
render "index", locals: { menu_name: project_or_global_menu }
end

Expand Down Expand Up @@ -109,5 +111,21 @@ def find_calendar
rescue ActiveRecord::RecordNotFound
render_404
end

def show_create_button?
if @project
User.current.allowed_in_project?(:manage_calendars, @project)
else
User.current.allowed_in_any_project?(:manage_calendars)
end
end

def dynamic_path
if @project
new_project_calendars_path(@project)
else
new_calendar_path
end
end
end
end
Loading
Loading