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

Load map when image is not loaded in Money Request view for distance request #34133

Merged
merged 30 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dded634
test map when image is not loaded in request view
shubham1206agra Dec 19, 2023
6d619cb
Merge branch 'main' into test-map
shubham1206agra Jan 9, 2024
ef26aaa
test changes
shubham1206agra Jan 9, 2024
54a63d6
fix lint
shubham1206agra Jan 9, 2024
46141e3
fix lint
shubham1206agra Jan 9, 2024
a06f144
Merge branch 'Expensify:main' into test-map
shubham1206agra Jan 16, 2024
0d919bf
Merge branch 'Expensify:main' into test-map
shubham1206agra Jan 22, 2024
be5367f
ts fixes
shubham1206agra Jan 22, 2024
e255ec8
test fix
shubham1206agra Jan 22, 2024
17cb86a
test fix attempt 2
shubham1206agra Jan 22, 2024
c7165dd
test fix attempt 3
shubham1206agra Jan 22, 2024
b0068d3
perf-test fix
shubham1206agra Jan 22, 2024
365d379
perf-test fix attempt 2
shubham1206agra Jan 22, 2024
fb5a70e
perf-test fix attempt 3
shubham1206agra Jan 22, 2024
adb33f6
perf-test fix attempt 4
shubham1206agra Jan 23, 2024
94c115a
fix lint
shubham1206agra Jan 23, 2024
e9ab6ce
Merge branch 'Expensify:main' into test-map
shubham1206agra Jan 23, 2024
3d8adec
Merge branch 'main' into test-map
shubham1206agra Jan 30, 2024
353bb6a
Merge branch 'main' into test-map
shubham1206agra Jan 31, 2024
0555ddf
Merge branch 'Expensify:main' into test-map
shubham1206agra Feb 1, 2024
18d755d
adjustment according to recommendation
shubham1206agra Feb 1, 2024
3fe850f
merge main
shubham1206agra Feb 3, 2024
b8b9f4e
merge main
shubham1206agra Feb 3, 2024
fdd2b88
fix lint
shubham1206agra Feb 3, 2024
262f9a3
merge main
shubham1206agra Feb 7, 2024
58fd979
ts fix
shubham1206agra Feb 7, 2024
e371877
Merge branch 'main' into test-map
shubham1206agra Feb 9, 2024
3021f36
Fix ts bug
shubham1206agra Feb 9, 2024
1336664
Fix minor bug after merge
shubham1206agra Feb 9, 2024
2f31293
Merge main
shubham1206agra Feb 20, 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 jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
`<rootDir>/?(*.)+(spec|test).${testFileExtension}`,
],
transform: {
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.[jt]sx?$': 'babel-jest',
'^.+\\.svg?$': 'jest-transformer-svg',
},
transformIgnorePatterns: ['<rootDir>/node_modules/(?!react-native)/'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import lodashSortBy from 'lodash/sortBy';
import React from 'react';
import {View} from 'react-native';
import type {GestureResponderEvent} from 'react-native';
import ConfirmedRoute from '@components/ConfirmedRoute';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import MoneyRequestSkeletonView from '@components/MoneyRequestSkeletonView';
Expand Down Expand Up @@ -114,6 +115,9 @@ function MoneyRequestPreviewContent({

const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(transaction)] : [];

const hasPendingWaypoints = transaction?.pendingFields?.waypoints;
const showMapAsImage = isDistanceRequest && hasPendingWaypoints;

const getSettledMessage = (): string => {
if (isCardTransaction) {
return translate('common.done');
Expand Down Expand Up @@ -206,7 +210,12 @@ function MoneyRequestPreviewContent({
!onPreviewPressed ? [styles.moneyRequestPreviewBox, containerStyles] : {},
]}
>
{hasReceipt && (
{showMapAsImage && (
<View style={styles.reportActionItemImages}>
<ConfirmedRoute transaction={transaction} />
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 #40318, we should've prevented interactivity here to avoid the map being movable whilst still loading.

</View>
)}
{!showMapAsImage && hasReceipt && (
<ReportActionItemImages
images={receiptImages}
isHovered={isHovered || isScanning}
Expand Down
28 changes: 18 additions & 10 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import ConfirmedRoute from '@components/ConfirmedRoute';
import * as Expensicons from '@components/Icon/Expensicons';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand Down Expand Up @@ -109,6 +110,8 @@ function MoneyRequestView({
const isEmptyMerchant = transactionMerchant === '' || transactionMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : '';
const hasPendingWaypoints = transaction?.pendingFields?.waypoints;
const showMapAsImage = isDistanceRequest && hasPendingWaypoints;
const formattedOriginalAmount = transactionOriginalAmount && transactionOriginalCurrency && CurrencyUtils.convertToDisplayString(transactionOriginalAmount, transactionOriginalCurrency);
const isCardTransaction = TransactionUtils.isCardTransaction(transaction);
const cardProgramName = isCardTransaction && transactionCardID !== undefined ? CardUtils.getCardDescription(transactionCardID) : '';
Expand Down Expand Up @@ -239,7 +242,8 @@ function MoneyRequestView({
<View style={[StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth)]}>
<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(isSmallScreenWidth)]}>
{hasReceipt && (
{/* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing */}
{(showMapAsImage || hasReceipt) && (
<OfflineWithFeedback
pendingAction={pendingAction}
errors={transaction?.errors}
Expand All @@ -252,15 +256,19 @@ function MoneyRequestView({
}}
>
<View style={styles.moneyRequestViewImage}>
<ReportActionItemImage
thumbnail={receiptURIs?.thumbnail}
image={receiptURIs?.image}
isLocalFile={receiptURIs?.isLocalFile}
filename={receiptURIs?.filename}
transaction={transaction}
enablePreviewModal
canEditReceipt={canEditReceipt}
/>
{showMapAsImage ? (
<ConfirmedRoute transaction={transaction} />
) : (
<ReportActionItemImage
thumbnail={receiptURIs?.thumbnail}
image={receiptURIs?.image}
isLocalFile={receiptURIs?.isLocalFile}
filename={receiptURIs?.filename}
transaction={transaction}
enablePreviewModal
canEditReceipt={canEditReceipt}
/>
)}
</View>
</OfflineWithFeedback>
)}
Expand Down
8 changes: 8 additions & 0 deletions src/components/__mocks__/ConfirmedRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {View} from 'react-native';

// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
function ConfirmedRoute(props: any) {
return <View />;
}
Comment on lines +3 to +6
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of this empty view mock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just to pass the UI tests, as Mapbox seems to break the tests.


export default ConfirmedRoute;
5 changes: 4 additions & 1 deletion src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {RecentWaypoint, Report, ReportAction, Transaction, TransactionViolation} from '@src/types/onyx';
import type {PolicyTaxRate, PolicyTaxRates} from '@src/types/onyx/PolicyTaxRates';
import type {Comment, Receipt, TransactionChanges, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
import type {Comment, Receipt, TransactionChanges, TransactionPendingFieldsKey, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {isCorporateCard, isExpensifyCard} from './CardUtils';
import DateUtils from './DateUtils';
import * as NumberUtils from './NumberUtils';
Expand Down Expand Up @@ -94,6 +95,7 @@ function buildOptimisticTransaction(
category = '',
tag = '',
billable = false,
pendingFields: Partial<{[K in TransactionPendingFieldsKey]: ValueOf<typeof CONST.RED_BRICK_ROAD_PENDING_ACTION>}> | undefined = undefined,
): Transaction {
// transactionIDs are random, positive, 64-bit numeric strings.
// Because JS can only handle 53-bit numbers, transactionIDs are strings in the front-end (just like reportActionID)
Expand All @@ -108,6 +110,7 @@ function buildOptimisticTransaction(
}

return {
...(!isEmptyObject(pendingFields) ? {pendingFields} : {}),
transactionID,
amount,
currency,
Expand Down
6 changes: 4 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ function getMoneyRequestInformation(
receiptObject.state = receipt.state ?? CONST.IOU.RECEIPT_STATE.SCANREADY;
filename = receipt.name;
}
const existingTransaction = allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`];
const isDistanceRequest = existingTransaction && existingTransaction.iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE;
let optimisticTransaction = TransactionUtils.buildOptimisticTransaction(
ReportUtils.isExpenseReport(iouReport) ? -amount : amount,
currency,
Expand All @@ -804,6 +806,7 @@ function getMoneyRequestInformation(
category,
tag,
billable,
isDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : undefined,
);

const optimisticPolicyRecentlyUsedCategories = Policy.buildOptimisticPolicyRecentlyUsedCategories(iouReport.policyID, category);
Expand All @@ -814,8 +817,7 @@ function getMoneyRequestInformation(
// data. This is a big can of worms to change it to `Onyx.merge()` as explored in https://expensify.slack.com/archives/C05DWUDHVK7/p1692139468252109.
// I want to clean this up at some point, but it's possible this will live in the code for a while so I've created https://github.com/Expensify/App/issues/25417
// to remind me to do this.
const existingTransaction = allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`];
if (existingTransaction && existingTransaction.iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE) {
if (isDistanceRequest) {
optimisticTransaction = fastMerge(existingTransaction, optimisticTransaction, false);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/perf-test/ReportActionsList.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jest.mock('@react-navigation/native', () => {
};
});

jest.mock('../../src/components/ConfirmedRoute.tsx');

beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
Expand Down
2 changes: 2 additions & 0 deletions tests/perf-test/ReportScreen.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jest.mock('react-native-reanimated', () => ({
useAnimatedRef: jest.fn,
}));

jest.mock('../../src/components/ConfirmedRoute.tsx');

jest.mock('../../src/components/withNavigationFocus', () => (Component) => {
function WithNavigationFocus(props) {
return (
Expand Down
1 change: 1 addition & 0 deletions tests/ui/UnreadIndicatorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jest.setTimeout(30000);

jest.mock('../../src/libs/Notification/LocalNotification');
jest.mock('../../src/components/Icon/Expensicons');
jest.mock('../../src/components/ConfirmedRoute.tsx');

// Needed for: https://stackoverflow.com/questions/76903168/mocking-libraries-in-jest
jest.mock('react-native/Libraries/LogBox/LogBox', () => ({
Expand Down
Loading