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

[#60875] Introduce comment "copy link" drawn from the comment id replacing sequenced activity numbers

Kabiru Mwenja4dc433ca1f66
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 7ea180f1a7a..832900e2444 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,12 +1,12 @@
<%=
component_wrapper(data: wrapper_data_attributes, class: "work-packages-activities-tab-journals-item-component") do
- flex_layout(data: {
+ flex_layout(data: {
test_selector: "op-wp-journal-entry-#{journal.id}"
}) do |journal_container|
if show_comment_container?
journal_container.with_row do
render(border_box_container(
- id: "activity-anchor-#{journal.sequence_version}",
+ id: "activity-anchor-#{journal_container_id}",
padding: :condensed,
"aria-label": I18n.t("activities.work_packages.activity_tab.commented")
)) do |border_box_component|
@@ -55,21 +55,13 @@
))
end
end
- header_end_container.with_column do
- render(Primer::Beta::Link.new(
- href: activity_url(journal),
- scheme: :secondary,
- underline: false,
- font_size: :small,
- data: {
- turbo: false,
- action: "click->work-packages--activities-tab--index#setAnchor:prevent",
- "work-packages--activities-tab--index-id-param": journal.sequence_version
- }
- )) do
- "##{journal.sequence_version}"
+
+ unless OpenProject::FeatureDecisions.work_package_comment_id_url_active?
+ header_end_container.with_column do
+ activity_anchor_link(journal)
end
end
+
header_end_container.with_column(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|
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 af733a7474c..15bf31665e5 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component.rb
@@ -90,6 +90,10 @@ module WorkPackages
User.current.allowed_in_project?(:add_work_package_notes, journal.journable.project)
end
+ def journal_container_id
+ journal_activity_id(journal)
+ end
+
def copy_url_action_item(menu)
menu.with_item(label: t("button_copy_link_to_clipboard"),
tag: :button,
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 529fbcd6ab9..2cbcb6b3688 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
@@ -193,16 +193,7 @@ module WorkPackages
pr: 3,
classes: "work-packages-activities-tab-journals-item-component-details--activity-link-container"
) do
- render(Primer::Beta::Link.new(
- href: activity_url(journal),
- scheme: :secondary,
- underline: false,
- font_size: :small,
- data: { turbo: false, action: "click->work-packages--activities-tab--index#setAnchor:prevent",
- "work-packages--activities-tab--index-id-param": journal.sequence_version }
- )) do
- "##{journal.sequence_version}"
- end
+ activity_anchor_link(journal)
end
end
diff --git a/app/components/work_packages/activities_tab/shared_helpers.rb b/app/components/work_packages/activities_tab/shared_helpers.rb
index 4540142cf74..65e4984dc5a 100644
--- a/app/components/work_packages/activities_tab/shared_helpers.rb
+++ b/app/components/work_packages/activities_tab/shared_helpers.rb
@@ -43,6 +43,23 @@ module WorkPackages
end
end
+ def activity_anchor_link(journal)
+ render(Primer::Beta::Link.new(
+ href: activity_url(journal),
+ scheme: :secondary,
+ underline: false,
+ font_size: :small,
+ data: {
+ turbo: false,
+ action: "click->work-packages--activities-tab--index#setAnchor:prevent",
+ "work-packages--activities-tab--index-id-param": journal_activity_id(journal),
+ "work-packages--activities-tab--index-anchor-name-param": anchor_name
+ }
+ )) do
+ "##{journal_activity_id(journal)}"
+ end
+ end
+
def journal_sorting
User.current.preference&.comments_sorting || OpenProject::Configuration.default_comment_sort_order
end
@@ -52,7 +69,19 @@ module WorkPackages
end
def activity_anchor(journal)
- "#activity-#{journal.sequence_version}"
+ "##{anchor_name}-#{journal_activity_id(journal)}"
+ end
+
+ def anchor_name
+ OpenProject::FeatureDecisions.work_package_comment_id_url_active? ? "comment" : "activity"
+ end
+
+ def journal_activity_id(journal)
+ if OpenProject::FeatureDecisions.work_package_comment_id_url_active?
+ journal.id
+ else
+ journal.sequence_version
+ end
end
end
end
diff --git a/config/initializers/feature_decisions.rb b/config/initializers/feature_decisions.rb
index 5a969cf8e5c..763b13179cb 100644
--- a/config/initializers/feature_decisions.rb
+++ b/config/initializers/feature_decisions.rb
@@ -68,3 +68,8 @@ OpenProject::FeatureDecisions.add :oidc_token_exchange,
description: "Enables the under construction OAuth2 token exchange, allowing " \
"users to interact with storage providers without consenting " \
"in OAuth screens before first use."
+
+OpenProject::FeatureDecisions.add :work_package_comment_id_url,
+ description: "Introduced a new WP comment URL identifier structure " \
+ "`#comment-<journal-id>` replacing the old " \
+ "`#activity-<journal-sequence_number>`."
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 b0b1cf60ab9..cc919a20ada 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
@@ -8,6 +8,7 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
interface CustomEventWithIdParam extends Event {
params:{
id:string;
+ anchorName:string;
};
}
@@ -350,9 +351,11 @@ export default class IndexController extends Controller {
}
private handleInitialScroll() {
- if (window.location.hash.includes('#activity-')) {
- const activityId = window.location.hash.replace('#activity-', '');
- this.scrollToActivity(activityId);
+ // Ex. [ "#comment-80", "comment", "80" ]
+ const activityIdMatch = window.location.hash.match(/#(comment|activity)-(\d+)/);
+
+ if (activityIdMatch && activityIdMatch.length === 3) {
+ this.scrollToActivity(activityIdMatch[2]);
} else if (this.sortingValue === 'asc' && (!this.isMobile() || this.isWithinNotificationCenter())) {
this.scrollToBottom();
}
@@ -429,9 +432,10 @@ export default class IndexController extends Controller {
// native anchor scroll is causing positioning issues
event.preventDefault();
const activityId = event.params.id;
+ const anchorName = event.params.anchorName;
this.scrollToActivity(activityId);
- window.location.hash = `#activity-${activityId}`;
+ window.location.hash = `#${anchorName}-${activityId}`;
}
private getCkEditorElement():HTMLElement | null {