Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6392 Comment actions when replying in full page #4381

Merged
merged 25 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ def redirect_to_all_comments(commentable, options = {})
delete_comment_id: options[:delete_comment_id],
view_full_work: options[:view_full_work],
anchor: options[:anchor],
page: options[:page]
page: options[:page],
only_path: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicted about this.

On one hand, it does fix every issue I had in tests about being redirect to the wrong domain (example.com).

On the other, changing such a critical piece of code just so tests pass trigger every warning in my brain.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm normally not a fan of that either, and the alarm bells are screaming. But ignoring my knee-jerk "let's not do this," I can't think of a reason it shouldn't be only_path: true. We definitely prefer paths to URLs. I think the only reason we hadn't already changed it is we do something in nginx that means this wasn't actively causing issues when we were supporting both HTTP and HTTPS. So this is probably fine.

end
end

Expand Down
31 changes: 15 additions & 16 deletions app/helpers/comments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,6 @@ def can_review_comment?(comment)

#### HELPERS FOR REPLYING TO COMMENTS #####

def add_cancel_comment_reply_link(comment)
if params[:add_comment_reply_id] && params[:add_comment_reply_id] == comment.id.to_s
cancel_comment_reply_link(comment)
else
add_comment_reply_link(comment)
end
end

# return link to add new reply to a comment
def add_comment_reply_link(comment)
commentable_id = comment.ultimate_parent.is_a?(Tag) ?
Expand Down Expand Up @@ -250,14 +242,17 @@ def cancel_comment_reply_link(comment)
comment.parent.id
link_to(
ts("Cancel"),
url_for(controller: :comments,
action: :cancel_comment_reply,
id: comment.id,
comment_id: params[:comment_id],
commentable_id => commentable_value,
view_full_work: params[:view_full_work],
page: params[:page]),
remote: true)
url_for(
controller: :comments,
action: :cancel_comment_reply,
id: comment.id,
comment_id: params[:comment_id],
commentable_id => commentable_value,
view_full_work: params[:view_full_work],
page: params[:page]
),
remote: true
)
end

# canceling an edit
Expand Down Expand Up @@ -394,4 +389,8 @@ def comments_are_moderated(commentable)
parent = find_parent(commentable)
parent.respond_to?(:moderated_commenting_enabled) && parent.moderated_commenting_enabled?
end

def focused_on_comment(commentable)
params[:add_comment_reply_id] && params[:add_comment_reply_id] == commentable.id.to_s
end
end
6 changes: 3 additions & 3 deletions app/views/comments/_comment_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h5 class="landmark heading"><%= ts("Comment Actions") %></h5>

<ul class="actions" id="navigation_for_comment_<%= comment.id %>">
<ul class="actions" id="navigation_for_comment_<%= comment.id %>" <% if focused_on_comment(comment) %> style="display:none;"<% end %>>
<% # The effect is "Frozen" replaces "Reply." We can't do that in the helper
# method for the reply link because that would prevent "Frozen" from
# appearing on the Unreviewed Comments page for works with moderated
Expand All @@ -9,7 +9,7 @@
<li><%= frozen_comment_indicator %></li>
<% end %>
<% if can_reply_to_comment?(comment) %>
<li id="add_comment_reply_link_<%= comment.id %>"><%= add_cancel_comment_reply_link comment %></li>
<li id="add_comment_reply_link_<%= comment.id %>"><%= add_comment_reply_link comment %></li>
<% end %>
<% unless comment.unreviewed? %>
<li><%= link_to ts("Thread"), comment %></li>
Expand Down Expand Up @@ -65,7 +65,7 @@
<% if can_reply_to_comment?(comment) %>
<% # This is where the reply-to box will be added when "Reply" is hit, if the user has JavaScript. %>
<% # If not, we will render the comment form if this is the comment we are replying to. %>
<% if params[:add_comment_reply_id] && params[:add_comment_reply_id] == comment.id.to_s %>
<% if focused_on_comment(comment) %>
<div id="add_comment_reply_placeholder_<%= comment.id %>" title="<%= ts("reply to this comment") %>">
<%= render 'comments/comment_form',
:comment => Comment.new,
Expand Down
37 changes: 37 additions & 0 deletions features/comments_and_kudos/add_comment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,43 @@ Scenario: Users with different time zone preferences should see the time in thei
Then I should see "AEST" within ".posted.datetime"
And I should see "AEST" within ".edited.datetime"

Scenario: It hides comment actions when a reply form is open
Given the work "The One Where Neal is Awesome"
And I am logged in as "commenter"
And I post the comment "I loved this!" on the work "The One Where Neal is Awesome"
When I follow "Reply"
Then I should see "Comment as commenter"
And I should not see "Thread"

@javascript
Scenario: It shows and hides cancel buttons properly
Given the work "Aftermath" by "creator" with guest comments enabled
And a comment "Ugh." by "pest" on the work "Aftermath"
When I view the work "Aftermath"
And I display comments
Then I should see "Ugh."
When I open the reply box
Then I should see "Cancel"
But I should not see "Reply"
When I cancel the reply box
Then I should not see "Cancel"
But I should see "Reply"

@javascript
Scenario: It shows and hides cancel buttons properly even on a new page
Given the work "Aftermath" by "creator" with guest comments enabled
And a comment "Ugh." by "pest" on the work "Aftermath"
When I view the work "Aftermath"
And I display comments
Then I should see "Ugh."
# Go to /chapters/XX?add_comment_reply_id=YY&show_comments=true#comment_YY"; akin to a Ctrl+Click on "Reply"
When I reply on a new page
Then I should see "Cancel"
But I should not see "Reply"
When I cancel the reply box
Then I should not see "Cancel"
But I should see "Reply"

Scenario: Cannot comment (no form) while logged as admin

Given the work "Generic Work" by "creator" with guest comments enabled
Expand Down
16 changes: 16 additions & 0 deletions features/step_definitions/comment_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,19 @@
When "I confirm I want to mark the comment as spam" do
expect(page.accept_alert).to eq("Are you sure you want to mark this as spam?") if @javascript
end

When "I display comments" do
click_link("Comments")
end

When "I open the reply box" do
click_link("Reply")
end

When "I cancel the reply box" do
click_link("Cancel")
end

When "I reply on a new page" do
visit find(:link, "Reply")["href"]
end
ceithir marked this conversation as resolved.
Show resolved Hide resolved
Loading