Skip to content

Commit

Permalink
AO3-6392 Comment actions when replying in full page (#4381)
Browse files Browse the repository at this point in the history
* Hide comment actions same as with JS

https://otwarchive.atlassian.net/browse/AO3-6392
Reproduce the behavior of add_comment_reply.js

* Fix Cancel button on non-JS reply

By forcing a non-JS behavior
https://otwarchive.atlassian.net/browse/AO3-6392

* Hound

* Hound

* Add test for hiding feature

* Work page test

* Add test for the cancel button not being updated

* Hound

* Hound (bis)

* Reviewdog

* Use function instead of copy paste

* Reviewdog?

* Reviewdog, but right this time

At least works locally

* Fix wrong domain issue in tests

* Wording

Totally not a trick to trigger a new build

* Rename

* Actually unused?

The first case of the if wasn't accessible anymore
As the form was hidden if the condition was true

* No more need for forced reload

* Test cleanup

* Fix guest comments in tests

---------

Co-authored-by: Brian Austin <brianjaustin@gmail.com>
  • Loading branch information
ceithir and brianjaustin authored Sep 8, 2024
1 parent 9d68c85 commit dade1c1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
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
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

0 comments on commit dade1c1

Please sign in to comment.