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

LB-530: Refactor the LastFm Modal code #1214

Merged
merged 6 commits into from Jan 11, 2021
Merged

Conversation

kshitijk83
Copy link
Contributor

@kshitijk83 kshitijk83 commented Dec 29, 2020

Problem

Currently the function for showing messages in LastFm Importer Modal is present in other components. However this is against React's design principles and makes it difficult to add new code or test the existing code. Refactoring the code so that the content shown by Modal is controlled by the component itself will solve the issue.

For reference this is the code which has to be refactored

https://github.com/metabrainz/listenbrainz-server/blob/master/listenbrainz/webserver/static/js/src/LastFMImporterModal.tsx

https://github.com/metabrainz/listenbrainz-server/blob/master/listenbrainz/webserver/static/js/src/Importer.tsx

JIRA ticket: https://tickets.metabrainz.org/browse/LB-530

Solution

Refactored the LastFmImporter.tsx code to include the importing functionality which was delegated to Importer.tsx file, kept the same private variables and initialized them in the constructor function. The workaround for updating state using setInterval wasn't required now (so i removed it) and was performance degrading as setInterval was rerendering the component after each 100ms.

#Action
Do we still need static functions in this component after refactoring?

@brainzbot
Copy link
Member

Can one of the admins verify this patch?

3 similar comments
@brainzbot
Copy link
Member

Can one of the admins verify this patch?

@brainzbot
Copy link
Member

Can one of the admins verify this patch?

@brainzbot
Copy link
Member

Can one of the admins verify this patch?

Copy link
Collaborator

@shivam-kapila shivam-kapila 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 the contribution Looks good. Maybe @ishaanshah has some other things in mind too. Would like his review. Other than this please remove the duplicated code from Importer.tsx and not to forget the tests.

listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
listenbrainz/webserver/static/js/src/RecentListens.tsx Outdated Show resolved Hide resolved
@shivam-kapila
Copy link
Collaborator

I checked this PR out and saw a lot of linting related issues, especially Must use destructuring props assignment. You can observe these issues (and correct some of them automatically) by running lint.sh. Please look into this too

Copy link
Collaborator

@shivam-kapila shivam-kapila left a comment

Choose a reason for hiding this comment

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

this looks good. I think we can remove the redundant code from Importer..tsx and fix the tests (cut paste IG)

listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@ishaanshah ishaanshah left a comment

Choose a reason for hiding this comment

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

Hey, thanks a lot for opening the PR.
I tested PR, however I found out couple of regressions

  • The importer doesn't report an error if the user is invalid.
  • The importer also doesn't report an error if there's an network error and the page freezes.

Also can you add regression tests for the above errors to ensure that it doesn't happen in the future.

listenbrainz/webserver/static/js/src/LastFMImporter.tsx Outdated Show resolved Hide resolved
@kshitijk83
Copy link
Contributor Author

Hey, thanks a lot for opening the PR.
I tested PR, however I found out couple of regressions

* The importer doesn't report an error if the user is invalid.

* The importer also doesn't report an error if there's an network error and the page freezes.

Also can you add regression tests for the above errors to ensure that it doesn't happen in the future.

Hey @ishaanshah .. regarding the page freeze issue, i noticed it is freezing only when the server is not running, i guess that's bound to happen if i stop the server while clicking submit. Can you explain more about this issue, as in my system it is working fine and is not freezing on the network error given that the server is running.

Copy link
Collaborator

@ishaanshah ishaanshah left a comment

Choose a reason for hiding this comment

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

Hey @ishaanshah .. regarding the page freeze issue, i noticed it is freezing only when the server is not running.

Hi, thanks for making the changes. You are correct about the freezing issue, I accidentally disabled all networks (including docker) which made the server unreachable and caused the free. On turning of internet access the importer worked as expected. The PR looks good to me, thanks again for opening it. I'll let @MonkeyDo have a look at it and merge it.

Copy link
Collaborator

@shivam-kapila shivam-kapila left a comment

Choose a reason for hiding this comment

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

@kshitijk83 I think there must be some redundant code left in the original files after you moved the functions. Can you remove that please?

@shivam-kapila
Copy link
Collaborator

@brainzbot retest this please

Copy link
Collaborator

@shivam-kapila shivam-kapila 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 your contribution. This looks ready. The failing JS build is failing due to a known other is (fixed in #1228), related to this issue. The changes here are good to go 🎉

Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

I'm not very familiar with the LastFM importer code, but the PR looks fine to me, thanks for opening it ! :)

@MonkeyDo MonkeyDo merged commit aa2db43 into metabrainz:master Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants