Skip to content
Closed
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 @@ -20,6 +20,7 @@ import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import {useReportPaymentContext} from '@hooks/usePaymentContext';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
Expand All @@ -30,12 +31,13 @@ import {syncMissingAttendeesViolation} from '@libs/AttendeeUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {isAttendeeTrackingEnabled} from '@libs/PolicyUtils';
import {getNonHeldAndFullAmount, isInvoiceReport, isOpenExpenseReport, isProcessingReport, isReportPendingDelete} from '@libs/ReportUtils';
import {getSearchReportAvatarProps, hasVisibleViolations} from '@libs/SearchUIUtils';
import {isOnHold, isViolationDismissed, shouldShowViolation, showPendingCardTransactionsBlockModal} from '@libs/TransactionUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {isActionLoadingSelector} from '@src/selectors/ReportMetaData';
import type {Policy, Report} from '@src/types/onyx';
import type {PersonalDetailsList, Policy, Report} from '@src/types/onyx';
import ExpenseReportListItemRow from './ExpenseReportListItemRow';
import type {ExpenseReportListItemProps, ExpenseReportListItemType} from './types';
import useLiveRowCapabilities from './useLiveRowCapabilities';
Expand Down Expand Up @@ -77,7 +79,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
const areAllReportTransactionsSelected =
transactionsWithoutPendingDelete.length > 0 && transactionsWithoutPendingDelete.every((transaction) => selectedTransactions[transaction.keyForList]?.isSelected);
const isSelected = liveRowSelected || areAllReportTransactionsSelected;
const {translate} = useLocalize();
const {translate, formatPhoneNumber} = useLocalize();
const {isLargeScreenWidth} = useResponsiveLayout();
const {currentSearchHash, currentSearchKey} = useSearchQueryContext();
const {currentSearchResults} = useSearchResultsContext();
Expand Down Expand Up @@ -167,8 +169,24 @@ function ExpenseReportListItem<TItem extends ListItem>({
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const {showConfirmModal} = useConfirmModal();
const {showHoldMenu} = useHoldMenuModal();
const {transactions: reportTransactions} = useTransactionsAndViolationsForReport(reportItem.reportID);
const {transactions: reportTransactions, violations: reportViolations} = useTransactionsAndViolationsForReport(reportItem.reportID);
const liveReportTransactions = useMemo(() => Object.values(reportTransactions), [reportTransactions]);

// Recompute the avatar and violations badge from live policy at the row, replacing the screen-level
// `policies` merge that getSections previously did. Policy comes from the live `policyForViolations`
// (parentPolicy ?? snapshot); violations + transactions come from the report's live Onyx data.
const isReportArchived = useReportIsArchived(reportItem.reportID);
const snapshotPersonalDetails = (searchData?.personalDetailsList ?? {}) as PersonalDetailsList;
const liveAvatarProps = getSearchReportAvatarProps(reportForViolations, formatPhoneNumber, snapshotPersonalDetails, policyForViolations, isReportArchived);
const liveReportItemWithAvatar = {...liveReportItem, ...liveAvatarProps};
const liveHasVisibleViolations = hasVisibleViolations(
reportForViolations,
reportViolations,
currentUserDetails.email ?? '',
currentUserDetails.accountID,
liveReportTransactions,
policyForViolations,
);
const {currentUserAccountID, currentUserLogin, introSelected, betas, isSelfTourViewed, activePolicy, nextStep, chatReportPolicy, amountOwed} = useReportPaymentContext({
reportID: reportItem.reportID,
chatReportPolicyID: parentChatReport?.policyID ?? snapshotChatReport?.policyID,
Expand Down Expand Up @@ -301,8 +319,8 @@ function ExpenseReportListItem<TItem extends ListItem>({
// 1. Pre-computed hasVisibleViolations from search data, OR
// 2. Synced missingAttendees violation computed at render time (for stale data)
// We're using || instead of ?? because the variables are boolean
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const hasAnyVisibleViolations = reportItem?.hasVisibleViolations || hasSyncedMissingAttendeesViolation;
const hasAnyVisibleViolations = liveHasVisibleViolations || hasSyncedMissingAttendeesViolation;

const getDescription = useMemo(() => {
if (reportItem?.isRejectedReport) {
Expand Down Expand Up @@ -386,7 +404,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
<View style={[styles.flex1]}>
{!isLargeScreenWidth && (
<UserInfoAndActionButtonRow
item={liveReportItem}
item={liveReportItemWithAvatar}
shouldShowUserInfo={!!reportItem?.from}
stateNum={reportItem.stateNum}
statusNum={reportItem.statusNum}
Expand Down
3 changes: 0 additions & 3 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ function Search({
const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [policyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES);
const {accountID, email, login} = useCurrentUserPersonalDetails();
const selfDMReport = useSelfDMReport();
Expand Down Expand Up @@ -590,7 +589,6 @@ function Search({
const [filteredData1, allLength, hasDeletedTransactionFromSections] = getSections({
type,
data: searchDataWithOptimisticTransaction,
policies,
currentAccountID: accountID,
currentUserEmail: email ?? '',
translate,
Expand Down Expand Up @@ -639,7 +637,6 @@ function Search({
isActionLoadingSet,
cardFeeds,
nonPersonalAndWorkspaceCards,
policies,
bankAccountList,
violations,
customCardNames,
Expand Down
9 changes: 2 additions & 7 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ type TransactionQuarterGroupSorting = ColumnSortMapping<TransactionQuarterGroupL

type GetReportSectionsParams = {
data: OnyxTypes.SearchResults['data'];
policies: OnyxCollection<OnyxTypes.Policy>;
currentSearch: SearchKey;
currentAccountID: number;
currentUserEmail: string;
Expand Down Expand Up @@ -587,7 +586,6 @@ type GetSectionsResult = [
type GetSectionsParams = {
type: SearchDataTypes;
data: OnyxTypes.SearchResults['data'];
policies?: OnyxCollection<OnyxTypes.Policy>;
currentAccountID: number;
currentUserEmail: string;
translate: LocalizedTranslate;
Expand Down Expand Up @@ -2735,7 +2733,6 @@ function getReportActionsSections(
*/
function getReportSections({
data,
policies,
currentSearch,
currentAccountID,
currentUserEmail,
Expand Down Expand Up @@ -2826,8 +2823,7 @@ function getReportSections({
const formattedTo = !shouldShowBlankTo ? formatPhoneNumber(getDisplayNameOrDefault(toDetails)) : '';

const formattedStatus = getReportStatusTranslation({stateNum: reportItem.stateNum, statusNum: reportItem.statusNum, translate});
const policyFromKey = getPolicyFromKey(data, reportItem);
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportItem?.policyID ?? String(CONST.DEFAULT_NUMBER_ID)}`] ?? policyFromKey;
const policy = getPolicyFromKey(data, reportItem);

const shouldShowStatusAsPending = !!isOffline && reportItem?.pendingFields?.nextStep === CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE;

Expand Down Expand Up @@ -3573,7 +3569,6 @@ function getListItem(type: SearchDataTypes, status: SearchStatus, groupBy?: Sear
function getSections({
type,
data,
policies,
currentAccountID,
currentUserEmail,
translate,
Expand Down Expand Up @@ -3608,7 +3603,6 @@ function getSections({
if (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) {
return getReportSections({
data,
policies,
currentSearch,
currentAccountID,
currentUserEmail,
Expand Down Expand Up @@ -6274,6 +6268,7 @@ export {
shouldShowDeleteOption,
getToFieldValueForTransaction,
getSearchReportAvatarProps,
hasVisibleViolations,
isTodoSearch,
getActiveGroupSearchHashes,
getSelectedGroupFilterEntry,
Expand Down