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
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
setIsFloatingMessageCounterVisible(false);

if (!hasNewestReportAction) {
openReport({reportID, introSelected, betas});
openReport({reportID, introSelected, betas, hasReportActions: true});
reportScrollManager.scrollToEnd();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useReportActionsScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function useReportActionsScroll({
if (!Navigation.getReportRHPActiveRoute()) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID, undefined, undefined, backTo));
}
openReport({reportID, introSelected, betas});
openReport({reportID, introSelected, betas, hasReportActions: true});
reportScrollManager.scrollToBottom();
return;
}
Expand Down
6 changes: 5 additions & 1 deletion src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ type OpenReportActionParams = {
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
hasCompletedGuidedSetupFlow?: boolean;

/** Whether the report has report actions or not */
hasReportActions?: boolean;

/** Beta features list */
betas: OnyxEntry<Beta[]>;
};
Expand Down Expand Up @@ -1482,6 +1485,7 @@ function openReport(params: OpenReportActionParams) {
currentUserAccountID,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
hasReportActions,
} = params;
if (!reportID) {
return;
Expand All @@ -1492,7 +1496,7 @@ function openReport(params: OpenReportActionParams) {
const participantAccountIDList = participants.map((p) => p.accountID).filter((id): id is number => id !== undefined);
const existingReportName = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportName;
const isCreatingNewReport = !isEmptyObject(newReportObject);
const optimisticReport: Partial<Pick<Report, 'reportName'>> = reportActionsExist(reportID) || !existingReportName ? {} : {reportName: existingReportName};
const optimisticReport: Partial<Pick<Report, 'reportName'>> = (hasReportActions ?? reportActionsExist(reportID)) || !existingReportName ? {} : {reportName: existingReportName};

const optimisticData: Array<
OnyxUpdate<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function TransactionReceiptModalContent({navigation, route}: AttachmentModalScre
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Camera', 'Download', 'Crop', 'Trashcan', 'Rotate', 'Close', 'Checkmark']);

const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [hasReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {selector: Boolean});
const allTransactions = useAllTransactions();
const transactionMain = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`];
const [transactionDraft] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${getNonEmptyStringOnyxID(transactionID)}`);
Expand Down Expand Up @@ -184,7 +185,7 @@ function TransactionReceiptModalContent({navigation, route}: AttachmentModalScre
if ((!!report && !!transaction) || isDraftTransaction) {
return;
}
openReport({reportID, introSelected, betas});
openReport({reportID, introSelected, betas, hasReportActions});
// I'm disabling the warning, as it expects to use exhaustive deps, even though we want this useEffect to run only on the first render.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ function ReportAddAttachmentModalContent({route, navigation}: AttachmentModalScr
// Extract the reportActionID from the attachmentID (format: reportActionID_index)
const reportActionID = useMemo(() => attachmentID?.split('_')?.[0], [attachmentID]);

const hasReportActions = !!reportActions;

const shouldFetchReport = useMemo(() => {
return isEmptyObject(reportActions?.[reportActionID ?? CONST.DEFAULT_NUMBER_ID]);
}, [reportActions, reportActionID]);

const fetchReport = useCallback(() => {
openReport({reportID, introSelected, reportActionID, betas});
}, [reportID, introSelected, reportActionID, betas]);
openReport({reportID, introSelected, reportActionID, betas, hasReportActions});
}, [reportID, introSelected, reportActionID, betas, hasReportActions]);

// Close the modal if user loses write access (e.g., admin switches "Who can post" to Admins only)
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function ReportAttachmentModalContent({route, navigation}: AttachmentModalScreen
} = route.params;

const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`);
const hasReportActions = !!reportActions;
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [betas] = useOnyx(ONYXKEYS.BETAS);

Expand Down Expand Up @@ -74,8 +75,8 @@ function ReportAttachmentModalContent({route, navigation}: AttachmentModalScreen
return;
}

openReport({reportID: reportActionReportID, introSelected, reportActionID, betas});
}, [reportActionReportID, shouldFetchReport, introSelected, reportActionID, betas]);
openReport({reportID: reportActionReportID, introSelected, reportActionID, betas, hasReportActions});
}, [reportActionReportID, shouldFetchReport, introSelected, reportActionID, betas, hasReportActions]);

const onCarouselAttachmentChange = (attachment: Attachment) => {
const routeToNavigate = ROUTES.REPORT_ATTACHMENTS.getRoute({
Expand Down
6 changes: 6 additions & 0 deletions tests/actions/IOUTest/DeleteMoneyRequestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
}));
// When Opening a thread report with the given details
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: TEST_INTRO_SELECTED,
betas: undefined,
Expand Down Expand Up @@ -644,6 +645,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {

// When Opening a thread report with the given details
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: TEST_INTRO_SELECTED,
betas: undefined,
Expand Down Expand Up @@ -776,6 +778,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: TEST_INTRO_SELECTED,
betas: undefined,
Expand Down Expand Up @@ -922,6 +925,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: TEST_INTRO_SELECTED,
betas: undefined,
Expand Down Expand Up @@ -1238,6 +1242,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: TEST_INTRO_SELECTED,
betas: undefined,
Expand Down Expand Up @@ -1419,6 +1424,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: TEST_INTRO_SELECTED,
betas: undefined,
Expand Down
2 changes: 2 additions & 0 deletions tests/actions/IOUTest/DuplicateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ describe('actions/Duplicate', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: transactionThreadReport1.reportID,
introSelected: undefined,
personalDetails: allPersonalDetails,
Expand All @@ -471,6 +472,7 @@ describe('actions/Duplicate', () => {
parentReportActionID: iouAction1?.reportActionID,
});
openReport({
hasReportActions: true,
reportID: transactionThreadReport2.reportID,
introSelected: undefined,
personalDetails: allPersonalDetails,
Expand Down
2 changes: 2 additions & 0 deletions tests/actions/IOUTest/TrackExpenseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,7 @@ describe('actions/IOU/TrackExpense', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: TEST_INTRO_SELECTED,
betas: undefined,
Expand Down Expand Up @@ -2549,6 +2550,7 @@ describe('actions/IOU/TrackExpense', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: TEST_INTRO_SELECTED,
betas: undefined,
Expand Down
2 changes: 2 additions & 0 deletions tests/actions/MergeTransactionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ describe('mergeTransactionRequest', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: undefined,
participants,
Expand Down Expand Up @@ -1329,6 +1330,7 @@ describe('mergeTransactionRequest', () => {
accountID: participantAccountIDs.at(index),
}));
openReport({
hasReportActions: true,
reportID: thread.reportID,
introSelected: undefined,
participants,
Expand Down
27 changes: 17 additions & 10 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ describe('actions/Report', () => {

// When the user visits the report
currentTime = DateUtils.getDBTime();
Report.openReport({reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
Report.readNewestAction(REPORT_ID, true);
waitForBatchedUpdates();
return waitForBatchedUpdates();
Expand Down Expand Up @@ -1169,6 +1169,7 @@ describe('actions/Report', () => {

for (let i = 0; i < 5; i++) {
Report.openReport({
hasReportActions: true,
reportID: REPORT_ID,
introSelected: TEST_INTRO_SELECTED,
participants: [{login: 'test@user.com'}],
Expand All @@ -1195,11 +1196,7 @@ describe('actions/Report', () => {
setHasRadio(false);
await waitForBatchedUpdates();

Report.openReport({
reportID: REPORT_ID,
introSelected: undefined,
betas: undefined,
});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined});
await waitForBatchedUpdates();

const report = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`);
Expand All @@ -1216,6 +1213,7 @@ describe('actions/Report', () => {
await waitForBatchedUpdates();

Report.openReport({
hasReportActions: true,
reportID: REPORT_ID,
introSelected: undefined,
betas: undefined,
Expand Down Expand Up @@ -1289,7 +1287,14 @@ describe('actions/Report', () => {
const transaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${TXN_ID}` as const);
expect(transaction).toBeTruthy();

Report.openReport({reportID: CHILD_REPORT_ID, introSelected: undefined, betas: undefined, transaction: transaction ?? undefined, parentReportID: SELF_DM_ID});
Report.openReport({
hasReportActions: true,
reportID: CHILD_REPORT_ID,
introSelected: undefined,
betas: undefined,
transaction: transaction ?? undefined,
parentReportID: SELF_DM_ID,
});
await waitForBatchedUpdates();

// Validate the correct Onyx key received the new action and existing one is preserved
Expand Down Expand Up @@ -1335,6 +1340,7 @@ describe('actions/Report', () => {
reportID = `${i}`;
}
Report.openReport({
hasReportActions: true,
reportID,
introSelected: TEST_INTRO_SELECTED,
participants: [{login: 'test@user.com'}],
Expand Down Expand Up @@ -2283,6 +2289,7 @@ describe('actions/Report', () => {
const reportAction = TestHelper.buildTestReportComment(created, TEST_USER_ACCOUNT_ID, reportActionID);

Report.openReport({
hasReportActions: true,
reportID: REPORT_ID,
introSelected: TEST_INTRO_SELECTED,
participants: [{login: 'test@user.com'}],
Expand Down Expand Up @@ -4873,7 +4880,7 @@ describe('actions/Report', () => {
await Onyx.set(ONYXKEYS.NVP_INTRO_SELECTED, TEST_INTRO_SELECTED);
await waitForBatchedUpdates();

Report.openReport({reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
await waitForBatchedUpdates();

TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);
Expand All @@ -4884,7 +4891,7 @@ describe('actions/Report', () => {

const REPORT_ID = '2';

Report.openReport({reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
await waitForBatchedUpdates();

TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);
Expand All @@ -4895,7 +4902,7 @@ describe('actions/Report', () => {

const REPORT_ID = '3';

Report.openReport({reportID: REPORT_ID, introSelected: undefined, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined});
await waitForBatchedUpdates();

TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);
Expand Down
Loading