Skip to content
Merged
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
@@ -1,9 +1,10 @@
import type {OnyxCollection} from 'react-native-onyx';
import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Transaction} from '@src/types/onyx';
import type {Transaction, TransactionViolation} from '@src/types/onyx';

let previousTransactions: OnyxCollection<Transaction> = {};
let previousViolations: OnyxCollection<TransactionViolation[]> = {};

export default createOnyxDerivedValueConfig({
key: ONYXKEYS.DERIVED.REPORT_TRANSACTIONS_AND_VIOLATIONS,
Expand Down Expand Up @@ -56,16 +57,25 @@ export default createOnyxDerivedValueConfig({
}

const transactionID = transaction.transactionID;
const transactionViolations = violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`];
const violationKey = `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`;
const transactionViolations = violations?.[violationKey];
const previousTransactionViolations = previousViolations?.[violationKey];

const violationInSourceValues = transactionViolationsUpdates?.[violationKey];

// If violations exist and have length > 0, add them to the structure
if (transactionViolations && transactionViolations.length > 0) {
reportTransactionsAndViolations[reportID].violations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] = transactionViolations;
reportTransactionsAndViolations[reportID].violations[violationKey] = transactionViolations;
} else if (violationInSourceValues === undefined || (previousTransactionViolations && previousTransactionViolations.length > 0)) {
// If violations were removed (previous had violations but current doesn't) or explicitly set to undefined, remove them from the structure
delete reportTransactionsAndViolations[reportID].violations[violationKey];
}

reportTransactionsAndViolations[reportID].transactions[transactionKey] = transaction;
}

previousTransactions = transactions;
previousViolations = violations;

return reportTransactionsAndViolations;
},
Expand Down
Loading