From 44fc4674819138483c2cb8eda15b8f9a93e8eb51 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 22 Jul 2023 17:33:46 +0700 Subject: [PATCH 1/7] update draft --- src/libs/ReportActionsUtils.js | 8 +++++ .../report/ReportActionItemMessageEdit.js | 32 +++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index dbfd57a85c43..7d08a16fed6c 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -460,6 +460,13 @@ function getReportAction(reportID, reportActionID) { return lodashGet(allReportActions, [reportID, reportActionID], {}); } +function getFirstReportAction(reportID) { + return _.find( + allReportActions[reportID], + (reportAction) => reportAction.actionName === 'CREATED', + ); +} + /** * @returns {string} */ @@ -568,4 +575,5 @@ export { isWhisperAction, isPendingRemove, getReportAction, + getFirstReportAction }; diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index d45f0442f3f7..84c770b0dc03 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -7,10 +7,12 @@ import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import Str from 'expensify-common/lib/str'; import reportActionPropTypes from './reportActionPropTypes'; import styles from '../../../styles/styles'; +import compose from '../../../libs/compose'; import themeColors from '../../../styles/themes/default'; import * as StyleUtils from '../../../styles/StyleUtils'; import Composer from '../../../components/Composer'; import * as Report from '../../../libs/actions/Report'; +import { withReportActionsDrafts} from '../../../components/OnyxProvider'; import openReportActionComposeViewWhenClosingMessageEdit from '../../../libs/openReportActionComposeViewWhenClosingMessageEdit'; import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager'; import EmojiPickerButton from '../../../components/EmojiPicker/EmojiPickerButton'; @@ -35,6 +37,7 @@ import useKeyboardState from '../../../hooks/useKeyboardState'; import useWindowDimensions from '../../../hooks/useWindowDimensions'; import useReportScrollManager from '../../../hooks/useReportScrollManager'; import * as EmojiPickerAction from '../../../libs/actions/EmojiPickerAction'; +import * as ReportActionsUtils from '../../../libs/ReportActionsUtils'; const propTypes = { /** All the data of the action */ @@ -59,6 +62,10 @@ const propTypes = { /** Whether or not the emoji picker is disabled */ shouldDisableEmojiPicker: PropTypes.bool, + /** Draft message - if this is set the comment is in 'edit' mode */ + // eslint-disable-next-line react/forbid-prop-types + drafts: PropTypes.object, + /** Stores user's preferred skin tone */ preferredSkinTone: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), @@ -70,6 +77,7 @@ const defaultProps = { report: {}, shouldDisableEmojiPicker: false, preferredSkinTone: CONST.EMOJI_DEFAULT_SKIN_TONE, + drafts: {} }; // native ids @@ -229,6 +237,20 @@ function ReportActionItemMessageEdit(props) { const trimmedNewDraft = draft.trim(); + const report = ReportUtils.getReport(props.reportID); + if (report && report.parentReportActionID) { + const parentReportAction = ReportActionsUtils.getParentReportAction(report); + if ((lodashGet(props.drafts, [`reportActionsDrafts_${report.parentReportID}_${parentReportAction.reportActionID}`], undefined))) { + Report.saveReportActionDraft(report.parentReportID, parentReportAction.reportActionID, trimmedNewDraft); + } + } + const childReport = ReportUtils.getReport(props.action.childReportID); + if (props.action.childReportID && childReport) { + if ((lodashGet(props.drafts, [`reportActionsDrafts_${childReport.reportID}_${props.action.reportActionID}`], undefined))) { + Report.saveReportActionDraft(childReport.reportID, props.action.reportActionID, trimmedNewDraft); + } + } + // When user tries to save the empty message, it will delete it. Prompt the user to confirm deleting. if (!trimmedNewDraft) { ReportActionContextMenu.showDeleteModal(props.reportID, props.action, false, deleteDraft, () => InteractionManager.runAfterInteractions(() => textInputRef.current.focus())); @@ -236,7 +258,7 @@ function ReportActionItemMessageEdit(props) { } Report.editReportComment(props.reportID, props.action, trimmedNewDraft); deleteDraft(); - }, [props.action, debouncedSaveDraft, deleteDraft, draft, props.reportID]); + }, [props.action, debouncedSaveDraft, deleteDraft, draft, props.reportID, props.drafts]); /** * @param {String} emoji @@ -385,7 +407,13 @@ ReportActionItemMessageEdit.propTypes = propTypes; ReportActionItemMessageEdit.defaultProps = defaultProps; ReportActionItemMessageEdit.displayName = 'ReportActionItemMessageEdit'; -export default withLocalize( +export default compose( + withLocalize, + withReportActionsDrafts({ + propName: 'drafts', + transformValue: (drafts) => drafts, + }), +)( React.forwardRef((props, ref) => ( Date: Tue, 25 Jul 2023 11:50:39 +0700 Subject: [PATCH 2/7] update draft --- .../home/report/ReportActionItemMessageEdit.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 84c770b0dc03..af81e7f6213a 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -238,16 +238,14 @@ function ReportActionItemMessageEdit(props) { const trimmedNewDraft = draft.trim(); const report = ReportUtils.getReport(props.reportID); - if (report && report.parentReportActionID) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); - if ((lodashGet(props.drafts, [`reportActionsDrafts_${report.parentReportID}_${parentReportAction.reportActionID}`], undefined))) { - Report.saveReportActionDraft(report.parentReportID, parentReportAction.reportActionID, trimmedNewDraft); + if (report && report.parentReportActionID && ReportActionsUtils.hasCommentThread(props.action)) { + if ((lodashGet(props.drafts, [`reportActionsDrafts_${report.parentReportID}_${props.action.reportActionID}`], undefined))) { + Report.saveReportActionDraft(report.parentReportID, props.action.reportActionID, trimmedNewDraft); } } - const childReport = ReportUtils.getReport(props.action.childReportID); - if (props.action.childReportID && childReport) { - if ((lodashGet(props.drafts, [`reportActionsDrafts_${childReport.reportID}_${props.action.reportActionID}`], undefined))) { - Report.saveReportActionDraft(childReport.reportID, props.action.reportActionID, trimmedNewDraft); + if (!report.parentReportActionID && props.action.childReportID) { + if ((lodashGet(props.drafts, [`reportActionsDrafts_${props.action.childReportID}_${props.action.reportActionID}`], undefined))) { + Report.saveReportActionDraft(props.action.childReportID, props.action.reportActionID, trimmedNewDraft); } } From 3636f88293b1fdfc1ca31daae6ca772301b9a37a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 26 Jul 2023 16:33:55 +0700 Subject: [PATCH 3/7] fix: update draft message logic --- src/libs/ReportActionsUtils.js | 7 ++----- .../report/ReportActionItemMessageEdit.js | 20 ++++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 7d08a16fed6c..d1b0bb7116fd 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -461,10 +461,7 @@ function getReportAction(reportID, reportActionID) { } function getFirstReportAction(reportID) { - return _.find( - allReportActions[reportID], - (reportAction) => reportAction.actionName === 'CREATED', - ); + return _.find(allReportActions[reportID], (reportAction) => reportAction.actionName === 'CREATED'); } /** @@ -575,5 +572,5 @@ export { isWhisperAction, isPendingRemove, getReportAction, - getFirstReportAction + getFirstReportAction, }; diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index af81e7f6213a..6644a46f6693 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -12,7 +12,7 @@ import themeColors from '../../../styles/themes/default'; import * as StyleUtils from '../../../styles/StyleUtils'; import Composer from '../../../components/Composer'; import * as Report from '../../../libs/actions/Report'; -import { withReportActionsDrafts} from '../../../components/OnyxProvider'; +import {withReportActionsDrafts} from '../../../components/OnyxProvider'; import openReportActionComposeViewWhenClosingMessageEdit from '../../../libs/openReportActionComposeViewWhenClosingMessageEdit'; import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager'; import EmojiPickerButton from '../../../components/EmojiPicker/EmojiPickerButton'; @@ -37,7 +37,6 @@ import useKeyboardState from '../../../hooks/useKeyboardState'; import useWindowDimensions from '../../../hooks/useWindowDimensions'; import useReportScrollManager from '../../../hooks/useReportScrollManager'; import * as EmojiPickerAction from '../../../libs/actions/EmojiPickerAction'; -import * as ReportActionsUtils from '../../../libs/ReportActionsUtils'; const propTypes = { /** All the data of the action */ @@ -77,7 +76,7 @@ const defaultProps = { report: {}, shouldDisableEmojiPicker: false, preferredSkinTone: CONST.EMOJI_DEFAULT_SKIN_TONE, - drafts: {} + drafts: {}, }; // native ids @@ -238,16 +237,19 @@ function ReportActionItemMessageEdit(props) { const trimmedNewDraft = draft.trim(); const report = ReportUtils.getReport(props.reportID); - if (report && report.parentReportActionID && ReportActionsUtils.hasCommentThread(props.action)) { - if ((lodashGet(props.drafts, [`reportActionsDrafts_${report.parentReportID}_${props.action.reportActionID}`], undefined))) { + + // updating in child message cause parent draft message to change + if (report.parentReportActionID && lodashGet(props.action, 'childType', '') === CONST.REPORT.TYPE.CHAT) { + if (lodashGet(props.drafts, [`reportActionsDrafts_${report.parentReportID}_${props.action.reportActionID}`], undefined)) { Report.saveReportActionDraft(report.parentReportID, props.action.reportActionID, trimmedNewDraft); } - } - if (!report.parentReportActionID && props.action.childReportID) { - if ((lodashGet(props.drafts, [`reportActionsDrafts_${props.action.childReportID}_${props.action.reportActionID}`], undefined))) { + } + // updating in parent message cause child draft message to change + if (props.action.childReportID) { + if (lodashGet(props.drafts, [`reportActionsDrafts_${props.action.childReportID}_${props.action.reportActionID}`], undefined)) { Report.saveReportActionDraft(props.action.childReportID, props.action.reportActionID, trimmedNewDraft); } - } + } // When user tries to save the empty message, it will delete it. Prompt the user to confirm deleting. if (!trimmedNewDraft) { From b6ba307c96cf6d3b078800a4b9639b770864045e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 26 Jul 2023 16:48:30 +0700 Subject: [PATCH 4/7] fix: remove redundant function --- src/libs/ReportActionsUtils.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index d1b0bb7116fd..dbfd57a85c43 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -460,10 +460,6 @@ function getReportAction(reportID, reportActionID) { return lodashGet(allReportActions, [reportID, reportActionID], {}); } -function getFirstReportAction(reportID) { - return _.find(allReportActions[reportID], (reportAction) => reportAction.actionName === 'CREATED'); -} - /** * @returns {string} */ @@ -572,5 +568,4 @@ export { isWhisperAction, isPendingRemove, getReportAction, - getFirstReportAction, }; From 0031c689ed962c952c3ba936360fb9dad6daa909 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 31 Jul 2023 12:42:30 +0700 Subject: [PATCH 5/7] fix: comment --- src/pages/home/report/ReportActionItemMessageEdit.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index aef05b28e812..af082c1c39d1 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -38,6 +38,7 @@ import useKeyboardState from '../../../hooks/useKeyboardState'; import useWindowDimensions from '../../../hooks/useWindowDimensions'; import useReportScrollManager from '../../../hooks/useReportScrollManager'; import * as EmojiPickerAction from '../../../libs/actions/EmojiPickerAction'; +import ONYXKEYS from '../../../ONYXKEYS'; const propTypes = { /** All the data of the action */ @@ -239,15 +240,15 @@ function ReportActionItemMessageEdit(props) { const report = ReportUtils.getReport(props.reportID); - // updating in child message cause parent draft message to change + // Updating in child message cause parent draft message to change if (report.parentReportActionID && lodashGet(props.action, 'childType', '') === CONST.REPORT.TYPE.CHAT) { - if (lodashGet(props.drafts, [`reportActionsDrafts_${report.parentReportID}_${props.action.reportActionID}`], undefined)) { + if (lodashGet(props.drafts, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${report.parentReportID}_${props.action.reportActionID}`], undefined)) { Report.saveReportActionDraft(report.parentReportID, props.action.reportActionID, trimmedNewDraft); } } - // updating in parent message cause child draft message to change + // Updating in parent message cause child draft message to change if (props.action.childReportID) { - if (lodashGet(props.drafts, [`reportActionsDrafts_${props.action.childReportID}_${props.action.reportActionID}`], undefined)) { + if (lodashGet(props.drafts, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${props.action.childReportID}_${props.action.reportActionID}`], undefined)) { Report.saveReportActionDraft(props.action.childReportID, props.action.reportActionID, trimmedNewDraft); } } @@ -412,7 +413,6 @@ export default compose( withLocalize, withReportActionsDrafts({ propName: 'drafts', - transformValue: (drafts) => drafts, }), )( React.forwardRef((props, ref) => ( From a1d9932f6a13888f433e1ec37c9e595cd510b851 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Tue, 8 Aug 2023 09:07:01 +0700 Subject: [PATCH 6/7] Update src/pages/home/report/ReportActionItemMessageEdit.js Co-authored-by: Youssef Lourayad --- src/pages/home/report/ReportActionItemMessageEdit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index af082c1c39d1..3bba198e1071 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -240,7 +240,7 @@ function ReportActionItemMessageEdit(props) { const report = ReportUtils.getReport(props.reportID); - // Updating in child message cause parent draft message to change + // Updates in child message should cause the parent draft message to change if (report.parentReportActionID && lodashGet(props.action, 'childType', '') === CONST.REPORT.TYPE.CHAT) { if (lodashGet(props.drafts, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${report.parentReportID}_${props.action.reportActionID}`], undefined)) { Report.saveReportActionDraft(report.parentReportID, props.action.reportActionID, trimmedNewDraft); From 77d7f01a9855b57fce4f71ea4875da06759207f0 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Tue, 8 Aug 2023 09:07:13 +0700 Subject: [PATCH 7/7] Update src/pages/home/report/ReportActionItemMessageEdit.js Co-authored-by: Youssef Lourayad --- src/pages/home/report/ReportActionItemMessageEdit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 3bba198e1071..0fba4c458283 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -246,7 +246,7 @@ function ReportActionItemMessageEdit(props) { Report.saveReportActionDraft(report.parentReportID, props.action.reportActionID, trimmedNewDraft); } } - // Updating in parent message cause child draft message to change + // Updates in the parent message should cause the child draft message to change if (props.action.childReportID) { if (lodashGet(props.drafts, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${props.action.childReportID}_${props.action.reportActionID}`], undefined)) { Report.saveReportActionDraft(props.action.childReportID, props.action.reportActionID, trimmedNewDraft);