Skip to content

Fix view more projects link on public gallery #20321

Merged
Erin007 merged 1 commit into
stagingfrom
view-more-projects-link
Jan 31, 2018
Merged

Fix view more projects link on public gallery #20321
Erin007 merged 1 commit into
stagingfrom
view-more-projects-link

Conversation

@Erin007
Copy link
Copy Markdown
Contributor

@Erin007 Erin007 commented Jan 30, 2018

I missed a few fat arrow functions that relied on this when converting ProjectAppTypeArea in #20211, which broke the view more projects link in the public gallery.
screen shot 2018-01-30 at 3 53 27 pm

This PR fixes the broken link and updates all the functions that rely on this to the new syntax.

@Erin007
Copy link
Copy Markdown
Contributor Author

Erin007 commented Jan 30, 2018

I'm not sure how this test passed with the original change: 🤔

it('displays more projects when View More is pressed', () => {

@Erin007
Copy link
Copy Markdown
Contributor Author

Erin007 commented Jan 31, 2018

ooh, actually, that's a different "View More" button, not the link for specific project types. I'll add some coverage for the link.

Copy link
Copy Markdown
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

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

Hi Erin,

I believe the only one of these you need to fix is the viewMore, but there is one I'm not totally sure on.

I've looked for an article explaining when to bind or not, but none offer a super concise description. my understanding though is that you only need it for a method which you pass as a prop to another react component (e.g. onClick).

@islemaster, have you used the tool described at https://reactjs.org/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactcreateclass for these conversions? Have you found a good article explaining when to bind or not?

maxNumProjects: nextProps.projectList ? nextProps.projectList.length : 0
});
}
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

react life cycle methods do not need to be bound to this, so you can safely leave this method how it was before.

};

renderProjectCardList(projectList, max) {
renderProjectCardList = (projectList, max) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

binding renderProjectCardList is also unnecessary

* completed and the done handler has been run (if successful).
*/
fetchOlderProjects() {
fetchOlderProjects = () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suspect this binding is unnecessary because the function that's calling it already has this bound correctly, but I'm not sure. @islemaster may know. Better safe than sorry, so fine to keep this the way you have it in this PR for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's correct. It's not really harmful to bind it here, but you don't need to bind functions that are:

  • React lifecycle methods (unless you call them manually at some point)
  • Only called with context, i.e. this.methodName()

@davidsbailey
Copy link
Copy Markdown
Member

Nice find @Erin007 ! Since Brad is out today I think it's fine to get this merged without his answers to my questions.

@Erin007 Erin007 merged commit 6c6f95b into staging Jan 31, 2018
@Erin007 Erin007 deleted the view-more-projects-link branch January 31, 2018 16:59
@Erin007
Copy link
Copy Markdown
Contributor Author

Erin007 commented Jan 31, 2018

Merging so this fix can go in and people can see more projects, but will follow up by cleaning up functions that don't need fat arrows and adding test coverage for the view more link.

@islemaster
Copy link
Copy Markdown
Contributor

I haven't used the codemod tool for these conversions because I'm not sure it will correctly understand/translate our class-property syntax babel extension... and because I see these conversions as a useful effort to improve our test coverage too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants