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 @@ -376,12 +376,12 @@ function MoneyRequestReportTransactionList({
const ids = new Set<string>();
for (const transaction of transactions) {
const violations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`] ?? [];
if (transactionHasRBR(transaction, violations, login, accountID, report, policy, reportActionsMap, actionErrors)) {
if (transactionHasRBR(transaction, violations, login, accountID, report, ownerLogin, policy, reportActionsMap, actionErrors)) {
ids.add(transaction.transactionID);
}
}
return ids;
}, [isDefaultSort, allTransactionViolations, currentUserDetails?.login, currentUserDetails?.accountID, transactions, report, policy, reportActionsMap]);
}, [isDefaultSort, allTransactionViolations, currentUserDetails?.login, currentUserDetails?.accountID, transactions, report, ownerLogin, policy, reportActionsMap]);

const sortedTransactions: TransactionWithOptionalHighlight[] = useMemo(() => {
return [...transactions].sort((a, b) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import Text from '@components/Text';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useIsFocusedRef from '@hooks/useIsFocusedRef';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';

import shouldAdjustScroll from '@libs/shouldAdjustScroll';
import {compareByRBR} from '@libs/TransactionPreviewUtils';
import {getCreated} from '@libs/TransactionUtils';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails';
import type {Policy, Report, Transaction} from '@src/types/onyx';

import type {FlashListRef, ListRenderItem, ListRenderItemInfo} from '@shopify/flash-list';
Expand Down Expand Up @@ -75,22 +78,32 @@ function useReportPreviewCarousel({
const styles = useThemeStyles();
const {translate, localeCompare} = useLocalize();
const currentUserDetails = useCurrentUserPersonalDetails();
const [ownerLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(iouReport?.ownerAccountID)});
const isFocusedRef = useIsFocusedRef();

const carouselTransactions = useMemo(() => {
if (shouldShowAccessPlaceHolder) {
return [];
}
const sorted = [...transactions].sort((a, b) => {
const rbrComparison = compareByRBR(a, b, transactionViolations, currentUserDetails?.login ?? '', currentUserDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID, iouReport, policy);
const rbrComparison = compareByRBR(
a,
b,
transactionViolations,
currentUserDetails?.login ?? '',
currentUserDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
iouReport,
ownerLogin,
policy,
);
if (rbrComparison !== 0) {
return rbrComparison;
}
// Tiebreak by date (ascending — oldest first) so position is stable across RBR state changes
return localeCompare(getCreated(a), getCreated(b));
});
return sorted.slice(0, MAX_PREVIEWS_NUMBER + 1);
}, [shouldShowAccessPlaceHolder, transactions, transactionViolations, currentUserDetails?.login, currentUserDetails?.accountID, iouReport, policy, localeCompare]);
}, [shouldShowAccessPlaceHolder, transactions, transactionViolations, currentUserDetails?.login, currentUserDetails?.accountID, iouReport, ownerLogin, policy, localeCompare]);
const prevCarouselTransactionLength = useRef(0);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {getDecodedLeafCategoryName} from '@libs/CategoryUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {calculateAmount} from '@libs/IOUUtils';
import Parser from '@libs/Parser';
import {getLoginByAccountID} from '@libs/PersonalDetailsUtils';
import {getCommaSeparatedTagNameWithSanitizedColons} from '@libs/PolicyUtils';
import {getThumbnailAndImageURIs} from '@libs/ReceiptUtils';
import {getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils';
Expand Down Expand Up @@ -93,6 +94,7 @@ function TransactionPreviewContent({
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {selector: getStableReportSelector});
const managerID = report?.managerID ?? reportPreviewAction?.childManagerAccountID ?? CONST.DEFAULT_NUMBER_ID;
const ownerAccountID = report?.ownerAccountID ?? reportPreviewAction?.childOwnerAccountID ?? CONST.DEFAULT_NUMBER_ID;
const ownerLogin = getLoginByAccountID(ownerAccountID, personalDetails);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(report?.reportID)}`);
const isChatReportArchived = useReportIsArchived(chatReport?.reportID);
const currentUserDetails = useCurrentUserPersonalDetails();
Expand All @@ -102,14 +104,15 @@ function TransactionPreviewContent({
const transactionPreviewCommonArguments = useMemo(
() => ({
iouReport: report,
iouReportOwnerLogin: ownerLogin,
policy,
transaction,
action,
isBillSplit,
violations,
transactionDetails,
}),
[action, report, policy, isBillSplit, transaction, transactionDetails, violations],
[action, report, ownerLogin, policy, isBillSplit, transaction, transactionDetails, violations],
);

const conditionals = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function ExpenseReportListItemInner<TItem extends ListItem>({
return reportItem?.transactions?.some((transaction) => {
const relevantViolations = (transaction.violations ?? []).filter(
(violation) =>
!isViolationDismissed(transaction, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, reportForViolations, policyForViolations, submitterLogin) &&
!isViolationDismissed(transaction, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, reportForViolations, submitterLogin, policyForViolations) &&
shouldShowViolation(reportForViolations, policyForViolations, violation.name, currentUserDetails.email ?? '', false, transaction),
);

Expand Down Expand Up @@ -225,6 +225,7 @@ function ExpenseReportListItemInner<TItem extends ListItem>({
// (parentPolicy ?? snapshot); violations + transactions come from the report's live Onyx data.
const liveHasVisibleViolations = hasVisibleViolations(
reportForViolations,
submitterLogin,
reportViolations,
currentUserDetails.email ?? '',
currentUserDetails.accountID,
Expand Down Expand Up @@ -389,6 +390,7 @@ function ExpenseReportListItemInner<TItem extends ListItem>({
const fallbackHasVisibleViolations = liveViolationsForSnapshotTransactions
? hasVisibleViolations(
reportForViolations,
submitterLogin,
liveViolationsForSnapshotTransactions,
currentUserDetails.email ?? '',
currentUserDetails.accountID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function TransactionListItemInner<TItem extends ListItem>({

const onyxViolations = (transactionViolationsForRow ?? []).filter(
(violation: TransactionViolation) =>
!isViolationDismissed(transactionItem, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, reportForViolations, policyForViolations, submitterLogin) &&
!isViolationDismissed(transactionItem, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, reportForViolations, submitterLogin, policyForViolations) &&
shouldShowViolation(reportForViolations, policyForViolations, violation.name, currentUserDetails.email ?? '', false, transactionItem),
);

Expand Down
8 changes: 5 additions & 3 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Onyx from 'react-native-onyx';
import EmailUtils from './EmailUtils';
import {formatPhoneNumber as formatPhoneNumberPhoneUtils} from './LocalePhoneNumber';
import {isTrackOnboardingChoice} from './OnboardingUtils';
import {getLoginsByAccountIDs, getPersonalDetailsByIDs} from './PersonalDetailsUtils';
import {deprecatedGetLoginsByAccountIDs, deprecatedGetPersonalDetailsByIDs} from './PersonalDetailsUtils';
import {getApprovalWorkflow, getCorrectedAutoReportingFrequency, getReimburserAccountID} from './PolicyUtils';
import {
getDisplayNameForParticipant,
Expand Down Expand Up @@ -512,7 +512,8 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca
const autoReportingFrequency = getCorrectedAutoReportingFrequency(policy);
const isInstantSubmitEnabled = autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT;
const shouldShowFixMessage = hasViolations && isInstantSubmitEnabled && !isASAPSubmitBetaEnabled;
const [policyOwnerPersonalDetails, ownerPersonalDetails] = getPersonalDetailsByIDs({
// eslint-disable-next-line @typescript-eslint/no-deprecated
const [policyOwnerPersonalDetails, ownerPersonalDetails] = deprecatedGetPersonalDetailsByIDs({
accountIDs: [policy?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID, ownerAccountID],
currentUserAccountID: currentUserAccountIDParam ?? CONST.DEFAULT_NUMBER_ID,
shouldChangeUserDisplayName: true,
Expand All @@ -530,7 +531,8 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca
? (getDisplayNameForParticipant({accountID: bypassNextApproverID, formatPhoneNumber: formatPhoneNumberPhoneUtils}) ?? getPersonalDetailsForAccountID(bypassNextApproverID).login)
: getNextApproverDisplayName(report, isUnapprove);
const approverAccountID = bypassNextApproverID ?? getNextApproverAccountID(report, isUnapprove);
const approvers = getLoginsByAccountIDs([approverAccountID ?? CONST.DEFAULT_NUMBER_ID]);
// eslint-disable-next-line @typescript-eslint/no-deprecated
const approvers = deprecatedGetLoginsByAccountIDs([approverAccountID ?? CONST.DEFAULT_NUMBER_ID]);

const reimburserAccountID = getReimburserAccountID(policy);
const type: ReportNextStepDeprecated['type'] = 'neutral';
Expand Down
19 changes: 15 additions & 4 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ function getPersonalDetailsByID(accountID: number | undefined, personalDetailsLi
* @param currentUserAccountID
* @param shouldChangeUserDisplayName - It will replace the current user's personal detail object's displayName with 'You'.
* @returns - Array of personal detail objects
* @deprecated Don't use this. The only usage left is in deprecated NextStepUtils/buildNextStepNew which will be removed later.
*/
function getPersonalDetailsByIDs({
function deprecatedGetPersonalDetailsByIDs({
accountIDs,
currentUserAccountID,
shouldChangeUserDisplayName = false,
Expand Down Expand Up @@ -204,7 +205,7 @@ function getPersonalDetailsByIDs({
return result;
}

function newGetPersonalDetailsByIDs(accountIDs: number[] | undefined, personalDetails: OnyxEntry<PersonalDetailsList>): PersonalDetails[] {
function getPersonalDetailsByIDs(accountIDs: number[] | undefined, personalDetails: OnyxEntry<PersonalDetailsList>): PersonalDetails[] {
if (!accountIDs) {
return [];
}
Expand Down Expand Up @@ -302,7 +303,7 @@ function getLoginByAccountID(accountID: number | undefined, personalDetails: Ony
* @param personalDetailsList Record of user personal details, indexed by user id
* @returns Array of logins according to passed accountIDs
*/
function getLoginsByAccountIDs(accountIDs: number[] | undefined, personalDetailsList: OnyxEntry<PersonalDetailsList> = allPersonalDetails): string[] {
function getLoginsByAccountIDs(accountIDs: number[] | undefined, personalDetailsList: OnyxEntry<PersonalDetailsList>): string[] {
return (
accountIDs?.reduce((foundLogins: string[], accountID) => {
const currentLogin = getLoginByAccountID(accountID, personalDetailsList);
Expand All @@ -314,6 +315,13 @@ function getLoginsByAccountIDs(accountIDs: number[] | undefined, personalDetails
);
}

/**
* @deprecated Don't use this. The only usage left is in deprecated NextStepUtils/buildNextStepNew which will be removed later.
*/
function deprecatedGetLoginsByAccountIDs(accountIDs: number[] | undefined): string[] {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I created a deprecated version of this because we still use this in another deprecated function (buildNextStepNew) from NextStepUtils above. As discussed on Slack, I decided not to migrate that one.

return getLoginsByAccountIDs(accountIDs, allPersonalDetails);
}

/**
* Provided a set of invited logins and optimistic accountIDs. Returns the ones which are not known to the user i.e. they do not exist in the personalDetailsList.
*/
Expand Down Expand Up @@ -612,14 +620,17 @@ function areTravelPersonalDetailsMissing(privatePersonalDetails: OnyxEntry<Priva
export {
getDisplayNameOrDefault,
getPersonalDetailsByID,
// eslint-disable-next-line @typescript-eslint/no-deprecated
deprecatedGetPersonalDetailsByIDs,
getPersonalDetailsByIDs,
newGetPersonalDetailsByIDs,
getParticipantsPersonalDetails,
getPersonalDetailsListByIDs,
getDisplayNameOrYou,
getPersonalDetailByEmail,
getKnownAccountIDByLogin,
getAccountIDsByLogins,
// eslint-disable-next-line @typescript-eslint/no-deprecated
deprecatedGetLoginsByAccountIDs,
getLoginsByAccountIDs,
getPersonalDetailsOnyxDataForOptimisticUsers,
getCurrentAddress,
Expand Down
31 changes: 18 additions & 13 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9184,6 +9184,8 @@ function getViolatingReportIDForRBRInLHN(report: OnyxEntry<Report>, transactionV
true,
transactions,
potentialReport,
// This path only runs for reports the current user submitted, so the report owner is the current user.
currentUserLogin,
policy,
) ||
hasWarningTypeViolations(
Expand All @@ -9194,6 +9196,8 @@ function getViolatingReportIDForRBRInLHN(report: OnyxEntry<Report>, transactionV
true,
transactions,
potentialReport,
// This path only runs for reports the current user submitted, so the report owner is the current user.
currentUserLogin,
policy,
) ||
hasNoticeTypeViolationsForRBRInLHN(
Expand Down Expand Up @@ -9225,7 +9229,8 @@ function hasNoticeTypeViolationsForRBRInLHN(
return false;
}
const filteredViolations = excludedViolationNames.length > 0 ? rawViolations.filter((violation) => !excludedViolationNames.includes(violation.name)) : rawViolations;
return hasNoticeTypeViolation(transaction, filteredViolations, currentUserEmailParam, currentUserAccountIDParam, report, policy, true);
// This path only runs for reports the current user submitted, so the report owner is the current user.
return hasNoticeTypeViolation(transaction, filteredViolations, currentUserEmailParam, currentUserAccountIDParam, report, currentUserEmailParam, policy, true);
});
}

Expand All @@ -9240,10 +9245,13 @@ function hasViolations(
shouldShowInReview?: boolean,
reportTransactions?: Transaction[],
report?: OnyxEntry<Report>,
reportOwnerLogin?: string,
policy?: OnyxEntry<Policy>,
Comment thread
bernhardoj marked this conversation as resolved.
): boolean {
const transactions = reportTransactions ?? getReportTransactions(reportID);
return transactions.some((transaction) => hasViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, report, policy, shouldShowInReview));
return transactions.some((transaction) =>
hasViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, report, reportOwnerLogin, policy, shouldShowInReview),
);
}

function hasVisibleReportFieldViolations(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, currentUserAccountID: number | undefined): boolean {
Expand Down Expand Up @@ -9293,11 +9301,12 @@ function hasWarningTypeViolations(
shouldShowInReview?: boolean,
reportTransactions?: Transaction[],
report?: OnyxEntry<Report>,
reportOwnerLogin?: string,
policy?: OnyxEntry<Policy>,
): boolean {
const transactions = reportTransactions ?? getReportTransactions(reportID);
return transactions.some((transaction) =>
hasWarningTypeViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, report, policy, shouldShowInReview),
hasWarningTypeViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, report, reportOwnerLogin, policy, shouldShowInReview),
);
}

Expand All @@ -9321,14 +9330,12 @@ function hasNoticeTypeViolations(
transactionViolations: OnyxCollection<TransactionViolation[]>,
currentUserAccountIDParam: number,
currentUserEmailParam: string,
shouldShowInReview?: boolean,
reportTransactions?: Transaction[],
report?: OnyxEntry<Report>,
policy?: OnyxEntry<Policy>,
shouldShowInReview: boolean,
reportTransactions: Transaction[] | undefined,
): boolean {
const transactions = reportTransactions ?? getReportTransactions(reportID);
return transactions.some((transaction) =>
hasNoticeTypeViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, report, policy, shouldShowInReview),
hasNoticeTypeViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, undefined, undefined, undefined, shouldShowInReview),
);
}

Expand All @@ -9341,13 +9348,11 @@ function hasAnyViolations(
currentUserAccountIDParam: number,
currentUserEmailParam: string,
reportTransactions?: Transaction[],
report?: OnyxEntry<Report>,
policy?: OnyxEntry<Policy>,
) {
return (
hasViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam, undefined, reportTransactions, report, policy) ||
hasNoticeTypeViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam, true, reportTransactions, report, policy) ||
hasWarningTypeViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam ?? '', true, reportTransactions, report, policy)
hasViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam, undefined, reportTransactions) ||
hasNoticeTypeViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam, true, reportTransactions) ||
hasWarningTypeViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam ?? '', true, reportTransactions)
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,7 @@ function classifyAndPreprocess(data: OnyxTypes.SearchResults['data']): Omit<Prep
*/
function hasVisibleViolations(
report: OnyxEntry<OnyxTypes.Report>,
reportOwnerLogin: string | undefined,
allViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>,
currentUserEmail: string,
currentUserAccountID: number,
Expand All @@ -2033,7 +2034,7 @@ function hasVisibleViolations(
}

for (const violation of tvs) {
if (isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, report, policy)) {
if (isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, report, reportOwnerLogin, policy)) {
continue;
}

Expand Down Expand Up @@ -2891,6 +2892,7 @@ function getReportSections({

const hasVisibleViolationsForReport = hasVisibleViolations(
reportItem,
getLoginByAccountID(reportItem.ownerAccountID, mergedPersonalDetails),
allViolations,
currentUserEmail,
currentAccountID ?? CONST.DEFAULT_NUMBER_ID,
Expand Down
Loading
Loading