-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Removing violations for duplicate transactions. #65107
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
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
1162976
inital testing
Tony-MK b33699c
renaming varible
Tony-MK a383b2c
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK 193740a
using helper function for deleting money request
Tony-MK fb801ab
prettier
Tony-MK 580c098
Merge branch 'Expensify:main' into duplicateTransactions
Tony-MK 3afab42
Merge branch 'Expensify:main' into duplicateTransactions
Tony-MK c1bfda2
applied fix to updateMoneyRequestDate
Tony-MK f97a346
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK 900bec9
Merge branch 'main' into duplicateTransactions
Tony-MK b8b1bab
clearing up comments
Tony-MK ee7721f
prettier
Tony-MK b2eab4b
prettier
Tony-MK 545f1d7
Merge branch 'Expensify:main' into duplicateTransactions
Tony-MK 7f7df39
refactoring function into one (#61)
Tony-MK 0c53536
Merge branch 'Expensify:main' into duplicateTransactions
Tony-MK 4fd1419
prettier
Tony-MK dbcbb9f
Merge branch 'Expensify:main' into duplicateTransactions
Tony-MK afa7c11
Merge branch 'main' into duplicateTransactions
Tony-MK e5c6c8f
Merge branch 'Expensify:main' into duplicateTransactions
Tony-MK deb5be8
revert condition
Tony-MK c1d4082
Merge branch 'duplicateTransactions' of https://github.com/Tony-MK/Ex…
Tony-MK 582e3a0
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK 8a2c58c
Merge branch 'main' into duplicateTransactions
Tony-MK 74ee6d8
lint
Tony-MK dbfc695
prettier
Tony-MK 7d5cbd3
lint
Tony-MK 29af4bc
prettier
Tony-MK 05d0534
fixed tests...
Tony-MK 4f2a157
opps, tests again...
Tony-MK 2968ed9
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK a7370fa
applied suggestions
Tony-MK ec0b927
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK 9e6a003
lint
Tony-MK 21a667d
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK f17b8fa
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK 2aea09b
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK 5f6dd47
useDuplicateTransactionsAndViolations
Tony-MK 76a83ad
prettier...
Tony-MK 47be6d1
lint
Tony-MK 233da31
Resolving conflicts
Tony-MK 3ece8d2
Merge branch 'main' into duplicateTransactions
Tony-MK 9480a57
Update useDuplicateTransactionsAndViolations.ts
Tony-MK b6a5894
lint
Tony-MK 7c16719
useDuplicateTransactionAndViolation.ts
Tony-MK 9657362
moving useDuplicateTransactionsAndViolations
Tony-MK 9705cf9
applied suggestions
Tony-MK 6e8a9af
applied changes
Tony-MK cb54fde
lint
Tony-MK 97ac841
applied suggestions
Tony-MK 496809d
typecheck
Tony-MK 2e4ae6e
refactoring getValidDuplicateTransactionIDs
Tony-MK 8464f3d
Merge branch 'main' of https://github.com/Expensify/App into duplicat…
Tony-MK daa8de5
reverting line
Tony-MK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import {useMemo} from 'react'; | ||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Transaction, TransactionViolations} from '@src/types/onyx'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** | ||
| * Selects violations related to provided transaction IDs and if present, the violations of their duplicates. | ||
| * @param transactionIDs - An array of transaction IDs to fetch their violations for. | ||
| * @param allTransactionsViolations - A collection of all transaction violations currently in the onyx db. | ||
| * @returns - A collection of violations related to the transaction IDs and if present, the violations of their duplicates. | ||
| * @private | ||
| */ | ||
| function selectViolationsWithDuplicates(transactionIDs: string[], allTransactionsViolations: OnyxCollection<TransactionViolations>): OnyxCollection<TransactionViolations> { | ||
| if (!allTransactionsViolations || !transactionIDs?.length) { | ||
| return {}; | ||
| } | ||
|
|
||
| const result: OnyxCollection<TransactionViolations> = {}; | ||
|
|
||
| for (const transactionID of transactionIDs) { | ||
| const key = `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`; | ||
| const transactionViolations = allTransactionsViolations[key]; | ||
|
|
||
| if (!transactionViolations) { | ||
| continue; | ||
| } | ||
|
|
||
| result[key] = transactionViolations; | ||
|
|
||
| transactionViolations | ||
| .filter((violations) => violations.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION) | ||
| .flatMap((violations) => violations?.data?.duplicates ?? []) | ||
| .forEach((duplicateID) => { | ||
| if (!duplicateID) { | ||
| return; | ||
| } | ||
|
|
||
| const duplicateKey = `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`; | ||
| const duplicateViolations = allTransactionsViolations[duplicateKey]; | ||
|
|
||
| if (duplicateViolations) { | ||
| result[duplicateKey] = duplicateViolations; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Selects transactions related to provided transaction IDs and if present, the duplicate transactions. | ||
| * @param transactionIDs - An array of transaction IDs to fetch their transactions for. | ||
| * @param allTransactions - A collection of all transactions currently in the onyx. | ||
| * @param duplicateTransactionViolations - A collection of all duplicate transaction violations currently in the onyx. | ||
| * @returns - A collection of transactions related to the transaction IDs and if present, the duplicate transactions. | ||
| */ | ||
|
|
||
| function selectTransactionsWithDuplicates( | ||
| transactionIDs: string[], | ||
| allTransactions: OnyxCollection<Transaction>, | ||
| duplicateTransactionViolations: OnyxCollection<TransactionViolations>, | ||
| ): OnyxCollection<Transaction> { | ||
| if (!allTransactions) { | ||
| return {}; | ||
| } | ||
|
|
||
| const result: OnyxCollection<Transaction> = {}; | ||
|
|
||
| for (const transactionID of transactionIDs) { | ||
| const key = `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`; | ||
| const transaction = allTransactions[key]; | ||
| if (transaction) { | ||
| result[key] = transaction; | ||
| } | ||
|
|
||
| const transactionViolations = duplicateTransactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; | ||
|
|
||
| if (!transactionViolations) { | ||
| continue; | ||
| } | ||
|
|
||
| transactionViolations | ||
| .filter((violations) => violations.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION) | ||
| .flatMap((violations) => violations?.data?.duplicates ?? []) | ||
| .forEach((duplicateID) => { | ||
| if (!duplicateID) { | ||
| return; | ||
| } | ||
|
|
||
| const duplicateKey = `${ONYXKEYS.COLLECTION.TRANSACTION}${duplicateID}`; | ||
| const duplicateTransaction = allTransactions[duplicateKey]; | ||
|
|
||
| if (duplicateTransaction) { | ||
| result[duplicateKey] = duplicateTransaction; | ||
| } | ||
| }); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| type DuplicateTransactionsAndViolations = { | ||
| duplicateTransactions: OnyxCollection<Transaction>; | ||
| duplicateTransactionViolations: OnyxCollection<TransactionViolations>; | ||
| }; | ||
|
|
||
| /** | ||
| * A hook to fetch transactions, their violations and if present, the duplicate transactions and their violations. | ||
| * @param transactionIDs - Array of transaction IDs to check for duplicates. | ||
| * @returns - An object containing duplicate transactions and their violations. | ||
| */ | ||
| function useDuplicateTransactionsAndViolations(transactionIDs: string[]): DuplicateTransactionsAndViolations { | ||
| const violationsSelectorMemo = useMemo(() => { | ||
| return (allTransactionsViolations: OnyxCollection<TransactionViolations>) => selectViolationsWithDuplicates(transactionIDs, allTransactionsViolations); | ||
| }, [transactionIDs]); | ||
|
|
||
| const [duplicateTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, { | ||
| canBeMissing: true, | ||
| selector: violationsSelectorMemo, | ||
| }); | ||
|
|
||
| const transactionSelector = useMemo(() => { | ||
| return (allTransactions: OnyxCollection<Transaction>) => selectTransactionsWithDuplicates(transactionIDs, allTransactions, duplicateTransactionViolations); | ||
| }, [transactionIDs, duplicateTransactionViolations]); | ||
|
|
||
| const [duplicateTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { | ||
| canBeMissing: true, | ||
| selector: transactionSelector, | ||
| }); | ||
|
|
||
| return useMemo( | ||
| () => ({ | ||
| duplicateTransactions, | ||
| duplicateTransactionViolations, | ||
| }), | ||
| [duplicateTransactions, duplicateTransactionViolations], | ||
| ); | ||
| } | ||
|
|
||
| export default useDuplicateTransactionsAndViolations; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.