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 'IOUWaypoint' page to TypeScript #33244

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
dde6aca
chore: move IOUWaypoint Pages to TS
kubabutkiewicz Dec 18, 2023
36c73ed
ref: seperate types
kubabutkiewicz Dec 18, 2023
a32e718
chore: added todos
kubabutkiewicz Dec 20, 2023
1d1f0fa
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Dec 20, 2023
049e7ad
fix: address comments
kubabutkiewicz Dec 20, 2023
2a75175
fix: adjust recentwaypoint type
kubabutkiewicz Dec 21, 2023
437636a
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 2, 2024
9b36c85
fix: type problems
kubabutkiewicz Jan 2, 2024
3a448bb
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 3, 2024
7f463df
fix: resolve comments
kubabutkiewicz Jan 3, 2024
26ee70c
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 8, 2024
72b7efb
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 15, 2024
02dbc36
fix: move changes to new file
kubabutkiewicz Jan 15, 2024
e6164a2
fix: type errors
kubabutkiewicz Jan 15, 2024
f8c1cc4
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 15, 2024
b399f8a
fix: types
kubabutkiewicz Jan 15, 2024
4755a0f
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 18, 2024
374a4a3
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 22, 2024
5adf756
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 31, 2024
bfb8b43
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 2, 2024
5190bd1
fix: typecheck
kubabutkiewicz Feb 2, 2024
4bcf243
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 2, 2024
c232f39
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 5, 2024
bf8e335
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 6, 2024
2deb942
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 6, 2024
e945840
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 7, 2024
490c77a
fix: typecheck
kubabutkiewicz Feb 7, 2024
ce58b9d
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 8, 2024
040a383
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 13, 2024
61a2595
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 14, 2024
7a7baf9
fix: typecheck
kubabutkiewicz Feb 14, 2024
75073fe
fix: typecheck
kubabutkiewicz Feb 14, 2024
59a03f9
fix: typecheck
kubabutkiewicz Feb 14, 2024
3aea0ef
fix: when searching for waypoint
kubabutkiewicz Feb 14, 2024
b94ab89
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 15, 2024
f600f67
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 15, 2024
0f84798
fix: ci
kubabutkiewicz Feb 15, 2024
e60d866
fix: removed podfile.lock and gemfile
kubabutkiewicz Feb 20, 2024
567d0a7
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 20, 2024
73d0864
fix: revert changes to Gemfile.lock
kubabutkiewicz Feb 20, 2024
28eacfe
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 22, 2024
e34ae0b
fix: resolve comments
kubabutkiewicz Feb 22, 2024
1ff718c
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 23, 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
2 changes: 1 addition & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,4 @@ type RouteIsPlainString = IsEqual<AllRoutes, string>;
*/
type Route = RouteIsPlainString extends true ? never : AllRoutes;

export type {Route};
export type {Route, AllRoutes};
9 changes: 6 additions & 3 deletions src/hooks/useLocationBias.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import type {Location} from '@pages/iou/request/step/IOURequestStepWaypoint';
import type {UserLocation} from '@src/types/onyx';

/**
* Construct the rectangular boundary based on user location and waypoints
*/
export default function useLocationBias(allWaypoints: Record<string, {lng?: number; lat?: number}>, userLocation?: {latitude: number; longitude: number}) {
export default function useLocationBias(allWaypoints: Record<string, Location>, userLocation?: OnyxEntry<UserLocation>) {
return useMemo(() => {
const hasFilledWaypointCount = Object.values(allWaypoints).some((waypoint) => Object.keys(waypoint).length > 0);
// If there are no filled wayPoints and if user's current location cannot be retrieved,
Expand All @@ -29,8 +32,8 @@ export default function useLocationBias(allWaypoints: Record<string, {lng?: numb
// When no filled waypoints are available but the current location of the user is available,
// let us consider the current user's location to construct a rectangular bound
if (!hasFilledWaypointCount && userLocation !== undefined) {
longitudes.push(userLocation.longitude);
latitudes.push(userLocation.latitude);
longitudes.push(userLocation?.longitude ?? 0);
latitudes.push(userLocation?.latitude ?? 0);
}

// Extend the rectangular bound by 0.5 degree (roughly around 25-30 miles in US)
Expand Down
1 change: 1 addition & 0 deletions src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ function addErrorMessage<TKey extends TranslationPaths>(errors: ErrorsList, inpu
}

export {getAuthenticateErrorMessage, getMicroSecondOnyxError, getMicroSecondOnyxErrorObject, getLatestErrorMessage, getLatestErrorField, getEarliestErrorField, addErrorMessage};
export type {ErrorsList};
7 changes: 7 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ type MoneyRequestNavigatorParamList = {
reportID: string;
backTo: string;
};
[SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: {
iouType: ValueOf<typeof CONST.IOU.TYPE>;
reportID: string;
backTo: Routes | undefined;
action: ValueOf<typeof CONST.IOU.ACTION>;
pageIndex: string;
};
[SCREENS.MONEY_REQUEST.MERCHANT]: {
iouType: string;
reportID: string;
Expand Down
13 changes: 9 additions & 4 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {isEqual} from 'lodash';
import lodashClone from 'lodash/clone';
import lodashHas from 'lodash/has';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import * as CollectionUtils from '@libs/CollectionUtils';
Expand Down Expand Up @@ -100,7 +101,10 @@ function saveWaypoint(transactionID: string, index: string, waypoint: RecentWayp
}
}

function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft: boolean) {
function removeWaypoint(transaction: OnyxEntry<Transaction>, currentIndex: string, isDraft?: boolean) {
if (!transaction) {
return;
}
// Index comes from the route params and is a string
const index = Number(currentIndex);
const existingWaypoints = transaction?.comment?.waypoints ?? {};
Expand Down Expand Up @@ -128,9 +132,10 @@ function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft:
// to remove nested keys while also preserving other object keys
// Doing a deep clone of the transaction to avoid mutating the original object and running into a cache issue when using Onyx.set
let newTransaction: Transaction = {
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
...transaction,
comment: {
...transaction.comment,
...transaction?.comment,
waypoints: reIndexedWaypoints,
},
amount: CONST.IOU.DEFAULT_AMOUNT,
Expand All @@ -155,10 +160,10 @@ function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft:
};
}
if (isDraft) {
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, newTransaction);
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction?.transactionID}`, newTransaction);
return;
}
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, newTransaction);
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction?.transactionID}`, newTransaction);
MonilBhavsar marked this conversation as resolved.
Show resolved Hide resolved
}

function getOnyxDataForRouteRequest(transactionID: string, isDraft = false): OnyxData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
import PropTypes from 'prop-types';
import type {StackScreenProps} from '@react-navigation/stack';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import type {MoneyRequestNavigatorParamList} from '@libs/Navigation/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import IOURequestStepWaypoint from './request/step/IOURequestStepWaypoint';

const propTypes = {
/** The transactionID of this request */
transactionID: PropTypes.string,

/** Route params */
route: PropTypes.shape({
params: PropTypes.shape({
/** IOU type */
iouType: PropTypes.string,

/** Index of the waypoint being edited */
waypointIndex: PropTypes.string,
}),
}),
};

const defaultProps = {
transactionID: '',
route: {
params: {
iouType: '',
waypointIndex: '',
},
},
type MoneyRequestWaypointPageOnyxProps = {
transactionID: string | undefined;
};
type MoneyRequestWaypointPageProps = StackScreenProps<MoneyRequestNavigatorParamList, typeof SCREENS.MONEY_REQUEST.STEP_WAYPOINT> & MoneyRequestWaypointPageOnyxProps;

// This component is responsible for grabbing the transactionID from the IOU key
// You can't use Onyx props in the withOnyx mapping, so we need to set up and access the transactionID here, and then pass it down so that WaypointEditor can subscribe to the transaction.
function MoneyRequestWaypointPage({transactionID, route}) {
function MoneyRequestWaypointPage({transactionID = '', route}: MoneyRequestWaypointPageProps) {
return (
// @ts-expect-error TODO: Remove this once withFullTransactionOrNotFound is migrated to TypeScript.
<IOURequestStepWaypoint
Copy link
Contributor

Choose a reason for hiding this comment

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

Link the issue if it exists (same for other comments)

Suggested change
// @ts-expect-error TODO: Remove this once withFullTransactionOrNotFound is migrated to TypeScript.
// @ts-expect-error TODO: Remove this once withFullTransactionOrNotFound is migrated to TypeScript.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are no issues, at least in spreadsheet
image

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 Let's remove todo and link issue. Here is the issue #36123
Also can you please comment there so whoever picks up can clean this up.

// Put the transactionID into the route params so that WaypointEdit behaves the same when creating a new waypoint
// or editing an existing waypoint.
Expand All @@ -48,8 +30,7 @@ function MoneyRequestWaypointPage({transactionID, route}) {
}

MoneyRequestWaypointPage.displayName = 'MoneyRequestWaypointPage';
MoneyRequestWaypointPage.propTypes = propTypes;
MoneyRequestWaypointPage.defaultProps = defaultProps;
export default withOnyx({
transactionID: {key: ONYXKEYS.IOU, selector: (iou) => iou && iou.transactionID},

export default withOnyx<MoneyRequestWaypointPageProps, MoneyRequestWaypointPageOnyxProps>({
transactionID: {key: ONYXKEYS.IOU, selector: (iou) => iou?.transactionID},
})(MoneyRequestWaypointPage);
Loading
Loading