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

Make optimistic requests/IOUs/expense reports “hidden” #29681

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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: 14 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,16 @@ function getReport(reportID) {
return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}) || {};
}

/**
* Get the notification preference given a report
*
* @param {Object} report
* @returns {String}
*/
function getReportNotificationPreference(report) {
rezkiy37 marked this conversation as resolved.
Show resolved Hide resolved
return lodashGet(report, 'notificationPreference', '');
}

/**
* Can only delete if the author is this user and the action is an ADDCOMMENT action or an IOU action in an unsettled report, or if the user is a
* policy admin
Expand Down Expand Up @@ -2240,7 +2250,7 @@ function buildOptimisticIOUReport(payeeAccountID, payerAccountID, total, chatRep

// We don't translate reportName because the server response is always in English
reportName: `${payerEmail} owes ${formattedTotal}`,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
mountiny marked this conversation as resolved.
Show resolved Hide resolved
parentReportID: chatReportID,
};
}
Expand Down Expand Up @@ -2279,7 +2289,7 @@ function buildOptimisticExpenseReport(chatReportID, policyID, payeeAccountID, to
state: CONST.REPORT.STATE.SUBMITTED,
stateNum: CONST.REPORT.STATE_NUM.PROCESSING,
total: storedTotal,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
parentReportID: chatReportID,
};
}
Expand Down Expand Up @@ -2974,7 +2984,7 @@ function buildTransactionThread(reportAction, moneyRequestReportID) {
'',
undefined,
undefined,
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
reportAction.reportActionID,
moneyRequestReportID,
);
Expand Down Expand Up @@ -3981,6 +3991,7 @@ export {
getDisplayNamesWithTooltips,
getReportName,
getReport,
getReportNotificationPreference,
getReportIDFromLink,
getRouteFromLink,
getDeletedParentActionMessageForChatReport,
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ function addActions(reportID, text = '', file) {
isLastMessageDeletedParentAction: null,
};

if (ReportUtils.getReportNotificationPreference(ReportUtils.getReport(reportID)) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
optimisticReport.notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS;
}

// Optimistically add the new actions to the store before waiting to save them to the server
const optimisticReportActions = {};
if (text) {
Expand Down
17 changes: 17 additions & 0 deletions tests/actions/IOUTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ describe('actions/IOU', () => {
const iouReport = iouReports[0];
iouReportID = iouReport.reportID;

expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

// They should be linked together
expect(chatReport.participantAccountIDs).toEqual([CARLOS_ACCOUNT_ID]);
expect(chatReport.iouReportID).toBe(iouReport.reportID);
Expand Down Expand Up @@ -242,6 +244,8 @@ describe('actions/IOU', () => {
const iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU);
iouReportID = iouReport.reportID;

expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

// They should be linked together
expect(chatReport.iouReportID).toBe(iouReportID);
expect(chatReport.hasOutstandingIOU).toBe(true);
Expand Down Expand Up @@ -570,6 +574,8 @@ describe('actions/IOU', () => {
const iouReport = iouReports[0];
iouReportID = iouReport.reportID;

expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

// They should be linked together
expect(chatReport.participantAccountIDs).toEqual([CARLOS_ACCOUNT_ID]);
expect(chatReport.iouReportID).toBe(iouReport.reportID);
Expand Down Expand Up @@ -978,6 +984,7 @@ describe('actions/IOU', () => {
expect(carlosChatReport.hasOutstandingIOU).toBe(true);
expect(carlosChatReport.iouReportID).toBe(carlosIOUReport.reportID);
expect(carlosIOUReport.chatReportID).toBe(carlosChatReport.reportID);
expect(carlosIOUReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

expect(julesChatReport.hasOutstandingIOU).toBe(true);
expect(julesChatReport.iouReportID).toBe(julesIOUReport.reportID);
Expand All @@ -986,6 +993,7 @@ describe('actions/IOU', () => {
expect(vitChatReport.hasOutstandingIOU).toBe(true);
expect(vitChatReport.iouReportID).toBe(vitIOUReport.reportID);
expect(vitIOUReport.chatReportID).toBe(vitChatReport.reportID);
expect(carlosIOUReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

resolve();
},
Expand Down Expand Up @@ -1702,6 +1710,8 @@ describe('actions/IOU', () => {
// Given a transaction thread
thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID);

expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
callback: (val) => (reportActions = val),
Expand Down Expand Up @@ -1779,6 +1789,9 @@ describe('actions/IOU', () => {

// Given a transaction thread
thread = ReportUtils.buildTransactionThread(createIOUAction);

expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs);
jest.advanceTimersByTime(10);
Report.openReport(thread.reportID, userLogins, thread, createIOUAction.reportActionID);
Expand Down Expand Up @@ -1863,6 +1876,8 @@ describe('actions/IOU', () => {
jest.advanceTimersByTime(10);
thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID);

expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
callback: (val) => (reportActions = val),
Expand Down Expand Up @@ -2076,6 +2091,8 @@ describe('actions/IOU', () => {
jest.advanceTimersByTime(10);
thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID);

expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
callback: (val) => (reportActions = val),
Expand Down
Loading