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

Cleanup props and callbacks for OptionsList #13319

Merged
merged 22 commits into from
Dec 7, 2022
Merged

Conversation

tgolen
Copy link
Contributor

@tgolen tgolen commented Dec 5, 2022

Details

There were a number of minor things I did here, nothing major.

  • Removed a lot of props that were no longer used
  • Simplified some of the props (like hideAdditionalOptionStates which was only used along with customIcons so it wasn't necessary)
  • Changed a lot of callback to follow our standards
  • Rename a couple props to be more specific

Fixed Issues

This PR is partially for https://github.com/Expensify/Expensify/issues/228943 but is not a full fix. It is just a bunch of cleanup.

Tests

Most of the tests are going to be general regression tests. The best way to test these is to compare them against production for style and general behavior.

Report Participants Page

  1. On a group chat, click the header of the report (where the participants are listed) to view the report participants
  2. Verify users are listed, they are all visually displayed the same, clicking on a row takes you to the user's profile

Report Search Page

  1. Click on the search icon in the left-hand-navigation
  2. Verify that searching for different things shows the proper results. All results should be visually displayed the same

IOU Pages

Split a bill from the floating-action-button:

  1. From the floating-action-button, create a bill split
  2. Enter an amount
  3. Verify that people are listed and there could be two groups: "Recents" and "Contacts"
  4. Verify that all options are styled the same
  5. Verify that the search works
  6. Select a few people and click Next
  7. On the final confirmation page, verify that the people are listed and CANNOT be selected/deselected and they show up in two groups: "Who paid?" and "Who was there?"

Create a split from a group chat:

  1. Go to a group chat
  2. Click the + button in the left side of the comment composer
  3. Enter an amount and click Next
  4. On the final confirmation page, verify that the people are listed and CAN be selected/deselected and they show up in two groups: "Who paid?" and "Who was there?"

IOU Currency Selection

  1. Split a bill with someone
  2. On the step for entering an amount, click on the currency symbol
  3. Verify you can search for different currencies
  4. Verify the currencies are listed properly and all visually displayed the same

Request Money

  1. Click on the floating-action-button and select Request money
  2. Enter an amount
  3. Verify you can search for people and select them then click Next
  4. Verify that the people are listed properly and all visually displayed the same

New Chat Page

  1. Try creating both a new chat and a group chat
  2. Verify that people are listed and there could be two groups: "Recents" and "Contacts"
  3. Verify that searching for different things shows the proper results. All results should be visually displayed the same

Workspace Invite

  1. Go to a workspace settings and go to Manage Members
  2. Click the Invite button
  3. Verify that you can search for users, they are all visually displayed the same, can be selected
  • Verify that no errors appear in the JS console

Offline tests

When offline, some of the avatars might only be displayed as a default or blank avatar. This is normal and expected.

image

QA Steps

Same as all the tests above

  • 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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and 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
    • 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 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
2022-12-05_11-36-15.mp4
Mobile Web - Chrome
2022-12-05_11-48-16.mp4
Mobile Web - Safari
2022-12-05_11-55-27.mp4
Desktop
2022-12-05_11-58-01.mp4
iOS
2022-12-05_11-52-32.mp4
Android
2022-12-05_11-44-15.mp4

@tgolen tgolen self-assigned this Dec 5, 2022
@tgolen tgolen changed the title Tgolen optimize optionlist Cleanup props and callbacks for OptionsList Dec 5, 2022
@tgolen tgolen marked this pull request as ready for review December 5, 2022 19:00
@tgolen tgolen requested a review from a team as a code owner December 5, 2022 19:00
@melvin-bot melvin-bot bot requested review from Luke9389 and removed request for a team December 5, 2022 19:01
@melvin-bot
Copy link

melvin-bot bot commented Dec 5, 2022

@Luke9389 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]

@tgolen tgolen requested a review from Beamanator December 5, 2022 19:01
Luke9389
Luke9389 previously approved these changes Dec 6, 2022
Copy link
Contributor

@Luke9389 Luke9389 left a comment

Choose a reason for hiding this comment

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

What a satisfying diff. It's hard to imagine merging some of those patterns to begin with! Thanks for cleaning them up.

I'm seeing that we pass an almost identical method to OptionsSelector each time via the onChangeText prop. Do you think it's worth making another pass or a followup PR to reduce some of that repetition?

@Luke9389
Copy link
Contributor

Luke9389 commented Dec 6, 2022

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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and 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 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web Screen Shot 2022-12-06 at 4 04 11 PM
Mobile Web - Chrome

I'm currently unable to test here. I'm getting what seems to be an infinite splash screen. This is not a result of this PR. Somethings up with my environment. For now I'll check this one off from the checklist and rely on Web QA and Tim.

Screen Shot 2022-12-06 at 4 11 47 PM
Mobile Web - Safari Screen Shot 2022-12-06 at 4 07 39 PM
Desktop Screen Shot 2022-12-06 at 4 19 35 PM
iOS Screen Shot 2022-12-06 at 4 17 28 PM
Android Screen Shot 2022-12-06 at 4 15 43 PM

@Luke9389
Copy link
Contributor

Luke9389 commented Dec 6, 2022

I think the Tests for IOU Pages are slightly incorrect. I'm not able to select/deselect participants when I make the bill split from the group chat, but I am able to select/deselect when making the bill split from the FAB.

I'm going to resume testing but wanted to mention that.

@Luke9389
Copy link
Contributor

Luke9389 commented Dec 6, 2022

I'm getting an error when testing this on web. This is during the New Chat Page tests.

Warning: Failed prop type: Invalid prop `onConfirmSelection` of type `boolean` supplied to `BaseOptionsSelector`, expected `function`.

Screenshot:
Screen Shot 2022-12-05 at 5 36 58 PM

I'm not getting this error on the main branch. Screenshot:
Screen Shot 2022-12-05 at 5 42 04 PM

Comment on lines 256 to 257
onConfirmSelection={this.props.isGroupChat ? this.createGroup : () => {}}
onConfirmSelection={this.props.isGroupChat && this.createGroup}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is causing the error I posted about in the thread.
#13319 (comment)

Copy link
Contributor

@Beamanator Beamanator left a comment

Choose a reason for hiding this comment

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

When I added a few members to a group chat, after creating the group chat I saw this console warning (Note: I tried to reproduce but only saw this once ever 🤷 ):

Screen Shot 2022-12-06 at 4 03 12 PM

Also I believe I found one bug:

  1. Split Bill -> enter money -> select 2 or more people -> continue
  2. click on the people you just added - in staging, you can de-select people but on your branch, you can't. Video:
Screen.Recording.2022-12-06.at.4.11.22.PM.mov

src/components/OptionsSelector/optionsSelectorPropTypes.js Outdated Show resolved Hide resolved
src/components/OptionsList/optionsListPropTypes.js Outdated Show resolved Hide resolved
src/components/OptionRow.js Outdated Show resolved Hide resolved
@tgolen
Copy link
Contributor Author

tgolen commented Dec 6, 2022

OK, thanks for the reviews, and I'll look into some of those prop warnings.

Regarding the logic for select/deselect participants, it's a bit murky. I actually have an open PR that flips some of the logic for when participants can be modified. Maybe we should put this PR on HOLD until that is merged so that we are all clear on what the correct logic is? I think that will help me, so I'll go ahead and do that, but let's keep reviewing this.

I'm seeing that we pass an almost identical method to OptionsSelector each time via the onChangeText prop. Do you think it's worth making another pass or a followup PR to reduce some of that repetition?

I thought about this too. The conclusion that I came to is that I couldn't really think of a very good solution. Each of those methods is unique enough and modifies the state of the parent component, so it's not something that could be generalized inside of OptionsList and I don't think it would make sense to move it to a utils file either. The logic that most of those functions use is already in a utils file, so it's been DRYed up quite a bit already.

@tgolen
Copy link
Contributor Author

tgolen commented Dec 6, 2022

OK, well... that's been merged already today, so I will go through here and try to clean up the testing steps a little to denote when you should and shouldn't be able to select people

@tgolen
Copy link
Contributor Author

tgolen commented Dec 6, 2022

Updated! I fixed the prop warning that Luke found.

I also checked the tests and they did have the right logic, it's just the code hadn't been updated with the correct logic. Now that the other PR was merged, this code has the correct logic, so the tests will be correct for when you can select/deselect people.

I found a bug that the OptionRow wasn't being memo'ed properly. I found this out because it wouldn't let me select/deselect people (so just keep an eye out for that).

Lastly, the warning about the keys in virtualized list, that appears to be unrelated to these changes and it happens from the ReportActionsList in some situations (mostly when you're starting brand new chats). So, I would consider that out-of-scope of this PR to fix, but you can open a new GH for it 👍

@Luke9389
Copy link
Contributor

Luke9389 commented Dec 6, 2022

I'll resume testing/review this one this evening.

@Luke9389
Copy link
Contributor

Luke9389 commented Dec 6, 2022

OK done with Web QA and blockers so I'm back on the review for this.

Comment on lines 256 to 323
// export default withLocalize(memo(OptionRow, (prevProps, nextProps) => {
// if (prevProps.optionIsFocused !== nextProps.optionIsFocused) {
// return false;
// }
//
// if (prevProps.isSelected !== nextProps.isSelected) {
// return false;
// }
//
// if (prevProps.mode !== nextProps.mode) {
// return false;
// }
//
// if (prevProps.option.isUnread !== nextProps.option.isUnread) {
// return false;
// }
//
// if (prevProps.option.alternateText !== nextProps.option.alternateText) {
// return false;
// }
//
// if (prevProps.option.descriptiveText !== nextProps.option.descriptiveText) {
// return false;
// }
//
// if (prevProps.option.hasDraftComment !== nextProps.option.hasDraftComment) {
// return false;
// }
//
// if (prevProps.option.isPinned !== nextProps.option.isPinned) {
// return false;
// }
//
// if (prevProps.option.hasOutstandingIOU !== nextProps.option.hasOutstandingIOU) {
// return false;
// }
//
// if (!_.isEqual(prevProps.option.icons, nextProps.option.icons)) {
// return false;
// }
//
// // Re-render when the text changes
// if (prevProps.option.text !== nextProps.option.text) {
// return false;
// }
//
// if (prevProps.showSelectedState !== nextProps.showSelectedState) {
// return false;
// }
//
// if (prevProps.isDisabled !== nextProps.isDisabled) {
// return false;
// }
//
// if (prevProps.showTitleTooltip !== nextProps.showTitleTooltip) {
// return false;
// }
//
// if (prevProps.backgroundColor !== nextProps.backgroundColor) {
// return false;
// }
//
// if (prevProps.option.brickRoadIndicator !== nextProps.option.brickRoadIndicator) {
// return false;
// }
//
// return true;
// }));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this is not supposed to be here 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed 👍 😊

@Luke9389
Copy link
Contributor

Luke9389 commented Dec 7, 2022

OK! Looking good except for that last thing. Happy to merge as soon as that's taken care of.

@tgolen tgolen mentioned this pull request Dec 7, 2022
50 tasks
@tgolen
Copy link
Contributor Author

tgolen commented Dec 7, 2022

Updated and ready for final review and merge

@Luke9389 Luke9389 requested a review from Beamanator December 7, 2022 19:49
@Luke9389 Luke9389 dismissed Beamanator’s stale review December 7, 2022 19:50

Alex is OOO but we want to merge now.

@Luke9389 Luke9389 merged commit 9512731 into main Dec 7, 2022
@Luke9389 Luke9389 deleted the tgolen-optimize-optionlist branch December 7, 2022 19:51
@OSBotify
Copy link
Contributor

OSBotify commented Dec 7, 2022

✋ 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
Copy link
Contributor

🚀 Deployed to production by @chiragsalian in version: 1.2.38-6 🚀

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

@mananjadhav
Copy link
Collaborator

mananjadhav commented Apr 27, 2023

I am tagging this PR to highlight an issue fixed here. All conditions in ternary expressions or left-hand operands on conditional renders, should be boolean. This PR is one of the PRs that uses conditional render with string operands, hence I am tagging it here for the contributors to check.

We've also updated the item in the checklist with this PR to avoid this issue in the future.

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.

5 participants