Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useReportAttributes from '@hooks/useReportAttributes';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useSyncFocus from '@hooks/useSyncFocus';
Expand Down Expand Up @@ -126,6 +127,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [cardFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER);
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const reportAttributes = useReportAttributes();

let transactions: TransactionListItemType[];
if (isExpenseReportType) {
Expand All @@ -146,6 +148,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
cardFeeds,
conciergeReportID,
convertToDisplayString,
reportAttributesDerivedValue: reportAttributes,
}) as [TransactionListItemType[], number, boolean];
transactions = sectionData.map((transactionItem) => ({
...transactionItem,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Search/SearchStaticList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import TransactionItemRow from '@components/TransactionItemRow';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useReportAttributes from '@hooks/useReportAttributes';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -76,6 +77,7 @@ function SearchStaticList({
const session = useSession();
const accountID = session?.accountID ?? CONST.DEFAULT_NUMBER_ID;
const email = session?.email;
const reportAttributes = useReportAttributes();
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [hasCompletedGuidedSetupFlow] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasCompletedGuidedSetupFlowSelector});

Expand Down Expand Up @@ -103,6 +105,7 @@ function SearchStaticList({
allReportMetadata: undefined,
conciergeReportID: undefined,
convertToDisplayString,
reportAttributesDerivedValue: reportAttributes,
});

return getSortedSections(type, status, filteredData, localeCompare, translate, sortBy, sortOrder, validGroupBy)
Expand Down
2 changes: 2 additions & 0 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ function Search({
allReportMetadata,
conciergeReportID,
convertToDisplayString,
reportAttributesDerivedValue,
});
return {
...item,
Expand All @@ -634,6 +635,7 @@ function Search({
allReportMetadata,
conciergeReportID,
convertToDisplayString,
reportAttributesDerivedValue,
]);

const hasLoadedAllTransactions = useMemo(() => {
Expand Down
17 changes: 9 additions & 8 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ type GetReportNameParams = {
personalDetails?: Partial<PersonalDetailsList>;
invoiceReceiverPolicy?: OnyxEntry<Policy>;
/** Report attributes used to return a precomputed report name */
reportAttributes?: ReportAttributesDerivedValue['reports'];
reportAttributes: ReportAttributesDerivedValue['reports'];
transactions?: Transaction[];
reports?: Report[];
isReportArchived?: boolean;
Expand Down Expand Up @@ -5738,10 +5738,9 @@ function getReportName(reportNameInformation: GetReportNameParams): string {
// Check if we can use report name in derived values - only when we have report but no other params
const canUseDerivedValue =
report && policy === undefined && parentReportActionParam === undefined && personalDetails === undefined && invoiceReceiverPolicy === undefined && isReportArchived === undefined;
const attributes = reportAttributes ?? reportAttributesDerivedValue;
const derivedNameExists = report && !!attributes?.[report.reportID]?.reportName;
const derivedNameExists = report && !!reportAttributes?.[report.reportID]?.reportName;
if (canUseDerivedValue && derivedNameExists) {
return attributes[report.reportID].reportName;
return reportAttributes[report.reportID].reportName;
}

let formattedName: string | undefined;
Expand All @@ -5765,7 +5764,7 @@ function getReportName(reportNameInformation: GetReportNameParams): string {
reportPolicy,
parentReport,
personalDetails as PersonalDetailsList,
attributes,
reportAttributes,
);

if (parentReportActionBasedName) {
Expand All @@ -5775,7 +5774,7 @@ function getReportName(reportNameInformation: GetReportNameParams): string {
if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.CREATED_REPORT_FOR_UNAPPROVED_TRANSACTIONS)) {
const {originalID} = getOriginalMessage(parentReportAction) ?? {};
const originalReport = deprecatedAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${originalID}`];
const reportName = getReportName({report: originalReport});
const reportName = getReportName({report: originalReport, reportAttributes});
return getCreatedReportForUnapprovedTransactionsMessage(originalID, reportName, !!parentReportAction.isOriginalReportDeleted, translateLocal);
}

Expand Down Expand Up @@ -5929,6 +5928,7 @@ function getSearchReportName(props: GetReportNameParams): string {
parentReportActionParam: props.parentReportActionParam,
personalDetails: props.personalDetails,
invoiceReceiverPolicy: props.invoiceReceiverPolicy,
reportAttributes: props.reportAttributes,
transactions: props.transactions,
isReportArchived: props.isReportArchived,
reports: props.reports,
Expand All @@ -5948,6 +5948,7 @@ function getSearchReportName(props: GetReportNameParams): string {
parentReportActionParam: props.parentReportActionParam,
personalDetails: props.personalDetails,
invoiceReceiverPolicy: props.invoiceReceiverPolicy,
reportAttributes: props.reportAttributes,
transactions: props.transactions,
isReportArchived: props.isReportArchived,
reports: props.reports,
Expand Down Expand Up @@ -6056,7 +6057,7 @@ function getParentNavigationSubtitle(
policy: OnyxEntry<Policy>,
conciergeReportID: string | undefined,
isParentReportArchived = false,
reportAttributes?: ReportAttributesDerivedValue['reports'],
reportAttributes: ReportAttributesDerivedValue['reports'] = {},
): ParentNavigationSummaryParams {
const parentReport = getParentReport(report);

Expand Down Expand Up @@ -6101,7 +6102,7 @@ function getParentNavigationSubtitle(
}

return {
reportName: getReportNameFromNameUtils(parentReport, reportAttributes ?? reportAttributesDerivedValue),
reportName: getReportNameFromNameUtils(parentReport, reportAttributes),
workspaceName: getPolicyName({report: parentReport, policy, returnEmptyIfNotFound: true}),
};
}
Expand Down
23 changes: 18 additions & 5 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ type GetSectionsParams = {
onyxPersonalDetailsList?: OnyxTypes.PersonalDetailsList;
policyForMovingExpenses?: OnyxTypes.Policy;
optimisticTransactionID?: string;
reportAttributesDerivedValue?: OnyxTypes.ReportAttributesDerivedValue['reports'];
reportAttributesDerivedValue: OnyxTypes.ReportAttributesDerivedValue['reports'] | undefined;
};

/**
Expand Down Expand Up @@ -2600,7 +2600,11 @@ function createAndOpenSearchTransactionThread({
*
* Do not use directly, use only via `getSections()` facade.
*/
function getReportActionsSections(data: OnyxTypes.SearchResults['data'], visibleReportActionsData?: OnyxTypes.VisibleReportActionsDerivedValue): [ReportActionListItemType[], number] {
function getReportActionsSections(
data: OnyxTypes.SearchResults['data'],
visibleReportActionsData?: OnyxTypes.VisibleReportActionsDerivedValue,
reportAttributesDerivedValue: OnyxTypes.ReportAttributesDerivedValue['reports'] = {},
): [ReportActionListItemType[], number] {
const reportActionItems: ReportActionListItemType[] = [];

const transactions = Object.keys(data)
Expand Down Expand Up @@ -2651,7 +2655,16 @@ function getReportActionsSections(data: OnyxTypes.SearchResults['data'], visible
...reportAction,
reportID,
from,
reportName: getSearchReportName({report, policy, personalDetails: data.personalDetailsList, transactions, invoiceReceiverPolicy, reports, isReportArchived}),
reportName: getSearchReportName({
report,
policy,
personalDetails: data.personalDetailsList,
reportAttributes: reportAttributesDerivedValue,
transactions,
invoiceReceiverPolicy,
reports,
isReportArchived,
}),
formattedFrom: from?.displayName ?? from?.login ?? '',
date: reportAction.created,
keyForList: reportAction.reportActionID,
Expand Down Expand Up @@ -3468,12 +3481,12 @@ function getSections({
conciergeReportID,
onyxPersonalDetailsList,
policyForMovingExpenses,
reportAttributesDerivedValue,
reportAttributesDerivedValue = {},
convertToDisplayString,
optimisticTransactionID,
}: GetSectionsParams): GetSectionsResult {
if (type === CONST.SEARCH.DATA_TYPES.CHAT) {
return [...getReportActionsSections(data, visibleReportActionsData), false];
return [...getReportActionsSections(data, visibleReportActionsData, reportAttributesDerivedValue), false];
}
if (type === CONST.SEARCH.DATA_TYPES.TASK) {
return [...getTaskSections(data, formatPhoneNumber, conciergeReportID, archivedReportsIDList, reportAttributesDerivedValue), false];
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata, reportLoading
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const {showConfirmModal} = useConfirmModal();
const reportAttributes = useReportAttributes();
const isPolicyAdmin = useMemo(() => isPolicyAdminUtil(policy), [policy]);
const isPolicyEmployee = useMemo(() => isPolicyEmployeeUtil(report?.policyID, policy), [report?.policyID, policy]);
const isPolicyExpenseChat = useMemo(() => isPolicyExpenseChatUtil(report), [report]);
Expand Down Expand Up @@ -240,7 +241,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata, reportLoading
const isReportArchived = useReportIsArchived(report?.reportID);
const isArchivedRoom = useMemo(() => isArchivedNonExpenseReport(report, isReportArchived), [report, isReportArchived]);
const shouldDisableRename = useMemo(() => shouldDisableRenameUtil(report, isReportArchived), [report, isReportArchived]);
const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, isParentReportArchived);
const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, isParentReportArchived, reportAttributes);
const base62ReportID = getBase62ReportID(Number(report.reportID));
const ancestors = useAncestors(report);

Expand Down Expand Up @@ -338,7 +339,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata, reportLoading
} else if (caseID === CASES.DEFAULT) {
deleteMenuItemTitle = translate('common.delete');
}
const reportAttributes = useReportAttributes();
const isWorkspaceChat = useMemo(() => isWorkspaceChatUtil(report?.chatType ?? ''), [report?.chatType]);

useEffect(() => {
Expand Down
6 changes: 4 additions & 2 deletions src/pages/ShareCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ function ShareCodePage({report, policy, backTo}: ShareCodePageProps) {
.join(' & ');
}

return getParentNavigationSubtitle(report, policy, conciergeReportID, isParentReportArchived).workspaceName ?? getChatRoomSubtitle(report, false, isReportArchived);
return (
getParentNavigationSubtitle(report, policy, conciergeReportID, isParentReportArchived, reportAttributes).workspaceName ?? getChatRoomSubtitle(report, false, isReportArchived)
);
}

return currentUserPersonalDetails.login;
}, [report, policy, currentUserPersonalDetails.login, isReport, isReportArchived, isParentReportArchived, formatPhoneNumber, conciergeReportID]);
}, [report, policy, currentUserPersonalDetails.login, isReport, isReportArchived, isParentReportArchived, formatPhoneNumber, conciergeReportID, reportAttributes]);

const reportForTitle = useMemo(() => getReportForHeader(report), [report]);

Expand Down
3 changes: 3 additions & 0 deletions src/pages/home/SpendOverTimeSection/useSpendOverTimeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useReportAttributes from '@hooks/useReportAttributes';
import {search} from '@libs/actions/Search';
import {getSections, getSortedSections, getSuggestedSearches, isSearchDataLoaded} from '@libs/SearchUIUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -57,6 +58,7 @@ function useSpendOverTimeData() {
const {accountID, login} = useCurrentUserPersonalDetails();
const [searchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${queryJSON?.hash}`);
const isSearchLoading = !!searchResults?.search?.isLoading;
const reportAttributes = useReportAttributes();

const {isOffline} = useNetwork();
const isFocused = useIsFocused();
Expand Down Expand Up @@ -101,6 +103,7 @@ function useSpendOverTimeData() {
allReportMetadata: undefined,
conciergeReportID: undefined,
convertToDisplayString,
reportAttributesDerivedValue: reportAttributes,
})[0],
localeCompare,
translate,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/inbox/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps)
: undefined;
const statusColorForInvoiceReport = isParentInvoiceAndIsChatThread ? getReportStatusColorStyle(theme, reportHeaderData?.stateNum, reportHeaderData?.statusNum) : {};
const isParentReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.parentReportID);
const parentNavigationSubtitleData = getParentNavigationSubtitle(parentNavigationReport, policy, conciergeReportID, isParentReportHeaderDataArchived);
const parentNavigationSubtitleData = getParentNavigationSubtitle(parentNavigationReport, policy, conciergeReportID, isParentReportHeaderDataArchived, reportAttributes);
const humanAgentAccountID = getHumanAgentAccountIDFromReportAction(parentReportAction);
const humanAgentName = getHumanAgentFirstName(parentReportAction, personalDetails);
const reportDescription = StringUtils.lineBreaksToSpaces(Parser.htmlToText(getReportDescription(report)));
Expand Down
Loading
Loading