-
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
Fix CLICK-to-Upload Image Cross-Wiring Issues #8987
Fix CLICK-to-Upload Image Cross-Wiring Issues #8987
Conversation
Code Climate has analyzed commit ca17ce3 and detected 0 issues on this pull request. View more on Code Climate. |
@@ -33,25 +33,27 @@ jQuery(function() { | |||
}); | |||
$('.dropzone').on('drop',function(e) { | |||
// this 'drop' listener is also reused for pages with just one form, ie. /wiki/new | |||
$D.selected = $(e.target).closest('div.comment-form-wrapper').eq(0); | |||
const closestCommentFormWrapper = e.target.closest('div.comment-form-wrapper'); // this returns null if there is no match | |||
e.preventDefault(); | |||
let params = {}; |
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.
I rewrote this part for greater readability, using JavaScript's closest
(as opposed to jQuery's method with the same name).
JavaScript's closest
returns null
, whereas jQuery's returns an object. I thought this would be more intuitive.
Codecov Report
@@ Coverage Diff @@
## main #8987 +/- ##
=======================================
Coverage ? 82.03%
=======================================
Files ? 100
Lines ? 5956
Branches ? 0
=======================================
Hits ? 4886
Misses ? 1070
Partials ? 0 |
// for click-upload-button scenarios, it's important to set $D.selected here, because the 'drop' listener above doesn't run in those: | ||
$D.selected = $(e.target).closest('div.comment-form-wrapper'); | ||
// the above line is redundant in drag & drop, because it's assigned in 'drop' listener too. | ||
// on /wiki/new & /wiki/edit, $D.selected will = undefined from this assignment |
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 is a major change: assign $D.selected
in the start
upload function.
As a reminder, this function runs on both click
and drop
image upload events. It's important to assign $D.selected
here for click
events, because the drop
listener doesn't run for those.
I left a comment in the code about this, but I'm thinking it would be good down the road to not have to assign $D.selected
twice in a row for drop
events. Not sure how to do that yet.
args['textarea'] = args['textarea'] || 'text-input' | ||
$E.textarea = $('#'+args['textarea']) | ||
$E.title = $('#title') | ||
$E.textarea.bind('input propertychange',$E.save) | ||
// preview | ||
args['preview'] = args['preview'] || 'preview' |
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.
No additions here, just rearranged stuff for greater readability. Sometime soon, I'd like to rewrite this part to use JavaScript ES6's default parameters: initialize(textarea = 'text-input')
$E.textarea = ($D.selected).find('textarea').eq(0); | ||
$E.textarea.bind('input propertychange',$E.save); | ||
// preview | ||
$E.preview = ($D.selected).find('#preview').eq(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.
I didn't think these lines needed to be inside of a conditional checking for $D.selected
(it made it little less readable). I moved the conditional into $E.wrap
// we don't need to refresh $E's values if we're on a page with a single comment form, ie. /wiki/new or /wiki/edit | ||
if (window.location.pathname !== "/wiki/new" && !isWikiCommentPage && $D.selected) { | ||
this.refresh(); | ||
} | ||
var len = $E.textarea.val().length; |
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 is a pretty big change too. The (window.location + '').includes('wiki')
part was originally done in #5650 to fix image upload in /wiki/new
and /wiki/{wiki name}/edit
...
Unfortunately this had the side effect of running refresh
on wiki comments pages (which include('wiki')
in the window.location
). I finally figured out this doesn't need to happen, because the wiki#show
view just loads comments through note#comments
. This used to make writing system tests more difficult because things ran differently for wiki comments.
The last note is that I'm thinking that this.refresh();
may not need to be called at all. We could remove it entirely if we assign $D.selected
in all the right places, and if $E.textarea
remains constant on /wiki/new
and /wiki/edit
. But that's for another PR.
visit get_path(page_type, nodes(node_name).path) | ||
# Create a comment | ||
main_comment_form = page.find('h4', text: /Post comment|Post Comment/).find(:xpath, '..') # title text on wikis is 'Post comment' | ||
# fill out the comment form |
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.
I'm trying to prune the system tests bit-by-bit. Every time we post a comment manually where we don't need to do so is extra runtime. Here node.add_comment
can save some time.
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.
Looks great! Ready to merge? Thanks!!!
@jywarren Yep, ready to merge! |
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.
Fantastic !!
🎉🎉🎉 |
* add new image upload system tests * rename comment fixtures * assign D.selected in start; rewrite drop assignment publiclab#8926 * specify E.refresh conditional call in E.wrap publiclab#8926
* add new image upload system tests * rename comment fixtures * assign D.selected in start; rewrite drop assignment publiclab#8926 * specify E.refresh conditional call in E.wrap publiclab#8926
* add new image upload system tests * rename comment fixtures * assign D.selected in start; rewrite drop assignment publiclab#8926 * specify E.refresh conditional call in E.wrap publiclab#8926
* add new image upload system tests * rename comment fixtures * assign D.selected in start; rewrite drop assignment publiclab#8926 * specify E.refresh conditional call in E.wrap publiclab#8926
Fixes #8926
I think the plan I described in the issue above is actually working!
e.target
is now accurate in thestart
fileupload
functions. which means we can use it to assign$D.selected
. That means that every time a user successfully uploads a file by clicking on the upload button, there's a much higher likelihood (if not 100%) that it's going to go into the appropriate box.Summary:
dragdrop.js
'sdrop
eventListener$D.selected
toe.target
indragdrop.js
'sstart
fileupload
functioneditor.js
'swrap
andrefresh
methods(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)