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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Extract "AddButtonComponent" for both overview and index pages
Aaron Contreras681d72852d5d
diff --git a/modules/team_planner/app/components/team_planner/add_button_component.html.erb b/modules/team_planner/app/components/team_planner/add_button_component.html.erbnew file mode 100644index 00000000000..662ee1417f2--- /dev/null+++ b/modules/team_planner/app/components/team_planner/add_button_component.html.erb@@ -0,0 +1,9 @@+<li class="<%= li_css_class %>">+ <%= link_to dynamic_path,+ class: link_css_class,+ title: title,+ aria_label: aria_label do %>+ <%= icon %>+ <%= label %>+ <% end %>+</li>diff --git a/modules/team_planner/app/components/team_planner/add_button_component.rb b/modules/team_planner/app/components/team_planner/add_button_component.rbnew file mode 100644index 00000000000..13a982ed0d9--- /dev/null+++ b/modules/team_planner/app/components/team_planner/add_button_component.rb@@ -0,0 +1,74 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# +++#++module TeamPlanner+ class AddButtonComponent < ::ApplicationComponent+ options :current_project++ def render?+ if current_project+ User.current.allowed_to?(:manage_team_planner, current_project)+ else+ User.current.allowed_to_globally?(:manage_team_planner)+ end+ end++ def dynamic_path+ polymorphic_path([:new, current_project, :team_planners])+ end++ def title+ I18n.t('team_planner.label_create_new_team_planner')+ end++ def aria_label+ I18n.t('team_planner.label_create_new_team_planner')+ end++ def li_css_class+ 'toolbar-item'+ end++ def link_css_class+ 'button -alt-highlight'+ end++ def label+ content_tag(:span,+ t(:'team_planner.label_team_planner'),+ class: 'button--text')+ end++ def icon+ helpers.op_icon('button--icon icon-add')+ end+ end+enddiff --git a/modules/team_planner/app/views/team_planner/team_planner/index.html.erb b/modules/team_planner/app/views/team_planner/team_planner/index.html.erbindex 624d912e16f..10f9bfa3de4 100644--- a/modules/team_planner/app/views/team_planner/team_planner/index.html.erb+++ b/modules/team_planner/app/views/team_planner/team_planner/index.html.erb@@ -1,16 +1,7 @@<% html_title(t('team_planner.label_team_planner_plural')) -%><%= toolbar title: t(:'team_planner.label_team_planner_plural') do %>- <% if current_user.allowed_to?(:manage_team_planner, @project) %>- <li class="toolbar-item">- <%= link_to new_project_team_planners_path(@project),- class: 'button -alt-highlight',- title: t(:'team_planner.label_create_new_team_planner') do %>- <%= op_icon('button--icon icon-add') %>- <span class="button--text"><%= t(:'team_planner.label_team_planner') %></span>- <% end %>- </li>- <% end %>+ <%= render ::TeamPlanner::AddButtonComponent.new(current_project: @project) %><% end %>-<%= render ::TeamPlanner::TableComponent.new(rows: @views, current_user: current_user) %>\ No newline at end of file+<%= render ::TeamPlanner::TableComponent.new(rows: @views, current_user: current_user) %>diff --git a/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb b/modules/team_planner/app/views/team_planner/team_planner/overview.html.erbindex 5ec1711568b..bb684321f68 100644--- a/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb+++ b/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb@@ -1,5 +1,7 @@<% html_title(t('team_planner.label_team_planner_plural')) -%>-<%= toolbar title: t(:'team_planner.label_team_planner_plural') %>+<%= toolbar title: t(:'team_planner.label_team_planner_plural') do %>+ <%= render ::TeamPlanner::AddButtonComponent.new %>+<% end %><%= render ::TeamPlanner::Overview::TableComponent.new(rows: @views, current_user: current_user) %>diff --git a/modules/team_planner/spec/features/team_planner_index_spec.rb b/modules/team_planner/spec/features/team_planner_index_spec.rbindex c1441e46974..44e23eeca00 100644--- a/modules/team_planner/spec/features/team_planner_index_spec.rb+++ b/modules/team_planner/spec/features/team_planner_index_spec.rb@@ -45,9 +45,12 @@ RSpec.describe 'Team planner index', :js, :with_cuprite, with_ee: %i[team_plannecontext 'with no view' dolet(:team_plan) { nil }- it 'shows an index action' do- expect(page).to have_text 'There is currently nothing to display.'- expect(page).to have_selector '.button', text: 'Team planner'+ it 'shows an empty index action' do+ team_planner.expect_no_views_rendered+ end++ it 'shows a create button' do+ team_planner.expect_create_buttonendit 'can create an action through the sidebar' do@@ -60,8 +63,8 @@ RSpec.describe 'Team planner index', :js, :with_cuprite, with_ee: %i[team_plannecontext 'with an existing view' doit 'shows that view' do- expect(page).to have_selector 'td', text: query.name- expect(page).to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"+ team_planner.expect_view_rendered query+ team_planner.expect_delete_button_for queryendcontext 'with another user with limited access' do@@ -72,28 +75,21 @@ RSpec.describe 'Team planner index', :js, :with_cuprite, with_ee: %i[team_plannemember_with_permissions: %w[view_work_packages view_team_planner])end- it 'does not show the create button' do- expect(page).to have_selector 'td', text: query.name+ it 'does not show the management buttons' do+ team_planner.expect_view_rendered query- # Does not show the delete- expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"-- # Does not show the create button- expect(page).not_to have_selector '.button', text: 'Team planner'+ team_planner.expect_no_delete_button_for query+ team_planner.expect_no_create_buttonendcontext 'when the view is non-public' dolet(:query) { create(:query, user:, project:, public: false) }it 'does not show a non-public view' do- expect(page).to have_text 'There is currently nothing to display.'- expect(page).not_to have_selector 'td', text: query.name-- # Does not show the delete- expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"+ team_planner.expect_no_views_rendered+ team_planner.expect_view_not_rendered query- # Does not show the create button- expect(page).not_to have_selector '.button', text: 'Team planner'+ team_planner.expect_no_create_buttonendendenddiff --git a/modules/team_planner/spec/features/team_planner_overview_spec.rb b/modules/team_planner/spec/features/team_planner_overview_spec.rbindex dba8054a28a..c952a0f02a5 100644--- a/modules/team_planner/spec/features/team_planner_overview_spec.rb+++ b/modules/team_planner/spec/features/team_planner_overview_spec.rb@@ -55,21 +55,23 @@ RSpec.describe 'Team planner overview',endend- it 'shows no create button' do- expect(page).not_to have_selector '.button', text: 'Team planner'+ it 'shows a create button' do+ team_planner.expect_create_buttonendcontext 'with no view' dolet(:team_plan) { nil }- it 'shows an overview action' do- expect(page).to have_text 'There is currently nothing to display.'+ it 'shows an empty overview action' do+ team_planner.expect_no_views_renderedendendcontext 'with an existing view' doit 'shows that view' do- expect(page).to have_selector 'td', text: query.name+ team_planner.expect_view_rendered query++ team_planner.expect_no_delete_button_for queryendcontext 'with another user with limited access' do@@ -81,27 +83,20 @@ RSpec.describe 'Team planner overview',endit 'does not show the management buttons' do- expect(page).to have_selector 'td', text: query.name-- # Does not show the delete- expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"+ team_planner.expect_view_rendered query- # Does not show the create button- expect(page).not_to have_selector '.button', text: 'Team planner'+ team_planner.expect_no_delete_button_for query+ team_planner.expect_no_create_buttonendcontext 'when the view is non-public' dolet(:query) { create(:query, user:, project:, public: false) }it 'does not show a non-public view' do- expect(page).to have_text 'There is currently nothing to display.'- expect(page).not_to have_selector 'td', text: query.name-- # Does not show the delete- expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"+ team_planner.expect_no_views_rendered+ team_planner.expect_view_not_rendered query- # Does not show the create button- expect(page).not_to have_selector '.button', text: 'Team planner'+ team_planner.expect_no_create_buttonendendenddiff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rbindex 8c5474cd3d1..0b25d2a96a4 100644--- a/modules/team_planner/spec/support/pages/team_planner.rb+++ b/modules/team_planner/spec/support/pages/team_planner.rb@@ -145,6 +145,38 @@ module Pagesendend+ def expect_no_views_rendered+ expect(page).to have_text 'There is currently nothing to display.'+ end++ def expect_view_rendered(query)+ expect(page).to have_selector 'td', text: query.name+ end++ def expect_delete_button_for(query)+ expect(page).to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"+ end++ def expect_no_delete_button_for(query)+ expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"+ end++ def expect_view_not_rendered(query)+ expect(page).not_to have_selector 'td', text: query.name+ end++ def expect_create_button+ within '.toolbar-items' do+ expect(page).to have_link text: 'Team planner'+ end+ end++ def expect_no_create_button+ within '.toolbar-items' do+ expect(page).not_to have_link text: 'Team planner'+ end+ end+def add_assignee(name)click_add_userpage.find('[data-qa-selector="tp-add-assignee"] input')