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

Fix - Distance request thumbnail is different in reports preview when created offline #39243

Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
087cbcd
implemented confirmed route for report preview
FitseTLT Mar 20, 2024
46ac65e
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Mar 28, 2024
cd70586
minor fixes
FitseTLT Mar 28, 2024
cbc5f9c
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Apr 8, 2024
4828b62
Changed empty state route pending icon
FitseTLT Apr 8, 2024
77e3ca4
add icon fill color
FitseTLT Apr 8, 2024
420850d
down sized icon for multiple previews
FitseTLT Apr 8, 2024
e16cde5
change ultra large icon size
FitseTLT Apr 9, 2024
3a7f04c
changed background color
FitseTLT Apr 9, 2024
fc8f34f
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Apr 10, 2024
85a48d7
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Apr 11, 2024
23d62ea
fix border radius
FitseTLT Apr 11, 2024
cd719c1
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Apr 12, 2024
bb3c43e
fixed border radius problem
FitseTLT Apr 12, 2024
0461c1f
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Apr 15, 2024
4026391
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Apr 19, 2024
649e85d
centralized map view display inside ReportActionItemImages
FitseTLT Apr 19, 2024
a96484f
added pending waypoints case to display map view
FitseTLT Apr 19, 2024
0cbef95
remove unnecessary condition
FitseTLT Apr 19, 2024
7e280da
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Apr 25, 2024
3c9d5bd
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Apr 25, 2024
d04f1a3
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 2, 2024
118f065
disable map interactiveness
FitseTLT May 2, 2024
17dbb41
changed variable name
FitseTLT May 2, 2024
de71096
changed variable name to isSmallerIcon
FitseTLT May 2, 2024
b2e5791
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 8, 2024
b0cb6bc
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 9, 2024
4460deb
remove redundant variable
FitseTLT May 9, 2024
95924c6
changed map pending subtitle color to supporting text
FitseTLT May 9, 2024
927e82f
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 13, 2024
b8612b8
minor fix
FitseTLT May 13, 2024
a6c6ebc
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 15, 2024
cba14d8
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 16, 2024
b988fe0
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 24, 2024
6f58d86
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 29, 2024
5bd900a
remove duplicate helper
FitseTLT May 29, 2024
f488ecb
remove dupe
FitseTLT May 29, 2024
aad7ac8
fix displaying map without route
FitseTLT May 29, 2024
e5f1df3
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 30, 2024
363d425
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT May 31, 2024
a3819ee
changed variable name
FitseTLT Jun 3, 2024
bc2fa19
Merge branch 'main' into fix-distance-request-thumbnail-mismatch
FitseTLT Jun 3, 2024
b288702
minor fix
FitseTLT Jun 3, 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
19 changes: 18 additions & 1 deletion assets/images/emptystate__routepending.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions src/components/BlockingViews/BlockingView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useMemo} from 'react';
import type {ImageSourcePropType, StyleProp, ViewStyle, WebStyle} from 'react-native';
import type {ImageSourcePropType, StyleProp, TextStyle, ViewStyle, WebStyle} from 'react-native';
import {View} from 'react-native';
import type {SvgProps} from 'react-native-svg';
import type {MergeExclusive} from 'type-fest';
Expand All @@ -22,6 +22,9 @@ type BaseBlockingViewProps = {
/** Subtitle message below the title */
subtitle?: string;

/** The style of the subtitle message */
subtitleStyle?: StyleProp<TextStyle>;

/** Link message below the subtitle */
linkKey?: TranslationPaths;

Expand Down Expand Up @@ -72,6 +75,7 @@ function BlockingView({
iconColor,
title,
subtitle = '',
subtitleStyle,
linkKey = 'notFound.goBackHome',
shouldShowLink = false,
iconWidth = variables.iconSizeSuperLarge,
Expand All @@ -89,7 +93,7 @@ function BlockingView({
() => (
<>
<AutoEmailLink
style={[styles.textAlignCenter]}
style={[styles.textAlignCenter, subtitleStyle]}
text={subtitle}
/>
{shouldShowLink ? (
Expand All @@ -102,7 +106,7 @@ function BlockingView({
) : null}
</>
),
[styles, subtitle, shouldShowLink, linkKey, onLinkPress, translate],
[styles, subtitle, shouldShowLink, linkKey, onLinkPress, translate, subtitleStyle],
);

const subtitleContent = useMemo(() => {
Expand Down
25 changes: 21 additions & 4 deletions src/components/ConfirmedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {ReactNode} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import useNetwork from '@hooks/useNetwork';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as TransactionUtils from '@libs/TransactionUtils';
Expand All @@ -27,17 +28,28 @@ type ConfirmedRouteProps = ConfirmedRoutePropsOnyxProps & {
/** Transaction that stores the distance expense data */
transaction: OnyxEntry<Transaction>;

/** Whether the size of the route pending icon is smaller. */
isSmallerIcon?: boolean;

/** Whether it should have border radius */
shouldHaveBorderRadius?: boolean;

/** Whether it should display the Mapbox map only when the route/coordinates exist otherwise
* it will display pending map icon */
shouldDisplayMapOnlyIfCoordinatesExist?: boolean;

FitseTLT marked this conversation as resolved.
Show resolved Hide resolved
/** Whether the map is interactable or not */
interactive?: boolean;
};

function ConfirmedRoute({mapboxAccessToken, transaction, interactive}: ConfirmedRouteProps) {
function ConfirmedRoute({mapboxAccessToken, transaction, isSmallerIcon, shouldHaveBorderRadius = true, shouldDisplayMapOnlyIfCoordinatesExist = false, interactive}: ConfirmedRouteProps) {
const {isOffline} = useNetwork();
const {route0: route} = transaction?.routes ?? {};
const waypoints = transaction?.comment?.waypoints ?? {};
const coordinates = route?.geometry?.coordinates ?? [];
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

const getMarkerComponent = useCallback(
(icon: IconAsset): ReactNode => (
Expand Down Expand Up @@ -90,7 +102,9 @@ function ConfirmedRoute({mapboxAccessToken, transaction, interactive}: Confirmed
return MapboxToken.stop;
}, []);

return !isOffline && Boolean(mapboxAccessToken?.token) ? (
const shouldDisplayMap = !shouldDisplayMapOnlyIfCoordinatesExist || (shouldDisplayMapOnlyIfCoordinatesExist && !!coordinates.length);
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved

return !isOffline && Boolean(mapboxAccessToken?.token) && shouldDisplayMap ? (
<DistanceMapView
interactive={interactive}
accessToken={mapboxAccessToken?.token ?? ''}
Expand All @@ -101,12 +115,15 @@ function ConfirmedRoute({mapboxAccessToken, transaction, interactive}: Confirmed
location: waypointMarkers?.[0]?.coordinate ?? (CONST.MAPBOX.DEFAULT_COORDINATE as [number, number]),
}}
directionCoordinates={coordinates as Array<[number, number]>}
style={[styles.mapView, styles.br4]}
style={[styles.mapView, shouldHaveBorderRadius && styles.br4]}
waypoints={waypointMarkers}
styleURL={CONST.MAPBOX.STYLE_URL}
/>
) : (
<PendingMapView />
<PendingMapView
isSmallerIcon={isSmallerIcon}
style={!shouldHaveBorderRadius && StyleUtils.getBorderRadiusStyle(0)}
/>
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/DistanceMapView/index.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Expensicons from '@components/Icon/Expensicons';
import MapView from '@components/MapView';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import type DistanceMapViewProps from './types';

Expand All @@ -13,6 +14,7 @@ function DistanceMapView({overlayStyle, ...rest}: DistanceMapViewProps) {
const [isMapReady, setIsMapReady] = useState(false);
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const theme = useTheme();

return (
<>
Expand All @@ -33,6 +35,7 @@ function DistanceMapView({overlayStyle, ...rest}: DistanceMapViewProps) {
title={translate('distance.mapPending.title')}
subtitle={isOffline ? translate('distance.mapPending.subtitle') : translate('distance.mapPending.onlineSubtitle')}
shouldShowLink={false}
iconColor={theme.border}
/>
</View>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/MapView/MapViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type PendingMapViewProps = {

/** Style applied to PendingMapView */
style?: StyleProp<ViewStyle>;

/** Whether the size of the route pending icon is smaller. */
isSmallerIcon?: boolean;
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
};

// Initial state of the map
Expand Down
12 changes: 9 additions & 3 deletions src/components/MapView/PendingMapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,34 @@ import {View} from 'react-native';
import BlockingView from '@components/BlockingViews/BlockingView';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import type {PendingMapViewProps} from './MapViewTypes';

function PendingMapView({title = '', subtitle = '', style}: PendingMapViewProps) {
function PendingMapView({title = '', subtitle = '', style, isSmallerIcon = false}: PendingMapViewProps) {
const hasTextContent = !_.isEmpty(title) || !_.isEmpty(subtitle);
const styles = useThemeStyles();
const theme = useTheme();
const iconSize = isSmallerIcon ? variables.iconSizeSuperLarge : variables.iconSizeUltraLarge;
return (
<View style={[styles.mapPendingView, style]}>
{hasTextContent ? (
<BlockingView
icon={Expensicons.EmptyStateRoutePending}
iconColor={theme.border}
title={title}
subtitle={subtitle}
subtitleStyle={styles.textSupporting}
shouldShowLink={false}
/>
) : (
<View style={[styles.flex1, styles.alignItemsCenter, styles.justifyContentCenter, styles.ph10]}>
<Icon
src={Expensicons.EmptyStateRoutePending}
width={variables.iconSizeUltraLarge}
height={variables.iconSizeUltraLarge}
width={iconSize}
height={iconSize}
fill={theme.border}
/>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import truncate from 'lodash/truncate';
import React, {useMemo} 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 {ReceiptScan} from '@components/Icon/Expensicons';
Expand Down Expand Up @@ -124,10 +123,7 @@ function MoneyRequestPreviewContent({
merchantOrDescription = description || '';
}

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

const hasPendingWaypoints = transaction?.pendingFields?.waypoints;
const showMapAsImage = isDistanceRequest && hasPendingWaypoints;
const receiptImages = hasReceipt ? [{...ReceiptUtils.getThumbnailAndImageURIs(transaction), transaction}] : [];

const getSettledMessage = (): string => {
if (isCardTransaction) {
Expand Down Expand Up @@ -254,15 +250,7 @@ function MoneyRequestPreviewContent({
!onPreviewPressed ? [styles.moneyRequestPreviewBox, containerStyles] : {},
]}
>
{showMapAsImage && (
<View style={styles.reportActionItemImages}>
<ConfirmedRoute
transaction={transaction}
interactive={false}
/>
</View>
)}
{!showMapAsImage && hasReceipt && (
{hasReceipt && (
<ReportActionItemImages
images={receiptImages}
isHovered={isHovered || isScanning}
Expand Down
37 changes: 13 additions & 24 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 @@ -119,8 +118,6 @@ 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 = Boolean(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 @@ -315,7 +312,6 @@ function MoneyRequestView({
</OfflineWithFeedback>
);

const shouldShowMapOrReceipt = showMapAsImage || hasReceipt;
const isReceiptAllowed = !isPaidReport && !isInvoice;
const shouldShowReceiptEmptyState =
isReceiptAllowed && !hasReceipt && !isApproved && !isSettled && (canEditReceipt || isAdmin || isApprover) && (canEditReceipt || ReportUtils.isPaidGroupPolicy(report));
Expand All @@ -329,7 +325,7 @@ function MoneyRequestView({
const receiptViolations =
transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? [];
const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report);
const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || shouldShowMapOrReceipt) && canUseViolations && ReportUtils.isPaidGroupPolicy(report);
const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt) && canUseViolations && ReportUtils.isPaidGroupPolicy(report);

return (
<View style={styles.pRelative}>
Expand All @@ -341,7 +337,7 @@ function MoneyRequestView({
shouldShowAuditMessage={Boolean(shouldShowNotesViolations && didRceiptScanSucceed)}
/>
)}
{shouldShowMapOrReceipt && (
{hasReceipt && (
<OfflineWithFeedback
pendingAction={pendingAction}
errors={transaction?.errorFields?.route ?? transaction?.errors}
Expand All @@ -354,23 +350,16 @@ function MoneyRequestView({
}}
>
<View style={styles.moneyRequestViewImage}>
{showMapAsImage ? (
<ConfirmedRoute
transaction={transaction}
interactive={false}
/>
) : (
<ReportActionItemImage
thumbnail={receiptURIs?.thumbnail}
fileExtension={receiptURIs?.fileExtension}
isThumbnail={receiptURIs?.isThumbnail}
image={receiptURIs?.image}
isLocalFile={receiptURIs?.isLocalFile}
filename={receiptURIs?.filename}
transaction={transaction}
enablePreviewModal
/>
)}
<ReportActionItemImage
thumbnail={receiptURIs?.thumbnail}
fileExtension={receiptURIs?.fileExtension}
isThumbnail={receiptURIs?.isThumbnail}
image={receiptURIs?.image}
isLocalFile={receiptURIs?.isLocalFile}
filename={receiptURIs?.filename}
transaction={transaction}
enablePreviewModal
/>
</View>
</OfflineWithFeedback>
)}
Expand All @@ -391,7 +380,7 @@ function MoneyRequestView({
}
/>
)}
{!shouldShowReceiptEmptyState && !shouldShowMapOrReceipt && <View style={{marginVertical: 6}} />}
{!shouldShowReceiptEmptyState && !hasReceipt && <View style={{marginVertical: 6}} />}
{shouldShowNotesViolations && <ReceiptAuditMessages notes={receiptViolations} />}
<OfflineWithFeedback pendingAction={getPendingFieldAction('amount')}>
<MenuItemWithTopDescription
Expand Down
Loading
Loading