Skip to content
Merged
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
113 changes: 63 additions & 50 deletions src/components/ParentNavigationSubtitle.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {useRoute} from '@react-navigation/native';
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import type {StyleProp, TextStyle} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import useHover from '@hooks/useHover';
import useLocalize from '@hooks/useLocalize';
import useRootNavigationState from '@hooks/useRootNavigationState';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName';
import Navigation from '@libs/Navigation/Navigation';
Expand All @@ -16,8 +19,8 @@ import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
import Text from './Text';
import TextLink from './TextLink';

type ParentNavigationSubtitleProps = {
parentNavigationSubtitleData: ParentNavigationSummaryParams;
Expand All @@ -29,7 +32,7 @@ type ParentNavigationSubtitleProps = {
parentReportActionID?: string;

/** PressableWithoutFeedback additional styles */
pressableStyles?: StyleProp<ViewStyle>;
pressableStyles?: StyleProp<TextStyle>;

/** Whether to open the parent report link in the current tab if possible */
openParentReportInCurrentTab?: boolean;
Expand All @@ -44,6 +47,13 @@ function ParentNavigationSubtitle({
}: ParentNavigationSubtitleProps) {
const currentRoute = useRoute();
const styles = useThemeStyles();
const theme = useTheme();
const StyleUtils = useStyleUtils();
const {
hovered,
bind: {onMouseEnter, onMouseLeave},
} = useHover();

const {workspaceName, reportName} = parentNavigationSubtitleData;
const {translate} = useLocalize();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, {canBeMissing: false});
Expand All @@ -56,61 +66,64 @@ function ParentNavigationSubtitle({
return;
}

return (
<PressableWithoutFeedback
onPress={() => {
const parentAction = getReportAction(parentReportID, parentReportActionID);
const isVisibleAction = shouldReportActionBeVisible(parentAction, parentAction?.reportActionID ?? CONST.DEFAULT_NUMBER_ID, canUserPerformWriteAction);

if (openParentReportInCurrentTab && isReportInRHP) {
// If the report is displayed in RHP in Reports tab, we want to stay in the current tab after opening the parent report
if (currentFullScreenRoute?.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR) {
const lastRoute = currentFullScreenRoute?.state?.routes.at(-1);
if (lastRoute?.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT) {
const moneyRequestReportID = (lastRoute?.params as SearchFullscreenNavigatorParamList[typeof SCREENS.SEARCH.MONEY_REQUEST_REPORT])?.reportID;
// If the parent report is already displayed underneath RHP, simply dismiss the modal
if (moneyRequestReportID === parentReportID) {
Navigation.dismissModal();
return;
}
}

Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: parentReportID}));
return;
}
const onPress = () => {
const parentAction = getReportAction(parentReportID, parentReportActionID);
const isVisibleAction = shouldReportActionBeVisible(parentAction, parentAction?.reportActionID ?? CONST.DEFAULT_NUMBER_ID, canUserPerformWriteAction);

if (openParentReportInCurrentTab && isReportInRHP) {
// If the report is displayed in RHP in Reports tab, we want to stay in the current tab after opening the parent report
if (currentFullScreenRoute?.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR) {
const lastRoute = currentFullScreenRoute?.state?.routes.at(-1);
if (lastRoute?.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT) {
const moneyRequestReportID = (lastRoute?.params as SearchFullscreenNavigatorParamList[typeof SCREENS.SEARCH.MONEY_REQUEST_REPORT])?.reportID;
// If the parent report is already displayed underneath RHP, simply dismiss the modal
if (Navigation.getTopmostReportId() === parentReportID) {
if (moneyRequestReportID === parentReportID) {
Navigation.dismissModal();
return;
}
}

if (isVisibleAction) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(parentReportID, parentReportActionID));
} else {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(parentReportID));
}
}}
accessibilityLabel={translate('threads.parentNavigationSummary', {reportName, workspaceName})}
role={CONST.ROLE.LINK}
style={pressableStyles}
Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: parentReportID}));
return;
}

// If the parent report is already displayed underneath RHP, simply dismiss the modal
if (Navigation.getTopmostReportId() === parentReportID) {
Navigation.dismissModal();
return;
Comment on lines +90 to +93

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have considered the case when report screen remains in the navigation stack, but it isn't displayed underneath RHP.
More details: #76325 (comment)

}
}

if (isVisibleAction) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(parentReportID, parentReportActionID));
} else {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(parentReportID));
}
};

return (
<Text
style={[styles.optionAlternateText, styles.textLabelSupporting]}
numberOfLines={1}
>
<Text
style={[styles.optionAlternateText, styles.textLabelSupporting]}
numberOfLines={1}
>
{!!reportName && (
<>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{`${translate('threads.from')} `}</Text>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}>{reportName}</Text>
</>
)}
{!!workspaceName && workspaceName !== reportName && (
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{` ${translate('threads.in')} ${workspaceName}`}</Text>
)}
</Text>
</PressableWithoutFeedback>
{!!reportName && (
<>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{`${translate('threads.from')} `}</Text>
<TextLink
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onPress={onPress}
accessibilityLabel={translate('threads.parentNavigationSummary', {reportName, workspaceName})}
style={[pressableStyles, styles.optionAlternateText, styles.textLabelSupporting, hovered ? StyleUtils.getColorStyle(theme.linkHover) : styles.link]}
>
Comment on lines +112 to +118

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changed caused

We should set prop dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}

{reportName}
</TextLink>
</>
)}
{!!workspaceName && workspaceName !== reportName && (
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{` ${translate('threads.in')} ${workspaceName}`}</Text>
)}
</Text>
);
}

Expand Down