-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add Unique HTML IDs to .dropzones, #fileinputs #8927
Conversation
Codecov Report
@@ Coverage Diff @@
## main #8927 +/- ##
=======================================
Coverage ? 81.89%
=======================================
Files ? 100
Lines ? 5948
Branches ? 0
=======================================
Hits ? 4871
Misses ? 1077
Partials ? 0 |
There was a problem hiding this 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!!! 👍
app/views/comments/_edit.html.erb
Outdated
@@ -8,8 +8,8 @@ | |||
#imagebar {width:100%;} | |||
</style> | |||
|
|||
|
|||
<%= render :partial => "editor/toolbar" %> | |||
<%# toolbar needs location & comment_id to make unique element IDs%> |
There was a problem hiding this comment.
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;" /> |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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!
app/views/comments/_form.html.erb
Outdated
|
||
<% 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 %> |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
app/helpers/application_helper.rb
Outdated
# used in views/comments/_form.html.erb | ||
def get_large_dropzone_id(location, reply_to) | ||
case location | ||
when :main |
There was a problem hiding this comment.
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
.
app/helpers/application_helper.rb
Outdated
case location | ||
when :main | ||
'-main' | ||
when :reply |
There was a problem hiding this comment.
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
.
app/helpers/application_helper.rb
Outdated
'-main' | ||
when :reply | ||
'-reply-' + reply_to.to_s | ||
when :responses |
There was a problem hiding this comment.
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
.
I just pushed the commits, so this one's ready to merge! |
Awesome would you like to take code climates suggestions or just resolve them? Thanks!!! |
Code Climate has analyzed commit 12726f4 and detected 0 issues on this pull request. View more on Code Climate. |
Just pushed the commits, it's ready (again) now! |
Hooray 🎉👏👏 |
* 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
* 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
* 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
* 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
See issues #8926 #8670 #8478
Adds unique HTML IDs to .dropzones and #fileinputs in comment forms.
.dropzone
(with no ID) wrapping#fileinput
(which is used twice in the same comment form, or multiple times per page)#dropzone-small-edit-22
#fileinput-button-edit-22
#dropzone-reply-22
for reply forms,#dropzone-main
for base comment form in notes, questions, and wikis.dropzone
(with no ID) wrapping the form's entire face, same class as A#dropzone-large-reply-20
in reply forms and#dropzone-large-main
in main forms#fileinput
here (distinct from A, but with the same ID)#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)