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 21 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 @@ -665,7 +665,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 @@ -183,14 +183,6 @@ def parent_disallows_comments?(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 @@ -221,14 +213,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 @@ -364,4 +359,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
41 changes: 41 additions & 0 deletions features/comments_and_kudos/add_comment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,44 @@ Scenario: Try to post a comment with a < angle bracket before a linebreak, with
"""
And I press "Comment"
Then I should see "Comment created!"

Scenario: It hides comment actions when a reply form is open
When I am logged in as "author"
And I post the work "The One Where Neal is Awesome"
When 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"
Then I should not see "Thread"
ceithir marked this conversation as resolved.
Show resolved Hide resolved

@javascript
Scenario: It shows and hides cancel buttons properly
Given the work "Aftermath" by "creator"
And a comment "Ugh." by "pest" on the work "Aftermath"
When I am logged in as "creator"
And 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"
Then I should not see "Reply"
When I cancel the reply box
Then I should not see "Cancel"
Then I should see "Reply"
ceithir marked this conversation as resolved.
Show resolved Hide resolved

@javascript
Scenario: It shows and hides cancel buttons properly even on a new page
Given the work "Aftermath" by "creator"
And a comment "Ugh." by "pest" on the work "Aftermath"
When I am logged in as "creator"
And I view the work "Aftermath"
And I display comments
Then I should see "Ugh."
When I reply on a new page
Then I should see "Aftermath"
Then I should see "Cancel"
Then I should not see "Reply"
When I cancel the reply box
Then I should see "Aftermath"
Then I should not see "Cancel"
Then I should see "Reply"
ceithir marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions features/step_definitions/comment_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,22 @@
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
new_window = window_opened_by do
find(:link, "Reply").click(:control)
end
switch_to_window(new_window)
end
ceithir marked this conversation as resolved.
Show resolved Hide resolved
Loading