Skip to content

Commit c46f457

Browse files
authored
Merge pull request Expensify#69116 from Expensify/vit-fix69052
[CP Staging] Revert "Merge pull request Expensify#68508 from daledah/fix/67098"
2 parents 648b2d6 + ba0d19c commit c46f457

4 files changed

Lines changed: 18 additions & 137 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8278,11 +8278,7 @@ type ReportErrorsAndReportActionThatRequiresAttention = {
82788278
reportAction?: OnyxEntry<ReportAction>;
82798279
};
82808280

8281-
function getAllReportActionsErrorsAndReportActionThatRequiresAttention(
8282-
report: OnyxEntry<Report>,
8283-
reportActions: OnyxEntry<ReportActions>,
8284-
isReportArchived = false,
8285-
): ReportErrorsAndReportActionThatRequiresAttention {
8281+
function getAllReportActionsErrorsAndReportActionThatRequiresAttention(report: OnyxEntry<Report>, reportActions: OnyxEntry<ReportActions>): ReportErrorsAndReportActionThatRequiresAttention {
82868282
const reportActionsArray = Object.values(reportActions ?? {}).filter((action) => !isDeletedAction(action));
82878283
const reportActionErrors: ErrorFields = {};
82888284
let reportAction: OnyxEntry<ReportAction>;
@@ -8301,7 +8297,11 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(
83018297
? undefined
83028298
: allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
83038299

8304-
if (!isReportArchived) {
8300+
// This will get removed as part of https://github.com/Expensify/App/issues/59961
8301+
// eslint-disable-next-line deprecation/deprecation
8302+
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);
8303+
8304+
if (!isArchivedReport(reportNameValuePairs)) {
83058305
if (wasActionTakenByCurrentUser(parentReportAction) && isTransactionThread(parentReportAction)) {
83068306
const transactionID = isMoneyRequestAction(parentReportAction) ? getOriginalMessage(parentReportAction)?.IOUTransactionID : null;
83078307
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
@@ -8329,9 +8329,9 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(
83298329
/**
83308330
* Get an object of error messages keyed by microtime by combining all error objects related to the report.
83318331
*/
8332-
function getAllReportErrors(report: OnyxEntry<Report>, reportActions: OnyxEntry<ReportActions>, isReportArchived = false): Errors {
8332+
function getAllReportErrors(report: OnyxEntry<Report>, reportActions: OnyxEntry<ReportActions>): Errors {
83338333
const reportErrorFields = report?.errorFields ?? {};
8334-
const {errors: reportActionErrors} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions, isReportArchived);
8334+
const {errors: reportActionErrors} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions);
83358335

83368336
// All error objects related to the report. Each object in the sources contains error messages keyed by microtime
83378337
const errorSources = {
@@ -11325,13 +11325,13 @@ function generateReportAttributes({
1132511325
chatReport,
1132611326
reportActions,
1132711327
transactionViolations,
11328-
isReportArchived = false,
11328+
reportNameValuePairs,
1132911329
}: {
1133011330
report: OnyxEntry<Report>;
1133111331
chatReport: OnyxEntry<Report>;
1133211332
reportActions?: OnyxCollection<ReportActions>;
1133311333
transactionViolations: OnyxCollection<TransactionViolation[]>;
11334-
isReportArchived: boolean;
11334+
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>;
1133511335
}) {
1133611336
const reportActionsList = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.reportID}`];
1133711337
const parentReportActionsList = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`];
@@ -11340,10 +11340,11 @@ function generateReportAttributes({
1134011340
const doesReportHasViolations = hasReportViolations(report?.reportID);
1134111341
const hasViolationsToDisplayInLHN = shouldDisplayViolationsRBRInLHN(report, transactionViolations);
1134211342
const hasAnyTypeOfViolations = hasViolationsToDisplayInLHN || (!isReportSettled && isCurrentUserReportOwner && doesReportHasViolations);
11343-
const reportErrors = getAllReportErrors(report, reportActionsList, isReportArchived);
11343+
const reportErrors = getAllReportErrors(report, reportActionsList);
1134411344
const hasErrors = Object.entries(reportErrors ?? {}).length > 0;
1134511345
const oneTransactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, reportActionsList);
1134611346
const parentReportAction = report?.parentReportActionID ? parentReportActionsList?.[report.parentReportActionID] : undefined;
11347+
const isReportArchived = !!reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]?.private_isArchived;
1134711348
const requiresAttention = requiresAttentionFromCurrentUser(report, parentReportAction, isReportArchived);
1134811349

1134911350
return {
@@ -11355,6 +11356,7 @@ function generateReportAttributes({
1135511356
oneTransactionThreadReportID,
1135611357
parentReportAction,
1135711358
requiresAttention,
11359+
isReportArchived,
1135811360
};
1135911361
}
1136011362

src/libs/SidebarUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ function getReasonAndReportActionThatHasRedBrickRoad(
541541
transactionViolations?: OnyxCollection<TransactionViolation[]>,
542542
isReportArchived = false,
543543
): ReasonAndReportActionThatHasRedBrickRoad | null {
544-
const {reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions, isReportArchived);
544+
const {reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions);
545545
const errors = reportErrors;
546546
const hasErrors = Object.keys(errors).length !== 0;
547547

src/libs/actions/OnyxDerived/configs/reportAttributes.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {generateIsEmptyReport, generateReportAttributes, generateReportName, isArchivedReport, isValidReport} from '@libs/ReportUtils';
1+
import {generateIsEmptyReport, generateReportAttributes, generateReportName, isValidReport} from '@libs/ReportUtils';
22
import SidebarUtils from '@libs/SidebarUtils';
33
import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig';
44
import {hasKeyTriggeredCompute} from '@userActions/OnyxDerived/utils';
@@ -128,13 +128,12 @@ export default createOnyxDerivedValueConfig({
128128

129129
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`];
130130
const reportActionsList = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`];
131-
const isReportArchived = isArchivedReport(reportNameValuePairs);
132-
const {hasAnyViolations, requiresAttention, reportErrors} = generateReportAttributes({
131+
const {hasAnyViolations, requiresAttention, isReportArchived, reportErrors} = generateReportAttributes({
133132
report,
134133
chatReport,
135134
reportActions,
136135
transactionViolations,
137-
isReportArchived,
136+
reportNameValuePairs,
138137
});
139138

140139
let brickRoadStatus;

tests/unit/ReportUtilsTest.ts

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
canUserPerformWriteAction,
3535
findLastAccessedReport,
3636
getAllAncestorReportActions,
37-
getAllReportActionsErrorsAndReportActionThatRequiresAttention,
3837
getApprovalChain,
3938
getChatByParticipants,
4039
getDefaultWorkspaceAvatar,
@@ -79,7 +78,7 @@ import {buildOptimisticTransaction} from '@libs/TransactionUtils';
7978
import CONST from '@src/CONST';
8079
import IntlStore from '@src/languages/IntlStore';
8180
import ONYXKEYS from '@src/ONYXKEYS';
82-
import type {Beta, OnyxInputOrEntry, PersonalDetailsList, Policy, PolicyEmployeeList, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction} from '@src/types/onyx';
81+
import type {Beta, OnyxInputOrEntry, PersonalDetailsList, Policy, PolicyEmployeeList, Report, ReportAction, ReportNameValuePairs, Transaction} from '@src/types/onyx';
8382
import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon';
8483
import type {Participant} from '@src/types/onyx/Report';
8584
import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet';
@@ -5412,123 +5411,4 @@ describe('ReportUtils', () => {
54125411
});
54135412
});
54145413
});
5415-
5416-
describe('getAllReportActionsErrorsAndReportActionThatRequiresAttention', () => {
5417-
const report: Report = {
5418-
...createRandomReport(40003),
5419-
parentReportID: '40004',
5420-
parentReportActionID: '2',
5421-
};
5422-
const parentReport: Report = {
5423-
...createRandomReport(40004),
5424-
statusNum: 0,
5425-
};
5426-
const reportAction1: ReportAction = {
5427-
...createRandomReportAction(1),
5428-
reportID: report.reportID,
5429-
};
5430-
const parentReportAction1: ReportAction = {
5431-
...createRandomReportAction(2),
5432-
reportID: '40004',
5433-
actorAccountID: currentUserAccountID,
5434-
};
5435-
const reportActions = [reportAction1, parentReportAction1].reduce<ReportActions>((acc, action) => {
5436-
if (action.reportActionID) {
5437-
acc[action.reportActionID] = action;
5438-
}
5439-
return acc;
5440-
}, {});
5441-
beforeEach(async () => {
5442-
await Onyx.clear();
5443-
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
5444-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
5445-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, parentReport);
5446-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportAction1.reportID}`, {
5447-
[reportAction1.reportActionID]: reportAction1,
5448-
});
5449-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportAction1.reportID}`, {
5450-
[parentReportAction1.reportActionID]: parentReportAction1,
5451-
});
5452-
5453-
return waitForBatchedUpdates();
5454-
});
5455-
it("should return nothing when there's no actions required", () => {
5456-
expect(getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions, false)).toEqual({
5457-
errors: {},
5458-
reportAction: undefined,
5459-
});
5460-
});
5461-
it("should return error with report action when there's actions required", async () => {
5462-
const reportActionWithError: ReportAction = {
5463-
...createRandomReportAction(1),
5464-
reportID: report.reportID,
5465-
errors: {
5466-
reportID: 'Error message',
5467-
accountID: 'Error in accountID',
5468-
},
5469-
};
5470-
const reportActionsWithError = {
5471-
...reportActions,
5472-
[reportActionWithError.reportActionID]: reportActionWithError,
5473-
};
5474-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportActionWithError.reportID}`, {
5475-
[reportActionWithError.reportActionID]: reportActionWithError,
5476-
});
5477-
await waitForBatchedUpdates();
5478-
expect(getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActionsWithError, false)).toEqual({
5479-
errors: {
5480-
reportID: 'Error message',
5481-
accountID: 'Error in accountID',
5482-
},
5483-
reportAction: reportActionWithError,
5484-
});
5485-
});
5486-
it("should return smart scan error with no report action when there's actions required and report is not archived", async () => {
5487-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportAction1.reportID}`, {
5488-
[parentReportAction1.reportActionID]: {
5489-
actorAccountID: currentUserAccountID,
5490-
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
5491-
originalMessage: {
5492-
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
5493-
IOUTransactionID: '12345',
5494-
},
5495-
},
5496-
});
5497-
const transaction: Transaction = {
5498-
...createRandomTransaction(12345),
5499-
reportID: parentReport.reportID,
5500-
amount: 0,
5501-
};
5502-
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction);
5503-
await waitForBatchedUpdates();
5504-
const {errors, reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions, false);
5505-
expect(Object.keys(errors)).toHaveLength(1);
5506-
expect(Object.keys(errors).at(0)).toBe('smartscan');
5507-
expect(Object.keys(errors.smartscan ?? {})).toHaveLength(1);
5508-
expect(errors.smartscan?.[Object.keys(errors.smartscan)[0]]).toEqual('Transaction is missing fields');
5509-
expect(reportAction).toBeUndefined();
5510-
});
5511-
it("should return no error and no report action when there's actions required and report is archived", async () => {
5512-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportAction1.reportID}`, {
5513-
[parentReportAction1.reportActionID]: {
5514-
actorAccountID: currentUserAccountID,
5515-
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
5516-
originalMessage: {
5517-
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
5518-
IOUTransactionID: '12345',
5519-
},
5520-
},
5521-
});
5522-
const transaction: Transaction = {
5523-
...createRandomTransaction(12345),
5524-
reportID: parentReport.reportID,
5525-
amount: 0,
5526-
};
5527-
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction);
5528-
await waitForBatchedUpdates();
5529-
const {errors, reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions, true);
5530-
expect(Object.keys(errors)).toHaveLength(0);
5531-
expect(reportAction).toBeUndefined();
5532-
});
5533-
});
55345414
});

0 commit comments

Comments
 (0)