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

Merge comments/edit & comments/form Partials #9183

Merged
merged 6 commits into from
Feb 15, 2021

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Feb 11, 2021

These two partials are basically very close copies of each other... Even more so with all the recent refactoring of the Comment Editor.

In the past, if I made a change in one partial, I had to do it in the other to match.

Merging these two partials into one, to increase maintainability and DRYness!


(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)

@gitpod-io
Copy link

gitpod-io bot commented Feb 11, 2021

<% if current_user && current_user.id == @node.uid %>
<span class="pull-right" style="color:#ccc;">
<a target="_blank" href="https://publiclab.org/comment-templates">Add a template</a>
</span>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated change: I'm deleting the template functionality in this PR.

class="comment-form"
<% if location != :edit %>
action="/comment/create/<%= @node.nid %>"
data-remote="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.

This data-remote="true" (along with comment.js) seems to play a crucial role in form submission in edit forms vs. the others.

Edit comment submissions refresh the page, while reply & main comment form submissions don't!

Funnily enough, this was something that was stumping me in this comment here way back a the beginning of the internship.

Copy link
Contributor Author

@noi5e noi5e Feb 11, 2021

Choose a reason for hiding this comment

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

Like, if you're just searching in VSCode for places where submitFormAjax and addComment are called, you don't find anything. For the longest time, I thought that these functions weren't actually being called.

But now I think they are! I think they work by attaching extra classes to particular comment forms, and jQuery.triggering events. This intrigues me because a similar thing could be done to edit comment forms so they are submitted with AJAX and don't refresh the page.

Copy link
Member

Choose a reason for hiding this comment

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

OK, i think i can help here -- the data-remote attribute is used by the obscure rails-ujs library -- https://guides.rubyonrails.org/working_with_javascript_in_rails.html#remote-elements

However this is so obscure that I think it's just not worth using this technique; we don't have to remove it but let's add an explanatory comment to help future coders.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, very good to know!

@codecov
Copy link

codecov bot commented Feb 11, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@a29514a). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9183   +/-   ##
=======================================
  Coverage        ?   82.06%           
=======================================
  Files           ?      100           
  Lines           ?     5939           
  Branches        ?        0           
=======================================
  Hits            ?     4874           
  Misses          ?     1065           
  Partials        ?        0           

@codeclimate
Copy link

codeclimate bot commented Feb 11, 2021

Code Climate has analyzed commit 3f2e807 and detected 0 issues on this pull request.

View more on Code Climate.

<!-- get_comment_form_id defined in app/helpers/application_helper.rb: -->
<% comment_form_id = get_comment_form_id(location, local_assigns[:reply_to], nil) %>
<div class="comment-form-wrapper card-body" style="background-color:#f8f8f8; border: 1px solid #e7e7e7;padding: 18px;">
<form id="comment-form-<%= comment_form_id %>" class="comment-form" data-remote="true" action="/comment/create/<%= @node.nid %><%= "?type=question" if local_assigns[:type]=="question" %>" <% if local_assigns[:aid].blank? %>method="post"<% end %>>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleting this ?type=question part here.

@noi5e
Copy link
Contributor Author

noi5e commented Feb 12, 2021

Just did a lot of double-checking of the now-deleted edit partial. This one is ready to merge!

Copy link
Collaborator

@cesswairimu cesswairimu left a comment

Choose a reason for hiding this comment

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

This is looking great 🚀 thanks for working on this

@jywarren
Copy link
Member

This looks great. Thank you! This will also be easy to track if there are any errors, as the PR touches both files. So even if we catch something later this will be traceable. Thanks a lot!!!

@jywarren jywarren merged commit 7d6500a into publiclab:main Feb 15, 2021
@noi5e noi5e deleted the merge-edit-and-comment-forms branch February 15, 2021 20:20
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
* merge comments/_edit & comments/_form partials

* delete templates functionality

* merge comments/_edit & comments/_form partials; change #edit-comment-form-wrapper to #comment-form-wrapper-edit

* stop attaching ajax:event to edit forms

* stop running scripts on edit forms

* add hidden_field_tag for reply_to
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* merge comments/_edit & comments/_form partials

* delete templates functionality

* merge comments/_edit & comments/_form partials; change #edit-comment-form-wrapper to #comment-form-wrapper-edit

* stop attaching ajax:event to edit forms

* stop running scripts on edit forms

* add hidden_field_tag for reply_to
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* merge comments/_edit & comments/_form partials

* delete templates functionality

* merge comments/_edit & comments/_form partials; change #edit-comment-form-wrapper to #comment-form-wrapper-edit

* stop attaching ajax:event to edit forms

* stop running scripts on edit forms

* add hidden_field_tag for reply_to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants