-
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
Refactor Editor Constructor and Methods, Write Editor Getters #9110
Refactor Editor Constructor and Methods, Write Editor Getters #9110
Conversation
Codecov Report
@@ Coverage Diff @@
## main #9110 +/- ##
=======================================
Coverage ? 50.04%
=======================================
Files ? 100
Lines ? 6112
Branches ? 0
=======================================
Hits ? 3059
Misses ? 3053
Partials ? 0 |
$E.title = $('#' + title + 'title'); // not sure why this exists? seems like $E.title is always #title | ||
$E.textarea = $('#' + textarea); | ||
} | ||
setState(commentFormID) { |
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.
Removing the default parameter (commentFormID = "main"
) here. I think it makes sense so that errors will be easier to catch.
} | ||
setState(commentFormID) { | ||
this.commentFormID = commentFormID; | ||
this.textarea = $("#text-input-" + commentFormID); | ||
$E.textarea.bind('input propertychange', $E.save); |
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 changed most instances of $E.method
to this.method
except for this one here. I toyed around with this, but it opens up a can of worms and is out of scope of this PR. Will go back to this when I refactor save and recover functions.
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.
Just to explain this a little further, it's because when $E.textarea
is changed to this.textarea
it brings up JavaScript this
weirdness. The eventListener for input propertychange
(which I'm not sure is a valid event type? I tried Googling it) gets attached to the wrong this
.
get textAreaElement() { | ||
const textAreaID = "#text-input-" + this.commentFormID; | ||
return $(textAreaID); | ||
} |
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.
New getter functions!
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.
oohhhhh!
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.
Hmm, are these transpiled out in the asset pipeline? Any worries about internet explorer? I guess not these days!
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
I mean, i guess it's still 5% of usage: https://www.netmarketshare.com/browser-market-share.aspx?qprid=2&qpcustomd=0
what do you think?
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 huh... That's a good point. I hadn't checked this one out in MDN.
I think they can be rewritten as regular methods! That won't be too hard. Can do it in another PR although... Do our users really use IE to access the website? Better safe than sorry I guess.
Tests passing, this one's ready to merge... After these prerequisites (in order): |
Hey @noi5e , I think you should had kept base branch for PR-2 as PR-1 and for PR-3 as PR-2, so that:
No worries for now, we can follow this approach next time 😄 |
Thanks Sagarpreet for reading through all these PRs! I know it's complicated. Thanks also for showing me how to change the target merge branch... I wasn't able to do it for these PRs since all the branches are in my forked repository at Thanks again, I know it's hard to read, but I think it will be easier once the earlier PRs are merged and the Files Updated changes. Again, here's the suggested order of merge in my planning issue: #9069 |
These could be timing related, i'll see if they persist after a restart:
|
I caught the error that was causing the test failures, it was because I was undoing the merge conflicts manually. GitHub thought a line from
Hmm, that's weird! That test definitely shouldn't have been running in this PR. That's the new toggle preview test I wrote in #9123, which hasn't been merged yet! I guess it was running at the same time in that PR, so the CI must have gotten confused. |
@jywarren Phew, okay that did the trick! Ready to merge again! |
let previewIDPrefix = "#comment-preview-"; | ||
if (this.elementIDPrefixes.hasOwnProperty("preview")) { | ||
// eg. on /wiki/new & /wiki/edit, the preview element is called #preview-main | ||
previewIDPrefix = "#" + this.elementIDPrefixes["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.
This is one of the main changes in this PR. Honestly, I have mixed feelings about it since it's a little weird, especially in the constructor.
But I do think it's an okay workaround. I made this because there was some tension in having editor.js
operative on both 1) multi-comment pages and 2) /wiki/new
and /wiki/edit
.
I wanted preview elements to be named #comment-preview-reply-123
(they used to just be called #preview
), for greater transparency. But that clashes with the wiki editor, where there are no comments involved.
So, this is my workaround. It's a little weird, but thanks to OOP, it can be scaled back or revised much easier.
Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com>
Code Climate has analyzed commit f3dae9f and detected 0 issues on this pull request. View more on Code Climate. |
Merging 🎉 🎉 🎉 |
* merge branches #9104 #9107 #9108 #9110 #9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test * add text-input class, data-form-id attribute to textarea #9004 #9131 * add data-form-id to save & recover buttons #9004 #9131 * E.setState when clicking save, recover, & .text-input #9004 #9131 * refactor save & recover #9004 #9131 * add icon to recover button #9004 #9131 * restore edit button tooltip #9004 #9131 * save with window.location.pathname, not href #9004 #9131 * new system test for save & recover #9004 #9131 * update test selector #9004 #9131
…lab#9110) * merge editor refactor branches publiclab#9004 * remove dropzone class publiclab#9004 * add new constructor param; write getter methods; change E.method to this.method publiclab#9004 * call new E.textAreaValue getter publiclab#9004 * call new E.constructor; change imagebar IDs publiclab#9004 * change preview ID selector publiclab#9004 * delete typo from merge conflict publiclab#9004 * apply suggestions from code review Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com> Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com>
* merge branches publiclab#9104 publiclab#9107 publiclab#9108 publiclab#9110 publiclab#9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test
* merge branches publiclab#9104 publiclab#9107 publiclab#9108 publiclab#9110 publiclab#9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test * add text-input class, data-form-id attribute to textarea publiclab#9004 publiclab#9131 * add data-form-id to save & recover buttons publiclab#9004 publiclab#9131 * E.setState when clicking save, recover, & .text-input publiclab#9004 publiclab#9131 * refactor save & recover publiclab#9004 publiclab#9131 * add icon to recover button publiclab#9004 publiclab#9131 * restore edit button tooltip publiclab#9004 publiclab#9131 * save with window.location.pathname, not href publiclab#9004 publiclab#9131 * new system test for save & recover publiclab#9004 publiclab#9131 * update test selector publiclab#9004 publiclab#9131
…lab#9110) * merge editor refactor branches publiclab#9004 * remove dropzone class publiclab#9004 * add new constructor param; write getter methods; change E.method to this.method publiclab#9004 * call new E.textAreaValue getter publiclab#9004 * call new E.constructor; change imagebar IDs publiclab#9004 * change preview ID selector publiclab#9004 * delete typo from merge conflict publiclab#9004 * apply suggestions from code review Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com> Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com>
* merge branches publiclab#9104 publiclab#9107 publiclab#9108 publiclab#9110 publiclab#9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test
* merge branches publiclab#9104 publiclab#9107 publiclab#9108 publiclab#9110 publiclab#9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test * add text-input class, data-form-id attribute to textarea publiclab#9004 publiclab#9131 * add data-form-id to save & recover buttons publiclab#9004 publiclab#9131 * E.setState when clicking save, recover, & .text-input publiclab#9004 publiclab#9131 * refactor save & recover publiclab#9004 publiclab#9131 * add icon to recover button publiclab#9004 publiclab#9131 * restore edit button tooltip publiclab#9004 publiclab#9131 * save with window.location.pathname, not href publiclab#9004 publiclab#9131 * new system test for save & recover publiclab#9004 publiclab#9131 * update test selector publiclab#9004 publiclab#9131
…lab#9110) * merge editor refactor branches publiclab#9004 * remove dropzone class publiclab#9004 * add new constructor param; write getter methods; change E.method to this.method publiclab#9004 * call new E.textAreaValue getter publiclab#9004 * call new E.constructor; change imagebar IDs publiclab#9004 * change preview ID selector publiclab#9004 * delete typo from merge conflict publiclab#9004 * apply suggestions from code review Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com> Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com>
* merge branches publiclab#9104 publiclab#9107 publiclab#9108 publiclab#9110 publiclab#9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test
* merge branches publiclab#9104 publiclab#9107 publiclab#9108 publiclab#9110 publiclab#9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test * add text-input class, data-form-id attribute to textarea publiclab#9004 publiclab#9131 * add data-form-id to save & recover buttons publiclab#9004 publiclab#9131 * E.setState when clicking save, recover, & .text-input publiclab#9004 publiclab#9131 * refactor save & recover publiclab#9004 publiclab#9131 * add icon to recover button publiclab#9004 publiclab#9131 * restore edit button tooltip publiclab#9004 publiclab#9131 * save with window.location.pathname, not href publiclab#9004 publiclab#9131 * new system test for save & recover publiclab#9004 publiclab#9131 * update test selector publiclab#9004 publiclab#9131
…lab#9110) * merge editor refactor branches publiclab#9004 * remove dropzone class publiclab#9004 * add new constructor param; write getter methods; change E.method to this.method publiclab#9004 * call new E.textAreaValue getter publiclab#9004 * call new E.constructor; change imagebar IDs publiclab#9004 * change preview ID selector publiclab#9004 * delete typo from merge conflict publiclab#9004 * apply suggestions from code review Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com> Co-authored-by: Sagarpreet <53554917+Sagarpreet@users.noreply.github.com>
* merge branches publiclab#9104 publiclab#9107 publiclab#9108 publiclab#9110 publiclab#9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test
* merge branches publiclab#9104 publiclab#9107 publiclab#9108 publiclab#9110 publiclab#9118 * change #dropzone-large ID to #comment-form-body * add comprehensive preview button test * add text-input class, data-form-id attribute to textarea publiclab#9004 publiclab#9131 * add data-form-id to save & recover buttons publiclab#9004 publiclab#9131 * E.setState when clicking save, recover, & .text-input publiclab#9004 publiclab#9131 * refactor save & recover publiclab#9004 publiclab#9131 * add icon to recover button publiclab#9004 publiclab#9131 * restore edit button tooltip publiclab#9004 publiclab#9131 * save with window.location.pathname, not href publiclab#9004 publiclab#9131 * new system test for save & recover publiclab#9004 publiclab#9131 * update test selector publiclab#9004 publiclab#9131
Related to #9004, OOP refactor of Comment/Legacy Editor.
#comment-preview-main
#preview-main
, not also#comment-preview-main
$E = new Editor("main", { "preview": "preview" })
to customize element IDs.editor.js
, I wrote getter methods to retrieve$E.textarea
,$E.textAreaValue
, and$E.preview
.editor.js
, changed most instances of$E.method()
tothis.method()
.(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)