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

fix: Standardize the hover menu options to always include the same options #39894

Merged
merged 9 commits into from
Apr 23, 2024
134 changes: 80 additions & 54 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,37 @@ const ContextMenuActions: ContextMenuAction[] = [
},
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.markAsUnread',
icon: Expensicons.ChatBubbleUnread,
successIcon: Expensicons.Checkmark,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID, isPinnedChat, isUnreadChat) =>
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION || (type === CONST.CONTEXT_MENU_TYPES.REPORT && !isUnreadChat),
onPress: (closePopover, {reportAction, reportID}) => {
const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction) ?? '';
Report.markCommentAsUnread(originalReportID, reportAction?.created);
if (closePopover) {
hideContextMenu(true, ReportActionComposeFocusManager.focus);
}
},
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.markAsRead',
icon: Expensicons.Mail,
successIcon: Expensicons.Checkmark,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID, isPinnedChat, isUnreadChat) =>
type === CONST.CONTEXT_MENU_TYPES.REPORT && isUnreadChat,
onPress: (closePopover, {reportID}) => {
Report.readNewestAction(reportID);
if (closePopover) {
hideContextMenu(true, ReportActionComposeFocusManager.focus);
}
},
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.editAction',
Expand Down Expand Up @@ -250,37 +281,6 @@ const ContextMenuActions: ContextMenuAction[] = [
},
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.markAsUnread',
icon: Expensicons.ChatBubbleUnread,
successIcon: Expensicons.Checkmark,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID, isPinnedChat, isUnreadChat) =>
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION || (type === CONST.CONTEXT_MENU_TYPES.REPORT && !isUnreadChat),
onPress: (closePopover, {reportAction, reportID}) => {
const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction) ?? '';
Report.markCommentAsUnread(originalReportID, reportAction?.created);
if (closePopover) {
hideContextMenu(true, ReportActionComposeFocusManager.focus);
}
},
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.markAsRead',
icon: Expensicons.Mail,
successIcon: Expensicons.Checkmark,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID, isPinnedChat, isUnreadChat) =>
type === CONST.CONTEXT_MENU_TYPES.REPORT && isUnreadChat,
onPress: (closePopover, {reportID}) => {
Report.readNewestAction(reportID);
if (closePopover) {
hideContextMenu(true, ReportActionComposeFocusManager.focus);
}
},
getDescription: () => {},
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this up too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, what do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

Move mark as read up before edit action.

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 updated

isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.joinThread',
Expand Down Expand Up @@ -430,29 +430,6 @@ const ContextMenuActions: ContextMenuAction[] = [
},
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.deleteAction',
icon: Expensicons.Trashcan,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID) =>
// Until deleting parent threads is supported in FE, we will prevent the user from deleting a thread parent
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION &&
ReportUtils.canDeleteReportAction(reportAction, reportID) &&
!isArchivedRoom &&
!isChronosReport &&
!ReportActionsUtils.isMessageDeleted(reportAction),
onPress: (closePopover, {reportID, reportAction}) => {
if (closePopover) {
// Hide popover, then call showDeleteConfirmModal
hideContextMenu(false, () => showDeleteModal(reportID, reportAction));
return;
}

// No popover to hide, call showDeleteConfirmModal immediately
showDeleteModal(reportID, reportAction);
},
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'common.pin',
Expand Down Expand Up @@ -499,6 +476,55 @@ const ContextMenuActions: ContextMenuAction[] = [
},
getDescription: () => {},
},
{
isAnonymousAction: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

@nkdengineer You forgot to remove this option from above. Now it got duplicated.

textTranslateKey: 'common.download',
icon: Expensicons.Download,
successTextTranslateKey: 'common.download',
successIcon: Expensicons.Download,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID, isPinnedChat, isUnreadChat, isOffline): reportAction is ReportAction => {
const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction);
const messageHtml = reportAction?.message?.at(0)?.html;
return (
isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && !!reportAction?.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction) && !isOffline
);
},
onPress: (closePopover, {reportAction}) => {
const html = getActionHtml(reportAction);
const {originalFileName, sourceURL} = getAttachmentDetails(html);
const sourceURLWithAuth = addEncryptedAuthTokenToURL(sourceURL ?? '');
const sourceID = (sourceURL?.match(CONST.REGEX.ATTACHMENT_ID) ?? [])[1];
Download.setDownload(sourceID, true);
fileDownload(sourceURLWithAuth, originalFileName ?? '').then(() => Download.setDownload(sourceID, false));
if (closePopover) {
hideContextMenu(true, ReportActionComposeFocusManager.focus);
}
},
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.deleteAction',
icon: Expensicons.Trashcan,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID) =>
// Until deleting parent threads is supported in FE, we will prevent the user from deleting a thread parent
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION &&
ReportUtils.canDeleteReportAction(reportAction, reportID) &&
!isArchivedRoom &&
!isChronosReport &&
!ReportActionsUtils.isMessageDeleted(reportAction),
onPress: (closePopover, {reportID, reportAction}) => {
if (closePopover) {
// Hide popover, then call showDeleteConfirmModal
hideContextMenu(false, () => showDeleteModal(reportID, reportAction));
return;
}

// No popover to hide, call showDeleteConfirmModal immediately
showDeleteModal(reportID, reportAction);
},
getDescription: () => {},
},
{
isAnonymousAction: true,
textTranslateKey: 'reportActionContextMenu.menu',
Expand Down
Loading