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

Add Unique IDs to Comment Forms #9062

Merged
merged 7 commits into from Jan 26, 2021
Merged

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Jan 21, 2021

Related to #9004 (Object-Oriented Refactor of Comment Editor)

See this comment for more context: #9004 (comment)


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

@noi5e noi5e requested a review from a team as a code owner January 21, 2021 23:00
@gitpod-io
Copy link

gitpod-io bot commented Jan 21, 2021

@noi5e noi5e added JavaScript outreachy feature explains that the issue is to add a new feature labels Jan 21, 2021
@codecov
Copy link

codecov bot commented Jan 21, 2021

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9062   +/-   ##
=======================================
  Coverage        ?   82.15%           
=======================================
  Files           ?      100           
  Lines           ?     5936           
  Branches        ?        0           
=======================================
  Hits            ?     4877           
  Misses          ?     1059           
  Partials        ?        0           

const textArea = 'c'+id+'text';
const preview = 'c'+id+'preview';
$E.setState(textArea, preview);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes in this file are mostly due to slightly fixing the indentation.

# used in views/comments/_form.html.erb
def get_textarea_id(location, reply_to)
case location
when :main
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 function, it was unnecessary.

<div class="comment-form-wrapper">
<div class="card card-body bg-light">
<form method="post" id="c<%= comment.id %>edit" style="display:none;" class="well" <% if comment.is_a?Answer %> action= "/answers/update/<%= comment.id %>" <% else %> action="/comment/update/<%= comment.id %>" <% end %>>
<div class="card card-body bg-light comment-form-wrapper">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I collapsed <div class="card card-body bg-light"> and <div class="comment-form-wrapper"> into one <div>. I know there's a lot of <div> spam in the views built up over the years, trying to do my part in reducing it.

I checked the CSS by both viewing locally and hunting through the stylesheets, and this doesn't seem to create any new issues.

@noi5e noi5e requested a review from a team as a code owner January 22, 2021 00:46
@@ -17,7 +17,7 @@
</div>
</div>

<div class="well" id="preview-main" style="display:none;"> </div>
<div class="well" id="comment-preview-main" style="display:none;"> </div>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know this is kind of weird on the wiki editor to have this ID be #comment-preview-main, but I have a master plan for this and will take care of it in the next few PRs.

Basically with an OOP refactor of editor.js, it will be possible to $E.initialize({default main editor form ID}).

@codeclimate
Copy link

codeclimate bot commented Jan 22, 2021

Code Climate has analyzed commit 698c8cf and detected 0 issues on this pull request.

View more on Code Climate.

@noi5e
Copy link
Contributor Author

noi5e commented Jan 22, 2021

Okay, I kept trying to add more to this PR, but I've decided to stop here for now. @jywarren This one is ready to merge!

Just to summarize the changes I made in this PR:

  • MAIN comment form:
    • <form id="comment-form> is now #comment-form-main
    • #preview-main is now #comment-preview-main
  • REPLY comment form:
    • <form id="comment-form> is now #comment-form-reply-123
    • #preview1234 is now #comment-preview-reply-1234
  • EDIT comment form:
    • <form id="c123edit"> is now #comment-form-edit-123

I'm basically just trying to get everything organized so that $E can setState on the last part of the IDs: main, or reply-1234 or edit-1234.

I still need to add unique IDs to _edit.html.erb (remember that it's distinct from _form.html.erb, which is what REPLY and MAIN uses):

  • #c1234textarea needs to be #text-input-edit-1234
  • #c1234preview needs to be #comment-preview-edit-1234

But I will do that in a separate PR!

@jywarren
Copy link
Member

This looks great. Is it worth adding some extra CSS assertions to enforce the assumption of:

I'm basically just trying to get everything organized so that $E can setState on the last part of the IDs: main, or reply-1234 or edit-1234.

I still need to add unique IDs to _edit.html.erb (remember that it's distinct from _form.html.erb, which is what REPLY and MAIN uses):

That way it's actually written somewhere and the convention is documented and protected? CSS assertions are so cheap anyways...

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

image

💪

Woohoo!

@jywarren jywarren merged commit 7b4bc4d into publiclab:main Jan 26, 2021
@noi5e noi5e deleted the unique-comment-form-IDs branch January 26, 2021 20:37
@noi5e
Copy link
Contributor Author

noi5e commented Jan 26, 2021

@jywarren Thanks! I didn't know it was possible to hide whitespace changes. And I'll look into CSS assertions.

@jywarren
Copy link
Member

yeah i thought it might be useful to know - it's a lifesaver when reviewing! Thank you!!

manchere pushed a commit to manchere/plots2 that referenced this pull request Feb 13, 2021
* delete get_textarea_id method publiclab#9004

* change #c23edit selector to #comment-form-edit-23 publiclab#9004

* assign unique IDs to comment forms publiclab#9004

* change selectors from #c1edit to #comment-form-edit-1 publiclab#9004

* change preview IDs from #preview1 to #comment-preview-1 publiclab#9004

* change main preview selector to #comment-preview-main from #preview-main publiclab#9004

* change main preview selector to #comment-preview-main from #preview-main publiclab#9004
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
* delete get_textarea_id method publiclab#9004

* change #c23edit selector to #comment-form-edit-23 publiclab#9004

* assign unique IDs to comment forms publiclab#9004

* change selectors from #c1edit to #comment-form-edit-1 publiclab#9004

* change preview IDs from #preview1 to #comment-preview-1 publiclab#9004

* change main preview selector to #comment-preview-main from #preview-main publiclab#9004

* change main preview selector to #comment-preview-main from #preview-main publiclab#9004
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* delete get_textarea_id method publiclab#9004

* change #c23edit selector to #comment-form-edit-23 publiclab#9004

* assign unique IDs to comment forms publiclab#9004

* change selectors from #c1edit to #comment-form-edit-1 publiclab#9004

* change preview IDs from #preview1 to #comment-preview-1 publiclab#9004

* change main preview selector to #comment-preview-main from #preview-main publiclab#9004

* change main preview selector to #comment-preview-main from #preview-main publiclab#9004
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* delete get_textarea_id method publiclab#9004

* change #c23edit selector to #comment-form-edit-23 publiclab#9004

* assign unique IDs to comment forms publiclab#9004

* change selectors from #c1edit to #comment-form-edit-1 publiclab#9004

* change preview IDs from #preview1 to #comment-preview-1 publiclab#9004

* change main preview selector to #comment-preview-main from #preview-main publiclab#9004

* change main preview selector to #comment-preview-main from #preview-main publiclab#9004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature explains that the issue is to add a new feature JavaScript outreachy readytomerge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants