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

Added animation to save icon when user enters a comment text #9384

Merged
merged 8 commits into from
Jun 11, 2021

Conversation

waridrox
Copy link
Member

@waridrox waridrox commented Mar 29, 2021

Fixes #9362

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

Final working version -

Final.mp4

I've removed the console.log statements 😄.

@noi5e kindly review this. Thanks :)

@gitpod-io
Copy link

gitpod-io bot commented Mar 29, 2021

@codecov
Copy link

codecov bot commented Mar 29, 2021

Codecov Report

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

❗ Current head e58228f differs from pull request most recent head 320ff86. Consider uploading reports for the commit 320ff86 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9384   +/-   ##
=======================================
  Coverage        ?   81.35%           
=======================================
  Files           ?       98           
  Lines           ?     5928           
  Branches        ?        0           
=======================================
  Hits            ?     4823           
  Misses          ?     1105           
  Partials        ?        0           

@noi5e
Copy link
Contributor

noi5e commented Mar 30, 2021

@waridrox Thanks so much for this, will give a detailed review and feedback later today, but honestly it looks pretty good.

One thing to note is that the save & recover system test needs to be updated (that's what's failing right now).

@waridrox
Copy link
Member Author

waridrox commented Mar 31, 2021

One thing to note is that the save & recover system test needs to be updated (that's what's failing right now).

Oh!😅 Will take a look at this soon...

@noi5e
Copy link
Contributor

noi5e commented Mar 31, 2021

Oh!😅 Will take a look at this soon...

@waridrox Yeah, that's a good idea! Updating the test isn't necessarily your responsibility (I wrote it), but I still recommend taking a look.

I'm thinking the test probably needs to be updated to wait for the debouncing to occur before it refreshes the page. I think it will be a relatively easy fix.

@waridrox
Copy link
Member Author

waridrox commented Apr 4, 2021

My apologies, got a little busy lately 😅, @noi5e can you point me to the right file to implement the tests for debounce function. Further researching upon, I came across the sleep method in ruby which waits the program for a certain amount of time. Can we use this in the tests...?

@RuthNjeri
Copy link
Contributor

Hi @waridrox, from the system tests here the failing test is
Screenshot 2021-04-15 at 22 14 49

comment_test.rb

@waridrox
Copy link
Member Author

waridrox commented Apr 23, 2021

Just when I though about adding tests, I realised we missed an edge case wherein due to the similar functional elements like the toolbar and the image upload section, the current changes also reflect if a Reply to a Comment is open along with Post Comment window. Here's an example for that case and I'm working on first fixing that!

edge-case.mp4

let comment_temp_id = (document.activeElement.parentElement.parentElement.id);
let imager_bar = (document.activeElement.nextElementSibling.className);

$('#'+comment_temp_id).find('.btn-toolbar').find(".save-button").find("i").removeClass("fa fa-save").addClass("fas fa-sync fa-spin");
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

app/assets/javascripts/editor.js Show resolved Hide resolved
app/assets/javascripts/editor.js Show resolved Hide resolved
app/assets/javascripts/editor.js Show resolved Hide resolved

//adding delay and revering the styles
setTimeout(() => {
$("#comment-form-main .btn-toolbar #save-button-main").find("i").removeClass("fas fa-sync fa-spin").addClass("fa fa-save");;
Copy link

Choose a reason for hiding this comment

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

Unnecessary semicolon.

@waridrox
Copy link
Member Author

waridrox commented Apr 26, 2021

Here's the fix for the edge case: reason being that each comment has its own unique id associated so earlier code was targeting all ids instead of the specific one that the user is currently making changes on.

edge.case.fix.mp4

Now working on testing...

$E.save($E);
})
//preventing multiple clicks on the button
if(!e.detail || e.detail == 1) {
Copy link

Choose a reason for hiding this comment

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

Expected '===' and instead saw '=='.

Copy link
Member Author

@waridrox waridrox Apr 27, 2021

Choose a reason for hiding this comment

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

Isn't === supposed to check type as well 🤔. I think here == should suffice. But e.detail returns a typeof = number so I think we can use === here.

@waridrox
Copy link
Member Author

waridrox commented Apr 27, 2021

The tests for save and recover button have been updated to account for debounce function and they pass now :)
Screenshot 2021-04-27 at 6 11 41 PM

@noi5e @RuthNjeri Kindly review this. Thanks :)

@RuthNjeri
Copy link
Contributor

Hi @waridrox, what do you think about the other comments made by CodeClimate? Do you think you can address them? I see you responded to one...would you like to address the rest? We usually don't implement everything suggested by CodeClimate depending on the trade offs.

@waridrox
Copy link
Member Author

waridrox commented May 2, 2021

Hi @waridrox, what do you think about the other comments made by CodeClimate? Do you think you can address them? I see you responded to one...would you like to address the rest? We usually don't implement everything suggested by CodeClimate depending on the trade offs.

Yes, @RuthNjeri, I've looked at the comments by CodeClimate, most of them being a repetition of one another 😅. But I don't see any problem in the issues that it is suggesting to be fixed -

  • Function attachSaveListener has 32 lines of code (exceeds 25 allowed). - This function also houses comments for explanations, but CodeClimate is also counting those in the number of lines.
  • Similar blocks of code found in 2 locations(✕4). Consider refactoring. - The code blocks do start similarly but eventually do different things at their completion.

@gitpod-io
Copy link

gitpod-io bot commented May 2, 2021

@waridrox
Copy link
Member Author

waridrox commented May 11, 2021

@RuthNjeri @noi5e @jywarren pls review the changes. Thanks :)

@waridrox waridrox requested a review from RuthNjeri May 16, 2021 12:16
@waridrox waridrox closed this May 16, 2021
@waridrox waridrox reopened this May 16, 2021
@waridrox
Copy link
Member Author

Sorry the tests did not run and instead failed...

@pydevsg
Copy link
Member

pydevsg commented May 17, 2021

Refactor the code @waridrox.
This will pass the test 😅

@jywarren
Copy link
Member

If you'd like we can bypass the code climate suggestions! They are only suggestions but if you'd like to address any of them we can also wait, no rush!

@waridrox
Copy link
Member Author

waridrox commented May 19, 2021

Hi @jywarren @pydevsg, I was talking about all the tests instead of just the code climate ones😅I've tried to address them but all of them seem fine to me...

Copy link
Contributor

@RuthNjeri RuthNjeri left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @waridrox, it looks good to me, I think one more reviewer should approve this(@jywarren or @cesswairimu)...then it will be okay to merge 🚀

@waridrox waridrox requested review from a team as code owners May 23, 2021 12:15
@waridrox waridrox force-pushed the patch-animateSaveIcon branch 3 times, most recently from f1b318a to 338859f Compare May 23, 2021 20:10
@waridrox
Copy link
Member Author

waridrox commented May 23, 2021

After syncing the branch with upstream, unit tests seem to be failing...🤔

@jywarren
Copy link
Member

Aha - for some reason i also saw this on #9665 (comment) and suggested a fix there - adding a sort to the test or to the main codebase, as i believe it's an ordering issue that can happen sometimes if we don't explicitly send a sort to the database. If you're able to open a new PR then possibly this and #9665 (comment) can both be rebased over it once we resolve that. In the meantime, i'll restart the test to see if we get past it that way. Thanks!

@jywarren
Copy link
Member

Ok sorry @waridrox but now the unit tests upstream are fixed and just one more rebase should work. Many thanks for your patience!!!

@waridrox waridrox force-pushed the patch-animateSaveIcon branch from e58228f to 320ff86 Compare May 30, 2021 08:25
@codeclimate
Copy link

codeclimate bot commented May 30, 2021

Code Climate has analyzed commit 320ff86 and detected 5 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 4

View more on Code Climate.

@waridrox
Copy link
Member Author

waridrox commented Jun 2, 2021

@jywarren Done!

@jywarren
Copy link
Member

OK, merging now, and many thanks!!!

Regarding the revert button, i wonder if we should have saving add the text to an array of recent texts that have been saved. Then revert could just cycle back through that list.

@jywarren jywarren merged commit c76e485 into publiclab:main Jun 11, 2021
@jywarren
Copy link
Member

@waridrox @noi5e we could break out that idea of the array of comments saves into a new issue too! I think we'd have to be careful to flush the list... maybe only save 5 or 10 states, and/or delete much older ones or something? For example, what if someone types in something private, it saves, and they change their mind before posting it, they log out, someone else logs in, and they are able to recover the text.

@jywarren
Copy link
Member

i.e. we could make it auto-delete texts older than an hour to mitigate this risk maybe.

@jywarren
Copy link
Member

I know @waridrox is now working on other projects, though! So perhaps someone else from the @publiclab/soc team would be interested in taking this idea of fixing the comment revert button up?

reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
…ab#9384)

* Added animation to save icon when user enters a comment text

* Edge case handled

* Updated tests for save and recover buttons

* Update editorToolbar.js

* Unnecessary semicolon

* ESLint typeof operator

* let instead of var

* Matched padding of saving text with file upload text
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
…ab#9384)

* Added animation to save icon when user enters a comment text

* Edge case handled

* Updated tests for save and recover buttons

* Update editorToolbar.js

* Unnecessary semicolon

* ESLint typeof operator

* let instead of var

* Matched padding of saving text with file upload text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Animate Save Icon When User Enters Comment Text
5 participants