From 1ac87b0c49fad3a42a480a715b0d6ba09925daad Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 16 Jan 2024 14:54:45 +0530 Subject: [PATCH 1/8] fixes the issue of copy to clipboard of whisper message --- src/libs/ReportActionsUtils.ts | 24 ++++++++++++++++++- .../report/ContextMenu/ContextMenuActions.js | 3 +++ src/types/onyx/OriginalMessage.ts | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index ee4fa201ee2f..96e6ae8402f5 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -6,7 +6,7 @@ import OnyxUtils from 'react-native-onyx/lib/utils'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {ActionName, ChangeLog} from '@src/types/onyx/OriginalMessage'; +import type {ActionName, ChangeLog, OriginalMessageActionableMentionWhisper} from '@src/types/onyx/OriginalMessage'; import type Report from '@src/types/onyx/Report'; import type {Message, ReportActions} from '@src/types/onyx/ReportAction'; import type ReportAction from '@src/types/onyx/ReportAction'; @@ -810,6 +810,26 @@ function hasRequestFromCurrentAccount(reportID: string, currentAccountID: number return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID); } +function isActionableMentionWhisper(reportAction: OnyxEntry): boolean { + return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER; +} + +function getActionableMentionWhisperMessage(reportAction: OnyxEntry): string { + const originalMessage = reportAction?.originalMessage as OriginalMessageActionableMentionWhisper['originalMessage']; + const targetAccountIDs: number[] = originalMessage?.inviteeAccountIDs ?? []; + const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); + const mentionElements = targetAccountIDs.map((accountID): string => { + const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); + const handleText = PersonalDetailsUtils.getEffectiveDisplayName(personalDetail) ?? Localize.translateLocal('common.hidden'); + return `@${handleText}` + }); + const preMentionsText = 'Heads up, ' + const mentions = mentionElements.join(', ').replace(/, ([^,]*)$/, ' and $1'); + const postMentionsText = ` ${mentionElements.length > 1 ? 'aren\'t members' : 'isn\'t a member'} of this room.` + + return `${preMentionsText}${mentions}${postMentionsText}`; +} + export { extractLinksFromMessageHtml, getAllReportActions, @@ -860,6 +880,8 @@ export { getMemberChangeMessageFragment, getMemberChangeMessagePlainText, isReimbursementDeQueuedAction, + isActionableMentionWhisper, + getActionableMentionWhisperMessage, }; export type {LastVisibleMessage}; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 7db39c1ed856..b8183f3d9d2f 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -302,6 +302,9 @@ export default [ } else if (ReportActionsUtils.isSubmittedExpenseAction(reportAction)) { const submittedMessage = _.reduce(reportAction.message, (acc, curr) => `${acc}${curr.text}`, ''); Clipboard.setString(submittedMessage); + } else if (ReportActionsUtils.isActionableMentionWhisper(reportAction)) { + const mentionWhisperMessage = ReportActionsUtils.getActionableMentionWhisperMessage(reportAction); + setClipboardMessage(mentionWhisperMessage); } else if (content) { setClipboardMessage(content); } diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 09be2d9e04dd..fadb872e291f 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -287,4 +287,5 @@ export type { OriginalMessageIOU, OriginalMessageCreated, OriginalMessageAddComment, + OriginalMessageActionableMentionWhisper }; From 80251b459269bc568b2b66ec9c66d4af53dded60 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Thu, 18 Jan 2024 21:35:08 +0530 Subject: [PATCH 2/8] prettier diffs --- src/libs/ReportActionsUtils.ts | 8 ++++---- src/types/onyx/OriginalMessage.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index fb4da897cc20..162f2e5d592c 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -6,7 +6,7 @@ import OnyxUtils from 'react-native-onyx/lib/utils'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {ActionName, ChangeLog, OriginalMessageReimbursementDequeued, OriginalMessageActionableMentionWhisper} from '@src/types/onyx/OriginalMessage'; +import type {ActionName, ChangeLog, OriginalMessageActionableMentionWhisper, OriginalMessageReimbursementDequeued} from '@src/types/onyx/OriginalMessage'; import type Report from '@src/types/onyx/Report'; import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction'; import type ReportAction from '@src/types/onyx/ReportAction'; @@ -821,11 +821,11 @@ function getActionableMentionWhisperMessage(reportAction: OnyxEntry { const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); const handleText = PersonalDetailsUtils.getEffectiveDisplayName(personalDetail) ?? Localize.translateLocal('common.hidden'); - return `@${handleText}` + return `@${handleText}`; }); - const preMentionsText = 'Heads up, ' + const preMentionsText = 'Heads up, '; const mentions = mentionElements.join(', ').replace(/, ([^,]*)$/, ' and $1'); - const postMentionsText = ` ${mentionElements.length > 1 ? 'aren\'t members' : 'isn\'t a member'} of this room.` + const postMentionsText = ` ${mentionElements.length > 1 ? "aren't members" : "isn't a member"} of this room.`; return `${preMentionsText}${mentions}${postMentionsText}`; } diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 733ff5cffc1e..bbf850914c10 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -283,5 +283,5 @@ export type { OriginalMessageCreated, OriginalMessageAddComment, OriginalMessageActionableMentionWhisper, - OriginalMessageReimbursementDequeued + OriginalMessageReimbursementDequeued, }; From bef06123b28659e0020d0bc793662bbee0cbaf33 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Fri, 19 Jan 2024 20:56:21 +0530 Subject: [PATCH 3/8] fixes the issue --- src/pages/home/report/ReportActionItem.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 34129a87d9b5..6611cb3a7622 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -307,7 +307,7 @@ function ReportActionItem(props) { ); const actionableItemButtons = useMemo(() => { - if (!(props.action.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER && !lodashGet(props.action, 'originalMessage.resolution', null))) { + if (!(ReportActionsUtils.isActionableMentionWhisper(props.action) && !lodashGet(props.action, 'originalMessage.resolution', null))) { return []; } return [ @@ -687,6 +687,11 @@ function ReportActionItem(props) { return null; } + // if isActionableMentionWhisper, and resolved, then we don't want to render anything + if (ReportActionsUtils.isActionableMentionWhisper(props.action) && lodashGet(props.action, 'originalMessage.resolution', null)) { + return null; + } + const hasErrors = !_.isEmpty(props.action.errors); const whisperedToAccountIDs = props.action.whisperedToAccountIDs || []; const isWhisper = whisperedToAccountIDs.length > 0; From 4a66337088c177198c33afd7e5412195d4655796 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Fri, 26 Jan 2024 01:14:41 +0530 Subject: [PATCH 4/8] fixes gap between buttons --- src/components/ReportActionItem/ActionableItemButtons.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ActionableItemButtons.tsx b/src/components/ReportActionItem/ActionableItemButtons.tsx index d1f169d2f409..6ead20d3e643 100644 --- a/src/components/ReportActionItem/ActionableItemButtons.tsx +++ b/src/components/ReportActionItem/ActionableItemButtons.tsx @@ -21,7 +21,7 @@ function ActionableItemButtons(props: ActionableItemButtonsProps) { const {translate} = useLocalize(); return ( - + {props.items?.map((item) => (