Skip to content

Commit dbf8aad

Browse files
authored
Merge pull request Expensify#62592 from daledah/fix/62415
fix: show correct report field
2 parents 1a1d5f5 + b3ff211 commit dbf8aad

8 files changed

Lines changed: 62 additions & 9 deletions

src/components/MoneyRequestConfirmationListFooter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ function MoneyRequestConfirmationListFooter({
283283
const transactionReport = !!transaction?.reportID && Object.values(allReports ?? {}).find((report) => report?.reportID === transaction.reportID);
284284
const policyID = selectedParticipants?.at(0)?.policyID;
285285
const reportOwnerAccountID = selectedParticipants?.at(0)?.ownerAccountID;
286-
const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID);
287-
const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}).at(0);
286+
const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID, undefined, false);
287+
const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, undefined, false).at(0);
288288
let reportName: string | undefined;
289289
if (shouldUseTransactionReport) {
290290
reportName = transactionReport.reportName;

src/libs/ReportUtils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import getStateFromPath from './Navigation/helpers/getStateFromPath';
9797
import {isFullScreenName} from './Navigation/helpers/isNavigatorName';
9898
import {linkingConfig} from './Navigation/linkingConfig';
9999
import Navigation, {navigationRef} from './Navigation/Navigation';
100+
import type {MoneyRequestNavigatorParamList, ReportsSplitNavigatorParamList} from './Navigation/types';
100101
import {rand64} from './NumberUtils';
101102
import Parser from './Parser';
102103
import {getParsedMessageWithShortMentions} from './ParsingUtils';
@@ -9974,18 +9975,24 @@ function isReportOutstanding(
99749975
iouReport: OnyxInputOrEntry<Report>,
99759976
policyID: string | undefined,
99769977
reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = allReportNameValuePair,
9978+
allowSubmitted = true,
99779979
): boolean {
99789980
if (!iouReport || isEmptyObject(iouReport)) {
99799981
return false;
99809982
}
9983+
const currentRoute = navigationRef.getCurrentRoute();
9984+
const params = currentRoute?.params as MoneyRequestNavigatorParamList[typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION] | ReportsSplitNavigatorParamList[typeof SCREENS.REPORT];
9985+
const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${params?.reportID}`];
9986+
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
99819987
const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`];
9988+
const shouldAllowSubmittedReport = allowSubmitted || isInstantSubmitEnabled(policy) || isProcessingReport(activeReport);
99829989
return (
99839990
isExpenseReport(iouReport) &&
99849991
iouReport?.stateNum !== undefined &&
99859992
iouReport?.statusNum !== undefined &&
99869993
iouReport?.policyID === policyID &&
9987-
iouReport?.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED &&
9988-
iouReport?.statusNum <= CONST.REPORT.STATUS_NUM.SUBMITTED &&
9994+
(shouldAllowSubmittedReport ? iouReport?.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.stateNum < CONST.REPORT.STATE_NUM.SUBMITTED) &&
9995+
(shouldAllowSubmittedReport ? iouReport?.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.statusNum < CONST.REPORT.STATE_NUM.SUBMITTED) &&
99899996
!hasForwardedAction(iouReport.reportID) &&
99909997
!isArchivedReport(reportNameValuePair)
99919998
);
@@ -10003,6 +10010,7 @@ function getOutstandingReportsForUser(
1000310010
reportOwnerAccountID: number | undefined,
1000410011
reports: OnyxCollection<Report> = allReports,
1000510012
reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = allReportNameValuePair,
10013+
allowSubmitted = true,
1000610014
): Array<OnyxEntry<Report>> {
1000710015
if (!reports) {
1000810016
return [];
@@ -10011,7 +10019,7 @@ function getOutstandingReportsForUser(
1001110019
.filter(
1001210020
(report) =>
1001310021
report?.pendingFields?.preview !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
10014-
isReportOutstanding(report, policyID, reportNameValuePairs) &&
10022+
isReportOutstanding(report, policyID, reportNameValuePairs, allowSubmitted) &&
1001510023
report?.ownerAccountID === reportOwnerAccountID,
1001610024
)
1001710025
.sort((a, b) => localeCompare(a?.reportName?.toLowerCase() ?? '', b?.reportName?.toLowerCase() ?? ''));

src/pages/Search/SearchTransactionsChangeReport.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function SearchTransactionsChangeReport() {
4545
backTo={undefined}
4646
transactionsReports={transactionsReports}
4747
selectReport={selectReport}
48+
isEditing
4849
/>
4950
);
5051
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {ListItem} from '@components/SelectionList/types';
44
import useOnyx from '@hooks/useOnyx';
55
import {changeTransactionsReport} from '@libs/actions/Transaction';
66
import Navigation from '@libs/Navigation/Navigation';
7+
import CONST from '@src/CONST';
78
import ONYXKEYS from '@src/ONYXKEYS';
89
import type SCREENS from '@src/SCREENS';
910
import IOURequestEditReportCommon from './IOURequestEditReportCommon';
@@ -18,7 +19,7 @@ type TransactionGroupListItem = ListItem & {
1819
type IOURequestEditReportProps = WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.EDIT_REPORT>;
1920

2021
function IOURequestEditReport({route}: IOURequestEditReportProps) {
21-
const {backTo, reportID} = route.params;
22+
const {backTo, reportID, action} = route.params;
2223

2324
const {selectedTransactionIDs, clearSelectedTransactions} = useSearchContext();
2425

@@ -40,6 +41,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
4041
backTo={backTo}
4142
transactionsReports={transactionReport ? [transactionReport] : []}
4243
selectReport={selectReport}
44+
isEditing={action === CONST.IOU.ACTION.EDIT}
4345
/>
4446
);
4547
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ type Props = {
4343
transactionsReports: Report[];
4444
policyID?: string;
4545
selectReport: (item: TransactionGroupListItem) => void;
46+
isEditing?: boolean;
4647
};
4748

48-
function IOURequestEditReportCommon({backTo, transactionsReports, selectReport, policyID: policyIDFromProps}: Props) {
49+
function IOURequestEditReportCommon({backTo, transactionsReports, selectReport, policyID: policyIDFromProps, isEditing}: Props) {
4950
const {translate} = useLocalize();
5051
const {options} = useOptionsList();
5152
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: (reports) => mapOnyxCollectionItems(reports, reportSelector), canBeMissing: true});
@@ -66,10 +67,11 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport,
6667
transactionsReports.at(0)?.ownerAccountID ?? currentUserPersonalDetails.accountID,
6768
allReports ?? {},
6869
reportNameValuePairs,
70+
isEditing,
6971
);
7072
return reports;
7173
}),
72-
[allReports, currentUserPersonalDetails.accountID, transactionsReports, allPoliciesID, reportNameValuePairs, policyIDFromProps],
74+
[allReports, currentUserPersonalDetails.accountID, transactionsReports, isEditing, allPoliciesID, reportNameValuePairs, policyIDFromProps],
7375
);
7476

7577
const reportOptions: TransactionGroupListItem[] = useMemo(() => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function IOURequestStepConfirmation({
137137
*/
138138
const transactionReport = getReportOrDraftReport(transaction?.reportID);
139139
const shouldUseTransactionReport =
140-
transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id);
140+
transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false);
141141
const report = shouldUseTransactionReport ? transactionReport : (reportReal ?? reportDraft);
142142
const policy = policyReal ?? policyDraft;
143143
const isDraftPolicy = policy === policyDraft;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
120120
transactionsReports={transactionReport ? [transactionReport] : []}
121121
selectReport={selectReport}
122122
policyID={!isEditing && !isFromGlobalCreate ? reportOrDraftReport?.policyID : undefined}
123+
isEditing={isEditing}
123124
/>
124125
);
125126
}

tests/unit/ReportUtilsTest.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
113113
// Be sure to include the mocked permissions library or else the beta tests won't work
114114
jest.mock('@libs/Permissions');
115115

116+
jest.mock('@libs/Navigation/Navigation', () => ({
117+
setNavigationActionToMicrotaskQueue: jest.fn(),
118+
navigationRef: {
119+
getCurrentRoute: jest.fn(() => ({
120+
params: {
121+
reportID: '2',
122+
},
123+
})),
124+
},
125+
}));
126+
116127
const testDate = DateUtils.getDBTime();
117128
const currentUserEmail = 'bjorn@vikings.net';
118129
const currentUserAccountID = 5;
@@ -3695,6 +3706,34 @@ describe('ReportUtils', () => {
36953706
};
36963707
expect(isReportOutstanding(report, policy.id)).toBe(true);
36973708
});
3709+
it('should return false for submitted reports if we specify it', () => {
3710+
const report: Report = {
3711+
...createRandomReport(1),
3712+
policyID: policy.id,
3713+
type: CONST.REPORT.TYPE.EXPENSE,
3714+
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
3715+
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
3716+
};
3717+
expect(isReportOutstanding(report, policy.id, undefined, false)).toBe(false);
3718+
});
3719+
it('should return true for submitted reports if top most report ID is processing', async () => {
3720+
const report: Report = {
3721+
...createRandomReport(1),
3722+
policyID: policy.id,
3723+
type: CONST.REPORT.TYPE.EXPENSE,
3724+
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
3725+
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
3726+
};
3727+
const activeReport: Report = {
3728+
...createRandomReport(2),
3729+
policyID: policy.id,
3730+
type: CONST.REPORT.TYPE.EXPENSE,
3731+
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
3732+
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
3733+
};
3734+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${activeReport.reportID}`, activeReport);
3735+
expect(isReportOutstanding(report, policy.id)).toBe(true);
3736+
});
36983737
it('should return false for archived report', async () => {
36993738
const report: Report = {
37003739
...createRandomReport(1),

0 commit comments

Comments
 (0)