Skip to content

[CP Staging] [Better Expense Reports]: Fix disabled arrow function #61840

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

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,7 @@ const CONST = {
},
RESERVED_ROOM_NAMES: ['#admins', '#announce'],
MAX_PREVIEW_AVATARS: 4,
TRANSACTION_PREVIEW_WIDTH_WIDE: 303,
MAX_ROOM_NAME_LENGTH: 99,
LAST_MESSAGE_TEXT_MAX_LENGTH: 200,
MIN_LENGTH_LAST_MESSAGE_WITH_ELLIPSIS: 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function MoneyRequestReportPreviewContent({
lastTransactionViolations,
isDelegateAccessRestricted,
renderTransactionItem,
onLayout,
onCarouselLayout,
onWrapperLayout,
currentWidth,
reportPreviewStyles,
shouldDisplayContextMenu = true,
Expand Down Expand Up @@ -409,7 +410,10 @@ function MoneyRequestReportPreviewContent({
};

// The button should expand up to transaction width
const buttonMaxWidth = !shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewStyle.width >= 303 ? {maxWidth: reportPreviewStyles.transactionPreviewStyle.width} : {};
const buttonMaxWidth =
!shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewStyle.width >= CONST.REPORT.TRANSACTION_PREVIEW_WIDTH_WIDE
? {maxWidth: reportPreviewStyles.transactionPreviewStyle.width}
: {};

const approvedOrSettledIcon = (iouSettled || isApproved) && (
<ImageSVG
Expand Down Expand Up @@ -575,14 +579,17 @@ function MoneyRequestReportPreviewContent({
};

return (
<View onLayout={onLayout}>
<View onLayout={onWrapperLayout}>
<OfflineWithFeedback
pendingAction={iouReport?.pendingFields?.preview}
shouldDisableOpacity={!!(action.pendingAction ?? action.isOptimisticAction)}
needsOffscreenAlphaCompositing
style={styles.mt1}
>
<View style={[styles.chatItemMessage, containerStyles]}>
<View
style={[styles.chatItemMessage, containerStyles]}
onLayout={onCarouselLayout}
>
<PressableWithoutFeedback
onPress={onPress}
onPressIn={() => canUseTouchScreen() && ControlSelection.block()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ function MoneyRequestReportPreview({
const isTrackExpenseAction = isTrackExpenseActionReportActionsUtils(action);
const isSplitBillAction = isSplitBillActionReportActionsUtils(action);
const [currentWidth, setCurrentWidth] = useState(256);
const [currentWrapperWidth, setCurrentWrapperWidth] = useState(256);
const reportPreviewStyles = useMemo(
() => StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, currentWidth, transactions.length === 1),
[StyleUtils, currentWidth, shouldUseNarrowLayout, transactions.length],
() => StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, currentWidth, currentWrapperWidth, transactions.length === 1),
[StyleUtils, currentWidth, currentWrapperWidth, shouldUseNarrowLayout, transactions.length],
);

const shouldShowIOUData = useMemo(() => {
Expand Down Expand Up @@ -127,9 +128,12 @@ function MoneyRequestReportPreview({
lastTransactionViolations={lastTransactionViolations}
isDelegateAccessRestricted={isDelegateAccessRestricted}
renderTransactionItem={renderItem}
onLayout={(e: LayoutChangeEvent) => {
onCarouselLayout={(e: LayoutChangeEvent) => {
setCurrentWidth(e.nativeEvent.layout.width ?? 255);
}}
onWrapperLayout={(e: LayoutChangeEvent) => {
setCurrentWrapperWidth(e.nativeEvent.layout.width ?? 255);
}}
currentWidth={currentWidth}
reportPreviewStyles={reportPreviewStyles}
shouldDisplayContextMenu={shouldDisplayContextMenu}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ type MoneyRequestReportPreviewContentProps = MoneyRequestReportPreviewContentOny
/** MoneyRequestReportPreview's current width */
currentWidth: number;

/** Callback passed to onLayout */
onLayout: (e: LayoutChangeEvent) => void;
/** Callback passed to Carousel's onLayout */
onCarouselLayout: (e: LayoutChangeEvent) => void;

/** Callback passed to Component wrapper view's onLayout */
onWrapperLayout: (e: LayoutChangeEvent) => void;

/** Callback to render a transaction preview item */
renderTransactionItem: ListRenderItem<Transaction>;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ function PureReportActionItem({
[StyleUtils, isReportActionLinked, theme.messageHighlightBG],
);

const reportPreviewStyles = StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, undefined, true);
const reportPreviewStyles = StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, undefined, undefined, true);

const isDeletedParentAction = isDeletedParentActionUtils(action);

Expand Down
2 changes: 1 addition & 1 deletion src/stories/MoneyRequestReportPreview.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const mockTransactionsBig = Array.from({length: 12}).map((item, index) => {
return {...transactionR14932, transactionID: `${transactionR14932.transactionID}${index}`};
});

const reportPreviewStyle = getMoneyRequestReportPreviewStyle(false, 400, false);
const reportPreviewStyle = getMoneyRequestReportPreviewStyle(false, 400, 400, false);

const mockRenderItem: ListRenderItem<Transaction> = ({item}) => (
<TransactionPreviewContent
Expand Down
18 changes: 12 additions & 6 deletions src/styles/utils/getMoneyRequestReportPreviewStyle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {MoneyRequestReportPreviewStyleType} from '@components/ReportActionI
import sizing from '@styles/utils/sizing';
// eslint-disable-next-line no-restricted-imports
import spacing from '@styles/utils/spacing';
import CONST from '@src/CONST';

const componentsSpacing = {
flatListStyle: [spacing.mhn4],
Expand All @@ -11,7 +12,7 @@ const componentsSpacing = {
};

const NEXT_TRANSACTION_PEEK = 32;
const TRANSACTION_WIDTH_WIDE = 303;
const TRANSACTION_WIDTH_WIDE = CONST.REPORT.TRANSACTION_PREVIEW_WIDTH_WIDE;

const mobileStyle = (currentWidth: number, isSingleTransaction?: boolean) => {
const peek = isSingleTransaction ? spacing.p4.padding : NEXT_TRANSACTION_PEEK;
Expand All @@ -23,20 +24,25 @@ const mobileStyle = (currentWidth: number, isSingleTransaction?: boolean) => {
};
};

const desktopStyle = (currentWidth: number, isSingleTransaction?: boolean) => {
const desktopStyle = (currentWrapperWidth: number, isSingleTransaction?: boolean) => {
const peek = isSingleTransaction ? spacing.p4.padding : NEXT_TRANSACTION_PEEK;
const transactionPreviewWidth = currentWidth - spacing.p4.padding - peek;
const transactionPreviewWidth = currentWrapperWidth - spacing.p4.padding - peek;
const minimalWrapperWidth = TRANSACTION_WIDTH_WIDE + spacing.p4.padding + peek;
return {
transactionPreviewStyle: {width: currentWidth > minimalWrapperWidth ? TRANSACTION_WIDTH_WIDE : transactionPreviewWidth},
transactionPreviewStyle: {width: currentWrapperWidth > minimalWrapperWidth ? TRANSACTION_WIDTH_WIDE : transactionPreviewWidth},
componentStyle: [{maxWidth: 'min(680px, 100%)'}, {width: 'min-content'}],
expenseCountVisible: transactionPreviewWidth >= TRANSACTION_WIDTH_WIDE,
};
};

const getMoneyRequestReportPreviewStyle = (shouldUseNarrowLayout: boolean, currentWidth?: number, isSingleTransaction?: boolean): MoneyRequestReportPreviewStyleType => ({
const getMoneyRequestReportPreviewStyle = (
shouldUseNarrowLayout: boolean,
currentWidth?: number,
currentWrapperWidth?: number,
isSingleTransaction?: boolean,
): MoneyRequestReportPreviewStyleType => ({
...componentsSpacing,
...(shouldUseNarrowLayout ? mobileStyle(currentWidth ?? 256, isSingleTransaction) : desktopStyle(currentWidth ?? 1000, isSingleTransaction)),
...(shouldUseNarrowLayout ? mobileStyle(currentWidth ?? 256, isSingleTransaction) : desktopStyle(currentWrapperWidth ?? 1000, isSingleTransaction)),
});

export default getMoneyRequestReportPreviewStyle;