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
4 changes: 3 additions & 1 deletion src/components/AvatarWithDisplayName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -169,7 +170,8 @@ function AvatarWithDisplayName({
const parentReportActionParam = report?.parentReportActionID ? parentReportActions?.[report.parentReportActionID] : undefined;
const title = getReportName(report, undefined, parentReportActionParam, personalDetails, invoiceReceiverPolicy, reportAttributes);
const subtitle = getChatRoomSubtitle(report, {isCreateExpenseFlow: true});
const parentNavigationSubtitleData = getParentNavigationSubtitle(report);
const isReportArchived = useReportIsArchived(report?.reportID);
const parentNavigationSubtitleData = getParentNavigationSubtitle(report, isReportArchived);
const isMoneyRequestOrReport = isMoneyRequestReport(report) || isMoneyRequest(report) || isTrackExpenseReport(report) || isInvoiceReport(report);
const ownerPersonalDetails = getPersonalDetailsForAccountIDs(report?.ownerAccountID ? [report.ownerAccountID] : [], personalDetails);
const displayNamesWithTooltips = getDisplayNamesWithTooltips(Object.values(ownerPersonalDetails), false, localeCompare);
Expand Down
6 changes: 2 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
const parsedReportActionMessageCache: Record<string, string> = {};

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

Check warning on line 908 in src/libs/ReportUtils.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.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportID = value;
Expand All @@ -913,7 +913,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 916 in src/libs/ReportUtils.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) => {
// When signed out, val is undefined
Expand All @@ -931,7 +931,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 934 in src/libs/ReportUtils.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) => {
if (currentUserAccountID) {
Expand All @@ -943,14 +943,14 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 946 in src/libs/ReportUtils.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_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
});

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

Check warning on line 953 in src/libs/ReportUtils.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: (value) => (allPolicies = value),
Expand All @@ -958,7 +958,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 961 in src/libs/ReportUtils.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 Down Expand Up @@ -999,14 +999,14 @@
});

let allBetas: OnyxEntry<Beta[]>;
Onyx.connect({

Check warning on line 1002 in src/libs/ReportUtils.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.BETAS,
callback: (value) => (allBetas = value),
});

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1009 in src/libs/ReportUtils.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.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1032,7 +1032,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1035 in src/libs/ReportUtils.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 @@ -1045,7 +1045,7 @@

let allReportMetadata: OnyxCollection<ReportMetadata>;
const allReportMetadataKeyValue: Record<string, ReportMetadata> = {};
Onyx.connect({

Check warning on line 1048 in src/libs/ReportUtils.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_METADATA,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -5526,7 +5526,7 @@
/**
* Gets the parent navigation subtitle for the report
*/
function getParentNavigationSubtitle(report: OnyxEntry<Report>): ParentNavigationSummaryParams {
function getParentNavigationSubtitle(report: OnyxEntry<Report>, isReportArchived = false): ParentNavigationSummaryParams {
const parentReport = getParentReport(report);
if (isEmptyObject(parentReport)) {
const ownerAccountID = report?.ownerAccountID;
Expand All @@ -5550,9 +5550,7 @@
if (isInvoiceReport(report) || isInvoiceRoom(parentReport)) {
let reportName = `${getPolicyName({report: parentReport})} & ${getInvoicePayerName(parentReport)}`;

// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
if (isArchivedNonExpenseReport(parentReport, !!getReportNameValuePairs(parentReport?.reportID)?.private_isArchived)) {
if (isArchivedNonExpenseReport(parentReport, isReportArchived)) {
reportName += ` (${translateLocal('common.archived')})`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
const isReportArchived = useReportIsArchived(report?.reportID);
const isArchivedRoom = useMemo(() => isArchivedNonExpenseReport(report, isReportArchived), [report, isReportArchived]);
const shouldDisableRename = useMemo(() => shouldDisableRenameUtil(report, isReportArchived), [report, isReportArchived]);
const parentNavigationSubtitleData = getParentNavigationSubtitle(report);
const parentNavigationSubtitleData = getParentNavigationSubtitle(report, isReportArchived);
const base62ReportID = getBase62ReportID(Number(report.reportID));
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- policy is a dependency because `getChatRoomSubtitle` calls `getPolicyName` which in turn retrieves the value from the `policy` value stored in Onyx
const chatRoomSubtitle = useMemo(() => {
Expand Down
6 changes: 4 additions & 2 deletions src/pages/ShareCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ScrollView from '@components/ScrollView';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import Clipboard from '@libs/Clipboard';
Expand Down Expand Up @@ -75,6 +76,7 @@ function ShareCodePage({report, policy, backTo}: ShareCodePageProps) {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();

const isReport = !!report?.reportID;
const isReportArchived = useReportIsArchived(report?.reportID);

const subtitle = useMemo(() => {
if (isReport) {
Expand All @@ -88,11 +90,11 @@ function ShareCodePage({report, policy, backTo}: ShareCodePageProps) {
.join(' & ');
}

return getParentNavigationSubtitle(report).workspaceName ?? getChatRoomSubtitle(report);
return getParentNavigationSubtitle(report, isReportArchived).workspaceName ?? getChatRoomSubtitle(report);
}

return currentUserPersonalDetails.login;
}, [report, currentUserPersonalDetails, isReport]);
}, [isReport, currentUserPersonalDetails.login, report, isReportArchived]);

const title = isReport ? getReportName(report) : (currentUserPersonalDetails.displayName ?? '');
const urlWithTrailingSlash = addTrailingForwardSlash(environmentURL);
Expand Down
4 changes: 3 additions & 1 deletion src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSubscriptionPlan from '@hooks/useSubscriptionPlan';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -133,7 +134,8 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
// Use sorted display names for the title for group chats on native small screen widths
const title = getReportName(reportHeaderData, policy, parentReportAction, personalDetails, invoiceReceiverPolicy);
const subtitle = getChatRoomSubtitle(reportHeaderData);
const parentNavigationSubtitleData = getParentNavigationSubtitle(reportHeaderData);
const isReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.reportID);
const parentNavigationSubtitleData = getParentNavigationSubtitle(reportHeaderData, isReportHeaderDataArchived);
const reportDescription = Parser.htmlToText(getReportDescription(report));
const policyName = getPolicyName({report, returnEmptyIfNotFound: true});
const policyDescription = getPolicyDescriptionText(policy);
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
getInvoiceChatByParticipants,
getMoneyReportPreviewName,
getMostRecentlyVisitedReport,
getParentNavigationSubtitle,
getParticipantsList,
getPolicyExpenseChat,
getReasonAndReportActionThatRequiresAttention,
Expand Down Expand Up @@ -921,6 +922,48 @@ describe('ReportUtils', () => {
});
});

describe('getParentNavigationSubtitle', () => {
const baseArchivedPolicyExpenseChat = {
reportID: '2',
lastReadTime: '2024-02-01 04:56:47.233',
parentReportActionID: '1',
parentReportID: '1',
reportName: 'Base Report',
type: CONST.REPORT.TYPE.INVOICE,
};

const reports: Report[] = [
{
reportID: '1',
lastReadTime: '2024-02-01 04:56:47.233',
reportName: 'Report',
policyName: 'A workspace',
invoiceReceiver: {type: CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, accountID: 1},
},
baseArchivedPolicyExpenseChat,
];

beforeAll(() => {
const reportCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.REPORT, reports, (report) => report.reportID);
Onyx.multiSet({
...reportCollectionDataSet,
});
return waitForBatchedUpdates();
});

it('should return the correct parent navigation subtitle for the archived invoice report', () => {
Comment thread
nkdengineer marked this conversation as resolved.
const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, true);
const normalizedActual = {...actual, reportName: actual.reportName?.replace(/\u00A0/g, ' ')};
expect(normalizedActual).toEqual({reportName: 'A workspace & Ragnar Lothbrok (archived)'});
});

it('should return the correct parent navigation subtitle for the non archived invoice report', () => {
const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, false);
const normalizedActual = {...actual, reportName: actual.reportName?.replace(/\u00A0/g, ' ')};
expect(normalizedActual).toEqual({reportName: 'A workspace & Ragnar Lothbrok'});
});
});

describe('requiresAttentionFromCurrentUser', () => {
afterEach(async () => {
await Onyx.clear();
Expand Down
Loading