Skip to content

chore: migrate BaseInvertedFlatList.js to function component - #26921

Merged
cead22 merged 7 commits into
Expensify:mainfrom
teneeto:chore/16168-migrate-base-inverted-flat-list-file-to-function-component
Oct 2, 2023
Merged

cead22 merged 7 commits into
Expensify:mainfrom
teneeto:chore/16168-migrate-base-inverted-flat-list-file-to-function-component

Conversation

@teneeto

@teneeto teneeto commented Sep 7, 2023

Copy link
Copy Markdown
Contributor

Details

This change is made to migrate the BaseInvertedFlatList.js from class to a function component

Fixed Issues

$: 16168
PROPOSAL: 16168

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-09-07.at.02.23.20.mov
Mobile Web - Chrome
Screen.Recording.2023-09-07.at.02.24.24.mov
Mobile Web - Safari
Screen.Recording.2023-09-07.at.02.22.03.mov
Desktop
Screen.Recording.2023-09-07.at.02.25.58.mov
iOS
Screen.Recording.2023-09-07.at.02.17.55.mov
Android
Screen.Recording.2023-09-07.at.02.40.09.mov

Comment thread src/components/InvertedFlatList/BaseInvertedFlatList.js
Comment thread src/components/InvertedFlatList/BaseInvertedFlatList.js Outdated
Comment thread src/components/InvertedFlatList/BaseInvertedFlatList.js Outdated
@teneeto
teneeto marked this pull request as ready for review September 7, 2023 16:52
@teneeto
teneeto requested a review from a team as a code owner September 7, 2023 16:52
@melvin-bot
melvin-bot Bot requested review from cead22 and removed request for a team September 7, 2023 16:52
@melvin-bot

melvin-bot Bot commented Sep 7, 2023

Copy link
Copy Markdown

@cead22 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@teneeto

teneeto commented Sep 12, 2023

Copy link
Copy Markdown
Contributor Author

Hi @cead22, any chance we could get this reviewed anytime soon?

Comment thread src/components/InvertedFlatList/BaseInvertedFlatList.js
Comment thread src/components/InvertedFlatList/BaseInvertedFlatList.js
Comment thread src/components/InvertedFlatList/BaseInvertedFlatList.js Outdated
@teneeto

teneeto commented Sep 18, 2023

Copy link
Copy Markdown
Contributor Author

@cead22 thanks for the reviews, resolved all, you might want to take a look again.

cead22
cead22 previously approved these changes Sep 19, 2023
@cead22

cead22 commented Sep 19, 2023

Copy link
Copy Markdown
Contributor

@gedu do you mind giving this another look before I merge?

BaseInvertedFlatList.defaultProps = defaultProps;
BaseInvertedFlatList.displayName = 'BaseInvertedFlatList';

export default forwardRef((props, ref) => (

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.

Seems from this thread that we are changing the way to use forwardRef, the documentation will be updated soon, I think we can use the new way

@gedu

gedu commented Sep 19, 2023

Copy link
Copy Markdown
Contributor

@cead22 will be a new way to use forwardRef do you think we should add it here? or on a follow-up PR?

that's my only comment, all LGTM

@cead22

cead22 commented Sep 20, 2023

Copy link
Copy Markdown
Contributor

@cead22 will be a new way to use forwardRef do you think we should add it here? or on a follow-up PR?

Can you share more details? I'm not familiar with this change. If we're ready to do it now and that's the ideal way to do it moving forward, then let's do it in this PR

@gedu

gedu commented Sep 20, 2023

Copy link
Copy Markdown
Contributor

@cead22 just double check and isn't ready yet, so I think the PR is good

@cead22

cead22 commented Sep 22, 2023

Copy link
Copy Markdown
Contributor

@teneeto conflicts. @s77rt can you please complete the reviewer checklist? I'm not sure why you were automatically assigned to this (or @danieldoglas for that matter)

Comment thread src/components/InvertedFlatList/BaseInvertedFlatList.js
@s77rt

s77rt commented Sep 23, 2023

Copy link
Copy Markdown
Member

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web web
Mobile Web - Chrome mweb-chrome
Mobile Web - Safari mweb-safari
Desktop desktop
iOS ios
Android android

@melvin-bot

melvin-bot Bot commented Sep 23, 2023

Copy link
Copy Markdown

🎯 @s77rt, thanks for reviewing and testing this PR! 🎉

An E/App issue has been created to issue payment here: #28083.

@danieldoglas

Copy link
Copy Markdown
Contributor

My bad it took me a while to get to this. We have merge conflicts

@cead22

cead22 commented Sep 26, 2023

Copy link
Copy Markdown
Contributor

@teneeto in case you missed the previous notification, we still have conflicts in this PR

@teneeto

teneeto commented Sep 26, 2023

Copy link
Copy Markdown
Contributor Author

@teneeto in case you missed the previous notification, we still have conflicts in this PR

Hi @cead22, sorry I was out for a while, but will attend to it ASAP.

@cead22

cead22 commented Sep 26, 2023

Copy link
Copy Markdown
Contributor

No problem, and no rush, I just wanted to make sure you saw this

…ate-base-inverted-flat-list-file-to-function-component
@teneeto

teneeto commented Sep 26, 2023

Copy link
Copy Markdown
Contributor Author

@cead22 @s77rt Conflict is resolved. This might need your review and approval again. Thanks.

@s77rt

s77rt commented Sep 26, 2023

Copy link
Copy Markdown
Member

Retested. Looks good to me 👍

@teneeto

teneeto commented Sep 27, 2023

Copy link
Copy Markdown
Contributor Author

A fresh approval is needed here 😉!


return (
<FlatList
// eslint-disable-next-line react/jsx-props-no-spreading

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.

Is there a reason we're suppressing this here instead of updating the code to comply with this rule?

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.

AFAIK there is no solution for this one. This is how we are passing props in the codebase. We can instead pass every prop explicitly but we have so many that ignoring the rule feels better.

When not to use the rule: If you are not using JSX or have lots of props to be passed or the props spreading is used inside HOC.

From https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md#when-not-to-use-it

@cead22 cead22 Sep 29, 2023

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.

I work on App much much less than you all, but I actually don't think ignoring the rule is better, and I'd love for us to consider passing all props explicitly

  • It makes the code easier to understand, because you know what's being passed without having to go up the component hierarchy
  • It prevents sending down extra props that aren't needed (maybe there are ways this is prevented that I don't know about)
  • Remove the rule would be better than having it and ignoring it

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.

When not to use the rule: If you are not using JSX or have lots of props to be passed or the props spreading is used inside HOC.

I think this is close, except the "have lots of props to be passed" is kind of misleading. The case where it's OK to use the spread operator is when you have a wrapper component that can pass any vast number of props and there is no way to know what those props will be.

This is why it's OK to be used inside an HOC (because it's generic and any component can be passing props).

I think there is another case worth mentioning and that is when there is a wrapper around a native-built or a third-party component. I don't think we would want to try and explicitly pass every prop that is available to those components (ie. we might not know all the props, or the props might change with library updates that we would not catch and know about).

That's why I think there is a pretty good case for using the spread operator here.

For the majority of cases, we shouldn't use the spread operator and therefore it's still valuable for the ESlint rule to be there. It gives us a chance to do a thorough review of all the exceptions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cead22 how do we proceed with this? should we not suppress the warning? Also AFFAIK, there are many other exceptional cases as this for HOCs.

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.

Yeah that makes sense. We can continue that discussion elsewhere without blocking this PR on it

@cead22
cead22 merged commit aabe4d6 into Expensify:main Oct 2, 2023
@melvin-bot

melvin-bot Bot commented Oct 2, 2023

Copy link
Copy Markdown

Congrats, that’s your 5th PR merged! 🎉 Do you know about the ContributorPlus role? It’s an opportunity to earn more in the Expensify Open Source community. Keep up the great work - thanks!

@OSBotify

OSBotify commented Oct 2, 2023

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

OSBotify commented Oct 3, 2023

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/cead22 in version: 1.3.77-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify

OSBotify commented Oct 5, 2023

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 1.3.77-7 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

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.

7 participants