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

[Manual Requests] Create thread for Manual Request when opening IOUPreview #18760

Merged
merged 26 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
202122a
create method to find if a thread exists or not
bondydaa May 11, 2023
fa1b3dc
add rough sketch of what needs to happen to create a thread on demand
bondydaa May 11, 2023
e30b603
fixing merge conflict
bondydaa May 12, 2023
a5e043e
rename method and update to return the report object for a thread
bondydaa May 12, 2023
94c9125
allow the passing of a parentReportActionID so we can create threads
bondydaa May 12, 2023
94c19d6
generate report optimistically and pass parentReportActionID to creat…
bondydaa May 12, 2023
b2c926f
Merge branch 'main' of github.com:Expensify/App into bondy-thread-man…
bondydaa May 12, 2023
6e3bf2c
appease linter
bondydaa May 12, 2023
b4a991b
appease linter and import full lib
bondydaa May 12, 2023
c0e2430
we dont need to prefilter the user making the request out since auth …
bondydaa May 12, 2023
4cfefbb
use amount not payee in report name
bondydaa May 12, 2023
9d518ba
fixing jsdocs and comment
bondydaa May 12, 2023
f83e240
use proper prop
bondydaa May 12, 2023
03f8c6f
Merge main and resolve conflicts
mountiny May 13, 2023
dfc4e79
Fix linter
mountiny May 13, 2023
33afd33
Merge branch 'main' into bondy-thread-manual-requests
mountiny May 14, 2023
6e6eb06
Merge branch 'vit-ensureDeleteShowsAsText' into bondy-thread-manual-r…
mountiny May 14, 2023
35c3c79
Ensure threads are created optimistically
mountiny May 14, 2023
22f9a4a
Add the childReportID to the report action so we do not create multip…
mountiny May 14, 2023
bcb6855
Merge branch 'main' into bondy-thread-manual-requests
mountiny May 14, 2023
3ec51b5
Remove unsused method
mountiny May 14, 2023
9acde61
Merge branch 'main' into bondy-thread-manual-requests
mountiny May 15, 2023
e9d4c4a
Access property safely
mountiny May 15, 2023
df1462a
Update spanish translation
mountiny May 15, 2023
42db583
Fix lint
mountiny May 15, 2023
e800564
Merge branch 'main' into bondy-thread-manual-requests
mountiny May 15, 2023
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
52 changes: 50 additions & 2 deletions src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import styles from '../../styles/styles';
import * as IOUUtils from '../../libs/IOUUtils';
import * as OptionsListUtils from '../../libs/OptionsListUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import * as Report from '../../libs/actions/Report';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import * as CurrencyUtils from '../../libs/CurrencyUtils';

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -56,6 +61,14 @@ const propTypes = {
isHovered: PropTypes.bool,

network: networkPropTypes.isRequired,

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user email */
email: PropTypes.string,
}),

...withLocalizePropTypes,
};

const defaultProps = {
Expand All @@ -67,15 +80,46 @@ const defaultProps = {
iouReport: {},
reportActions: {},
isHovered: false,
session: {
email: null,
},
};

const MoneyRequestAction = (props) => {
const hasMultipleParticipants = lodashGet(props.chatReport, 'participants', []).length > 1;
const onIOUPreviewPressed = () => {
if (hasMultipleParticipants) {
if (lodashGet(props.action, 'originalMessage.type', '') === CONST.IOU.REPORT_ACTION_TYPE.SPLIT && hasMultipleParticipants) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We only going to navigate to the details page in case of IOU split preview

Navigation.navigate(ROUTES.getReportParticipantsRoute(props.chatReportID));
return;
}

// If the childReportID is not present, we need to create a new thread
const childReportID = lodashGet(props.action, 'childReportID', '0');
if (childReportID === '0') {
const participants = _.uniq([props.session.email, props.action.actorEmail]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const participants = _.uniq([props.session.email, props.action.actorEmail]);
const participants = lodashGet(props.action, 'originalMessage.participants');

Can't we just get participants lists from the originalMessage object ?

Screenshot 2023-05-15 at 2 56 56 AM

Copy link
Contributor

Choose a reason for hiding this comment

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

it did not work for me that well when I had that before

Copy link
Contributor

Choose a reason for hiding this comment

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

In the expense report case
image there is FAKE as a participant

I would keep it like this if it works dure to deadline

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just filter those out?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mountiny To make sure we are on the same page , the PR checklist was created with the changes that I suggested :

const participants = lodashGet(props.action, 'originalMessage.participants');

With this actual code, the report is created for user 1 and shared to the DM but the user can’t access the report , That's because participants doesn’t include user2 mail

            const participants = _.uniq([props.session.email, props.action.actorEmail]);

const formattedUserLogins = _.map(participants, (login) => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase());
const thread = ReportUtils.buildOptimisticChatReport(
formattedUserLogins,
props.translate('iou.threadReportName', {
formattedAmount: CurrencyUtils.convertToDisplayString(lodashGet(props.action, 'originalMessage.amount', 0), lodashGet(props.action, 'originalMessage.currency', '')),
comment: props.action.originalMessage.comment,
}),
'',
CONST.POLICY.OWNER_EMAIL_FAKE,
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 IOU - Workspace avatar shows 'U' avatar before reverting to actual avatar in IOU view:
We could use real policyID from iouReport to avoid flickering in offline mode.

lodashGet(props.iouReport, 'policyID', CONST.POLICY.OWNER_EMAIL_FAKE)

CONST.POLICY.OWNER_EMAIL_FAKE,
false,
'',
undefined,
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
props.action.reportActionID,
props.chatReportID, // Needs to be changed to iouReportID
);
Comment on lines +99 to +116
Copy link
Contributor

Choose a reason for hiding this comment

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

Eventually we should move this to reportUtils but now for urgency just leaving this pragmatically here, I hope that works

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, we should create an utils method. Seems ok to leave it for now given that this is blocking other issues


Report.openReport(thread.reportID, thread.participants, thread, props.action.reportActionID);
Navigation.navigate(ROUTES.getReportRoute(thread.reportID));
} else {
Navigation.navigate(ROUTES.getIouDetailsRoute(props.chatReportID, props.action.originalMessage.IOUReportID));
Report.openReport(childReportID);
Navigation.navigate(ROUTES.getReportRoute(childReportID));
}
};

Expand Down Expand Up @@ -125,6 +169,7 @@ MoneyRequestAction.defaultProps = defaultProps;
MoneyRequestAction.displayName = 'MoneyRequestAction';

export default compose(
withLocalize,
withOnyx({
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
Expand All @@ -136,6 +181,9 @@ export default compose(
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`,
canEvict: false,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
withNetwork(),
)(MoneyRequestAction);
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export default {
payerSettled: ({amount}) => `settled up ${amount}`,
noReimbursableExpenses: 'This report has an invalid amount',
pendingConversionMessage: "Total will update when you're back online",
threadReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`,
mountiny marked this conversation as resolved.
Show resolved Hide resolved
error: {
invalidSplit: 'Split amounts do not equal total amount',
other: 'Unexpected error, please try again later',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export default {
payerSettled: ({amount}) => `pagado ${amount}`,
noReimbursableExpenses: 'El monto de este informe es inválido',
pendingConversionMessage: 'El total se actualizará cuando estés online',
threadReportName: ({formattedAmount, comment}) => `${formattedAmount} pedido${comment ? ` per ${comment}` : ''}`,
error: {
invalidSplit: 'La suma de las partes no equivale al monto total',
other: 'Error inesperado, por favor inténtalo más tarde',
Expand Down
12 changes: 12 additions & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ function getParentReportAction(report) {
return lodashGet(allReportActions, [report.parentReportID, report.parentReportActionID], {});
}

/**
* Returns whether the thread is a transaction thread, which is any thread with IOU parent
* report action of type create.
*
* @param {Object} parentReportAction
* @returns {Boolean}
*/
function isTransactionThread(parentReportAction) {
return parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && lodashGet(parentReportAction, 'originalMessage.type') === CONST.IOU.REPORT_ACTION_TYPE.CREATE;
mountiny marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Sort an array of reportActions by their created timestamp first, and reportActionID second
* This gives us a stable order even in the case of multiple reportActions created on the same millisecond
Expand Down Expand Up @@ -322,4 +333,5 @@ export {
getLinkedTransactionID,
isCreatedTaskReportAction,
getParentReportAction,
isTransactionThread,
};
20 changes: 18 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,19 @@ function getMoneyRequestReportName(report) {
return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount});
}

/**
* Given a parent IOU report action get report name for the LHN.
*
* @param {Object} reportAction
* @returns {String}
*/
function getTransactionReportName(reportAction) {
return Localize.translateLocal('iou.threadReportName', {
formattedAmount: CurrencyUtils.convertToDisplayString(lodashGet(reportAction, 'originalMessage.amount', 0), lodashGet(reportAction, 'originalMessage.currency', '')),
comment: lodashGet(reportAction, 'originalMessage.comment'),
});
}

/**
* Get the title for a report.
*
Expand All @@ -1011,6 +1024,9 @@ function getReportName(report) {
let formattedName;
if (isThread(report)) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
if (ReportActionsUtils.isTransactionThread(parentReportAction)) {
return getTransactionReportName(parentReportAction);
Comment on lines +1027 to +1028
Copy link
Contributor

Choose a reason for hiding this comment

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

The reportName is specific for the transaction threads so hijackign this flow

}
const parentReportActionMessage = lodashGet(parentReportAction, ['message', 0, 'text'], '').replace(/(\r\n|\n|\r)/gm, ' ');
return parentReportActionMessage || Localize.translateLocal('parentReportAction.deletedMessage');
}
Expand Down Expand Up @@ -1388,8 +1404,8 @@ function buildOptimisticChatReport(
oldPolicyName = '',
visibility = undefined,
notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
parentReportActionID,
parentReportID,
parentReportActionID = '',
bondydaa marked this conversation as resolved.
Show resolved Hide resolved
parentReportID = '',
) {
const currentTime = DateUtils.getDBTime();
return {
Expand Down
14 changes: 14 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ function openReport(reportID, participantList = [], newReportObject = {}, parent
// Add the createdReportActionID parameter to the API call
params.createdReportActionID = optimisticCreatedAction.reportActionID;
}

// If we are creating a thread, ensure the report action has childReportID property added
if (newReportObject.parentReportID && parentReportActionID) {
onyxData.optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`,
value: {[parentReportActionID]: {childReportID: reportID}},
});
onyxData.failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`,
value: {[parentReportActionID]: {childReportID: '0'}},
});
}
Comment on lines +409 to +420
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sure that when we create a report, the parent report action gets the childReportID key added. It should be updated by pusher, but if you are offline we would keep creating new threads by clicking on the preview or we could also crete new ones by quickly clicking on the preview before the pusher update comes through

Copy link
Contributor

Choose a reason for hiding this comment

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

I ma not sure but I think no successData is needed here because we are only adding a property in ptimistic data and no pending value

}

API.write('OpenReport', params, onyxData);
Expand Down
6 changes: 6 additions & 0 deletions src/pages/home/report/ReportActionItemParentAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import compose from '../../../libs/compose';
import withLocalize from '../../../components/withLocalize';
import ReportActionItem from './ReportActionItem';
import reportActionPropTypes from './reportActionPropTypes';
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils';

const propTypes = {
/** The id of the report */
Expand Down Expand Up @@ -41,6 +42,11 @@ const defaultProps = {

const ReportActionItemParentAction = (props) => {
const parentReportAction = props.parentReportActions[`${props.report.parentReportActionID}`];

// In case of transaction threads, we do not want to render the parent report action.
if (ReportActionsUtils.isTransactionThread(parentReportAction)) {
return null;
}
Comment on lines +46 to +49
Copy link
Contributor

Choose a reason for hiding this comment

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

This is to ensure we do not show any report Action at the top of the transactions thread

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm working on a change that might affect this line, can you clarify what the goal here was? @mountiny

return (
<OfflineWithFeedback
pendingAction={lodashGet(props.report, 'pendingFields.addWorkspaceRoom') || lodashGet(props.report, 'pendingFields.createChat')}
Expand Down