Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update optimistic data for parent report action when completing or reopening task #22990

Merged
merged 6 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,30 @@ function updateOptimisticParentReportAction(parentReportAction, lastVisibleActio
};
}

/**
* Get optimistic data of parent report action
* @param {String} reportID The reportID of the report that is updated
* @param {String} lastVisibleActionCreated Last visible action created of the child report
* @param {String} type The type of action in the child report
* @returns {Object}
*/
const getOptimisticDataForParentReportAction = (reportID, lastVisibleActionCreated, type) => {
const report = getReport(reportID);
if (report && report.parentReportActionID) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
if (parentReportAction && parentReportAction.reportActionID) {
return {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`,
value: {
[parentReportAction.reportActionID]: updateOptimisticParentReportAction(parentReportAction, lastVisibleActionCreated, type),
},
};
}
}
return {};
};

/**
* Builds an optimistic reportAction for the parent report when a task is created
* @param {String} taskReportID - Report ID of the task
Expand Down Expand Up @@ -2591,6 +2615,7 @@ export {
buildOptimisticAddCommentReportAction,
buildOptimisticTaskCommentReportAction,
updateOptimisticParentReportAction,
getOptimisticDataForParentReportAction,
shouldReportBeInOptionList,
getChatByParticipants,
getChatByParticipantsByLoginList,
Expand Down
37 changes: 8 additions & 29 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,10 @@ function addActions(reportID, text = '', file) {
},
];

// Optimistically update the parent report action if the report is a thread
const report = ReportUtils.getReport(reportID);
if (report && report.parentReportActionID) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
if (parentReportAction && parentReportAction.reportActionID) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`,
value: {
[parentReportAction.reportActionID]: ReportUtils.updateOptimisticParentReportAction(parentReportAction, currentTime, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD),
},
});
}
// Update optimistic data for parent report action if the report is a child report
const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(reportID, currentTime, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #38002 , we should have updated the optimistic data for each ancestor thread.

if (!_.isEmpty(optimisticParentReportData)) {
optimisticData.push(optimisticParentReportData);
}

// Update the timezone if it's been 5 minutes from the last time the user added a comment
Expand Down Expand Up @@ -959,22 +950,10 @@ function deleteReportComment(reportID, reportAction) {
},
];

const report = ReportUtils.getReport(reportID);
if (report && report.parentReportActionID) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
if (parentReportAction && parentReportAction.reportActionID) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`,
value: {
[parentReportAction.reportActionID]: ReportUtils.updateOptimisticParentReportAction(
parentReportAction,
optimisticReport.lastVisibleActionCreated,
CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
),
},
});
}
// Update optimistic data for parent report action if the report is a child report
const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(reportID, optimisticReport.lastVisibleActionCreated, CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
if (!_.isEmpty(optimisticParentReportData)) {
optimisticData.push(optimisticParentReportData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #26012:
I won't say it's a regression but it could have been perfect if below case was handled as well:

If deleted message in thread has visible child actions, childVisibleActionCount of parentReportAction should not be decreased

}

const parameters = {
Expand Down
12 changes: 12 additions & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ function completeTask(taskReportID, taskTitle) {
},
];

// Update optimistic data for parent report action
const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, completedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
if (!_.isEmpty(optimisticParentReportData)) {
optimisticData.push(optimisticParentReportData);
}

API.write(
'CompleteTask',
{
Expand Down Expand Up @@ -312,6 +318,12 @@ function reopenTask(taskReportID, taskTitle) {
},
];

// Update optimistic data for parent report action
const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(taskReportID, reopenedTaskReportAction.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
if (!_.isEmpty(optimisticParentReportData)) {
optimisticData.push(optimisticParentReportData);
}

API.write(
'ReopenTask',
{
Expand Down
Loading