-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Move the logic of excluding contacts of DMs already included in reports to filterOptions
#50426
Move the logic of excluding contacts of DMs already included in reports to filterOptions
#50426
Conversation
Reviewer Checklist
Screenshots/VideosAndroid: Native0-android.mp4MacOS: Chrome / SafariMacOS: Desktop0-desktop.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested various cases and all look good. Just a comment worrying about possible performance downgrade.
@@ -2569,9 +2574,10 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt | |||
if (maxRecentReportsToShow > 0 && recentReports.length > maxRecentReportsToShow) { | |||
recentReports.splice(maxRecentReportsToShow); | |||
} | |||
const filteredPersonalDetails = filteredPersonalDetailsOfRecentReports(recentReports, personalDetails); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a use case when maxRecentReportsToShow = 0 and recentReports
is a long list? If so, then it seems there will be a performance downgrade here. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will but that might not be significant.
We iterate over all recentReports
here for each search word.
App/src/libs/OptionsListUtils.ts
Lines 2520 to 2542 in 9d86f30
const recentReports = filterArrayByMatch(items.recentReports, term, (item) => { | |
const values: string[] = []; | |
if (item.text) { | |
values.push(item.text); | |
} | |
if (item.login) { | |
values.push(item.login); | |
values.push(item.login.replace(CONST.EMAIL_SEARCH_REGEX, '')); | |
} | |
if (item.isThread) { | |
if (item.alternateText) { | |
values.push(item.alternateText); | |
} | |
} else if (!!item.isChatRoom || !!item.isPolicyExpenseChat) { | |
if (item.subtitle) { | |
values.push(item.subtitle); | |
} | |
} | |
return uniqFast(values); | |
}); |
We iterate over the recentReports
once more for this function filteredPersonalDetailsOfRecentReports
.
Since, we pass searchTerm
only to this function filterOptions
and not getOptions
, we need to do this exclusion of contacts only here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to review it on Monday.
Should we add lint rule to prevent wrong usage of filterOptions() as we discussed?
I checked the We have two other options.
if (options && options.reports && options.reports.length !== 0 && searchInputValue) {
console.error('getOptions: Do not provide searchInputValue when options.reports is not empty. Use the performant filterOptions to filter with searchInputValue.');
}
|
This sounds good, plus we can add a comment 👍 |
Yeah, I also agree - modifying types to achieve it sounds more viable 👍 |
Thanks! Let's do it 👍 |
I have not found a way to enforce the constraint in Here is the branch with some files changed. When we pass a search term in cases with reports or personal details (in the In cases where they are not passed, we can pass a search term, and TypeScript does not complain (as seen in enforceEmptySearchTerm.mp4This type modification can also make the usage of I think we should handle that in a separate PR so that if we make any mistakes, we can revert it easily. |
@c3024 Thanks for the update! Is it possible to achieve what we want through function overloads? See https://www.typescriptlang.org/docs/handbook/2/functions.html#function-overloads |
I did try with functional overloads with |
@c3024 Hmm, I think it's better to do this in this PR together because here we have good intention and willingness - prevent wrong usage and get cleaner codebase. |
There ya go! 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just minor comments
(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction, | ||
false, | ||
false, | ||
0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxRecentReportsToShow: 0
is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c3024 Btw this is crucial missing 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, my bad!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Screen.Recording.2024-10-17.at.9.04.48.PM.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retested it on web and works well!
@c3024 Thanks for your patience!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for TS cleanup. Looks good!
Thanks for the comments. Updated with these suggestions. I added a couple of comments in the last commit explaining why we are enforcing the types. Please have a look! |
Thank you for comments! |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 9.0.51-1 🚀
|
🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.0.51-4 🚀
|
🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.0.51-4 🚀
|
Details
Presently,
getOptions
excludes the contacts of DM reports included inrecentReports
. These are reduced to 5 recent reports in the participant selection page of "Submit Expense" flow if we pass amaxRecentReportsToShow
tofilterOptions
. Because the contacts of these DM reports are excluded already ingetOptions
, these do not appear in the "Contacts" section. The logic of exclusion of Contacts for reports added in recent reports is moved fromgetOptions
tofilterOptions
to fix this issue.Fixed Issues
$ #48114
PROPOSAL: #48114 (comment)
Tests
[Pre-requisite]: Login an account with more than 5 (say 10 DM) reports.
Test 1:
-- there are 5 recent reports in "Recents" section
-- all contacts of DMs not included in the "Recents" section are included in the "Contacts" section
-- contact of any DM shown in "Recents" section is not shown in "Contacts" section
-- there are 5 recent reports matching with the search term in "Recents" section
-- all contacts (matching with the search term) of DMs not included in the "Recents" section are included in the "Contacts" section
-- contact of any DM report matching with the search term shown in "Recents" section is not shown in "Contacts" section
Test 2:
Test 3:
Test 4:
Offline tests
[Pre-requisite]: Login an account with more than 5 (say 10 DM) reports.
Test 1:
-- there are 5 recent reports in "Recents" section
-- all contacts of DMs not included in the "Recents" section are included in the "Contacts" section
-- contact of any DM shown in "Recents" section is not shown in "Contacts" section
-- there are 5 recent reports matching with the search term in "Recents" section
-- all contacts (matching with the search term) of DMs not included in the "Recents" section are included in the "Contacts" section
-- contact of any DM report matching with the search term shown in "Recents" section is not shown in "Contacts" section
Test 2:
Test 3:
Test 4:
QA Steps
[Pre-requisite]: Login an account with more than 5 (say 10 DM) reports.
Test 1:
-- there are 5 recent reports in "Recents" section
-- all contacts of DMs not included in the "Recents" section are included in the "Contacts" section
-- contact of any DM shown in "Recents" section is not shown in "Contacts" section
-- there are 5 recent reports matching with the search term in "Recents" section
-- all contacts (matching with the search term) of DMs not included in the "Recents" section are included in the "Contacts" section
-- contact of any DM report matching with the search term shown in "Recents" section is not shown in "Contacts" section
Test 2:
Test 3:
Test 4:
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
filterAndroid1.mp4
filterAndroid2.mp4
filterAndroid3.mp4
Android: mWeb Chrome
filterAndroidmWeb.mp4
iOS: Native
filteriOS.mp4
iOS: mWeb Safari
filteriOSmWeb.mp4
MacOS: Chrome / Safari
filterChrome.mp4
MacOS: Desktop
filterDesktop.mp4