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

Subheader update and parent navigation #20484

Merged
merged 17 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,7 @@ export default {
lastReply: 'Last reply',
replies: 'Replies',
reply: 'Reply',
from: 'From',
},
qrCodes: {
copyUrlToClipboard: 'Copy URL to clipboard',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,7 @@ export default {
lastReply: 'Última respuesta',
replies: 'Respuestas',
reply: 'Respuesta',
from: 'De',
},
qrCodes: {
copyUrlToClipboard: 'Copiar URL al portapapeles',
Expand Down
99 changes: 54 additions & 45 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,48 +532,6 @@ function isThreadFirstChat(reportAction, reportID) {
return !_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === reportID;
}

/**
* Get either the policyName or domainName the chat is tied to
* @param {Object} report
* @returns {String}
*/
function getChatRoomSubtitle(report) {
if (isThread(report)) {
if (!getChatType(report)) {
return '';
}

const parentReport = lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`]);

// If thread is not from a DM or group chat, the subtitle will follow the pattern 'Workspace Name • #roomName'
const workspaceName = getPolicyName(report);
let roomName = '';
if (isChatRoom(report)) {
if (parentReport) {
roomName = lodashGet(parentReport, 'displayName', '');
} else {
roomName = lodashGet(report, 'displayName', '');
}
}

return roomName ? [workspaceName, roomName].join(' • ') : workspaceName;
}
if (!isDefaultRoom(report) && !isUserCreatedPolicyRoom(report) && !isPolicyExpenseChat(report)) {
return '';
}
if (getChatType(report) === CONST.REPORT.CHAT_TYPE.DOMAIN_ALL) {
// The domainAll rooms are just #domainName, so we ignore the prefix '#' to get the domainName
return report.reportName.substring(1);
}
if ((isPolicyExpenseChat(report) && report.isOwnPolicyExpenseChat) || isExpenseReport(report)) {
return Localize.translateLocal('workspace.common.workspace');
}
if (isArchivedRoom(report)) {
return report.oldPolicyName || '';
}
return getPolicyName(report);
}

/**
* Get welcome message based on room type
* @param {Object} report
Expand Down Expand Up @@ -868,11 +826,8 @@ function getDisplayNameForParticipant(login, shouldUseShortForm = false) {
return '';
}
const personalDetails = getPersonalDetailsForLogin(login);

const longName = personalDetails.displayName;

const shortName = personalDetails.firstName || longName;

return shouldUseShortForm ? shortName : longName;
}

Expand Down Expand Up @@ -1055,6 +1010,60 @@ function getReportName(report) {
return _.map(participantsWithoutCurrentUser, (login) => getDisplayNameForParticipant(login, isMultipleParticipantReport)).join(', ');
}

/**
* Recursively navigates through parent to get the root reports name only for DM reports.
* @param {Object} report
* @returns {String|*}
*/
function getDMRootReportName(report) {
if (isThread(report) && !getChatType(report)) {
const parentReport = lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`]);
return getDMRootReportName(parentReport);
}

return getReportName(report);
}

/**
* Get either the policyName or domainName the chat is tied to
* @param {Object} report
* @returns {String}
*/
function getChatRoomSubtitle(report) {
if (isThread(report)) {
if (!getChatType(report)) {
return `${Localize.translateLocal('threads.from')} ${getDMRootReportName(report)}`;
}

let roomName = '';
if (isChatRoom(report)) {
const parentReport = lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`]);
if (parentReport) {
roomName = lodashGet(parentReport, 'displayName', '');
} else {
roomName = lodashGet(report, 'displayName', '');
}
}

const workspaceName = getPolicyName(report);
return `${Localize.translateLocal('threads.from')} ${roomName ? [roomName, workspaceName].join(' in ') : workspaceName}`;
}
if (!isDefaultRoom(report) && !isUserCreatedPolicyRoom(report) && !isPolicyExpenseChat(report)) {
return '';
}
if (getChatType(report) === CONST.REPORT.CHAT_TYPE.DOMAIN_ALL) {
// The domainAll rooms are just #domainName, so we ignore the prefix '#' to get the domainName
return report.reportName.substring(1);
}
if ((isPolicyExpenseChat(report) && report.isOwnPolicyExpenseChat) || isExpenseReport(report)) {
return Localize.translateLocal('workspace.common.workspace');
}
if (isArchivedRoom(report)) {
return report.oldPolicyName || '';
}
return getPolicyName(report);
}

/**
* Get the report for a reportID
*
Expand Down
35 changes: 28 additions & 7 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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';

const propTypes = {
/** Toggles the navigationMenu open and closed */
Expand Down Expand Up @@ -79,7 +81,7 @@ const HeaderView = (props) => {
const isTaskReport = ReportUtils.isTaskReport(props.report);
const reportHeaderData = (isTaskReport || !isThread) && props.report.parentReportID ? props.parentReport : props.report;
const title = ReportUtils.getReportName(reportHeaderData);
const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData, props.parentReport);
const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData);
const isConcierge = participants.length === 1 && _.contains(participants, CONST.EMAIL.CONCIERGE);
const isAutomatedExpensifyAccount = participants.length === 1 && ReportUtils.hasAutomatedExpensifyEmails(participants);
const guideCalendarLink = lodashGet(props.account, 'guideCalendarLink');
Expand Down Expand Up @@ -176,12 +178,31 @@ const HeaderView = (props) => {
shouldUseFullTitle={isChatRoom || isPolicyExpenseChat || isThread || isTaskReport}
/>
{(isChatRoom || isPolicyExpenseChat || isThread) && !_.isEmpty(subtitle) && (
<Text
style={[styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting, styles.pre]}
numberOfLines={1}
>
{subtitle}
</Text>
<>
{isThread ? (
<PressableWithoutFeedback
chiragsalian marked this conversation as resolved.
Show resolved Hide resolved
onPress={() => {
Navigation.navigate(ROUTES.getReportRoute(props.report.parentReportID));
}}
accessibilityLabel={subtitle}
accessibilityRole="link"
>
<Text
Copy link
Collaborator

@mananjadhav mananjadhav Jul 10, 2023

Choose a reason for hiding this comment

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

When we added this component, the content is stretched and hence clicking the blank space was opening user chat instead of the chat details. This caused a regression here.

I think the issue occurred because we copy pasted the Text content, which didn't have the click behavior earlier.

style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}
numberOfLines={1}
>
{subtitle}
</Text>
</PressableWithoutFeedback>
) : (
<Text
style={[styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting]}
numberOfLines={1}
>
{subtitle}
</Text>
)}
</>
)}
</View>
{brickRoadIndicator === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR && (
Expand Down