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

Display report preview using new reportAction data source #18423

Merged
merged 49 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
15cf4c5
New report action type in CONST file.
cristipaval Apr 28, 2023
972480e
Create ReportPreview component.
cristipaval Apr 28, 2023
7b86c61
Utility method to get report preview action.
cristipaval Apr 28, 2023
ff09d17
Utility function which builds optimistic report preview.
cristipaval Apr 28, 2023
fb94299
Add report preview in optimistic and success data
cristipaval May 1, 2023
4f72a9f
WIP.
cristipaval May 1, 2023
8b463a0
Connect to Onyx in ReportActionsUtils to get the current user email.
cristipaval May 2, 2023
87f0c6b
Improve message property in optimistic report preview action.
cristipaval May 2, 2023
650389d
Build the preview component starting from IOUAction
cristipaval May 2, 2023
4615b3f
Remove the iou preview.
cristipaval May 2, 2023
e36b159
Remove unnecessary props and logic. from the component.
cristipaval May 2, 2023
3ff969b
Remove unused default props.
cristipaval May 2, 2023
538eb6e
Pull iou report from onyx to get the cached iou total
cristipaval May 2, 2023
bc63580
No more IOUQUote reusability in ReportPreview
cristipaval May 2, 2023
dd26649
Hardcode translations.
cristipaval May 2, 2023
031ffbf
Add reportPreviewReportActionID as a param to RequestMoney command
cristipaval May 4, 2023
c75e249
Merge remote-tracking branch 'origin/main' into cristi_display-report…
cristipaval May 4, 2023
5b053f4
Merge remote-tracking branch 'origin/main' into cristi_display-report…
cristipaval May 4, 2023
595cb41
Improvements.
cristipaval May 4, 2023
a77f5c6
Pay button.
cristipaval May 4, 2023
8ba163e
Add logic for report preview action for split the bill
cristipaval May 9, 2023
9387a58
wip
cristipaval May 9, 2023
3582868
Merge remote-tracking branch 'origin/main' into cristi_display-report…
cristipaval May 9, 2023
372074b
Merge remote-tracking branch 'origin/main' into cristi_display-report…
cristipaval May 10, 2023
d618723
Merge branch 'main' into cristi_display-report-preview
Julesssss May 11, 2023
62ab68f
apply lint fixes
Julesssss May 11, 2023
a79f513
Merge branch 'cristi_display-report-preview' into jules-reportPreview…
Julesssss May 11, 2023
8caecc0
apply fix for missing currency
Julesssss May 11, 2023
5537cd9
stop showing reportPreview within IOUAction component
Julesssss May 11, 2023
083081d
update prop name for reportpreview format string
Julesssss May 11, 2023
3036057
launch IOUDetails page when request preview is tapped
Julesssss May 11, 2023
d2fc338
remove temp changes
Julesssss May 11, 2023
2cb3661
add action type == IOU filter to IOUTransactions component
Julesssss May 11, 2023
b21560b
linkedReportID instead of IOUReportID
cristipaval May 12, 2023
0c934e6
Merge branch 'main' into cristi_display-report-preview
Julesssss May 15, 2023
d782749
apply prettier style changes
Julesssss May 15, 2023
0957f0d
update IOU test cases to account for the new preview action
Julesssss May 15, 2023
6b4035d
clear the iouPreview pending action after successfully creating it
Julesssss May 15, 2023
581c229
fix console error in IOUDetailsModal by providing default report prop
Julesssss May 15, 2023
3b2bc3a
Merge branch 'main' into cristi_display-report-preview
Julesssss May 16, 2023
c620d14
resolve lint issue
Julesssss May 16, 2023
fafb4ae
resolve conflicts
luacmartins May 16, 2023
30e8c70
rm circular dependency
luacmartins May 16, 2023
6f19516
refactor split bill
luacmartins May 16, 2023
6d2250f
define const, navigate to correct report
luacmartins May 16, 2023
4621d19
resolve conflicts
luacmartins May 16, 2023
d678e0e
Merge branch 'cmartins-createRequestsInExpenseReports' into cristi_di…
Julesssss May 17, 2023
8a8ad58
apply prettier again
Julesssss May 17, 2023
1330745
remove duplicate description field, added in merge conflict resolution
Julesssss May 17, 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
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ const CONST = {
CHRONOSOOOLIST: 'CHRONOSOOOLIST',
TASKCOMPLETED: 'TASKCOMPLETED',
TASKREOPENED: 'TASKREOPENED',
REPORTPREVIEW: 'REPORTPREVIEW',
POLICYCHANGELOG: {
ADD_APPROVER_RULE: 'POLICYCHANGELOG_ADD_APPROVER_RULE',
ADD_CATEGORY: 'POLICYCHANGELOG_ADD_CATEGORY',
Expand Down
7 changes: 3 additions & 4 deletions src/components/Pressable/PressableWithFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ const PressableWithFeedback = forwardRef((props, ref) => {
setDisabled(props.disabled);
return;
}
onPress
.finally(() => {
setDisabled(props.disabled);
});
onPress.finally(() => {
setDisabled(props.disabled);
});
});
}}
>
Expand Down
1 change: 0 additions & 1 deletion src/components/ReportActionItem/IOUPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ const IOUPreview = (props) => {
</View>
)}
</View>

<View style={[styles.flexRow]}>
<View style={[styles.flex1]}>
{!isCurrentUserManager && props.shouldShowPendingConversionMessage && (
Expand Down
12 changes: 0 additions & 12 deletions src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ONYXKEYS from '../../ONYXKEYS';
import CONST from '../../CONST';
import {withNetwork} from '../OnyxProvider';
import compose from '../../libs/compose';
import ReportPreview from './ReportPreview';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
import networkPropTypes from '../networkPropTypes';
import iouReportPropTypes from '../../pages/iouReportPropTypes';
Expand Down Expand Up @@ -149,17 +148,6 @@ const MoneyRequestAction = (props) => {
containerStyles={[styles.cursorPointer, props.isHovered ? styles.iouPreviewBoxHover : undefined]}
isHovered={props.isHovered}
/>
{props.isMostRecentIOUReportAction && !hasMultipleParticipants && (
<ReportPreview
action={props.action}
chatReportID={props.chatReportID}
iouReportID={props.requestReportID}
contextMenuAnchor={props.contextMenuAnchor}
onViewDetailsPressed={onIOUPreviewPressed}
checkIfContextMenuActive={props.checkIfContextMenuActive}
isHovered={props.isHovered}
/>
)}
</>
);
};
Expand Down
15 changes: 7 additions & 8 deletions src/components/ReportActionItem/ReportPreview.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: We have an unnecessary mt4

Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import styles from '../../styles/styles';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import ControlSelection from '../../libs/ControlSelection';
import * as DeviceCapabilities from '../../libs/DeviceCapabilities';
import {showContextMenuForReport} from '../ShowContextMenuContext';
import * as StyleUtils from '../../styles/StyleUtils';
import * as CurrencyUtils from '../../libs/CurrencyUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import Button from '../Button';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import themeColors from '../../styles/themes/default';
import getButtonState from '../../libs/getButtonState';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import ONYXKEYS from '../../ONYXKEYS';

const propTypes = {
/** All the data of the action */
Expand All @@ -36,6 +36,7 @@ const propTypes = {
// eslint-disable-next-line react/no-unused-prop-types
iouReportID: PropTypes.string.isRequired,

/* Onyx Props */
/** chatReport associated with iouReport */
chatReport: PropTypes.shape({
/** The participants of this report */
Expand Down Expand Up @@ -72,9 +73,6 @@ const propTypes = {
/** Popover context menu anchor, used for showing context menu */
contextMenuAnchor: PropTypes.shape({current: PropTypes.elementType}),

/** Callback invoked when View Details is pressed */
onViewDetailsPressed: PropTypes.func,

/** Callback for updating context menu active state, used for showing context menu */
checkIfContextMenuActive: PropTypes.func,

Expand All @@ -89,7 +87,6 @@ const defaultProps = {
isHovered: false,
chatReport: {},
iouReport: {},
onViewDetailsPressed: () => {},
checkIfContextMenuActive: () => {},
session: {
email: null,
Expand All @@ -106,7 +103,9 @@ const ReportPreview = (props) => {
{_.map(props.action.message, (index) => (
<Pressable
key={`ReportPreview-${props.action.reportActionID}-${index}`}
onPress={props.onViewDetailsPressed}
onPress={() => {
Navigation.navigate(ROUTES.getReportRoute(props.iouReportID));
}}
onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
onLongPress={(event) => showContextMenuForReport(event, props.contextMenuAnchor, props.chatReportID, props.action, props.checkIfContextMenuActive)}
Expand Down
17 changes: 17 additions & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ function getSortedReportActions(reportActions, shouldSortInDescendingOrder = fal
if ((first.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED || second.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) && first.actionName !== second.actionName) {
return (first.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED ? -1 : 1) * invertedMultiplier;
}
// Ensure that `REPORTPREVIEW` actions always come after if they have the same timestamp as another action type
if ((first.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW || second.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW) && first.actionName !== second.actionName) {
return (first.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW ? 1 : -1) * invertedMultiplier;
}

// Then fallback on reportActionID as the final sorting criteria. It is a random number,
// but using this will ensure that the order of reportActions with the same created time and action type
Expand Down Expand Up @@ -333,6 +337,18 @@ function getLinkedTransactionID(reportID, reportActionID) {
return reportAction.originalMessage.IOUTransactionID;
}

/**
* @param {*} chatReportID
* @param {*} iouReportID
* @returns {Object} The report preview action or `null` if one couldn't be found
*/
function getReportPreviewAction(chatReportID, iouReportID) {
return _.find(
allReportActions[chatReportID],
(reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lodashGet(reportAction, 'originalMessage.linkedReportID') === iouReportID,
);
}

function isCreatedTaskReportAction(reportAction) {
return reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && _.has(reportAction.originalMessage, 'taskReportID');
}
Expand All @@ -351,6 +367,7 @@ export {
getLatestReportActionFromOnyxData,
isMoneyRequestAction,
getLinkedTransactionID,
getReportPreviewAction,
isCreatedTaskReportAction,
getParentReportAction,
isTransactionThread,
Expand Down
24 changes: 24 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,29 @@ function buildOptimisticIOUReportAction(type, amount, currency, comment, partici
};
}

function buildOptimisticReportPreview(reportID, iouReportID, payeeAccountID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing jsdoc. (Why lint is not failing here?)

return {
reportActionID: NumberUtils.rand64(),
reportID,
created: DateUtils.getDBTime(),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
accountID: payeeAccountID,
message: [
{
html: '',
text: '',
isEdited: false,
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
},
],
originalMessage: {
linkedReportID: iouReportID,
},
actorEmail: currentUserEmail,
};
}

function buildOptimisticTaskReportAction(taskReportID, actionName, message = '') {
const originalMessage = {
taskReportID,
Expand Down Expand Up @@ -2219,6 +2242,7 @@ export {
buildOptimisticIOUReport,
buildOptimisticExpenseReport,
buildOptimisticIOUReportAction,
buildOptimisticReportPreview,
buildOptimisticTaskReportAction,
buildOptimisticAddCommentReportAction,
buildOptimisticTaskCommentReportAction,
Expand Down
Loading