Skip to content

Commit fedd2df

Browse files
committed
chore: update getLastMessageTextForReport
1 parent e0344f8 commit fedd2df

7 files changed

Lines changed: 11 additions & 29 deletions

File tree

src/components/LHNOptionsList/LHNOptionsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
212212
}
213213
: null;
214214
}
215-
const lastMessageTextFromReport = getLastMessageTextForReport(item, lastActorDetails, itemPolicy, itemReportNameValuePairs);
215+
const lastMessageTextFromReport = getLastMessageTextForReport(item, lastActorDetails, itemPolicy, !!itemReportNameValuePairs?.private_isArchived);
216216

217217
const shouldShowRBRorGBRTooltip = firstReportIDWithGBRorRBR === reportID;
218218

src/components/ReportActionItem/TaskView.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
6262
const isOpen = isOpenTaskReport(report);
6363
const isCompleted = isCompletedTaskReport(report);
6464
const isParentReportArchived = useReportIsArchived(parentReport?.reportID);
65-
const isReportArchived = useReportIsArchived(report?.reportID);
6665
const isTaskModifiable = canModifyTask(report, currentUserPersonalDetails.accountID, isParentReportArchived);
6766
const isTaskActionable = canActionTask(report, currentUserPersonalDetails.accountID, parentReport, isParentReportArchived);
6867

@@ -74,15 +73,15 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
7473
() => ({
7574
anchor: null,
7675
report,
77-
isReportArchived,
76+
isReportArchived: undefined,
7877
action,
7978
transactionThreadReport: undefined,
8079
checkIfContextMenuActive: () => {},
8180
isDisabled: true,
8281
onShowContextMenu: (callback: () => void) => callback(),
8382
shouldDisplayContextMenu: false,
8483
}),
85-
[report, action, isReportArchived],
84+
[report, action],
8685
);
8786

8887
const attachmentContextValue = useMemo(() => ({type: CONST.ATTACHMENT_TYPE.ONBOARDING, accountID}), [accountID]);

src/libs/OptionsListUtils.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ import {
125125
getUpgradeWorkspaceMessage,
126126
hasIOUWaitingOnCurrentUserBankAccount,
127127
isArchivedNonExpenseReport,
128-
isArchivedReport,
129128
isChatThread,
130129
isDefaultRoom,
131130
isDM,
@@ -717,20 +716,15 @@ function hasHiddenDisplayNames(accountIDs: number[]) {
717716
/**
718717
* Get the last message text from the report directly or from other sources for special cases.
719718
*/
720-
function getLastMessageTextForReport(
721-
report: OnyxEntry<Report>,
722-
lastActorDetails: Partial<PersonalDetails> | null,
723-
policy?: OnyxEntry<Policy>,
724-
reportNameValuePairs?: OnyxInputOrEntry<ReportNameValuePairs>,
725-
): string {
719+
function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails: Partial<PersonalDetails> | null, policy?: OnyxEntry<Policy>, isReportArchived?: boolean): string {
726720
const reportID = report?.reportID;
727721
const lastReportAction = reportID ? lastVisibleReportActions[reportID] : undefined;
728722

729723
// some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action
730724
const lastOriginalReportAction = reportID ? lastReportActions[reportID] : undefined;
731725
let lastMessageTextFromReport = '';
732726

733-
if (isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived)) {
727+
if (isArchivedNonExpenseReport(report, isReportArchived)) {
734728
const archiveReason =
735729
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
736730
(isClosedAction(lastOriginalReportAction) && getOriginalMessage(lastOriginalReportAction)?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT;
@@ -856,7 +850,7 @@ function getLastMessageTextForReport(
856850
// we do not want to show report closed in LHN for non archived report so use getReportLastMessage as fallback instead of lastMessageText from report
857851
if (
858852
reportID &&
859-
!isArchivedReport(reportNameValuePairs) &&
853+
!isReportArchived &&
860854
(report.lastActionType === CONST.REPORT.ACTIONS.TYPE.CLOSED || (lastOriginalReportAction?.reportActionID && isDeletedAction(lastOriginalReportAction)))
861855
) {
862856
return lastMessageTextFromReport || (getReportLastMessage(reportID).lastMessageText ?? '');
@@ -971,7 +965,7 @@ function createOption(accountIDs: number[], personalDetails: OnyxInputOrEntry<Pe
971965
const lastActorAccountID = report.lastActorAccountID || lastAction?.actorAccountID;
972966
const lastActorDetails = lastActorAccountID ? (personalDetails?.[lastActorAccountID] ?? null) : null;
973967
const lastActorDisplayName = getLastActorDisplayName(lastActorDetails);
974-
const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails, undefined, reportNameValuePairs);
968+
const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails, undefined, !!reportNameValuePairs?.private_isArchived);
975969
let lastMessageText = lastMessageTextFromReport;
976970

977971
const shouldDisplayLastActorName =

src/libs/SidebarUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ function getOptionData({
648648
const lastActorDisplayName = getLastActorDisplayName(lastActorDetails);
649649
let lastMessageTextFromReport = lastMessageTextFromReportProp;
650650
if (!lastMessageTextFromReport) {
651-
lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails, policy, reportNameValuePairs);
651+
lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails, policy, !!reportNameValuePairs?.private_isArchived);
652652
}
653653

654654
// We need to remove sms domain in case the last message text has a phone number mention with sms domain.

src/pages/TransactionDuplicate/Confirmation.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
1515
import Text from '@components/Text';
1616
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1717
import useLocalize from '@hooks/useLocalize';
18-
import useReportIsArchived from '@hooks/useReportIsArchived';
1918
import useReviewDuplicatesNavigation from '@hooks/useReviewDuplicatesNavigation';
2019
import useThemeStyles from '@hooks/useThemeStyles';
2120
import Navigation from '@libs/Navigation/Navigation';
@@ -49,7 +48,6 @@ function Confirmation() {
4948
const reportAction = Object.values(reportActions ?? {}).find(
5049
(action) => ReportActionsUtils.isMoneyRequestAction(action) && ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID === reviewDuplicates?.transactionID,
5150
);
52-
const isReportArchived = useReportIsArchived(report?.reportID);
5351

5452
const transactionsMergeParams = useMemo(() => TransactionUtils.buildMergeDuplicatesParams(reviewDuplicates, transaction), [reviewDuplicates, transaction]);
5553
const isReportOwner = iouReport?.ownerAccountID === currentUserPersonalDetails?.accountID;
@@ -74,11 +72,11 @@ function Confirmation() {
7472
report,
7573
checkIfContextMenuActive: () => {},
7674
onShowContextMenu: () => {},
77-
isReportArchived,
75+
isReportArchived: undefined,
7876
anchor: null,
7977
isDisabled: false,
8078
}),
81-
[report, reportAction, isReportArchived],
79+
[report, reportAction],
8280
);
8381

8482
const reportTransactionID = report?.reportID ? getTransactionID(report.reportID) : undefined;

src/pages/home/report/PureReportActionItem.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ type PureReportActionItemProps = {
270270
/** Linked transaction route error */
271271
linkedTransactionRouteError?: Errors;
272272

273-
/** Optional property for report name-value pairs */
274-
reportNameValuePairs?: OnyxTypes.ReportNameValuePairs;
275-
276273
/** Optional property to indicate if the user is validated */
277274
isUserValidated?: boolean;
278275

@@ -398,7 +395,6 @@ function PureReportActionItem({
398395
iouReportOfLinkedReport,
399396
emojiReactions,
400397
linkedTransactionRouteError,
401-
reportNameValuePairs,
402398
isUserValidated,
403399
parentReport,
404400
personalDetails,
@@ -1232,8 +1228,7 @@ function PureReportActionItem({
12321228
index={index}
12331229
ref={composerTextInputRef}
12341230
shouldDisableEmojiPicker={
1235-
(chatIncludesConcierge(report) && isBlockedFromConcierge(blockedFromConcierge)) ||
1236-
isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived)
1231+
(chatIncludesConcierge(report) && isBlockedFromConcierge(blockedFromConcierge)) || isArchivedNonExpenseReport(report, isReportArchived)
12371232
}
12381233
isGroupPolicyReport={!!report?.policyID && report.policyID !== CONST.POLICY.ID_FAKE}
12391234
/>
@@ -1590,7 +1585,6 @@ export default memo(PureReportActionItem, (prevProps, nextProps) => {
15901585
prevProps.iouReport?.reportID === nextProps.iouReport?.reportID &&
15911586
deepEqual(prevProps.emojiReactions, nextProps.emojiReactions) &&
15921587
deepEqual(prevProps.linkedTransactionRouteError, nextProps.linkedTransactionRouteError) &&
1593-
deepEqual(prevProps.reportNameValuePairs, nextProps.reportNameValuePairs) &&
15941588
prevProps.isUserValidated === nextProps.isUserValidated &&
15951589
prevProps.parentReport?.reportID === nextProps.parentReport?.reportID &&
15961590
deepEqual(prevProps.personalDetails, nextProps.personalDetails) &&

src/pages/home/report/ReportActionItem.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ function ReportActionItem({allReports, action, report, transactions, shouldShowD
6868
canBeMissing: true,
6969
selector: (transaction) => transaction?.errorFields?.route ?? null,
7070
});
71-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- This is needed to prevent the app from crashing when the app is using imported state.
72-
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`, {canBeMissing: true});
7371

7472
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true});
7573
// The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here.
@@ -99,7 +97,6 @@ function ReportActionItem({allReports, action, report, transactions, shouldShowD
9997
iouReportOfLinkedReport={iouReportOfLinkedReport}
10098
emojiReactions={emojiReactions}
10199
linkedTransactionRouteError={linkedTransactionRouteError}
102-
reportNameValuePairs={reportNameValuePairs}
103100
isUserValidated={isUserValidated}
104101
parentReport={parentReport}
105102
personalDetails={personalDetails}

0 commit comments

Comments
 (0)