From 190b78dbc537c8c5dd889e0ce2cdcfc70a332bfb Mon Sep 17 00:00:00 2001 From: Huu Le <20178761+huult@users.noreply.github.com> Date: Wed, 30 Oct 2024 23:57:21 +0700 Subject: [PATCH 1/2] fix remove double spacing in LHN report welcome text --- src/libs/SidebarUtils.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 14fb727e4d7b..4de66e533439 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -79,6 +79,10 @@ type MiniReport = { lastVisibleActionCreated?: string; }; +function ensureSingleSpacing(welcomeMessage: string) { + return welcomeMessage.replace(/\s+/g, ' ').trim(); +} + /** * @returns An array of reportIDs sorted in the proper order */ @@ -549,9 +553,11 @@ function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry) welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne'); welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree'); - welcomeMessage.messageText = `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName( - report, - )} ${welcomeMessage.phrase3}`; + welcomeMessage.messageText = ensureSingleSpacing( + `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName(report)} ${ + welcomeMessage.phrase3 + }`, + ); } return welcomeMessage; } @@ -593,7 +599,7 @@ function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry) }) .join(' '); - welcomeMessage.messageText = displayNamesWithTooltips.length ? `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}` : ''; + welcomeMessage.messageText = displayNamesWithTooltips.length ? ensureSingleSpacing(`${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`) : ''; return welcomeMessage; } @@ -641,7 +647,7 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartOne'); welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartTwo'); } - welcomeMessage.messageText = `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; + welcomeMessage.messageText = ensureSingleSpacing(`${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`); return welcomeMessage; } From 11f0fc18716a933b7c805065c8617c23492ad45d Mon Sep 17 00:00:00 2001 From: Huu Le <20178761+huult@users.noreply.github.com> Date: Thu, 31 Oct 2024 06:54:48 +0700 Subject: [PATCH 2/2] define CONST.REGEX.WHITESPACE for whitespace matching --- src/CONST.ts | 1 + src/libs/SidebarUtils.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index ac42732f2325..23dea990a7a5 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2842,6 +2842,7 @@ const CONST = { SHORT_MENTION: new RegExp(`@[\\w\\-\\+\\'#@]+(?:\\.[\\w\\-\\'\\+]+)*(?![^\`]*\`)`, 'gim'), REPORT_ID_FROM_PATH: /\/r\/(\d+)/, DISTANCE_MERCHANT: /^[0-9.]+ \w+ @ (-|-\()?[^0-9.\s]{1,3} ?[0-9.]+\)? \/ \w+$/, + WHITESPACE: /\s+/g, get EXPENSIFY_POLICY_DOMAIN_NAME() { return new RegExp(`${EXPENSIFY_POLICY_DOMAIN}([a-zA-Z0-9]+)\\${EXPENSIFY_POLICY_DOMAIN_EXTENSION}`); diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 4de66e533439..e7399a6d3982 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -79,8 +79,8 @@ type MiniReport = { lastVisibleActionCreated?: string; }; -function ensureSingleSpacing(welcomeMessage: string) { - return welcomeMessage.replace(/\s+/g, ' ').trim(); +function ensureSingleSpacing(text: string) { + return text.replace(CONST.REGEX.WHITESPACE, ' ').trim(); } /**