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
Rework NewsComponent to use semantic lists
Alexander Brandon Coles7fc00e9bee1a
diff --git a/modules/grids/app/components/grids/widgets/news_component.html.erb b/modules/grids/app/components/grids/widgets/news_component.html.erbindex ca94764cea4..fee146598e3 100644--- a/modules/grids/app/components/grids/widgets/news_component.html.erb+++ b/modules/grids/app/components/grids/widgets/news_component.html.erb@@ -29,53 +29,17 @@ See COPYRIGHT and LICENSE files for more details.<%=component_wrapper tag: :"turbo-frame" do- box_collection do |box|- if @newest.empty?- box.with_box do- render(Primer::Beta::Text.new(color: :subtle)) { t(:"js.grid.widgets.news.no_results") }- end- else- @newest.each_with_index do |news, i|- box.with_box(mt: 2, pb: 2, border: i == @newest.count - 1 ? false : :bottom) do- component_collection do |body|- body.with_component(- if @project- render(- Primer::Beta::Link.new(- font_weight: :bold,- underline: true,- href: news_path(news)- )- ) { news.title }- else- render(Primer::OpenProject::FlexLayout.new) do |layout|- layout.with_column do- render(- Primer::Beta::Link.new(- font_weight: :bold,- scheme: :secondary,- underline: false,- href: project_path(news.project)- )- ) { "#{news.project.name}:" }- end-- layout.with_column do- render(Primer::Beta::Link.new(ml: 1, font_weight: :bold, underline: true, href: news_path(news))) { news.title }- end- end-- end- )- body.with_component(- render(Primer::Beta::Text.new(tag: :p, color: :subtle)) { helpers.authoring_at(format_time(news.created_at), news.author) }- )- body.with_component(- render(Primer::Beta::Text.new) { news.summary }- )- end- end- end+ if @newest.empty?+ render(Primer::Beta::Text.new(color: :subtle)) { t(:"js.grid.widgets.news.no_results") }+ else+ render(OpPrimer::ListComponent.new(m: 0)) do+ render(+ ItemComponent.with_collection(+ @newest,+ project:,+ spacer_component: OpPrimer::ListComponent::Divider.new(border: :bottom)+ )+ )endendenddiff --git a/modules/grids/app/components/grids/widgets/news_component/item_component.html.erb b/modules/grids/app/components/grids/widgets/news_component/item_component.html.erbnew file mode 100644index 00000000000..49b55066ffc--- /dev/null+++ b/modules/grids/app/components/grids/widgets/news_component/item_component.html.erb@@ -0,0 +1,71 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 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.++++#%>++<%=+ render(OpPrimer::ListComponent::Item.new) do+ render(Primer::Box.new(mt: 2, pb: 2)) do+ component_collection do |body|+ body.with_component(+ if project+ render(+ Primer::Beta::Link.new(+ font_weight: :bold,+ underline: true,+ href: news_path(item)+ )+ ) { item.title }+ else+ render(Primer::OpenProject::FlexLayout.new) do |layout|+ layout.with_column do+ render(+ Primer::Beta::Link.new(+ font_weight: :bold,+ scheme: :secondary,+ underline: false,+ href: project_path(item.project)+ )+ ) { "#{item.project.name}:" }+ end++ layout.with_column do+ render(Primer::Beta::Link.new(ml: 1, font_weight: :bold, underline: true, href: news_path(item))) { item.title }+ end+ end+ end+ )+ body.with_component(+ render(Primer::Beta::Text.new(tag: :p, color: :subtle)) { helpers.authoring_at(format_time(item.created_at), item.author) }+ )+ body.with_component(+ render(Primer::Beta::Text.new) { item.summary }+ )+ end+ end+ end+%>diff --git a/modules/grids/app/components/grids/widgets/news_component/item_component.rb b/modules/grids/app/components/grids/widgets/news_component/item_component.rbnew file mode 100644index 00000000000..058934e3537--- /dev/null+++ b/modules/grids/app/components/grids/widgets/news_component/item_component.rb@@ -0,0 +1,51 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 Grids+ module Widgets+ class NewsComponent < ApplicationComponent+ class ItemComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers++ attr_reader :item, :project, :current_user++ def initialize(item:, project:, current_user: User.current, **system_arguments)+ super()++ @item = item+ @project = project+ @current_user = current_user+ @system_arguments = system_arguments+ end+ end+ end+ end+enddiff --git a/modules/grids/spec/components/grids/widgets/news_component_spec.rb b/modules/grids/spec/components/grids/widgets/news_component_spec.rbindex d3f3d202f30..e99f435460f 100644--- a/modules/grids/spec/components/grids/widgets/news_component_spec.rb+++ b/modules/grids/spec/components/grids/widgets/news_component_spec.rb@@ -59,11 +59,12 @@ RSpec.describe Grids::Widgets::NewsComponent, type: :component docontext "with news" dolet(:author) { create(:user) }- let!(:news) { create_list(:news, 3, author:) }+ let!(:news) { create_list(:news, 2, author:) }it "renders news items", :aggregate_failures do- expect(rendered_component).to have_css(".mt-2", count: 3)- expect(rendered_component).to have_css(".mt-2:last-of-type") do |item|+ expect(rendered_component).to have_list_item(count: 3)+ expect(rendered_component).to have_list_item(count: 1, aria: { hidden: true }) # dividers+ expect(rendered_component).to have_list_item(position: 3) do |item|expect(item).to have_link href: news_path(news.first)expect(item).to have_content /Added by .+ on \d{2}\/\d{2}\/\d{4} \d{2}:\d{2} [AP]M/expect(item).to have_link href: user_path(author)@@ -86,8 +87,9 @@ RSpec.describe Grids::Widgets::NewsComponent, type: :component dolet!(:news) { create_list(:news, 3, project:, author:) }it "renders news items", :aggregate_failures do- expect(rendered_component).to have_css(".mt-2", count: 3)- expect(rendered_component).to have_css(".mt-2:last-of-type") do |item|+ expect(rendered_component).to have_list_item(count: 5)+ expect(rendered_component).to have_list_item(count: 2, aria: { hidden: true }) # dividers+ expect(rendered_component).to have_list_item(position: 5) do |item|expect(item).to have_link href: news_path(news.first)expect(item).to have_content /Added by .+ on \d{2}\/\d{2}\/\d{4} \d{2}:\d{2} [AP]M/expect(item).to have_link href: user_path(author)