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
Defer loading of journal items actions menu for improved performance (#20566)
Kabiru Mwenjafe5ced513079
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.erbindex 79ae87b2ba2..0a75697f056 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@@ -95,15 +95,18 @@ml: 1,classes: "work-packages-activities-tab-journals-item-component--action-menu") do- render(Primer::Alpha::ActionMenu.new(data: { test_selector: "op-wp-journal-#{journal.id}-action-menu" })) do |menu|+ render(+ Primer::Alpha::ActionMenu.new(+ menu_id:,+ data: { test_selector: "op-wp-journal-#{journal.id}-action-menu" },+ src: item_actions_work_package_activity_path(journal.journable, journal)+ )+ ) do |menu|menu.with_show_button(icon: "kebab-horizontal","aria-label": I18n.t(:button_actions),scheme: :invisible)- copy_url_action_item(menu)- edit_action_item(menu) if allowed_to_edit?- quote_action_item(menu) if journal.notes.present? && allowed_to_quote?endendenddiff --git a/app/components/work_packages/activities_tab/journals/item_component.rb b/app/components/work_packages/activities_tab/journals/item_component.rbindex 82424b83266..c6ac51e53b4 100644--- a/app/components/work_packages/activities_tab/journals/item_component.rb+++ b/app/components/work_packages/activities_tab/journals/item_component.rb@@ -51,6 +51,10 @@ module WorkPackagesattr_reader :journal, :state, :filter, :grouped_emoji_reactions+ def menu_id+ ItemComponent::Actions.menu_id(journal)+ end+def wrapper_uniq_byjournal.idend@@ -107,69 +111,6 @@ module WorkPackagesdef notification_on_details?has_unread_notifications? && journal.notes.blank?end-- def allowed_to_edit?- journal.editable_by?(User.current)- end-- def allowed_to_quote?- User.current.allowed_in_project?(:add_work_package_comments, journal.journable.project)- end-- def copy_url_action_item(menu)- menu.with_item(label: t("button_copy_link_to_clipboard"),- tag: :button,- content_arguments: {- data: {- action: "click->work-packages--activities-tab--item#copyActivityUrlToClipboard"- }- }) do |item|- item.with_leading_visual_icon(icon: :copy)- end- end-- def edit_action_item(menu)- menu.with_item(label: edit_action_label,- href: edit_work_package_activity_path(journal.journable, journal, filter:),- content_arguments: {- data: { turbo_stream: true, test_selector: "op-wp-journal-#{journal.id}-edit" }- }) do |item|- item.with_leading_visual_icon(icon: :pencil)- end- end-- def edit_action_label- if journal.user == User.current- t("js.label_edit_comment")- else- t("js.label_moderate_comment")- end- end-- def quote_action_item(menu)- menu.with_item(label: t("js.label_quote_comment"),- tag: :button,- content_arguments: {- data: quote_action_data_attributes- }) do |item|- item.with_leading_visual_icon(icon: :quote)- end- end-- def quote_action_data_attributes # rubocop:disable Metrics/AbcSize- {- test_selector: "op-wp-journal-#{journal.id}-quote",- controller: quote_comments_stimulus_controller,- action: "click->#{quote_comments_stimulus_controller}#quote:prevent",- quote_comments_stimulus_controller("-content-param") => journal.notes,- quote_comments_stimulus_controller("-user-id-param") => journal.user_id,- quote_comments_stimulus_controller("-user-name-param") => journal.user.name,- quote_comments_stimulus_controller("-is-internal-param") => journal.internal?,- quote_comments_stimulus_controller("-text-wrote-param") => I18n.t(:text_wrote),- quote_comments_stimulus_controller("-#{internal_comment_stimulus_controller}-outlet") => add_comment_component_dom_selector, # rubocop:disable Layout/LineLength- quote_comments_stimulus_controller("-#{editor_stimulus_controller}-outlet") => index_component_dom_selector- }- endendendenddiff --git a/app/components/work_packages/activities_tab/journals/item_component/actions.html.erb b/app/components/work_packages/activities_tab/journals/item_component/actions.html.erbnew file mode 100644index 00000000000..ebd3a3ddbf7--- /dev/null+++ b/app/components/work_packages/activities_tab/journals/item_component/actions.html.erb@@ -0,0 +1,41 @@+<%=+ render(+ Primer::Alpha::ActionMenu::List.new(menu_id:)+ ) do |menu|+ menu.with_item(+ label: t("button_copy_link_to_clipboard"),+ tag: :button,+ content_arguments: {+ data: {+ action: "click->work-packages--activities-tab--item#copyActivityUrlToClipboard"+ }+ }+ ) do |item|+ item.with_leading_visual_icon(icon: :copy)+ end++ if editable?+ menu.with_item(+ label: edit_action_label,+ href: edit_work_package_activity_path(journal.journable, journal),+ content_arguments: {+ data: { turbo_stream: true, test_selector: "op-wp-journal-#{journal.id}-edit" }+ }+ ) do |item|+ item.with_leading_visual_icon(icon: :pencil)+ end+ end++ if quotable?+ menu.with_item(+ label: I18n.t("js.label_quote_comment"),+ tag: :button,+ content_arguments: {+ data: quote_action_data_attributes+ }+ ) do |item|+ item.with_leading_visual_icon(icon: :quote)+ end+ end+ end+%>diff --git a/app/components/work_packages/activities_tab/journals/item_component/actions.rb b/app/components/work_packages/activities_tab/journals/item_component/actions.rbnew file mode 100644index 00000000000..57a6d8cc7c4--- /dev/null+++ b/app/components/work_packages/activities_tab/journals/item_component/actions.rb@@ -0,0 +1,92 @@+# 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 WorkPackages+ module ActivitiesTab+ module Journals+ class ItemComponent::Actions < ApplicationComponent+ include WorkPackages::ActivitiesTab::StimulusControllers++ def initialize(journal)+ super++ @journal = journal+ end++ def self.menu_id(journal)+ "wp-journal-#{journal.id}-action-menu"+ end++ def menu_id+ self.class.menu_id(journal)+ end++ private++ attr_reader :journal++ def editable?+ journal.editable_by?(User.current)+ end++ def quotable?+ journal.notes.present? && allowed_to_quote?+ end++ def allowed_to_quote?+ User.current.allowed_in_project?(:add_work_package_comments, journal.journable.project)+ end++ def edit_action_label+ if journal.user == User.current+ I18n.t("js.label_edit_comment")+ else+ I18n.t("js.label_moderate_comment")+ end+ end++ def quote_action_data_attributes # rubocop:disable Metrics/AbcSize+ {+ test_selector: "op-wp-journal-#{journal.id}-quote",+ controller: quote_comments_stimulus_controller,+ action: "click->#{quote_comments_stimulus_controller}#quote:prevent",+ quote_comments_stimulus_controller("-content-param") => journal.notes,+ quote_comments_stimulus_controller("-user-id-param") => journal.user_id,+ quote_comments_stimulus_controller("-user-name-param") => journal.user.name,+ quote_comments_stimulus_controller("-is-internal-param") => journal.internal?,+ quote_comments_stimulus_controller("-text-wrote-param") => I18n.t(:text_wrote),+ quote_comments_stimulus_controller("-#{internal_comment_stimulus_controller}-outlet") => add_comment_component_dom_selector, # rubocop:disable Layout/LineLength+ quote_comments_stimulus_controller("-#{editor_stimulus_controller}-outlet") => index_component_dom_selector+ }+ end+ end+ end+ end+enddiff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rbindex 7a538028f36..98297931976 100644--- a/app/controllers/work_packages/activities_tab_controller.rb+++ b/app/controllers/work_packages/activities_tab_controller.rb@@ -34,7 +34,7 @@ class WorkPackages::ActivitiesTabController < ApplicationControllerbefore_action :find_work_packagebefore_action :find_project- before_action :find_journal, only: %i[edit cancel_edit update toggle_reaction]+ before_action :find_journal, only: %i[item_actions edit cancel_edit update toggle_reaction]before_action :set_filterbefore_action :authorize@@ -86,6 +86,11 @@ class WorkPackages::ActivitiesTabController < ApplicationControllerrespond_with_turbo_streamsend+ def item_actions+ render WorkPackages::ActivitiesTab::Journals::ItemComponent::Actions.new(@journal),+ layout: false+ end+def editif allowed_to_edit?(@journal)update_item_edit_component(journal: @journal)diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex abd50c324bd..9c24b0d57c5 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -261,7 +261,7 @@ Rails.application.reloader.to_prepare dowork_packages: %i[show index show_conflict_flash_message share_upsell],work_packages_api: [:get],"work_packages/reports": %i[report report_details],- "work_packages/activities_tab": %i[index update_streams update_sorting update_filter],+ "work_packages/activities_tab": %i[index item_actions update_streams update_sorting update_filter],"work_packages/menus": %i[show],"work_packages/hover_card": %i[show],work_package_relations_tab: %i[index],diff --git a/config/routes.rb b/config/routes.rbindex 91f76b32431..c27328bce3f 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -735,6 +735,7 @@ Rails.application.routes.draw doresources :activities, controller: "work_packages/activities_tab", only: %i[index create edit update] domember doget :cancel_edit+ get :item_actionsput :toggle_reactionenddiff --git a/spec/support/components/work_packages/activities.rb b/spec/support/components/work_packages/activities.rbindex ab6e4867566..4bc7565185a 100644--- a/spec/support/components/work_packages/activities.rb+++ b/spec/support/components/work_packages/activities.rb@@ -290,7 +290,7 @@ module Componentsif savepage.within_test_selector("op-wp-journals-container") do# wait for the comment to be loaded- wait_for { page }.to have_test_selector("op-journal-notes-body", text:)+ expect(page).to have_test_selector("op-journal-notes-body", text:, wait: 10)endend