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

fixed filter behavior

Jonas Jabarib09c50d0288e
diff --git a/app/components/work_packages/activities_tab/journals/day_component.html.erb b/app/components/work_packages/activities_tab/journals/day_component.html.erb
index 3b547089447..f221b92151b 100644
--- a/app/components/work_packages/activities_tab/journals/day_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/day_component.html.erb
@@ -9,7 +9,7 @@
journals.each do |journal|
journals_of_day_container.with_row do
render(
- WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:)
+ WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:, filter:)
)
end
end
diff --git a/app/components/work_packages/activities_tab/journals/day_component.rb b/app/components/work_packages/activities_tab/journals/day_component.rb
index 2b72d553e33..5ddc32cc8a3 100644
--- a/app/components/work_packages/activities_tab/journals/day_component.rb
+++ b/app/components/work_packages/activities_tab/journals/day_component.rb
@@ -36,17 +36,18 @@ module WorkPackages
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(day_as_date:, journals:, work_package:)
+ def initialize(day_as_date:, journals:, work_package:, filter:)
super
@work_package = work_package
@day_as_date = day_as_date
@journals = journals
+ @filter = filter
end
private
- attr_reader :work_package, :day_as_date, :journals
+ attr_reader :work_package, :day_as_date, :journals, :filter
def insert_target_modified?
true
diff --git a/app/components/work_packages/activities_tab/journals/index_component.html.erb b/app/components/work_packages/activities_tab/journals/index_component.html.erb
index fdac77e9d30..6eed26bc545 100644
--- a/app/components/work_packages/activities_tab/journals/index_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/index_component.html.erb
@@ -5,7 +5,7 @@
journals_grouped_by_day.each do |day, journals|
journals_index_container.with_row do
render(
- WorkPackages::ActivitiesTab::Journals::DayComponent.new(day_as_date: day, journals:, work_package:)
+ WorkPackages::ActivitiesTab::Journals::DayComponent.new(day_as_date: day, journals:, work_package:, filter:)
)
end
end
diff --git a/app/components/work_packages/activities_tab/journals/index_component.rb b/app/components/work_packages/activities_tab/journals/index_component.rb
index 5dc61aedbf5..d2dfa17857e 100644
--- a/app/components/work_packages/activities_tab/journals/index_component.rb
+++ b/app/components/work_packages/activities_tab/journals/index_component.rb
@@ -63,7 +63,6 @@ module WorkPackages
result = work_package.journals.includes(:user, :notifications).reorder(version: journal_sorting)
result = result.where.not(notes: "") if filter == :only_comments
- result = result.where(notes: "") if filter == :only_changes
result.group_by { |journal| journal.created_at.in_time_zone(User.current.time_zone).to_date }
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component.html.erb b/app/components/work_packages/activities_tab/journals/item_component.html.erb
index 0a8d45e5a9d..50613ac1021 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/item_component.html.erb
@@ -1,8 +1,8 @@
<%=
component_wrapper(data: wrapper_data_attributes, class: "work-packages-activities-tab-journals-item-component") do
flex_layout do |journal_container|
- if journal.notes.present?
- journal_container.with_row do
+ if show_comment_container?
+ journal_container.with_row(classes: "comment-border-box") do
render(border_box_container(id: "activity-#{journal.version}", padding: :condensed)) do |border_box_component|
border_box_component.with_header(px: 2, py: 0) do
flex_layout(align_items: :center, justify_content: :space_between) do |header_container|
@@ -73,7 +73,7 @@
end
end
journal_container.with_row do
- render(WorkPackages::ActivitiesTab::Journals::ItemComponent::Details.new(journal:, has_unread_notifications: notification_on_details?))
+ render(WorkPackages::ActivitiesTab::Journals::ItemComponent::Details.new(journal:, has_unread_notifications: notification_on_details?, filter:))
end
end
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component.rb b/app/components/work_packages/activities_tab/journals/item_component.rb
index 7b7042b8231..67048023500 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component.rb
@@ -34,11 +34,12 @@ module WorkPackages
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(journal:, state: :show)
+ def initialize(journal:, filter:, state: :show)
super
@journal = journal
@state = state
+ @filter = filter
end
def content
@@ -52,14 +53,14 @@ module WorkPackages
private
- attr_reader :journal, :state
+ attr_reader :journal, :state, :filter
def wrapper_uniq_by
journal.id
end
def child_component_params
- { journal: }.compact
+ { journal:, filter: }.compact
end
def wrapper_data_attributes
@@ -70,6 +71,10 @@ module WorkPackages
}
end
+ def show_comment_container?
+ journal.notes.present? && filter != :only_changes
+ end
+
def activity_url
"#{project_work_package_url(journal.journable.project, journal.journable)}/activity#{activity_anchor}"
end
@@ -110,7 +115,7 @@ module WorkPackages
def edit_action_item(menu)
menu.with_item(label: t("js.label_edit_comment"),
- href: edit_work_package_activity_path(journal.journable, journal),
+ href: edit_work_package_activity_path(journal.journable, journal, filter:),
content_arguments: {
data: { "turbo-stream": true }
}) do |item|
diff --git a/app/components/work_packages/activities_tab/journals/item_component/details.html.erb b/app/components/work_packages/activities_tab/journals/item_component/details.html.erb
index 384c3c0a532..561ee79a863 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/details.html.erb
+++ b/app/components/work_packages/activities_tab/journals/item_component/details.html.erb
@@ -1,14 +1,21 @@
<%=
component_wrapper(class: "work-packages-activities-tab-journals-item-component-details") do
- if journal.details.any?
+ if journal.details.any? && filter != :only_comments
flex_layout(my: 0, border: :left, classes: "details-container") do |details_container|
- if journal.notes.present?
+ if journal.notes.present? && filter != :only_changes
render_details(details_container)
else
render_details_header(details_container)
render_details(details_container)
end
end
+ elsif journal.details.empty?
+ unless filter == :only_changes
+ flex_layout(my: 0, border: :left, classes: "details-container details-container--empty--#{journal_sorting}") do |details_container|
+ # empty row to render the flex layout with its minimal height
+ render_empty_line(details_container)
+ end
+ end
else
flex_layout(my: 0, border: :left, classes: "details-container details-container--empty--#{journal_sorting}") do |details_container|
# empty row to render the flex layout with its minimal height
diff --git a/app/components/work_packages/activities_tab/journals/item_component/details.rb b/app/components/work_packages/activities_tab/journals/item_component/details.rb
index 776d8db809e..1152bc0ddca 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/details.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component/details.rb
@@ -36,16 +36,17 @@ module WorkPackages
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(journal:, has_unread_notifications: false)
+ def initialize(journal:, filter:, has_unread_notifications: false)
super
@journal = journal
@has_unread_notifications = has_unread_notifications
+ @filter = filter
end
private
- attr_reader :journal, :has_unread_notifications
+ attr_reader :journal, :has_unread_notifications, :filter
def wrapper_uniq_by
journal.id
diff --git a/app/components/work_packages/activities_tab/journals/item_component/edit.html.erb b/app/components/work_packages/activities_tab/journals/item_component/edit.html.erb
index 47bbd8e0bf8..a17fb186d2f 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/edit.html.erb
+++ b/app/components/work_packages/activities_tab/journals/item_component/edit.html.erb
@@ -6,7 +6,7 @@
model: journal,
method: :put,
data: { turbo: true, turbo_stream: true },
- url: work_package_activity_path(work_package_id: work_package.id, id: journal.id),
+ url: work_package_activity_path(work_package_id: work_package.id, id: journal.id, filter:),
) do |f|
flex_layout do |form_container|
form_container.with_row do
@@ -18,7 +18,7 @@
scheme: :secondary,
size: :medium,
tag: :a,
- href: cancel_edit_work_package_activity_path(work_package.id, id: journal.id),
+ href: cancel_edit_work_package_activity_path(work_package.id, id: journal.id, filter:),
data: { "turbo-stream": true }
)) do
t("button_cancel")
diff --git a/app/components/work_packages/activities_tab/journals/item_component/edit.rb b/app/components/work_packages/activities_tab/journals/item_component/edit.rb
index 8bf22a5f7a8..a6bc75b2207 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/edit.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component/edit.rb
@@ -34,16 +34,17 @@ module WorkPackages
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(journal:)
+ def initialize(journal:, filter:)
super
@journal = journal
@work_package = journal.journable
+ @filter = filter
end
private
- attr_reader :journal, :work_package
+ attr_reader :journal, :work_package, :filter
def wrapper_uniq_by
journal.id
diff --git a/app/components/work_packages/activities_tab/journals/item_component/show.rb b/app/components/work_packages/activities_tab/journals/item_component/show.rb
index a461cd5e43e..e3abc222206 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/show.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component/show.rb
@@ -36,15 +36,16 @@ module WorkPackages
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(journal:)
+ def initialize(journal:, filter:)
super
@journal = journal
+ @filter = filter
end
private
- attr_reader :journal
+ attr_reader :journal, :filter
def wrapper_uniq_by
journal.id
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index f304d4abc29..3c2c42c722c 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -76,7 +76,8 @@ class WorkPackages::ActivitiesTabController < ApplicationController
update_via_turbo_stream(
component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
journal: @journal,
- state: :edit
+ state: :edit,
+ filter: params[:filter]&.to_sym || :all
)
)
@@ -87,7 +88,8 @@ class WorkPackages::ActivitiesTabController < ApplicationController
update_via_turbo_stream(
component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
journal: @journal,
- state: :show
+ state: :show,
+ filter: params[:filter]&.to_sym || :all
)
)
@@ -111,15 +113,14 @@ class WorkPackages::ActivitiesTabController < ApplicationController
update_via_turbo_stream(
component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
journal: call.result,
- state: :show
+ state: :show,
+ filter: params[:filter]&.to_sym || :all
)
)
end
generate_time_based_update_streams(params[:last_update_timestamp], params[:filter])
end
- # clear_form_via_turbo_stream
-
respond_with_turbo_streams
end
@@ -132,7 +133,8 @@ class WorkPackages::ActivitiesTabController < ApplicationController
update_via_turbo_stream(
component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
journal: call.result,
- state: :show
+ state: :show,
+ filter: params[:filter]&.to_sym || :all
)
)
end
@@ -185,28 +187,27 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
def generate_time_based_update_streams(last_update_timestamp, filter)
+ filter = filter&.to_sym || :all
# TODO: prototypical implementation
journals = @work_package.journals
- if filter == "only_comments"
+ if filter == :only_comments
journals = journals.where.not(notes: "")
end
- if filter == "only_changes"
- journals = journals.where(notes: "")
- end
-
journals.where("updated_at > ?", last_update_timestamp).find_each do |journal|
update_via_turbo_stream(
# only use the show component in order not to loose an edit state
component: WorkPackages::ActivitiesTab::Journals::ItemComponent::Show.new(
- journal:
+ journal:,
+ filter:
)
)
update_via_turbo_stream(
# only use the show component in order not to loose an edit state
component: WorkPackages::ActivitiesTab::Journals::ItemComponent::Details.new(
- journal:
+ journal:,
+ filter:
)
)
end
@@ -214,28 +215,32 @@ class WorkPackages::ActivitiesTabController < ApplicationController
latest_journal_visible_for_user = journals.where(created_at: ..last_update_timestamp).last
journals.where("created_at > ?", last_update_timestamp).find_each do |journal|
- append_or_prepend_latest_journal_via_turbo_stream(journal, latest_journal_visible_for_user)
+ append_or_prepend_latest_journal_via_turbo_stream(journal, latest_journal_visible_for_user, filter)
end
end
- def append_or_prepend_latest_journal_via_turbo_stream(journal, latest_journal)
+ def append_or_prepend_latest_journal_via_turbo_stream(journal, latest_journal, filter)
if latest_journal.created_at.to_date == journal.created_at.to_date
target_component = WorkPackages::ActivitiesTab::Journals::DayComponent.new(
work_package: @work_package,
day_as_date: journal.created_at.to_date,
- journals: [journal] # we don't need to pass all actual journals of this day as we do not really render this component
+ journals: [journal], # we don't need to pass all actual journals of this day as we do not really render this component
+ filter:
)
component = WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
- journal:
+ journal:,
+ filter:
)
else
target_component = WorkPackages::ActivitiesTab::Journals::IndexComponent.new(
- work_package: @work_package
+ work_package: @work_package,
+ filter:
)
component = WorkPackages::ActivitiesTab::Journals::DayComponent.new(
work_package: @work_package,
day_as_date: journal.created_at.to_date,
- journals: [journal]
+ journals: [journal],
+ filter:
)
end
stream_config = {
@@ -250,18 +255,4 @@ class WorkPackages::ActivitiesTabController < ApplicationController
prepend_via_turbo_stream(**stream_config)
end
end
-
- def update_journal_via_turbo_stream(journal)
- update_via_turbo_stream(
- component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:)
- )
- end
-
- def clear_form_via_turbo_stream
- update_via_turbo_stream(
- component: WorkPackages::ActivitiesTab::Journals::NewComponent.new(
- work_package: @work_package
- )
- )
- end
end
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
index 097eb712e87..aff02ebe912 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
@@ -347,12 +347,19 @@ export default class IndexController extends Controller {
// TODO: I wasn't able to find a pure CSS solution
// Didn't want to identify on server-side which element is last in the list in order to avoid n+1 queries
// happy to get rid of this hacky JS solution!
- this.element.querySelectorAll('.details-container--empty--last--asc').forEach((container) => container.classList.remove('details-container--empty--last--asc'));
-
- const containers = this.element.querySelectorAll('.details-container--empty--asc');
- if (containers.length > 0) {
- const lastContainer = containers[containers.length - 1] as HTMLElement;
- lastContainer.classList.add('details-container--empty--last--asc');
- }
+ //
+ // Note: below works but not if filter is changed, skipping for now
+ //
+ // this.element.querySelectorAll('.details-container--empty--last--asc').forEach((container) => container.classList.remove('details-container--empty--last--asc'));
+
+ // const containers = this.element.querySelectorAll('.details-container--empty--asc');
+ // if (containers.length > 0) {
+ // const lastContainer = containers[containers.length - 1] as HTMLElement;
+ // // only apply for stem part after comment box
+ // if (lastContainer?.parentElement?.parentElement?.previousElementSibling?.classList.contains('comment-border-box')) {
+ // lastContainer.classList.add('details-container--empty--last--asc');
+ // }
+ // // lastContainer.classList.add('details-container--empty--last--asc');
+ // }
}
}