Skip to content
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

Updated selected transaction If getting new updates #49829

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,34 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0;
const isSearchResultsEmpty = !searchResults?.data || SearchUtils.isSearchResultsEmpty(searchResults);
const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty);
const data = searchResults === undefined ? [] : SearchUtils.getSections(type, status, searchResults.data, searchResults.search);

useEffect(() => {
/** We only want to display the skeleton for the status filters the first time we load them for a specific data type */
setShouldShowStatusBarLoading(shouldShowLoadingState && searchResults?.search?.type !== type);
}, [searchResults?.search?.type, setShouldShowStatusBarLoading, shouldShowLoadingState, type]);

useEffect(() => {
const newTransactionList: SelectedTransactions = {};
data.forEach((report) => {
const transactionsData: TransactionListItemType[] = Object.hasOwn(report, 'transactions') && 'transactions' in report ? report.transactions : [];
transactionsData.forEach((transaction) => {
if (!Object.keys(selectedTransactions).includes(transaction.transactionID)) {
return;
}
newTransactionList[transaction.transactionID] = {
action: transaction.action,
canHold: transaction.canHold,
canUnhold: transaction.canUnhold,
isSelected: selectedTransactions[transaction.transactionID].isSelected,
canDelete: transaction.canDelete,
};
});
});
setSelectedTransactions(newTransactionList, data);
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [data, setSelectedTransactions]);
Copy link
Contributor

@ishpaul777 ishpaul777 Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{BZ CHECKLIST} This Caused this regression #49829, Here we only handle the cases where report data was returned but SearchUtils.getSections returns three types of data depending on the condition:

App/src/libs/SearchUtils.ts

Lines 320 to 328 in d03066f

function getSections(type: SearchDataTypes, status: SearchStatus, data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']) {
if (type === CONST.SEARCH.DATA_TYPES.CHAT) {
return getReportActionsSections(data);
}
if (status === CONST.SEARCH.STATUS.EXPENSE.ALL) {
return getTransactionsSections(data, metadata);
}
return getReportSections(data, metadata);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the link above correct? It's a reference to this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! Sorry this one #50286


useEffect(() => {
if (!isSearchResultsEmpty || prevIsSearchResultEmpty) {
return;
Expand All @@ -208,7 +230,6 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
}

const ListItem = SearchUtils.getListItem(type, status);
const data = SearchUtils.getSections(type, status, searchResults.data, searchResults.search);
const sortedData = SearchUtils.getSortedSections(type, status, data, sortBy, sortOrder);
const sortedSelectedData = sortedData.map((item) => {
const baseKey = `${ONYXKEYS.COLLECTION.TRANSACTION}${(item as TransactionListItemType).transactionID}`;
Expand Down
Loading