From e09a423d7d34fc914bac6ac902f8bd879eefe6cf Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 29 May 2025 00:54:10 +0800 Subject: [PATCH 1/3] fix violations doesn't update when transactions collcetion is updated --- src/hooks/useReportWithTransactionsAndViolations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useReportWithTransactionsAndViolations.ts b/src/hooks/useReportWithTransactionsAndViolations.ts index f9308165fc85f..0d5c88093cd5d 100644 --- a/src/hooks/useReportWithTransactionsAndViolations.ts +++ b/src/hooks/useReportWithTransactionsAndViolations.ts @@ -20,7 +20,7 @@ function useReportWithTransactionsAndViolations(reportID?: string): [OnyxEntry transaction.transactionID === key.replace(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, '')), ), ), - }); + }, [transactions]); return [report, transactions ?? DEFAULT_TRANSACTIONS, violations ?? DEFAULT_VIOLATIONS]; } From 9cb19f1eb46ef5306590cf156293aa77f8b2201d Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 29 May 2025 01:03:52 +0800 Subject: [PATCH 2/3] lint --- src/hooks/useReportWithTransactionsAndViolations.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hooks/useReportWithTransactionsAndViolations.ts b/src/hooks/useReportWithTransactionsAndViolations.ts index 0d5c88093cd5d..392015fa54a38 100644 --- a/src/hooks/useReportWithTransactionsAndViolations.ts +++ b/src/hooks/useReportWithTransactionsAndViolations.ts @@ -1,6 +1,5 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {reportTransactionsSelector} from '@libs/ReportUtils'; -import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Report, Transaction, TransactionViolation} from '@src/types/onyx'; import useOnyx from './useOnyx'; @@ -9,9 +8,10 @@ const DEFAULT_TRANSACTIONS: Transaction[] = []; const DEFAULT_VIOLATIONS: Record = {}; function useReportWithTransactionsAndViolations(reportID?: string): [OnyxEntry, Transaction[], OnyxCollection] { - const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID ?? CONST.DEFAULT_NUMBER_ID}`); + const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: false}); const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { selector: (_transactions) => reportTransactionsSelector(_transactions, reportID), + canBeMissing: true, }); const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, { selector: (allViolations) => @@ -20,6 +20,7 @@ function useReportWithTransactionsAndViolations(reportID?: string): [OnyxEntry transaction.transactionID === key.replace(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, '')), ), ), + canBeMissing: true, }, [transactions]); return [report, transactions ?? DEFAULT_TRANSACTIONS, violations ?? DEFAULT_VIOLATIONS]; } From 9df2b1483ca4fcc24769377cede94b255864df90 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 29 May 2025 01:04:58 +0800 Subject: [PATCH 3/3] prettier --- .../useReportWithTransactionsAndViolations.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/hooks/useReportWithTransactionsAndViolations.ts b/src/hooks/useReportWithTransactionsAndViolations.ts index 392015fa54a38..caf854dd97406 100644 --- a/src/hooks/useReportWithTransactionsAndViolations.ts +++ b/src/hooks/useReportWithTransactionsAndViolations.ts @@ -13,15 +13,19 @@ function useReportWithTransactionsAndViolations(reportID?: string): [OnyxEntry reportTransactionsSelector(_transactions, reportID), canBeMissing: true, }); - 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, '')), + 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, '')), + ), ), - ), - canBeMissing: true, - }, [transactions]); + canBeMissing: true, + }, + [transactions], + ); return [report, transactions ?? DEFAULT_TRANSACTIONS, violations ?? DEFAULT_VIOLATIONS]; }