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

Move News widget to Overiew module and let it inherit from WidgetComponent

Henriette Darge4f4830f64e55
diff --git a/modules/grids/app/components/grids/widget_box_component.rb b/modules/grids/app/components/grids/widget_box_component.rb
index 5922380b52b..2812d862f3e 100644
--- a/modules/grids/app/components/grids/widget_box_component.rb
+++ b/modules/grids/app/components/grids/widget_box_component.rb
@@ -97,6 +97,7 @@ module Grids
def before_render
return unless header
+
@list_arguments[:aria] = { labelledby: @header_id }
end
end
diff --git a/modules/grids/app/views/grids/widgets/news/show.html.erb b/modules/grids/app/views/grids/widgets/news/show.html.erb
index f308a9bf7a8..d0a19d13267 100644
--- a/modules/grids/app/views/grids/widgets/news/show.html.erb
+++ b/modules/grids/app/views/grids/widgets/news/show.html.erb
@@ -27,4 +27,4 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= render Grids::Widgets::NewsComponent.new(project: @project, current_user:) %>
+<%= render Overviews::Widgets::NewsComponent.new(@project) %>
diff --git a/modules/overviews/app/components/overviews/overview_grid_component.html.erb b/modules/overviews/app/components/overviews/overview_grid_component.html.erb
index dd9a8f2ff28..9afccac1ecc 100644
--- a/modules/overviews/app/components/overviews/overview_grid_component.html.erb
+++ b/modules/overviews/app/components/overviews/overview_grid_component.html.erb
@@ -30,7 +30,10 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render(Grids::WidgetGridComponent.new) do |grid|
grid.with_widget(Overviews::Widgets::DescriptionComponent, @project)
- grid.with_widget(Overviews::Widgets::SubitemsComponent, @project)
grid.with_widget(Overviews::Widgets::ProjectStatusComponent, @project)
+ grid.with_widget(Overviews::Widgets::SubitemsComponent, @project)
+ if OpenProject::FeatureDecisions.beta_widgets_active?
+ grid.with_widget(Overviews::Widgets::NewsComponent, @project)
+ end
end
%>
diff --git a/modules/grids/app/components/grids/widgets/news_component.html.erb b/modules/overviews/app/components/overviews/widgets/news_component.html.erb
similarity index 82%
rename from modules/grids/app/components/grids/widgets/news_component.html.erb
rename to modules/overviews/app/components/overviews/widgets/news_component.html.erb
index fee146598e3..ebb09bf6d88 100644
--- a/modules/grids/app/components/grids/widgets/news_component.html.erb
+++ b/modules/overviews/app/components/overviews/widgets/news_component.html.erb
@@ -28,18 +28,19 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%=
- component_wrapper tag: :"turbo-frame" do
+ widget_wrapper do |container|
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)
+ @newest.each do |item|
+ container.with_row do
+ render(
+ ItemComponent.new(
+ item:,
+ project:
+ )
)
- )
+ end
end
end
end
diff --git a/modules/grids/app/components/grids/widgets/news_component.rb b/modules/overviews/app/components/overviews/widgets/news_component.rb
similarity index 91%
rename from modules/grids/app/components/grids/widgets/news_component.rb
rename to modules/overviews/app/components/overviews/widgets/news_component.rb
index 8b0529fb3bb..4765f842dbe 100644
--- a/modules/grids/app/components/grids/widgets/news_component.rb
+++ b/modules/overviews/app/components/overviews/widgets/news_component.rb
@@ -28,9 +28,9 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Grids
+module Overviews
module Widgets
- class NewsComponent < ApplicationComponent
+ class NewsComponent < Grids::WidgetComponent
NEWS_LIMIT = 5
include ApplicationHelper
@@ -39,7 +39,7 @@ module Grids
attr_reader :project, :current_user
- def initialize(project:, current_user:)
+ def initialize(project)
super()
@project = project
@@ -56,6 +56,11 @@ module Grids
@newest = @news.limit(NEWS_LIMIT).to_a
end
+
+ def title
+ Project.human_attribute_name(:news)
+ end
+
end
end
end
diff --git a/modules/grids/app/components/grids/widgets/news_component/item_component.html.erb b/modules/overviews/app/components/overviews/widgets/news_component/item_component.html.erb
similarity index 56%
rename from modules/grids/app/components/grids/widgets/news_component/item_component.html.erb
rename to modules/overviews/app/components/overviews/widgets/news_component/item_component.html.erb
index 911c5f5bf92..ed0be9a0b55 100644
--- a/modules/grids/app/components/grids/widgets/news_component/item_component.html.erb
+++ b/modules/overviews/app/components/overviews/widgets/news_component/item_component.html.erb
@@ -28,35 +28,33 @@ 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(
- flex_layout do |layout|
- unless project
- layout.with_column do
- render(
- Primer::Beta::Link.new(
- font_weight: :bold,
- scheme: :secondary,
- href: project_path(item.project)
- )
- ) { "#{item.project.name}:" }
- end
- end
-
+ render(Primer::Box.new) do
+ component_collection do |body|
+ body.with_component(
+ flex_layout do |layout|
+ unless project
layout.with_column do
- render(Primer::Beta::Link.new(ml: 1, font_weight: :bold, href: news_path(item))) { item.title }
+ render(
+ Primer::Beta::Link.new(
+ font_weight: :bold,
+ scheme: :secondary,
+ href: project_path(item.project)
+ )
+ ) { "#{item.project.name}:" }
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
+
+ layout.with_column do
+ render(Primer::Beta::Link.new(ml: 1, font_weight: :bold, href: news_path(item))) { item.title }
+ 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
%>
diff --git a/modules/grids/app/components/grids/widgets/news_component/item_component.rb b/modules/overviews/app/components/overviews/widgets/news_component/item_component.rb
similarity index 96%
rename from modules/grids/app/components/grids/widgets/news_component/item_component.rb
rename to modules/overviews/app/components/overviews/widgets/news_component/item_component.rb
index 058934e3537..da19bcc9905 100644
--- a/modules/grids/app/components/grids/widgets/news_component/item_component.rb
+++ b/modules/overviews/app/components/overviews/widgets/news_component/item_component.rb
@@ -28,9 +28,9 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Grids
+module Overviews
module Widgets
- class NewsComponent < ApplicationComponent
+ class NewsComponent < Grids::WidgetComponent
class ItemComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
diff --git a/modules/grids/spec/components/grids/widgets/news_component_spec.rb b/modules/overviews/spec/components/overviews/widgets/news_component_spec.rb
similarity index 98%
rename from modules/grids/spec/components/grids/widgets/news_component_spec.rb
rename to modules/overviews/spec/components/overviews/widgets/news_component_spec.rb
index e99f435460f..9960530ac0b 100644
--- a/modules/grids/spec/components/grids/widgets/news_component_spec.rb
+++ b/modules/overviews/spec/components/overviews/widgets/news_component_spec.rb
@@ -30,7 +30,7 @@
require "rails_helper"
-RSpec.describe Grids::Widgets::NewsComponent, type: :component do
+RSpec.describe Overviews::Widgets::NewsComponent, type: :component do
include Rails.application.routes.url_helpers
def render_component(...)