Skip to content

Commit 1d4ac0b

Browse files
authored
Merge pull request Expensify#72154 from DylanDylann/refactor-602
[Part 2] Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES in Category.ts
2 parents 305b81f + c8684e2 commit 1d4ac0b

7 files changed

Lines changed: 195 additions & 75 deletions

File tree

src/libs/actions/IOU.ts

Lines changed: 159 additions & 63 deletions
Large diffs are not rendered by default.

src/libs/actions/Policy/Category.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ function getPolicyCategories(policyID: string) {
314314
API.read(READ_COMMANDS.GET_POLICY_CATEGORIES, params);
315315
}
316316

317+
/**
318+
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
319+
* All usages of this function should be replaced with useOnyx hook in React components.
320+
*/
317321
function buildOptimisticPolicyRecentlyUsedCategories(policyID?: string, category?: string) {
318322
if (!policyID || !category) {
319323
return [];
@@ -1486,6 +1490,8 @@ function setPolicyCategoryTax(policyID: string, categoryName: string, taxID: str
14861490
export {
14871491
buildOptimisticPolicyCategories,
14881492
buildOptimisticMccGroup,
1493+
// TODO: Replace buildOptimisticPolicyRecentlyUsedCategories with useOnyx hook (https://github.com/Expensify/App/issues/66557)
1494+
// eslint-disable-next-line deprecation/deprecation
14891495
buildOptimisticPolicyRecentlyUsedCategories,
14901496
clearCategoryErrors,
14911497
createPolicyCategory,

src/pages/Share/SubmitDetailsPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function SubmitDetailsPage({
5656
const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector});
5757
const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true});
5858
const [validFilesToUpload] = useOnyx(ONYXKEYS.VALIDATED_FILE_OBJECT, {canBeMissing: true});
59+
const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${getIOURequestPolicyID(transaction, report)}`, {canBeMissing: true});
5960
const [currentAttachment] = useOnyx(ONYXKEYS.SHARE_TEMP_FILE, {canBeMissing: true});
6061
const shouldUsePreValidatedFile = shouldValidateFile(currentAttachment);
6162
const isLinkedTrackedExpenseReportArchived = useReportIsArchived(transaction?.linkedTrackedExpenseReportID);
@@ -138,7 +139,7 @@ function SubmitDetailsPage({
138139
requestMoney({
139140
report,
140141
participantParams: {payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant},
141-
policyParams: {policy, policyTagList: policyTags, policyCategories},
142+
policyParams: {policy, policyTagList: policyTags, policyCategories, policyRecentlyUsedCategories},
142143
gpsPoints,
143144
action: CONST.IOU.TYPE.CREATE,
144145
transactionParams: {

src/pages/iou/SplitExpensePage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
2222
import {
2323
addSplitExpenseField,
2424
clearSplitTransactionDraftErrors,
25+
getIOURequestPolicyID,
2526
initDraftSplitExpenseDataForEdit,
2627
initSplitExpenseItemData,
2728
saveSplitTransactions,
@@ -72,6 +73,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
7273
const [currencyList] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true});
7374
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: false});
7475
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportID)}`, {canBeMissing: true});
76+
const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${getIOURequestPolicyID(transaction, report)}`, {canBeMissing: true});
7577

7678
const policy = usePolicy(report?.policyID);
7779
const isSplitAvailable = report && transaction && isSplitAction(report, [transaction], policy);
@@ -152,7 +154,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
152154
return;
153155
}
154156

155-
saveSplitTransactions(draftTransaction, currentSearchHash, policyCategories, expenseReportPolicy);
157+
saveSplitTransactions(draftTransaction, currentSearchHash, policyCategories, expenseReportPolicy, policyRecentlyUsedCategories);
156158
}, [
157159
splitExpenses,
158160
childTransactions.length,
@@ -166,6 +168,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
166168
currentSearchHash,
167169
policyCategories,
168170
expenseReportPolicy,
171+
policyRecentlyUsedCategories,
169172
splitFieldDataFromOriginalTransaction,
170173
translate,
171174
transactionID,

src/pages/iou/request/step/IOURequestStepCategory.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function IOURequestStepCategory({
5858
const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy?.id}`, {canBeMissing: true});
5959
const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${policyIdDraft}`, {canBeMissing: true});
6060
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policy?.id}`, {canBeMissing: true});
61+
const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policy?.id}`, {canBeMissing: true});
6162

6263
const report = reportReal ?? reportDraft;
6364
const policyCategories = policyCategoriesReal ?? policyCategoriesDraft;
@@ -116,7 +117,16 @@ function IOURequestStepCategory({
116117
}
117118

118119
if (isEditing && report) {
119-
updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory, policy, policyTags, policyCategories, currentSearchHash);
120+
updateMoneyRequestCategory(
121+
transaction.transactionID,
122+
report.reportID,
123+
updatedCategory,
124+
policy,
125+
policyTags,
126+
policyCategories,
127+
policyRecentlyUsedCategories,
128+
currentSearchHash,
129+
);
120130
navigateBack();
121131
return;
122132
}

src/pages/iou/request/step/IOURequestStepConfirmation.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ function IOURequestStepConfirmation({
535535
policy,
536536
policyTagList: policyTags,
537537
policyCategories,
538+
policyRecentlyUsedCategories,
538539
},
539540
gpsPoints,
540541
action,
@@ -578,6 +579,7 @@ function IOURequestStepConfirmation({
578579
policy,
579580
policyTags,
580581
policyCategories,
582+
policyRecentlyUsedCategories,
581583
action,
582584
transactionTaxCode,
583585
transactionTaxAmount,
@@ -724,6 +726,7 @@ function IOURequestStepConfirmation({
724726
policy,
725727
policyCategories,
726728
policyTagList: policyTags,
729+
policyRecentlyUsedCategories,
727730
},
728731
transactionParams: {
729732
amount: transaction.amount,
@@ -752,10 +755,11 @@ function IOURequestStepConfirmation({
752755
currentUserPersonalDetails.login,
753756
currentUserPersonalDetails.accountID,
754757
iouType,
755-
isManualDistanceRequest,
756758
policy,
757759
policyCategories,
758760
policyTags,
761+
policyRecentlyUsedCategories,
762+
isManualDistanceRequest,
759763
transactionTaxCode,
760764
transactionTaxAmount,
761765
customUnitRateID,

tests/actions/IOUTest.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@ describe('actions/IOU', () => {
27082708
originalTransactionID: transaction.transactionID,
27092709
},
27102710
};
2711-
saveSplitTransactions(draftTransaction, 1, undefined, undefined);
2711+
saveSplitTransactions(draftTransaction, 1, undefined, undefined, []);
27122712

27132713
await waitForBatchedUpdates();
27142714

@@ -2767,7 +2767,7 @@ describe('actions/IOU', () => {
27672767

27682768
// When splitting the expense
27692769
const hash = 1;
2770-
saveSplitTransactions(draftTransaction, hash, undefined, undefined);
2770+
saveSplitTransactions(draftTransaction, hash, undefined, undefined, []);
27712771

27722772
await waitForBatchedUpdates();
27732773

@@ -2841,7 +2841,7 @@ describe('actions/IOU', () => {
28412841

28422842
// When splitting the expense
28432843
const hash = 1;
2844-
saveSplitTransactions(draftTransaction, hash, undefined, undefined);
2844+
saveSplitTransactions(draftTransaction, hash, undefined, undefined, []);
28452845

28462846
await waitForBatchedUpdates();
28472847

@@ -5566,7 +5566,7 @@ describe('actions/IOU', () => {
55665566
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {reportID: transactionThreadReportID});
55675567

55685568
// When updating a money request category
5569-
updateMoneyRequestCategory(transactionID, transactionThreadReportID, category, fakePolicy, undefined, undefined);
5569+
updateMoneyRequestCategory(transactionID, transactionThreadReportID, category, fakePolicy, undefined, undefined, []);
55705570

55715571
await waitForBatchedUpdates();
55725572

@@ -5631,7 +5631,7 @@ describe('actions/IOU', () => {
56315631
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);
56325632

56335633
// When updating a money request category
5634-
updateMoneyRequestCategory(transactionID, '3', category, fakePolicy, undefined, undefined);
5634+
updateMoneyRequestCategory(transactionID, '3', category, fakePolicy, undefined, undefined, []);
56355635

56365636
await waitForBatchedUpdates();
56375637

@@ -5663,7 +5663,7 @@ describe('actions/IOU', () => {
56635663
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);
56645664

56655665
// When updating the money request category
5666-
updateMoneyRequestCategory(transactionID, '3', category, fakePolicy, undefined, undefined);
5666+
updateMoneyRequestCategory(transactionID, '3', category, fakePolicy, undefined, undefined, []);
56675667

56685668
await waitForBatchedUpdates();
56695669

@@ -7205,7 +7205,7 @@ describe('actions/IOU', () => {
72057205
},
72067206
};
72077207

7208-
saveSplitTransactions(draftTransaction, -2, undefined, undefined);
7208+
saveSplitTransactions(draftTransaction, -2, undefined, undefined, []);
72097209
await waitForBatchedUpdates();
72107210

72117211
const split1 = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}235`);
@@ -7305,7 +7305,7 @@ describe('actions/IOU', () => {
73057305
},
73067306
};
73077307

7308-
saveSplitTransactions(draftTransaction, -2, undefined, undefined);
7308+
saveSplitTransactions(draftTransaction, -2, undefined, undefined, []);
73097309
await waitForBatchedUpdates();
73107310

73117311
const split1 = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}235`);

0 commit comments

Comments
 (0)