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

[TS migration] Migrate 'ReportActionItemMoneyRequest' component to TypeScript #34564

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a56bce1
Migrate MoneyRequestAction to TypeScript
VickyStash Jan 15, 2024
0f627ba
Migrate MoneyRequestPreview to TypeScript
VickyStash Jan 16, 2024
02296e8
Migrate MoneyRequestView to TypeScript
VickyStash Jan 16, 2024
6b8c3a3
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 16, 2024
03a0c4c
Fix lint errors
VickyStash Jan 16, 2024
7a64f0c
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 16, 2024
6c8137a
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 17, 2024
6637583
Use ContextMenuAnchor type for anchor typing
VickyStash Jan 17, 2024
e1e39e1
Code improvements
VickyStash Jan 17, 2024
ccef5e0
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 18, 2024
fb3f8d1
Update getDisplayDeleteAmountText function, move transactionViolation…
VickyStash Jan 18, 2024
60d8105
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 19, 2024
69a4df4
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 22, 2024
be37558
TS fixes after merging main
VickyStash Jan 22, 2024
c8438bf
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 23, 2024
01fa104
Fix TS issues
VickyStash Jan 23, 2024
f65fbe0
Update image typing
VickyStash Jan 23, 2024
73e5685
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 25, 2024
696f337
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 26, 2024
c07a39e
TS fixes after merging OptionsListUtils migration
VickyStash Jan 26, 2024
a5f3dba
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 26, 2024
eb4631e
TS fixes after merging main
VickyStash Jan 26, 2024
8b9bac8
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 29, 2024
00c5436
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 30, 2024
15cffe2
Fix Onyx types import
VickyStash Jan 30, 2024
dedfe12
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Jan 31, 2024
e7ff217
Fix TS issues after merging main
VickyStash Jan 31, 2024
5e1e232
Merge branch 'main' into ts-migration/reportActionItemMoneyRequest-co…
VickyStash Feb 2, 2024
d3f64c9
Retry performance test
VickyStash Feb 2, 2024
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
3 changes: 2 additions & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ type OnyxValues = {
[ONYXKEYS.COLLECTION.DOWNLOAD]: OnyxTypes.Download;
[ONYXKEYS.COLLECTION.POLICY]: OnyxTypes.Policy;
[ONYXKEYS.COLLECTION.POLICY_DRAFTS]: OnyxTypes.Policy;
[ONYXKEYS.COLLECTION.POLICY_CATEGORIES]: OnyxTypes.PolicyCategory;
[ONYXKEYS.COLLECTION.POLICY_CATEGORIES]: OnyxTypes.PolicyCategories;
[ONYXKEYS.COLLECTION.POLICY_TAGS]: OnyxTypes.PolicyTags;
[ONYXKEYS.COLLECTION.POLICY_MEMBERS]: OnyxTypes.PolicyMembers;
[ONYXKEYS.COLLECTION.POLICY_MEMBERS_DRAFTS]: OnyxTypes.PolicyMember;
Expand All @@ -459,6 +459,7 @@ type OnyxValues = {
[ONYXKEYS.COLLECTION.SECURITY_GROUP]: OnyxTypes.SecurityGroup;
[ONYXKEYS.COLLECTION.TRANSACTION]: OnyxTypes.Transaction;
[ONYXKEYS.COLLECTION.TRANSACTION_DRAFT]: OnyxTypes.Transaction;
[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS]: OnyxTypes.TransactionViolations;
[ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS]: OnyxTypes.RecentlyUsedTags;
[ONYXKEYS.COLLECTION.SELECTED_TAB]: string;
[ONYXKEYS.COLLECTION.PRIVATE_NOTES_DRAFT]: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ type MenuItemProps = (IconProps | AvatarProps | NoIcon) & {
shouldBlockSelection?: boolean;

/** Whether should render title as HTML or as Text */
shouldParseTitle?: false;
shouldParseTitle?: boolean;

/** Should check anonymous user in onPress function */
shouldCheckActionAllowedOnPress?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pressable/GenericPressable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type PressableProps = RNPressableProps &
/**
* onPress callback
*/
onPress: (event?: GestureResponderEvent | KeyboardEvent) => void | Promise<void>;
onPress: ((event?: GestureResponderEvent | KeyboardEvent) => void | Promise<void>) | undefined;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved

/**
* Specifies keyboard shortcut to trigger onPressHandler
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pressable/PressableWithDelayToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function PressableWithDelayToggle(
return;
}
temporarilyDisableInteractions();
onPress();
onPress?.();
};

// Due to limitations in RN regarding the vertical text alignment of non-Text elements,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pressable/PressableWithoutFocus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function PressableWithoutFocus({children, onPress, onLongPress, ...rest}: Pressa

const pressAndBlur = () => {
ref?.current?.blur();
onPress();
onPress?.();
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,63 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import networkPropTypes from '@components/networkPropTypes';
import {withNetwork} from '@components/OnyxProvider';
import refPropTypes from '@components/refPropTypes';
import type {OnyxEntry} from 'react-native-onyx/lib/types';
import RenderHTML from '@components/RenderHTML';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import compose from '@libs/compose';
import * as IOUUtils from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import reportActionPropTypes from '@pages/home/report/reportActionPropTypes';
import iouReportPropTypes from '@pages/iouReportPropTypes';
import reportPropTypes from '@pages/reportPropTypes';
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import * as Report from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import MoneyRequestPreview from './MoneyRequestPreview';

const propTypes = {
type MoneyRequestActionOnyxProps = {
/** Chat report associated with iouReport */
chatReport: OnyxEntry<OnyxTypes.Report>;

/** IOU report data object */
iouReport: OnyxEntry<OnyxTypes.Report>;

/** Report actions for this report */
reportActions: OnyxEntry<OnyxTypes.ReportActions>;
};

type MoneyRequestActionProps = MoneyRequestActionOnyxProps & {
/** All the data of the action */
action: PropTypes.shape(reportActionPropTypes).isRequired,
action: OnyxTypes.ReportAction;

/** The ID of the associated chatReport */
chatReportID: PropTypes.string.isRequired,
chatReportID: string;

/** The ID of the associated request report */
requestReportID: PropTypes.string.isRequired,
requestReportID: string;

/** Is this IOUACTION the most recent? */
isMostRecentIOUReportAction: PropTypes.bool.isRequired,
isMostRecentIOUReportAction: boolean;

/** Popover context menu anchor, used for showing context menu */
contextMenuAnchor: refPropTypes,
contextMenuAnchor?: ContextMenuAnchor;

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

/* Onyx Props */
/** chatReport associated with iouReport */
chatReport: reportPropTypes,

/** IOU report data object */
iouReport: iouReportPropTypes,

/** Array of report actions for this report */
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
checkIfContextMenuActive?: () => void;

/** Whether the IOU is hovered so we can modify its style */
isHovered: PropTypes.bool,

network: networkPropTypes.isRequired,
isHovered?: boolean;

/** Whether a message is a whisper */
isWhisper: PropTypes.bool,
isWhisper?: boolean;

/** Styles to be assigned to Container */
// eslint-disable-next-line react/forbid-prop-types
style: PropTypes.arrayOf(PropTypes.object),
};

const defaultProps = {
contextMenuAnchor: undefined,
checkIfContextMenuActive: () => {},
chatReport: {},
iouReport: {},
reportActions: {},
isHovered: false,
style: [],
isWhisper: false,
style?: StyleProp<ViewStyle>;
};

function MoneyRequestAction({
Expand All @@ -83,31 +66,32 @@ function MoneyRequestAction({
requestReportID,
isMostRecentIOUReportAction,
contextMenuAnchor,
checkIfContextMenuActive,
checkIfContextMenuActive = () => {},
chatReport,
iouReport,
reportActions,
isHovered,
network,
isHovered = false,
style,
isWhisper,
}) {
isWhisper = false,
}: MoneyRequestActionProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const isSplitBillAction = lodashGet(action, 'originalMessage.type', '') === CONST.IOU.REPORT_ACTION_TYPE.SPLIT;
const {isOffline} = useNetwork();

const isSplitBillAction = action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT;

const onMoneyRequestPreviewPressed = () => {
if (isSplitBillAction) {
const reportActionID = lodashGet(action, 'reportActionID', '0');
const reportActionID = action.reportActionID ?? '0';
Navigation.navigate(ROUTES.SPLIT_BILL_DETAILS.getRoute(chatReportID, reportActionID));
return;
}

// If the childReportID is not present, we need to create a new thread
const childReportID = lodashGet(action, 'childReportID', 0);
const childReportID = action?.childReportID ?? '0';
if (!childReportID) {
Copy link
Contributor

@youssef-lr youssef-lr Feb 6, 2024

Choose a reason for hiding this comment

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

@VickyStash heads up! All IDs must be numbers, this created this bug #35904. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

accountIDs are numbers and reportIDs are strings, right? 🤔

Copy link
Contributor

@aldo-expensify aldo-expensify Feb 6, 2024

Choose a reason for hiding this comment

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

@youssef-lr reportIDs are expected to be string, otherwise they can overflow, right?
Unless this changed lately

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah sorry my bad, they are all numbers in the backend, but in JS reportIDs & reportActionIDs are strings. In this specific example it doesn't make sense to use '0', because the condition below this line evaluates to false when it should evaluate to true if (!childReportID) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@youssef-lr you are right, my bad!

Copy link
Contributor

@aldo-expensify aldo-expensify Feb 6, 2024

Choose a reason for hiding this comment

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

Commented in your PR @youssef-lr , I don't think we should default to 0 either

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that sounds good, updated.

const thread = ReportUtils.buildTransactionThread(action, requestReportID);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs ?? []);
Report.openReport(thread.reportID, userLogins, thread, action.reportActionID);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(thread.reportID));
return;
Expand All @@ -120,12 +104,12 @@ function MoneyRequestAction({
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(action);
const isReversedTransaction = ReportActionsUtils.isReversedTransaction(action);
if (
!_.isEmpty(iouReport) &&
!_.isEmpty(reportActions) &&
chatReport.iouReportID &&
!isEmptyObject(iouReport) &&
!isEmptyObject(reportActions) &&
chatReport?.iouReportID &&
isMostRecentIOUReportAction &&
action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD &&
network.isOffline
isOffline
) {
shouldShowPendingConversionMessage = IOUUtils.isIOUReportPendingCurrencyConversion(iouReport);
}
Expand All @@ -142,29 +126,24 @@ function MoneyRequestAction({
checkIfContextMenuActive={checkIfContextMenuActive}
shouldShowPendingConversionMessage={shouldShowPendingConversionMessage}
onPreviewPressed={onMoneyRequestPreviewPressed}
containerStyles={[styles.cursorPointer, isHovered ? styles.reportPreviewBoxHoverBorder : undefined, ...style]}
containerStyles={[styles.cursorPointer, isHovered ? styles.reportPreviewBoxHoverBorder : undefined, style]}
isHovered={isHovered}
isWhisper={isWhisper}
/>
);
}

MoneyRequestAction.propTypes = propTypes;
MoneyRequestAction.defaultProps = defaultProps;
MoneyRequestAction.displayName = 'MoneyRequestAction';

export default compose(
withOnyx({
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
},
iouReport: {
key: ({requestReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${requestReportID}`,
},
reportActions: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`,
canEvict: false,
},
}),
withNetwork(),
)(MoneyRequestAction);
export default withOnyx<MoneyRequestActionProps, MoneyRequestActionOnyxProps>({
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
},
iouReport: {
key: ({requestReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${requestReportID}`,
},
reportActions: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`,
canEvict: false,
},
})(MoneyRequestAction);
Loading
Loading