Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update header subtitle styles for thread (child) reports #23621

Merged
merged 9 commits into from
Aug 2, 2023
26 changes: 7 additions & 19 deletions src/components/AvatarWithDisplayName.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import compose from '../libs/compose';
import * as OptionsListUtils from '../libs/OptionsListUtils';
import Text from './Text';
import * as StyleUtils from '../styles/StyleUtils';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
import ParentNavigationSubtitle from './ParentNavigationSubtitle';

const propTypes = {
/** The report currently being looked at */
Expand Down Expand Up @@ -55,7 +53,7 @@ const defaultProps = {
function AvatarWithDisplayName(props) {
const title = props.isAnonymous ? ReportUtils.getReportName(props.report) : ReportUtils.getDisplayNameForParticipant(props.report.ownerAccountID, true);
const subtitle = ReportUtils.getChatRoomSubtitle(props.report);
const parentNavigationSubtitle = ReportUtils.getParentNavigationSubtitle(props.report);
const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(props.report);
const isExpenseReport = ReportUtils.isExpenseReport(props.report);
const icons = ReportUtils.getIcons(props.report, props.personalDetails, props.policies);
const ownerPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs([props.report.ownerAccountID], props.personalDetails);
Expand Down Expand Up @@ -90,21 +88,11 @@ function AvatarWithDisplayName(props) {
textStyles={[props.isAnonymous ? styles.headerAnonymousFooter : styles.headerText, styles.pre]}
shouldUseFullTitle={isExpenseReport || props.isAnonymous}
/>
{!_.isEmpty(parentNavigationSubtitle) && (
<PressableWithoutFeedback
onPress={() => {
Navigation.navigate(ROUTES.getReportRoute(props.report.parentReportID));
}}
accessibilityLabel={subtitle}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.LINK}
>
<Text
style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}
numberOfLines={1}
>
{parentNavigationSubtitle}
</Text>
</PressableWithoutFeedback>
{!_.isEmpty(parentNavigationSubtitleData) && (
<ParentNavigationSubtitle
parentNavigationSubtitleData={parentNavigationSubtitleData}
report={props.report}
grgia marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
{!_.isEmpty(subtitle) && (
<Text
Expand Down
63 changes: 63 additions & 0 deletions src/components/ParentNavigationSubtitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import CONST from '../CONST';
import Text from './Text';
import reportPropTypes from '../pages/reportPropTypes';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import useLocalize from '../hooks/useLocalize';

const propTypes = {
parentNavigationSubtitleData: PropTypes.shape({
// Title of root report room
rootReportName: PropTypes.string,

// Name of workspace, if any
workspaceName: PropTypes.string,
}).isRequired,

/** report */
report: reportPropTypes,
grgia marked this conversation as resolved.
Show resolved Hide resolved

/** PressableWithoutFeedack additional styles */
// eslint-disable-next-line react/forbid-prop-types
pressableStyles: PropTypes.arrayOf(PropTypes.object),
};

const defaultProps = {
report: {},
pressableStyles: [],
};

function ParentNavigationSubtitle(props) {
const {workspaceName, rootReportName} = props.parentNavigationSubtitleData;

const {translate} = useLocalize();

return (
<PressableWithoutFeedback
onPress={() => {
Navigation.navigate(ROUTES.getReportRoute(props.report.parentReportID));
}}
accessibilityLabel={translate('threads.parentNavigationSummary', {rootReportName, workspaceName})}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.LINK}
style={[...props.pressableStyles]}
>
<Text
style={[styles.optionAlternateText]}
numberOfLines={1}
>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{`${translate('threads.from')} `}</Text>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}>{rootReportName}</Text>
{Boolean(workspaceName) && <Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{` ${translate('threads.in')} ${workspaceName}`}</Text>}
</Text>
</PressableWithoutFeedback>
);
}

ParentNavigationSubtitle.defaultProps = defaultProps;
ParentNavigationSubtitle.propTypes = propTypes;
ParentNavigationSubtitle.displayName = 'ParentNavigationSubtitle';
export default ParentNavigationSubtitle;
2 changes: 2 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,8 @@ export default {
threads: {
replies: 'Replies',
reply: 'Reply',
from: 'From',
in: 'In',
parentNavigationSummary: ({rootReportName, workspaceName}) => `From ${rootReportName}${workspaceName ? ` in ${workspaceName}` : ''}`,
},
qrCodes: {
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,8 @@ export default {
threads: {
replies: 'Respuestas',
reply: 'Respuesta',
from: 'De',
in: 'en',
parentNavigationSummary: ({rootReportName, workspaceName}) => `De ${rootReportName}${workspaceName ? ` en ${workspaceName}` : ''}`,
},
qrCodes: {
Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,12 +1354,12 @@ function getParentNavigationSubtitle(report) {
const parentReport = lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`]);
const {rootReportName, workspaceName} = getRootReportAndWorkspaceName(parentReport);
if (_.isEmpty(rootReportName)) {
return '';
return {};
}

return Localize.translateLocal('threads.parentNavigationSummary', {rootReportName, workspaceName});
return {rootReportName, workspaceName};
}
return '';
return {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the JSDoc that this returns an object and not a string

}

/**
Expand Down
27 changes: 8 additions & 19 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ import * as Task from '../../libs/actions/Task';
import reportActionPropTypes from './report/reportActionPropTypes';
import PressableWithoutFeedback from '../../components/Pressable/PressableWithoutFeedback';
import PinButton from '../../components/PinButton';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import TaskHeaderActionButton from '../../components/TaskHeaderActionButton';
import ParentNavigationSubtitle from '../../components/ParentNavigationSubtitle';

const propTypes = {
/** Toggles the navigationMenu open and closed */
Expand Down Expand Up @@ -90,7 +89,7 @@ function HeaderView(props) {
const reportHeaderData = !isTaskReport && !isChatThread && props.report.parentReportID ? props.parentReport : props.report;
const title = ReportUtils.getReportName(reportHeaderData);
const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData);
const parentNavigationSubtitle = ReportUtils.getParentNavigationSubtitle(reportHeaderData);
const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(reportHeaderData);
const isConcierge = ReportUtils.hasSingleParticipant(props.report) && _.contains(participants, CONST.ACCOUNT_ID.CONCIERGE);
const isAutomatedExpensifyAccount = ReportUtils.hasSingleParticipant(props.report) && ReportUtils.hasAutomatedExpensifyAccountIDs(participants);
const guideCalendarLink = lodashGet(props.account, 'guideCalendarLink');
Expand Down Expand Up @@ -189,22 +188,12 @@ function HeaderView(props) {
textStyles={[styles.headerText, styles.pre]}
shouldUseFullTitle={isChatRoom || isPolicyExpenseChat || isChatThread || isTaskReport}
/>
{!_.isEmpty(parentNavigationSubtitle) && (
<PressableWithoutFeedback
onPress={() => {
Navigation.navigate(ROUTES.getReportRoute(props.report.parentReportID));
}}
style={[styles.alignSelfStart, styles.mw100]}
accessibilityLabel={parentNavigationSubtitle}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.LINK}
>
<Text
style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}
numberOfLines={1}
>
{parentNavigationSubtitle}
</Text>
</PressableWithoutFeedback>
{!_.isEmpty(parentNavigationSubtitleData) && (
<ParentNavigationSubtitle
grgia marked this conversation as resolved.
Show resolved Hide resolved
parentNavigationSubtitleData={parentNavigationSubtitleData}
report={props.report}
pressableStyles={[styles.alignSelfStart, styles.mw100]}
/>
)}
{!_.isEmpty(subtitle) && (
<Text
Expand Down
Loading