-
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 8 commits
1e084f2
fafe6d4
3c2ab26
1143243
fc381b2
acb2a64
6913635
083bf1e
17fcb63
b7dc805
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; | |
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useTransactionViolations from '@hooks/useTransactionViolations'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import ControlSelection from '@libs/ControlSelection'; | ||
import {convertToDisplayString} from '@libs/CurrencyUtils'; | ||
|
@@ -48,7 +49,6 @@ import type {TransactionDetails} from '@libs/ReportUtils'; | |
import StringUtils from '@libs/StringUtils'; | ||
import { | ||
compareDuplicateTransactionFields, | ||
getTransactionViolations, | ||
hasMissingSmartscanFields, | ||
hasNoticeTypeViolation as hasNoticeTypeViolationTransactionUtils, | ||
hasPendingUI, | ||
|
@@ -113,7 +113,8 @@ function MoneyRequestPreviewContent({ | |
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); | ||
const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS); | ||
const [allViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); | ||
const transactionViolations = getTransactionViolations(transaction?.transactionID); | ||
const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); | ||
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. This is the same collection as the previous line? 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. Yeah. A cleanup can be done here. 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. This is the main remaining thing I want to see addressed before this PR is merged 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. @rojiphil I have updated this. Please review and let me know if there's something left. Thanks. |
||
const transactionViolations = useTransactionViolations(transaction?.transactionID); | ||
|
||
const sessionAccountID = session?.accountID; | ||
const managerID = iouReport?.managerID ?? CONST.DEFAULT_NUMBER_ID; | ||
|
@@ -146,7 +147,7 @@ function MoneyRequestPreviewContent({ | |
const isOnHold = isOnHoldTransactionUtils(transaction); | ||
const isSettlementOrApprovalPartial = !!iouReport?.pendingFields?.partial; | ||
const isPartialHold = isSettlementOrApprovalPartial && isOnHold; | ||
const hasViolations = hasViolationTransactionUtils(transaction?.transactionID, allViolations, true); | ||
const hasViolations = hasViolationTransactionUtils(transaction, allViolations, true); | ||
const hasNoticeTypeViolations = hasNoticeTypeViolationTransactionUtils(transaction?.transactionID, allViolations, true) && isPaidGroupPolicy(iouReport); | ||
const hasWarningTypeViolations = hasWarningTypeViolationTransactionUtils(transaction?.transactionID, allViolations, true); | ||
const hasFieldErrors = hasMissingSmartscanFields(transaction); | ||
|
@@ -281,7 +282,7 @@ function MoneyRequestPreviewContent({ | |
if (isPending(transaction)) { | ||
return {shouldShow: true, messageIcon: Expensicons.CreditCardHourglass, messageDescription: translate('iou.transactionPending')}; | ||
} | ||
if (shouldShowBrokenConnectionViolation(transaction ? [transaction.transactionID] : [], iouReport, policy)) { | ||
if (shouldShowBrokenConnectionViolation(transaction ? [transaction.transactionID] : [], iouReport, policy, allTransactionViolations)) { | ||
return {shouldShow: true, messageIcon: Expensicons.Hourglass, messageDescription: translate('violations.brokenConnection530Error')}; | ||
} | ||
if (hasPendingUI(transaction, transactionViolations)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {useMemo} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import {isViolationDismissed} from '@libs/TransactionUtils'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {TransactionViolations} from '@src/types/onyx'; | ||
|
||
function useTransactionViolations(transactionID?: string): TransactionViolations { | ||
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); | ||
const [transactionViolations = []] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`); | ||
return useMemo(() => transactionViolations.filter((violation) => !isViolationDismissed(transaction, violation)), [transaction, transactionViolations]); | ||
} | ||
|
||
roryabraham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export default useTransactionViolations; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6920,7 +6920,7 @@ function hasViolations( | |
reportTransactions?: SearchTransaction[], | ||
): boolean { | ||
const transactions = reportTransactions ?? getReportTransactions(reportID); | ||
return transactions.some((transaction) => hasViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); | ||
return transactions.some((transaction) => hasViolation(transaction, transactionViolations, shouldShowInReview)); | ||
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. Same question. Why not transaction.transactionID? 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. @rojiphil, the util function |
||
} | ||
|
||
/** | ||
|
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.
NAB because we need to get this merged and CP'd, but we could also optimize this to only select the violations for the transactions that we care about, so the component doesn't re-render if other violations change:
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.
Quite a lot of optimizations have gone in here and I think we can optimize this too.
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.
@rojiphil I have updated this. Please review and let me know if there's something left. Thanks.