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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=111 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=110 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto",
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
"check-lazy-loading": "ts-node scripts/checkLazyLoading.ts",
"lint-watch": "npx eslint-watch --watch --changed",
Expand Down
9 changes: 8 additions & 1 deletion src/components/TransactionItemRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import Text from '@components/Text';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
Expand All @@ -43,6 +44,7 @@
} from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, Policy, Report, TransactionViolation} from '@src/types/onyx';
import type {SearchTransactionAction} from '@src/types/onyx/SearchResults';
import CategoryCell from './DataCells/CategoryCell';
Expand Down Expand Up @@ -184,6 +186,7 @@
const StyleUtils = useStyleUtils();
const theme = useTheme();
const {isLargeScreenWidth} = useResponsiveLayout();
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const hasCategoryOrTag = !isCategoryMissing(transactionItem?.category) || !!transactionItem.tag;
const createdAt = getTransactionCreated(transactionItem);
const expensicons = useMemoizedLazyExpensifyIcons(['ArrowRight']);
Expand Down Expand Up @@ -527,7 +530,11 @@
[CONST.SEARCH.TABLE_COLUMNS.TITLE]: (
<View style={[StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TITLE)]}>
<TextCell
text={computeReportName(transactionItem.report) ?? transactionItem.report?.reportName ?? ''}
text={
computeReportName(transactionItem.report, undefined, undefined, undefined, undefined, undefined, undefined, session?.accountID) ??
transactionItem.report?.reportName ??
''
}
isLargeScreenWidth={isLargeScreenWidth}
/>
</View>
Expand All @@ -549,7 +556,7 @@
</View>
),
}),
[

Check warning on line 559 in src/components/TransactionItemRow/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has missing dependencies: 'hash' and 'session?.accountID'. Either include them or remove the dependency array

Check warning on line 559 in src/components/TransactionItemRow/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has missing dependencies: 'hash' and 'session?.accountID'. Either include them or remove the dependency array
StyleUtils,
transactionItem,
shouldShowTooltip,
Expand Down
8 changes: 4 additions & 4 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,14 +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({

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,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -233,7 +233,7 @@
});

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

Check warning on line 236 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 +245,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
const lastVisibleReportActions: ReportActions = {};
Onyx.connect({

Check warning on line 248 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 Down Expand Up @@ -307,7 +307,7 @@
});

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

Check warning on line 310 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 @@ -654,7 +654,7 @@
: undefined;
// For workspace chats, use the report title
if (reportUtilsIsPolicyExpenseChat(report) && !isEmptyObject(iouReport)) {
const reportName = computeReportName(iouReport);
const reportName = computeReportName(iouReport, undefined, undefined, undefined, undefined, undefined, undefined, currentUserAccountID);
lastMessageTextFromReport = formatReportLastMessageText(reportName);
} else {
const reportPreviewMessage = getReportPreviewMessage(
Expand Down Expand Up @@ -914,7 +914,7 @@
: 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, allReports, allPolicies, undefined, allReportNameValuePairs, personalDetailsForCompute, allReportActions, currentUserAccountID);
reportName = showPersonalDetails
? getDisplayNameForParticipant({accountID: accountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils}) || formatPhoneNumberPhoneUtils(personalDetail?.login ?? '')
: computedReportName;
Expand Down Expand Up @@ -976,7 +976,7 @@
// eslint-disable-next-line @typescript-eslint/no-deprecated
option.alternateText = translateLocal('reportActionsView.yourSpace');
} else if (option.isInvoiceRoom) {
option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined);
option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined, currentUserAccountID);
// eslint-disable-next-line @typescript-eslint/no-deprecated
option.alternateText = translateLocal('workspace.common.invoices');
} else {
Expand Down Expand Up @@ -1025,7 +1025,7 @@
// eslint-disable-next-line @typescript-eslint/no-deprecated
option.alternateText = translateLocal('reportActionsView.yourSpace');
} else if (option.isInvoiceRoom) {
option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined);
option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined, currentUserAccountID);
// eslint-disable-next-line @typescript-eslint/no-deprecated
option.alternateText = translateLocal('workspace.common.invoices');
} else if (unknownUserDetails) {
Expand Down
25 changes: 14 additions & 11 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,9 @@
isUserCreatedPolicyRoom,
} from './ReportUtils';

let currentUserAccountID: number | undefined;
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;

Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserAccountID = value?.accountID;
},
});

Onyx.connect({

Check warning on line 119 in src/libs/ReportNameUtils.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 = value;
Expand All @@ -141,7 +133,15 @@
* This function is useful in contexts such as 1:1 direct messages (DMs) or other group chats.
* It limits to a maximum of 5 participants for the title and uses short names unless there is only one participant.
*/
const buildReportNameFromParticipantNames = ({report, personalDetailsList: personalDetailsData}: {report: OnyxEntry<Report>; personalDetailsList?: Partial<PersonalDetailsList>}) =>
const buildReportNameFromParticipantNames = ({
report,
personalDetailsList: personalDetailsData,
currentUserAccountID,
}: {
report: OnyxEntry<Report>;
personalDetailsList?: Partial<PersonalDetailsList>;
currentUserAccountID?: number;
}) =>
Object.keys(report?.participants ?? {})
.map(Number)
.filter((id) => id !== currentUserAccountID)
Expand Down Expand Up @@ -250,11 +250,13 @@
receiverPolicy,
personalDetails,
policies,
currentUserAccountID,
}: {
report: OnyxEntry<Report>;
receiverPolicy: OnyxEntry<Policy>;
personalDetails?: Partial<PersonalDetailsList>;
policies?: Policy[];
currentUserAccountID?: number;
}): string {
const invoiceReceiver = report?.invoiceReceiver;
const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL;
Expand Down Expand Up @@ -625,6 +627,7 @@
allReportNameValuePairs?: OnyxCollection<ReportNameValuePairs>,
personalDetailsList?: PersonalDetailsList,
reportActions?: OnyxCollection<ReportActions>,
currentUserAccountID?: number,
): string {
if (!report || !report.reportID) {
return '';
Expand Down Expand Up @@ -696,7 +699,7 @@
receiverPolicyID = (receiver as {policyID: string}).policyID;
}
const invoiceReceiverPolicy = receiverPolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${receiverPolicyID}`] : undefined;
formattedName = getInvoicesChatName({report, receiverPolicy: invoiceReceiverPolicy, personalDetails: personalDetailsList});
formattedName = getInvoicesChatName({report, receiverPolicy: invoiceReceiverPolicy, personalDetails: personalDetailsList, currentUserAccountID});
}

if (isSelfDM(report)) {
Expand All @@ -717,7 +720,7 @@
}

// Not a room or PolicyExpenseChat, generate title from first 5 other participants
formattedName = buildReportNameFromParticipantNames({report, personalDetailsList});
formattedName = buildReportNameFromParticipantNames({report, personalDetailsList, currentUserAccountID});

const finalName = formattedName ?? report?.reportName ?? '';

Expand Down
5 changes: 4 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5687,11 +5687,13 @@ function getInvoicesChatName({
receiverPolicy,
personalDetails,
policies,
currentUserAccountIDParam,
}: {
report: OnyxEntry<Report>;
receiverPolicy: OnyxEntry<Policy>;
personalDetails?: Partial<PersonalDetailsList>;
policies?: Policy[];
currentUserAccountIDParam?: number;
}): string {
const invoiceReceiver = report?.invoiceReceiver;
const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL;
Expand All @@ -5700,7 +5702,8 @@ function getInvoicesChatName({
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const invoiceReceiverPolicy = receiverPolicy ?? getPolicy(invoiceReceiverPolicyID);
const isCurrentUserReceiver = (isIndividual && invoiceReceiverAccountID === currentUserAccountID) || (!isIndividual && isPolicyAdminPolicyUtils(invoiceReceiverPolicy));
const isCurrentUserReceiver =
(isIndividual && invoiceReceiverAccountID === (currentUserAccountIDParam ?? currentUserAccountID)) || (!isIndividual && isPolicyAdminPolicyUtils(invoiceReceiverPolicy));

if (isCurrentUserReceiver) {
return getPolicyName({report, policies});
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/OnyxDerived/configs/reportAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ export default createOnyxDerivedValueConfig({
ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
ONYXKEYS.COLLECTION.TRANSACTION,
ONYXKEYS.PERSONAL_DETAILS_LIST,
ONYXKEYS.SESSION,
ONYXKEYS.COLLECTION.POLICY,
ONYXKEYS.COLLECTION.REPORT_METADATA,
],
compute: (
[reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies],
[reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, session, policies],
{currentValue, sourceValues, areAllConnectionsSet},
) => {
if (!areAllConnectionsSet) {
Expand Down Expand Up @@ -219,7 +220,7 @@ export default createOnyxDerivedValueConfig({
}

acc[report.reportID] = {
reportName: report ? computeReportName(report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions) : '',
reportName: report ? computeReportName(report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions, session?.accountID) : '',
isEmpty: generateIsEmptyReport(report, isReportArchived),
brickRoadStatus,
requiresAttention,
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Search/AdvancedSearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@ function getFilterExpenseDisplayTitle(filters: Partial<SearchAdvancedFiltersForm
: undefined;
}

function getFilterInDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, _: LocaleContextProps['translate'], reports?: OnyxCollection<Report>) {
function getFilterInDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, _: LocaleContextProps['translate'], reports?: OnyxCollection<Report>, currentUserAccountID?: number) {
return filters.in
?.map((id) => computeReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reports))
?.map((id) => computeReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reports, undefined, undefined, undefined, undefined, undefined, currentUserAccountID))
?.filter(Boolean)
?.join(', ');
}
Expand All @@ -548,8 +548,8 @@ function AdvancedSearchFilters() {
const personalDetails = usePersonalDetails();

const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});

const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: emailSelector});
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const currentUserLogin = emailSelector(session);

const taxRates = getAllTaxRates(policies);

Expand Down Expand Up @@ -609,7 +609,7 @@ function AdvancedSearchFilters() {
) {
filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters[key] ?? [], personalDetails, formatPhoneNumber);
} else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) {
filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate, reports);
filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate, reports, session?.accountID);
} else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID) {
const workspacesData = workspaces.flatMap((value) => value.data);
filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, workspacesData);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/iou/SplitExpenseEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) {
const isSplitAvailable = report && transaction && isSplitAction(currentReport, [transaction], originalTransaction, currentPolicy);

const isCategoryRequired = !!currentPolicy?.requiresCategory;
const reportName = computeReportName(currentReport);
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const reportName = computeReportName(currentReport, undefined, undefined, undefined, undefined, undefined, undefined, session?.accountID);
const isDescriptionRequired = isCategoryDescriptionRequired(policyCategories, splitExpenseDraftTransactionDetails?.category, currentPolicy?.areRulesEnabled);

const shouldShowTags = !!currentPolicy?.areTagsEnabled && !!(transactionTag || hasEnabledTags(policyTagLists));
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/OnyxDerivedTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ describe('OnyxDerived', () => {
const transaction = createRandomTransaction(1);

// When the report attributes are recomputed with both report and transaction updates
reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {areAllConnectionsSet: true});
const reportAttributesComputedValue = reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {
reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {areAllConnectionsSet: true});
const reportAttributesComputedValue = reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {
sourceValues: {
[ONYXKEYS.COLLECTION.REPORT]: {
[`${ONYXKEYS.COLLECTION.REPORT}${reportID1}`]: reports[`${ONYXKEYS.COLLECTION.REPORT}${reportID1}`],
Expand Down
Loading
Loading