Skip to content

Commit

Permalink
[#60875] Introduce comment "copy link" drawn from the comment id repl…
Browse files Browse the repository at this point in the history
…acing sequenced activity numbers

https://community.openproject.org/work_packages/60875
  • Loading branch information
akabiru committed Jan 24, 2025
1 parent 269bc5c commit 4dc433c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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|
Expand Down Expand Up @@ -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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def allowed_to_quote?
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,7 @@ def render_activity_link(container)
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

Expand Down
31 changes: 30 additions & 1 deletion app/components/work_packages/activities_tab/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ def truncated_user_name(user)
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
Expand All @@ -52,7 +69,19 @@ def activity_url(journal)
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
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/feature_decisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@
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>`."
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
interface CustomEventWithIdParam extends Event {
params:{
id:string;
anchorName:string;
};
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4dc433c

Please sign in to comment.