Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/hooks/useOptimisticNextStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function useOptimisticNextStep(reportID: string | undefined) {
}
return acc;
}, {});
const {errors} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(moneyRequestReport, reportActionsObject, reportTransactions);
const {errors} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(moneyRequestReport, reportActionsObject, reportTransactions, accountID);

if (errors?.dewSubmitFailed) {
optimisticNextStep = buildOptimisticNextStepForDynamicExternalWorkflowSubmitError(theme.danger);
Expand Down
2 changes: 2 additions & 0 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ function getReasonAndReportActionForRBRInLHNRow(
hasViolations: boolean,
reportErrors: Errors,
isOffline: boolean,
currentUserAccountID: number,
isArchivedReport = false,
): RBRReasonAndReportAction | null {
const {reason, reportAction} =
Expand All @@ -1567,6 +1568,7 @@ function getReasonAndReportActionForRBRInLHNRow(
reportErrors,
transactions,
isOffline,
currentUserAccountID,
transactionViolations,
isArchivedReport,
) ?? {};
Expand Down
23 changes: 9 additions & 14 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5581,8 +5581,7 @@ function getReportActionWithMissingSmartscanFields(
iouReport: OnyxEntry<Report>,
iouReportID: string | undefined,
iouReportTransactions: OnyxCollection<Transaction>,
// TODO: Remove optional (?) once all callers pass currentUserAccountID. Refactor issue: https://github.com/Expensify/App/issues/66408
currentUserAccountID?: number,
currentUserAccountID: number,
): ReportAction | undefined {
const reportActions = Object.values(getAllReportActions(iouReportID));
return reportActions.find((action) => {
Expand All @@ -5608,8 +5607,7 @@ function shouldShowRBRForMissingSmartscanFields(
iouReport: OnyxEntry<Report>,
iouReportID: string | undefined,
iouReportTransactions: OnyxCollection<Transaction>,
// TODO: Remove optional (?) once all callers pass currentUserAccountID. Refactor issue: https://github.com/Expensify/App/issues/66408
currentUserAccountID?: number,
currentUserAccountID: number,
): boolean {
return !!getReportActionWithMissingSmartscanFields(iouReport, iouReportID, iouReportTransactions, currentUserAccountID);
}
Expand Down Expand Up @@ -9670,10 +9668,9 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(
report: OnyxEntry<Report>,
reportActions: OnyxEntry<ReportActions>,
allTransactions: OnyxCollection<Transaction>,
currentUserAccountID: number,
isReportArchived = false,
reports?: OnyxCollection<Report>,
// TODO: Remove optional (?) once all callers pass currentUserAccountID. Refactor issue: https://github.com/Expensify/App/issues/66408
currentUserAccountID?: number,
): ReportErrorsAndReportActionThatRequiresAttention {
const reportActionsArray = Object.values(reportActions ?? {}).filter((action) => !isDeletedAction(action));
const reportActionErrors: ErrorFields = {};
Expand All @@ -9689,9 +9686,9 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(
}
}

if (!isReportArchived && hasSmartscanError(reportActionsArray, report, allTransactions, reports, currentUserAccountID)) {
if (!isReportArchived && hasSmartscanError(reportActionsArray, report, allTransactions, currentUserAccountID, reports)) {
reportActionErrors.smartscan = getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage');
reportAction = getReportActionWithSmartscanError(reportActionsArray, report, allTransactions, reports, currentUserAccountID);
reportAction = getReportActionWithSmartscanError(reportActionsArray, report, allTransactions, currentUserAccountID, reports);
}

if (!isReportArchived && isReportOwner(report) && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN) {
Expand Down Expand Up @@ -9724,9 +9721,9 @@ function getAllReportErrors(
report,
reportActions,
allTransactions,
currentUserAccountID,
isReportArchived,
reports,
currentUserAccountID,
);

// All error objects related to the report. Each object in the sources contains error messages keyed by microtime
Expand Down Expand Up @@ -11111,9 +11108,8 @@ function getReportActionWithSmartscanError(
reportActions: ReportAction[],
report: OnyxEntry<Report>,
allTransactions: OnyxCollection<Transaction>,
currentUserAccountID: number,
reports?: OnyxCollection<Report>,
// TODO: Remove optional (?) once all callers pass currentUserAccountID. Refactor issue: https://github.com/Expensify/App/issues/66408
currentUserAccountID?: number,
): ReportAction | undefined {
return reportActions.find((action) => {
const isReportPreview = isReportPreviewAction(action);
Expand Down Expand Up @@ -11144,11 +11140,10 @@ function hasSmartscanError(
reportActions: ReportAction[],
report: OnyxEntry<Report>,
allTransactions: OnyxCollection<Transaction>,
currentUserAccountID: number,
reports?: OnyxCollection<Report>,
// TODO: Remove optional (?) once all callers pass currentUserAccountID. Refactor issue: https://github.com/Expensify/App/issues/66408
currentUserAccountID?: number,
): boolean {
return !!getReportActionWithSmartscanError(reportActions, report, allTransactions, reports, currentUserAccountID);
return !!getReportActionWithSmartscanError(reportActions, report, allTransactions, currentUserAccountID, reports);
}

function shouldAutoFocusOnKeyPress(event: KeyboardEvent): boolean {
Expand Down
5 changes: 4 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,8 @@ type ReasonAndReportActionThatHasRedBrickRoad = {
reportAction?: OnyxEntry<ReportAction>;
};

// TODO: Refactor to use options object parameter to reduce parameter count
// eslint-disable-next-line @typescript-eslint/max-params
function getReasonAndReportActionThatHasRedBrickRoad(
report: Report,
chatReport: OnyxEntry<Report>,
Expand All @@ -763,6 +765,7 @@ function getReasonAndReportActionThatHasRedBrickRoad(
reportErrors: Errors,
transactions: OnyxCollection<Transaction>,
isOffline: boolean,
currentUserAccountID: number,
transactionViolations?: OnyxCollection<TransactionViolation[]>,
isReportArchived = false,
reports?: OnyxCollection<Report>,
Expand All @@ -780,7 +783,7 @@ function getReasonAndReportActionThatHasRedBrickRoad(
};
}

const {reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions, transactions, isReportArchived, reports);
const {reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions, transactions, currentUserAccountID, isReportArchived, reports);
const errors = reportErrors;
const hasErrors = Object.keys(errors).length !== 0;

Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/OnyxDerived/configs/reportAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ export default createOnyxDerivedValueConfig({
reportErrors,
transactions,
isOffline,
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute report attributes when session changes

When REPORT_ATTRIBUTES has already been computed and ONYXKEYS.SESSION later arrives or changes (for example during startup or after switching users), the incremental path above does not include session in needsFullRecompute or the updates list and returns the existing value when there are no report/transaction deltas. Since this new argument makes smartscan RBR attribution depend on session?.accountID, a first pass that used CONST.DEFAULT_NUMBER_ID or a previous account can leave the LHN Fix/RBR action stale until some unrelated report data changes; please force a full recompute on session-triggered computes or otherwise refresh the affected reports.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a problem

transactionViolations,
!!isReportArchived,
reports,
Expand Down
1 change: 1 addition & 0 deletions src/pages/Debug/Report/DebugReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function DebugReportPage({
hasViolations,
reportAttributes?.reportErrors ?? {},
isOffline,
currentUserAccountID,
isReportArchived,
) ?? {};
const hasRBR = !!reasonRBR;
Expand Down
36 changes: 31 additions & 5 deletions tests/unit/DebugUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@ describe('DebugUtils', () => {
false,
{},
false,
RORY_ACCOUNT_ID,
) ?? {};
expect(reportAction).toBeUndefined();
});
Expand Down Expand Up @@ -1313,6 +1314,7 @@ describe('DebugUtils', () => {
false,
{},
false,
12345,
) ?? {};
expect(reportAction).toBe(undefined);
});
Expand Down Expand Up @@ -1389,6 +1391,7 @@ describe('DebugUtils', () => {
false,
reportErrors,
false,
RORY_ACCOUNT_ID,
) ?? {};
expect(reportAction).toMatchObject(MOCK_CHAT_REPORT_ACTIONS['1']);
});
Expand Down Expand Up @@ -1461,8 +1464,17 @@ describe('DebugUtils', () => {
};
const reportErrors = getAllReportErrors(MOCK_CHAT_REPORT, MOCK_REPORT_ACTIONS, mockTransactions, RORY_ACCOUNT_ID);
const {reportAction} =
DebugUtils.getReasonAndReportActionForRBRInLHNRow(MOCK_CHAT_REPORT, chatReportR14932, MOCK_REPORT_ACTIONS, mockTransactions, undefined, false, reportErrors, false) ??
{};
DebugUtils.getReasonAndReportActionForRBRInLHNRow(
MOCK_CHAT_REPORT,
chatReportR14932,
MOCK_REPORT_ACTIONS,
mockTransactions,
undefined,
false,
reportErrors,
false,
12345,
) ?? {};
expect(reportAction).toMatchObject(MOCK_REPORT_ACTIONS['3']);
});
});
Expand Down Expand Up @@ -1521,6 +1533,7 @@ describe('DebugUtils', () => {
false,
reportErrors,
false,
RORY_ACCOUNT_ID,
) ?? {};
expect(reportAction).toMatchObject(MOCK_REPORT_ACTIONS['1']);
});
Expand Down Expand Up @@ -1549,8 +1562,17 @@ describe('DebugUtils', () => {

const reportErrors = getAllReportErrors(mockedReport, mockedReportActions, sharedAllTransactions, RORY_ACCOUNT_ID);
const {reason} =
DebugUtils.getReasonAndReportActionForRBRInLHNRow(mockedReport, chatReportR14932, mockedReportActions, sharedAllTransactions, undefined, false, reportErrors, false) ??
{};
DebugUtils.getReasonAndReportActionForRBRInLHNRow(
mockedReport,
chatReportR14932,
mockedReportActions,
sharedAllTransactions,
undefined,
false,
reportErrors,
false,
RORY_ACCOUNT_ID,
) ?? {};
expect(reason).toBe('debug.reasonRBR.hasErrors');
});
it('returns correct reason when there are violations', () => {
Expand All @@ -1566,6 +1588,7 @@ describe('DebugUtils', () => {
true,
{},
false,
RORY_ACCOUNT_ID,
) ?? {};
expect(reason).toBe('debug.reasonRBR.hasViolations');
});
Expand All @@ -1582,6 +1605,7 @@ describe('DebugUtils', () => {
true,
{},
false,
RORY_ACCOUNT_ID,
true,
) ?? {};
expect(reason).toBe(undefined);
Expand Down Expand Up @@ -1638,7 +1662,7 @@ describe('DebugUtils', () => {
reportID: '1',
}),
};
const {reason} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, chatReportR14932, {}, violationTransactions, transactionViolations, false, {}, false) ?? {};
const {reason} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, chatReportR14932, {}, violationTransactions, transactionViolations, false, {}, false, 1234) ?? {};
expect(reason).toBe('debug.reasonRBR.hasTransactionThreadViolations');
});
it('forwards isOffline through to SidebarUtils so the live IOU transaction-thread receipt error surfaces only when isOffline=false excludes the deleted pending-delete action', () => {
Expand Down Expand Up @@ -1707,6 +1731,7 @@ describe('DebugUtils', () => {
false,
{},
true,
12345,
);
const online = DebugUtils.getReasonAndReportActionForRBRInLHNRow(
OFFLINE_EXPENSE_REPORT,
Expand All @@ -1717,6 +1742,7 @@ describe('DebugUtils', () => {
false,
{},
false,
12345,
);

// Online: deleted pending-delete is skipped → 1 IOU thread → receipt error surfaces.
Expand Down
Loading
Loading