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

Reusable function instead of repetitive statements #22649

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,22 @@ function buildOptimisticReportPreview(chatReport, iouReport) {
};
}

function updateReportPreview(iouReport, reportPreviewAction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing JSDocs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Added for both buildOptimisticReportPreview and updateReportPreview

const message = getReportPreviewMessage(iouReport, reportPreviewAction);
return {
...reportPreviewAction,
created: DateUtils.getDBTime(),
message: [
{
html: message,
text: message,
isEdited: false,
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
},
],
Comment on lines +1800 to +1807
Copy link
Contributor

Choose a reason for hiding this comment

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

This will re-write existing reportPreviewAction.message[0]. Is it fine? Original code just replaced html and text inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this is fine. The original code was introduced in the previous PR where we decided to improve the code in this follow-up PR, so we are safe.

};
}

function buildOptimisticTaskReportAction(taskReportID, actionName, message = '') {
const originalMessage = {
taskReportID,
Expand Down Expand Up @@ -2544,6 +2560,7 @@ export {
buildOptimisticExpenseReport,
buildOptimisticIOUReportAction,
buildOptimisticReportPreview,
updateReportPreview,
buildOptimisticTaskReportAction,
buildOptimisticAddCommentReportAction,
buildOptimisticTaskCommentReportAction,
Expand Down
16 changes: 3 additions & 13 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,7 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part

let reportPreviewAction = isNewIOUReport ? null : ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID);
if (reportPreviewAction) {
reportPreviewAction.created = DateUtils.getDBTime();
const message = ReportUtils.getReportPreviewMessage(iouReport, reportPreviewAction);
reportPreviewAction.message[0].html = message;
reportPreviewAction.message[0].text = message;
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction);
} else {
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport);
}
Expand Down Expand Up @@ -657,10 +654,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco

let oneOnOneReportPreviewAction = ReportActionsUtils.getReportPreviewAction(oneOnOneChatReport.reportID, oneOnOneIOUReport.reportID);
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction.created = DateUtils.getDBTime();
const message = ReportUtils.getReportPreviewMessage(oneOnOneIOUReport, oneOnOneReportPreviewAction);
oneOnOneReportPreviewAction.message[0].html = message;
oneOnOneReportPreviewAction.message[0].text = message;
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction);
} else {
oneOnOneReportPreviewAction = ReportUtils.buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport);
}
Expand Down Expand Up @@ -1141,11 +1135,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
login: recipient.login,
};

const optimisticReportPreviewAction = ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID);
optimisticReportPreviewAction.created = DateUtils.getDBTime();
const message = ReportUtils.getReportPreviewMessage(iouReport, optimisticReportPreviewAction);
optimisticReportPreviewAction.message[0].html = message;
optimisticReportPreviewAction.message[0].text = message;
const optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID));

const optimisticData = [
{
Expand Down