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
9 changes: 3 additions & 6 deletions src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
const report = changedReportsEntries[reportKey];
const reportID = reportKey.replace(ONYXKEYS.COLLECTION.REPORT, '');
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
const {reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, chatReport, reportAttributes?.reports);
const {reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, reportAttributes?.reports);

if (reportOption) {
updatedReportsMap.set(reportID, reportOption);
Expand Down Expand Up @@ -169,8 +168,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
const reportID = key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, '');
const reportItem = updatedReportsMap.get(reportID)?.item;
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportItem?.chatReportID}`];
const {reportOption} = processReport(reportItem, personalDetails, privateIsArchived, currentUserAccountID, chatReport, reportAttributes?.reports);
const {reportOption} = processReport(reportItem, personalDetails, privateIsArchived, currentUserAccountID, reportAttributes?.reports);

if (reportOption) {
updatedReportsMap.set(reportID, reportOption);
Expand Down Expand Up @@ -240,8 +238,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
}

const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`];
const newReportOption = createOptionFromReport(report, personalDetails, currentUserAccountID, chatReport, privateIsArchived, reportAttributes?.reports, {
const newReportOption = createOptionFromReport(report, personalDetails, currentUserAccountID, privateIsArchived, reportAttributes?.reports, {
showPersonalDetails: true,
});
const replaceIndex = options.reports.findIndex((option) => option.reportID === report.reportID);
Expand Down
5 changes: 1 addition & 4 deletions src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
const selectedOptions: OptionData[] = selectedReportIDs.map((id) => {
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${id}`];
const reportData = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`];
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportData?.chatReportID}`];
const report = getSelectedOptionData(
createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, chatReport, privateIsArchived, reportAttributesDerived),
);
const report = getSelectedOptionData(createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, privateIsArchived, reportAttributesDerived));
const isReportArchived = !!privateIsArchived;
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`];
const alternateText = getAlternateText(report, {}, isReportArchived, currentUserEmail, policy, {}, undefined, undefined, reportAttributesDerived);
Expand Down
3 changes: 1 addition & 2 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
}

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

Expand Down
5 changes: 2 additions & 3 deletions src/hooks/useUserToInviteReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import ONYXKEYS from '@src/ONYXKEYS';
import useOnyx from './useOnyx';

/**
* For policy expense chat invitees, resolves the expense report and its associated chat report.
* For policy expense chat invitees, resolves the expense report.
*/
export default function useUserToInviteReports(userToInvite: SearchOptionData | null | undefined) {
const userToInviteReportID = userToInvite?.isPolicyExpenseChat ? userToInvite.reportID : undefined;
const [userToInviteExpenseReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(userToInviteReportID)}`);
const [userToInviteChatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(userToInviteExpenseReport?.chatReportID)}`);

return {userToInviteExpenseReport, userToInviteChatReport};
return {userToInviteExpenseReport};
}
64 changes: 12 additions & 52 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@

let allReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,

Check warning on line 210 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

Check warning on line 210 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

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

let allReportNameValuePairsOnyxConnect: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,

Check warning on line 219 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

Check warning on line 219 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
waitForCollectionCallback: true,
callback: (value) => {
allReportNameValuePairsOnyxConnect = value;
Expand All @@ -225,9 +225,10 @@

const lastReportActions: ReportActions = {};
const allSortedReportActions: Record<string, ReportAction[]> = {};
const cachedOneTransactionThreadReportIDs: Record<string, string | undefined> = {};
let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,

Check warning on line 231 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

Check warning on line 231 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
waitForCollectionCallback: true,
callback: (actions) => {
if (!actions) {
Expand All @@ -251,7 +252,10 @@

// If the report is a one-transaction report, we need to return the combined reportActions so that the LHN can display modifications
// to the transaction thread or the report itself.
// Cache the result for O(1) lookup in renderItem.
const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, actions[reportActions[0]]);
cachedOneTransactionThreadReportIDs[reportID] = transactionThreadReportID;

if (transactionThreadReportID) {
const transactionThreadReportActionsArray = Object.values(actions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? {});
sortedReportActions = getCombinedReportActions(sortedReportActions, transactionThreadReportID, transactionThreadReportActionsArray, reportID);
Expand All @@ -269,7 +273,7 @@

let activePolicyID: OnyxEntry<string>;
Onyx.connect({
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,

Check warning on line 276 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

Check warning on line 276 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (value) => (activePolicyID = value),
});

Expand Down Expand Up @@ -433,8 +437,6 @@
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
) {
const report = getReportOrDraftReport(option.reportID);
// TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378)
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
const isAdminRoom = reportUtilsIsAdminRoom(report);
const isAnnounceRoom = reportUtilsIsAnnounceRoom(report);
const isGroupChat = reportUtilsIsGroupChat(report);
Expand All @@ -449,7 +451,6 @@
lastActorDetails,
policy,
isReportArchived,
chatReport,
visibleReportActionsDataParam: visibleReportActionsData,
reportAttributesDerived,
currentUserLogin,
Expand Down Expand Up @@ -597,7 +598,6 @@
policy,
isReportArchived = false,
policyForMovingExpensesID,
chatReport,
reportMetadata,
visibleReportActionsDataParam,
lastAction,
Expand All @@ -613,7 +613,6 @@
policy?: OnyxEntry<Policy>;
isReportArchived?: boolean;
policyForMovingExpensesID?: string;
chatReport?: OnyxEntry<Report>;
reportMetadata?: OnyxEntry<ReportMetadata>;
visibleReportActionsDataParam?: VisibleReportActionsDerivedValue;
lastAction?: OnyxEntry<ReportAction>;
Expand All @@ -625,8 +624,7 @@
const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived);
let lastReportAction = lastAction ?? getLastVisibleAction(reportID, canUserPerformWrite, {}, undefined, visibleReportActionsDataParam);

const chatReportForTransactionThread = chatReport ?? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
const transactionThreadReportID = reportID ? getOneTransactionThreadReportID(report, chatReportForTransactionThread, allSortedReportActions[reportID]) : undefined;
const transactionThreadReportID = reportID ? cachedOneTransactionThreadReportIDs[reportID] : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute transaction-thread lookup when report data updates

getLastMessageTextForReport() now relies exclusively on cachedOneTransactionThreadReportIDs, but that cache is only populated inside the REPORT_ACTIONS subscription. If report/chatReport is unavailable when that callback runs (or if chatReportID is updated later), the cached value stays undefined and we stop including transaction-thread actions in preview generation for one-transaction reports, so LHN/search previews can show stale parent-report text until another report-action update happens.

Useful? React with 👍 / 👎.


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chatReport is only used to get send money action which is not much used.

const sendMoneyFlow = getSendMoneyFlowAction(reportActions, chatReport);
if (sendMoneyFlow?.childReportID) {
return sendMoneyFlow;
}

This flow test well though

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. The cache is populated in the REPORT_ACTIONS Onyx callback which already has access to allReports, so chatReport is resolved there. The only edge case would be a chatReportID update without a corresponding REPORT_ACTIONS change, but that does not happen in practice since chatReportID is set at report creation time.

if (reportID && !lastAction && transactionThreadReportID) {
lastReportAction =
Expand Down Expand Up @@ -953,7 +951,6 @@
personalDetails: OnyxInputOrEntry<PersonalDetailsList>,
report: OnyxInputOrEntry<Report>,
currentUserAccountID: number,
chatReport: OnyxEntry<Report>,
config?: PreviewConfig,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
privateIsArchived?: string,
Expand Down Expand Up @@ -1042,7 +1039,6 @@
report,
lastActorDetails,
isReportArchived: !!result.private_isArchived,
chatReport,
visibleReportActionsDataParam: visibleReportActionsData,
reportAttributesDerived,
currentUserLogin,
Expand Down Expand Up @@ -1117,16 +1113,13 @@
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
): OptionData {
const report = getReportOrDraftReport(participant.reportID, undefined, undefined, reportDrafts);
// TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378)
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
const visibleParticipantAccountIDs = getParticipantsAccountIDsForDisplay(report, true);

const option = createOption(
visibleParticipantAccountIDs,
personalDetails ?? {},
!isEmptyObject(report) ? report : undefined,
currentUserAccountID,
chatReport,
{
showChatPreviewLine: false,
forcePolicyNamePreview: false,
Expand Down Expand Up @@ -1176,7 +1169,6 @@
currentUserAccountID: number,
personalDetails: OnyxEntry<PersonalDetailsList>,
privateIsArchived: string | undefined,
chatReport: OnyxEntry<Report>,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
): OptionData {
Expand All @@ -1187,7 +1179,6 @@
personalDetails ?? {},
!isEmptyObject(report) ? report : undefined,
currentUserAccountID,
chatReport,
{
showChatPreviewLine: false,
forcePolicyNamePreview: false,
Expand Down Expand Up @@ -1229,7 +1220,6 @@
currentUserAccountID: number,
personalDetails: OnyxEntry<PersonalDetailsList>,
expenseReport: OnyxEntry<Report>,
chatReport: OnyxEntry<Report>,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
): SearchOptionData {
Expand All @@ -1242,7 +1232,6 @@
personalDetails ?? {},
!isEmptyObject(expenseReport) ? expenseReport : null,
currentUserAccountID,
chatReport,
{
showChatPreviewLine: false,
forcePolicyNamePreview: false,
Expand Down Expand Up @@ -1360,7 +1349,6 @@
personalDetails: OnyxEntry<PersonalDetailsList>,
privateIsArchived: string | undefined,
currentUserAccountID: number,
chatReport: OnyxEntry<Report>,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
): {
Expand All @@ -1386,7 +1374,7 @@
reportMapEntry,
reportOption: {
item: report,
...createOption(accountIDs, personalDetails, report, currentUserAccountID, chatReport, undefined, reportAttributesDerived, privateIsArchived, visibleReportActionsData),
...createOption(accountIDs, personalDetails, report, currentUserAccountID, undefined, reportAttributesDerived, privateIsArchived, visibleReportActionsData),
},
};
}
Expand All @@ -1407,16 +1395,7 @@
if (reports) {
for (const report of Object.values(reports)) {
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`];
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
const {reportMapEntry, reportOption} = processReport(
report,
personalDetails,
privateIsArchived,
currentUserAccountID,
chatReport,
reportAttributesDerived,
visibleReportActionsData,
);
const {reportMapEntry, reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, reportAttributesDerived, visibleReportActionsData);

if (reportMapEntry) {
const [accountID, reportValue] = reportMapEntry;
Expand All @@ -1432,16 +1411,13 @@
const allPersonalDetailsOptions = Object.values(personalDetails ?? {}).map((personalDetail) => {
const report = reportMapForAccountIDs[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID];
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`];
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];

return {
item: personalDetail,
...createOption(
[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID],
personalDetails,
report,
currentUserAccountID,
chatReport,
{
showPersonalDetails: true,
},
Expand Down Expand Up @@ -1540,8 +1516,7 @@
const reportOptions: Array<SearchOption<Report>> = [];
for (const report of limitedReports) {
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
const {reportMapEntry, reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, chatReport, reportAttributesDerived, visibleReportActionsData);
const {reportMapEntry, reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, reportAttributesDerived, visibleReportActionsData);

if (reportMapEntry) {
const [accountID, reportValue] = reportMapEntry;
Expand Down Expand Up @@ -1571,15 +1546,13 @@

const report = reportMapForAccountIDs[accountID];
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`];
const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
return {
item: personalDetail,
...createOption(
[accountID],
personalDetails,
reportMapForAccountIDs[accountID],
currentUserAccountID,
chatReport,
{showPersonalDetails: true},
reportAttributesDerived,
privateIsArchived,
Expand All @@ -1599,7 +1572,6 @@
report: Report,
personalDetails: OnyxEntry<PersonalDetailsList>,
currentUserAccountID: number,
chatReport: OnyxEntry<Report>,
privateIsArchived: string | undefined,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
config?: PreviewConfig,
Expand All @@ -1609,7 +1581,7 @@

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

Expand Down Expand Up @@ -1933,17 +1905,7 @@
login: searchValue,
},
};
const userToInvite = createOption(
[optimisticAccountID],
personalDetailsExtended,
null,
currentUserAccountID,
undefined,
{showChatPreviewLine},
undefined,
undefined,
visibleReportActionsData,
);
const userToInvite = createOption([optimisticAccountID], personalDetailsExtended, null, currentUserAccountID, {showChatPreviewLine}, undefined, undefined, visibleReportActionsData);
userToInvite.isOptimisticAccount = true;
userToInvite.login = searchValue;

Expand Down Expand Up @@ -2934,9 +2896,8 @@
if (isReportPolicyExpenseChat) {
// TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378)
const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`];
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`];
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`];
return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived);
return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, reportAttributesDerived);
}
return getParticipantsOption(participant, personalDetails);
})
Expand Down Expand Up @@ -2967,9 +2928,8 @@
if (isReportPolicyExpenseChat) {
// TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378)
const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`];
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`];
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`];
return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived);
return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, reportAttributesDerived);
}
return getParticipantsOption(participant, personalDetails);
})
Expand Down
Loading
Loading