From 2df2702ba15f8ae390162546f91eb25c4434b94f Mon Sep 17 00:00:00 2001 From: Rafael Date: Tue, 29 Jun 2021 15:52:59 -0300 Subject: [PATCH 1/5] adds delete option to attachment comments --- src/libs/reportUtils.js | 20 ++++++++++++++++++- .../home/report/ReportActionContextMenu.js | 4 ++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index 2f59d580d3bd..40784eca23f4 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -46,7 +46,8 @@ function sortReportsByLastVisited(reports) { } /** - * Can only edit if it's a ADDCOMMENT, the author is this user and it's not a optimistic response. + * Can only edit if it's a ADDCOMMENT that is not an attachment, + * the author is this user and it's not a optimistic response. * If it's an optimistic response comment it will not have a reportActionID, * and we should wait until it does before we show the actions * @@ -61,6 +62,22 @@ function canEditReportAction(reportAction) { && !isReportMessageAttachment(lodashGet(reportAction, ['message', 0, 'text'], '')); } +/** + * Can only delete if it's a ADDCOMMENT, the author is this user and it's not a optimistic response. + * If it's an optimistic response comment it will not have a reportActionID, + * and we should wait until it does before we show the actions + * + * @param {Object} reportAction + * @param {String} sessionEmail + * @returns {Boolean} + */ + function canDeleteReportAction(reportAction) { + return reportAction.actorEmail === sessionEmail + && reportAction.reportActionID + && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT; +} + + /** * Given a collection of reports returns the most recently accessed one * @@ -90,6 +107,7 @@ export { isReportMessageAttachment, findLastAccessedReport, canEditReportAction, + canDeleteReportAction, sortReportsByLastVisited, isDefaultRoom, }; diff --git a/src/pages/home/report/ReportActionContextMenu.js b/src/pages/home/report/ReportActionContextMenu.js index c38b8d7db847..e0ec05837cdc 100755 --- a/src/pages/home/report/ReportActionContextMenu.js +++ b/src/pages/home/report/ReportActionContextMenu.js @@ -15,7 +15,7 @@ import ReportActionContextMenuItem from './ReportActionContextMenuItem'; import ReportActionPropTypes from './ReportActionPropTypes'; import Clipboard from '../../../libs/Clipboard'; import compose from '../../../libs/compose'; -import {isReportMessageAttachment, canEditReportAction} from '../../../libs/reportUtils'; +import {isReportMessageAttachment, canEditReportAction, canDeleteReportAction} from '../../../libs/reportUtils'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; import ConfirmModal from '../../../components/ConfirmModal'; import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager'; @@ -134,7 +134,7 @@ class ReportActionContextMenu extends React.Component { { text: this.props.translate('reportActionContextMenu.deleteComment'), icon: Trashcan, - shouldShow: () => canEditReportAction(this.props.reportAction), + shouldShow: () => canDeleteReportAction(this.props.reportAction), onPress: () => this.setState({isDeleteCommentConfirmModalVisible: true}), }, ]; From 63fab7cbac348d704719120d6f2a93f4bf94edfe Mon Sep 17 00:00:00 2001 From: Rafael Date: Tue, 29 Jun 2021 16:47:55 -0300 Subject: [PATCH 2/5] lint fixes --- src/libs/reportUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index 40784eca23f4..50a984a5b01a 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -46,7 +46,7 @@ function sortReportsByLastVisited(reports) { } /** - * Can only edit if it's a ADDCOMMENT that is not an attachment, + * Can only edit if it's a ADDCOMMENT that is not an attachment, * the author is this user and it's not a optimistic response. * If it's an optimistic response comment it will not have a reportActionID, * and we should wait until it does before we show the actions @@ -71,7 +71,7 @@ function canEditReportAction(reportAction) { * @param {String} sessionEmail * @returns {Boolean} */ - function canDeleteReportAction(reportAction) { +function canDeleteReportAction(reportAction) { return reportAction.actorEmail === sessionEmail && reportAction.reportActionID && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT; From 9884ad368d09ff045f6979ede81dea28edd61619 Mon Sep 17 00:00:00 2001 From: Rafael Djuric <53711423+rdjuric@users.noreply.github.com> Date: Tue, 29 Jun 2021 19:51:22 -0300 Subject: [PATCH 3/5] Update src/libs/reportUtils.js Co-authored-by: Carlos Martins --- src/libs/reportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index 50a984a5b01a..65f131d1f4cb 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -47,7 +47,7 @@ function sortReportsByLastVisited(reports) { /** * Can only edit if it's a ADDCOMMENT that is not an attachment, - * the author is this user and it's not a optimistic response. + * the author is this user and it's not an optimistic response. * If it's an optimistic response comment it will not have a reportActionID, * and we should wait until it does before we show the actions * From 7436e3be1e0c0958fb0364f6c2e7a9199d981a7e Mon Sep 17 00:00:00 2001 From: Rafael Djuric <53711423+rdjuric@users.noreply.github.com> Date: Tue, 29 Jun 2021 19:51:28 -0300 Subject: [PATCH 4/5] Update src/libs/reportUtils.js Co-authored-by: Carlos Martins --- src/libs/reportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index 65f131d1f4cb..3fe920c9e352 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -63,7 +63,7 @@ function canEditReportAction(reportAction) { } /** - * Can only delete if it's a ADDCOMMENT, the author is this user and it's not a optimistic response. + * Can only delete if it's an ADDCOMMENT, the author is this user and it's not an optimistic response. * If it's an optimistic response comment it will not have a reportActionID, * and we should wait until it does before we show the actions * From c9631e4f5eaf8a3c0d5950a0e09ed928e3364b57 Mon Sep 17 00:00:00 2001 From: Rafael Djuric <53711423+rdjuric@users.noreply.github.com> Date: Tue, 29 Jun 2021 19:51:37 -0300 Subject: [PATCH 5/5] Update src/libs/reportUtils.js Co-authored-by: Carlos Martins --- src/libs/reportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index 3fe920c9e352..7e44cd182c8e 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -46,7 +46,7 @@ function sortReportsByLastVisited(reports) { } /** - * Can only edit if it's a ADDCOMMENT that is not an attachment, + * Can only edit if it's an ADDCOMMENT that is not an attachment, * the author is this user and it's not an optimistic response. * If it's an optimistic response comment it will not have a reportActionID, * and we should wait until it does before we show the actions