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

[46191] Indicate the subproject only when the update concerns a subproject

Mir Bhatia6300e75cca38
diff --git a/app/components/activities/days_component.html.erb b/app/components/activities/days_component.html.erb
index cac31715ac6..ef82be8d038 100644
--- a/app/components/activities/days_component.html.erb
+++ b/app/components/activities/days_component.html.erb
@@ -3,6 +3,7 @@
<%= content_tag(@header_tag, helpers.format_activity_day(day), class: 'op-activity-days--header') %>
<%= render(Activities::ListComponent.new(events:,
+ current_project: @current_project,
display_user: @display_user,
activity_page: @activity_page))
%>
diff --git a/app/components/activities/days_component.rb b/app/components/activities/days_component.rb
index 6b5b081d57d..807cca8d276 100644
--- a/app/components/activities/days_component.rb
+++ b/app/components/activities/days_component.rb
@@ -29,9 +29,10 @@
#++
class Activities::DaysComponent < ViewComponent::Base
- def initialize(events:, display_user: true, header_tag: 'h3', activity_page: nil)
+ def initialize(events:, current_project: nil, display_user: true, header_tag: 'h3', activity_page: nil)
super()
@events = events
+ @current_project = current_project
@display_user = display_user
@header_tag = header_tag
@activity_page = activity_page
diff --git a/app/components/activities/item_component.html.erb b/app/components/activities/item_component.html.erb
index 9f0b6a5b650..cdb1ad2f1fe 100644
--- a/app/components/activities/item_component.html.erb
+++ b/app/components/activities/item_component.html.erb
@@ -1,9 +1,7 @@
<li class="op-activity-list--item">
<div class="op-activity-list--item-title">
<%= link_to format_activity_title(@event.event_title), @event.event_path %>
- <% if display_belonging_project? -%>
- (<%= I18n.t('events.title.project', name: content_tag('span', link_to(@event.project.name, @event.project), class: 'project')).html_safe %>)
- <% end -%>
+ <%= project_suffix %>
</div>
<%=
render(Activities::ItemSubtitleComponent.new(user: display_user? && @event.event_author,
diff --git a/app/components/activities/item_component.rb b/app/components/activities/item_component.rb
index 13beb30546c..4ca2c90b870 100644
--- a/app/components/activities/item_component.rb
+++ b/app/components/activities/item_component.rb
@@ -30,16 +30,23 @@
class Activities::ItemComponent < ViewComponent::Base
with_collection_parameter :event
+ strip_trailing_whitespace
- def initialize(event:, display_user: true, activity_page: nil)
+ def initialize(event:, current_project: nil, display_user: true, activity_page: nil)
super()
@event = event
+ @current_project = current_project
@display_user = display_user
@activity_page = activity_page
end
- def display_belonging_project?
- @event.journal.journable_type != 'Project'
+ def project_suffix
+ return if project_activity?
+ return if activity_is_from_current_project?
+
+ kind = activity_is_from_subproject? ? 'subproject' : 'project'
+ suffix = I18n.t("events.title.#{kind}", name: link_to(@event.project.name, @event.project))
+ "(#{suffix})".html_safe # rubocop:disable Rails/OutputSafety
end
def display_user?
@@ -64,18 +71,32 @@ class Activities::ItemComponent < ViewComponent::Base
end
def comment
- return unless work_package?
+ return unless work_package_activity?
@event.event_description
end
def description
- return if work_package?
+ return if work_package_activity?
@event.event_description
end
- def work_package?
+ private
+
+ def work_package_activity?
@event.journal.journable_type == "WorkPackage"
end
+
+ def project_activity?
+ @event.journal.journable_type == 'Project'
+ end
+
+ def activity_is_from_current_project?
+ @current_project && (@event.project == @current_project)
+ end
+
+ def activity_is_from_subproject?
+ @current_project && (@event.project != @current_project)
+ end
end
diff --git a/app/components/activities/list_component.html.erb b/app/components/activities/list_component.html.erb
index 31bd35fc0db..d732652e7bd 100644
--- a/app/components/activities/list_component.html.erb
+++ b/app/components/activities/list_component.html.erb
@@ -1,6 +1,9 @@
<ul class="op-activity-list">
- <%= render(Activities::ItemComponent.with_collection(@events,
- display_user: @display_user,
- activity_page: @activity_page))
+ <%=
+ render(Activities::ItemComponent.with_collection(@events,
+ current_project: @current_project,
+ display_user: @display_user,
+ activity_page: @activity_page))
+
%>
</ul>
diff --git a/app/components/activities/list_component.rb b/app/components/activities/list_component.rb
index dfa0cf31f14..784eac34f39 100644
--- a/app/components/activities/list_component.rb
+++ b/app/components/activities/list_component.rb
@@ -29,9 +29,10 @@
#++
class Activities::ListComponent < ViewComponent::Base
- def initialize(events:, display_user: true, activity_page: nil)
+ def initialize(events:, current_project:, display_user: true, activity_page: nil)
super()
@events = events.sort { |x, y| y.event_datetime <=> x.event_datetime }
+ @current_project = current_project
@display_user = display_user
@activity_page = activity_page
end
diff --git a/app/views/activities/index.html.erb b/app/views/activities/index.html.erb
index 0c91921d410..f98d122f27c 100644
--- a/app/views/activities/index.html.erb
+++ b/app/views/activities/index.html.erb
@@ -33,7 +33,7 @@ See COPYRIGHT and LICENSE files for more details.
subtitle: t(:label_date_from_to, start: format_date(@date_to - @days), end: format_date(@date_to-1))
%>
-<%= render(Activities::DaysComponent.new(events: @events, activity_page: @activity_page)) %>
+<%= render(Activities::DaysComponent.new(events: @events, current_project: @project, activity_page: @activity_page)) %>
<% if @events.empty? %>
<%= no_results_box %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 41b0f9e8e0e..ca035d5e700 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1427,6 +1427,7 @@ en:
work_package_note: 'Work Package note added'
title:
project: "Project: %{name}"
+ subproject: "Subproject: %{name}"
export:
your_work_packages_export: "Your work packages export"
diff --git a/spec/components/activities/item_component_spec.rb b/spec/components/activities/item_component_spec.rb
index 3daa6a0d3b1..73d20a4185d 100644
--- a/spec/components/activities/item_component_spec.rb
+++ b/spec/components/activities/item_component_spec.rb
@@ -42,20 +42,59 @@ RSpec.describe Activities::ItemComponent, type: :component do
journal:
)
end
- let(:project) { build_stubbed(:project) }
+ let(:project) { build_stubbed(:project, name: 'My project') }
let(:journal) { build_stubbed(:work_package_journal) }
- it 'renders the title escaped' do
- event.event_title = 'Hello <b>World</b>!'
+ it 'renders the activity title' do
render_inline(described_class.new(event:))
- expect(page).to have_css('.op-activity-list--item-title', text: 'Hello <b>World</b>!')
+ expect(page).to have_css('.op-activity-list--item-title', text: 'Event Title')
end
- it 'renders the project name to which the event belongs, escaped' do
+ it 'adds "(Project: ...)" suffix after the activity title' do
+ render_inline(described_class.new(event:))
+
+ expect(page).to have_css('.op-activity-list--item-title', text: /Event Title\s+\(Project: My project\)/)
+ end
+
+ it 'escapes HTML in the activity title and the project suffix' do
+ event.event_title = 'Hello <b>World</b>!'
event.project.name = 'Project <b>name</b> with HTML'
render_inline(described_class.new(event:))
- expect(page).to have_css('.op-activity-list--item-title', text: '(Project: Project <b>name</b> with HTML)')
+ expect(page).to have_css('.op-activity-list--item-title', text: 'Hello <b>World</b>!')
+ expect(page).to have_css('.op-activity-list--item-title', text: 'Project: Project <b>name</b> with HTML)')
+ end
+
+ context 'for Project activities' do
+ let(:journal) { build_stubbed(:project_journal) }
+
+ it 'does not add the project suffix' do
+ component = described_class.new(event:)
+ render_inline(component)
+
+ expect(component.project_suffix).to be_nil
+ expect(page).to have_css('.op-activity-list--item-title', text: /\A\s*Event Title\s*\z/)
+ end
+ end
+
+ context 'when :current_project is set' do
+ it 'does not display the project suffix for activities of the current project' do
+ event.project.name = 'My project'
+ component = described_class.new(event:, current_project: project)
+ render_inline(component)
+
+ expect(component.project_suffix).to be_nil
+ expect(page).not_to have_css('.op-activity-list--item-title', text: '(Project: My project)')
+ end
+
+ it 'adds "(Subproject: ...)" suffix for activities of subprojects of the current project' do
+ parent_project = build_stubbed(:project)
+ event.project.parent = parent_project
+ event.project.name = 'My subproject'
+ render_inline(described_class.new(event:, current_project: parent_project))
+
+ expect(page).to have_css('.op-activity-list--item-title', text: '(Subproject: My subproject)')
+ end
end
end