Skip to content

Commit

Permalink
Merge pull request #30844 from hoangzinh/fix/27296
Browse files Browse the repository at this point in the history
Fix - App marks Task as unread even when no changes are done
  • Loading branch information
stitesExpensify authored Nov 30, 2023
2 parents d0233c0 + bfe61c2 commit ef3d8cd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
11 changes: 10 additions & 1 deletion src/libs/StringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@ function removeInvisibleCharacters(value: string): string {
return result.trim();
}

export default {sanitizeString, isEmptyString, removeInvisibleCharacters};
/**
* Replace all CRLF with LF
* @param value - The input string
* @returns The string with all CRLF replaced with LF
*/
function normalizeCRLF(value?: string): string | undefined {
return value?.replace(/\r\n/g, '\n');
}

export default {sanitizeString, isEmptyString, removeInvisibleCharacters, normalizeCRLF};
18 changes: 7 additions & 11 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function reopenTask(taskReport) {
* @param {object} report
* @param {Object} editedTask
*/
function editTaskAndNavigate(report, {title, description}) {
function editTask(report, {title, description}) {
// Create the EditedReportAction on the task
const editTaskReportAction = ReportUtils.buildOptimisticEditedTaskReportAction(currentUserEmail);

Expand Down Expand Up @@ -433,11 +433,9 @@ function editTaskAndNavigate(report, {title, description}) {
},
{optimisticData, successData, failureData},
);

Navigation.dismissModal(report.reportID);
}

function editTaskAssigneeAndNavigate(report, ownerAccountID, assigneeEmail, assigneeAccountID = 0, assigneeChatReport = null) {
function editTaskAssignee(report, ownerAccountID, assigneeEmail, assigneeAccountID = 0, assigneeChatReport = null) {
// Create the EditedReportAction on the task
const editTaskReportAction = ReportUtils.buildOptimisticEditedTaskReportAction(currentUserEmail);
const reportName = report.reportName.trim();
Expand Down Expand Up @@ -525,8 +523,6 @@ function editTaskAssigneeAndNavigate(report, ownerAccountID, assigneeEmail, assi
},
{optimisticData, successData, failureData},
);

Navigation.dismissModal(report.reportID);
}

/**
Expand Down Expand Up @@ -628,9 +624,9 @@ function setAssigneeValue(assigneeEmail, assigneeAccountID, shareDestination, is
// This is only needed for creation of a new task and so it should only be stored locally
Onyx.merge(ONYXKEYS.TASK, {assignee: assigneeEmail, assigneeAccountID});

// When we're editing the assignee, we immediately call EditTaskAndNavigate. Since setting the assignee is async,
// the chatReport is not yet set when EditTaskAndNavigate is called. So we return the chatReport here so that
// EditTaskAndNavigate can use it.
// When we're editing the assignee, we immediately call editTaskAssignee. Since setting the assignee is async,
// the chatReport is not yet set when editTaskAssignee is called. So we return the chatReport here so that
// editTaskAssignee can use it.
return chatReport;
}

Expand Down Expand Up @@ -941,8 +937,8 @@ function getTaskReportActionMessage(actionName, reportID, isCreateTaskAction) {

export {
createTaskAndNavigate,
editTaskAndNavigate,
editTaskAssigneeAndNavigate,
editTask,
editTaskAssignee,
setTitleValue,
setDescriptionValue,
setTaskReport,
Expand Down
9 changes: 6 additions & 3 deletions src/pages/tasks/TaskAssigneeSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ function TaskAssigneeSelectorModal(props) {

// Check to see if we're editing a task and if so, update the assignee
if (report) {
const assigneeChatReport = Task.setAssigneeValue(option.login, option.accountID, props.route.params.reportID, OptionsListUtils.isCurrentUser(option));
if (option.accountID !== report.managerID) {
const assigneeChatReport = Task.setAssigneeValue(option.login, option.accountID, props.route.params.reportID, OptionsListUtils.isCurrentUser(option));

// Pass through the selected assignee
Task.editTaskAssigneeAndNavigate(report, props.session.accountID, option.login, option.accountID, assigneeChatReport);
// Pass through the selected assignee
Task.editTaskAssignee(report, props.session.accountID, option.login, option.accountID, assigneeChatReport);
}
return Navigation.dismissModal(report.reportID);
}
};

Expand Down
12 changes: 9 additions & 3 deletions src/pages/tasks/TaskDescriptionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as Browser from '@libs/Browser';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import StringUtils from '@libs/StringUtils';
import updateMultilineInputRange from '@libs/UpdateMultilineInputRange';
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound';
import reportPropTypes from '@pages/reportPropTypes';
Expand Down Expand Up @@ -42,9 +43,14 @@ function TaskDescriptionPage(props) {

const submit = useCallback(
(values) => {
// Set the description of the report in the store and then call Task.editTaskReport
// to update the description of the report on the server
Task.editTaskAndNavigate(props.report, {description: values.description});
// props.report.description might contain CRLF from the server
if (StringUtils.normalizeCRLF(values.description) !== StringUtils.normalizeCRLF(props.report.description)) {
// Set the description of the report in the store and then call EditTask API
// to update the description of the report on the server
Task.editTask(props.report, {description: values.description});
}

Navigation.dismissModal(props.report.reportID);
},
[props],
);
Expand Down
10 changes: 7 additions & 3 deletions src/pages/tasks/TaskTitlePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ function TaskTitlePage(props) {

const submit = useCallback(
(values) => {
// Set the title of the report in the store and then call Task.editTaskReport
// to update the title of the report on the server
Task.editTaskAndNavigate(props.report, {title: values.title});
if (values.title !== props.report.reportName) {
// Set the title of the report in the store and then call EditTask API
// to update the title of the report on the server
Task.editTask(props.report, {title: values.title});
}

Navigation.dismissModal(props.report.reportID);
},
[props],
);
Expand Down

0 comments on commit ef3d8cd

Please sign in to comment.