-
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
fix: Expense details - Violation is not displayed on description field when opening IOU details. #56405
base: main
Are you sure you want to change the base?
fix: Expense details - Violation is not displayed on description field when opening IOU details. #56405
Changes from 3 commits
1e084f2
fafe6d4
3c2ab26
1143243
fc381b2
acb2a64
6913635
083bf1e
17fcb63
b7dc805
6000897
b99c0d9
61e467f
c57af96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,7 @@ function ReportPreview({ | |
const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { | ||
selector: (_transactions) => reportTransactionsSelector(_transactions, iouReportID), | ||
}); | ||
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); | ||
const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); | ||
roryabraham marked this conversation as resolved.
Show resolved
Hide resolved
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. Can add selector to get violations only for transactions on the current report: diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx
index 7635d2946bf..bc0bce19d00 100644
--- a/src/components/ReportActionItem/ReportPreview.tsx
+++ b/src/components/ReportActionItem/ReportPreview.tsx
@@ -148,7 +148,11 @@ function ReportPreview({
selector: (_transactions) => reportTransactionsSelector(_transactions, iouReportID),
});
const lastTransaction = transactions?.at(0);
- const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
+ const transactionIDList = transactions?.map((reportTransaction) => reportTransaction.transactionID) ?? [];
+ const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {
+ selector: (allTransactionViolations) =>
+ Object.fromEntries(Object.entries(allTransactionViolations ?? {}).filter(([key]) => transactionIDList.includes(key.replace(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, '')))),
+ });
const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`,
@@ -230,17 +234,16 @@ function ReportPreview({
const hasErrors =
(hasMissingSmartscanFields && !iouSettled) ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
- hasViolations(iouReportID, allTransactionViolations, true) ||
- hasNoticeTypeViolations(iouReportID, allTransactionViolations, true) ||
- hasWarningTypeViolations(iouReportID, allTransactionViolations, true) ||
+ hasViolations(iouReportID, violations, true) ||
+ hasNoticeTypeViolations(iouReportID, violations, true) ||
+ hasWarningTypeViolations(iouReportID, violations, true) ||
(isReportOwner(iouReport) && hasReportViolations(iouReportID)) ||
hasActionsWithErrors(iouReportID);
const lastThreeTransactions = transactions?.slice(-3) ?? [];
const lastThreeReceipts = lastThreeTransactions.map((transaction) => ({...getThumbnailAndImageURIs(transaction), transaction}));
- const transactionIDList = transactions?.map((reportTransaction) => reportTransaction.transactionID) ?? [];
const lastTransactionViolations = useTransactionViolations(lastTransaction?.transactionID);
const showRTERViolationMessage = numberOfRequests === 1 && hasPendingUI(lastTransaction, lastTransactionViolations);
- const shouldShowBrokenConnectionViolation = numberOfRequests === 1 && shouldShowBrokenConnectionViolationTransactionUtils(transactionIDList, iouReport, policy, allTransactionViolations);
+ const shouldShowBrokenConnectionViolation = numberOfRequests === 1 && shouldShowBrokenConnectionViolationTransactionUtils(transactionIDList, iouReport, policy, violations);
let formattedMerchant = numberOfRequests === 1 ? getMerchant(lastTransaction) : null;
const formattedDescription = numberOfRequests === 1 ? getDescription(lastTransaction) : null;
@@ -251,7 +254,7 @@ function ReportPreview({
const isArchived = isArchivedReportWithID(iouReport?.reportID);
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const filteredTransactions = transactions?.filter((transaction) => transaction) ?? [];
- const shouldShowSubmitButton = canSubmitReport(iouReport, policy, filteredTransactions, allTransactionViolations);
+ const shouldShowSubmitButton = canSubmitReport(iouReport, policy, filteredTransactions, violations);
const shouldDisableSubmitButton = shouldShowSubmitButton && !isAllowedToSubmitDraftExpenseReport(iouReport);
// The submit button should be success green colour only if the user is submitter and the policy does not have Scheduled Submit turned on
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. You could also DRY this selector into a hook. Something like: import {useOnyx} from 'react-native-onyx';
import {reportTransactionsSelector} from '@libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
function useReportWithTransactionsAndViolations(reportID?: string) {
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID ?? '-1'}`);
const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
selector: (_transactions) => reportTransactionsSelector(_transactions, reportID),
});
const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {
selector: (allViolations) =>
Object.fromEntries(
Object.entries(allViolations ?? {}).filter(([key]) =>
transactions.some((transaction) => transaction.transactionID === key.replace(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, '')),
),
),
});
return [report, transactions, violations];
}
export default useReportWithTransactionsAndViolations; 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. All done, also created the |
||
const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); | ||
const [invoiceReceiverPolicy] = useOnyx( | ||
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`, | ||
|
@@ -229,16 +229,16 @@ function ReportPreview({ | |
const hasErrors = | ||
(hasMissingSmartscanFields && !iouSettled) || | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
hasViolations(iouReportID, transactionViolations, true) || | ||
hasNoticeTypeViolations(iouReportID, transactionViolations, true) || | ||
hasWarningTypeViolations(iouReportID, transactionViolations, true) || | ||
hasViolations(iouReportID, allTransactionViolations, true) || | ||
hasNoticeTypeViolations(iouReportID, allTransactionViolations, true) || | ||
hasWarningTypeViolations(iouReportID, allTransactionViolations, true) || | ||
(isReportOwner(iouReport) && hasReportViolations(iouReportID)) || | ||
hasActionsWithErrors(iouReportID); | ||
const lastThreeTransactions = transactions?.slice(-3) ?? []; | ||
const lastTransaction = transactions?.at(0); | ||
const lastThreeReceipts = lastThreeTransactions.map((transaction) => ({...getThumbnailAndImageURIs(transaction), transaction})); | ||
const transactionIDList = transactions?.map((reportTransaction) => reportTransaction.transactionID) ?? []; | ||
const showRTERViolationMessage = numberOfRequests === 1 && hasPendingUI(lastTransaction, getTransactionViolations(lastTransaction?.transactionID)); | ||
const showRTERViolationMessage = numberOfRequests === 1 && hasPendingUI(lastTransaction, getTransactionViolations(lastTransaction?.transactionID, allTransactionViolations)); | ||
const shouldShowBrokenConnectionViolation = numberOfRequests === 1 && shouldShowBrokenConnectionViolationTransactionUtils(transactionIDList, iouReport, policy); | ||
let formattedMerchant = numberOfRequests === 1 ? getMerchant(lastTransaction) : null; | ||
const formattedDescription = numberOfRequests === 1 ? getDescription(lastTransaction) : null; | ||
|
@@ -250,7 +250,7 @@ function ReportPreview({ | |
const isArchived = isArchivedReportWithID(iouReport?.reportID); | ||
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; | ||
const filteredTransactions = transactions?.filter((transaction) => transaction) ?? []; | ||
const shouldShowSubmitButton = canSubmitReport(iouReport, policy, filteredTransactions); | ||
const shouldShowSubmitButton = canSubmitReport(iouReport, policy, filteredTransactions, allTransactionViolations); | ||
|
||
const shouldDisableSubmitButton = shouldShowSubmitButton && !isAllowedToSubmitDraftExpenseReport(iouReport); | ||
|
||
|
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.
You don't need to subscribe to the whole collection here: