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 @@ -726,7 +726,7 @@
setIsFloatingMessageCounterVisible(false);

if (!hasNewestReportAction) {
openReport(report.reportID, introSelected);
openReport({reportID: report.reportID, introSelected});
reportScrollManager.scrollToEnd();
return;
}
Expand All @@ -734,7 +734,7 @@
reportScrollManager.scrollToEnd();
readActionSkipped.current = false;
readNewestAction(report.reportID, !!reportMetadata?.hasOnceLoadedReportActions);
}, [setIsFloatingMessageCounterVisible, hasNewestReportAction, reportScrollManager, report.reportID, reportMetadata?.hasOnceLoadedReportActions]);

Check warning on line 737 in src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has a missing dependency: 'introSelected'. Either include it or remove the dependency array

Check warning on line 737 in src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a missing dependency: 'introSelected'. Either include it or remove the dependency array

const scrollToNewTransaction = useCallback(
(pageY: number) => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function AuthScreens() {
} else {
const reportID = getReportIDFromLink(initialURL ?? null);
if (reportID && !isAuthenticatedAtStartup) {
Report.openReport(reportID, introSelected);
Report.openReport({reportID, introSelected});
// Don't want to call `openReport` again when logging out and then logging in
setIsAuthenticatedAtStartup(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function openReportFromDeepLink(url: string, reports: OnyxCollection<Report>, is
});

// Call the OpenReport command to check in the server if it's a public room. If so, we'll open it as an anonymous user
openReport(reportID, introSelected, undefined, [], undefined, '0', true);
openReport({reportID, introSelected, parentReportActionID: '0', isFromDeepLink: true});

// Show the sign-in page if the app is offline
if (networkStatus === CONST.NETWORK.NETWORK_STATUS.OFFLINE) {
Expand Down
150 changes: 101 additions & 49 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,56 @@
type?: string;
};

type OpenReportActionParams = {
/** The ID of the report to open */
reportID: string | undefined;

/** The intro selected by the user */
introSelected: OnyxEntry<IntroSelected>;

/** The ID used to fetch a specific range of report actions related to the current reportActionID when opening a chat */
reportActionID?: string;

/** The list of users that are included in a new chat, not including the user creating it */
participantLoginList?: string[];

/** The optimistic report object created when making a new chat, saved as optimistic data */
newReportObject?: OptimisticChatReport;

/** The parent report action that a thread was created from (only passed for new threads) */
parentReportActionID?: string;

/** Whether or not this report is being opened from a deep link */
isFromDeepLink?: boolean;

/** The list of accountIDs that are included in a new chat, not including the user creating it */
participantAccountIDList?: number[];

/** Whether this is a new thread being created */
isNewThread?: boolean;

/** The transaction object for legacy transactions that don't have a transaction thread or money request preview yet */
transaction?: Transaction;

/** The violations for the transaction, if any */
transactionViolations?: TransactionViolations;

/** The parent report ID for the transaction thread (optional, defaults to transaction.reportID) */
parentReportID?: string;

/** Whether to add pending fields to the report */
shouldAddPendingFields?: boolean;

/** The optimistic selfDM report when it exists on the server but was filtered out from OpenApp response (e.g., no actions yet) */
optimisticSelfDMReport?: Report;

/** The current user's login */
currentUserLogin?: string;

/** The current user's account ID */
currentUserAccountID?: number;
};

type PregeneratedResponseParams = {
optimisticConciergeReportActionID: string;
pregeneratedResponse: string;
Expand Down Expand Up @@ -315,7 +365,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 368 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -327,7 +377,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 380 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -336,7 +386,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 389 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand All @@ -354,7 +404,7 @@
});

let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({

Check warning on line 407 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ONBOARDING,
callback: (val) => {
if (Array.isArray(val)) {
Expand All @@ -365,7 +415,7 @@
});

let deprecatedIntroSelected: OnyxEntry<IntroSelected> = {};
Onyx.connect({

Check warning on line 418 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (val) => (deprecatedIntroSelected = val),
});
Expand Down Expand Up @@ -1181,39 +1231,26 @@
/**
* Gets the latest page of report actions and updates the last read message
* If a chat with the passed reportID is not found, we will create a chat based on the passed participantList
*
* @param reportID The ID of the report to open
* @param reportActionID The ID used to fetch a specific range of report actions related to the current reportActionID when opening a chat.
* @param participantLoginList The list of users that are included in a new chat, not including the user creating it
* @param newReportObject The optimistic report object created when making a new chat, saved as optimistic data
* @param parentReportActionID The parent report action that a thread was created from (only passed for new threads)
* @param isFromDeepLink Whether or not this report is being opened from a deep link
* @param participantAccountIDList The list of accountIDs that are included in a new chat, not including the user creating it
* @param isNewThread Whether this is a new thread being created
* @param transaction The transaction object for legacy transactions that don't have a transaction thread or money request preview yet
* @param transactionViolations The violations for the transaction, if any
* @param parentReportID The parent report ID for the transaction thread (optional, defaults to transaction.reportID)
* @param optimisticSelfDMReport The optimistic selfDM report when it exists on the server but was filtered out from OpenApp response (e.g., no actions yet)
Comment on lines -1185 to -1196

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 think we should keep these comments

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.

@dukenv0307 How about this?

*/
// eslint-disable-next-line @typescript-eslint/max-params
function openReport(
reportID: string | undefined,
introSelected: OnyxEntry<IntroSelected>,
reportActionID?: string,
participantLoginList: string[] = [],
newReportObject?: OptimisticChatReport,
parentReportActionID?: string,
isFromDeepLink = false,
participantAccountIDList: number[] = [],
isNewThread = false,
transaction?: Transaction,
transactionViolations?: TransactionViolations,
parentReportID?: string,
shouldAddPendingFields = true,
optimisticSelfDMReport?: Report,
currentUserLogin?: string,
currentUserAccountID?: number,
) {
function openReport(params: OpenReportActionParams) {
const {
reportID,
introSelected,
reportActionID,
participantLoginList = [],
newReportObject,
parentReportActionID,
isFromDeepLink = false,
participantAccountIDList = [],
isNewThread = false,
transaction,
transactionViolations,
parentReportID,
shouldAddPendingFields = true,
optimisticSelfDMReport,
currentUserLogin,
currentUserAccountID,
} = params;
if (!reportID) {
return;
}
Expand Down Expand Up @@ -1868,24 +1905,20 @@
const optimisticTransactionThreadReportID = generateReportID();
const optimisticTransactionThread = buildTransactionThread(iouReportAction, reportToUse, undefined, optimisticTransactionThreadReportID);
const shouldAddPendingFields = transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || iouReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD;
openReport(
optimisticTransactionThreadReportID,
openReport({
reportID: optimisticTransactionThreadReportID,
introSelected,
undefined,
currentUserLogin ? [currentUserLogin] : [],
optimisticTransactionThread,
iouReportAction?.reportActionID,
false,
[],
false,
participantLoginList: currentUserLogin ? [currentUserLogin] : [],
newReportObject: optimisticTransactionThread,
parentReportActionID: iouReportAction?.reportActionID,
transaction,
transactionViolations,
selfDMReportID,
parentReportID: selfDMReportID,
shouldAddPendingFields,
optimisticSelfDMReport,
currentUserLogin,
currentUserAccountID,
);
});
return optimisticTransactionThread;
}

Expand Down Expand Up @@ -1933,7 +1966,7 @@
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
});
// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport(newChat?.reportID, introSelected, '', userLogins, newChat);
openReport({reportID: newChat?.reportID, introSelected, reportActionID: '', participantLoginList: userLogins, newReportObject: newChat});
}
const report = isEmptyObject(chat) ? newChat : chat;

Expand Down Expand Up @@ -1971,7 +2004,13 @@
participantList: [...participantAccountIDs, currentUserAccountID],
});
// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport(newChat?.reportID, deprecatedIntroSelected, '', [], newChat, '0', false, participantAccountIDs);
openReport({
reportID: newChat?.reportID,
introSelected: deprecatedIntroSelected,
newReportObject: newChat,
parentReportActionID: '0',
participantAccountIDList: participantAccountIDs,
});
}
const report = chat ?? newChat;

Expand Down Expand Up @@ -2018,7 +2057,14 @@
const childReportID = childReport?.reportID ?? parentReportAction.childReportID;
if (!childReportID) {
const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(Object.keys(newChat.participants ?? {}).map(Number));
openReport(newChat.reportID, deprecatedIntroSelected, '', participantLogins, newChat, parentReportAction.reportActionID, undefined, undefined, true);
openReport({
reportID: newChat.reportID,
introSelected: deprecatedIntroSelected,
participantLoginList: participantLogins,
newReportObject: newChat,
parentReportActionID: parentReportAction.reportActionID,
isNewThread: true,
});
} else {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${childReportID}`, newChat);
}
Expand Down Expand Up @@ -2804,7 +2850,7 @@
prevNotificationPreference?: NotificationPreference,
) {
if (childReportID) {
openReport(childReportID, deprecatedIntroSelected);
openReport({reportID: childReportID, introSelected: deprecatedIntroSelected});
const parentReportActionID = parentReportAction.reportActionID;
if (!prevNotificationPreference || isHiddenForCurrentUser(prevNotificationPreference)) {
updateNotificationPreference(
Expand Down Expand Up @@ -2839,7 +2885,13 @@
});

const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(participantAccountIDs);
openReport(newChat.reportID, deprecatedIntroSelected, '', participantLogins, newChat, parentReportAction.reportActionID);
openReport({
reportID: newChat.reportID,
introSelected: deprecatedIntroSelected,
participantLoginList: participantLogins,
newReportObject: newChat,
parentReportActionID: parentReportAction.reportActionID,
});
const notificationPreference = isHiddenForCurrentUser(prevNotificationPreference) ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
updateNotificationPreference(newChat.reportID, prevNotificationPreference, notificationPreference, currentUserAccountID, parentReport?.reportID, parentReportAction.reportActionID);
}
Expand Down Expand Up @@ -6966,7 +7018,7 @@
});
}

export type {Video, GuidedSetupData, TaskForParameters, IntroSelected};
export type {Video, GuidedSetupData, TaskForParameters, IntroSelected, OpenReportActionParams};

export {
addAttachmentWithComment,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/replaceOptimisticReportWithActualReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ function replaceOptimisticReportWithActualReport(report: Report, draftReportComm
callback();

// We are already on the parent one expense report, so just call the API to fetch report data
openReport(parentReportID, undefined);
openReport({reportID: parentReportID, introSelected: undefined});
});
} else {
callback();

// We are already on the parent one expense report, so just call the API to fetch report data
openReport(parentReportID, undefined);
openReport({reportID: parentReportID, introSelected: undefined});
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Search/SearchMoneyRequestReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
}
Navigation.dismissModal();
}
}, [report]);

Check warning on line 100 in src/pages/Search/SearchMoneyRequestReportPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useEffect has missing dependencies: 'isFocused' and 'prevReport'. Either include them or remove the dependency array

useEffect(() => {
// Update last visit time when the expense super wide RHP report is focused
Expand Down Expand Up @@ -238,7 +238,7 @@
return;
}

openReport(reportIDFromRoute, introSelected, '', [], undefined, undefined, false, []);
openReport({reportID: reportIDFromRoute, introSelected});
isInitialMountRef.current = false;

// oneTransactionID dependency handles the case when deleting a transaction:
Expand Down
14 changes: 5 additions & 9 deletions src/pages/Share/ShareDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,12 @@ function ShareDetailsPage({route}: ShareDetailsPageProps) {
validateFileName,
(file) => {
if (isDraft) {
openReport(
report.reportID,
openReport({
reportID: report.reportID,
introSelected,
'',
displayReport.participantsList?.filter((u) => u.accountID !== personalDetail.accountID).map((u) => u.login ?? '') ?? [],
report,
undefined,
undefined,
undefined,
);
participantLoginList: displayReport.participantsList?.filter((u) => u.accountID !== personalDetail.accountID).map((u) => u.login ?? '') ?? [],
newReportObject: report,
});
}
if (report.reportID) {
addAttachmentWithComment({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/TransactionDuplicate/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function TransactionDuplicateReview() {
if (!route.params.threadReportID || report?.reportID) {
return;
}
openReport(route.params.threadReportID, introSelected);
openReport({reportID: route.params.threadReportID, introSelected});
}, [report?.reportID, route.params.threadReportID, introSelected]);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/inbox/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr
}
}

openReport(reportIDFromRoute, introSelected, reportActionIDFromRoute);
openReport({reportID: reportIDFromRoute, introSelected, reportActionID: reportActionIDFromRoute});
}, [reportMetadata.isOptimisticReport, report, isOffline, isLoadingApp, introSelected, isOnboardingCompleted, isInviteOnboardingComplete, reportIDFromRoute, reportActionIDFromRoute]);

useEffect(() => {
Expand Down Expand Up @@ -691,7 +691,7 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr
if (!shouldUseNarrowLayout || !isFocused || prevIsFocused || !isChatThread(report) || !isHiddenForCurrentUser(report) || isTransactionThreadView) {
return;
}
openReport(reportID, introSelected);
openReport({reportID, introSelected});

// We don't want to run this useEffect every time `report` is changed
// Excluding shouldUseNarrowLayout from the dependency list to prevent re-triggering on screen resize events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ const ContextMenuActions: ContextMenuAction[] = [
if (isMoneyRequestAction(reportAction) || isMoneyRequestAction(moneyRequestAction)) {
const editExpense = () => {
const childReportID = reportAction?.childReportID;
openReport(childReportID, introSelected);
openReport({reportID: childReportID, introSelected});
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(childReportID));
};
if (closePopover) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/inbox/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ function ReportActionsList({
if (!Navigation.getReportRHPActiveRoute()) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID, undefined, undefined, backTo));
}
openReport(report.reportID, introSelected);
openReport({reportID: report.reportID, introSelected});
reportScrollManager.scrollToBottom();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function <TProps extends WithReportAndReportActionOrNotFoundProps
if (!shouldUseNarrowLayout || (!isEmptyObject(report) && !isEmptyObject(linkedReportAction))) {
return;
}
openReport(props.route.params.reportID, introSelected);
openReport({reportID: props.route.params.reportID, introSelected});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [shouldUseNarrowLayout, props.route.params.reportID]);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/inbox/report/withReportOrNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function (shouldRequireReportID = true): <TProps extends WithRepo
return;
}

openReport(props.route.params.reportID, introSelected);
openReport({reportID: props.route.params.reportID, introSelected});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [shouldFetchReport, isReportLoaded, props.route.params.reportID]);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function IOURequestStepDistance({
if (!transaction?.reportID || hasRoute(transaction, true)) {
return;
}
openReport(transaction?.reportID, introSelected);
openReport({reportID: transaction?.reportID, introSelected});
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepDistanceMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function IOURequestStepDistanceMap({
if (!transaction?.reportID || hasRoute(transaction, true)) {
return;
}
openReport(transaction?.reportID, introSelected);
openReport({reportID: transaction?.reportID, introSelected});
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function <TProps extends WithWritableReportOrNotFoundProps<MoneyR
if (!!report?.reportID || !route.params.reportID || !!reportDraft || !isEditing) {
return;
}
openReport(route.params.reportID, introSelected);
openReport({reportID: route.params.reportID, introSelected});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function TransactionReceiptModalContent({navigation, route}: AttachmentModalScre
if ((!!report && !!transaction) || isDraftTransaction) {
return;
}
openReport(reportID, introSelected);
openReport({reportID, introSelected});
// 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
Loading
Loading