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 HTML IDs to .dropzones, #fileinputs #8927

Merged
merged 5 commits into from Jan 6, 2021

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Jan 3, 2021

See issues #8926 #8670 #8478

Adds unique HTML IDs to .dropzones and #fileinputs in comment forms.

Edit Comment

  • A: currently: .dropzone (with no ID) wrapping #fileinput (which is used twice in the same comment form, or multiple times per page)
    • after merging: #dropzone-small-edit-22
    • after merging: #fileinput-button-edit-22
    • after merging: #dropzone-reply-22 for reply forms, #dropzone-main for base comment form in notes, questions, and wikis
  • B: currently: .dropzone (with no ID) wrapping the form's entire face, same class as A
    • after merging: #dropzone-large-reply-20 in reply forms and #dropzone-large-main in main forms
  • C: currently: second #fileinput here (distinct from A, but with the same ID)
    • this is now #fileinput-choose-one-reply-1234 or #fileinput-choose-one-main

As usual, had to rewrite some of the old system tests that relied on the old classes and IDs.

There's probably more tests to rewrite before this is ready-to-merge, thought it would be faster/easier to see in CI rather than run tests locally.


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

@noi5e noi5e added bug the issue is regarding one of our programs which faces problems when a certain task is executed testing issues are usually for adding unit tests, integration tests or any other tests for a feature outreachy labels Jan 3, 2021
@noi5e noi5e requested review from a team as code owners January 3, 2021 08:53
@gitpod-io
Copy link

gitpod-io bot commented Jan 3, 2021

@codecov
Copy link

codecov bot commented Jan 3, 2021

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8927   +/-   ##
=======================================
  Coverage        ?   81.89%           
=======================================
  Files           ?      100           
  Lines           ?     5948           
  Branches        ?        0           
=======================================
  Hits            ?     4871           
  Misses          ?     1077           
  Partials        ?        0           

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.

This looks amazing @noi5e -- i think it's pretty much good to merge unless you want to do more; my questions below are clarifications and "just checking" so i defer to you on a final call on any of them. If it's ready to merge just note that in a comment and we can do it!

Fantastic work here!!! 👍

@@ -8,8 +8,8 @@
#imagebar {width:100%;}
</style>


<%= render :partial => "editor/toolbar" %>
<%# toolbar needs location & comment_id to make unique element IDs%>
Copy link
Member

Choose a reason for hiding this comment

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

here you could use an HTML comment perhaps? <!-- comment --> just to simplify a little?

<label for="fileinput">
<input id="fileinput" type="file" name="image[photo]" style="display:none;" />
<label for="fileinput-choose-one<%= dropzone_large_id %>">
<input id="fileinput-choose-one<%= dropzone_large_id %>" type="file" name="image[photo]" style="display:none;" />
Copy link
Member

Choose a reason for hiding this comment

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

Will this change styling at all? Noting that sometimes adding unique classnames instead of ids can be better since elements are allowed to have more than one class but only one ID. I tend to use classes instead of IDs for that reason, but it's just a convention or habit, so no big deal here, just curious!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's a really good point about styling. I did a simple search in VSCode for #fileinput and input#fileinput but it didn't come up with anything in /assets/stylesheets, so I think this is good. It looks as normal when I load it up in development too.

That's also a good point about classes vs. IDs. Since my ultimate goal is to be able to use e.target to set $D.selected upon file upload, I thought an ID made the most sense here... Good reminder though that I can use classes in other situations.

I was aware of the one ID per page rule. dropzone_large_id includes the comment ID, so it's going to resolve to a unique ID every time this form is rendered (#fileinput-reply-large-22 or something like that)... Which means that there shouldn't be any conflicting IDs here, at least throughout comments-list!

@@ -166,7 +166,16 @@
<div id="comment-<%= comment.cid %>-reply-section">
<% if current_user %>
<div class="inline" id="question-comment-form">
<%= render :partial => "comments/form", :locals => { title: "Reply to this comment", reply_to: comment.cid, comment: false, placeholder: "Help the author refine their post, or point them at other helpful information on the site. Mention users by @username to notify them of this thread by email", url1: '/conduct', author: current_user.title, is_new_contributor:current_user.is_new_contributor? } %>
<%= render :partial => "comments/form", :locals => {
Copy link
Member

Choose a reason for hiding this comment

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

so much more readable, thank you!


<% if local_assigns[:reply_to].present? %>
<%= hidden_field_tag :reply_to, local_assigns[:reply_to] %>
<% end %>

<div class="form-group dropzone">

<%# most comment forms have two dropzones: 1) small button, 2) large form that covers textarea %>
Copy link
Member

Choose a reason for hiding this comment

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

There's a case possibly to be made that logic doesn't belong in a template, but i see why this may be an exception. But just to explore the possibility, would it be possible to wrap this logic in a function and do it in a single line in the template, with the logic tucked into the application_helper.rb (helpers is where template-specific logic often goes, by convention)?

But, i'm not feeling strongly either way, there are pros and cons - it might be more readable in pure Ruby in the helper, but it's also more work to go and find it...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! This is great feedback, and helps me learn more about Rails conventions (which I'm going to be learning for a while). I went ahead and put the logic in application_helper.rb, just for the sake of developing good habits.

# used in views/comments/_form.html.erb
def get_large_dropzone_id(location, reply_to)
case location
when :main
Copy link

Choose a reason for hiding this comment

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

Indent when as deep as end.

case location
when :main
'-main'
when :reply
Copy link

Choose a reason for hiding this comment

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

Indent when as deep as end.

'-main'
when :reply
'-reply-' + reply_to.to_s
when :responses
Copy link

Choose a reason for hiding this comment

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

Indent when as deep as end.

@noi5e
Copy link
Contributor Author

noi5e commented Jan 5, 2021

I just pushed the commits, so this one's ready to merge!

@jywarren
Copy link
Member

jywarren commented Jan 5, 2021

Awesome would you like to take code climates suggestions or just resolve them? Thanks!!!

@codeclimate
Copy link

codeclimate bot commented Jan 5, 2021

Code Climate has analyzed commit 12726f4 and detected 0 issues on this pull request.

View more on Code Climate.

@noi5e
Copy link
Contributor Author

noi5e commented Jan 6, 2021

Just pushed the commits, it's ready (again) now!

@jywarren jywarren merged commit 0f770f2 into publiclab:main Jan 6, 2021
@jywarren
Copy link
Member

jywarren commented Jan 6, 2021

Hooray 🎉👏👏

@noi5e noi5e deleted the feature/add-unique-ids-to-dropzones branch January 6, 2021 03:41
@noi5e noi5e changed the title Feature: Add Unique HTML IDs to .dropzones, #fileinputs Add Unique HTML IDs to .dropzones, #fileinputs Jan 23, 2021
manchere pushed a commit to manchere/plots2 that referenced this pull request Feb 13, 2021
* generate unique HTML IDs for image upload .dropzones & inputs

* update system tests referring to #fileinput

* move get_dropzone_id logic to application_helper.rb publiclab#8926

* change comments to HTML comments

* fix indents to pass linter
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
* generate unique HTML IDs for image upload .dropzones & inputs

* update system tests referring to #fileinput

* move get_dropzone_id logic to application_helper.rb publiclab#8926

* change comments to HTML comments

* fix indents to pass linter
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* generate unique HTML IDs for image upload .dropzones & inputs

* update system tests referring to #fileinput

* move get_dropzone_id logic to application_helper.rb publiclab#8926

* change comments to HTML comments

* fix indents to pass linter
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* generate unique HTML IDs for image upload .dropzones & inputs

* update system tests referring to #fileinput

* move get_dropzone_id logic to application_helper.rb publiclab#8926

* change comments to HTML comments

* fix indents to pass linter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed outreachy testing issues are usually for adding unit tests, integration tests or any other tests for a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants