-
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 JS Function add_tag() and create add_comment() for Javascript API #6422
Conversation
@cesswairimu Can you (or any of the mentors!) check my code to make sure I'm doing this correctly? Thank you!! |
Sure, not sure why travis is failing....taking a look |
@jywarren Can you take a look at my code and let me know if this is what you intended? I wasn't sure if you wanted to reference the form at all in the Javascript. |
Wow, it looks like this may need some rebasing and cleaning up! @nstjean this can be a bit rough, but please save a local copy of your branch with Would you like to try rebasing again over the latest master branch? I can also help a bit with this! There's some guidance here, however! https://publiclab.org/wiki/contributing-to-public-lab-software#Rewinding+the+master+branch |
Thanks for sticking with this one! It's a really awesome one! Just ping me if you get super stuck! |
Yes I'll try rebasing using rewinding the master branch! |
8ad2ca3
to
0b1e514
Compare
@jywarren I reset the HEAD, pulled from upstream (publiclab), switched to my branch, rebased. But now when trying to run tests on my local everything is failing, even in Master. Do I have to do something else? |
When I try to run my test for my javascript function I get this error, which points to a Chrome version error. But I haven't changed anything other than pulling the new version of Master.
|
4dfd7a8
to
070df16
Compare
app/assets/javascripts/ajax.js
Outdated
@@ -0,0 +1,9 @@ | |||
function sendFormSubmissionAjax(dataObj, selector) { |
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 looking good! Perhaps this file needs a more descriptive name, however; but is it a generic utility? If so, maybe can add a sentence or two on how to use it?
Thanks!
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.
Yes, I should do that!
This looks good! Not sure where this error is coming from though:
That's for this test: Line 529 in 8c2713f
... i guess it seems unrelated? I'll try restarting the unit tests to see what happens.. Thanks for the epic rebase!!!! |
@@ -0,0 +1,27 @@ | |||
require 'test_helper' |
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.
Wow, really awesome tests!!!!
page.evaluate_script("addComment('fantastic four')") | ||
|
||
# check that the tag showed up on the page | ||
assert_selector('#comments-list .comment-body p', text: 'fantastic four') |
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.
🎉
// Allows data to be submitted from anywhere on the page using Javascript without using the form itself | ||
function sendFormSubmissionAjax(dataObj, selector) { | ||
$.ajax({ | ||
url: $(selector).attr('action'), // grab the URL from the 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.
Could we offer a parameter like url
which defaults back to this value? That way it could be done without a form!
@jywarren I've been thinking about this. Will it get confusing if sometimes the function is passed a URL and sometimes it is passed the ID of the form? It only needs one or the other. Maybe it should be two different functions? Say function2 takes in a URL as a parameter and submits the form. Then function2 takes in a selector, gets the URL from the form, and then calls function1? |
Could we... Refactor the form so it submits through ajax only? I am not
that worries about the ambiguity but I would be fine consolidating
everything into a single remote call a dropping the direct use of the html
form if it's bothering you! Thanks!
…On Tue, Nov 26, 2019, 3:31 PM Natalie St Jean ***@***.***> wrote:
@jywarren <https://github.com/jywarren> I've been thinking about this.
Will it get confusing if sometimes the function is passed a URL and
sometimes it is passed the ID of the form? It only needs one or the other.
Maybe it should be two different functions? Say function2 takes in a URL as
a parameter and submits the form. Then function2 takes in a selector, gets
the URL from the form, and then calls function1?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6422?email_source=notifications&email_token=AAAF6J5NGAI7YGZC2CI4TJLQVWBPTA5CNFSM4I6U7RQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFHK65A#issuecomment-558804852>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF6J4YCOYPN6BJHAP6P7DQVWBPTANCNFSM4I6U7RQA>
.
|
Okay! :) |
67c3b0f
to
08962f6
Compare
Ok I allowed either a selector or a url to get passed in and it decides what to do from there. :) I also added a test case for a URL being used in both addComment and addTag. Tests work on local. |
app/assets/javascripts/comment.js
Outdated
@@ -51,3 +51,10 @@ function insertTitleSuggestionTemplate() { | |||
var newText = currentText+template; | |||
element.val(newText); | |||
} | |||
|
|||
// JS API for submitting comments | |||
function addComment(comment, submitTo) { |
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.
Great, and this works appropriately for nested comments (responding to other comments) as well as top-level comments? Just checking!
|
||
end | ||
|
||
test 'adding a tag via javascript with url only' do |
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.
Love this. Just one more question - does adding tags to your profile also still work? I think that might've become broken at some point because we (unfortunately) share code between node tags and user tags, but just curious if this touches that at all? Thanks!
Let me check on those possibilities! |
Thanks. What's really nice about your code is that we will be moving away from more brittle implementations like the current one, and backing it up with tests, so the hope is to have fewer "gotchas" like this in the future. Thanks a lot!!! |
For what it's worth, i just tried adding a profile tag and got some kind of error i think... it submitted via XHR (ajax) to: https://publiclab.org/profile/warren?remote=true&name=providence also which I think isn't right! |
So, what we can do is merge this, pending the comment-responses clarification above, and then in a new PR (if you're willing!) try to fix the profile tagging -- preferably by extending the methods you've written, to have a more rational system for handling profile tagging, too! The nice thing is that we are trying to add profile tags at different places around the site, so having a general purpose JS method to do this will be really great. |
Ok! I added the ability to add a parent comment ID number to the function call so it will nest it appropriately... and added a test to check. I can check on the profile tag implementation in another PR! |
It's throwing an error on my test test_adding_a_tag_via_javascript_with_url_only - but it works when I run it on local. I'll try to figure out what's going on with it. |
It appears I have fixed it! Should be all set! |
Super! Now go take a break! 😁🎉🙌🏽 You'll be able to test it out at stable.publiclab.org soon once it builds! |
Thanks! 🎉 Enjoy your Thanksgiving break! |
…t API (publiclab#6422) * change addTag to AJAX * addTag ajax now works * add system test for addTag js function * fix codeclimate error * add js function AddComment and system test for function * add parentheses to logic statement * add JS function sendFormSubmissionAjax to reduce duplicate code * rename ajax.js to submit_form_ajax.js * remove parentheses in Node.find_by_tag_and_author * allow sendFormSubmissionAjax to take in a selector or a url * allow js addComment and addTest to use URL and add test case for both * fix codeclimate error * add to JS addComment ability to reply to parent comment - and add test for it * attempt to fix tag_test travis error
Fixes #6411 (<=== Add issue number here)
Creating a Pull Request early to get feedback! I'm not sure if I'm doing this right.
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
rake test
@publiclab/reviewers
for help, in a comment belowIf tests do fail, click on the red
X
to learn why by reading the logs.Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software
Thanks!