-
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
Changes from 10 commits
12bfe36
3aecfd0
4a61a45
56cdff8
bf869b2
2093e69
3fd262d
8782a51
0687b54
f61b280
6dc170c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||
import cloneDeep from 'lodash/cloneDeep'; | ||||||
import type {OnyxCollection} from 'react-native-onyx'; | ||||||
import type {ValueOf} from 'type-fest'; | ||||||
import type {ASTNode, QueryFilter, QueryFilters, SearchColumnType, SearchQueryJSON, SearchQueryString, SearchStatus, SortOrder} from '@components/Search/types'; | ||||||
import type {AdvancedFiltersKeys, ASTNode, QueryFilter, QueryFilters, SearchColumnType, SearchQueryJSON, SearchQueryString, SearchStatus, SortOrder} from '@components/Search/types'; | ||||||
import ChatListItem from '@components/SelectionList/ChatListItem'; | ||||||
import ReportListItem from '@components/SelectionList/Search/ReportListItem'; | ||||||
import TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; | ||||||
|
@@ -406,8 +406,30 @@ function isSearchResultsEmpty(searchResults: SearchResults) { | |||||
return !Object.keys(searchResults?.data).some((key) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)); | ||||||
} | ||||||
|
||||||
function getQueryHashFromString(query: SearchQueryString): number { | ||||||
return UserUtils.hashText(query, 2 ** 32); | ||||||
function getQueryHash(query: SearchQueryJSON): number { | ||||||
let orderedQuery = ''; | ||||||
if (query.policyID) { | ||||||
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID}:${query.policyID} `; | ||||||
} | ||||||
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}`; | ||||||
|
||||||
Object.keys(query.flatFilters) | ||||||
.sort() | ||||||
.forEach((key) => { | ||||||
const filterValues = query.flatFilters?.[key as AdvancedFiltersKeys]; | ||||||
const sortedFilterValues = filterValues?.sort((queryFilter1, queryFilter2) => { | ||||||
if (queryFilter1.value > queryFilter2.value) { | ||||||
return 1; | ||||||
} | ||||||
return -1; | ||||||
}); | ||||||
orderedQuery += `${buildFilterString(key, sortedFilterValues ?? [])}`; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB
Suggested change
|
||||||
}); | ||||||
|
||||||
return UserUtils.hashText(orderedQuery, 2 ** 32); | ||||||
} | ||||||
|
||||||
function getExpenseTypeTranslationKey(expenseType: ValueOf<typeof CONST.SEARCH.TRANSACTION_TYPE>): TranslationPaths { | ||||||
|
@@ -545,8 +567,8 @@ function buildSearchQueryJSON(query: SearchQueryString) { | |||||
|
||||||
// Add the full input and hash to the results | ||||||
result.inputQuery = query; | ||||||
result.hash = getQueryHashFromString(query); | ||||||
result.flatFilters = flatFilters; | ||||||
result.hash = getQueryHash(result); | ||||||
return result; | ||||||
} catch (e) { | ||||||
console.error(`Error when parsing SearchQuery: "${query}"`, e); | ||||||
|
@@ -592,6 +614,9 @@ function buildQueryStringFromFilterFormValues(filterValues: Partial<SearchAdvanc | |||||
const {type, status, policyID, ...otherFilters} = filterValues; | ||||||
const filtersString: string[] = []; | ||||||
|
||||||
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}`); | ||||||
Comment on lines
+617
to
+618
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will cause the saved query name to include Screen.Recording.2024-10-18.at.11.06.40.AM.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know why the saved query name includes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. However, we are not including Also, please see this comment: #50921 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
|
||||||
if (type) { | ||||||
const sanitizedType = sanitizeString(type); | ||||||
filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${sanitizedType}`); | ||||||
|
@@ -652,7 +677,6 @@ function buildQueryStringFromFilterFormValues(filterValues: Partial<SearchAdvanc | |||||
|
||||||
const amountFilter = buildAmountFilterQuery(filterValues); | ||||||
filtersString.push(amountFilter); | ||||||
|
||||||
return filtersString.join(' ').trim(); | ||||||
} | ||||||
|
||||||
|
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 thesearchOptions
(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.