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: split filtering & ordering in OptionsListUtils #53371

Merged

Conversation

hannojg
Copy link
Contributor

@hannojg hannojg commented Dec 2, 2024

Explanation of Change

This PR is a refactoring that clearly splits the responsibilities into:

  • filtering options
  • ordering options

Before ordering and filtering was happening inter-connectedly, which makes it hard to change anything about that code.

Over at this PR i am working on improving the performance of the filtering:

and i need the filtering and ordering to be two clearly separate operations (so we can easily just swap out the filtering for a faster implementation).

Notes about the changes:

  • I found that the excludeUnknownUsers was a option that had no code path that was ever used, so I was able to remove it
  • Likewise sortPersonalDetailsByAlphaAsc was default true and there was no code path that was setting this to false so I removed that as well
  • For ordering the options we need to sort by the lastVisibleActionCreated. It was currently not present on the option and so i added it to createOption
  • I renamed getOptions to getValidOptions to emphasis the functions responsibility to return us only the options that are valid for showing in the UI
  • I created separate functions for filtering and ordering. The new function to get a filtered and ordered options object is now called filterAndOrderOptions (before it was filterOptions). The new separate functions are:
    • orderReportOptions
    • orderPersonalDetailsOptions
    • orderOptions, combines the two above functions
    • filterReports
    • filterPersonalDetails
    • filterCurrentUserOption
    • filterUserToInvite
    • filterOptions combines the four above

There is also a performance advantage to this I want to point out:

Before we were applying some ordering to all options before filtering them. Now, we filter the options first and then apply the ordering to the remaining search result, which can be way more efficient.

Fixed Issues

$ #51954
PROPOSAL: #51954 (comment)

Tests

  • Verify that no errors appear in the JS console
  • Open the search:
    • Confirm that search results between this branch and production are very much the same (it might be that on dev / production you've different items loaded which can slightly influence the search results, but largely they should match)

Offline tests

QA Steps

Same as testing

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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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 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 used JaimeGPT to get English > Spanish translation. I then posted it 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 either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • 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.ts 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 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(theme.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 the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • 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.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • 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.

Screenshots/Videos

Android: Native

CleanShot 2024-12-02 at 14 48 07

Android: mWeb Chrome

CleanShot 2024-12-02 at 14 48 07

iOS: Native

CleanShot 2024-12-02 at 14 48 07

iOS: mWeb Safari

CleanShot 2024-12-02 at 14 48 07

MacOS: Chrome / Safari

CleanShot 2024-12-02 at 14 48 07

MacOS: Desktop

CleanShot 2024-12-02 at 14 48 07

The current problem is with the max reports number. I currently only splice in the order function. but in the filter function we filter the personal details based on the recent reports. if the recent reports aren't limited in the filter function then then we will have fewer personal details (as more reports have been loaded).

however i can't limit the recent reports in filter yet as they aren't ordered yet…

we might need to split up getOptions for reports and pD actually
@hannojg hannojg mentioned this pull request Dec 2, 2024
50 tasks
@hannojg
Copy link
Contributor Author

hannojg commented Dec 2, 2024

cc @ahmedGaber93 since you reviewed all PRs of this cleanup so far 🫶
This is ready for review (will mark it as such once i've filled all the details)

@hannojg hannojg changed the title Cleanup/split filtering ordering cleanup: split filtering ordering Dec 2, 2024
@hannojg hannojg changed the title cleanup: split filtering ordering cleanup: split filtering & ordering in OptionsListUtils Dec 2, 2024
@hannojg hannojg marked this pull request as ready for review December 2, 2024 13:50
@hannojg hannojg requested a review from a team as a code owner December 2, 2024 13:50
@melvin-bot melvin-bot bot requested review from neil-marcellini and removed request for a team December 2, 2024 13:50
Copy link

melvin-bot bot commented Dec 2, 2024

@neil-marcellini 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]

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Nice work! It mostly looks good to me. I recognize that it's pretty hard to test such a large refactor like this, but I will add a C+ to stick to our process and have another set of eyes.

I have some questions about the unit tests.

src/libs/OptionsListUtils.ts Outdated Show resolved Hide resolved
tests/unit/OptionsListUtilsTest.ts Outdated Show resolved Hide resolved
tests/unit/OptionsListUtilsTest.ts Show resolved Hide resolved
@ahmedGaber93
Copy link
Contributor

Reviewing and testing today.

Copy link
Contributor

@ahmedGaber93 ahmedGaber93 left a comment

Choose a reason for hiding this comment

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

Great refactoring, just small notes

src/components/Search/SearchFiltersChatsSelector.tsx Outdated Show resolved Hide resolved
if (option.private_isArchived) {
return CONST.DATE.UNIX_EPOCH;
}
return option?.lastVisibleActionCreated ?? '';
Copy link
Contributor

Choose a reason for hiding this comment

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

The fallback ?? '' didn't exist before the refactoring, I think this may affect on the ordering because orderBy() places undefined values at the end of the sorted array, and empty value '' at the top, you can try it 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.

fixed this one! also realized i was missing one other parameter to the ordering which i added now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually i probably have to rewrite this a bit. I think in the original implementation there was kind of a bug. Will explain in detail once fixed …

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so we don't need the additional private_isArchived, we don't need the additional isSelfDM check.

The code i have written makes sure to check all of these properties only once (before we were using those options in the multiple order functions, which makes it harder to understand whats happening).

The ?? '' is actually correct, i added a code comment to better explain it

src/libs/OptionsListUtils.ts Outdated Show resolved Hide resolved
tests/unit/OptionsListUtilsTest.ts Outdated Show resolved Hide resolved
@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Dec 3, 2024

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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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 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 either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • 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.ts 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(theme.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 the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • 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

Android: Native
aa.mp4
Android: mWeb Chrome
wwaa.mp4
iOS: Native
iiiii.mp4
iOS: mWeb Safari
wwiii.mp4
MacOS: Chrome / Safari
phone.number.user.to.invite.mp4
phone.number.mp4
start.chat.mp4
number.mp4
user.to.join.mp4
you.mp4
multi.search.text.mp4
search.tab.mp4
20241205210114123.mp4
MacOS: Desktop
20241210161849467.mp4

@hannojg hannojg force-pushed the cleanup/split-filtering-ordering branch from 00e284f to c60f18d Compare December 4, 2024 17:24
@hannojg hannojg marked this pull request as ready for review December 4, 2024 18:45
@hannojg
Copy link
Contributor Author

hannojg commented Dec 4, 2024

Okay, prod and dev looked the same now in my test cases:

CleanShot 2024-12-04 at 17 30 59

Copy link
Contributor

@neil-marcellini neil-marcellini 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 updates, all my requested changes from last time were addressed. It all looks good to me except for one test. Let's also please add more test steps with more detail, trying to cover most of the areas that were changed. If we do that it's less likely we'll have to revert this due to regressions on staging.

tests/unit/OptionsListUtilsTest.ts Outdated Show resolved Hide resolved
@neil-marcellini
Copy link
Contributor

Another option is to ask Applause to run the regression tests on this branch, I think we do that sometimes for large changes. I'm not sure it's appropriate for this one, but we can ask if you want to try that.

@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Dec 5, 2024

I tested it as much as I could. Search result look the same on dev and staging except the last case

✅ search tab
search.tab.mp4
✅ search from header icon
20241205210114123.mp4
✅ multi search terms
multi.search.text.mp4
✅ self DM
you.mp4
✅ user to join - email
user.to.join.mp4
✅ user to join - phone
phone.number.user.to.invite.mp4
✅ start chat
start.chat.mp4
❌ create expense
  1. Fresh login with a high traffic account that have a lot of workspaces on DEV and staging
  2. Click Fab icon > Create expense > choose participant

The recent reports are not in the same order, especially "Big chat" workspace.

Screenshot 2024-12-05 at 9 46 04 PM

@hannojg
Copy link
Contributor Author

hannojg commented Dec 6, 2024

@ahmedGaber93 Thanks for the thorough testing! Can you please test this case again?

@hannojg
Copy link
Contributor Author

hannojg commented Dec 6, 2024

@neil-marcellini yeah i would sleep better if this PR would get a Applause regression test 😅 maybe we can ask them to only test search features / features that are related to where we show result lists?

@ahmedGaber93
Copy link
Contributor

Can you please test this case again?

Hmm! Ordering still not the same.

Comment on lines 129 to 131
const orderedOptions = OptionsListUtils.orderOptions(optionList, undefined, {
sortByReportTypeInSearch: isPaidGroupPolicy,
});
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 config will be ignored when we're passing searchValue as undefined because orderReportOptions(options: ReportUtils.OptionData[]) doesn't have a config parameter

Copy link
Contributor

@ahmedGaber93 ahmedGaber93 Dec 6, 2024

Choose a reason for hiding this comment

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

The ordering looks the same with me in this case only when remove sortComparatorReportOptionByDate here, but I don't know if we should remove it or no and also don't test this change effect on the other cases

Update: I test it on other places, and it causes a lot of mismatching ordering, so it is not the correct way. But it may help to investigate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, okay, will double check with multiple accounts - good observation with the config not being used, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a function overloading for orderOptions to make sure you can only call it with options when you've provided a search value

@hannojg hannojg force-pushed the cleanup/split-filtering-ordering branch from c16d172 to ee50f31 Compare December 9, 2024 13:22
@hannojg
Copy link
Contributor Author

hannojg commented Dec 9, 2024

@ahmedGaber93 Okay I think I fixed the ordering now. I did this by separating the order statements, this is how it was working before (ie. the first order function was called in getOptions the second in filterOptions - both functions are now called in the orderReportOptions functions). Would appreciate if you could test this one more time 🙏

I will revisit the ordering function after the cleanup PR is merged. I think sorting twice is quite inefficient and especially lodash orderBy is known to be slow (but will profile soon and provide before and after values!)

Copy link
Contributor

@ahmedGaber93 ahmedGaber93 left a comment

Choose a reason for hiding this comment

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

Tested well! All yours @neil-marcellini.

Copy link

melvin-bot bot commented Dec 10, 2024

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

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

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Ok, looks like it's time to merge. Hopefully QA will catch any issues we missed and if they create a blocker issue we'll revert this and fix the specific problem.

@neil-marcellini neil-marcellini merged commit 1a95147 into Expensify:main Dec 11, 2024
18 checks passed
@OSBotify
Copy link
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.

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.

4 participants