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

Fix Rich-Text & Image Upload in FRESHLY Posted Comments #9162

Merged
merged 6 commits into from
Feb 9, 2021

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Feb 8, 2021

Fixes #9072


(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 JavaScript outreachy labels Feb 8, 2021
@noi5e noi5e requested review from a team as code owners February 8, 2021 21:36
@gitpod-io
Copy link

gitpod-io bot commented Feb 8, 2021

@@ -132,9 +132,6 @@ class Editor {
this.textAreaElement.val(this.textAreaValue+'\n\n'+this.templates[template])
}
}
generate_preview(id,text) {
$('#' + id)[0].innerHTML = marked(text)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated changes in this file (sorry)! Deleted this unused code.

// used to create fileupload functionality for:
// 1. existing comments at document.load
// 2. dynamically inserted (freshly posted) comments, see /app/views/comments/create.js.erb
function getFileUploadOptions(dropZone, isSmallDropzone = false) {
Copy link

Choose a reason for hiding this comment

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

Function getFileUploadOptions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.

// used to create fileupload functionality for:
// 1. existing comments at document.load
// 2. dynamically inserted (freshly posted) comments, see /app/views/comments/create.js.erb
function getFileUploadOptions(dropZone, isSmallDropzone = false) {
Copy link

Choose a reason for hiding this comment

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

Function getFileUploadOptions has 48 lines of code (exceeds 25 allowed). Consider refactoring.

@codeclimate
Copy link

codeclimate bot commented Feb 8, 2021

Code Climate has analyzed commit b52e480 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2

View more on Code Climate.

replyFormBody.fileupload(replyFormOptions);
editFormBody.fileupload(editFormOptions);
replyButton.fileupload(replyButtonOptions);
editButton.fileupload(editButtonOptions);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think create.js.erb runs when comments/create is called from the controller.

I had a choice between putting this code here, or in /app/assets/javascripts/comment.js. The second choice (where ajax:success is triggered on adding a comment) seemed more intuitive, but also more complicated to rewrite. Putting this here for now.

Copy link
Member

Choose a reason for hiding this comment

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

That note on when/where it is run may be good to include in the file itself in a header comment, how does that sound? Just thinking to help future devs. Thanks!!!

<i class="fa fa-upload"></i>
<a><%= translation('comments._form.upload_image') %></a>
</span>
</label>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an unrelated change (sorry again), for some reason the imagebar text ("Drag and drop an image, or choose one to upload") wasn't appearing in the legacy editor pages. It was just a blank grey spot.

@codecov
Copy link

codecov bot commented Feb 8, 2021

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9162   +/-   ##
=======================================
  Coverage        ?   81.94%           
=======================================
  Files           ?      100           
  Lines           ?     5939           
  Branches        ?        0           
=======================================
  Hits            ?     4867           
  Misses          ?     1072           
  Partials        ?        0           

@noi5e
Copy link
Contributor Author

noi5e commented Feb 8, 2021

@jywarren Do you have the ability to override codeclimate? I can't do it. Would prefer not to take the suggestions in this case.

Otherwise this is ready to merge!

@jywarren
Copy link
Member

jywarren commented Feb 8, 2021 via email

});
const isSmallDropzone = $(this).hasClass("dropzone-small");
const fileUploadOptions = getFileUploadOptions($(this), isSmallDropzone);
$(this).fileupload(fileUploadOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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.

Thanks @noi5e and reviewers!!!!

@jywarren jywarren merged commit 17fa875 into publiclab:main Feb 9, 2021
@noi5e noi5e deleted the dynamic-form-eventHandlers branch February 9, 2021 18:06
manchere pushed a commit to manchere/plots2 that referenced this pull request Feb 13, 2021
* delete unused code; add semicolon publiclab#9072

* attach eventHandlers to #legacy-editor-container publiclab#9072

* add image upload functionality to new comments publiclab#9072

* add imagebar caption publiclab#9072

* add #legacy-editor-container class to attach eventHandlers publiclab#9072

* add system test for rich-text & image upload on fresh comments publiclab#9072
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
* delete unused code; add semicolon publiclab#9072

* attach eventHandlers to #legacy-editor-container publiclab#9072

* add image upload functionality to new comments publiclab#9072

* add imagebar caption publiclab#9072

* add #legacy-editor-container class to attach eventHandlers publiclab#9072

* add system test for rich-text & image upload on fresh comments publiclab#9072
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* delete unused code; add semicolon publiclab#9072

* attach eventHandlers to #legacy-editor-container publiclab#9072

* add image upload functionality to new comments publiclab#9072

* add imagebar caption publiclab#9072

* add #legacy-editor-container class to attach eventHandlers publiclab#9072

* add system test for rich-text & image upload on fresh comments publiclab#9072
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* delete unused code; add semicolon publiclab#9072

* attach eventHandlers to #legacy-editor-container publiclab#9072

* add image upload functionality to new comments publiclab#9072

* add imagebar caption publiclab#9072

* add #legacy-editor-container class to attach eventHandlers publiclab#9072

* add system test for rich-text & image upload on fresh comments publiclab#9072
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 JavaScript outreachy readytomerge 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.

[Bug] Attach Rich-Text & Image Upload Events on FRESH, Newly Created Comment Forms
3 participants