Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function TransactionListItem<TItem extends ListItem>({
onCheckboxPress={handleCheckboxPress}
shouldUseNarrowLayout={!isLargeScreenWidth}
columns={columns}
isActionLoading={isLoading ?? transactionItem.isActionLoading ?? isActionLoading}
isActionLoading={isLoading ?? isActionLoading}
isSelected={!!transactionItem.isSelected}
dateColumnSize={dateColumnSize}
amountColumnSize={amountColumnSize}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function UserInfoAndActionButtonRow({
const participantFromDisplayName = item?.from?.displayName ?? item?.from?.login ?? translate('common.hidden');
const participantToDisplayName = item?.to?.displayName ?? item?.to?.login ?? translate('common.hidden');
const shouldShowToRecipient = hasFromSender && hasToRecipient && !!item?.to?.accountID && !!isCorrectSearchUserName(participantToDisplayName);
const isLoading = 'isActionLoading' in item ? item?.isActionLoading : isActionLoading;
return (
<View
style={[
Expand Down Expand Up @@ -70,7 +69,7 @@ function UserInfoAndActionButtonRow({
action={item.action}
goToItem={handleActionButtonPress}
isSelected={item.isSelected}
isLoading={isLoading}
isLoading={isActionLoading}
policyID={item.policyID}
reportID={item.reportID}
hash={item.hash}
Expand Down
1 change: 1 addition & 0 deletions src/components/SelectionListWithSections/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ type ListItem<K extends string | number = string> = {
};

type TransactionListItemType = ListItem &
// eslint-disable-next-line @typescript-eslint/no-deprecated
SearchTransaction & {
/** Report to which the transaction belongs */
report: Report | undefined;
Expand Down
31 changes: 25 additions & 6 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ function getSuggestedSearchesVisibility(
* Returns a list of properties that are common to every Search ListItem
*/
function getTransactionItemCommonFormattedProperties(
// eslint-disable-next-line @typescript-eslint/no-deprecated
transactionItem: SearchTransaction,
from: OnyxTypes.PersonalDetails,
to: OnyxTypes.PersonalDetails,
Expand Down Expand Up @@ -766,12 +767,14 @@ function isAmountTooLong(amount: number, maxLength = 8): boolean {
return Math.abs(amount).toString().length >= maxLength;
}

// eslint-disable-next-line @typescript-eslint/no-deprecated
function isTransactionAmountTooLong(transactionItem: TransactionListItemType | SearchTransaction | OnyxTypes.Transaction) {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const amount = Math.abs(transactionItem.modifiedAmount || transactionItem.amount);
return isAmountTooLong(amount);
}

// eslint-disable-next-line @typescript-eslint/no-deprecated
function isTransactionTaxAmountTooLong(transactionItem: TransactionListItemType | SearchTransaction | OnyxTypes.Transaction) {
// it won't matter if pass true or false as second argument to getTaxAmount here because isAmountTooLong function uses Math.abs on the returned value of getTaxAmount
const taxAmount = getTaxAmount(transactionItem, false);
Expand All @@ -785,6 +788,7 @@ function getWideAmountIndicators(data: TransactionListItemType[] | TransactionGr
let isAmountWide = false;
let isTaxAmountWide = false;

// eslint-disable-next-line @typescript-eslint/no-deprecated
const processTransaction = (transaction: TransactionListItemType | SearchTransaction) => {
isAmountWide ||= isTransactionAmountTooLong(transaction);
isTaxAmountWide ||= isTransactionTaxAmountTooLong(transaction);
Expand Down Expand Up @@ -908,6 +912,7 @@ function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: Tra

function getTransactionViolations(
allViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>,
// eslint-disable-next-line @typescript-eslint/no-deprecated
transaction: SearchTransaction,
currentUserEmail: string,
): OnyxTypes.TransactionViolation[] {
Expand Down Expand Up @@ -1016,6 +1021,7 @@ function getTransactionsSections(
currentAccountID: number | undefined,
currentUserEmail: string,
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
isActionLoadingSet: ReadonlySet<string> | undefined,
): TransactionListItemType[] {
const shouldShowMerchant = getShouldShowMerchant(data);
const doesDataContainAPastYearTransaction = shouldShowYear(data);
Expand All @@ -1040,7 +1046,9 @@ function getTransactionsSections(
const report = data[`${ONYXKEYS.COLLECTION.REPORT}${transactionItem.reportID}`] as SearchReport | undefined;

let shouldShow = true;
if (queryJSON && !transactionItem.isActionLoading) {

const isActionLoading = isActionLoadingSet?.has(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionItem.reportID}`);
if (queryJSON && !isActionLoading) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ Logic Error (context)

Critical bug: The condition logic was inverted incorrectly. The original code checked if the transaction IS loading (if (queryJSON && !transactionItem.isActionLoading)), meaning it would apply status filtering when the transaction is NOT loading.

The refactored code also checks if (queryJSON && !isActionLoading), but the logic differs from the original in the getReportSections function at line 1543. To maintain consistency with the original behavior:

  • If the original intent was to filter while loading, then line 1543 should be if (queryJSON && isActionLoading)
  • If the original intent was to filter when NOT loading, then line 1543 is wrong

Based on the original getReportSections code checking isActionLoadingSet?.has(...) (meaning IS loading), there's an inconsistency that needs clarification. Please verify the intended behavior across both functions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The original condition checked if not loading and that's still the case with the new logic.

if (queryJSON.type === CONST.SEARCH.DATA_TYPES.EXPENSE) {
const status = queryJSON.status;
if (Array.isArray(status)) {
Expand Down Expand Up @@ -1109,10 +1117,15 @@ function getTransactionsSections(
* Retrieves all transactions associated with a specific report ID from the search data.

*/
// eslint-disable-next-line @typescript-eslint/no-deprecated
function getTransactionsForReport(data: OnyxTypes.SearchResults['data'], reportID: string): SearchTransaction[] {
return Object.entries(data)
.filter(([key, value]) => isTransactionEntry(key) && (value as SearchTransaction)?.reportID === reportID)
.map(([, value]) => value as SearchTransaction);
return (
Object.entries(data)
// eslint-disable-next-line @typescript-eslint/no-deprecated
.filter(([key, value]) => isTransactionEntry(key) && (value as SearchTransaction)?.reportID === reportID)
// eslint-disable-next-line @typescript-eslint/no-deprecated
.map(([, value]) => value as SearchTransaction)
);
}

/**
Expand Down Expand Up @@ -1227,6 +1240,7 @@ function getActions(
}

const allActions: SearchTransactionAction[] = [];
// eslint-disable-next-line @typescript-eslint/no-deprecated
let allReportTransactions: SearchTransaction[];
if (isReportEntry(key)) {
allReportTransactions = getTransactionsForReport(data, report.reportID);
Expand Down Expand Up @@ -1497,7 +1511,9 @@ function getReportSections(
const actions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportItem.reportID}`];

let shouldShow = true;
if (queryJSON && isActionLoadingSet?.has(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportItem.reportID}`)) {

const isActionLoading = isActionLoadingSet?.has(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportItem.reportID}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ Logic Error (context)

Critical bug: The condition logic was inverted incorrectly. The original code checked if the report IS loading:

if (queryJSON && isActionLoadingSet?.has(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportItem.reportID}`))

But the refactored code checks if it's NOT loading:

if (queryJSON && !isActionLoading)

This reverses the intended behavior and will cause reports to be hidden when they're loading, and shown when they shouldn't be filtered.

Fix: Change line 1543 from:

if (queryJSON && !isActionLoading) {

to:

if (queryJSON && isActionLoading) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The original logic actually checked if not loading. It was changed here but I think it was a mistake cc @DylanDylann

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for update 🙏

if (queryJSON && !isActionLoading) {
if (queryJSON.type === CONST.SEARCH.DATA_TYPES.EXPENSE) {
const status = queryJSON.status;

Expand Down Expand Up @@ -1749,7 +1765,7 @@ function getSections({
}
}

return getTransactionsSections(data, currentSearch, currentAccountID, currentUserEmail, formatPhoneNumber);
return getTransactionsSections(data, currentSearch, currentAccountID, currentUserEmail, formatPhoneNumber, isActionLoadingSet);
}

/**
Expand Down Expand Up @@ -1925,6 +1941,7 @@ function isSearchResultsEmpty(searchResults: SearchResults, groupBy?: SearchGrou
return !Object.keys(searchResults?.data).some(
(key) =>
key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION) &&
// eslint-disable-next-line @typescript-eslint/no-deprecated
(searchResults?.data[key as keyof typeof searchResults.data] as SearchTransaction)?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
);
}
Expand Down Expand Up @@ -2432,6 +2449,7 @@ function getColumnsToShow(
};

const {moneyRequestReportActionsByTransactionID} = Array.isArray(data) ? {} : createReportActionsLookupMaps(data);
// eslint-disable-next-line @typescript-eslint/no-deprecated
const updateColumns = (transaction: OnyxTypes.Transaction | SearchTransaction) => {
const merchant = transaction.modifiedMerchant ? transaction.modifiedMerchant : (transaction.merchant ?? '');
if ((merchant !== '' && merchant !== CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT) || isScanning(transaction)) {
Expand Down Expand Up @@ -2470,6 +2488,7 @@ function getColumnsToShow(
columns[CONST.REPORT.TRANSACTION_LIST.COLUMNS.FROM] = true;
}

// eslint-disable-next-line @typescript-eslint/no-deprecated
const toFieldValue = getToFieldValueForTransaction(transaction as SearchTransaction, report, data.personalDetailsList, reportAction);
if (toFieldValue.accountID && toFieldValue.accountID !== currentAccountID && !columns[CONST.REPORT.TRANSACTION_LIST.COLUMNS.TO]) {
columns[CONST.REPORT.TRANSACTION_LIST.COLUMNS.TO] = !!report && !isOpenReport(report);
Expand Down
Loading
Loading