From c1afaca6da097ad5640e31d61873c45568ca32b5 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 1 Aug 2024 12:57:43 +0700 Subject: [PATCH 001/368] fix back button in the selection mode --- src/CONFIG.ts | 2 +- src/components/Search/SearchContext.tsx | 8 ++++++-- src/components/Search/index.tsx | 22 ++++++++------------- src/components/Search/types.ts | 3 ++- src/pages/Search/SearchPageBottomTab.tsx | 25 ++++++++++++++++++------ 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/CONFIG.ts b/src/CONFIG.ts index 8800cc907588..ec7f4b39af91 100644 --- a/src/CONFIG.ts +++ b/src/CONFIG.ts @@ -96,5 +96,5 @@ export default { IOS_CLIENT_ID: '921154746561-s3uqn2oe4m85tufi6mqflbfbuajrm2i3.apps.googleusercontent.com', }, GCP_GEOLOCATION_API_KEY: googleGeolocationAPIKey, - USE_REACT_STRICT_MODE: true, + USE_REACT_STRICT_MODE: false, } as const; diff --git a/src/components/Search/SearchContext.tsx b/src/components/Search/SearchContext.tsx index 3408ffbc4803..266d3563dea2 100644 --- a/src/components/Search/SearchContext.tsx +++ b/src/components/Search/SearchContext.tsx @@ -4,6 +4,7 @@ import type {SearchContext, SelectedTransactions} from './types'; const defaultSearchContext = { currentSearchHash: -1, + shouldTurnOffSelectionMode: false, selectedTransactions: {}, setCurrentSearchHash: () => {}, setSelectedTransactions: () => {}, @@ -13,9 +14,10 @@ const defaultSearchContext = { const Context = React.createContext(defaultSearchContext); function SearchContextProvider({children}: ChildrenProps) { - const [searchContextData, setSearchContextData] = useState>({ + const [searchContextData, setSearchContextData] = useState>({ currentSearchHash: defaultSearchContext.currentSearchHash, selectedTransactions: defaultSearchContext.selectedTransactions, + shouldTurnOffSelectionMode: false, }); const setCurrentSearchHash = useCallback((searchHash: number) => { @@ -29,16 +31,18 @@ function SearchContextProvider({children}: ChildrenProps) { setSearchContextData((prevState) => ({ ...prevState, selectedTransactions, + shouldTurnOffSelectionMode: false, })); }, []); const clearSelectedTransactions = useCallback( - (searchHash?: number) => { + (searchHash?: number, shouldTurnOffSelectionMode = false) => { if (searchHash === searchContextData.currentSearchHash) { return; } setSearchContextData((prevState) => ({ ...prevState, + shouldTurnOffSelectionMode, selectedTransactions: {}, })); }, diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index c2d7b52fa3e9..c3d2455196d1 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -79,7 +79,7 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { const {isLargeScreenWidth, isSmallScreenWidth} = useWindowDimensions(); const navigation = useNavigation>(); const lastSearchResultsRef = useRef>(); - const {setCurrentSearchHash, setSelectedTransactions, selectedTransactions, clearSelectedTransactions} = useSearchContext(); + const {setCurrentSearchHash, setSelectedTransactions, selectedTransactions, clearSelectedTransactions, shouldTurnOffSelectionMode} = useSearchContext(); const [selectionMode] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE); const [offset, setOffset] = useState(0); const [offlineModalVisible, setOfflineModalVisible] = useState(false); @@ -101,6 +101,13 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [hash]); + useEffect(() => { + const selectedKeys = Object.keys(selectedTransactions).filter((key) => selectedTransactions[key]); + if (selectedKeys.length === 0 && selectionMode?.isEnabled && shouldTurnOffSelectionMode) { + turnOffMobileSelectionMode(); + } + }, [selectedTransactions, selectionMode?.isEnabled, shouldTurnOffSelectionMode]); + useEffect(() => { const selectedKeys = Object.keys(selectedTransactions).filter((key) => selectedTransactions[key]); if (!isSmallScreenWidth) { @@ -134,19 +141,6 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { setDeleteExpensesConfirmModalVisible(true); }; - useEffect(() => { - const selectedKeys = Object.keys(selectedTransactions).filter((key) => selectedTransactions[key]); - if (!isSmallScreenWidth) { - if (selectedKeys.length === 0) { - turnOffMobileSelectionMode(); - } - return; - } - if (selectedKeys.length > 0 && !selectionMode?.isEnabled) { - turnOnMobileSelectionMode(); - } - }, [isSmallScreenWidth, selectedTransactions, selectionMode?.isEnabled]); - const getItemHeight = useCallback( (item: TransactionListItemType | ReportListItemType) => { if (SearchUtils.isTransactionListItemType(item)) { diff --git a/src/components/Search/types.ts b/src/components/Search/types.ts index 52adf28166f7..1c90b7bc76c4 100644 --- a/src/components/Search/types.ts +++ b/src/components/Search/types.ts @@ -31,7 +31,8 @@ type SearchContext = { selectedTransactions: SelectedTransactions; setCurrentSearchHash: (hash: number) => void; setSelectedTransactions: (selectedTransactions: SelectedTransactions) => void; - clearSelectedTransactions: (hash?: number) => void; + clearSelectedTransactions: (hash?: number, shouldTurnOffSelectionMode?: boolean) => void; + shouldTurnOffSelectionMode: boolean; }; type ASTNode = { diff --git a/src/pages/Search/SearchPageBottomTab.tsx b/src/pages/Search/SearchPageBottomTab.tsx index f80aed9b8c28..93bab08b1ec5 100644 --- a/src/pages/Search/SearchPageBottomTab.tsx +++ b/src/pages/Search/SearchPageBottomTab.tsx @@ -1,4 +1,5 @@ -import React, {useMemo} from 'react'; +import React, {useCallback, useEffect, useMemo} from 'react'; +import {BackHandler} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -9,7 +10,6 @@ import useActiveCentralPaneRoute from '@hooks/useActiveCentralPaneRoute'; import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; -import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; import Navigation from '@libs/Navigation/Navigation'; import type {AuthScreensParamList} from '@libs/Navigation/types'; import {buildSearchQueryJSON} from '@libs/SearchUtils'; @@ -28,6 +28,22 @@ function SearchPageBottomTab() { const {clearSelectedTransactions} = useSearchContext(); const [selectionMode] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE); + const handleBackButtonPress = useCallback(() => { + if (!selectionMode?.isEnabled) { + return false; + } + if (selectionMode?.isEnabled) { + clearSelectedTransactions(undefined, true); + return true; + } + }, [selectionMode, clearSelectedTransactions]); + + useEffect(() => { + const backHandler = BackHandler.addEventListener('hardwareBackPress', handleBackButtonPress); + + return () => backHandler.remove(); + }, [handleBackButtonPress]); + const {queryJSON, policyIDs, isCustomQuery} = useMemo(() => { if (!activeCentralPaneRoute || activeCentralPaneRoute.name !== SCREENS.SEARCH.CENTRAL_PANE) { return {queryJSON: undefined, policyIDs: undefined}; @@ -71,10 +87,7 @@ function SearchPageBottomTab() { ) : ( { - clearSelectedTransactions(); - turnOffMobileSelectionMode(); - }} + onBackButtonPress={handleBackButtonPress} /> )} {shouldUseNarrowLayout && queryJSON && ( From 53ea108a4e43a1d0dbe635c74dbc3fe835972db1 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 7 Aug 2024 10:17:20 +0700 Subject: [PATCH 002/368] remove useless code --- src/CONFIG.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CONFIG.ts b/src/CONFIG.ts index ec7f4b39af91..8800cc907588 100644 --- a/src/CONFIG.ts +++ b/src/CONFIG.ts @@ -96,5 +96,5 @@ export default { IOS_CLIENT_ID: '921154746561-s3uqn2oe4m85tufi6mqflbfbuajrm2i3.apps.googleusercontent.com', }, GCP_GEOLOCATION_API_KEY: googleGeolocationAPIKey, - USE_REACT_STRICT_MODE: false, + USE_REACT_STRICT_MODE: true, } as const; From c756e74f8ac344afbba0cd3bca06677a0ff54c0e Mon Sep 17 00:00:00 2001 From: zfurtak Date: Tue, 17 Sep 2024 13:48:46 +0100 Subject: [PATCH 003/368] Added policy header to chats in search --- src/components/SelectionList/ChatListItem.tsx | 88 +++++++++++-------- src/styles/index.ts | 5 ++ 2 files changed, 57 insertions(+), 36 deletions(-) diff --git a/src/components/SelectionList/ChatListItem.tsx b/src/components/SelectionList/ChatListItem.tsx index 8322c7e1406a..a83ee482c9de 100644 --- a/src/components/SelectionList/ChatListItem.tsx +++ b/src/components/SelectionList/ChatListItem.tsx @@ -3,12 +3,15 @@ import {View} from 'react-native'; import {AttachmentContext} from '@components/AttachmentContext'; import MultipleAvatars from '@components/MultipleAvatars'; import {ShowContextMenuContext} from '@components/ShowContextMenuContext'; +import Text from '@components/Text'; +import TextLink from '@components/TextLink'; import TextWithTooltip from '@components/TextWithTooltip'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import ReportActionItemDate from '@pages/home/report/ReportActionItemDate'; import ReportActionItemFragment from '@pages/home/report/ReportActionItemFragment'; +import variables from '@styles/variables'; import CONST from '@src/CONST'; import BaseListItem from './BaseListItem'; import type {ChatListItemProps, ListItem, ReportActionListItemType} from './types'; @@ -79,43 +82,56 @@ function ChatListItem({ {(hovered) => ( - - - - - - - + + + In + {}} + > + #wave-collect + - - {reportActionItem.message.map((fragment, index) => ( - - ))} + + + + + + + + + + + {reportActionItem.message.map((fragment, index) => ( + + ))} + + diff --git a/src/styles/index.ts b/src/styles/index.ts index 3d91d614f722..7c6b52355e97 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -2060,6 +2060,11 @@ const styles = (theme: ThemeColors) => paddingTop: 2, }, + chatItemMessageHeaderPolicy: { + color: theme.textSupporting, + fontSize: variables.fontSizeSmall, + }, + chatItemMessage: { color: theme.text, fontSize: variables.fontSizeNormal, From c0086bc6ce9f788c6acd5ae680754503f7354849 Mon Sep 17 00:00:00 2001 From: zfurtak Date: Wed, 18 Sep 2024 14:56:33 +0100 Subject: [PATCH 004/368] Added report name --- src/components/SelectionList/ChatListItem.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/SelectionList/ChatListItem.tsx b/src/components/SelectionList/ChatListItem.tsx index a83ee482c9de..02bf9004ad5e 100644 --- a/src/components/SelectionList/ChatListItem.tsx +++ b/src/components/SelectionList/ChatListItem.tsx @@ -1,5 +1,6 @@ import React from 'react'; import {View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; import {AttachmentContext} from '@components/AttachmentContext'; import MultipleAvatars from '@components/MultipleAvatars'; import {ShowContextMenuContext} from '@components/ShowContextMenuContext'; @@ -9,10 +10,12 @@ import TextWithTooltip from '@components/TextWithTooltip'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import * as ReportUtils from '@libs/ReportUtils'; import ReportActionItemDate from '@pages/home/report/ReportActionItemDate'; import ReportActionItemFragment from '@pages/home/report/ReportActionItemFragment'; import variables from '@styles/variables'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import BaseListItem from './BaseListItem'; import type {ChatListItemProps, ListItem, ReportActionListItemType} from './types'; @@ -56,7 +59,7 @@ function ChatListItem({ const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; const hoveredBackgroundColor = styles.sidebarLinkHover?.backgroundColor ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; - + const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); return ( ({ {(hovered) => ( - + In {}} + onPress={() => onSelectRow(item)} > - #wave-collect + {ReportUtils.getReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`])} From 3b9161571499abbb5686253ba967bf00f3876829 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 2 Oct 2024 16:31:25 +0700 Subject: [PATCH 005/368] implement for mWeb --- src/pages/Search/SearchPage.tsx | 31 +++++++++++++++++-- src/pages/Search/SearchPageBottomTab.tsx | 17 ++++------ .../useHandleBackButton/index.android.ts | 11 +++++++ src/pages/Search/useHandleBackButton/index.ts | 4 +++ src/pages/Search/useHandleBackButton/type.ts | 3 ++ 5 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 src/pages/Search/useHandleBackButton/index.android.ts create mode 100644 src/pages/Search/useHandleBackButton/index.ts create mode 100644 src/pages/Search/useHandleBackButton/type.ts diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index 7f82aaabfc6f..8400301d55dd 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -1,15 +1,19 @@ -import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useMemo} from 'react'; +import {useNavigation} from '@react-navigation/native'; +import type {StackNavigationProp, StackScreenProps} from '@react-navigation/stack'; +import React, {useEffect, useMemo, useRef} from 'react'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import ScreenWrapper from '@components/ScreenWrapper'; import Search from '@components/Search'; +import {useSearchContext} from '@components/Search/SearchContext'; import SearchPageHeader from '@components/Search/SearchPageHeader'; import SearchStatusBar from '@components/Search/SearchStatusBar'; +import useMobileSelectionMode from '@hooks/useMobileSelectionMode'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {AuthScreensParamList} from '@libs/Navigation/types'; import * as SearchUtils from '@libs/SearchUtils'; +import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; @@ -19,10 +23,33 @@ function SearchPage({route}: SearchPageProps) { const {shouldUseNarrowLayout} = useResponsiveLayout(); const styles = useThemeStyles(); const {q} = route.params; + const navigation = useNavigation>(); + const {clearSelectedTransactions} = useSearchContext(); + const {selectionMode} = useMobileSelectionMode(); + const clearSelectedTransactionsRef = useRef(clearSelectedTransactions); + const selectionModeRef = useRef(selectionMode); + selectionModeRef.current = selectionMode; + clearSelectedTransactionsRef.current = clearSelectedTransactions; const queryJSON = useMemo(() => SearchUtils.buildSearchQueryJSON(q), [q]); const handleOnBackButtonPress = () => Navigation.goBack(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: SearchUtils.buildCannedSearchQuery()})); + useEffect(() => { + navigation.addListener('beforeRemove', (e) => { + if (!selectionModeRef?.current?.isEnabled) { + navigation.dispatch(e.data.action); + return; + } + e.preventDefault(); + // When the navigation type is not reset that means we're not using the back button browser to navigate + // So we should still dispatch the action to go to the target page + if (e.data.action.type !== CONST.NAVIGATION_ACTIONS.RESET) { + navigation.dispatch(e.data.action); + } + clearSelectedTransactionsRef?.current?.(undefined, true); + }); + }, [navigation]); + // On small screens this page is not displayed, the configuration is in the file: src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx // To avoid calling hooks in the Search component when this page isn't visible, we return null here. if (shouldUseNarrowLayout) { diff --git a/src/pages/Search/SearchPageBottomTab.tsx b/src/pages/Search/SearchPageBottomTab.tsx index c3bf019e6542..70d846b6559f 100644 --- a/src/pages/Search/SearchPageBottomTab.tsx +++ b/src/pages/Search/SearchPageBottomTab.tsx @@ -1,5 +1,5 @@ -import React, {useCallback, useEffect} from 'react'; -import {BackHandler, View} from 'react-native'; +import React, {useCallback} from 'react'; +import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Animated, {clamp, useAnimatedScrollHandler, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; @@ -22,6 +22,7 @@ import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import SearchSelectionModeHeader from './SearchSelectionModeHeader'; import SearchTypeMenu from './SearchTypeMenu'; +import useHandleBackButton from './useHandleBackButton'; const TOO_CLOSE_TO_TOP_DISTANCE = 10; const TOO_CLOSE_TO_BOTTOM_DISTANCE = 10; @@ -40,17 +41,11 @@ function SearchPageBottomTab() { if (!selectionMode?.isEnabled) { return false; } - if (selectionMode?.isEnabled) { - clearSelectedTransactions(undefined, true); - return true; - } + clearSelectedTransactions(undefined, true); + return true; }, [selectionMode, clearSelectedTransactions]); - useEffect(() => { - const backHandler = BackHandler.addEventListener('hardwareBackPress', handleBackButtonPress); - - return () => backHandler.remove(); - }, [handleBackButtonPress]); + useHandleBackButton(handleBackButtonPress); const scrollOffset = useSharedValue(0); const topBarOffset = useSharedValue(variables.searchHeaderHeight); diff --git a/src/pages/Search/useHandleBackButton/index.android.ts b/src/pages/Search/useHandleBackButton/index.android.ts new file mode 100644 index 000000000000..69c36e8e06d4 --- /dev/null +++ b/src/pages/Search/useHandleBackButton/index.android.ts @@ -0,0 +1,11 @@ +import {useEffect} from 'react'; +import {BackHandler} from 'react-native'; +import type UseHandleBackButtonCallback from './type'; + +export default function useHandleBackButton(callback: UseHandleBackButtonCallback) { + useEffect(() => { + const backHandler = BackHandler.addEventListener('hardwareBackPress', callback); + + return () => backHandler.remove(); + }, [callback]); +} diff --git a/src/pages/Search/useHandleBackButton/index.ts b/src/pages/Search/useHandleBackButton/index.ts new file mode 100644 index 000000000000..691e2dd0378b --- /dev/null +++ b/src/pages/Search/useHandleBackButton/index.ts @@ -0,0 +1,4 @@ +import type UseHandleBackButtonCallback from './type'; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export default function useHandleBackButton(_callback: UseHandleBackButtonCallback) {} diff --git a/src/pages/Search/useHandleBackButton/type.ts b/src/pages/Search/useHandleBackButton/type.ts new file mode 100644 index 000000000000..e32f48555bde --- /dev/null +++ b/src/pages/Search/useHandleBackButton/type.ts @@ -0,0 +1,3 @@ +type UseHandleBackButtonCallback = () => boolean; + +export default UseHandleBackButtonCallback; From ec5d2fb01339f65d448096a8ff5e7e980e83595b Mon Sep 17 00:00:00 2001 From: zfurtak Date: Wed, 2 Oct 2024 13:59:26 +0100 Subject: [PATCH 006/368] First part of refactor --- src/libs/ModifiedExpenseMessage.ts | 9 ++--- src/libs/ReportUtils.ts | 53 ++++++++++++++++++------------ 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 20c5f6d7dce9..0fa22b798a23 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -2,7 +2,7 @@ import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PolicyTagLists, ReportAction} from '@src/types/onyx'; +import type {PolicyTagLists, Report, ReportAction} from '@src/types/onyx'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; import * as Localize from './Localize'; @@ -132,12 +132,13 @@ function getForDistanceRequest(newMerchant: string, oldMerchant: string, newAmou * ModifiedExpense::getNewDotComment in Web-Expensify should match this. * If we change this function be sure to update the backend as well. */ -function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry): string { +function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry, reports?: OnyxCollection, propPolicyTags?: OnyxCollection): string { if (!ReportActionsUtils.isModifiedExpenseAction(reportAction)) { return ''; } const reportActionOriginalMessage = ReportActionsUtils.getOriginalMessage(reportAction); - const policyID = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.policyID ?? '-1'; + const report = (reports ?? ReportConnection.getAllReports())?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const policyID = report?.policyID ?? '-1'; const removalFragments: string[] = []; const setFragments: string[] = []; @@ -224,7 +225,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr const hasModifiedTag = isReportActionOriginalMessageAnObject && 'oldTag' in reportActionOriginalMessage && 'tag' in reportActionOriginalMessage; if (hasModifiedTag) { - const policyTags = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {}; + const policyTags = (propPolicyTags ?? allPolicyTags)?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {}; const transactionTag = reportActionOriginalMessage?.tag ?? ''; const oldTransactionTag = reportActionOriginalMessage?.oldTag ?? ''; const splittedTag = TransactionUtils.getTagArrayFromName(transactionTag); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 687ef177609e..077abf0b04c5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -32,6 +32,7 @@ import type { PersonalDetailsList, Policy, PolicyReportField, + PolicyTagLists, Report, ReportAction, ReportMetadata, @@ -708,9 +709,9 @@ function getChatType(report: OnyxInputOrEntry | Participant): ValueOf { +function getReportOrDraftReport(reportID: string | undefined, reports?: OnyxCollection, draftReports?: OnyxCollection): OnyxEntry { const allReports = ReportConnection.getAllReports(); - return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? allReportsDraft?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportID}`]; + return (reports ?? allReports)?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? (draftReports ?? allReportsDraft)?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportID}`]; } /** @@ -732,8 +733,8 @@ function getReport(reportID: string): OnyxEntry { /** * Returns the report */ -function getReportNameValuePairs(reportID?: string): OnyxEntry { - return allReportNameValuePair?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID ?? -1}`]; +function getReportNameValuePairs(reportID?: string, reportNameValuePairs?: OnyxCollection): OnyxEntry { + return (reportNameValuePairs ?? allReportNameValuePair)?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID ?? -1}`]; } /** @@ -1398,15 +1399,15 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa /** * Whether the provided report has expenses */ -function hasExpenses(reportID?: string): boolean { - return !!Object.values(allTransactions ?? {}).find((transaction) => `${transaction?.reportID}` === `${reportID}`); +function hasExpenses(reportID?: string, transactions?: OnyxCollection): boolean { + return !!Object.values(transactions ?? {}).find((transaction) => `${transaction?.reportID}` === `${reportID}`); } /** * Whether the provided report is a closed expense report with no expenses */ -function isClosedExpenseReportWithNoExpenses(report: OnyxEntry): boolean { - return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && isExpenseReport(report) && !hasExpenses(report.reportID); +function isClosedExpenseReportWithNoExpenses(report: OnyxEntry, transactions?: OnyxCollection): boolean { + return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && isExpenseReport(report) && !hasExpenses(report.reportID, transactions); } /** @@ -3242,14 +3243,14 @@ function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewActio * * NOTE: This method is only meant to be used inside this action file. Do not export and use it elsewhere. Use withOnyx or Onyx.connect() instead. */ -function getLinkedTransaction(reportAction: OnyxEntry): OnyxEntry { +function getLinkedTransaction(reportAction: OnyxEntry, transactions?: OnyxCollection): OnyxEntry { let transactionID = ''; if (ReportActionsUtils.isMoneyRequestAction(reportAction)) { transactionID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID ?? '-1'; } - return allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + return (transactions ?? allTransactions)?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; } /** @@ -3284,7 +3285,12 @@ function shouldShowRBRForMissingSmartscanFields(iouReportID: string): boolean { /** * Given a parent IOU report action get report name for the LHN. */ -function getTransactionReportName(reportAction: OnyxEntry): string { +function getTransactionReportName( + reportAction: OnyxEntry, + transactions?: OnyxCollection, + reports?: OnyxCollection, + draftReports?: OnyxCollection, +): string { if (ReportActionsUtils.isReversedTransaction(reportAction)) { return Localize.translateLocal('parentReportAction.reversedTransaction'); } @@ -3293,7 +3299,7 @@ function getTransactionReportName(reportAction: OnyxEntry, repo /** * Get the report action message for a report action. */ -function getReportActionMessage(reportAction: OnyxEntry, reportID?: string, childReportID?: string) { +function getReportActionMessage(reportAction: OnyxEntry, reportID?: string, childReportID?: string, reports?: OnyxCollection, draftReports?: OnyxCollection) { if (isEmptyObject(reportAction)) { return ''; } @@ -3711,7 +3717,7 @@ function getReportActionMessage(reportAction: OnyxEntry, reportID? return ReportActionsUtils.getReportActionMessageText(reportAction); } if (ReportActionsUtils.isReimbursementQueuedAction(reportAction)) { - return getReimbursementQueuedActionMessage(reportAction, getReportOrDraftReport(reportID), false); + return getReimbursementQueuedActionMessage(reportAction, getReportOrDraftReport(reportID, reports, draftReports), false); } return parseReportActionHtmlToText(reportAction, reportID ?? '', childReportID); @@ -3756,6 +3762,11 @@ function getReportName( personalDetails?: Partial, invoiceReceiverPolicy?: OnyxEntry, shouldIncludePolicyName = false, + transactions?: OnyxCollection, + reports?: OnyxCollection, + draftReports?: OnyxCollection, + reportNameValuePairs?: OnyxCollection, + policyTagLists?: OnyxCollection, ): string { const reportID = report?.reportID; const cacheKey = getCacheKey(report); @@ -3795,8 +3806,8 @@ function getReportName( if (isChatThread(report)) { if (!isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) { - formattedName = getTransactionReportName(parentReportAction); - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + formattedName = getTransactionReportName(parentReportAction, transactions, reports, draftReports); + if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID, reportNameValuePairs))) { formattedName += ` (${Localize.translateLocal('common.archived')})`; } return formatReportLastMessageText(formattedName); @@ -3811,7 +3822,7 @@ function getReportName( } const isAttachment = ReportActionsUtils.isReportActionAttachment(!isEmptyObject(parentReportAction) ? parentReportAction : undefined); - const reportActionMessage = getReportActionMessage(parentReportAction, report?.parentReportID, report?.reportID ?? '').replace(/(\n+|\r\n|\n|\r)/gm, ' '); + const reportActionMessage = getReportActionMessage(parentReportAction, report?.parentReportID, report?.reportID ?? '', reports, draftReports).replace(/(\n+|\r\n|\n|\r)/gm, ' '); if (isAttachment && reportActionMessage) { return `[${Localize.translateLocal('common.attachment')}]`; } @@ -3825,11 +3836,11 @@ function getReportName( if (isAdminRoom(report) || isUserCreatedPolicyRoom(report)) { return getAdminRoomInvitedParticipants(parentReportAction, reportActionMessage); } - if (reportActionMessage && isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (reportActionMessage && isArchivedRoom(report, getReportNameValuePairs(report?.reportID, reportNameValuePairs))) { return `${reportActionMessage} (${Localize.translateLocal('common.archived')})`; } if (!isEmptyObject(parentReportAction) && ReportActionsUtils.isModifiedExpenseAction(parentReportAction)) { - const modifiedMessage = ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction); + const modifiedMessage = ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction, reports, policyTagLists); return formatReportLastMessageText(modifiedMessage); } if (isTripRoom(report)) { @@ -3842,7 +3853,7 @@ function getReportName( return reportActionMessage; } - if (isClosedExpenseReportWithNoExpenses(report)) { + if (isClosedExpenseReportWithNoExpenses(report, transactions)) { return Localize.translateLocal('parentReportAction.deletedReport'); } From 664ee133a6a0db3e74561b94dc5c231c1b35a69c Mon Sep 17 00:00:00 2001 From: zfurtak Date: Thu, 3 Oct 2024 09:46:53 +0100 Subject: [PATCH 007/368] Done refactoring functions --- src/libs/PersonalDetailsUtils.ts | 11 +++++++--- src/libs/ReportActionsUtils.ts | 6 +++--- src/libs/ReportUtils.ts | 37 ++++++++++++++++---------------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 3d9aed117ca3..03f96fd43a60 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -85,11 +85,16 @@ function getDisplayNameOrDefault(passedPersonalDetails?: Partial, +): PersonalDetails[] { const result: PersonalDetails[] = accountIDs - .filter((accountID) => !!allPersonalDetails?.[accountID]) + .filter((accountID) => !!(personalDetailsProp ?? allPersonalDetails)?.[accountID]) .map((accountID) => { - const detail = (allPersonalDetails?.[accountID] ?? {}) as PersonalDetails; + const detail = ((personalDetailsProp ?? allPersonalDetails)?.[accountID] ?? {}) as PersonalDetails; if (shouldChangeUserDisplayName && currentUserAccountID === detail.accountID) { return { diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 17a178128eed..7bd58304f00c 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -9,7 +9,7 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {OnyxInputOrEntry, PrivatePersonalDetails} from '@src/types/onyx'; +import type {OnyxInputOrEntry, PersonalDetailsList, PrivatePersonalDetails} from '@src/types/onyx'; import type {IssueNewCardOriginalMessage, JoinWorkspaceResolution, OriginalMessageChangeLog, OriginalMessageExportIntegration} from '@src/types/onyx/OriginalMessage'; import type Report from '@src/types/onyx/Report'; import type ReportAction from '@src/types/onyx/ReportAction'; @@ -1729,9 +1729,9 @@ function isCardIssuedAction(reportAction: OnyxEntry) { return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL, CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS); } -function getCardIssuedMessage(reportAction: OnyxEntry, shouldRenderHTML = false) { +function getCardIssuedMessage(reportAction: OnyxEntry, shouldRenderHTML = false, personalDetails?: Partial) { const assigneeAccountID = (getOriginalMessage(reportAction) as IssueNewCardOriginalMessage)?.assigneeAccountID; - const assigneeDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([assigneeAccountID], currentUserAccountID ?? -1).at(0); + const assigneeDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([assigneeAccountID], currentUserAccountID ?? -1, false, personalDetails).at(0); const assignee = shouldRenderHTML ? `` : assigneeDetails?.firstName ?? assigneeDetails?.login ?? ''; const link = shouldRenderHTML diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 077abf0b04c5..3a3e2f0e1338 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -789,13 +789,13 @@ const unavailableTranslation = Localize.translateLocal('workspace.common.unavail /** * Get the policy name from a given report */ -function getPolicyName(report: OnyxInputOrEntry, returnEmptyIfNotFound = false, policy?: OnyxInputOrEntry): string { +function getPolicyName(report: OnyxInputOrEntry, returnEmptyIfNotFound = false, policy?: OnyxInputOrEntry, policies?: OnyxCollection): string { const noPolicyFound = returnEmptyIfNotFound ? '' : unavailableTranslation; - if (isEmptyObject(report) || (isEmptyObject(allPolicies) && !report?.policyName)) { + if (isEmptyObject(report) || (isEmptyObject(allPolicies) && isEmptyObject(policies) && !report?.policyName)) { return noPolicyFound; } - const finalPolicy = policy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; + const finalPolicy = policy ?? (policies ?? allPolicies)?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const parentReport = getRootParentReport(report); @@ -2738,9 +2738,9 @@ function getMoneyRequestSpendBreakdown(report: OnyxInputOrEntry, allRepo /** * Get the title for a policy expense chat which depends on the role of the policy member seeing this report */ -function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry): string | undefined { +function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry, personalDetailsProp?: Partial): string | undefined { const ownerAccountID = report?.ownerAccountID; - const personalDetails = allPersonalDetails?.[ownerAccountID ?? -1]; + const personalDetails = (personalDetailsProp ?? allPersonalDetails)?.[ownerAccountID ?? -1]; const login = personalDetails ? personalDetails.login : null; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const reportOwnerDisplayName = getDisplayNameForParticipant(ownerAccountID) || login || report?.reportName; @@ -2840,8 +2840,8 @@ function getReportFieldKey(reportFieldId: string) { /** * Get the report fields attached to the policy given policyID */ -function getReportFieldsByPolicyID(policyID: string): Record { - const policyReportFields = Object.entries(allPolicies ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY, '') === policyID); +function getReportFieldsByPolicyID(policyID: string, policies?: OnyxCollection): Record { + const policyReportFields = Object.entries(policies ?? allPolicies ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY, '') === policyID); const fieldList = policyReportFields?.[1]?.fieldList; if (!policyReportFields || !fieldList) { @@ -2891,9 +2891,9 @@ function getAvailableReportFields(report: Report, policyReportFields: PolicyRepo /** * Get the title for an IOU or expense chat which will be showing the payer and the amount */ -function getMoneyRequestReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry): string { +function getMoneyRequestReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry, policies?: OnyxCollection): string { const isReportSettled = isSettled(report?.reportID ?? '-1'); - const reportFields = isReportSettled ? report?.fieldList : getReportFieldsByPolicyID(report?.policyID ?? '-1'); + const reportFields = isReportSettled ? report?.fieldList : getReportFieldsByPolicyID(report?.policyID ?? '-1', policies); const titleReportField = getFormulaTypeReportField(reportFields ?? {}); if (titleReportField && report?.reportName && isPaidGroupPolicyExpenseReport(report)) { @@ -3726,7 +3726,7 @@ function getReportActionMessage(reportAction: OnyxEntry, reportID? /** * Get the title for an invoice room. */ -function getInvoicesChatName(report: OnyxEntry, receiverPolicy: OnyxEntry): string { +function getInvoicesChatName(report: OnyxEntry, receiverPolicy: OnyxEntry, policies?: OnyxCollection): string { const invoiceReceiver = report?.invoiceReceiver; const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; const invoiceReceiverAccountID = isIndividual ? invoiceReceiver.accountID : -1; @@ -3742,7 +3742,7 @@ function getInvoicesChatName(report: OnyxEntry, receiverPolicy: OnyxEntr return PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[invoiceReceiverAccountID]); } - return getPolicyName(report, false, invoiceReceiverPolicy); + return getPolicyName(report, false, invoiceReceiverPolicy, policies); } const reportNameCache = new Map(); @@ -3767,6 +3767,7 @@ function getReportName( draftReports?: OnyxCollection, reportNameValuePairs?: OnyxCollection, policyTagLists?: OnyxCollection, + policies?: OnyxCollection, ): string { const reportID = report?.reportID; const cacheKey = getCacheKey(report); @@ -3848,7 +3849,7 @@ function getReportName( } if (ReportActionsUtils.isCardIssuedAction(parentReportAction)) { - return ReportActionsUtils.getCardIssuedMessage(parentReportAction); + return ReportActionsUtils.getCardIssuedMessage(parentReportAction, false, personalDetails); } return reportActionMessage; } @@ -3870,27 +3871,27 @@ function getReportName( } if (isPolicyExpenseChat(report)) { - formattedName = getPolicyExpenseChatName(report, policy); + formattedName = getPolicyExpenseChatName(report, policy, personalDetails); } if (isMoneyRequestReport(report)) { - formattedName = getMoneyRequestReportName(report, policy); + formattedName = getMoneyRequestReportName(report, policy, undefined, policies); } if (isInvoiceReport(report)) { - formattedName = getMoneyRequestReportName(report, policy, invoiceReceiverPolicy); + formattedName = getMoneyRequestReportName(report, policy, invoiceReceiverPolicy, policies); } if (isInvoiceRoom(report)) { - formattedName = getInvoicesChatName(report, invoiceReceiverPolicy); + formattedName = getInvoicesChatName(report, invoiceReceiverPolicy, policies); } if (shouldIncludePolicyName && (isUserCreatedPolicyRoom(report) || isDefaultRoom(report))) { - const policyName = getPolicyName(report, true); + const policyName = getPolicyName(report, true, undefined, policies); formattedName = policyName ? `${policyName} • ${report?.reportName}` : report?.reportName; } - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID, reportNameValuePairs))) { formattedName += ` (${Localize.translateLocal('common.archived')})`; } From 2c36ccc0f2d830a269026dc25cc32f89f3bd5535 Mon Sep 17 00:00:00 2001 From: zfurtak Date: Thu, 3 Oct 2024 09:53:34 +0100 Subject: [PATCH 008/368] Style change --- src/components/SelectionList/ChatListItem.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SelectionList/ChatListItem.tsx b/src/components/SelectionList/ChatListItem.tsx index 02bf9004ad5e..fa361efb11fa 100644 --- a/src/components/SelectionList/ChatListItem.tsx +++ b/src/components/SelectionList/ChatListItem.tsx @@ -85,7 +85,7 @@ function ChatListItem({ {(hovered) => ( - + In Date: Thu, 3 Oct 2024 15:34:22 +0100 Subject: [PATCH 009/368] Change props passing to getReportName --- src/components/AvatarWithDisplayName.tsx | 2 +- src/components/ReportWelcomeText.tsx | 4 +- .../LocalNotification/BrowserNotifications.ts | 2 +- src/libs/OptionsListUtils.ts | 4 +- src/libs/ReportUtils.ts | 45 ++++++++---- src/libs/SearchUtils.ts | 2 +- src/libs/SidebarUtils.ts | 6 +- src/libs/actions/Task.ts | 2 +- src/pages/ReportAvatar.tsx | 2 +- src/pages/ReportDetailsPage.tsx | 2 +- src/pages/RoomInvitePage.tsx | 2 +- src/pages/RoomMembersPage.tsx | 2 +- src/pages/Search/AdvancedSearchFilters.tsx | 2 +- src/pages/ShareCodePage.tsx | 2 +- src/pages/home/HeaderView.tsx | 9 ++- .../FloatingActionButtonAndPopover.tsx | 2 +- tests/perf-test/ReportUtils.perf-test.ts | 2 +- tests/unit/ReportUtilsTest.ts | 68 +++++++++++-------- 18 files changed, 97 insertions(+), 63 deletions(-) diff --git a/src/components/AvatarWithDisplayName.tsx b/src/components/AvatarWithDisplayName.tsx index 4f518452d3be..b8a07ae493d6 100644 --- a/src/components/AvatarWithDisplayName.tsx +++ b/src/components/AvatarWithDisplayName.tsx @@ -71,7 +71,7 @@ function AvatarWithDisplayName({ const [invoiceReceiverPolicy] = useOnyx( `${ONYXKEYS.COLLECTION.POLICY}${parentReport?.invoiceReceiver && 'policyID' in parentReport.invoiceReceiver ? parentReport.invoiceReceiver.policyID : -1}`, ); - const title = ReportUtils.getReportName(report, undefined, undefined, undefined, invoiceReceiverPolicy); + const title = ReportUtils.getReportName({report, policy: undefined, parentReportActionParam: undefined, personalDetails: undefined, invoiceReceiverPolicy}); const subtitle = ReportUtils.getChatRoomSubtitle(report); const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(report); const isMoneyRequestOrReport = diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index 97e611f0bafe..2c5c6fd450e1 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -53,7 +53,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP .map((item) => translate(`reportActionsView.iouTypes.${item}`)) .join(', '); const canEditPolicyDescription = ReportUtils.canEditPolicyDescription(policy); - const reportName = ReportUtils.getReportName(report); + const reportName = ReportUtils.getReportName({report}); const navigateToReport = () => { if (!report?.reportID) { @@ -137,7 +137,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP onPress={navigateToReport} suppressHighlighting > - {ReportUtils.getReportName(report)} + {ReportUtils.getReportName({report})} )} {welcomeMessage.phrase2 !== undefined && {welcomeMessage.phrase2}} diff --git a/src/libs/Notification/LocalNotification/BrowserNotifications.ts b/src/libs/Notification/LocalNotification/BrowserNotifications.ts index 4c214a66c569..44256eb069d8 100644 --- a/src/libs/Notification/LocalNotification/BrowserNotifications.ts +++ b/src/libs/Notification/LocalNotification/BrowserNotifications.ts @@ -110,7 +110,7 @@ export default { } if (isChatRoom) { - const roomName = ReportUtils.getReportName(report); + const roomName = ReportUtils.getReportName({report}); title = roomName; body = `${plainTextPerson}: ${plainTextMessage}`; } else { diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 90320b4a9ea1..b7e14fcbea60 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -816,7 +816,7 @@ function createOption( reportName = showPersonalDetails ? ReportUtils.getDisplayNameForParticipant(accountIDs.at(0)) || LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? '') - : ReportUtils.getReportName(report); + : ReportUtils.getReportName({report}); } else { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing reportName = ReportUtils.getDisplayNameForParticipant(accountIDs.at(0)) || LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? ''); @@ -863,7 +863,7 @@ function getReportOption(participant: Participant): ReportUtils.OptionData { if (option.isSelfDM) { option.alternateText = Localize.translateLocal('reportActionsView.yourSpace'); } else if (option.isInvoiceRoom) { - option.text = ReportUtils.getReportName(report); + option.text = ReportUtils.getReportName({report}); option.alternateText = Localize.translateLocal('workspace.common.invoices'); } else { option.text = ReportUtils.getPolicyName(report); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0434861d7640..121e1b5d329f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -547,6 +547,21 @@ type Thread = { parentReportActionID: string; } & Report; +type GetReportNameParams = { + report: OnyxEntry; + policy?: OnyxEntry; + parentReportActionParam?: OnyxInputOrEntry; + personalDetails?: Partial; + invoiceReceiverPolicy?: OnyxEntry; + shouldIncludePolicyName?: boolean; + transactions?: OnyxCollection; + reports?: OnyxCollection; + draftReports?: OnyxCollection; + reportNameValuePairs?: OnyxCollection; + policyTagLists?: OnyxCollection; + policies?: OnyxCollection; +}; + let currentUserEmail: string | undefined; let currentUserPrivateDomain: string | undefined; let currentUserAccountID: number | undefined; @@ -3679,7 +3694,7 @@ function parseReportActionHtmlToText(reportAction: OnyxEntry, repo for (const match of matches) { if (match[1] !== childReportID) { // eslint-disable-next-line @typescript-eslint/no-use-before-define - reportIDToName[match[1]] = getReportName(getReportOrDraftReport(match[1])) ?? ''; + reportIDToName[match[1]] = getReportName({report: getReportOrDraftReport(match[1])}) ?? ''; } } @@ -3755,20 +3770,20 @@ const getCacheKey = (report: OnyxEntry): string => `${report?.reportID}- /** * Get the title for a report. */ -function getReportName( - report: OnyxEntry, - policy?: OnyxEntry, - parentReportActionParam?: OnyxInputOrEntry, - personalDetails?: Partial, - invoiceReceiverPolicy?: OnyxEntry, +function getReportName({ + report, + policy, + parentReportActionParam, + personalDetails, + invoiceReceiverPolicy, shouldIncludePolicyName = false, - transactions?: OnyxCollection, - reports?: OnyxCollection, - draftReports?: OnyxCollection, - reportNameValuePairs?: OnyxCollection, - policyTagLists?: OnyxCollection, - policies?: OnyxCollection, -): string { + transactions, + reports, + draftReports, + reportNameValuePairs, + policyTagLists, + policies, +}: GetReportNameParams): string { const reportID = report?.reportID; const cacheKey = getCacheKey(report); @@ -4003,7 +4018,7 @@ function getParentNavigationSubtitle(report: OnyxEntry, invoiceReceiverP } return { - reportName: getReportName(parentReport), + reportName: getReportName({report: parentReport}), workspaceName: getPolicyName(parentReport, true), }; } diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 47cee2c7c2b4..8769ca3fa7bf 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -734,7 +734,7 @@ function getDisplayValue(filterName: string, filter: string, personalDetails: On return cardList[filter].bank; } if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) { - return ReportUtils.getReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${filter}`]); + return ReportUtils.getReportName({report: reports?.[`${ONYXKEYS.COLLECTION.REPORT}${filter}`]}); } return filter; } diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 0496bc66fe5b..cb8d5faac9c7 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -185,7 +185,7 @@ function getOrderedReportIDs( const report = reportToDisplay; const miniReport: MiniReport = { reportID: report?.reportID, - displayName: ReportUtils.getReportName(report), + displayName: ReportUtils.getReportName({report}), lastVisibleActionCreated: report?.lastVisibleActionCreated, }; @@ -488,7 +488,7 @@ function getOptionData({ result.phoneNumber = personalDetail?.phoneNumber ?? ''; } - const reportName = ReportUtils.getReportName(report, policy, undefined, undefined, invoiceReceiverPolicy, true); + const reportName = ReportUtils.getReportName({report, policy, invoiceReceiverPolicy, shouldIncludePolicyName: true}); result.text = reportName; result.subtitle = subtitle; @@ -604,7 +604,7 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartOne'); welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartTwo'); } - welcomeMessage.messageText = `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; + welcomeMessage.messageText = `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName({report}) : ''} ${welcomeMessage.phrase2 ?? ''}`; return welcomeMessage; } diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 2f9ec060c1e8..a110592ae3da 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -909,7 +909,7 @@ function getShareDestination(reportID: string, reports: OnyxCollection ReportUtils.getReportName(report), [report]); + const reportName = useMemo(() => ReportUtils.getReportName({report}), [report]); const inviteUsers = useCallback(() => { HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index f8c07e5b0a67..6e01651ef4fd 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -353,7 +353,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { > { if (selectionMode?.isEnabled) { setSelectedMembers([]); diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index 7009764629ba..98b414a10930 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -218,7 +218,7 @@ function getFilterExpenseDisplayTitle(filters: Partial, translate: LocaleContextProps['translate'], reports?: OnyxCollection) { - return filters.in ? filters.in.map((id) => ReportUtils.getReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`])).join(', ') : undefined; + return filters.in ? filters.in.map((id) => ReportUtils.getReportName({report: reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`]})).join(', ') : undefined; } function AdvancedSearchFilters() { const {translate} = useLocalize(); diff --git a/src/pages/ShareCodePage.tsx b/src/pages/ShareCodePage.tsx index 18f6c5960b5e..a77ffbb7621d 100644 --- a/src/pages/ShareCodePage.tsx +++ b/src/pages/ShareCodePage.tsx @@ -82,7 +82,7 @@ function ShareCodePage({report, policy, backTo}: ShareCodePageProps) { return currentUserPersonalDetails.login; }, [report, currentUserPersonalDetails, isReport]); - const title = isReport ? ReportUtils.getReportName(report) : currentUserPersonalDetails.displayName ?? ''; + const title = isReport ? ReportUtils.getReportName({report}) : currentUserPersonalDetails.displayName ?? ''; const urlWithTrailingSlash = Url.addTrailingForwardSlash(environmentURL); const url = isReport ? `${urlWithTrailingSlash}${ROUTES.REPORT_WITH_ID.getRoute(report.reportID)}` diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index 81ee426aa8dd..82b557d07760 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -87,7 +87,14 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto const isTaskReport = ReportUtils.isTaskReport(report); const reportHeaderData = !isTaskReport && !isChatThread && report?.parentReportID ? parentReport : report; // Use sorted display names for the title for group chats on native small screen widths - const title = ReportUtils.getReportName(reportHeaderData, policy, parentReportAction, personalDetails, invoiceReceiverPolicy, true); + const title = ReportUtils.getReportName({ + report: reportHeaderData, + policy, + parentReportActionParam: parentReportAction, + personalDetails, + invoiceReceiverPolicy, + shouldIncludePolicyName: true, + }); const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData, true); const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(reportHeaderData); const reportDescription = ReportUtils.getReportDescriptionText(report); diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index a49b474b185e..681f12203350 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -477,7 +477,7 @@ function FloatingActionButtonAndPopover( isLabelHoverable: false, floatRightAvatars: quickActionAvatars, floatRightAvatarSize: CONST.AVATAR_SIZE.SMALL, - description: !hideQABSubtitle ? ReportUtils.getReportName(quickActionReport) ?? translate('quickAction.updateDestination') : '', + description: !hideQABSubtitle ? ReportUtils.getReportName({report: quickActionReport}) ?? translate('quickAction.updateDestination') : '', numberOfLinesDescription: 1, onSelected: () => interceptAnonymousUser(() => navigateToQuickAction()), shouldShowSubscriptRightAvatar: ReportUtils.isPolicyExpenseChat(quickActionReport), diff --git a/tests/perf-test/ReportUtils.perf-test.ts b/tests/perf-test/ReportUtils.perf-test.ts index 8cd531db8628..dfff24bca0e1 100644 --- a/tests/perf-test/ReportUtils.perf-test.ts +++ b/tests/perf-test/ReportUtils.perf-test.ts @@ -128,7 +128,7 @@ describe('ReportUtils', () => { const policy = createRandomPolicy(1); await waitForBatchedUpdates(); - await measureFunction(() => ReportUtils.getReportName(report, policy)); + await measureFunction(() => ReportUtils.getReportName({report, policy})); }); test('[ReportUtils] canShowReportRecipientLocalTime on 1k participants', async () => { diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 091a8cafa37e..254606ddbcf8 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -117,8 +117,10 @@ describe('ReportUtils', () => { test('with displayName', () => { expect( ReportUtils.getReportName({ - reportID: '', - participants: ReportUtils.buildParticipantsFromAccountIDs([currentUserAccountID, 1]), + report: { + reportID: '', + participants: ReportUtils.buildParticipantsFromAccountIDs([currentUserAccountID, 1]), + }, }), ).toBe('Ragnar Lothbrok'); }); @@ -126,8 +128,10 @@ describe('ReportUtils', () => { test('no displayName', () => { expect( ReportUtils.getReportName({ - reportID: '', - participants: ReportUtils.buildParticipantsFromAccountIDs([currentUserAccountID, 2]), + report: { + reportID: '', + participants: ReportUtils.buildParticipantsFromAccountIDs([currentUserAccountID, 2]), + }, }), ).toBe('floki@vikings.net'); }); @@ -135,8 +139,10 @@ describe('ReportUtils', () => { test('SMS', () => { expect( ReportUtils.getReportName({ - reportID: '', - participants: ReportUtils.buildParticipantsFromAccountIDs([currentUserAccountID, 4]), + report: { + reportID: '', + participants: ReportUtils.buildParticipantsFromAccountIDs([currentUserAccountID, 4]), + }, }), ).toBe('(833) 240-3627'); }); @@ -145,8 +151,10 @@ describe('ReportUtils', () => { test('Group DM', () => { expect( ReportUtils.getReportName({ - reportID: '', - participants: ReportUtils.buildParticipantsFromAccountIDs([currentUserAccountID, 1, 2, 3, 4]), + report: { + reportID: '', + participants: ReportUtils.buildParticipantsFromAccountIDs([currentUserAccountID, 1, 2, 3, 4]), + }, }), ).toBe('Ragnar, floki@vikings.net, Lagertha, (833) 240-3627'); }); @@ -159,7 +167,7 @@ describe('ReportUtils', () => { }; test('Active', () => { - expect(ReportUtils.getReportName(baseAdminsRoom)).toBe('#admins'); + expect(ReportUtils.getReportName({report: baseAdminsRoom})).toBe('#admins'); }); test('Archived', () => { @@ -171,9 +179,9 @@ describe('ReportUtils', () => { private_isArchived: DateUtils.getDBTime(), }; - expect(ReportUtils.getReportName(archivedAdminsRoom)).toBe('#admins (archived)'); + expect(ReportUtils.getReportName({report: archivedAdminsRoom})).toBe('#admins (archived)'); - return Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES).then(() => expect(ReportUtils.getReportName(archivedAdminsRoom)).toBe('#admins (archivado)')); + return Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES).then(() => expect(ReportUtils.getReportName({report: archivedAdminsRoom})).toBe('#admins (archivado)')); }); }); @@ -185,7 +193,7 @@ describe('ReportUtils', () => { }; test('Active', () => { - expect(ReportUtils.getReportName(baseUserCreatedRoom)).toBe('#VikingsChat'); + expect(ReportUtils.getReportName({report: baseUserCreatedRoom})).toBe('#VikingsChat'); }); test('Archived', () => { @@ -197,9 +205,9 @@ describe('ReportUtils', () => { private_isArchived: DateUtils.getDBTime(), }; - expect(ReportUtils.getReportName(archivedPolicyRoom)).toBe('#VikingsChat (archived)'); + expect(ReportUtils.getReportName({report: archivedPolicyRoom})).toBe('#VikingsChat (archived)'); - return Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES).then(() => expect(ReportUtils.getReportName(archivedPolicyRoom)).toBe('#VikingsChat (archivado)')); + return Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES).then(() => expect(ReportUtils.getReportName({report: archivedPolicyRoom})).toBe('#VikingsChat (archivado)')); }); }); @@ -208,11 +216,13 @@ describe('ReportUtils', () => { test('as member', () => { expect( ReportUtils.getReportName({ - reportID: '', - chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, - policyID: policy.id, - isOwnPolicyExpenseChat: true, - ownerAccountID: 1, + report: { + reportID: '', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + policyID: policy.id, + isOwnPolicyExpenseChat: true, + ownerAccountID: 1, + }, }), ).toBe('Vikings Policy'); }); @@ -220,11 +230,13 @@ describe('ReportUtils', () => { test('as admin', () => { expect( ReportUtils.getReportName({ - reportID: '', - chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, - policyID: policy.id, - isOwnPolicyExpenseChat: false, - ownerAccountID: 1, + report: { + reportID: '', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + policyID: policy.id, + isOwnPolicyExpenseChat: false, + ownerAccountID: 1, + }, }), ).toBe('Ragnar Lothbrok'); }); @@ -249,10 +261,10 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: true, }; - expect(ReportUtils.getReportName(memberArchivedPolicyExpenseChat)).toBe('Vikings Policy (archived)'); + expect(ReportUtils.getReportName({report: memberArchivedPolicyExpenseChat})).toBe('Vikings Policy (archived)'); return Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES).then(() => - expect(ReportUtils.getReportName(memberArchivedPolicyExpenseChat)).toBe('Vikings Policy (archivado)'), + expect(ReportUtils.getReportName({report: memberArchivedPolicyExpenseChat})).toBe('Vikings Policy (archivado)'), ); }); @@ -262,10 +274,10 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: false, }; - expect(ReportUtils.getReportName(adminArchivedPolicyExpenseChat)).toBe('Ragnar Lothbrok (archived)'); + expect(ReportUtils.getReportName({report: adminArchivedPolicyExpenseChat})).toBe('Ragnar Lothbrok (archived)'); return Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES).then(() => - expect(ReportUtils.getReportName(adminArchivedPolicyExpenseChat)).toBe('Ragnar Lothbrok (archivado)'), + expect(ReportUtils.getReportName({report: adminArchivedPolicyExpenseChat})).toBe('Ragnar Lothbrok (archivado)'), ); }); }); From 47ccecaea6a41db4314a2ca79e1786e93e906f07 Mon Sep 17 00:00:00 2001 From: zfurtak Date: Mon, 7 Oct 2024 09:38:08 +0100 Subject: [PATCH 010/368] Adjusted to review --- src/components/ArchivedReportFooter.tsx | 2 +- src/components/AvatarWithDisplayName.tsx | 2 +- .../ReportActionItem/ReportPreview.tsx | 2 +- src/components/ReportWelcomeText.tsx | 2 +- src/components/SelectionList/ChatListItem.tsx | 2 +- src/libs/ModifiedExpenseMessage.ts | 7 +- src/libs/OptionsListUtils.ts | 6 +- src/libs/PersonalDetailsUtils.ts | 11 +-- src/libs/ReportActionsUtils.ts | 4 +- src/libs/ReportUtils.ts | 68 +++++++++++-------- src/libs/SidebarUtils.ts | 4 +- src/pages/ReportAvatar.tsx | 2 +- src/pages/ShareCodePage.tsx | 2 +- src/pages/home/HeaderView.tsx | 2 +- .../home/report/ReportActionItemSingle.tsx | 2 +- 15 files changed, 63 insertions(+), 55 deletions(-) diff --git a/src/components/ArchivedReportFooter.tsx b/src/components/ArchivedReportFooter.tsx index af77a20b4caa..919d405ebd42 100644 --- a/src/components/ArchivedReportFooter.tsx +++ b/src/components/ArchivedReportFooter.tsx @@ -45,7 +45,7 @@ function ArchivedReportFooter({report, reportClosedAction, personalDetails = {}} const shouldRenderHTML = archiveReason !== CONST.REPORT.ARCHIVE_REASON.DEFAULT && archiveReason !== CONST.REPORT.ARCHIVE_REASON.BOOKING_END_DATE_HAS_PASSED; - let policyName = ReportUtils.getPolicyName(report); + let policyName = ReportUtils.getPolicyName({report}); if (archiveReason === CONST.REPORT.ARCHIVE_REASON.INVOICE_RECEIVER_POLICY_DELETED) { policyName = originalMessage?.receiverPolicyName ?? ''; diff --git a/src/components/AvatarWithDisplayName.tsx b/src/components/AvatarWithDisplayName.tsx index b8a07ae493d6..062a380c434a 100644 --- a/src/components/AvatarWithDisplayName.tsx +++ b/src/components/AvatarWithDisplayName.tsx @@ -71,7 +71,7 @@ function AvatarWithDisplayName({ const [invoiceReceiverPolicy] = useOnyx( `${ONYXKEYS.COLLECTION.POLICY}${parentReport?.invoiceReceiver && 'policyID' in parentReport.invoiceReceiver ? parentReport.invoiceReceiver.policyID : -1}`, ); - const title = ReportUtils.getReportName({report, policy: undefined, parentReportActionParam: undefined, personalDetails: undefined, invoiceReceiverPolicy}); + const title = ReportUtils.getReportName({report, invoiceReceiverPolicy}); const subtitle = ReportUtils.getChatRoomSubtitle(report); const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(report); const isMoneyRequestOrReport = diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index cadfe5786079..f4f6bf00b3e2 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -285,7 +285,7 @@ function ReportPreview({ let payerOrApproverName; if (isPolicyExpenseChat) { - payerOrApproverName = ReportUtils.getPolicyName(chatReport, undefined, policy); + payerOrApproverName = ReportUtils.getPolicyName({report: chatReport, policy}); } else if (isInvoiceRoom) { payerOrApproverName = ReportUtils.getInvoicePayerName(chatReport, invoiceReceiverPolicy); } else { diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index 2c5c6fd450e1..cef9d6ccaf88 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -108,7 +108,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP {welcomeMessage.phrase1} {ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} {welcomeMessage.phrase2} - {ReportUtils.getPolicyName(report)} + {ReportUtils.getPolicyName({report})} {welcomeMessage.phrase3} ))} diff --git a/src/components/SelectionList/ChatListItem.tsx b/src/components/SelectionList/ChatListItem.tsx index 89ae30d2846d..b4bfa400797c 100644 --- a/src/components/SelectionList/ChatListItem.tsx +++ b/src/components/SelectionList/ChatListItem.tsx @@ -92,7 +92,7 @@ function ChatListItem({ fontSize={variables.fontSizeSmall} onPress={() => onSelectRow(item)} > - {/* {ReportUtils.getReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`])} */} + {/* {ReportUtils.getReportName( */} Report test diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 0fa22b798a23..b19e35e81406 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -132,12 +132,13 @@ function getForDistanceRequest(newMerchant: string, oldMerchant: string, newAmou * ModifiedExpense::getNewDotComment in Web-Expensify should match this. * If we change this function be sure to update the backend as well. */ -function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry, reports?: OnyxCollection, propPolicyTags?: OnyxCollection): string { +function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry, reports?: OnyxCollection, policyTagLists = allPolicyTags): string { if (!ReportActionsUtils.isModifiedExpenseAction(reportAction)) { return ''; } const reportActionOriginalMessage = ReportActionsUtils.getOriginalMessage(reportAction); - const report = (reports ?? ReportConnection.getAllReports())?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const allReports = reports ?? ReportConnection.getAllReports(); + const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; const policyID = report?.policyID ?? '-1'; const removalFragments: string[] = []; @@ -225,7 +226,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr const hasModifiedTag = isReportActionOriginalMessageAnObject && 'oldTag' in reportActionOriginalMessage && 'tag' in reportActionOriginalMessage; if (hasModifiedTag) { - const policyTags = (propPolicyTags ?? allPolicyTags)?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {}; + const policyTags = policyTagLists?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {}; const transactionTag = reportActionOriginalMessage?.tag ?? ''; const oldTransactionTag = reportActionOriginalMessage?.oldTag ?? ''; const splittedTag = TransactionUtils.getTagArrayFromName(transactionTag); diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index b7e14fcbea60..294065550ff1 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -633,7 +633,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails case CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED: { lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { displayName: PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails), - policyName: ReportUtils.getPolicyName(report, false, policy), + policyName: ReportUtils.getPolicyName({report, policy}), }); break; } @@ -866,7 +866,7 @@ function getReportOption(participant: Participant): ReportUtils.OptionData { option.text = ReportUtils.getReportName({report}); option.alternateText = Localize.translateLocal('workspace.common.invoices'); } else { - option.text = ReportUtils.getPolicyName(report); + option.text = ReportUtils.getPolicyName({report}); option.alternateText = Localize.translateLocal('workspace.common.workspace'); } option.isDisabled = ReportUtils.isDraftReport(participant.reportID); @@ -897,7 +897,7 @@ function getPolicyExpenseReportOption(participant: Participant | ReportUtils.Opt ); // Update text & alternateText because createOption returns workspace name only if report is owned by the user - option.text = ReportUtils.getPolicyName(expenseReport); + option.text = ReportUtils.getPolicyName({report: expenseReport}); option.alternateText = Localize.translateLocal('workspace.common.workspace'); option.selected = participant.selected; option.isSelected = participant.selected; diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 03f96fd43a60..9acd690609ed 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -85,16 +85,11 @@ function getDisplayNameOrDefault(passedPersonalDetails?: Partial, -): PersonalDetails[] { +function getPersonalDetailsByIDs(accountIDs: number[], currentUserAccountID: number, shouldChangeUserDisplayName = false, personalDetailsProp = allPersonalDetails): PersonalDetails[] { const result: PersonalDetails[] = accountIDs - .filter((accountID) => !!(personalDetailsProp ?? allPersonalDetails)?.[accountID]) + .filter((accountID) => !!personalDetailsProp?.[accountID]) .map((accountID) => { - const detail = ((personalDetailsProp ?? allPersonalDetails)?.[accountID] ?? {}) as PersonalDetails; + const detail = (personalDetailsProp?.[accountID] ?? {}) as PersonalDetails; if (shouldChangeUserDisplayName && currentUserAccountID === detail.accountID) { return { diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index fee6da04589d..71c9eb289f36 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -125,7 +125,7 @@ function isDeletedAction(reportAction: OnyxInputOrEntry) { return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL, CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS); } -function getCardIssuedMessage(reportAction: OnyxEntry, shouldRenderHTML = false, personalDetails?: Partial) { +function getCardIssuedMessage(reportAction: OnyxEntry, shouldRenderHTML = false, personalDetails?: OnyxEntry) { const assigneeAccountID = (getOriginalMessage(reportAction) as IssueNewCardOriginalMessage)?.assigneeAccountID; const assigneeDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([assigneeAccountID], currentUserAccountID ?? -1, false, personalDetails).at(0); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 121e1b5d329f..117044f7b688 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -551,7 +551,7 @@ type GetReportNameParams = { report: OnyxEntry; policy?: OnyxEntry; parentReportActionParam?: OnyxInputOrEntry; - personalDetails?: Partial; + personalDetails?: OnyxEntry; invoiceReceiverPolicy?: OnyxEntry; shouldIncludePolicyName?: boolean; transactions?: OnyxCollection; @@ -562,6 +562,13 @@ type GetReportNameParams = { policies?: OnyxCollection; }; +type GetPolicyNameParams = { + report: OnyxInputOrEntry; + returnEmptyIfNotFound?: boolean; + policy?: OnyxInputOrEntry; + policies?: OnyxCollection; +}; + let currentUserEmail: string | undefined; let currentUserPrivateDomain: string | undefined; let currentUserAccountID: number | undefined; @@ -724,9 +731,14 @@ function getChatType(report: OnyxInputOrEntry | Participant): ValueOf, draftReports?: OnyxCollection): OnyxEntry { - const allReports = ReportConnection.getAllReports(); - return (reports ?? allReports)?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? (draftReports ?? allReportsDraft)?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportID}`]; +function getReportOrDraftReport(reportID: string | undefined, reports?: OnyxCollection, draftReports: OnyxCollection = allReportsDraft): OnyxEntry { + const allReports = reports ?? ReportConnection.getAllReports(); + + if (allReports) { + return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + } + + return draftReports?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportID}`]; } /** @@ -748,8 +760,8 @@ function getReport(reportID: string): OnyxEntry { /** * Returns the report */ -function getReportNameValuePairs(reportID?: string, reportNameValuePairs?: OnyxCollection): OnyxEntry { - return (reportNameValuePairs ?? allReportNameValuePair)?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID ?? -1}`]; +function getReportNameValuePairs(reportID?: string, reportNameValuePairs: OnyxCollection = allReportNameValuePair): OnyxEntry { + return reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID ?? -1}`]; } /** @@ -804,13 +816,13 @@ const unavailableTranslation = Localize.translateLocal('workspace.common.unavail /** * Get the policy name from a given report */ -function getPolicyName(report: OnyxInputOrEntry, returnEmptyIfNotFound = false, policy?: OnyxInputOrEntry, policies?: OnyxCollection): string { +function getPolicyName({report, returnEmptyIfNotFound = false, policy, policies = allPolicies}: GetPolicyNameParams): string { const noPolicyFound = returnEmptyIfNotFound ? '' : unavailableTranslation; if (isEmptyObject(report) || (isEmptyObject(allPolicies) && isEmptyObject(policies) && !report?.policyName)) { return noPolicyFound; } - const finalPolicy = policy ?? (policies ?? allPolicies)?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; + const finalPolicy = policy ?? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const parentReport = getRootParentReport(report); @@ -1414,7 +1426,7 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa /** * Whether the provided report has expenses */ -function hasExpenses(reportID?: string, transactions?: OnyxCollection): boolean { +function hasExpenses(reportID?: string, transactions: OnyxCollection = allTransactions): boolean { return !!Object.values(transactions ?? {}).find((transaction) => `${transaction?.reportID}` === `${reportID}`); } @@ -2008,7 +2020,7 @@ const workSpaceIconsCache = new Map(); * Given a report, return the associated workspace icon. */ function getWorkspaceIcon(report: OnyxInputOrEntry, policy?: OnyxInputOrEntry): Icon { - const workspaceName = getPolicyName(report, false, policy); + const workspaceName = getPolicyName({report, policy}); const cacheKey = report?.policyID ?? workspaceName; const iconFromCache = workSpaceIconsCache.get(cacheKey); // disabling to protect against empty strings @@ -2753,16 +2765,16 @@ function getMoneyRequestSpendBreakdown(report: OnyxInputOrEntry, allRepo /** * Get the title for a policy expense chat which depends on the role of the policy member seeing this report */ -function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry, personalDetailsProp?: Partial): string | undefined { +function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry, personalDetailsProp = allPersonalDetails): string | undefined { const ownerAccountID = report?.ownerAccountID; - const personalDetails = (personalDetailsProp ?? allPersonalDetails)?.[ownerAccountID ?? -1]; + const personalDetails = personalDetailsProp?.[ownerAccountID ?? -1]; const login = personalDetails ? personalDetails.login : null; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const reportOwnerDisplayName = getDisplayNameForParticipant(ownerAccountID) || login || report?.reportName; // If the policy expense chat is owned by this user, use the name of the policy as the report name. if (report?.isOwnPolicyExpenseChat) { - return getPolicyName(report, false, policy); + return getPolicyName({report, policy}); } let policyExpenseChatRole = 'user'; @@ -2777,7 +2789,7 @@ function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry< const lastAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? '-1'); const archiveReason = ReportActionsUtils.isClosedAction(lastAction) ? ReportActionsUtils.getOriginalMessage(lastAction)?.reason : CONST.REPORT.ARCHIVE_REASON.DEFAULT; if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED && policyExpenseChatRole !== CONST.POLICY.ROLE.ADMIN) { - return getPolicyName(report, false, policy); + return getPolicyName({report, policy}); } } @@ -2855,8 +2867,8 @@ function getReportFieldKey(reportFieldId: string) { /** * Get the report fields attached to the policy given policyID */ -function getReportFieldsByPolicyID(policyID: string, policies?: OnyxCollection): Record { - const policyReportFields = Object.entries(policies ?? allPolicies ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY, '') === policyID); +function getReportFieldsByPolicyID(policyID: string, policies: OnyxCollection = allPolicies): Record { + const policyReportFields = Object.entries(policies ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY, '') === policyID); const fieldList = policyReportFields?.[1]?.fieldList; if (!policyReportFields || !fieldList) { @@ -2920,7 +2932,7 @@ function getMoneyRequestReportName(report: OnyxEntry, policy?: OnyxEntry let payerOrApproverName; if (isExpenseReport(report)) { - payerOrApproverName = getPolicyName(report, false, policy); + payerOrApproverName = getPolicyName({report, policy}); } else if (isInvoiceReport(report)) { const chatReport = getReportOrDraftReport(report?.chatReportID); payerOrApproverName = getInvoicePayerName(chatReport, invoiceReceiverPolicy); @@ -3258,14 +3270,14 @@ function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewActio * * NOTE: This method is only meant to be used inside this action file. Do not export and use it elsewhere. Use withOnyx or Onyx.connect() instead. */ -function getLinkedTransaction(reportAction: OnyxEntry, transactions?: OnyxCollection): OnyxEntry { +function getLinkedTransaction(reportAction: OnyxEntry, transactions: OnyxCollection = allTransactions): OnyxEntry { let transactionID = ''; if (ReportActionsUtils.isMoneyRequestAction(reportAction)) { transactionID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID ?? '-1'; } - return (transactions ?? allTransactions)?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + return transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; } /** @@ -3420,7 +3432,7 @@ function getReportPreviewMessage( const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID); const totalAmount = getMoneyRequestSpendBreakdown(report).totalDisplaySpend; - const policyName = getPolicyName(report, false, policy); + const policyName = getPolicyName({report, policy}); const payerName = isExpenseReport(report) ? policyName : getDisplayNameForParticipant(report.managerID, !isPreviewMessageForParentChatReport); const formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency); @@ -3665,7 +3677,7 @@ function getInvoicePayerName(report: OnyxEntry, invoiceReceiverPolicy?: return PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[invoiceReceiver.accountID]); } - return getPolicyName(report, false, invoiceReceiverPolicy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiver?.policyID}`]); + return getPolicyName({report, policy: invoiceReceiverPolicy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiver?.policyID}`]}); } /** @@ -3750,14 +3762,14 @@ function getInvoicesChatName(report: OnyxEntry, receiverPolicy: OnyxEntr const isCurrentUserReceiver = (isIndividual && invoiceReceiverAccountID === currentUserAccountID) || (!isIndividual && PolicyUtils.isPolicyAdmin(invoiceReceiverPolicy)); if (isCurrentUserReceiver) { - return getPolicyName(report); + return getPolicyName({report}); } if (isIndividual) { return PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[invoiceReceiverAccountID]); } - return getPolicyName(report, false, invoiceReceiverPolicy, policies); + return getPolicyName({report, policy: invoiceReceiverPolicy, policies}); } const reportNameCache = new Map(); @@ -3902,7 +3914,7 @@ function getReportName({ } if (shouldIncludePolicyName && (isUserCreatedPolicyRoom(report) || isDefaultRoom(report))) { - const policyName = getPolicyName(report, true, undefined, policies); + const policyName = getPolicyName({report, returnEmptyIfNotFound: true, policies}); formattedName = policyName ? `${policyName} • ${report?.reportName}` : report?.reportName; } @@ -3985,7 +3997,7 @@ function getChatRoomSubtitle(report: OnyxEntry, isTitleIncludePolicyName if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { return report?.oldPolicyName ?? ''; } - return getPolicyName(report); + return getPolicyName({report}); } /** @@ -4006,7 +4018,7 @@ function getParentNavigationSubtitle(report: OnyxEntry, invoiceReceiverP } if (isInvoiceReport(report) || isInvoiceRoom(parentReport)) { - let reportName = `${getPolicyName(parentReport)} & ${getInvoicePayerName(parentReport, invoiceReceiverPolicy)}`; + let reportName = `${getPolicyName({report: parentReport})} & ${getInvoicePayerName(parentReport, invoiceReceiverPolicy)}`; if (isArchivedRoom(parentReport, getReportNameValuePairs(parentReport?.reportID))) { reportName += ` (${Localize.translateLocal('common.archived')})`; @@ -4019,7 +4031,7 @@ function getParentNavigationSubtitle(report: OnyxEntry, invoiceReceiverP return { reportName: getReportName({report: parentReport}), - workspaceName: getPolicyName(parentReport, true), + workspaceName: getPolicyName({report: parentReport, returnEmptyIfNotFound: true}), }; } @@ -4495,7 +4507,7 @@ function buildOptimisticExpenseReport( ): OptimisticExpenseReport { // The amount for Expense reports are stored as negative value in the database const storedTotal = total * -1; - const policyName = getPolicyName(ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]); + const policyName = getPolicyName({report: ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]}); const formattedTotal = CurrencyUtils.convertToDisplayString(storedTotal, currency); const policy = getPolicy(policyID); diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index cb8d5faac9c7..2c2998ba17bc 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -524,7 +524,7 @@ function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry) welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree'); welcomeMessage.messageText = `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName( - report, + {report}, )} ${welcomeMessage.phrase3}`; } return welcomeMessage; @@ -576,7 +576,7 @@ function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry) */ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { const welcomeMessage: WelcomeMessage = {showReportName: true}; - const workspaceName = ReportUtils.getPolicyName(report); + const workspaceName = ReportUtils.getPolicyName({report}); if (report?.description) { welcomeMessage.messageHtml = report.description; diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index a7903e768151..7119945a0c4f 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -31,7 +31,7 @@ function ReportAvatar({route}: ReportAvatarProps) { return { source: UserUtils.getFullSizeAvatar(ReportUtils.getWorkspaceIcon(report).source, 0), - headerTitle: ReportUtils.getPolicyName(report, false, policy), + headerTitle: ReportUtils.getPolicyName({report, policy}), // In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar originalFileName: policy?.originalFileName ?? policy?.id ?? report?.policyID ?? '', isWorkspaceAvatar: true, diff --git a/src/pages/ShareCodePage.tsx b/src/pages/ShareCodePage.tsx index a77ffbb7621d..d953d42e0e92 100644 --- a/src/pages/ShareCodePage.tsx +++ b/src/pages/ShareCodePage.tsx @@ -67,7 +67,7 @@ function ShareCodePage({report, policy, backTo}: ShareCodePageProps) { const subtitle = useMemo(() => { if (isReport) { if (ReportUtils.isExpenseReport(report)) { - return ReportUtils.getPolicyName(report); + return ReportUtils.getPolicyName({report}); } if (ReportUtils.isMoneyRequestReport(report)) { // generate subtitle from participants diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index 82b557d07760..9826bcce2050 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -98,7 +98,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData, true); const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(reportHeaderData); const reportDescription = ReportUtils.getReportDescriptionText(report); - const policyName = ReportUtils.getPolicyName(report, true); + const policyName = ReportUtils.getPolicyName({report, returnEmptyIfNotFound: true}); const policyDescription = ReportUtils.getPolicyDescriptionText(policy); const isPersonalExpenseChat = isPolicyExpenseChat && ReportUtils.isCurrentUserSubmitter(report?.reportID ?? ''); const shouldShowSubtitle = () => { diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index ca11a1b02d26..1027df7221f7 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -103,7 +103,7 @@ function ReportActionItemSingle({ let avatarId: number | string | undefined = actorAccountID; if (isWorkspaceActor) { - displayName = ReportUtils.getPolicyName(report, undefined, policy); + displayName = ReportUtils.getPolicyName({report, policy}); actorHint = displayName; avatarSource = ReportUtils.getWorkspaceIcon(report, policy).source; avatarId = report?.policyID; From 06d6e65f857b7efcc05e9c00bc6de46be5a6eda7 Mon Sep 17 00:00:00 2001 From: zfurtak Date: Mon, 7 Oct 2024 09:56:06 +0100 Subject: [PATCH 011/368] Adjusted to review --- src/libs/ReportUtils.ts | 53 +++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 117044f7b688..bc9c327e3c0e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2765,9 +2765,17 @@ function getMoneyRequestSpendBreakdown(report: OnyxInputOrEntry, allRepo /** * Get the title for a policy expense chat which depends on the role of the policy member seeing this report */ -function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry, personalDetailsProp = allPersonalDetails): string | undefined { +function getPolicyExpenseChatName({ + report, + policy, + personalDetailsList = allPersonalDetails, +}: { + report: OnyxEntry; + policy?: OnyxEntry; + personalDetailsList?: OnyxEntry; +}): string | undefined { const ownerAccountID = report?.ownerAccountID; - const personalDetails = personalDetailsProp?.[ownerAccountID ?? -1]; + const personalDetails = personalDetailsList?.[ownerAccountID ?? -1]; const login = personalDetails ? personalDetails.login : null; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const reportOwnerDisplayName = getDisplayNameForParticipant(ownerAccountID) || login || report?.reportName; @@ -2918,7 +2926,17 @@ function getAvailableReportFields(report: Report, policyReportFields: PolicyRepo /** * Get the title for an IOU or expense chat which will be showing the payer and the amount */ -function getMoneyRequestReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry, policies?: OnyxCollection): string { +function getMoneyRequestReportName({ + report, + policy, + invoiceReceiverPolicy, + policies, +}: { + report: OnyxEntry; + policy?: OnyxEntry; + invoiceReceiverPolicy?: OnyxEntry; + policies?: OnyxCollection; +}): string { const isReportSettled = isSettled(report?.reportID ?? '-1'); const reportFields = isReportSettled ? report?.fieldList : getReportFieldsByPolicyID(report?.policyID ?? '-1', policies); const titleReportField = getFormulaTypeReportField(reportFields ?? {}); @@ -3312,12 +3330,17 @@ function shouldShowRBRForMissingSmartscanFields(iouReportID: string): boolean { /** * Given a parent IOU report action get report name for the LHN. */ -function getTransactionReportName( - reportAction: OnyxEntry, - transactions?: OnyxCollection, - reports?: OnyxCollection, - draftReports?: OnyxCollection, -): string { +function getTransactionReportName({ + reportAction, + transactions, + reports, + draftReports, +}: { + reportAction: OnyxEntry; + transactions?: OnyxCollection; + reports?: OnyxCollection; + draftReports?: OnyxCollection; +}): string { if (ReportActionsUtils.isReversedTransaction(reportAction)) { return Localize.translateLocal('parentReportAction.reversedTransaction'); } @@ -3834,7 +3857,7 @@ function getReportName({ if (isChatThread(report)) { if (!isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) { - formattedName = getTransactionReportName(parentReportAction, transactions, reports, draftReports); + formattedName = getTransactionReportName({reportAction: parentReportAction, transactions, reports, draftReports}); if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID, reportNameValuePairs))) { formattedName += ` (${Localize.translateLocal('common.archived')})`; } @@ -3898,15 +3921,15 @@ function getReportName({ } if (isPolicyExpenseChat(report)) { - formattedName = getPolicyExpenseChatName(report, policy, personalDetails); + formattedName = getPolicyExpenseChatName({report, policy, personalDetailsList: personalDetails}); } if (isMoneyRequestReport(report)) { - formattedName = getMoneyRequestReportName(report, policy, undefined, policies); + formattedName = getMoneyRequestReportName({report, policy, policies}); } if (isInvoiceReport(report)) { - formattedName = getMoneyRequestReportName(report, policy, invoiceReceiverPolicy, policies); + formattedName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy, policies}); } if (isInvoiceRoom(report)) { @@ -5927,14 +5950,14 @@ function buildTransactionThread( isOptimisticReport: true, parentReportActionID: reportAction?.reportActionID, parentReportID: moneyRequestReport?.reportID, - reportName: getTransactionReportName(reportAction), + reportName: getTransactionReportName({reportAction}), policyID: moneyRequestReport?.policyID, }; } return buildOptimisticChatReport( participantAccountIDs, - getTransactionReportName(reportAction), + getTransactionReportName({reportAction}), undefined, moneyRequestReport?.policyID ?? '-1', CONST.POLICY.OWNER_ACCOUNT_ID_FAKE, From 19a209d5e55357a1bbd435a14d084a871d7c8235 Mon Sep 17 00:00:00 2001 From: zfurtak Date: Mon, 21 Oct 2024 15:30:36 +0100 Subject: [PATCH 012/368] Fixed checks --- src/libs/ReportUtils.ts | 2 +- tests/unit/ReportUtilsTest.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9a11ca7f3bba..7c9157090d09 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3966,7 +3966,7 @@ function getReportName({ } if (ReportActionsUtils.isCardIssuedAction(parentReportAction)) { - return ReportActionsUtils.getCardIssuedMessage(parentReportAction, false, personalDetails); + return ReportActionsUtils.getCardIssuedMessage(parentReportAction, false); } return reportActionMessage; } diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 9a2e38ef82f2..6ba9764a636a 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -301,7 +301,7 @@ describe('ReportUtils', () => { }, } as ReportAction; - expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('submitted $1.69'); + expect(ReportUtils.getReportName({report: threadOfSubmittedReportAction, policy, parentReportActionParam: submittedParentReportAction})).toBe('submitted $1.69'); }); }); }); From 1bf9696efa9718311f5c11b3911eec23c23620b3 Mon Sep 17 00:00:00 2001 From: zfurtak Date: Thu, 24 Oct 2024 20:23:38 +0100 Subject: [PATCH 013/368] Adjusted to comments --- .../BrokenConnectionDescription.tsx | 6 +- .../Reactions/ReactionTooltipContent.tsx | 5 +- .../ReportActionItem/IssueCardMessage.tsx | 2 +- .../MoneyRequestPreviewContent.tsx | 13 +- .../ReportActionItem/MoneyRequestView.tsx | 2 +- .../ReportActionItem/ReportPreview.tsx | 6 +- src/components/ReportActionItem/TaskView.tsx | 2 +- src/components/ReportWelcomeText.tsx | 4 +- .../SearchFiltersParticipantsSelector.tsx | 6 +- src/hooks/useBasePopoverReactionList/index.ts | 2 +- src/libs/ModifiedExpenseMessage.ts | 12 +- src/libs/NextStepUtils.ts | 6 +- .../LocalNotification/BrowserNotifications.ts | 2 +- src/libs/OptionsListUtils.ts | 6 +- src/libs/PersonalDetailsUtils.ts | 16 +- src/libs/ReportActionsUtils.ts | 34 +++- src/libs/ReportUtils.ts | 168 ++++++++++-------- src/libs/SidebarUtils.ts | 10 +- src/libs/TransactionUtils/index.ts | 2 +- src/libs/actions/IOU.ts | 2 +- src/pages/ReportDetailsPage.tsx | 5 +- src/pages/ReportParticipantsPage.tsx | 2 +- src/pages/RoomMembersPage.tsx | 2 +- src/pages/ShareCodePage.tsx | 2 +- src/pages/TransactionDuplicate/Review.tsx | 4 +- .../report/ContextMenu/ContextMenuActions.tsx | 4 +- .../ReportActionCompose/SuggestionMention.tsx | 2 +- src/pages/home/report/ReportActionItem.tsx | 2 +- .../home/report/ReportActionItemSingle.tsx | 6 +- .../home/report/ReportTypingIndicator.tsx | 4 +- .../FloatingActionButtonAndPopover.tsx | 2 +- src/pages/workspace/WorkspaceMembersPage.tsx | 6 +- src/pages/workspace/WorkspacesListRow.tsx | 2 +- .../ModifiedExpenseMessage.perf-test.ts | 2 +- tests/unit/ModifiedExpenseMessageTest.ts | 36 ++-- 35 files changed, 234 insertions(+), 153 deletions(-) diff --git a/src/components/BrokenConnectionDescription.tsx b/src/components/BrokenConnectionDescription.tsx index c54bd0058f99..148f0014bdf2 100644 --- a/src/components/BrokenConnectionDescription.tsx +++ b/src/components/BrokenConnectionDescription.tsx @@ -53,7 +53,11 @@ function BrokenConnectionDescription({transactionID, policy, report}: BrokenConn ); } - if (ReportUtils.isReportApproved(report) || ReportUtils.isReportManuallyReimbursed(report) || (ReportUtils.isProcessingReport(report) && !PolicyUtils.isInstantSubmitEnabled(policy))) { + if ( + ReportUtils.isReportApproved({reportOrID: report}) || + ReportUtils.isReportManuallyReimbursed(report) || + (ReportUtils.isProcessingReport(report) && !PolicyUtils.isInstantSubmitEnabled(policy)) + ) { return translate('violations.memberBrokenConnectionError'); } diff --git a/src/components/Reactions/ReactionTooltipContent.tsx b/src/components/Reactions/ReactionTooltipContent.tsx index 8f469b01272c..59197fa7984d 100644 --- a/src/components/Reactions/ReactionTooltipContent.tsx +++ b/src/components/Reactions/ReactionTooltipContent.tsx @@ -26,7 +26,10 @@ type ReactionTooltipContentProps = Pick PersonalDetailsUtils.getPersonalDetailsByIDs(accountIDs, currentUserPersonalDetails.accountID, true), [currentUserPersonalDetails.accountID, accountIDs]); + const users = useMemo( + () => PersonalDetailsUtils.getPersonalDetailsByIDs({accountIDs, currentUserAccountID: currentUserPersonalDetails.accountID, shouldChangeUserDisplayName: true}), + [currentUserPersonalDetails.accountID, accountIDs], + ); const namesString = users .map((user) => user?.displayName) diff --git a/src/components/ReportActionItem/IssueCardMessage.tsx b/src/components/ReportActionItem/IssueCardMessage.tsx index c9fa9a6f2df0..5f26e26fae74 100644 --- a/src/components/ReportActionItem/IssueCardMessage.tsx +++ b/src/components/ReportActionItem/IssueCardMessage.tsx @@ -41,7 +41,7 @@ function IssueCardMessage({action, policyID}: IssueCardMessageProps) { return ( <> - ${ReportActionsUtils.getCardIssuedMessage(action, true, policyID)}`} /> + ${ReportActionsUtils.getCardIssuedMessage({reportAction: action, shouldRenderHTML: true, policyID})}`} /> {shouldShowAddMissingDetailsButton && (