Skip to content

Commit

Permalink
Merge pull request #48285 from mkzie2/mkzie2-issue-47655
Browse files Browse the repository at this point in the history
  • Loading branch information
cead22 authored Sep 9, 2024
2 parents 7ddbd56 + a2e09ec commit fe44ab2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails} from '@src/types/onyx';
import OptionRowLHNData from './OptionRowLHNData';
import type {LHNOptionsListProps, RenderItemProps} from './types';

Expand Down Expand Up @@ -148,6 +149,20 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
}
const lastReportActionTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${lastReportActionTransactionID}`];

// SidebarUtils.getOptionData in OptionRowLHNData does not get re-evaluated when the linked task report changes, so we have the lastMessageTextFromReport evaluation logic here
let lastActorDetails: Partial<PersonalDetails> | null =
itemFullReport?.lastActorAccountID && personalDetails?.[itemFullReport.lastActorAccountID] ? personalDetails[itemFullReport.lastActorAccountID] : null;
if (!lastActorDetails && lastReportAction) {
const lastActorDisplayName = lastReportAction?.person?.[0]?.text;
lastActorDetails = lastActorDisplayName
? {
displayName: lastActorDisplayName,
accountID: itemFullReport?.lastActorAccountID,
}
: null;
}
const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(itemFullReport, lastActorDetails, itemPolicy);

return (
<OptionRowLHNData
reportID={reportID}
Expand All @@ -163,6 +178,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
receiptTransactions={transactions}
viewMode={optionMode}
isFocused={!shouldDisableFocusOptions}
lastMessageTextFromReport={lastMessageTextFromReport}
onSelectRow={onSelectRow}
preferredLocale={preferredLocale}
hasDraftComment={hasDraftComment}
Expand Down
3 changes: 3 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function OptionRowLHNData({
transaction,
lastReportActionTransaction,
transactionViolations,
lastMessageTextFromReport,
...propsToForward
}: OptionRowLHNDataProps) {
const reportID = propsToForward.reportID;
Expand All @@ -49,6 +50,7 @@ function OptionRowLHNData({
policy,
parentReportAction,
hasViolations: !!shouldDisplayViolations || shouldDisplayReportViolations,
lastMessageTextFromReport,
transactionViolations,
invoiceReceiverPolicy,
});
Expand Down Expand Up @@ -76,6 +78,7 @@ function OptionRowLHNData({
receiptTransactions,
invoiceReceiverPolicy,
shouldDisplayReportViolations,
lastMessageTextFromReport,
]);

return (
Expand Down
3 changes: 3 additions & 0 deletions src/components/LHNOptionsList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ type OptionRowLHNDataProps = {
/** Toggle between compact and default view */
viewMode?: OptionMode;

/** The last message text from the report */
lastMessageTextFromReport: string;

/** A function that is called when an option is selected. Selected option is passed as a param */
onSelectRow?: (optionItem: OptionData, popoverAnchor: RefObject<View>) => void;

Expand Down
8 changes: 7 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ function getOptionData({
policy,
parentReportAction,
hasViolations,
lastMessageTextFromReport: lastMessageTextFromReportProp,
transactionViolations,
invoiceReceiverPolicy,
}: {
Expand All @@ -250,6 +251,7 @@ function getOptionData({
policy: OnyxEntry<Policy> | undefined;
parentReportAction: OnyxEntry<ReportAction> | undefined;
hasViolations: boolean;
lastMessageTextFromReport?: string;
invoiceReceiverPolicy?: OnyxEntry<Policy>;
transactionViolations?: OnyxCollection<TransactionViolation[]>;
}): ReportUtils.OptionData | undefined {
Expand Down Expand Up @@ -384,7 +386,11 @@ function getOptionData({
}

const lastActorDisplayName = OptionsListUtils.getLastActorDisplayName(lastActorDetails, hasMultipleParticipants);
const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy);

let lastMessageTextFromReport = lastMessageTextFromReportProp;
if (!lastMessageTextFromReport) {
lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy);
}

// We need to remove sms domain in case the last message text has a phone number mention with sms domain.
let lastMessageText = Str.removeSMSDomain(lastMessageTextFromReport);
Expand Down

0 comments on commit fe44ab2

Please sign in to comment.