Skip to content
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
7 changes: 4 additions & 3 deletions src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,19 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) {
const participantPersonalDetailListExcludeCurrentUser = Object.values(
getPersonalDetailsForAccountIDs(participantAccountIDsExcludeCurrentUser, personalDetails as OnyxInputOrEntry<PersonalDetailsList>),
);
const welcomeMessage = SidebarUtils.getWelcomeMessage(
const welcomeMessage = SidebarUtils.getWelcomeMessage({
report,
policy,
invoiceReceiverPolicy,
participantPersonalDetailListExcludeCurrentUser,
participantPersonalDetailList: participantPersonalDetailListExcludeCurrentUser,
translate,
localeCompare,
conciergeReportID,
isReportArchived,
reportDetailsLink,
shouldShowUsePlusButtonText,
additionalText,
);
});

return (
<>
Expand Down
74 changes: 54 additions & 20 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ import {getTaskReportActionMessage} from './TaskUtils';

type WelcomeMessage = {phrase1?: string; messageText?: string; messageHtml?: string};

type WelcomeMessageParams = {
report: OnyxEntry<Report>;
policy: OnyxEntry<Policy>;
invoiceReceiverPolicy: OnyxEntry<Policy>;
participantPersonalDetailList: PersonalDetails[];
translate: LocalizedTranslate;
localeCompare: LocaleContextProps['localeCompare'];
conciergeReportID: string | undefined;
isReportArchived?: boolean;
reportDetailsLink?: string;
shouldShowUsePlusButtonText?: boolean;
additionalText?: string;
};

function compareStringDates(a: string, b: string): 0 | 1 | -1 {
if (a < b) {
return -1;
Expand Down Expand Up @@ -1126,18 +1140,34 @@ function getOptionData({

if (!result.alternateText) {
result.alternateText = formatReportLastMessageText(
getWelcomeMessage(report, policy, invoiceReceiverPolicy, participantPersonalDetailListExcludeCurrentUser, translate, localeCompare, isReportArchived).messageText ??
translate('report.noActivityYet'),
getWelcomeMessage({
report,
policy,
invoiceReceiverPolicy,
participantPersonalDetailList: participantPersonalDetailListExcludeCurrentUser,
translate,
localeCompare,
conciergeReportID,
isReportArchived,
}).messageText ?? translate('report.noActivityYet'),
);
}
}
result.alternateText = prefix + result.alternateText;
} else {
if (!lastMessageText) {
lastMessageText = formatReportLastMessageText(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
getWelcomeMessage(report, policy, invoiceReceiverPolicy, participantPersonalDetailListExcludeCurrentUser, translate, localeCompare, isReportArchived).messageText ||
translate('report.noActivityYet'),
getWelcomeMessage({
report,
policy,
invoiceReceiverPolicy,
participantPersonalDetailList: participantPersonalDetailListExcludeCurrentUser,
translate,
localeCompare,
conciergeReportID,
isReportArchived,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Copy link
Contributor

Choose a reason for hiding this comment

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

❌ CONSISTENCY-5 (docs)

The eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing comment lacks a justification explaining why the rule is being disabled. While this comment existed before the PR (and also lacked justification), since it was moved to a new position it should be given a proper explanation.

Add a comment explaining why || is used instead of ?? here. For example:

                    isReportArchived,
                    // We use || instead of ?? because we want to fall back when messageText is an empty string, not just null/undefined
                    // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
                }).messageText || translate('report.noActivityYet'),

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't change it

}).messageText || translate('report.noActivityYet'),
);
}
if (shouldShowLastActorDisplayName(report, lastActorDetails, lastAction, currentUserAccountID) && !isReportArchived) {
Expand Down Expand Up @@ -1201,25 +1231,28 @@ function getOptionData({
return result;
}

function getWelcomeMessage(
report: OnyxEntry<Report>,
policy: OnyxEntry<Policy>,
invoiceReceiverPolicy: OnyxEntry<Policy>,
participantPersonalDetailList: PersonalDetails[],
translate: LocalizedTranslate,
localeCompare: LocaleContextProps['localeCompare'],
isReportArchived = false,
reportDetailsLink = '',
shouldShowUsePlusButtonText = false,
additionalText = '',
): WelcomeMessage {
function getWelcomeMessage(params: WelcomeMessageParams): WelcomeMessage {
const {
report,
policy,
invoiceReceiverPolicy,
participantPersonalDetailList,
translate,
localeCompare,
conciergeReportID,
isReportArchived = false,
reportDetailsLink = '',
shouldShowUsePlusButtonText = false,
additionalText = '',
} = params;

const welcomeMessage: WelcomeMessage = {};
if (isChatThread(report) || isTaskReport(report)) {
return welcomeMessage;
}

if (isChatRoom(report)) {
return getRoomWelcomeMessage(translate, report, invoiceReceiverPolicy, isReportArchived, reportDetailsLink);
return getRoomWelcomeMessage(translate, report, invoiceReceiverPolicy, conciergeReportID, isReportArchived, reportDetailsLink);
}

if (isPolicyExpenseChat(report)) {
Expand Down Expand Up @@ -1262,7 +1295,7 @@ function getWelcomeMessage(
if (shouldShowUsePlusButtonText) {
messageHtml += translate('reportActionsView.usePlusButton', {additionalText});
}
if (isConciergeChatReport(report)) {
if (isConciergeChatReport(report, conciergeReportID)) {
messageHtml = translate('reportActionsView.askConcierge');
}

Expand All @@ -1278,13 +1311,14 @@ function getRoomWelcomeMessage(
translate: LocalizedTranslate,
report: OnyxEntry<Report>,
invoiceReceiverPolicy: OnyxEntry<Policy>,
conciergeReportID: string | undefined,
isReportArchived = false,
reportDetailsLink = '',
): WelcomeMessage {
const welcomeMessage: WelcomeMessage = {};
const workspaceName = getPolicyName({report});
// eslint-disable-next-line @typescript-eslint/no-deprecated
const reportName = getReportName({report});
const reportName = getReportName({report, conciergeReportID});

if (report?.description) {
welcomeMessage.messageHtml = getReportDescription(report);
Expand Down
7 changes: 4 additions & 3 deletions src/pages/Debug/Report/DebugReportActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function DebugReportActions({reportID}: DebugReportActionsProps) {
const isReportArchived = useReportIsArchived(reportID);
const ifUserCanPerformWriteAction = canUserPerformWriteAction(report, isReportArchived);
const [personalDetails] = useMappedPersonalDetails(personalDetailMapper);
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);

const getSortedAllReportActionsSelector = useCallback(
(allReportActions: OnyxEntry<ReportActions>): ReportAction[] => {
Expand Down Expand Up @@ -70,8 +71,8 @@ function DebugReportActions({reportID}: DebugReportActionsProps) {

if (isCreatedAction(reportAction)) {
return formatReportLastMessageText(
SidebarUtils.getWelcomeMessage(report, policy, invoiceReceiverPolicy, participantPersonalDetailList, translate, localeCompare, isReportArchived).messageText ??
translate('report.noActivityYet'),
SidebarUtils.getWelcomeMessage({report, policy, invoiceReceiverPolicy, participantPersonalDetailList, translate, localeCompare, conciergeReportID, isReportArchived})
.messageText ?? translate('report.noActivityYet'),
);
}

Expand All @@ -81,7 +82,7 @@ function DebugReportActions({reportID}: DebugReportActionsProps) {

return getReportActionMessageText(reportAction);
},
[translate, report, policy, invoiceReceiverPolicy, participantPersonalDetailList, localeCompare, isReportArchived],
[translate, report, policy, invoiceReceiverPolicy, participantPersonalDetailList, localeCompare, conciergeReportID, isReportArchived],
);

const searchedReportActions = useMemo(() => {
Expand Down
Loading
Loading