-
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
Use new Search query syntax when calling api #46481
Merged
luacmartins
merged 8 commits into
Expensify:main
from
software-mansion-labs:kicu/45026-query-in-api
Aug 1, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
66834ca
send JSON ast query to Search api
Kicu 9e2ac8f
Correctly pass offset param when calling search api
Kicu ead7ea9
Merge branch 'main' into kicu/45026-query-in-api
Kicu 3ba594e
Fix missing filter query params when sorting search results
Kicu b92ecb0
Fix TS errors in Search
Kicu 5dca4d7
Merge branch 'main' into kicu/45026-query-in-api
Kicu f7b1cdd
Fix effects in Search after merge conflicts
Kicu 3d23bb2
Fix not sending policyIDs in search
Kicu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,14 @@ import ROUTES from '@src/ROUTES'; | |
import type SearchResults from '@src/types/onyx/SearchResults'; | ||
import {useSearchContext} from './SearchContext'; | ||
import SearchPageHeader from './SearchPageHeader'; | ||
import type {SearchColumnType, SearchQueryJSON, SearchStatus, SelectedTransactionInfo, SelectedTransactions, SortOrder} from './types'; | ||
import type {SearchColumnType, SearchQueryJSON, SelectedTransactionInfo, SelectedTransactions, SortOrder} from './types'; | ||
|
||
type SearchProps = { | ||
queryJSON: SearchQueryJSON; | ||
policyIDs?: string; | ||
isCustomQuery: boolean; | ||
policyIDs?: string; | ||
}; | ||
|
||
const sortableSearchTabs: SearchStatus[] = [CONST.SEARCH.STATUS.ALL]; | ||
const transactionItemMobileHeight = 100; | ||
const reportItemTransactionHeight = 52; | ||
const listItemPadding = 12; // this is equivalent to 'mb3' on every transaction/report list item | ||
|
@@ -49,7 +48,7 @@ function mapTransactionItemToSelectedEntry(item: TransactionListItemType): [stri | |
} | ||
|
||
function mapToTransactionItemWithSelectionInfo(item: TransactionListItemType, selectedTransactions: SelectedTransactions) { | ||
return {...item, isSelected: !!selectedTransactions[item.keyForList]?.isSelected}; | ||
return {...item, isSelected: selectedTransactions[item.keyForList]?.isSelected}; | ||
} | ||
|
||
function mapToItemWithSelectionInfo(item: TransactionListItemType | ReportListItemType, selectedTransactions: SelectedTransactions) { | ||
|
@@ -58,7 +57,7 @@ function mapToItemWithSelectionInfo(item: TransactionListItemType | ReportListIt | |
: { | ||
...item, | ||
transactions: item.transactions?.map((transaction) => mapToTransactionItemWithSelectionInfo(transaction, selectedTransactions)), | ||
isSelected: item.transactions.every((transaction) => !!selectedTransactions[transaction.keyForList]?.isSelected), | ||
isSelected: item.transactions.every((transaction) => selectedTransactions[transaction.keyForList]?.isSelected), | ||
}; | ||
} | ||
|
||
|
@@ -87,19 +86,14 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { | |
const [selectedTransactionsToDelete, setSelectedTransactionsToDelete] = useState<string[]>([]); | ||
const [deleteExpensesConfirmModalVisible, setDeleteExpensesConfirmModalVisible] = useState(false); | ||
const [downloadErrorModalVisible, setDownloadErrorModalVisible] = useState(false); | ||
const {status, sortBy, sortOrder, hash} = queryJSON; | ||
const {sortBy, sortOrder, hash} = queryJSON; | ||
|
||
const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`); | ||
|
||
useEffect(() => { | ||
if (isSmallScreenWidth) { | ||
return; | ||
} | ||
clearSelectedTransactions(hash); | ||
setCurrentSearchHash(hash); | ||
|
||
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps | ||
}, [hash]); | ||
}, [hash, clearSelectedTransactions, setCurrentSearchHash]); | ||
|
||
useEffect(() => { | ||
const selectedKeys = Object.keys(selectedTransactions).filter((key) => selectedTransactions[key]); | ||
|
@@ -114,6 +108,15 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { | |
} | ||
}, [isSmallScreenWidth, selectedTransactions, selectionMode?.isEnabled]); | ||
|
||
useEffect(() => { | ||
if (isOffline) { | ||
return; | ||
} | ||
|
||
SearchActions.search({queryJSON, offset, policyIDs}); | ||
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps | ||
}, [isOffline, offset, queryJSON]); | ||
|
||
const handleOnCancelConfirmModal = () => { | ||
setSelectedTransactionsToDelete([]); | ||
setDeleteExpensesConfirmModalVisible(false); | ||
|
@@ -134,19 +137,6 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { | |
setDeleteExpensesConfirmModalVisible(true); | ||
}; | ||
|
||
useEffect(() => { | ||
const selectedKeys = Object.keys(selectedTransactions).filter((key) => selectedTransactions[key]); | ||
if (!isSmallScreenWidth) { | ||
if (selectedKeys.length === 0) { | ||
turnOffMobileSelectionMode(); | ||
} | ||
return; | ||
} | ||
if (selectedKeys.length > 0 && !selectionMode?.isEnabled) { | ||
turnOnMobileSelectionMode(); | ||
} | ||
}, [isSmallScreenWidth, selectedTransactions, selectionMode?.isEnabled]); | ||
|
||
const getItemHeight = useCallback( | ||
(item: TransactionListItemType | ReportListItemType) => { | ||
if (SearchUtils.isTransactionListItemType(item)) { | ||
|
@@ -183,15 +173,6 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { | |
|
||
const searchResults = currentSearchResults?.data ? currentSearchResults : lastSearchResultsRef.current; | ||
|
||
useEffect(() => { | ||
if (isOffline) { | ||
return; | ||
} | ||
|
||
SearchActions.search({hash, query: status, policyIDs, offset, sortBy, sortOrder}); | ||
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps | ||
}, [hash, isOffline, offset]); | ||
|
||
const isDataLoaded = searchResults?.data !== undefined; | ||
const shouldShowLoadingState = !isOffline && !isDataLoaded; | ||
const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; | ||
|
@@ -306,15 +287,10 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { | |
}; | ||
|
||
const onSortPress = (column: SearchColumnType, order: SortOrder) => { | ||
const currentSearchParams = SearchUtils.getCurrentSearchParams(); | ||
const currentQueryJSON = SearchUtils.buildSearchQueryJSON(currentSearchParams.q, policyIDs); | ||
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. Note: I removed this because it was super redundant. We already have the parsed |
||
|
||
const newQuery = SearchUtils.buildSearchQueryString({...currentQueryJSON, sortBy: column, sortOrder: order}); | ||
const newQuery = SearchUtils.buildSearchQueryString({...queryJSON, sortBy: column, sortOrder: order}); | ||
navigation.setParams({q: newQuery}); | ||
}; | ||
|
||
const isSortingAllowed = sortableSearchTabs.includes(status); | ||
|
||
const shouldShowYear = SearchUtils.shouldShowYear(searchResults?.data); | ||
|
||
const canSelectMultiple = isSmallScreenWidth ? selectionMode?.isEnabled : true; | ||
|
@@ -344,7 +320,6 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { | |
metadata={searchResults?.search} | ||
onSortPress={onSortPress} | ||
sortOrder={sortOrder} | ||
isSortingAllowed={isSortingAllowed} | ||
sortBy={sortBy} | ||
shouldShowYear={shouldShowYear} | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import type {SortOrder} from '@components/Search/types'; | ||
import type {SearchQueryString} from '@components/Search/types'; | ||
|
||
type SearchParams = { | ||
hash: number; | ||
query: string; | ||
jsonQuery: SearchQueryString; | ||
// Tod this is temporary, remove top level policyIDs as part of: https://github.com/Expensify/App/issues/46592 | ||
policyIDs?: string; | ||
sortBy?: string; | ||
sortOrder?: SortOrder; | ||
offset: number; | ||
}; | ||
|
||
export default SearchParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 was a duplicate of useEffect in line 96 - probably someone made a mistake when refactoring