Skip to content
Open
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
1 change: 1 addition & 0 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type {BlockingViewProps} from '@components/BlockingViews/BlockingView';
import BlockingView from '@components/BlockingViews/BlockingView';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';

Check warning on line 13 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used by a pattern. Direct imports from Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details

Check warning on line 13 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used. Direct imports from @components/Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details
import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider';
import TextBlock from '@components/TextBlock';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
Expand Down Expand Up @@ -233,6 +233,7 @@
policy: itemPolicy,
isReportArchived: !!itemReportNameValuePairs?.private_isArchived,
policyForMovingExpensesID,
chatReport,
});

const shouldShowRBRorGBRTooltip = firstReportIDWithGBRorRBR === reportID;
Expand Down
3 changes: 2 additions & 1 deletion src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
continue;
}

const newReportOption = createOptionFromReport(report, personalDetails, reportAttributes?.reports, {showPersonalDetails: true});
const chatReport = report.chatReportID ? reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`] : undefined;
const newReportOption = createOptionFromReport(report, personalDetails, reportAttributes?.reports, {showPersonalDetails: true}, chatReport);
const replaceIndex = options.reports.findIndex((option) => option.reportID === report.reportID);
newReportOptions.push({
newReportOption,
Expand Down
4 changes: 3 additions & 1 deletion src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen

const selectedOptions = useMemo<OptionData[]>(() => {
return selectedReportIDs.map((id) => {
const report = getSelectedOptionData(createOptionFromReport({...reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reportID: id}, personalDetails, reportAttributesDerived));
const reportData = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`];
const chatReport = reportData?.chatReportID ? reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportData.chatReportID}`] : undefined;
const report = getSelectedOptionData(createOptionFromReport({...reportData, reportID: id}, personalDetails, reportAttributesDerived, undefined, chatReport));
const isReportArchived = archivedReportsIdSet.has(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`);
const alternateText = getAlternateText(report, {}, isReportArchived, {});
return {...report, alternateText};
Expand Down
3 changes: 2 additions & 1 deletion src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
return undefined;
}

const option = createOptionFromReport(report, personalDetails, undefined, {showPersonalDetails: true});
const chatReport = report.chatReportID ? reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`] : undefined;
const option = createOptionFromReport(report, personalDetails, undefined, {showPersonalDetails: true}, chatReport);
reportForContextualSearch = option;
}

Expand Down
86 changes: 48 additions & 38 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
*/
let currentUserLogin: string | undefined;
let currentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 193 in src/libs/OptionsListUtils/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.SESSION,
callback: (value) => {
currentUserLogin = value?.email;
Expand All @@ -199,13 +199,13 @@
});

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

Check warning on line 202 in src/libs/OptionsListUtils/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 = isEmptyObject(value) ? {} : value),
});

const policies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 208 in src/libs/OptionsListUtils/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.POLICY,
callback: (policy, key) => {
if (!policy || !key || !policy.name) {
Expand All @@ -217,23 +217,14 @@
});

let allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 220 in src/libs/OptionsListUtils/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.POLICY,
waitForCollectionCallback: true,
callback: (val) => (allPolicies = val),
});

let allReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
allReports = value;
},
});

let allReportNameValuePairs: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({

Check warning on line 227 in src/libs/OptionsListUtils/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_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -245,7 +236,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
const lastVisibleReportActions: ReportActions = {};
Onyx.connect({

Check warning on line 239 in src/libs/OptionsListUtils/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,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -265,8 +256,8 @@
const reportActionsArray = Object.values(reportActions[1] ?? {});
let sortedReportActions = getSortedReportActions(withDEWRoutedActionsArray(reportActionsArray), true);
allSortedReportActions[reportID] = sortedReportActions;
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
const report = getReportOrDraftReport(reportID);
const chatReport = getReportOrDraftReport(report?.chatReportID);

// If the report is a one-transaction report and has , we need to return the combined reportActions so that the LHN can display modifications
// to the transaction thread or the report itself
Expand Down Expand Up @@ -307,7 +298,7 @@
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 301 in src/libs/OptionsListUtils/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_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});
Expand Down Expand Up @@ -464,12 +455,13 @@
lastActorDetails: Partial<PersonalDetails> | null = {},
) {
const report = getReportOrDraftReport(option.reportID);
const chatReport = getReportOrDraftReport(report?.chatReportID);
const isAdminRoom = reportUtilsIsAdminRoom(report);
const isAnnounceRoom = reportUtilsIsAnnounceRoom(report);
const isGroupChat = reportUtilsIsGroupChat(report);
const isExpenseThread = isMoneyRequest(report);
const formattedLastMessageText =
formatReportLastMessageText(Parser.htmlToText(option.lastMessageText ?? '')) || getLastMessageTextForReport({report, lastActorDetails, isReportArchived});
formatReportLastMessageText(Parser.htmlToText(option.lastMessageText ?? '')) || getLastMessageTextForReport({report, lastActorDetails, isReportArchived, chatReport});
const reportPrefix = getReportSubtitlePrefix(report);
const formattedLastMessageTextWithPrefix = reportPrefix + formattedLastMessageText;

Expand Down Expand Up @@ -597,6 +589,7 @@
policy,
isReportArchived = false,
policyForMovingExpensesID,
chatReport,
}: {
report: OnyxEntry<Report>;
lastActorDetails: Partial<PersonalDetails> | null;
Expand All @@ -605,6 +598,7 @@
policy?: OnyxEntry<Policy>;
isReportArchived?: boolean;
policyForMovingExpensesID?: string;
chatReport?: OnyxEntry<Report>;
}): string {
const reportID = report?.reportID;
const lastReportAction = reportID ? lastVisibleReportActions[reportID] : undefined;
Expand Down Expand Up @@ -803,7 +797,6 @@
}

if (reportID && !lastMessageTextFromReport && lastReportAction) {
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
// If the report is a one-transaction report, get the last message text from combined report actions so the LHN can display modifications to the transaction thread or the report itself
const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]);
if (transactionThreadReportID) {
Expand Down Expand Up @@ -833,6 +826,7 @@
report: OnyxInputOrEntry<Report>,
config?: PreviewConfig,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
chatReport?: OnyxEntry<Report>,
): SearchOptionData {
const {showChatPreviewLine = false, forcePolicyNamePreview = false, showPersonalDetails = false, selected, isSelected, isDisabled} = config ?? {};

Expand Down Expand Up @@ -907,14 +901,14 @@

// If displaying chat preview line is needed, let's overwrite the default alternate text
const lastActorDetails = personalDetails?.[report?.lastActorAccountID ?? String(CONST.DEFAULT_NUMBER_ID)] ?? {};
result.lastMessageText = getLastMessageTextForReport({report, lastActorDetails, isReportArchived: !!result.private_isArchived});
result.lastMessageText = getLastMessageTextForReport({report, lastActorDetails, isReportArchived: !!result.private_isArchived, chatReport});
result.alternateText =
showPersonalDetails && personalDetail?.login
? personalDetail.login
: getAlternateText(result, {showChatPreviewLine, forcePolicyNamePreview}, !!result.private_isArchived, lastActorDetails);

const personalDetailsForCompute: PersonalDetailsList | undefined = personalDetails ?? undefined;
const computedReportName = computeReportName(report, allReports, allPolicies, undefined, allReportNameValuePairs, personalDetailsForCompute, allReportActions);
const computedReportName = computeReportName(report, undefined, allPolicies, undefined, allReportNameValuePairs, personalDetailsForCompute, allReportActions);
reportName = showPersonalDetails
? getDisplayNameForParticipant({accountID: accountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils}) || formatPhoneNumberPhoneUtils(personalDetail?.login ?? '')
: computedReportName;
Expand Down Expand Up @@ -1171,6 +1165,7 @@
report: OnyxEntry<Report> | null,
personalDetails: OnyxEntry<PersonalDetailsList>,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
chatReport?: OnyxEntry<Report>,
): {
reportMapEntry?: [number, Report]; // The entry to add to reportMapForAccountIDs if applicable
reportOption: SearchOption<Report> | null; // The report option to add to allReportOptions if applicable
Expand All @@ -1194,7 +1189,7 @@
reportMapEntry,
reportOption: {
item: report,
...createOption(accountIDs, personalDetails, report, undefined, reportAttributesDerived),
...createOption(accountIDs, personalDetails, report, undefined, reportAttributesDerived, chatReport),
},
};
}
Expand All @@ -1207,7 +1202,8 @@

if (reports) {
for (const report of Object.values(reports)) {
const {reportMapEntry, reportOption} = processReport(report, personalDetails, reportAttributesDerived);
const chatReport = report?.chatReportID ? reports[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`] : undefined;
const {reportMapEntry, reportOption} = processReport(report, personalDetails, reportAttributesDerived, chatReport);

if (reportMapEntry) {
const [accountID, reportValue] = reportMapEntry;
Expand All @@ -1220,18 +1216,23 @@
}
}

const allPersonalDetailsOptions = Object.values(personalDetails ?? {}).map((personalDetail) => ({
item: personalDetail,
...createOption(
[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID],
personalDetails,
reportMapForAccountIDs[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID],
{
showPersonalDetails: true,
},
reportAttributesDerived,
),
}));
const allPersonalDetailsOptions = Object.values(personalDetails ?? {}).map((personalDetail) => {
const mappedReport = reportMapForAccountIDs[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID];
const chatReport = mappedReport?.chatReportID && reports ? reports[`${ONYXKEYS.COLLECTION.REPORT}${mappedReport.chatReportID}`] : undefined;
return {
item: personalDetail,
...createOption(
[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID],
personalDetails,
mappedReport,
{
showPersonalDetails: true,
},
reportAttributesDerived,
chatReport,
),
};
});

span.setAttributes({
personalDetails: allPersonalDetailsOptions.length,
Expand Down Expand Up @@ -1317,7 +1318,8 @@
// Step 5: Process the limited set of reports (performance optimization)
const reportOptions: Array<SearchOption<Report>> = [];
for (const report of limitedReports) {
const {reportMapEntry, reportOption} = processReport(report, personalDetails, reportAttributesDerived);
const chatReport = report?.chatReportID ? reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`] : undefined;
const {reportMapEntry, reportOption} = processReport(report, personalDetails, reportAttributesDerived, chatReport);

if (reportMapEntry) {
const [accountID, reportValue] = reportMapEntry;
Expand All @@ -1344,10 +1346,12 @@
const personalDetailsOptions = includeP2P
? Object.values(personalDetails ?? {}).map((personalDetail) => {
const accountID = personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID;
const mappedReport = reportMapForAccountIDs[accountID];
const chatReport = mappedReport?.chatReportID ? reports?.[`${ONYXKEYS.COLLECTION.REPORT}${mappedReport.chatReportID}`] : undefined;

return {
item: personalDetail,
...createOption([accountID], personalDetails, reportMapForAccountIDs[accountID], {showPersonalDetails: true}, reportAttributesDerived),
...createOption([accountID], personalDetails, mappedReport, {showPersonalDetails: true}, reportAttributesDerived, chatReport),
};
})
: [];
Expand All @@ -1358,12 +1362,18 @@
};
}

function createOptionFromReport(report: Report, personalDetails: OnyxEntry<PersonalDetailsList>, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], config?: PreviewConfig) {
function createOptionFromReport(
report: Report,
personalDetails: OnyxEntry<PersonalDetailsList>,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
config?: PreviewConfig,
chatReport?: OnyxEntry<Report>,
) {
const accountIDs = getParticipantsAccountIDsForDisplay(report);

return {
item: report,
...createOption(accountIDs, personalDetails, report, config, reportAttributesDerived),
...createOption(accountIDs, personalDetails, report, config, reportAttributesDerived, chatReport),
};
}

Expand Down Expand Up @@ -1798,7 +1808,7 @@
return userToInvite;
}

function isValidReport(option: SearchOption<Report>, config: IsValidReportsConfig, draftComment: string | undefined): boolean {
function isValidReport(option: SearchOption<Report>, config: IsValidReportsConfig, draftComment: string | undefined, chatReport?: OnyxEntry<Report>): boolean {
const {
betas = [],
includeMultipleParticipantReports = false,
Expand All @@ -1819,8 +1829,6 @@
preferredPolicyID,
} = config;
const topmostReportId = Navigation.getTopmostReportId();

const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${option.item.chatReportID}`];
const doesReportHaveViolations = shouldDisplayViolationsRBRInLHN(option.item, transactionViolations);

const shouldBeInOptionList = shouldReportBeInOptionList({
Expand Down Expand Up @@ -1973,12 +1981,12 @@

let isOptionUnread = option.isUnread;
if (shouldUnreadBeBold) {
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`];
const chatReport = getReportOrDraftReport(report.chatReportID);
const oneTransactionThreadReportID =
report.type === CONST.REPORT.TYPE.IOU || report.type === CONST.REPORT.TYPE.EXPENSE || report.type === CONST.REPORT.TYPE.INVOICE
? getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[report.reportID])
: undefined;
const oneTransactionThreadReport = oneTransactionThreadReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionThreadReportID}`] : undefined;
const oneTransactionThreadReport = oneTransactionThreadReportID ? getReportOrDraftReport(oneTransactionThreadReportID) : undefined;

isOptionUnread = isUnread(report, oneTransactionThreadReport, !!option.private_isArchived) && !!report.lastActorAccountID;
}
Expand Down Expand Up @@ -2154,6 +2162,7 @@
}

const draftComment = draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`];
const chatReport = getReportOrDraftReport(report.item.chatReportID);

return isValidReport(
report,
Expand All @@ -2164,6 +2173,7 @@
loginsToExclude,
},
draftComment,
chatReport,
);
};

Expand Down
4 changes: 3 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import {
// eslint-disable-next-line @typescript-eslint/no-deprecated
getReportName,
getReportNotificationPreference,
getReportOrDraftReport,
getReportParticipantsTitle,
getReportSubtitlePrefix,
getUnreportedTransactionMessage,
Expand Down Expand Up @@ -792,7 +793,8 @@ function getOptionData({
const lastActorDisplayName = getLastActorDisplayName(lastActorDetails);
let lastMessageTextFromReport = lastMessageTextFromReportProp;
if (!lastMessageTextFromReport) {
lastMessageTextFromReport = getLastMessageTextForReport({report, lastActorDetails, movedFromReport, movedToReport, policy, isReportArchived});
const chatReport = getReportOrDraftReport(report?.chatReportID);
lastMessageTextFromReport = getLastMessageTextForReport({report, lastActorDetails, movedFromReport, movedToReport, policy, isReportArchived, chatReport});
}

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