Skip to content

Commit

Permalink
Merge pull request #21092 from Expensify/chirag-nonChat-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
thienlnam authored Jul 3, 2023
2 parents e7a17f8 + 268ad57 commit 4d3c4ef
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 83 deletions.
20 changes: 20 additions & 0 deletions src/components/AvatarWithDisplayName.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ 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';

const propTypes = {
/** The report currently being looked at */
Expand Down Expand Up @@ -52,6 +55,7 @@ const defaultProps = {
function AvatarWithDisplayName(props) {
const title = props.isAnonymous ? props.report.displayName : ReportUtils.getDisplayNameForParticipant(props.report.ownerAccountID, true);
const subtitle = ReportUtils.getChatRoomSubtitle(props.report);
const parentNavigationSubtitle = 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 @@ -88,6 +92,22 @@ 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="link"
>
<Text
style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}
numberOfLines={1}
>
{parentNavigationSubtitle}
</Text>
</PressableWithoutFeedback>
)}
{!_.isEmpty(subtitle) && (
<Text
style={[styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting, styles.pre]}
Expand Down
6 changes: 1 addition & 5 deletions src/components/HeaderWithBackButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ const propTypes = {
/** Whether we should show an avatar */
shouldShowAvatarWithDisplay: PropTypes.bool,

/** Parent report, if provided it will override props.report for AvatarWithDisplay */
parentReport: iouReportPropTypes,

/** Report, if we're showing the details for one and using AvatarWithDisplay */
report: iouReportPropTypes,

Expand Down Expand Up @@ -133,7 +130,6 @@ const defaultProps = {
shouldShowBackButton: true,
shouldShowAvatarWithDisplay: false,
report: null,
parentReport: null,
policies: {},
personalDetails: {},
guidesCallTaskID: '',
Expand Down Expand Up @@ -192,7 +188,7 @@ class HeaderWithBackButton extends Component {
)}
{this.props.shouldShowAvatarWithDisplay && (
<AvatarWithDisplayName
report={this.props.parentReport || this.props.report}
report={this.props.report}
policies={this.props.policies}
personalDetails={this.props.personalDetails}
/>
Expand Down
8 changes: 6 additions & 2 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ function MoneyRequestHeader(props) {
const shouldShowSettlementButton = !isSettled && !props.isSingleTransactionView && isPayer;
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'payPalMeAddress']));
const report = props.report;
if (props.isSingleTransactionView) {
report.ownerAccountID = lodashGet(props, ['parentReport', 'ownerAccountID'], null);
report.ownerEmail = lodashGet(props, ['parentReport', 'ownerEmail'], '');
}
return (
<View style={[{backgroundColor: themeColors.highlightBG}, styles.pl0]}>
<HeaderWithBackButton
Expand All @@ -104,8 +109,7 @@ function MoneyRequestHeader(props) {
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(props.windowWidth)}
report={props.report}
parentReport={moneyRequestReport}
report={report}
policies={props.policies}
personalDetails={props.personalDetails}
shouldShowBackButton={props.isSmallScreenWidth}
Expand Down
2 changes: 1 addition & 1 deletion src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ export default {
lastReply: 'Last reply',
replies: 'Replies',
reply: 'Reply',
from: 'From',
parentNavigationSummary: ({rootReportName, workspaceName}) => `From ${rootReportName}${workspaceName ? ` in ${workspaceName}` : ''}`,
},
qrCodes: {
copyUrlToClipboard: 'Copy URL to clipboard',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ export default {
lastReply: 'Última respuesta',
replies: 'Respuestas',
reply: 'Respuesta',
from: 'De',
parentNavigationSummary: ({rootReportName, workspaceName}) => `De ${rootReportName}${workspaceName ? ` en ${workspaceName}` : ''}`,
},
qrCodes: {
copyUrlToClipboard: 'Copiar URL al portapapeles',
Expand Down
4 changes: 2 additions & 2 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, {
result.isArchivedRoom = ReportUtils.isArchivedRoom(report);
result.isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
result.isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
result.isThread = ReportUtils.isThread(report);
result.isThread = ReportUtils.isChatThread(report);
result.isTaskReport = ReportUtils.isTaskReport(report);
result.shouldShowSubscript = ReportUtils.shouldReportShowSubscript(report);
result.allReportErrors = getAllReportErrors(report, reportActions);
Expand Down Expand Up @@ -644,7 +644,7 @@ function getOptions(
return;
}

const isThread = ReportUtils.isThread(report);
const isThread = ReportUtils.isChatThread(report);
const isChatRoom = ReportUtils.isChatRoom(report);
const isTaskReport = ReportUtils.isTaskReport(report);
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
Expand Down
107 changes: 72 additions & 35 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,23 @@ function getBankAccountRoute(report) {
}

/**
* Returns true if report has a parent and is therefore a Thread.
* Returns true if report has a parent
*
* @param {Object} report
* @returns {Boolean}
*/
function isThread(report) {
return Boolean(report && report.parentReportID && report.parentReportActionID && report.type === CONST.REPORT.TYPE.CHAT);
return Boolean(report && report.parentReportID && report.parentReportActionID);
}

/**
* Returns true if report is of type chat and has a parent and is therefore a Thread.
*
* @param {Object} report
* @returns {Boolean}
*/
function isChatThread(report) {
return isThread(report) && report.type === CONST.REPORT.TYPE.CHAT;
}

/**
Expand All @@ -394,7 +404,7 @@ function isThread(report) {
* @returns {Boolean}
*/
function isConciergeChatReport(report) {
return lodashGet(report, 'participantAccountIDs', []).length === 1 && Number(report.participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE && !isThread(report);
return lodashGet(report, 'participantAccountIDs', []).length === 1 && Number(report.participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE && !isChatThread(report);
}

/**
Expand Down Expand Up @@ -480,9 +490,15 @@ function isArchivedRoom(report) {
* @param {String} report.policyID
* @param {String} report.oldPolicyName
* @param {String} report.policyName
* @param {Boolean} [returnEmptyIfNotFound]
* @returns {String}
*/
function getPolicyName(report) {
function getPolicyName(report, returnEmptyIfNotFound = false) {
const noPolicyFound = returnEmptyIfNotFound ? '' : Localize.translateLocal('workspace.common.unavailable');
if (report === undefined) {
return noPolicyFound;
}

if ((!allPolicies || _.size(allPolicies) === 0) && !report.policyName) {
return Localize.translateLocal('workspace.common.unavailable');
}
Expand All @@ -491,7 +507,7 @@ function getPolicyName(report) {
// // Public rooms send back the policy name with the reportSummary,
// // since they can also be accessed by people who aren't in the workspace

return lodashGet(policy, 'name') || report.policyName || report.oldPolicyName || Localize.translateLocal('workspace.common.unavailable');
return lodashGet(policy, 'name') || report.policyName || report.oldPolicyName || noPolicyFound;
}

/**
Expand Down Expand Up @@ -734,7 +750,7 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false,
result.source = Expensicons.DeletedRoomAvatar;
return [result];
}
if (isThread(report)) {
if (isChatThread(report)) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);

const actorEmail = lodashGet(parentReportAction, 'actorEmail', '');
Expand Down Expand Up @@ -1030,7 +1046,7 @@ function getReportPreviewMessage(report, reportAction) {
*/
function getReportName(report) {
let formattedName;
if (isThread(report)) {
if (isChatThread(report)) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
if (ReportActionsUtils.isTransactionThread(parentReportAction)) {
return getTransactionReportName(parentReportAction);
Expand Down Expand Up @@ -1072,17 +1088,33 @@ function getReportName(report) {
}

/**
* Recursively navigates through parent to get the root reports name only for DM reports.
* Recursively navigates through thread parents to get the root report and workspace name.
* The recursion stops when we find a non thread or money request report, whichever comes first.
* @param {Object} report
* @returns {String|*}
* @returns {Object}
*/
function getDMRootReportName(report) {
if (isThread(report) && !getChatType(report)) {
function getRootReportAndWorkspaceName(report) {
if (isThread(report) && !isMoneyRequestReport(report)) {
const parentReport = lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`]);
return getDMRootReportName(parentReport);
return getRootReportAndWorkspaceName(parentReport);
}

if (isIOUReport(report)) {
return {
rootReportName: lodashGet(report, 'displayName', ''),
};
}
if (isMoneyRequestReport(report)) {
return {
rootReportName: lodashGet(report, 'displayName', ''),
workspaceName: isIOUReport(report) ? CONST.POLICY.OWNER_EMAIL_FAKE : getPolicyName(report, true),
};
}

return getReportName(report);
return {
rootReportName: getReportName(report),
workspaceName: getPolicyName(report, true),
};
}

/**
Expand All @@ -1091,23 +1123,8 @@ function getDMRootReportName(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 (isChatThread(report)) {
return '';
}
if (!isDefaultRoom(report) && !isUserCreatedPolicyRoom(report) && !isPolicyExpenseChat(report)) {
return '';
Expand All @@ -1125,6 +1142,24 @@ function getChatRoomSubtitle(report) {
return getPolicyName(report);
}

/**
* Gets the parent navigation subtitle for the report
* @param {Object} report
* @returns {String}
*/
function getParentNavigationSubtitle(report) {
if (isThread(report)) {
const parentReport = lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`]);
const {rootReportName, workspaceName} = getRootReportAndWorkspaceName(parentReport);
if (_.isEmpty(rootReportName)) {
return '';
}

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

/**
* Get the report for a reportID
*
Expand All @@ -1143,7 +1178,7 @@ function getReport(reportID) {
function navigateToDetailsPage(report) {
const participantAccountIDs = lodashGet(report, 'participantAccountIDs', []);

if (isChatRoom(report) || isPolicyExpenseChat(report) || isThread(report)) {
if (isChatRoom(report) || isPolicyExpenseChat(report) || isChatThread(report)) {
Navigation.navigate(ROUTES.getReportDetailsRoute(report.reportID));
return;
}
Expand Down Expand Up @@ -1961,7 +1996,7 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep
if (
!report ||
!report.reportID ||
(_.isEmpty(report.participantAccountIDs) && !isThread(report) && !isPublicRoom(report) && !isArchivedRoom(report) && !isMoneyRequestReport(report) && !isTaskReport(report))
(_.isEmpty(report.participantAccountIDs) && !isChatThread(report) && !isPublicRoom(report) && !isArchivedRoom(report) && !isMoneyRequestReport(report) && !isTaskReport(report))
) {
return false;
}
Expand Down Expand Up @@ -2021,7 +2056,7 @@ function getChatByParticipants(newParticipantList) {
newParticipantList.sort();
return _.find(allReports, (report) => {
// If the report has been deleted, or there are no participants (like an empty #admins room) then skip it
if (!report || !report.participantAccountIDs || isThread(report)) {
if (!report || !report.participantAccountIDs || isChatThread(report)) {
return false;
}

Expand Down Expand Up @@ -2201,7 +2236,7 @@ function canRequestMoney(report) {
*/
function getMoneyRequestOptions(report, reportParticipants, betas) {
// In any thread, we do not allow any new money requests yet
if (isThread(report)) {
if (isChatThread(report)) {
return [];
}

Expand Down Expand Up @@ -2307,7 +2342,7 @@ function shouldReportShowSubscript(report) {
return false;
}

if (isPolicyExpenseChat(report) && !isThread(report) && !isTaskReport(report) && !report.isOwnPolicyExpenseChat) {
if (isPolicyExpenseChat(report) && !isChatThread(report) && !isTaskReport(report) && !report.isOwnPolicyExpenseChat) {
return true;
}

Expand Down Expand Up @@ -2372,6 +2407,7 @@ export {
isUserCreatedPolicyRoom,
isChatRoom,
getChatRoomSubtitle,
getParentNavigationSubtitle,
getPolicyName,
getPolicyType,
isArchivedRoom,
Expand Down Expand Up @@ -2440,6 +2476,7 @@ export {
getWhisperDisplayNames,
getWorkspaceAvatar,
isThread,
isChatThread,
isThreadParent,
isThreadFirstChat,
shouldReportShowSubscript,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function getOptionData(reportID) {
const participantPersonalDetailList = _.values(OptionsListUtils.getPersonalDetailsForAccountIDs(report.participantAccountIDs, personalDetails));
const personalDetail = participantPersonalDetailList[0] || {};

result.isThread = ReportUtils.isThread(report);
result.isThread = ReportUtils.isChatThread(report);
result.isChatRoom = ReportUtils.isChatRoom(report);
result.isTaskReport = ReportUtils.isTaskReport(report);
if (result.isTaskReport) {
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function createTaskAndNavigate(currentUserEmail, currentUserAccountID, parentRep
// Create the CreatedReportAction on the task
const optimisticTaskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(optimisticTaskReport.reportID);
const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(taskReportID, title, assignee, assigneeAccountID, `Created a task: ${title}`, parentReportID);
optimisticTaskReport.parentReportActionID = optimisticAddCommentReport.reportAction.reportActionID;

const currentTime = DateUtils.getDBTime();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function ReportDetailsPage(props) {
const isPolicyAdmin = useMemo(() => PolicyUtils.isPolicyAdmin(policy), [policy]);
const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(props.report), [props.report]);
const isChatRoom = useMemo(() => ReportUtils.isChatRoom(props.report), [props.report]);
const isThread = useMemo(() => ReportUtils.isThread(props.report), [props.report]);
const isThread = useMemo(() => ReportUtils.isChatThread(props.report), [props.report]);
const isUserCreatedPolicyRoom = useMemo(() => ReportUtils.isUserCreatedPolicyRoom(props.report), [props.report]);
const isArchivedRoom = useMemo(() => ReportUtils.isArchivedRoom(props.report), [props.report]);

Expand Down
4 changes: 3 additions & 1 deletion src/pages/ReportParticipantsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function ReportParticipantsPage(props) {
<FullPageNotFoundView shouldShow={_.isEmpty(props.report)}>
<HeaderWithBackButton
title={props.translate(
ReportUtils.isChatRoom(props.report) || ReportUtils.isPolicyExpenseChat(props.report) || ReportUtils.isThread(props.report) ? 'common.members' : 'common.details',
ReportUtils.isChatRoom(props.report) || ReportUtils.isPolicyExpenseChat(props.report) || ReportUtils.isChatThread(props.report)
? 'common.members'
: 'common.details',
)}
/>
<View
Expand Down
Loading

0 comments on commit 4d3c4ef

Please sign in to comment.