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

Roberto fix assigning duplicate badges #666

Merged
merged 4 commits into from
Mar 16, 2024

Conversation

robertoooc
Copy link
Contributor

@robertoooc robertoooc commented Dec 23, 2023

Description

Whenever trying to manually assign badges to a user and duplicate badges are involved there aren't any clear updates being made. There was no logic to handle duplicate badges which would not allow badges to be updated anymore.

Related PRS (if any):

Use latest frontend

Main changes explained:

  • Shortened fillEarnedDateToMatchCount function to handle all logic itself not needing a second helper function, also added edge case of user trying to lower badges count
  • Added logic to assignBadge function to handle instances of duplicate badges and merge them to one with updated variables.

How to test:

  1. check into current branch
  2. go to src/controllers/userProfileController.js, comment out lines 579 - 583. This step is important to clear backend cache, clearing cache through browser won't help when making changes to mongo compass and wanting to see changes immediately
  3. do npm install and npm run build && npm start to run this PR locally
  4. log as admin user
  5. go to any user profile and make sure they have at least 2 different badges assigned to them
  6. create duplicate badges, here's a quick way to do this:
How.to.force.duplicates.mov
  1. Verify that either assigning a new badge or even incrementing count of any badge results in duplicate badges being merged.

Screenshots or videos of changes:

Fixed.mov

Note:

Make sure to follow step 2, if you make changes to the database through mongo compass, you won't see immediate changes in frontend due to the backend cache still not being renewed

Copy link
Contributor

@jerryren527 jerryren527 left a comment

Choose a reason for hiding this comment

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

Hi, @robertoooc ,

This is a great solution for the issue of having duplicate badges and no real logic to handle this case! Your solution is elegant and works correctly according to my testing. Your code for the fillEarnedDateToMatchCount() function works well too. In my testing demonstration, I had two duplicate badges with multiple different earned dates. And after the two duplicate badges merge into one badge, all the earned dates are present and sorted in order. Great job!

fix.assigning.duplicate.badges.earned.dates.correct.mp4

Copy link
Contributor

@ilyaflaks ilyaflaks left a comment

Choose a reason for hiding this comment

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

I reviewed the functionality and the code changes and everything works well!
Reproduced the issue by editing badge UUID in Compass:
PR666-dev-branch-dupl-result-03
Assigned a new badge of a different kind on the front end:
PR666-roberto-branch-assign-4
The duplicates are now grouped together:
PR666-roberto-branch-grouped-05
I then reproduced the problem again and tested if changing the badge count groups the badges:
PR666-roberto-remove-dup-byincr-06
The duplicate badges are grouped together!
PR666-roberto-remove-dup-byincr-07
Very good, clean code! fillEarnedDateToMatchCount is now much more robust and the overall logic of combining "earnedDate" is now easier to follow

Copy link
Member

@ChengyanOo ChengyanOo left a comment

Choose a reason for hiding this comment

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

Hi @robertoooc,

Excellent work on implementing the new feature! I've thoroughly reviewed your code and can confirm that the changes are functioning as intended. Keep up the good work!

HGNRest_PR.666.mov

@one-community one-community added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label Jan 25, 2024
Copy link
Contributor

@pshereen pshereen left a comment

Choose a reason for hiding this comment

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

Tested the PR.
The implemented feature is working as per the requirement.
Added two new badges to a user.
Screenshot 2024-01-24 190934

Incremented count of one of the badges from 1 to 3. And the duplicate badges are grouped together.

Screenshot 2024-01-24 191331 image

The edge case of user trying to lower badges count is also handled.

image

Copy link

@Renanluizssx Renanluizssx left a comment

Choose a reason for hiding this comment

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

Hi @robertoooc, i reviewed your application and it's correct, nice.

2024-01-26-04-52-48.mov

@xmyoot
Copy link

xmyoot commented Jan 28, 2024

Hi Roberto, I reviewed your badge feature on the front end and it looks great! working properly please reference video:

PR.666.mov

Copy link
Contributor

@Pandani07 Pandani07 left a comment

Choose a reason for hiding this comment

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

Reviewed your PR and works as intended! Great
The duplicates are grouped together and after that, all the earned dates are retained and organized in sequential order
Screenshot 2024-01-30 at 3 23 54 PM
Screenshot 2024-01-30 at 3 21 38 PM

@XiaohanMeng XiaohanMeng self-requested a review February 16, 2024 22:53
Copy link
Contributor

@XiaohanMeng XiaohanMeng left a comment

Choose a reason for hiding this comment

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

Hi @robertoooc,

I've tested the PR you submitted, and I'm pleased to report that it runs smoothly and the code is efficient. My testing procedure involved the following steps: I used an admin account to change the badge of a volunteer account; then, in MongoDB Compass, I modified the badge to be the same as another; upon refreshing, all identical badges were successfully merged. Additionally, I observed that adding a badge also results in the merging of identical badges. Well done on implementing this feature.

BE-666-result.mov

Copy link

@brandta-1 brandta-1 left a comment

Choose a reason for hiding this comment

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

Review

I've reviewed the code in src/controllers/badgeController.js and tested through the front end as well as MongoDB Compass. The changes are functioning correctly.

Videos:

Splitting duplicate badge dates through MongoDB:

00_split_duplicate_MongoDB.mov

Creating duplicate badge dates through MongoDB:

01_duplicate_MongoDB.mov

Creating duplicate badge as front-end admin:

02_duplicate_front-end.mov

Copy link

@huangweihou huangweihou left a comment

Choose a reason for hiding this comment

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

Hi Roberto, The duplicate badges updated correctly and please use the screenshots as reference:
Screen Shot 2024-02-17 at 2 26 21 PM
Screen Shot 2024-02-17 at 2 27 03 PM
Screen Shot 2024-02-17 at 2 27 22 PM

Copy link
Contributor

@peterson337 peterson337 left a comment

Choose a reason for hiding this comment

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

HI Roberto, I tested your application, and everything worked as expected. Good job!

a

Copy link

@Coops023 Coops023 left a comment

Choose a reason for hiding this comment

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

Hi Roberto, i reviewed this PR and everything works as it should, great job on this one!

PR#666

@psharma1984 psharma1984 self-requested a review February 22, 2024 20:56
Copy link

@psharma1984 psharma1984 left a comment

Choose a reason for hiding this comment

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

Reviewed the PR, it works efficiently. I used an admin account to change the badge of another account; then, in MongoDB Compass, upon refreshing, found that all identical badges were successfully merged and saw the increase of the badge count as i added new badge. Screenshots for reference below
Screenshot 2024-02-22 120914
Screenshot 2024-02-22 125600
Screenshot 2024-02-22 125228
Screenshot 2024-02-22 125416

@Weiyao-Li
Copy link
Member

Following exactly the same step and encountering error during the build:
image

Copy link

@PratimaSingh02 PratimaSingh02 left a comment

Choose a reason for hiding this comment

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

duplicate_badge.mp4

I reviewed the functionality and it works well.
When adding new badges the duplicate badge created via Compass gets merged.
However assigning a new same type of badge from the frontend again, might give a wrong count (as shown in the video). It shows one extra badge when adding the same badge, after changing directly in database.

@robertoooc
Copy link
Contributor Author

@Weiyao-Li, I've tried compiling my code with the same command but don't face that issue at all.
Is this an issue you've encountered on other branches like development as well?

@robertoooc
Copy link
Contributor Author

@PratimaSingh02, nice catch! Seems like some new FE changes may have caused this problem.
OneCommunityGlobal/HighestGoodNetworkApp#1999
This new pr ^^ helps fix this issue.

@robertoooc robertoooc requested review from PratimaSingh02 and psharma1984 and removed request for psharma1984 February 27, 2024 22:46
Copy link
Contributor

@DiegoSalas27 DiegoSalas27 left a comment

Choose a reason for hiding this comment

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

Hi @robertoooc . Nice work. Your code seems clean and well written. I have some questions regarding the behavior (since there could be other alternative flows in the bagde assigning process). I have attached a video with related questions about how the webpage should behave in different scenarions. Overall, I really like the simplicity of your code, it was very easy to follow along.

screen-recording-2024-03-01-at-90140-am_6gPihOV5.mp4

@Sarthak32
Copy link
Member

Nice work! Your code is well-organized and easy to understand. It functions seamlessly.(There seems to be no duplication of badges) Here's how I tested it...

Screenshot 2024-03-01 212638
Screenshot 2024-03-01 212051

Copy link

@PratimaSingh02 PratimaSingh02 left a comment

Choose a reason for hiding this comment

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

The merge functionality seems to be working great except the wrong count that shows up when adding the same type of badges. Approving the change as new PR has been created for the same.

@one-community
Copy link
Member

Thank you all, moving to final review.

@one-community one-community added Moved to Final Review and removed High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible labels Mar 8, 2024
Copy link
Member

@ChengyanOo ChengyanOo left a comment

Choose a reason for hiding this comment

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

Great work, I went through your code and didn't found any code smells. Check out the last comment I left for the video

@robertoooc
Copy link
Contributor Author

@DiegoSalas27, to clarify any doubts mentioned in your video:
We're currently using the mongodb GUI to force duplicate badges, the cause for this is because there have been some occasions where we've seen duplicate badges pop up in a user's profile and it's not fully clear how they're being generated, so for testing purposes I am having people use the GUI to force duplicates and check the new logic fixes the bug. A duplicate badge in this case is the array of badgesCollection having instances where there are more than one object with the same badgeId as another, so basically at some point the logic was flawed and would push a new instance of a badge to the array rather than updating the contents of the object. Our previous logic for this route would also break when you tried to update the badgeCollection array if it contained duplicates because it didn't know how to handle it.
Another thing you may have mentioned in your video was about the counts, the logic is supposed to merge the counts by adding them and all other variables of the badge if there are duplicates.

@DiegoSalas27
Copy link
Contributor

@DiegoSalas27, to clarify any doubts mentioned in your video:

We're currently using the mongodb GUI to force duplicate badges, the cause for this is because there have been some occasions where we've seen duplicate badges pop up in a user's profile and it's not fully clear how they're being generated, so for testing purposes I am having people use the GUI to force duplicates and check the new logic fixes the bug. A duplicate badge in this case is the array of badgesCollection having instances where there are more than one object with the same badgeId as another, so basically at some point the logic was flawed and would push a new instance of a badge to the array rather than updating the contents of the object. Our previous logic for this route would also break when you tried to update the badgeCollection array if it contained duplicates because it didn't know how to handle it.

Another thing you may have mentioned in your video was about the counts, the logic is supposed to merge the counts by adding them and all other variables of the badge if there are duplicates.

Got it. Thank you for clarifying that.

Copy link

@666saofeng 666saofeng left a comment

Choose a reason for hiding this comment

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

Hi Roberto, it worked as intended. Great job!

HGN.APP.-.Google.Chrome.2024-03-13.18-08-51.mp4

Copy link
Contributor

@cvtqx cvtqx left a comment

Choose a reason for hiding this comment

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

Works as described - duplicate badges are grouped together.

  1. User with assigned badges:
1
  1. Added a duplicate badge to this user and the badges are grouped:
2
  1. The issue dates of duplicates are displayed correctly:
3

4.Incremented count, duplicate badges are grouped together and the count is correct:

4

Great job!

@one-community
Copy link
Member

Thank you all, merging!

@one-community one-community merged commit a253daf into development Mar 16, 2024
3 checks passed
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.