Skip to content

Commit

Permalink
Merge pull request #33198 from bernhardoj/fix/32529-optimistic-add-is…
Browse files Browse the repository at this point in the history
…-lost

Fix a fail to add and edit/delete message doesn't get cleared when closing the error message
  • Loading branch information
marcaaron authored Jan 8, 2024
2 parents 347a06e + 382a096 commit c0c4d64
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,7 @@ function buildOptimisticAddCommentReportAction(text?: string, file?: File): Opti
attachmentInfo,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
shouldShow: true,
isOptimisticAction: true,
},
};
}
Expand Down Expand Up @@ -4116,6 +4117,11 @@ 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}`,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function addActions(reportID: string, text = '', file?: File) {
const successReportActions: OnyxCollection<NullishDeep<ReportAction>> = {};

Object.entries(optimisticReportActions).forEach(([actionKey]) => {
successReportActions[actionKey] = {pendingAction: null};
successReportActions[actionKey] = {pendingAction: null, isOptimisticAction: null};
});

const successData: OnyxUpdate[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/ReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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)
Expand Down
4 changes: 3 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,9 @@ function ReportActionItem(props) {
<View style={StyleUtils.getReportActionItemStyle(hovered || isWhisper || isContextMenuActive || !_.isUndefined(props.draftMessage))}>
<OfflineWithFeedback
onClose={() => ReportActions.clearReportActionErrors(props.report.reportID, props.action)}
pendingAction={!_.isUndefined(props.draftMessage) ? null : props.action.pendingAction}
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]}
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,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;
Expand Down

0 comments on commit c0c4d64

Please sign in to comment.