Skip to content

Commit 119e4f7

Browse files
authored
Merge pull request Expensify#81707 from Expensify/tgolen-refactorOnyxConnection-reportactions-2and3
[PR 2 of 15] Remove global Onyx reference from getOriginalReportID step 1
2 parents d1affbe + 63ce87f commit 119e4f7

15 files changed

Lines changed: 66 additions & 31 deletions

src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ function MoneyRequestReportActionsList({
558558
hasNextActionMadeBySameActor(visibleReportActions, index);
559559

560560
const actionEmojiReactions = emojiReactions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportAction.reportActionID}`];
561-
const originalReportID = getOriginalReportID(report.reportID, reportAction);
561+
const originalReportID = getOriginalReportID(report.reportID, reportAction, undefined);
562562
const reportDraftMessages = draftMessage?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`];
563563
const matchingDraftMessage = reportDraftMessages?.[reportAction.reportActionID];
564564
const matchingDraftMessageString = matchingDraftMessage?.message;

src/components/ShowContextMenuContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function showContextMenuForReport(
6262
contextMenuAnchor: anchor,
6363
report: {
6464
reportID,
65-
originalReportID: reportID ? getOriginalReportID(reportID, action) : undefined,
65+
originalReportID: reportID ? getOriginalReportID(reportID, action, undefined) : undefined,
6666
isArchivedRoom,
6767
},
6868
reportAction: {

src/libs/ReportUtils.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9967,11 +9967,11 @@ function canUserPerformWriteAction(report: OnyxEntry<Report>, isReportArchived:
99679967
/**
99689968
* Returns ID of the original report from which the given reportAction is first created.
99699969
*/
9970-
function getOriginalReportID(reportID: string | undefined, reportAction: OnyxInputOrEntry<ReportAction>): string | undefined {
9970+
function getOriginalReportID(reportID: string | undefined, reportAction: OnyxInputOrEntry<ReportAction>, reportActionsParam: OnyxEntry<ReportActions> | undefined): string | undefined {
99719971
if (!reportID) {
99729972
return undefined;
99739973
}
9974-
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
9974+
const reportActions = reportActionsParam ?? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
99759975
const currentReportAction = reportAction?.reportActionID ? reportActions?.[reportAction.reportActionID] : undefined;
99769976
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
99779977
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
@@ -10814,16 +10814,6 @@ function getIndicatedMissingPaymentMethod(
1081410814
return !hasCreditBankAccount(bankAccountList) ? 'bankAccount' : undefined;
1081510815
}
1081610816

10817-
/**
10818-
* Checks if report chat contains missing payment method
10819-
*/
10820-
function hasMissingPaymentMethod(userWalletTierName: string | undefined, iouReportID: string | undefined, bankAccountList: OnyxEntry<BankAccountList>): boolean {
10821-
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`] ?? {};
10822-
return Object.values(reportActions)
10823-
.filter(Boolean)
10824-
.some((action) => getIndicatedMissingPaymentMethod(userWalletTierName, iouReportID, action, bankAccountList) !== undefined);
10825-
}
10826-
1082710817
/**
1082810818
* Used from expense actions to decide if we need to build an optimistic expense report.
1082910819
* Create a new report if:
@@ -12946,7 +12936,6 @@ export {
1294612936
hasExpensifyGuidesEmails,
1294712937
hasHeldExpenses,
1294812938
hasIOUWaitingOnCurrentUserBankAccount,
12949-
hasMissingPaymentMethod,
1295012939
hasNonReimbursableTransactions,
1295112940
hasOnlyHeldExpenses,
1295212941
hasOnlyTransactionsWithPendingRoutes,

src/libs/actions/Report/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,7 @@ function deleteReportComment(
21272127
currentEmail: string,
21282128
) {
21292129
const reportID = report?.reportID;
2130-
const originalReportID = getOriginalReportID(reportID, reportAction);
2130+
const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
21312131
const reportActionID = reportAction.reportActionID;
21322132

21332133
if (!reportActionID || !originalReportID || !reportID) {
@@ -2455,13 +2455,13 @@ function editReportComment(
24552455

24562456
/** Deletes the draft for a comment report action. */
24572457
function deleteReportActionDraft(reportID: string | undefined, reportAction: ReportAction) {
2458-
const originalReportID = getOriginalReportID(reportID, reportAction);
2458+
const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
24592459
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, {[reportAction.reportActionID]: null});
24602460
}
24612461

24622462
/** Saves the draft for a comment report action. This will put the comment into "edit mode" */
24632463
function saveReportActionDraft(reportID: string | undefined, reportAction: ReportAction, draftMessage: string) {
2464-
const originalReportID = getOriginalReportID(reportID, reportAction);
2464+
const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
24652465
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, {[reportAction.reportActionID]: {message: draftMessage}});
24662466
}
24672467

@@ -3797,7 +3797,7 @@ function toggleEmojiReaction(
37973797
currentUserAccountID: number,
37983798
ignoreSkinToneOnCompare = false,
37993799
) {
3800-
const originalReportID = getOriginalReportID(reportID, reportAction);
3800+
const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
38013801

38023802
if (!originalReportID) {
38033803
return;

src/libs/actions/ReportActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Onyx.connect({
2727
});
2828

2929
function clearReportActionErrors(reportID: string, reportAction: ReportAction, keys?: string[]) {
30-
const originalReportID = getOriginalReportID(reportID, reportAction);
30+
const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
3131

3232
if (!reportAction?.reportActionID) {
3333
return;

src/pages/FlagCommentPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ function FlagCommentPage({parentReportAction, route, report, parentReport, repor
6060
if (isChatThread(report) && reportAction?.reportActionID === parentReportAction?.reportActionID) {
6161
reportID = parentReport?.reportID;
6262
}
63-
const originalReportID = getOriginalReportID(reportID, reportAction);
63+
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {canBeMissing: true});
64+
const originalReportID = getOriginalReportID(reportID, reportAction, reportActions);
6465
const [originalReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`, {canBeMissing: true});
6566
const isOriginalReportArchived = useReportIsArchived(originalReportID);
6667
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID, {canBeMissing: true});

src/pages/ReportDetailsPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
176176
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID, {canBeMissing: true});
177177

178178
const {reportActions} = usePaginatedReportActions(report.reportID);
179+
const [reportActionsForOriginalReportID] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canBeMissing: true});
179180

180181
const {removeTransaction} = useSearchContext();
181182

@@ -440,7 +441,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
440441
}
441442

442443
if (isTrackExpenseReport && !isDeletedParentAction) {
443-
const actionReportID = getOriginalReportID(report.reportID, parentReportAction);
444+
const actionReportID = getOriginalReportID(report.reportID, parentReportAction, reportActionsForOriginalReportID);
444445
const whisperAction = getTrackExpenseActionableWhisper(iouTransactionID, moneyRequestReport?.reportID);
445446
const actionableWhisperReportActionID = whisperAction?.reportActionID;
446447
items.push({
@@ -622,6 +623,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
622623
allTransactionDrafts,
623624
activePolicy,
624625
parentReport,
626+
reportActionsForOriginalReportID,
625627
]);
626628

627629
const displayNamesWithTooltips = useMemo(() => {

src/pages/TransactionDuplicate/DuplicateTransactionItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function DuplicateTransactionItem({transaction, index, allReports, policies, onP
4343
return IOUTransactionID === transaction?.transactionID;
4444
});
4545

46-
const originalReportID = getOriginalReportID(report?.reportID, action);
46+
const originalReportID = getOriginalReportID(report?.reportID, action, reportActions);
4747

4848
const [draftMessage] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, {
4949
canBeMissing: true,

src/pages/inbox/report/ContextMenu/BaseReportActionContextMenu.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ function BaseReportActionContextMenu({
367367
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
368368
reportAction: (reportAction ?? null) as ReportAction,
369369
reportID,
370+
originalReportID,
370371
report,
371372
draftMessage,
372373
selection,

src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ import {
152152
getIOUReportActionDisplayMessage,
153153
getMovedActionMessage,
154154
getMovedTransactionMessage,
155-
getOriginalReportID,
156155
getPolicyChangeMessage,
157156
getReimbursementDeQueuedOrCanceledActionMessage,
158157
getReimbursementQueuedActionMessage,
@@ -251,6 +250,7 @@ type ContextMenuActionPayload = {
251250
reportAction: ReportAction;
252251
transaction?: OnyxEntry<Transaction>;
253252
reportID: string | undefined;
253+
originalReportID: string | undefined;
254254
currentUserAccountID: number;
255255
report: OnyxEntry<ReportType>;
256256
policy?: OnyxEntry<Policy>;
@@ -1100,8 +1100,7 @@ const ContextMenuActions: ContextMenuAction[] = [
11001100
const isDynamicWorkflowRoutedAction = isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.DYNAMIC_EXTERNAL_WORKFLOW_ROUTED);
11011101
return type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && !isAttachmentTarget && !isMessageDeleted(reportAction) && !isDynamicWorkflowRoutedAction;
11021102
},
1103-
onPress: (closePopover, {reportAction, reportID}) => {
1104-
const originalReportID = getOriginalReportID(reportID, reportAction);
1103+
onPress: (closePopover, {reportAction, originalReportID}) => {
11051104
getEnvironmentURL().then((environmentURL) => {
11061105
const reportActionID = reportAction?.reportActionID;
11071106
Clipboard.setString(`${environmentURL}/r/${originalReportID}/${reportActionID}`);

0 commit comments

Comments
 (0)