-
Notifications
You must be signed in to change notification settings - Fork 3k
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
ignore periods on search #8375
ignore periods on search #8375
Conversation
At this point we still have the edge case @Santhosh-Sellavel said on #8007 (comment) I think we could do: ((recentReportOptions.length === 0 && personalDetailsOptions.length === 0) || && _.every(selectedOptions, option => option.login !== searchValue) here: App/src/libs/OptionsListUtils.js Lines 577 to 585 in 6a3759b
What do you think @Santhosh-Sellavel? |
src/libs/OptionsListUtils.js
Outdated
searchTerms.push(personalDetail.login); | ||
searchTerms.push(personalDetail.login.replace(/\./g, '')); |
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.
Do we need both 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.
I think we won't need line 177 anymore
No bad idea. It would produce incorrect results. |
@mateusbra && ((recentReportOptions.length + personalDetailsOptions.length) === 0 || _.contains(searchValue, '.')) && ((recentReportOptions.length + personalDetailsOptions.length) === 0
|| (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue.toLowerCase()))) cc: @stitesExpensify |
@Santhosh-Sellavel do you think there's something we have to change in addition? |
src/libs/OptionsListUtils.js
Outdated
&& recentReportOptions.length === 0 | ||
&& personalDetailsOptions.length === 0 | ||
&& ((recentReportOptions.length + personalDetailsOptions.length) === 0 | ||
|| (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue.toLowerCase()))) |
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.
thought: It might help readability if we just extract this whole if block to a method like canAddUserToInvite()
? It looks pretty crazy and we are duplicating some logic for the login options.
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 have this feeling too.
What do you think of changing the if block to:
if (canAddUserToInvite(searchValue,recentReportOptions,personalDetailsOptions,loginOptionsToExclude,selectedOptions,loginOptionsToExclude))
adding the method:
function canAddUserToInvite(searchValue,recentReportOptions,personalDetailsOptions,loginOptionsToExclude,selectedOptions){
const canAddUserToInvite = searchValue && ((recentReportOptions.length + personalDetailsOptions.length) === 0
|| (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue.toLowerCase())))
&& !isCurrentUser({login: searchValue})
&& _.every(selectedOptions, option => option.login !== searchValue)
&& ((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue)) || Str.isValidPhone(searchValue))
&& (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue.toLowerCase()))
return canAddUserToInvite;
}
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.
we are duplicating some logic for the login options.
Yes
thinking A = (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue.toLowerCase()))
and B = (recentReportOptions.length + personalDetailsOptions.length) === 0
We have A && (A || B), its a redundant logic, we could change to A.
A && (A || B) = A , so we could discard the B logic keeping the same behavior:
function canAddUserToInvite(searchValue,loginOptionsToExclude,selectedOptions){
const canAddUserToInvite = searchValue
&& !isCurrentUser({login: searchValue})
&& _.every(selectedOptions, option => option.login !== searchValue)
&& ((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue)) || Str.isValidPhone(searchValue))
&& (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue.toLowerCase()))
return canAddUserToInvite;
}
let me know what you guys think before I push some changes to it
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.
Yeah that's a lot of variables for a method, but cleaning it up would be an improvement. We could also maybe making it less of a giant ternary that is hard to make sense out of and use extra variables and if statements (but let's pause that for a second).
As for the redundancy, I agree with the assessment that B
would be unneeded - but is the proposal to remove the code to check for available options? Why was the change added in the first place?
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.
this change was added in order to prevent this edge case @Santhosh-Sellavel found on #8007 (comment) , so we needed to show user to invite even when it doesn't found a result from search(when lenghts == 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.
@marcaaron nice one! may I commit all thoses changes?
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.
Yep!
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.
Sorry, @marcaaron for the confusion.
You are right,
looking at
loginOptionsToExclude
doesn’t make sense.
The confusion originated from my suggestions here. #8375 (comment) those were two quick suggestions.
But we would really avoided this conversation if @mateusbra went with first suggestion, because this occurs only when search has dot.
&& ((recentReportOptions.length + personalDetailsOptions.length) === 0 || _.contains(searchValue, '.'))
But this is the better & simpler solution, unfortunately we both missed to foresee
!_.find(personalDetailsOptions.concat(recentReportOptions), option => option.login === searchValue.toLowerCase());
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.
Sorry @Santhosh-Sellavel I thought the second sugestion you proposed was better 😅, but now I think the misunderstoods were solved.
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 commited the changes, if you think its better to use the first suggestion from #8375 (comment) please tell me.
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.
Need to add tests for this new case in OptionsListUtilsTest.js
Working on it |
|
||
// Then we expect to have the personal detail with period filtered | ||
expect(results.recentReports.length).toBe(1); | ||
expect(results.recentReports[0].text).toBe('The Flash'); |
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.
Can we add a test for the userToInvite case we are discussing above?
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.
Yes
I added the tests and commited the changes guys! Take a look when you can. cc: @marcaaron |
PR Reviewer Checklist
|
Everything looks good, testing steps can include an example of search terms & results. |
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 to me, tests well.
@stitesExpensify Will leave it you!
Thanks for the input everyone! Looking now |
✋ 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 @stitesExpensify in version: 1.1.56-0 🚀
|
🚀 Deployed to production by @francoisl in version: 1.1.56-0 🚀
|
Details
Ignore periods on searching reports
Fixed Issues
$ #8007
Tests
PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)PR Reviewer Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followed/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
Screenshots
Web
Mobile Web
Desktop
iOS
Android