From ab031410ea710ea539ce0bc3804cca7457999629 Mon Sep 17 00:00:00 2001 From: Nikhil Vats Date: Wed, 26 Jul 2023 17:23:55 +0530 Subject: [PATCH 1/3] Fix: hide draft icon when composer hides --- src/components/LHNOptionsList/OptionRowLHN.js | 6 +++++- src/components/LHNOptionsList/OptionRowLHNData.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN.js b/src/components/LHNOptionsList/OptionRowLHN.js index 3030e2227fad..8063f079a387 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.js +++ b/src/components/LHNOptionsList/OptionRowLHN.js @@ -45,6 +45,9 @@ const propTypes = { /** The item that should be rendered */ // eslint-disable-next-line react/forbid-prop-types optionItem: PropTypes.object, + + /** Whether user is allowed to comment so that we can hide the draft icon if user is not allowed to comment */ + isAllowedToComment: PropTypes.bool, }; const defaultProps = { @@ -54,6 +57,7 @@ const defaultProps = { style: null, optionItem: null, isFocused: false, + isAllowedToComment: false, }; function OptionRowLHN(props) { @@ -231,7 +235,7 @@ function OptionRowLHN(props) { fill={themeColors.success} /> )} - {optionItem.hasDraftComment && ( + {optionItem.hasDraftComment && props.isAllowedToComment && ( { + const {addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(fullReport); + // if composer is hidden then user is not allowed to comment therefore draft icon should be hidden + return !ReportUtils.shouldHideComposer(fullReport, addWorkspaceRoomOrChatErrors); + }, [fullReport]); + useEffect(() => { if (!optionItem || optionItem.hasDraftComment || !comment || comment.length <= 0 || isFocused) { return; @@ -94,6 +101,7 @@ function OptionRowLHNData({shouldDisableFocusOptions, currentReportID, fullRepor {...propsToForward} isFocused={isFocused} optionItem={optionItem} + isAllowedToComment={isAllowedToComment} /> ); } From ab054b253cd5da1244c654b930dc39689da441ae Mon Sep 17 00:00:00 2001 From: Nikhil Vats Date: Fri, 28 Jul 2023 18:18:25 +0530 Subject: [PATCH 2/3] Move isAllowedToComment to SidebarUtils --- src/components/LHNOptionsList/OptionRowLHN.js | 6 +----- src/components/LHNOptionsList/OptionRowLHNData.js | 8 -------- src/libs/SidebarUtils.js | 6 ++++++ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN.js b/src/components/LHNOptionsList/OptionRowLHN.js index 8063f079a387..e94a5ba66439 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.js +++ b/src/components/LHNOptionsList/OptionRowLHN.js @@ -45,9 +45,6 @@ const propTypes = { /** The item that should be rendered */ // eslint-disable-next-line react/forbid-prop-types optionItem: PropTypes.object, - - /** Whether user is allowed to comment so that we can hide the draft icon if user is not allowed to comment */ - isAllowedToComment: PropTypes.bool, }; const defaultProps = { @@ -57,7 +54,6 @@ const defaultProps = { style: null, optionItem: null, isFocused: false, - isAllowedToComment: false, }; function OptionRowLHN(props) { @@ -235,7 +231,7 @@ function OptionRowLHN(props) { fill={themeColors.success} /> )} - {optionItem.hasDraftComment && props.isAllowedToComment && ( + {optionItem.hasDraftComment && optionItem.isAllowedToComment && ( { - const {addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(fullReport); - // if composer is hidden then user is not allowed to comment therefore draft icon should be hidden - return !ReportUtils.shouldHideComposer(fullReport, addWorkspaceRoomOrChatErrors); - }, [fullReport]); - useEffect(() => { if (!optionItem || optionItem.hasDraftComment || !comment || comment.length <= 0 || isFocused) { return; @@ -101,7 +94,6 @@ function OptionRowLHNData({shouldDisableFocusOptions, currentReportID, fullRepor {...propsToForward} isFocused={isFocused} optionItem={optionItem} - isAllowedToComment={isAllowedToComment} /> ); } diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index dfb1637419cb..5e960719fdb5 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -227,6 +227,7 @@ function getOptionData(report, personalDetails, preferredLocale, policy) { isExpenseRequest: false, isWaitingOnBankAccount: false, isLastMessageDeletedParentAction: false, + isAllowedToComment: false, }; const participantPersonalDetailList = _.values(OptionsListUtils.getPersonalDetailsForAccountIDs(report.participantAccountIDs, personalDetails)); @@ -261,6 +262,11 @@ function getOptionData(report, personalDetails, preferredLocale, policy) { result.parentReportID = report.parentReportID || null; result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.notificationPreference = report.notificationPreference || null; + + const {addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report); + // if composer is hidden then user is not allowed to comment, this is used to hide draft icon + result.isAllowedToComment = !ReportUtils.shouldHideComposer(report, addWorkspaceRoomOrChatErrors); + const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; const subtitle = ReportUtils.getChatRoomSubtitle(report); From 88216fd27f3af9fd471446553a6d9d56f7a7e393 Mon Sep 17 00:00:00 2001 From: Nikhil Vats Date: Fri, 28 Jul 2023 18:39:00 +0530 Subject: [PATCH 3/3] Change default value of isAllowedToComment --- src/libs/SidebarUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 5e960719fdb5..dd55b025b55e 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -227,7 +227,7 @@ function getOptionData(report, personalDetails, preferredLocale, policy) { isExpenseRequest: false, isWaitingOnBankAccount: false, isLastMessageDeletedParentAction: false, - isAllowedToComment: false, + isAllowedToComment: true, }; const participantPersonalDetailList = _.values(OptionsListUtils.getPersonalDetailsForAccountIDs(report.participantAccountIDs, personalDetails)); @@ -264,7 +264,7 @@ function getOptionData(report, personalDetails, preferredLocale, policy) { result.notificationPreference = report.notificationPreference || null; const {addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report); - // if composer is hidden then user is not allowed to comment, this is used to hide draft icon + // If the composer is hidden then the user is not allowed to comment, same can be used to hide the draft icon. result.isAllowedToComment = !ReportUtils.shouldHideComposer(report, addWorkspaceRoomOrChatErrors); const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat;