Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
dfbb0e1
pushing violations for tags
Tony-MK May 23, 2025
8f99598
lint
Tony-MK May 23, 2025
76fbf0c
lint
Tony-MK May 24, 2025
21432cb
Merge branch 'main' into tags-violations
Tony-MK Jun 21, 2025
8426522
Merge branch 'Expensify:main' into tags-violations
Tony-MK Jun 26, 2025
8ad6eaf
setting tags violations
Tony-MK Jun 26, 2025
8c6ac33
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Jun 26, 2025
741aa02
prettier
Tony-MK Jun 26, 2025
6be1636
category tests
Tony-MK Jul 6, 2025
83f2d81
Merge branch 'main' into tags-violations
Tony-MK Jul 6, 2025
2e1a232
tags test
Tony-MK Jul 7, 2025
49bb64e
Merge branch 'Expensify:main' into tags-violations
Tony-MK Jul 7, 2025
f3d2be8
policy from usePolicy
Tony-MK Jul 7, 2025
a2d77de
Merge branch 'tags-violations' of https://github.com/Tony-MK/Expensif…
Tony-MK Jul 7, 2025
01f481e
comments
Tony-MK Jul 7, 2025
c7c6d82
lint
Tony-MK Jul 7, 2025
7e19133
fixing deps warning
Tony-MK Jul 7, 2025
6700d1a
prettier
Tony-MK Jul 7, 2025
8a5d9dd
Merge branch 'main' into tags-violations
Tony-MK Jul 9, 2025
791050f
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Jul 10, 2025
a9cca16
ignoring invoice reports
Tony-MK Jul 10, 2025
0ba6830
performance tests
Tony-MK Jul 11, 2025
b9779cd
mig
Tony-MK Jul 11, 2025
734b6b6
Merge branch 'main' into tags-violations
Tony-MK Jul 21, 2025
a278bb5
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Jul 22, 2025
9951457
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Jul 22, 2025
d3a1a64
refactoring
Tony-MK Jul 22, 2025
5474a34
lint
Tony-MK Jul 22, 2025
19107d2
tests
Tony-MK Jul 22, 2025
05ba6e3
prettier..
Tony-MK Jul 22, 2025
d6e0248
spell check
Tony-MK Jul 22, 2025
666e697
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Jul 27, 2025
757b0e8
resolving conflicts
Tony-MK Jul 27, 2025
3ffa2ed
prettier..
Tony-MK Jul 27, 2025
11f6bba
tags..
Tony-MK Aug 1, 2025
3476c2d
Merge branch 'Expensify:main' into tags-violations
Tony-MK Aug 13, 2025
5cbdef2
update tags
Tony-MK Aug 14, 2025
9a77965
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Aug 14, 2025
693c6ad
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Aug 26, 2025
2378d23
created usePolicyData hook
Tony-MK Aug 28, 2025
418e1a9
convert params to policyData
Tony-MK Aug 28, 2025
63e0d8c
converted renamePolicyCategory to accept policyData
Tony-MK Aug 28, 2025
c5470a2
refactored tests and perfomance tests
Tony-MK Aug 28, 2025
42e2557
refactored other functions and pages to depend on usePolicyData
Tony-MK Aug 28, 2025
e9d6977
Merge branch 'main' into tags-violations
Tony-MK Aug 28, 2025
fdfec07
fixed policy and catergory tests
Tony-MK Aug 30, 2025
d177fd0
Created usePolicyData.test.ts
Tony-MK Aug 31, 2025
0bb275f
fixed tests
Tony-MK Aug 31, 2025
85c236a
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Aug 31, 2025
b963ab3
Merge branch 'Expensify:main' into tags-violations
Tony-MK Sep 2, 2025
7fe0452
lint
Tony-MK Sep 3, 2025
2dd48ef
Merge branch 'Expensify:main' into tags-violations
Tony-MK Sep 3, 2025
013fa7d
Merge branch 'Expensify:main' into tags-violations
Tony-MK Sep 5, 2025
a2e018c
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Sep 7, 2025
0b5fa55
reverted dependency line in InviteReceiptPartnerPolicyPage.tsx by re…
Tony-MK Sep 7, 2025
641931e
Moved 'usePolicyData' to it's own folder and create types file
Tony-MK Sep 7, 2025
70496e6
Created 'usePolicyData' to own folder and split 'usePolicyData' into …
Tony-MK Sep 7, 2025
72d9f86
fixing 'usePolicyData' catergories and tags empty value
Tony-MK Sep 7, 2025
cd59515
lint...
Tony-MK Sep 8, 2025
708ee53
Merge branch 'Expensify:main' into tags-violations
Tony-MK Sep 11, 2025
bd60815
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Sep 12, 2025
bcfbe79
Merge branch 'tags-violations' of https://github.com/Tony-MK/Expensif…
Tony-MK Sep 12, 2025
481b895
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Sep 13, 2025
677322c
fix: added dependencies useOnyx hooks in the usePolicyData hook and u…
Tony-MK Sep 13, 2025
283af11
Merge branch 'Expensify:main' into tags-violations
Tony-MK Sep 15, 2025
bbcc3d0
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Sep 16, 2025
95f1b2f
Merge branch 'tags-violations' of https://github.com/Tony-MK/Expensif…
Tony-MK Sep 16, 2025
3ead6ac
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Sep 17, 2025
ea93663
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Sep 17, 2025
c15e9d1
Merge branch 'main' of https://www.github.com/Expensify/App into tags…
Tony-MK Sep 19, 2025
d9dcd7e
Merge branch 'main' into tags-violations
Tony-MK Sep 20, 2025
33366b4
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Sep 23, 2025
0d5cc59
Apply suggestions from code review: Removing whitespace
Tony-MK Sep 26, 2025
73538c2
Removing whitespace
Tony-MK Sep 26, 2025
e0649fc
Merge branch 'Expensify:main' into tags-violations
Tony-MK Sep 26, 2025
e42a8f6
Refactor: Remove unnecessary policy checks before category and tag op…
Tony-MK Sep 26, 2025
c7818be
refactore: removed duplicate dependency 'transactions' prop from the …
Tony-MK Sep 26, 2025
1b7173c
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Sep 29, 2025
87a030e
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 2, 2025
37aa992
fix: update deleteWorkspaceCategories to accept an additional parameter
Tony-MK Oct 2, 2025
2da5223
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 5, 2025
2226044
Add missing Onyx.set call to update policy in PolicyTagTest
Tony-MK Oct 5, 2025
519199b
Merge branch 'main' into tags-violations
Tony-MK Oct 6, 2025
a60857d
Fix import order in PolicyTagTest to ensure proper module resolution
Tony-MK Oct 6, 2025
695286a
Merge branch 'main' into tags-violations
Tony-MK Oct 8, 2025
afa1c3b
Merge branch 'main' into tags-violations
Tony-MK Oct 10, 2025
feecdf6
Merge branch 'main' into tags-violations
Tony-MK Oct 14, 2025
49554bf
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 14, 2025
fa68042
applied suggestions
Tony-MK Oct 14, 2025
5aff137
reverting check in setWorkspaceTagEnabled
Tony-MK Oct 14, 2025
c11f1fc
Merge branch 'main' into tags-violations
Tony-MK Oct 16, 2025
4b3c02d
refactor: IOURequestStepCategory to use policyID for policy data
Tony-MK Oct 16, 2025
c8caabe
fix: ensure policy existence check before accessing areCategoriesEnabled
Tony-MK Oct 16, 2025
d5c94f2
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 16, 2025
9ee5710
lint
Tony-MK Oct 16, 2025
80a0bf4
Merge branch 'main' into tags-violations
Tony-MK Oct 16, 2025
eac84a8
lint
Tony-MK Oct 17, 2025
606cc9f
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 19, 2025
530921e
lint
Tony-MK Oct 19, 2025
7df6c42
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 20, 2025
7e42904
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 20, 2025
62ba679
lint
Tony-MK Oct 20, 2025
9718f48
refactor: improve test structure and organization in PolicyTagTest
Tony-MK Oct 20, 2025
eae79c3
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 21, 2025
362996a
refactor: PolicyTagTests.ts
Tony-MK Oct 22, 2025
bc3af87
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 22, 2025
839777b
refactor: lint
Tony-MK Oct 22, 2025
2ae6a3a
prettier
Tony-MK Oct 22, 2025
3b3a600
Merge pull request #62627 from Expensify/App/main
Tony-MK Oct 23, 2025
393e451
lint
Tony-MK Oct 23, 2025
5719caf
refactor: PolicyTagTest and ReportUtils tests to improve setup and im…
Tony-MK Oct 23, 2025
0f6d13b
test: Improve rerender handling in PolicyTag tests for better state m…
Tony-MK Oct 23, 2025
9784b27
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 24, 2025
a9f112d
refactor: reverted renamePolicyTagList and improved it's tests to b…
Tony-MK Oct 24, 2025
aaae69d
refactor: reverted renamePolicyTagList and improved it's tests to be…
Tony-MK Oct 24, 2025
d099f96
Merge branch 'tags-violations' of https://github.com/Tony-MK/Expensif…
Tony-MK Oct 24, 2025
170defa
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 24, 2025
f7b76a9
refactor: update parameter names and improve handling of policy tag l…
Tony-MK Oct 29, 2025
9519081
refactor: enhance pushTransactionViolationsOnyxData to handle reports…
Tony-MK Oct 29, 2025
aaa4437
refactor: change import of ReportTransactionsAndViolations to type im…
Tony-MK Oct 29, 2025
607fbbf
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 29, 2025
1a9c7c6
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Oct 30, 2025
0480e9a
:Merge branch 'main' of https://github.com/Expensify/App into tags-vi…
Tony-MK Oct 30, 2025
34585ac
refactor: pushTransactionViolationsOnyxData to streamline policy upda…
Tony-MK Oct 30, 2025
a762a91
refactor: lint
Tony-MK Oct 30, 2025
c17ddc9
refactor: remove unused import from ReportUtils.ts
Tony-MK Oct 30, 2025
dd0fec0
refactor: optimize tag merging logic in pushTransactionViolationsOnyx…
Tony-MK Oct 31, 2025
d39d36d
Merge branch 'Expensify:main' into tags-violations
Tony-MK Oct 31, 2025
9ea0182
Merge branch 'main' into tags-violations
Tony-MK Oct 31, 2025
25197c4
refacting null updates
Tony-MK Nov 1, 2025
9103d55
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Nov 1, 2025
507ef5b
Merge branch 'main' into tags-violations
Tony-MK Nov 3, 2025
e062c0c
refactor: WorkspaceTagsSettingsPage to use policyTags from policyData
Tony-MK Nov 3, 2025
4a49279
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Nov 3, 2025
b1f49ef
Merge branch 'Expensify:main' into tags-violations
Tony-MK Nov 3, 2025
4eedc8d
Merge branch 'Expensify:main' into tags-violations
Tony-MK Nov 3, 2025
e5f39ad
Merge branch 'Expensify:main' into tags-violations
Tony-MK Nov 4, 2025
4be2485
Merge branch 'Expensify:main' into tags-violations
Tony-MK Nov 4, 2025
d4d0f6f
Merge branch 'Expensify:main' into tags-violations
Tony-MK Nov 4, 2025
7a24e7f
refactor: renamed SearchReport to Report
Tony-MK Nov 5, 2025
860c596
Merge branch 'tags-violations' of https://github.com/Tony-MK/Expensif…
Tony-MK Nov 5, 2025
c82bf94
Merge branch 'main' of https://github.com/Expensify/App into tags-vio…
Tony-MK Nov 5, 2025
660c0c9
refactor: simplify getTripIDFromTransactionParentReportID function
Tony-MK Nov 5, 2025
8849a80
lint
Tony-MK Nov 5, 2025
a1971ca
refactor: remove unused Report type import in SplitExpensePage
Tony-MK Nov 5, 2025
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
62 changes: 62 additions & 0 deletions src/hooks/usePolicyData/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {useMemo} from 'react';
import {useAllReportsTransactionsAndViolations} from '@components/OnyxListItemProvider';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Report} from '@src/types/onyx';
import type {ReportTransactionsAndViolationsDerivedValue} from '@src/types/onyx/DerivedValues';
import type {OnyxValueWithOfflineFeedback} from '@src/types/onyx/OnyxCommon';
import type PolicyData from './types';

/**
* Retrieves policy tags, categories, reports and their associated transactions and violations.
* @param policyID The ID of the policy to retrieve data for.
* @returns An object containing policy data
*/
function usePolicyData(policyID?: string): PolicyData {
const policy = usePolicy(policyID);
const allReportsTransactionsAndViolations = useAllReportsTransactionsAndViolations();
const [tags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {canBeMissing: true}, [policyID]);
const [categories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, {canBeMissing: true}, [policyID]);
const [reports] = useOnyx(
ONYXKEYS.COLLECTION.REPORT,
{
canBeMissing: true,
selector: (allReports) => {
if (!policyID || !allReports || !allReportsTransactionsAndViolations) {
return {};
}

// Filter reports to only include those that belong to the specified policy and have associated transactions
Comment thread
Tony-MK marked this conversation as resolved.
return Object.keys(allReportsTransactionsAndViolations).reduce<Record<string, Report>>((acc, reportID) => {
const policyReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
if (policyReport?.policyID === policyID) {
acc[reportID] = policyReport;
}
return acc;
}, {});
},
},
[policyID, allReportsTransactionsAndViolations],
);
const transactionsAndViolations = useMemo(() => {
if (!reports || !allReportsTransactionsAndViolations) {
return {};
}
return Object.keys(reports).reduce<ReportTransactionsAndViolationsDerivedValue>((acc, reportID) => {
if (allReportsTransactionsAndViolations[reportID]) {
acc[reportID] = allReportsTransactionsAndViolations[reportID];
}
return acc;
}, {});
}, [reports, allReportsTransactionsAndViolations]);
return {
transactionsAndViolations,
tags: tags ?? {},
categories: categories ?? {},
policy: policy as OnyxValueWithOfflineFeedback<Policy>,
reports: Object.values(reports ?? {}) as Array<OnyxValueWithOfflineFeedback<Report>>,
};
}

export default usePolicyData;
13 changes: 13 additions & 0 deletions src/hooks/usePolicyData/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type {Policy, PolicyCategories, PolicyTagLists, Report} from '@src/types/onyx';
import type {ReportTransactionsAndViolationsDerivedValue} from '@src/types/onyx/DerivedValues';
import type {OnyxValueWithOfflineFeedback} from '@src/types/onyx/OnyxCommon';

type PolicyData = {
policy: OnyxValueWithOfflineFeedback<Policy>;
tags: PolicyTagLists;
categories: PolicyCategories;
reports: Array<OnyxValueWithOfflineFeedback<Report>>;
transactionsAndViolations: ReportTransactionsAndViolationsDerivedValue;
};

export default PolicyData;
209 changes: 137 additions & 72 deletions src/libs/ReportUtils.ts

Large diffs are not rendered by default.

Loading
Loading