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
3 changes: 2 additions & 1 deletion src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
const personalDetails = usePersonalDetails();
const prevPersonalDetails = usePrevious(personalDetails);
const hasInitialData = useMemo(() => Object.keys(personalDetails ?? {}).length > 0, [personalDetails]);
const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});

const loadOptions = useCallback(() => {
const optionLists = createOptionList(personalDetails, reports, reportAttributes?.reports);
Expand Down Expand Up @@ -162,7 +163,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
reports: Array.from(updatedReportsMap.values()),
};
});
}, [changedReportActions, personalDetails, reportAttributes?.reports]);
}, [changedReportActions, personalDetails, reportAttributes?.reports, transactions]);

/**
* This effect is used to update the options list when personal details change.
Expand Down
13 changes: 10 additions & 3 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import type {Attendee, Participant} from '@src/types/onyx/IOU';
import type {Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import type {OriginalMessageMovedTransaction} from '@src/types/onyx/OriginalMessage';
import type {SearchTransaction} from '@src/types/onyx/SearchResults';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import Timing from './actions/Timing';
import {getEnabledCategoriesCount} from './CategoryUtils';
Expand Down Expand Up @@ -332,7 +333,7 @@
*/
let currentUserLogin: string | undefined;
let currentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 336 in src/libs/OptionsListUtils.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 @@ -341,19 +342,19 @@
});

let loginList: OnyxEntry<Login>;
Onyx.connect({

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

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

Check warning on line 351 in src/libs/OptionsListUtils.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 357 in src/libs/OptionsListUtils.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 @@ -365,14 +366,14 @@
});

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

Check warning on line 369 in src/libs/OptionsListUtils.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({

Check warning on line 376 in src/libs/OptionsListUtils.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 @@ -381,7 +382,7 @@
});

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

Check warning on line 385 in src/libs/OptionsListUtils.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 @@ -393,7 +394,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
const lastVisibleReportActions: ReportActions = {};
Onyx.connect({

Check warning on line 397 in src/libs/OptionsListUtils.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 Down Expand Up @@ -452,13 +453,13 @@
});

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

Check warning on line 456 in src/libs/OptionsListUtils.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),
});

let nvpDismissedProductTraining: OnyxEntry<DismissedProductTraining>;
Onyx.connect({

Check warning on line 462 in src/libs/OptionsListUtils.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_DISMISSED_PRODUCT_TRAINING,
callback: (value) => (nvpDismissedProductTraining = value),
});
Expand Down Expand Up @@ -904,6 +905,7 @@
report: OnyxInputOrEntry<Report>,
config?: PreviewConfig,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
transactions?: SearchTransaction[],
): OptionData {
const {showChatPreviewLine = false, forcePolicyNamePreview = false, showPersonalDetails = false, selected, isSelected, isDisabled} = config ?? {};
const result: OptionData = {
Expand Down Expand Up @@ -1014,7 +1016,9 @@
// If displaying chat preview line is needed, let's overwrite the default alternate text
result.alternateText = showPersonalDetails && personalDetail?.login ? personalDetail.login : getAlternateText(result, {showChatPreviewLine, forcePolicyNamePreview});

reportName = showPersonalDetails ? getDisplayNameForParticipant({accountID: accountIDs.at(0)}) || formatPhoneNumber(personalDetail?.login ?? '') : getReportName(report);
reportName = showPersonalDetails
? getDisplayNameForParticipant({accountID: accountIDs.at(0)}) || formatPhoneNumber(personalDetail?.login ?? '')
: getReportName(report, undefined, undefined, undefined, undefined, undefined, transactions);
} else {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
reportName = getDisplayNameForParticipant({accountID: accountIDs.at(0)}) || formatPhoneNumber(personalDetail?.login ?? '');
Expand Down Expand Up @@ -1248,6 +1252,7 @@
report: OnyxEntry<Report>,
personalDetails: OnyxEntry<PersonalDetailsList>,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
transactions?: SearchTransaction[],
): {
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 @@ -1271,7 +1276,7 @@
reportMapEntry,
reportOption: {
item: report,
...createOption(accountIDs, personalDetails, report, undefined, reportAttributesDerived),
...createOption(accountIDs, personalDetails, report, undefined, reportAttributesDerived, transactions),
},
};
}
Expand Down Expand Up @@ -2713,7 +2718,9 @@
return false;
}
for (let i = 0; i < a.reports.length; i++) {
if (a.reports.at(i)?.reportID !== b.reports.at(i)?.reportID) {
const aReport = a.reports.at(i);
const bReport = b.reports.at(i);
if (aReport?.reportID !== bReport?.reportID || aReport?.text !== bReport?.text) {
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5025,6 +5025,7 @@ function getReportName(
personalDetails?: Partial<PersonalDetailsList>,
invoiceReceiverPolicy?: OnyxEntry<Policy>,
reportAttributes?: ReportAttributesDerivedValue['reports'],
transactions?: SearchTransaction[],
): string {
// Check if we can use report name in derived values - only when we have report but no other params
const canUseDerivedValue = report && policy === undefined && parentReportActionParam === undefined && personalDetails === undefined && invoiceReceiverPolicy === undefined;
Expand All @@ -5033,7 +5034,7 @@ function getReportName(
if (canUseDerivedValue && derivedNameExists) {
return attributes[report.reportID].reportName;
}
return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy});
return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy, transactions});
}

function getSearchReportName(props: GetReportNameParams): string {
Expand Down
Loading