-
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
[Discussion] Refactor Comment Editor Using OOP #9004
Comments
I wonder, once all system tests are in place, would an actual React component be plausible here? I don't have much experience with React, do you? I'm mainly just curious how integration would work and if it would be worth it. Curious to hear your thoughts! I like what you're planning on here, thanks! |
@jywarren I do have an okay amount of React experience. I see that there is a Rails React gem... It's worth looking into in a deeper way, but I have a feeling it would require rewriting the entire codebase in React, like v3 of the entire site. I've never heard of, for example, using React for just the comments form on a website... Maybe this does happen, maybe it doesn't, but I'm only familiar with entire sites built with React. I guess I have a bias towards React being a junior developer, and it being the framework I'm most familiar with. I'd be willing to pitch in my two cents further down the line if Public Lab considered switching to a new stack! Luckily, I think the Comment Editor is small enough that we can get somewhere without using React... Like, I'm working on a PR right now that I'll link here that's doing some object-oriented refactoring of Another related issue I'm discovering in my refactoring is that a lot of the scripts used with the Comment Editor, like |
I believe it is possible to run just one component, and we've been interested in that as a proof of concept before trying to do the entire site... but really, that's out of scope unless you finish early and are really interested in it, so no worries! I hear you re: reused scripts. I think it's possible to explore copying the scripts and splitting their use cases instead of trying to retain the code re-usability, if that is slowing down your work and/or refactoring progress! |
* write setState method with default parameters #9004 * set preview when calling E.setState #9004 * set preview when calling E.setState #9004 * change E.initialize to E.setState; add comment-preview class #9004 * change E.initialize({}) to E.initialize() #9004 * change regex test to match /features/new in wrap #9004 * rewrite selector for more specificity #9004 * rewrite for cognitive complexity #9004 * desperately trying to pass codeclimate #9004 * desperately trying to pass codeclimate #9004 * desperately trying to pass codeclimate #9004 * desperately trying to pass codeclimate #9004 * oops, switched ternary operator #9004
* 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
* move E.initialize call to higher level views publiclab#9004 * change selectors for preview & textarea elements publiclab#9004 * change #edit-comment-btn to .edit-comment-btn publiclab#9004 * change selectors to match new edit form publiclab#9004 * update selectors for edit form publiclab#9004
* object-oriented refactor! publiclab#9004 * create instances of new object-oriented editor publiclab#9004 * pass codeclimate: add semicolon; comment unused methods publiclab#9004 * move editor instantiation to notes/comments partial publiclab#9004 * adding const to pass codeclimate publiclab#9004 * reformat object methods publiclab#9004 * instantiate 1 editor object each on wikis, notes, and questions publiclab#9004 * rewrite to reduce cognitive complexity publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * hopefully the last codeclimate rewrite publiclab#9004 * rewrite E.wrap's parameters to pass codeclimate publiclab#9004 * remove newlines to appease codeclimate publiclab#9004 * typo: highlighT instead of highligh publiclab#9004 * fixing typo publiclab#9004 * change const to let publiclab#9004 * assign textarea & preview to jQuery objects in constructor publiclab#9004 * change newText assignment Co-authored-by: Sagarpreet <[email protected]> * change uri check for null publiclab#9004 Co-authored-by: Sagarpreet <[email protected]> Co-authored-by: Sagarpreet <[email protected]>
* object-oriented refactor! publiclab#9004 create instances of new object-oriented editor publiclab#9004 pass codeclimate: add semicolon; comment unused methods publiclab#9004 move editor instantiation to notes/comments partial publiclab#9004 adding const to pass codeclimate publiclab#9004 reformat object methods publiclab#9004 instantiate 1 editor object each on wikis, notes, and questions publiclab#9004 rewrite to reduce cognitive complexity publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 hopefully the last codeclimate rewrite publiclab#9004 rewrite E.wrap's parameters to pass codeclimate publiclab#9004 remove newlines to appease codeclimate publiclab#9004 typo: highlighT instead of highligh publiclab#9004 fixing typo publiclab#9004 change const to let publiclab#9004 assign textarea & preview to jQuery objects in constructor publiclab#9004 * change main comment form ID to #text-input-main publiclab#9004 * change parameters for E.setState publiclab#9004 * delete get_toolbar_element_id helper publiclab#9004 * rewrite E.setState for 1 ID parameter publiclab#9004 * add unique ID to toggle preview button publiclab#9004 * rewrite constructor for 1 parameter; toggle preview button on unique ID publiclab#9004 * fix extra whitespace in edit comment form's textarea publiclab#9004 * update system tests with new selectors publiclab#9004 * toggle form preview on unique ID publiclab#9004
* merge editor refactor branches publiclab#9004 * delete refresh & isSingleFormPage methods publiclab#9004 * delete some D.selected assignments publiclab#9004 * add dropzone class to choose one input elements * E.setState on image select upload publiclab#9004 * remove D.selected from progress bar handlers publiclab#9004 * add unique IDs to image upload progress bars publiclab#9004 * updated image upload progress bar selectors publiclab#9004 * update progress bar selector publiclab#9004 * update selectors for image upload text publiclab#9004
…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 <[email protected]> Co-authored-by: Sagarpreet <[email protected]>
* merge comment editor refactor branches publiclab#9004 * add classes for small and large dropzones * disable drag&drop on image upload button * add data-form-ID attribute to large dropzone * update selectors for large dropzone
* 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
* write setState method with default parameters publiclab#9004 * set preview when calling E.setState publiclab#9004 * set preview when calling E.setState publiclab#9004 * change E.initialize to E.setState; add comment-preview class publiclab#9004 * change E.initialize({}) to E.initialize() publiclab#9004 * change regex test to match /features/new in wrap publiclab#9004 * rewrite selector for more specificity publiclab#9004 * rewrite for cognitive complexity publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * oops, switched ternary operator publiclab#9004
…b#9037) * move comment.js & dragdrop.js to higher-level views publiclab#9004 * attach eventListeners on document.load publiclab#9004 * move dragdrop.js & comment.js to notes/comments partial publiclab#9004
* remove editorHelper publiclab#9004 * deleted editorHelper & moved function to editorToolbar publiclab#9004 * moved rich-text eventListener to editorToolbar.js publiclab#9004 * rename dragdrop.js to editorToolbar.js publiclab#9004 * rename dragdrop.js to editorToolbar.js * rename dragdrop.js to editorToolbar.js
* 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
* move E.initialize call to higher level views publiclab#9004 * change selectors for preview & textarea elements publiclab#9004 * change #edit-comment-btn to .edit-comment-btn publiclab#9004 * change selectors to match new edit form publiclab#9004 * update selectors for edit form publiclab#9004
* object-oriented refactor! publiclab#9004 * create instances of new object-oriented editor publiclab#9004 * pass codeclimate: add semicolon; comment unused methods publiclab#9004 * move editor instantiation to notes/comments partial publiclab#9004 * adding const to pass codeclimate publiclab#9004 * reformat object methods publiclab#9004 * instantiate 1 editor object each on wikis, notes, and questions publiclab#9004 * rewrite to reduce cognitive complexity publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * hopefully the last codeclimate rewrite publiclab#9004 * rewrite E.wrap's parameters to pass codeclimate publiclab#9004 * remove newlines to appease codeclimate publiclab#9004 * typo: highlighT instead of highligh publiclab#9004 * fixing typo publiclab#9004 * change const to let publiclab#9004 * assign textarea & preview to jQuery objects in constructor publiclab#9004 * change newText assignment Co-authored-by: Sagarpreet <[email protected]> * change uri check for null publiclab#9004 Co-authored-by: Sagarpreet <[email protected]> Co-authored-by: Sagarpreet <[email protected]>
* object-oriented refactor! publiclab#9004 create instances of new object-oriented editor publiclab#9004 pass codeclimate: add semicolon; comment unused methods publiclab#9004 move editor instantiation to notes/comments partial publiclab#9004 adding const to pass codeclimate publiclab#9004 reformat object methods publiclab#9004 instantiate 1 editor object each on wikis, notes, and questions publiclab#9004 rewrite to reduce cognitive complexity publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 hopefully the last codeclimate rewrite publiclab#9004 rewrite E.wrap's parameters to pass codeclimate publiclab#9004 remove newlines to appease codeclimate publiclab#9004 typo: highlighT instead of highligh publiclab#9004 fixing typo publiclab#9004 change const to let publiclab#9004 assign textarea & preview to jQuery objects in constructor publiclab#9004 * change main comment form ID to #text-input-main publiclab#9004 * change parameters for E.setState publiclab#9004 * delete get_toolbar_element_id helper publiclab#9004 * rewrite E.setState for 1 ID parameter publiclab#9004 * add unique ID to toggle preview button publiclab#9004 * rewrite constructor for 1 parameter; toggle preview button on unique ID publiclab#9004 * fix extra whitespace in edit comment form's textarea publiclab#9004 * update system tests with new selectors publiclab#9004 * toggle form preview on unique ID publiclab#9004
* merge editor refactor branches publiclab#9004 * delete refresh & isSingleFormPage methods publiclab#9004 * delete some D.selected assignments publiclab#9004 * add dropzone class to choose one input elements * E.setState on image select upload publiclab#9004 * remove D.selected from progress bar handlers publiclab#9004 * add unique IDs to image upload progress bars publiclab#9004 * updated image upload progress bar selectors publiclab#9004 * update progress bar selector publiclab#9004 * update selectors for image upload text publiclab#9004
…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 <[email protected]> Co-authored-by: Sagarpreet <[email protected]>
* merge comment editor refactor branches publiclab#9004 * add classes for small and large dropzones * disable drag&drop on image upload button * add data-form-ID attribute to large dropzone * update selectors for large dropzone
* 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
* write setState method with default parameters publiclab#9004 * set preview when calling E.setState publiclab#9004 * set preview when calling E.setState publiclab#9004 * change E.initialize to E.setState; add comment-preview class publiclab#9004 * change E.initialize({}) to E.initialize() publiclab#9004 * change regex test to match /features/new in wrap publiclab#9004 * rewrite selector for more specificity publiclab#9004 * rewrite for cognitive complexity publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * oops, switched ternary operator publiclab#9004
…b#9037) * move comment.js & dragdrop.js to higher-level views publiclab#9004 * attach eventListeners on document.load publiclab#9004 * move dragdrop.js & comment.js to notes/comments partial publiclab#9004
* remove editorHelper publiclab#9004 * deleted editorHelper & moved function to editorToolbar publiclab#9004 * moved rich-text eventListener to editorToolbar.js publiclab#9004 * rename dragdrop.js to editorToolbar.js publiclab#9004 * rename dragdrop.js to editorToolbar.js * rename dragdrop.js to editorToolbar.js
* 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
* move E.initialize call to higher level views publiclab#9004 * change selectors for preview & textarea elements publiclab#9004 * change #edit-comment-btn to .edit-comment-btn publiclab#9004 * change selectors to match new edit form publiclab#9004 * update selectors for edit form publiclab#9004
* object-oriented refactor! publiclab#9004 * create instances of new object-oriented editor publiclab#9004 * pass codeclimate: add semicolon; comment unused methods publiclab#9004 * move editor instantiation to notes/comments partial publiclab#9004 * adding const to pass codeclimate publiclab#9004 * reformat object methods publiclab#9004 * instantiate 1 editor object each on wikis, notes, and questions publiclab#9004 * rewrite to reduce cognitive complexity publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * trying to pass codeclimate publiclab#9004 * hopefully the last codeclimate rewrite publiclab#9004 * rewrite E.wrap's parameters to pass codeclimate publiclab#9004 * remove newlines to appease codeclimate publiclab#9004 * typo: highlighT instead of highligh publiclab#9004 * fixing typo publiclab#9004 * change const to let publiclab#9004 * assign textarea & preview to jQuery objects in constructor publiclab#9004 * change newText assignment Co-authored-by: Sagarpreet <[email protected]> * change uri check for null publiclab#9004 Co-authored-by: Sagarpreet <[email protected]> Co-authored-by: Sagarpreet <[email protected]>
* object-oriented refactor! publiclab#9004 create instances of new object-oriented editor publiclab#9004 pass codeclimate: add semicolon; comment unused methods publiclab#9004 move editor instantiation to notes/comments partial publiclab#9004 adding const to pass codeclimate publiclab#9004 reformat object methods publiclab#9004 instantiate 1 editor object each on wikis, notes, and questions publiclab#9004 rewrite to reduce cognitive complexity publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 trying to pass codeclimate publiclab#9004 hopefully the last codeclimate rewrite publiclab#9004 rewrite E.wrap's parameters to pass codeclimate publiclab#9004 remove newlines to appease codeclimate publiclab#9004 typo: highlighT instead of highligh publiclab#9004 fixing typo publiclab#9004 change const to let publiclab#9004 assign textarea & preview to jQuery objects in constructor publiclab#9004 * change main comment form ID to #text-input-main publiclab#9004 * change parameters for E.setState publiclab#9004 * delete get_toolbar_element_id helper publiclab#9004 * rewrite E.setState for 1 ID parameter publiclab#9004 * add unique ID to toggle preview button publiclab#9004 * rewrite constructor for 1 parameter; toggle preview button on unique ID publiclab#9004 * fix extra whitespace in edit comment form's textarea publiclab#9004 * update system tests with new selectors publiclab#9004 * toggle form preview on unique ID publiclab#9004
* merge editor refactor branches publiclab#9004 * delete refresh & isSingleFormPage methods publiclab#9004 * delete some D.selected assignments publiclab#9004 * add dropzone class to choose one input elements * E.setState on image select upload publiclab#9004 * remove D.selected from progress bar handlers publiclab#9004 * add unique IDs to image upload progress bars publiclab#9004 * updated image upload progress bar selectors publiclab#9004 * update progress bar selector publiclab#9004 * update selectors for image upload text publiclab#9004
…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 <[email protected]> Co-authored-by: Sagarpreet <[email protected]>
* merge comment editor refactor branches publiclab#9004 * add classes for small and large dropzones * disable drag&drop on image upload button * add data-form-ID attribute to large dropzone * update selectors for large dropzone
* 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
I wanted to open up an issue to collect ideas/observations I've had about the comment editor's state management. I'll leave this issue open for a few weeks to collect thoughts as they come up (if that's okay). I'm hoping this will help us to conceptualize a code overhaul.
To start with, I wanted to give a bug as an example:
Video of this bug in action
✅ Expected Behavior: Rich-text changes go in the Reply Comment form.
❌ Actual Behavior: They go in the Edit Comment form.
Why This Happens
It's because we set state (for the focused comment form) here in the edit comment form partial:
plots2/app/views/comments/_edit.html.erb
Lines 46 to 52 in a3c8796
But we don't do a similar thing when we open a reply comment form:
plots2/app/views/notes/_comment.html.erb
Lines 213 to 217 in a3c8796
The Bug Fix
I currently have a PR open that fixes the above bug at #9003.
I intentionally decided not to fix the bug by putting lines to
set state
when opening a reply comment form.After all, just because a user opens up a comment form, doesn't mean that they necessarily want the focus to be there.
I thought a better fix would be to
set state
when the rich-text button was clicked. That seems to signal stronger user intention.State Management Idea
So the idea is to start thinking about which user actions should set state, and which should not.
✅ Set State
❌ Don't Set State
The Goal
Just to summarize: some sort of object-oriented, React-like refactoring where as much of this code can be inside a single script, creating modular comment form objects, where the state can be clearly transparent at each step of the way. 🎈
(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)
The text was updated successfully, but these errors were encountered: