-
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
Search router polish #50921
Search router polish #50921
Conversation
…earching from searchRouter
FYI I'll prepare videos as first thing in the morning |
Actually managed to do this today @luacmartins 😄 Maybe we'll manage to merge it today, if @rayane-djouah is still up. |
Is the PR ready for review? |
@rayane-djouah 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] |
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.
Found some small tweaks, please take a look
if (currentSearchOptions.userToInvite) { | ||
reports.push(currentSearchOptions.userToInvite); | ||
if (debouncedInputValue === '') { | ||
return searchOptions.recentReports.slice(0, 10); |
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'm curious if that doesn't change previous logic.
Originally we had debouncedInputValue === '' ? searchOptions
- so it meant that if the input is empty, we push in the searchOptions
(so I guess contextual search?).
But now we only show recent reports? Is that the change we want?
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.
Contextual search is added independently earlier in the code. This block of code was only responsible for adding recent chats section(which consisted of recentReports, personalDetails and userToInvite). Right now in case when text input is empty, we are limiting the recent chats section to only recentReports.
src/libs/SearchUtils.ts
Outdated
orderedQuery += `type ${query.type} `; | ||
orderedQuery += ` status ${query.status}`; | ||
orderedQuery += ` sortBy ${query.sortBy} `; | ||
orderedQuery += ` sortOrder ${query.sortOrder} `; |
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.
please use consts here, eg. SYNTAX_ROOT_KEYS.TYPE
etc
src/libs/SearchUtils.ts
Outdated
@@ -541,12 +567,13 @@ function getFilters(queryJSON: SearchQueryJSON) { | |||
function buildSearchQueryJSON(query: SearchQueryString) { | |||
try { | |||
const result = searchParser.parse(query) as SearchQueryJSON; | |||
// console.log('%%%%%\n', 'result', result); |
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.
remove this :)
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.
Haste makes waste 😄
Reviewer Checklist
Screenshots/VideosAndroid: NativeScreen.Recording.2024-10-18.at.7.06.01.PM.movAndroid: mWeb ChromeScreen.Recording.2024-10-18.at.7.08.00.PM.moviOS: NativeSimulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-10-18.at.19.02.57.mp4iOS: mWeb SafariSimulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-10-18.at.19.04.54.mp4 |
src/libs/SearchUtils.ts
Outdated
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}: ${query.sortBy} `; | ||
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_ORDER}: ${query.sortOrder} `; |
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.
Shouldn't we exclude contextual filters (sortBy, sortOrder, policyID) when we calculate the query hash?
EDIT: I think that including them is necessary here, but I suggested a solution for related issues here: #50921 (comment)
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 this will cause duplicate recent searches 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.
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 is reproducible also on main. I think we can fix it in a separate PR
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 a potential solution is to create two hashes for the query: one that includes sortBy
, sortOrder
, and policyID
, and one that does not.
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.
Hmm I think this should be fixed on BE, because recentSearches are generated on BE. In case when we are searching for some query twice, then it should be renewed in history and not duplicated.
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 also gave one argument for having sortOrder etc. here #50921 (comment).
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.
WDYT @rayane-djouah
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.
@SzymczakJ The duplication of the query isn't due to it being searched twice, but because the queries differ in sortBy
, sortOrder
, or policyID
. For instance, in this case: #51044 (comment), there are two queries: one with sortBy
and sortOrder
, and another without these filters, resulting in different hashes. I agree that we should always include these filters when sending the query to the backend and when calculating the hash. However, we need to filter out duplicate queries in saved searches and recent searches that differ only by sortBy
, sortOrder
, or policyID
. This can be achieved by computing a secondary hash that excludes these filters, and using this secondary hash to determine whether to display or exclude the query in saved and recent searches and whether to highlight the saved search item.
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 have a separate issue for this, so let's treat it as NAB for this PR and keep the discussion in that issue.
src/libs/SearchUtils.ts
Outdated
if (query.policyID) { | ||
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID} ${query.policyID} `; | ||
} |
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.
Same here
filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}:${CONST.SEARCH.TABLE_COLUMNS.DATE}`); | ||
filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_ORDER}:${CONST.SEARCH.SORT_ORDER.DESC}`); |
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 will cause the saved query name to include sortBy
and sortOrder
, and the highlight on the saved search item will be lost when we change the sort order.
Screen.Recording.2024-10-18.at.11.06.40.AM.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.
The highlight on the saved search item will be lost when we change the sort order
bug is reproducible on main and can be fixed in a separate PR. But the saved query name include sortBy and sortOrder
bug is specific to this PR
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 you know why the saved query name includes sortBy
and sortOrder
but not policyID
?
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.
highlight on the saved search item will be lost when we change the sort order
I tend to lean toward idea that this is not a bug. For me searches differing only with sortBy or sortOrder are two different queries. Reason:
- There might be a user which has about 1000 expenses with category 'Advertising'
- When he queries for category 'Advertising' he will get a paginated result with only 50 of newest expenses
- When we will change sortOrder then he will get 50 oldest expenses. These two queries are giving us different responses
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.
Good point. However, we are not including sortBy
, sortOrder
, and policyID
in the displayed query (in the header input and recent searches) because we want users to rely on the contextual filters rather than manually typing these parameters. Therefore, it doesn't make sense to include them in the saved search item name.
Also, please see this comment: #50921 (comment)
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 agree that those are different queries. We should treat these params the same way we do with status, since to @rayane-djouah's point, we use the contextual filters to change these values instead of manually typing them in.
src/libs/SearchUtils.ts
Outdated
function getQueryHash(query: SearchQueryJSON): number { | ||
let orderedQuery = ''; | ||
if (query.policyID) { | ||
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID} ${query.policyID} `; |
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.
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID} ${query.policyID} `; | |
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID}:${query.policyID}`; |
src/libs/SearchUtils.ts
Outdated
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}: ${query.type} `; | ||
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS}: ${query.status}`; | ||
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}: ${query.sortBy} `; | ||
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_ORDER}: ${query.sortOrder} `; |
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.
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}: ${query.type} `; | |
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS}: ${query.status}`; | |
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}: ${query.sortBy} `; | |
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_ORDER}: ${query.sortOrder} `; | |
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${query.type}`; | |
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS}:${query.status}`; | |
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}:${query.sortBy}`; | |
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_ORDER}:${query.sortOrder}`; |
src/libs/SearchUtils.ts
Outdated
orderedQuery += ` ${key}:`; | ||
filterValues | ||
?.sort((queryFilter1, queryFilter2) => { | ||
if (queryFilter1.value > queryFilter2.value) { | ||
return 1; | ||
} | ||
return -1; | ||
}) | ||
?.forEach((queryFilter) => { | ||
orderedQuery += ` ${queryFilter.operator} ${queryFilter.value}`; | ||
}); |
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.
orderedQuery += ` ${key}:`; | |
filterValues | |
?.sort((queryFilter1, queryFilter2) => { | |
if (queryFilter1.value > queryFilter2.value) { | |
return 1; | |
} | |
return -1; | |
}) | |
?.forEach((queryFilter) => { | |
orderedQuery += ` ${queryFilter.operator} ${queryFilter.value}`; | |
}); | |
const sortedFilterValues = filterValues | |
?.sort((queryFilter1, queryFilter2) => { | |
if (queryFilter1.value > queryFilter2.value) { | |
return 1; | |
} | |
return -1; | |
}); | |
orderedQuery += ` ${SearchUtils.buildFilterString(key, sortedFilterValues)}`; |
src/libs/SearchUtils.ts
Outdated
} | ||
return -1; | ||
}); | ||
orderedQuery += `${buildFilterString(key, sortedFilterValues ?? [])}`; |
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.
NAB
orderedQuery += `${buildFilterString(key, sortedFilterValues ?? [])}`; | |
orderedQuery += ` ${buildFilterString(key, sortedFilterValues ?? [])}`; |
@luacmartins What do you think about #50921 (comment) and #50921 (comment)? |
I left comments on both of those threads. I think we can handle both of those cases as part of #51044 since they'd likely have the same or similar solutions. |
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 have a few pending comments to resolve
Just resolved them @luacmartins |
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 and tests well. @luacmartins all yours!
🚀 Deployed to staging by https://github.com/luacmartins 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
This PR fixes following issues:
Fixed Issues
$ #50250
$ #50977
$ #50993
$ #50998
PROPOSAL:
Tests
Offline tests
QA Steps
Same as tests
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
android.mov
Android: mWeb Chrome
android.web.mov
iOS: Native
ios.mov
iOS: mWeb Safari
iosweb.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov