From af2bc11e79ce5516bd256899b298a51633631694 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 16 Dec 2023 14:08:13 +0800 Subject: [PATCH 1/5] add isOptimisticAction optimistically and remove on success --- src/libs/ReportUtils.ts | 3 ++- src/libs/actions/Report.ts | 2 +- src/libs/actions/Task.js | 2 +- src/types/onyx/ReportAction.ts | 3 +++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 24e795919649..d4f190d9ae6c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2470,6 +2470,7 @@ function buildOptimisticAddCommentReportAction(text?: string, file?: File): Opti attachmentInfo, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, shouldShow: true, + isOptimisticAction: true, }, }; } @@ -4143,7 +4144,7 @@ function getTaskAssigneeChatOnyxData( failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: {[optimisticAssigneeAddComment.reportAction.reportActionID ?? '']: {pendingAction: null}}, + value: {[optimisticAssigneeAddComment.reportAction.reportActionID ?? '']: {pendingAction: null, isOptimisticAction: null}}, }); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 135e616f7691..778e246bfa7f 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -363,7 +363,7 @@ function addActions(reportID: string, text = '', file?: File) { const successReportActions: OnyxCollection> = {}; Object.entries(optimisticReportActions).forEach(([actionKey]) => { - successReportActions[actionKey] = {pendingAction: null}; + successReportActions[actionKey] = {pendingAction: null, isOptimisticAction: null}; }); const successData: OnyxUpdate[] = [ diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 0fe6a528cda1..a980ec7c9a3b 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -183,7 +183,7 @@ function createTaskAndNavigate(parentReportID, title, description, assigneeEmail successData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, - value: {[optimisticAddCommentReport.reportAction.reportActionID]: {pendingAction: null}}, + value: {[optimisticAddCommentReport.reportAction.reportActionID]: {pendingAction: null, isOptimisticAction: null}}, }); // FOR PARENT REPORT (SHARE DESTINATION) diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index 8e56aaa67345..e80e80f49f43 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -190,6 +190,9 @@ type ReportActionBase = { /** We manually add this field while sorting to detect the end of the list */ isNewestReportAction?: boolean; + + /** Flag for checking if data is from optimistic data */ + isOptimisticAction?: boolean; }; type ReportAction = ReportActionBase & OriginalMessage; From 9d06f4808c22e484bbfe1b7e9a9ba0b455c08767 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 16 Dec 2023 14:08:36 +0800 Subject: [PATCH 2/5] remove optimistic action from onyx --- src/libs/actions/ReportActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/ReportActions.ts b/src/libs/actions/ReportActions.ts index 7cd72fb4cd49..ebde0cef93af 100644 --- a/src/libs/actions/ReportActions.ts +++ b/src/libs/actions/ReportActions.ts @@ -13,7 +13,7 @@ function clearReportActionErrors(reportID: string, reportAction: ReportAction) { return; } - if (reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { + if (reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || reportAction.isOptimisticAction) { // Delete the optimistic action Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, { [reportAction.reportActionID]: null, From 2445a22ae8e8b9c1e7cb773c11a71c01b3985c65 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 16 Dec 2023 14:08:59 +0800 Subject: [PATCH 3/5] fall back to add pending action if it's optimistic action --- src/pages/home/report/ReportActionItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index d4731d3b929b..bdd5e197cc49 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -694,7 +694,7 @@ function ReportActionItem(props) { ReportActions.clearReportActionErrors(props.report.reportID, props.action)} - pendingAction={props.draftMessage ? null : props.action.pendingAction} + pendingAction={props.draftMessage ? null : props.action.pendingAction || (props.action.isOptimisticAction ? CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD : '')} shouldHideOnDelete={!ReportActionsUtils.isThreadParentMessage(props.action, props.report.reportID)} errors={props.action.errors} errorRowStyles={[styles.ml10, styles.mr2]} From 6fb3faabe28a8e969bde8dea7f338d366ef7f29b Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 16 Dec 2023 14:30:55 +0800 Subject: [PATCH 4/5] clear isOptimisticAction on success data instead --- src/libs/ReportUtils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d4f190d9ae6c..944ac2b10db4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4141,10 +4141,15 @@ function getTaskAssigneeChatOnyxData( value: optimisticAssigneeReport, }, ); + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, + value: {[optimisticAssigneeAddComment.reportAction.reportActionID ?? '']: {isOptimisticAction: null}}, + }); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: {[optimisticAssigneeAddComment.reportAction.reportActionID ?? '']: {pendingAction: null, isOptimisticAction: null}}, + value: {[optimisticAssigneeAddComment.reportAction.reportActionID ?? '']: {pendingAction: null}}, }); } From 081e785912390d2188c687b20e006ed16f4ca266 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 3 Jan 2024 10:42:17 +0800 Subject: [PATCH 5/5] prettier --- src/pages/home/report/ReportActionItem.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 8b8004125164..8259d8055d17 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -688,7 +688,9 @@ function ReportActionItem(props) { ReportActions.clearReportActionErrors(props.report.reportID, props.action)} - pendingAction={!_.isUndefined(props.draftMessage) ? null : props.action.pendingAction || (props.action.isOptimisticAction ? CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD : '')} + pendingAction={ + !_.isUndefined(props.draftMessage) ? null : props.action.pendingAction || (props.action.isOptimisticAction ? CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD : '') + } shouldHideOnDelete={!ReportActionsUtils.isThreadParentMessage(props.action, props.report.reportID)} errors={props.action.errors} errorRowStyles={[styles.ml10, styles.mr2]}