From d99d92d4a1ba20976af09a51cc504fdd9a21169a Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 01:58:07 +0300 Subject: [PATCH 001/504] implemented receipt image component --- src/components/DistanceEReceipt.js | 13 +-- ...oraryForRefactorRequestConfirmationList.js | 8 +- src/components/ReceiptImage.tsx | 82 +++++++++++++++++++ .../ReportActionItemImage.tsx | 44 ++-------- 4 files changed, 97 insertions(+), 50 deletions(-) create mode 100644 src/components/ReceiptImage.tsx diff --git a/src/components/DistanceEReceipt.js b/src/components/DistanceEReceipt.js index 0241eea44063..f900da2affcf 100644 --- a/src/components/DistanceEReceipt.js +++ b/src/components/DistanceEReceipt.js @@ -16,8 +16,8 @@ import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; import ImageSVG from './ImageSVG'; import PendingMapView from './MapView/PendingMapView'; +import ReceiptImage from './ReceiptImage'; import Text from './Text'; -import ThumbnailImage from './ThumbnailImage'; import transactionPropTypes from './transactionPropTypes'; const propTypes = { @@ -64,16 +64,7 @@ function DistanceEReceipt({transaction}) { /> - {isOffline || !thumbnailSource ? ( - - ) : ( - - )} + {isOffline || !thumbnailSource ? : } {formattedTransactionAmount} diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index 36d424ea28f2..67cf9db3674c 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -36,6 +36,7 @@ import Image from './Image'; import MenuItemWithTopDescription from './MenuItemWithTopDescription'; import optionPropTypes from './optionPropTypes'; import OptionsSelector from './OptionsSelector'; +import ReceiptImage from './ReceiptImage'; import SettlementButton from './SettlementButton'; import Switch from './Switch'; import tagPropTypes from './tagPropTypes'; @@ -639,9 +640,12 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ )} {(receiptImage || receiptThumbnail) && ( - ; + isAuthTokenRequired?: boolean; + confirmationPage?: boolean; +}; + +function ReceiptImage({transaction, receiptPath, receiptFileName, style, isAuthTokenRequired, confirmationPage}: ReceiptImageProps) { + const styles = useThemeStyles(); + // URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg + const path = transaction?.receipt?.source ?? receiptPath ?? ''; + // filename of uploaded image or last part of remote URI + const filename = transaction?.filename ?? receiptFileName ?? ''; + const isReceiptImage = Str.isImage(filename); + const shouldDisplayThumbnail = Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints') || !isReceiptImage; + const image = !shouldDisplayThumbnail && !(path.startsWith('blob:') || path.startsWith('file:')) ? `${path}.1024.jpg` : path; + const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:') || path.startsWith('/'); + + const imageSource = tryResolveUrlFromApiRoot(image ?? ''); + + const isEReceipt = transaction && TransactionUtils.hasEReceipt(transaction); + + if (!transaction) { + return ( + + ); + } + + if (!!isEReceipt || shouldDisplayThumbnail) { + if (!(!isLocalFile && !Str.isPDF(imageSource))) { + return ( + + + + ); + } + + return ( + + ); + } + + return isReceiptImage && !confirmationPage ? ( + + ) : ( + + ); +} + +export default ReceiptImage; diff --git a/src/components/ReportActionItem/ReportActionItemImage.tsx b/src/components/ReportActionItem/ReportActionItemImage.tsx index aa5d0513f0d7..3822f3ab42aa 100644 --- a/src/components/ReportActionItem/ReportActionItemImage.tsx +++ b/src/components/ReportActionItem/ReportActionItemImage.tsx @@ -1,16 +1,10 @@ -import Str from 'expensify-common/lib/str'; import React from 'react'; -import type {ReactElement} from 'react'; -import {View} from 'react-native'; import AttachmentModal from '@components/AttachmentModal'; -import EReceiptThumbnail from '@components/EReceiptThumbnail'; -import Image from '@components/Image'; import PressableWithoutFocus from '@components/Pressable/PressableWithoutFocus'; +import ReceiptImage from '@components/ReceiptImage'; import {ShowContextMenuContext} from '@components/ShowContextMenuContext'; -import ThumbnailImage from '@components/ThumbnailImage'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as TransactionUtils from '@libs/TransactionUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; import CONST from '@src/CONST'; import type {Transaction} from '@src/types/onyx'; @@ -45,34 +39,6 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, tr const styles = useThemeStyles(); const {translate} = useLocalize(); const imageSource = tryResolveUrlFromApiRoot(image ?? ''); - const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail ?? ''); - const isEReceipt = transaction && TransactionUtils.hasEReceipt(transaction); - - let receiptImageComponent: ReactElement; - - if (isEReceipt) { - receiptImageComponent = ( - - - - ); - } else if (thumbnail && !isLocalFile && !Str.isPDF(imageSource as string)) { - receiptImageComponent = ( - - ); - } else { - receiptImageComponent = ( - - ); - } if (enablePreviewModal) { return ( @@ -98,7 +64,11 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, tr accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON} accessibilityLabel={translate('accessibilityHints.viewAttachment')} > - {receiptImageComponent} + ) } @@ -108,7 +78,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, tr ); } - return receiptImageComponent; + return ; } ReportActionItemImage.displayName = 'ReportActionItemImage'; From a1f5f69a11350073692f4bd4585d62f2ef6c0112 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 02:02:31 +0300 Subject: [PATCH 002/504] pass receipt name for non modal display --- src/components/ReportActionItem/ReportActionItemImage.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportActionItemImage.tsx b/src/components/ReportActionItem/ReportActionItemImage.tsx index 3822f3ab42aa..1570aba49f7c 100644 --- a/src/components/ReportActionItem/ReportActionItemImage.tsx +++ b/src/components/ReportActionItem/ReportActionItemImage.tsx @@ -78,7 +78,13 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, tr ); } - return ; + return ( + + ); } ReportActionItemImage.displayName = 'ReportActionItemImage'; From 7dfd88567c07d4279fa0ed4d1d8745b3c3a1961e Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 02:18:53 +0300 Subject: [PATCH 003/504] minor fix --- src/components/ReceiptImage.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 984ba0bf2e9a..8de6d23127a8 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -36,10 +36,11 @@ function ReceiptImage({transaction, receiptPath, receiptFileName, style, isAuthT if (!transaction) { return ( - ); } From e9c766607677fe453531776d31f4652ba2c4b959 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 22:00:19 +0300 Subject: [PATCH 004/504] changed implementation --- src/components/DistanceEReceipt.js | 12 +++- ...oraryForRefactorRequestConfirmationList.js | 13 ++-- src/components/ReceiptImage.tsx | 66 +++++-------------- .../ReportActionItem/MoneyRequestView.js | 1 + .../ReportActionItemImage.tsx | 39 ++++++----- .../ReportActionItemImages.tsx | 8 ++- src/libs/ReceiptUtils.ts | 38 ++--------- 7 files changed, 71 insertions(+), 106 deletions(-) diff --git a/src/components/DistanceEReceipt.js b/src/components/DistanceEReceipt.js index f900da2affcf..8593cdcb5b93 100644 --- a/src/components/DistanceEReceipt.js +++ b/src/components/DistanceEReceipt.js @@ -34,7 +34,7 @@ function DistanceEReceipt({transaction}) { const styles = useThemeStyles(); const {translate} = useLocalize(); const {isOffline} = useNetwork(); - const {thumbnail} = TransactionUtils.hasReceipt(transaction) ? ReceiptUtils.getThumbnailAndImageURIs(transaction) : {}; + const {thumbnail, isThumbnail} = TransactionUtils.hasReceipt(transaction) ? ReceiptUtils.getThumbnailAndImageURIs(transaction) : {}; const {amount: transactionAmount, currency: transactionCurrency, merchant: transactionMerchant, created: transactionDate} = ReportUtils.getTransactionDetails(transaction); const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : translate('common.tbd'); const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail || ''); @@ -64,7 +64,15 @@ function DistanceEReceipt({transaction}) { /> - {isOffline || !thumbnailSource ? : } + {isOffline || !thumbnailSource ? ( + + ) : ( + + )} {formattedTransactionAmount} diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index 67cf9db3674c..c6bc49fd381e 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -32,7 +32,6 @@ import categoryPropTypes from './categoryPropTypes'; import ConfirmedRoute from './ConfirmedRoute'; import FormHelpMessage from './FormHelpMessage'; import * as Expensicons from './Icon/Expensicons'; -import Image from './Image'; import MenuItemWithTopDescription from './MenuItemWithTopDescription'; import optionPropTypes from './optionPropTypes'; import OptionsSelector from './OptionsSelector'; @@ -614,7 +613,11 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ ); }, [isReadOnly, iouType, selectedParticipants.length, confirm, bankAccountRoute, iouCurrencyCode, policyID, splitOrRequestOptions, formError, styles.ph1, styles.mb2, translate]); - const {image: receiptImage, thumbnail: receiptThumbnail} = receiptPath && receiptFilename ? ReceiptUtils.getThumbnailAndImageURIs(transaction, receiptPath, receiptFilename) : {}; + const { + image: receiptImage, + thumbnail: receiptThumbnail, + isThumbnail, + } = receiptPath && receiptFilename ? ReceiptUtils.getThumbnailAndImageURIs(transaction, receiptPath, receiptFilename) : {}; return ( ; + transactionID?: string; + isThumbnail?: boolean; + shouldUseThumnailImage?: boolean; + isEReceipt?: boolean; + source?: string; isAuthTokenRequired?: boolean; - confirmationPage?: boolean; + style?: StyleProp; }; -function ReceiptImage({transaction, receiptPath, receiptFileName, style, isAuthTokenRequired, confirmationPage}: ReceiptImageProps) { +function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImage = false, isEReceipt = false, source, isAuthTokenRequired, style}: ReceiptImageProps) { const styles = useThemeStyles(); - // URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg - const path = transaction?.receipt?.source ?? receiptPath ?? ''; - // filename of uploaded image or last part of remote URI - const filename = transaction?.filename ?? receiptFileName ?? ''; - const isReceiptImage = Str.isImage(filename); - const shouldDisplayThumbnail = Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints') || !isReceiptImage; - const image = !shouldDisplayThumbnail && !(path.startsWith('blob:') || path.startsWith('file:')) ? `${path}.1024.jpg` : path; - const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:') || path.startsWith('/'); - const imageSource = tryResolveUrlFromApiRoot(image ?? ''); - - const isEReceipt = transaction && TransactionUtils.hasEReceipt(transaction); - - if (!transaction) { + if (isEReceipt || isThumbnail) { return ( - + + + ); } - if (!!isEReceipt || shouldDisplayThumbnail) { - if (!(!isLocalFile && !Str.isPDF(imageSource))) { - return ( - - - - ); - } - + if (shouldUseThumnailImage) { return ( - ) : ( + return ( ); } +export type {ReceiptImageProps}; export default ReceiptImage; diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 86affbcac114..4fa2f76e20b8 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -237,6 +237,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate - + ) } @@ -78,13 +93,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, tr ); } - return ( - - ); + return ; } ReportActionItemImage.displayName = 'ReportActionItemImage'; diff --git a/src/components/ReportActionItem/ReportActionItemImages.tsx b/src/components/ReportActionItem/ReportActionItemImages.tsx index c24defb8ac08..8c2fc9638dea 100644 --- a/src/components/ReportActionItem/ReportActionItemImages.tsx +++ b/src/components/ReportActionItem/ReportActionItemImages.tsx @@ -11,8 +11,9 @@ import type {Transaction} from '@src/types/onyx'; import ReportActionItemImage from './ReportActionItemImage'; type Image = { - thumbnail: string | number; - image: string | number; + thumbnail?: string; + isThumbnail?: boolean; + image: string; transaction: Transaction; isLocalFile: boolean; }; @@ -71,7 +72,7 @@ function ReportActionItemImages({images, size, total, isHovered = false}: Report return ( - {shownImages.map(({thumbnail, image, transaction, isLocalFile}, index) => { + {shownImages.map(({thumbnail, isThumbnail, image, transaction, isLocalFile}, index) => { const isLastImage = index === numberOfShownImages - 1; // Show a border to separate multiple images. Shown to the right for each except the last. @@ -87,6 +88,7 @@ function ReportActionItemImages({images, size, total, isHovered = false}: Report image={image} isLocalFile={isLocalFile} transaction={transaction} + isThumbnail={isThumbnail} /> {isLastImage && remaining > 0 && ( diff --git a/src/libs/ReceiptUtils.ts b/src/libs/ReceiptUtils.ts index bcba68a3a0bd..a01f7779c13a 100644 --- a/src/libs/ReceiptUtils.ts +++ b/src/libs/ReceiptUtils.ts @@ -1,24 +1,13 @@ import Str from 'expensify-common/lib/str'; -import type {ImageSourcePropType} from 'react-native'; -import ReceiptDoc from '@assets/images/receipt-doc.png'; -import ReceiptGeneric from '@assets/images/receipt-generic.png'; -import ReceiptHTML from '@assets/images/receipt-html.png'; -import ReceiptSVG from '@assets/images/receipt-svg.png'; -import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {Transaction} from '@src/types/onyx'; -import * as FileUtils from './fileDownload/FileUtils'; type ThumbnailAndImageURI = { - image: ImageSourcePropType | string; - thumbnail: ImageSourcePropType | string | null; + image: string; + thumbnail?: string; transaction?: Transaction; isLocalFile?: boolean; -}; - -type FileNameAndExtension = { - fileExtension?: string; - fileName?: string; + isThumbnail?: boolean; }; /** @@ -39,12 +28,12 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) { if (hasEReceipt) { - return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction}; + return {image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction}; } // For local files, we won't have a thumbnail yet if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) { - return {thumbnail: null, image: path, isLocalFile: true}; + return {image: path, isLocalFile: true}; } if (isReceiptImage) { @@ -52,22 +41,9 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string } } - const {fileExtension} = FileUtils.splitExtensionFromFileName(filename) as FileNameAndExtension; - let image = ReceiptGeneric; - if (fileExtension === CONST.IOU.FILE_TYPES.HTML) { - image = ReceiptHTML; - } - - if (fileExtension === CONST.IOU.FILE_TYPES.DOC || fileExtension === CONST.IOU.FILE_TYPES.DOCX) { - image = ReceiptDoc; - } - - if (fileExtension === CONST.IOU.FILE_TYPES.SVG) { - image = ReceiptSVG; - } - const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:') || path.startsWith('/'); - return {thumbnail: image, image: path, isLocalFile}; + + return {isThumbnail: true, image: path, isLocalFile}; } // eslint-disable-next-line import/prefer-default-export From e88e1ce8082cfc9845a6dbe267e45ee6c73f1c2c Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 22:08:44 +0300 Subject: [PATCH 005/504] fix styling --- src/components/ReceiptImage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index df34aec496e0..7c5fde88f600 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -21,7 +21,7 @@ function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImag if (isEReceipt || isThumbnail) { return ( - + ); From 26fa66ba9be8a4f87a8ce1b673653811f3c87f9c Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 22:35:37 +0300 Subject: [PATCH 006/504] fix borderRadius --- src/components/EReceiptThumbnail.tsx | 4 +++- src/components/ReceiptImage.tsx | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index 5976200975cd..b677a60cc02c 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -18,6 +18,7 @@ import Image from './Image'; type EReceiptThumbnailOnyxProps = { transaction: OnyxEntry; + borderRadius?: number; }; type EReceiptThumbnailProps = EReceiptThumbnailOnyxProps & { @@ -35,7 +36,7 @@ const backgroundImages = { [CONST.ERECEIPT_COLORS.PINK]: eReceiptBGs.EReceiptBG_Pink, }; -function EReceiptThumbnail({transaction}: EReceiptThumbnailProps) { +function EReceiptThumbnail({transaction, borderRadius}: EReceiptThumbnailProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -83,6 +84,7 @@ function EReceiptThumbnail({transaction}: EReceiptThumbnailProps) { styles.overflowHidden, styles.alignItemsCenter, containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint ? styles.justifyContentCenter : {}, + borderRadius && {borderRadius}, ]} onLayout={onContainerLayout} > diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 7c5fde88f600..7317869cf5d3 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -22,7 +22,10 @@ function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImag if (isEReceipt || isThumbnail) { return ( - + ); } From d4abf53440ba81bca0752b5b6836a787829d50b6 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 23:01:52 +0300 Subject: [PATCH 007/504] type fix --- src/components/EReceiptThumbnail.tsx | 4 ++-- src/components/ReceiptImage.tsx | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index b677a60cc02c..a15f0a2d17bc 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -18,13 +18,13 @@ import Image from './Image'; type EReceiptThumbnailOnyxProps = { transaction: OnyxEntry; - borderRadius?: number; }; type EReceiptThumbnailProps = EReceiptThumbnailOnyxProps & { /** TransactionID of the transaction this EReceipt corresponds to. It's used by withOnyx HOC */ // eslint-disable-next-line react/no-unused-prop-types transactionID: string; + borderRadius?: number; }; const backgroundImages = { @@ -84,7 +84,7 @@ function EReceiptThumbnail({transaction, borderRadius}: EReceiptThumbnailProps) styles.overflowHidden, styles.alignItemsCenter, containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint ? styles.justifyContentCenter : {}, - borderRadius && {borderRadius}, + borderRadius ? {borderRadius} : {}, ]} onLayout={onContainerLayout} > diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 7317869cf5d3..2c78337c725a 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -1,11 +1,12 @@ import React from 'react'; -import type {ImageStyle, StyleProp} from 'react-native'; import {View} from 'react-native'; import useThemeStyles from '@hooks/useThemeStyles'; import EReceiptThumbnail from './EReceiptThumbnail'; import Image from './Image'; import ThumbnailImage from './ThumbnailImage'; +type Style = {height: number; borderRadius: number; margin: number}; + type ReceiptImageProps = { transactionID?: string; isThumbnail?: boolean; @@ -13,7 +14,7 @@ type ReceiptImageProps = { isEReceipt?: boolean; source?: string; isAuthTokenRequired?: boolean; - style?: StyleProp; + style?: Style; }; function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImage = false, isEReceipt = false, source, isAuthTokenRequired, style}: ReceiptImageProps) { From 63b41f664bb31b0bfe309521f18982f65abf2024 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 23:28:32 +0300 Subject: [PATCH 008/504] minor fix --- src/components/DistanceEReceipt.js | 1 - src/components/ReportActionItem/ReportActionItemImage.tsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/DistanceEReceipt.js b/src/components/DistanceEReceipt.js index 8593cdcb5b93..ead2e2487848 100644 --- a/src/components/DistanceEReceipt.js +++ b/src/components/DistanceEReceipt.js @@ -69,7 +69,6 @@ function DistanceEReceipt({transaction}) { ) : ( )} diff --git a/src/components/ReportActionItem/ReportActionItemImage.tsx b/src/components/ReportActionItem/ReportActionItemImage.tsx index b9a98777eb53..d7d2514352c7 100644 --- a/src/components/ReportActionItem/ReportActionItemImage.tsx +++ b/src/components/ReportActionItem/ReportActionItemImage.tsx @@ -56,7 +56,7 @@ function ReportActionItemImage({thumbnail, isThumbnail, image, enablePreviewModa } else if ((thumbnail ?? isThumbnail) && !isLocalFile && !Str.isPDF(imageSource)) { propsObj = thumbnailSource ? {shouldUseThumnailImage: true, source: thumbnailSource} : {isThumbnail: true, transactionID: transaction?.transactionID}; } else { - propsObj = {isThumbnail, source: thumbnail ?? image}; + propsObj = {isThumbnail, transactionID: transaction?.transactionID, source: thumbnail ?? image}; } if (enablePreviewModal) { From 404fd8c39c0b19cff84e3c634e715c397e0d2240 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Sat, 20 Jan 2024 23:54:15 +0300 Subject: [PATCH 009/504] passed transaction prop --- src/components/DistanceEReceipt.js | 2 +- src/components/ReportActionItem/MoneyRequestPreview.js | 2 +- src/components/ReportActionItem/ReportPreview.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/DistanceEReceipt.js b/src/components/DistanceEReceipt.js index ead2e2487848..e322ccd28f4d 100644 --- a/src/components/DistanceEReceipt.js +++ b/src/components/DistanceEReceipt.js @@ -34,7 +34,7 @@ function DistanceEReceipt({transaction}) { const styles = useThemeStyles(); const {translate} = useLocalize(); const {isOffline} = useNetwork(); - const {thumbnail, isThumbnail} = TransactionUtils.hasReceipt(transaction) ? ReceiptUtils.getThumbnailAndImageURIs(transaction) : {}; + const {thumbnail} = TransactionUtils.hasReceipt(transaction) ? ReceiptUtils.getThumbnailAndImageURIs(transaction) : {}; const {amount: transactionAmount, currency: transactionCurrency, merchant: transactionMerchant, created: transactionDate} = ReportUtils.getTransactionDetails(transaction); const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : translate('common.tbd'); const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail || ''); diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 9cb27e6fac4a..e0351e4e642f 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -178,7 +178,7 @@ function MoneyRequestPreview(props) { merchantOrDescription = requestMerchant.replace(CONST.REGEX.FIRST_SPACE, translate('common.tbd')); } - const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(props.transaction)] : []; + const receiptImages = hasReceipt ? [{...ReceiptUtils.getThumbnailAndImageURIs(props.transaction), transaction: props.transaction}] : []; const getSettledMessage = () => { if (isExpensifyCardTransaction) { diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 204c9b5e31d4..f448a227a1a6 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -173,7 +173,7 @@ function ReportPreview(props) { const isScanning = hasReceipts && areAllRequestsBeingSmartScanned; const hasErrors = (hasReceipts && hasMissingSmartscanFields) || (canUseViolations && ReportUtils.hasViolations(props.iouReportID, props.transactionViolations)); const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3); - const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, (transaction) => ReceiptUtils.getThumbnailAndImageURIs(transaction)); + const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, (transaction) => ({...ReceiptUtils.getThumbnailAndImageURIs(transaction), transaction})); let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null; if (TransactionUtils.isPartialMerchant(formattedMerchant)) { formattedMerchant = null; From 9d38d933207f225f9667a15cc424003c59cc8099 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Wed, 24 Jan 2024 00:13:34 +0300 Subject: [PATCH 010/504] updated attachement modal to consider thumnail display --- src/components/AttachmentModal.js | 6 +++++- src/components/ReportActionItem/ReportActionItemImage.tsx | 1 + src/libs/ReceiptUtils.ts | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 346ff19987ef..2fd8f3b30170 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -49,6 +49,9 @@ const propTypes = { /** Optional source (URL, SVG function) for the image shown. If not passed in via props must be specified when modal is opened. */ source: PropTypes.oneOfType([PropTypes.string, sourcePropTypes]), + /** Whether thumnail should be display */ + isThumbnail: PropTypes.bool, + /** Optional callback to fire when we want to preview an image and approve it for use. */ onConfirm: PropTypes.func, @@ -101,6 +104,7 @@ const propTypes = { const defaultProps = { source: '', + isThumbnail: false, onConfirm: null, defaultOpen: false, originalFileName: '', @@ -471,7 +475,7 @@ function AttachmentModal(props) { setDownloadButtonVisibility={setDownloadButtonVisibility} /> ) : ( - Boolean(sourceForAttachmentView) && + (Boolean(sourceForAttachmentView) || props.isThumbnail) && shouldLoadAttachment && ( Date: Wed, 24 Jan 2024 00:15:27 +0300 Subject: [PATCH 011/504] minor fix --- .../MoneyTemporaryForRefactorRequestConfirmationList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index b82f3eaf2f0f..1ece4679d065 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -643,7 +643,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ )} - {receiptImage || receiptThumbnail ? ( + {receiptImage || receiptThumbnail || isThumbnail ? ( Date: Wed, 24 Jan 2024 00:17:23 +0300 Subject: [PATCH 012/504] minor revert --- src/libs/ReceiptUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReceiptUtils.ts b/src/libs/ReceiptUtils.ts index 18d56075844c..70925b0d42c3 100644 --- a/src/libs/ReceiptUtils.ts +++ b/src/libs/ReceiptUtils.ts @@ -44,7 +44,7 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:') || path.startsWith('/'); - return {isThumbnail: true, isLocalFile}; + return {isThumbnail: true, image: path, isLocalFile}; } // eslint-disable-next-line import/prefer-default-export From dc760ca13e718edbcbb3b768b247c608c1d8f7c9 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Wed, 24 Jan 2024 00:18:48 +0300 Subject: [PATCH 013/504] small fix --- .../MoneyTemporaryForRefactorRequestConfirmationList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index 1ece4679d065..b82f3eaf2f0f 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -643,7 +643,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ )} - {receiptImage || receiptThumbnail || isThumbnail ? ( + {receiptImage || receiptThumbnail ? ( Date: Wed, 24 Jan 2024 17:53:31 +0300 Subject: [PATCH 014/504] fix on thumbnail display logic --- src/components/AttachmentModal.js | 6 +----- src/components/MoneyRequestConfirmationList.js | 15 ++++++++++----- .../ReportActionItem/ReportActionItemImage.tsx | 1 - src/libs/ReceiptUtils.ts | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 2fd8f3b30170..346ff19987ef 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -49,9 +49,6 @@ const propTypes = { /** Optional source (URL, SVG function) for the image shown. If not passed in via props must be specified when modal is opened. */ source: PropTypes.oneOfType([PropTypes.string, sourcePropTypes]), - /** Whether thumnail should be display */ - isThumbnail: PropTypes.bool, - /** Optional callback to fire when we want to preview an image and approve it for use. */ onConfirm: PropTypes.func, @@ -104,7 +101,6 @@ const propTypes = { const defaultProps = { source: '', - isThumbnail: false, onConfirm: null, defaultOpen: false, originalFileName: '', @@ -475,7 +471,7 @@ function AttachmentModal(props) { setDownloadButtonVisibility={setDownloadButtonVisibility} /> ) : ( - (Boolean(sourceForAttachmentView) || props.isThumbnail) && + Boolean(sourceForAttachmentView) && shouldLoadAttachment && ( )} {receiptImage || receiptThumbnail ? ( - Date: Wed, 24 Jan 2024 18:47:34 +0300 Subject: [PATCH 015/504] minor type fix --- src/libs/ReceiptUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReceiptUtils.ts b/src/libs/ReceiptUtils.ts index c7728889c865..509c88d5305d 100644 --- a/src/libs/ReceiptUtils.ts +++ b/src/libs/ReceiptUtils.ts @@ -3,7 +3,7 @@ import ROUTES from '@src/ROUTES'; import type {Transaction} from '@src/types/onyx'; type ThumbnailAndImageURI = { - image?: string; + image: string; thumbnail?: string; transaction?: Transaction; isLocalFile?: boolean; From 0cfb3cba8a164fceafd8e9b534b3320a49760bdf Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Thu, 25 Jan 2024 20:56:52 +0300 Subject: [PATCH 016/504] Added file type label support for eThumbnail --- src/components/EReceiptThumbnail.tsx | 8 ++++++-- src/components/MoneyRequestConfirmationList.js | 2 ++ ...poraryForRefactorRequestConfirmationList.js | 2 ++ src/components/ReceiptImage.tsx | 5 ++++- .../ReportActionItem/MoneyRequestView.js | 1 + .../ReportActionItem/ReportActionItemImage.tsx | 18 +++++++++++++++--- .../ReportActionItemImages.tsx | 15 ++++----------- src/libs/ReceiptUtils.ts | 8 ++++++-- 8 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index a15f0a2d17bc..75f82b0f0e26 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -15,6 +15,7 @@ import * as eReceiptBGs from './Icon/EReceiptBGs'; import * as Expensicons from './Icon/Expensicons'; import * as MCCIcons from './Icon/MCCIcons'; import Image from './Image'; +import Text from './Text'; type EReceiptThumbnailOnyxProps = { transaction: OnyxEntry; @@ -25,6 +26,8 @@ type EReceiptThumbnailProps = EReceiptThumbnailOnyxProps & { // eslint-disable-next-line react/no-unused-prop-types transactionID: string; borderRadius?: number; + fileExtension?: string; + isThumbnail?: boolean; }; const backgroundImages = { @@ -36,7 +39,7 @@ const backgroundImages = { [CONST.ERECEIPT_COLORS.PINK]: eReceiptBGs.EReceiptBG_Pink, }; -function EReceiptThumbnail({transaction, borderRadius}: EReceiptThumbnailProps) { +function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnail = false}: EReceiptThumbnailProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -102,7 +105,8 @@ function EReceiptThumbnail({transaction, borderRadius}: EReceiptThumbnailProps) fill={secondaryColor} additionalStyles={[styles.fullScreen]} /> - {MCCIcon ? ( + {isThumbnail && fileExtension && {fileExtension.toUpperCase()}} + {MCCIcon && !isThumbnail ? ( ) : ( // The empty receipt component should only show for IOU Requests of a paid policy ("Team" or "Corporate") diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index b82f3eaf2f0f..aea3d20f0b00 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -618,6 +618,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ image: receiptImage, thumbnail: receiptThumbnail, isThumbnail, + fileExtension, } = receiptPath && receiptFilename ? ReceiptUtils.getThumbnailAndImageURIs(transaction, receiptPath, receiptFilename) : {}; return ( ) : ( // The empty receipt component should only show for IOU Requests of a paid policy ("Team" or "Corporate") diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 2c78337c725a..bf4b0ef832fc 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -15,9 +15,10 @@ type ReceiptImageProps = { source?: string; isAuthTokenRequired?: boolean; style?: Style; + fileExtension?: string; }; -function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImage = false, isEReceipt = false, source, isAuthTokenRequired, style}: ReceiptImageProps) { +function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImage = false, isEReceipt = false, source, isAuthTokenRequired, style, fileExtension}: ReceiptImageProps) { const styles = useThemeStyles(); if (isEReceipt || isThumbnail) { @@ -26,6 +27,8 @@ function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImag ); diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index e2ebc701523d..73c478ca0164 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -237,6 +237,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate - {shownImages.map(({thumbnail, isThumbnail, image, transaction, isLocalFile}, index) => { + {shownImages.map(({thumbnail, isThumbnail, image, transaction, isLocalFile, fileExtension}, index) => { const isLastImage = index === numberOfShownImages - 1; // Show a border to separate multiple images. Shown to the right for each except the last. @@ -85,6 +77,7 @@ function ReportActionItemImages({images, size, total, isHovered = false}: Report > type === fileExtension), image: path, isLocalFile}; } // eslint-disable-next-line import/prefer-default-export export {getThumbnailAndImageURIs}; +export type {ThumbnailAndImageURI}; From c059ed1b78e9af5fa69bae467aaf682a17989625 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Thu, 25 Jan 2024 21:15:53 +0300 Subject: [PATCH 017/504] pass transactionID for confirmation --- src/components/MoneyRequestConfirmationList.js | 1 + .../MoneyTemporaryForRefactorRequestConfirmationList.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index 5f43e6a83204..ed39b6256dc4 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -620,6 +620,7 @@ function MoneyRequestConfirmationList(props) { // So if we have a thumbnail, it means we're retrieving the image from the server isAuthTokenRequired={!_.isEmpty(receiptThumbnail)} fileExtension={fileExtension} + transactionID={props.transactionID || (props.transaction && props.transaction.transactionID)} /> ) : ( // The empty receipt component should only show for IOU Requests of a paid policy ("Team" or "Corporate") diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index aea3d20f0b00..a47ddfc3843b 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -653,6 +653,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ // but we don't need it to load the blob:// or file:// image when starting a money request / split bill // So if we have a thumbnail, it means we're retrieving the image from the server isAuthTokenRequired={!_.isEmpty(receiptThumbnail)} + transactionID={transaction && transaction.transactionID} fileExtension={fileExtension} /> ) : ( From 7008a5d10307b64093b65440a675d2e3f0325393 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Mon, 29 Jan 2024 16:36:34 +0300 Subject: [PATCH 018/504] minor fix --- src/components/DistanceEReceipt.js | 2 +- src/components/ReceiptImage.tsx | 6 +++--- src/components/ReportActionItem/ReportActionItemImage.tsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/DistanceEReceipt.js b/src/components/DistanceEReceipt.js index e322ccd28f4d..a42b4cbe42db 100644 --- a/src/components/DistanceEReceipt.js +++ b/src/components/DistanceEReceipt.js @@ -69,7 +69,7 @@ function DistanceEReceipt({transaction}) { ) : ( )} diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index bf4b0ef832fc..d04830bebb36 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -10,7 +10,7 @@ type Style = {height: number; borderRadius: number; margin: number}; type ReceiptImageProps = { transactionID?: string; isThumbnail?: boolean; - shouldUseThumnailImage?: boolean; + shouldUseThumbnailImage?: boolean; isEReceipt?: boolean; source?: string; isAuthTokenRequired?: boolean; @@ -18,7 +18,7 @@ type ReceiptImageProps = { fileExtension?: string; }; -function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImage = false, isEReceipt = false, source, isAuthTokenRequired, style, fileExtension}: ReceiptImageProps) { +function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumbnailImage = false, isEReceipt = false, source, isAuthTokenRequired, style, fileExtension}: ReceiptImageProps) { const styles = useThemeStyles(); if (isEReceipt || isThumbnail) { @@ -34,7 +34,7 @@ function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumnailImag ); } - if (shouldUseThumnailImage) { + if (shouldUseThumbnailImage) { return ( Date: Mon, 29 Jan 2024 17:11:24 +0300 Subject: [PATCH 019/504] fix unnecessary condition --- src/components/ReportActionItem/ReportActionItemImage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/ReportActionItemImage.tsx b/src/components/ReportActionItem/ReportActionItemImage.tsx index a63b491c18a5..435ff20a6f55 100644 --- a/src/components/ReportActionItem/ReportActionItemImage.tsx +++ b/src/components/ReportActionItem/ReportActionItemImage.tsx @@ -65,8 +65,8 @@ function ReportActionItemImage({ if (isEReceipt) { propsObj = {isEReceipt: true, transactionID: transaction.transactionID}; - } else if ((thumbnail ?? isThumbnail) && !isLocalFile && !Str.isPDF(imageSource)) { - propsObj = thumbnailSource ? {shouldUseThumbnailImage: true, source: thumbnailSource} : {isThumbnail: true, fileExtension, transactionID: transaction?.transactionID}; + } else if (thumbnail && !isLocalFile && !Str.isPDF(imageSource)) { + propsObj = {shouldUseThumbnailImage: true, source: thumbnailSource}; } else { propsObj = {isThumbnail, fileExtension, transactionID: transaction?.transactionID, source: thumbnail ?? image}; } From 3f019a51c6d2b6b4c19155e0084a7e814b82fb0d Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Mon, 29 Jan 2024 18:16:46 +0300 Subject: [PATCH 020/504] update to static icon layout --- src/components/EReceiptThumbnail.tsx | 11 ++++++----- src/components/ReceiptImage.tsx | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index 75f82b0f0e26..efef40b6f7bb 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -28,6 +28,7 @@ type EReceiptThumbnailProps = EReceiptThumbnailOnyxProps & { borderRadius?: number; fileExtension?: string; isThumbnail?: boolean; + useStaticIconLayout?: boolean; }; const backgroundImages = { @@ -39,7 +40,7 @@ const backgroundImages = { [CONST.ERECEIPT_COLORS.PINK]: eReceiptBGs.EReceiptBG_Pink, }; -function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnail = false}: EReceiptThumbnailProps) { +function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnail = false, useStaticIconLayout = false}: EReceiptThumbnailProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -69,11 +70,11 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnai let receiptIconHeight: number = variables.eReceiptIconHeight; let receiptMCCSize: number = variables.eReceiptMCCHeightWidth; - if (isSmall) { + if (isSmall && !useStaticIconLayout) { receiptIconWidth = variables.eReceiptIconWidthSmall; receiptIconHeight = variables.eReceiptIconHeightSmall; receiptMCCSize = variables.eReceiptMCCHeightWidthSmall; - } else if (isMedium) { + } else if (isMedium || useStaticIconLayout) { receiptIconWidth = variables.eReceiptIconWidthMedium; receiptIconHeight = variables.eReceiptIconHeightMedium; receiptMCCSize = variables.eReceiptMCCHeightWidthMedium; @@ -86,10 +87,10 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnai primaryColor ? StyleUtils.getBackgroundColorStyle(primaryColor) : {}, styles.overflowHidden, styles.alignItemsCenter, - containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint ? styles.justifyContentCenter : {}, + useStaticIconLayout || (containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint) ? styles.justifyContentCenter : {}, borderRadius ? {borderRadius} : {}, ]} - onLayout={onContainerLayout} + onLayout={useStaticIconLayout ? undefined : onContainerLayout} > ); From 6d7481c27b0ceed08d726298c7c30ef684f9e130 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Wed, 31 Jan 2024 21:32:48 +0300 Subject: [PATCH 021/504] changed to isStaticIconLayout --- src/components/EReceiptThumbnail.tsx | 12 ++++++------ src/components/ReceiptImage.tsx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index efef40b6f7bb..23429fe35d16 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -28,7 +28,7 @@ type EReceiptThumbnailProps = EReceiptThumbnailOnyxProps & { borderRadius?: number; fileExtension?: string; isThumbnail?: boolean; - useStaticIconLayout?: boolean; + isStaticIconLayout?: boolean; }; const backgroundImages = { @@ -40,7 +40,7 @@ const backgroundImages = { [CONST.ERECEIPT_COLORS.PINK]: eReceiptBGs.EReceiptBG_Pink, }; -function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnail = false, useStaticIconLayout = false}: EReceiptThumbnailProps) { +function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnail = false, isStaticIconLayout = false}: EReceiptThumbnailProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -70,11 +70,11 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnai let receiptIconHeight: number = variables.eReceiptIconHeight; let receiptMCCSize: number = variables.eReceiptMCCHeightWidth; - if (isSmall && !useStaticIconLayout) { + if (isSmall && !isStaticIconLayout) { receiptIconWidth = variables.eReceiptIconWidthSmall; receiptIconHeight = variables.eReceiptIconHeightSmall; receiptMCCSize = variables.eReceiptMCCHeightWidthSmall; - } else if (isMedium || useStaticIconLayout) { + } else if (isMedium || isStaticIconLayout) { receiptIconWidth = variables.eReceiptIconWidthMedium; receiptIconHeight = variables.eReceiptIconHeightMedium; receiptMCCSize = variables.eReceiptMCCHeightWidthMedium; @@ -87,10 +87,10 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnai primaryColor ? StyleUtils.getBackgroundColorStyle(primaryColor) : {}, styles.overflowHidden, styles.alignItemsCenter, - useStaticIconLayout || (containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint) ? styles.justifyContentCenter : {}, + isStaticIconLayout || (containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint) ? styles.justifyContentCenter : {}, borderRadius ? {borderRadius} : {}, ]} - onLayout={useStaticIconLayout ? undefined : onContainerLayout} + onLayout={isStaticIconLayout ? undefined : onContainerLayout} > ); From e61a6c7dffbd70f02df2faa72ad7f6c7a267c3de Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Wed, 31 Jan 2024 21:34:26 +0300 Subject: [PATCH 022/504] typescript fix --- src/components/ReportActionItem/ReportActionItemImages.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportActionItemImages.tsx b/src/components/ReportActionItem/ReportActionItemImages.tsx index 69bb6c592f54..e1abcb54adbb 100644 --- a/src/components/ReportActionItem/ReportActionItemImages.tsx +++ b/src/components/ReportActionItem/ReportActionItemImages.tsx @@ -72,7 +72,7 @@ function ReportActionItemImages({images, size, total, isHovered = false}: Report const borderStyle = shouldShowBorder ? styles.reportActionItemImageBorder : {}; return ( Date: Wed, 31 Jan 2024 22:05:51 +0300 Subject: [PATCH 023/504] set label text black --- src/components/EReceiptThumbnail.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index 23429fe35d16..708b1707716f 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -6,6 +6,7 @@ import {withOnyx} from 'react-native-onyx'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ReportUtils from '@libs/ReportUtils'; +import colors from '@styles/theme/colors'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -106,7 +107,7 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnai fill={secondaryColor} additionalStyles={[styles.fullScreen]} /> - {isThumbnail && fileExtension && {fileExtension.toUpperCase()}} + {isThumbnail && fileExtension && {fileExtension.toUpperCase()}} {MCCIcon && !isThumbnail ? ( Date: Thu, 1 Feb 2024 14:44:54 +0300 Subject: [PATCH 024/504] removed inline styles --- src/components/EReceiptThumbnail.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index 708b1707716f..fa2607965b57 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -107,7 +107,7 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnai fill={secondaryColor} additionalStyles={[styles.fullScreen]} /> - {isThumbnail && fileExtension && {fileExtension.toUpperCase()}} + {isThumbnail && fileExtension && {fileExtension.toUpperCase()}} {MCCIcon && !isThumbnail ? ( Date: Thu, 1 Feb 2024 14:51:07 +0300 Subject: [PATCH 025/504] fix on comment --- src/libs/ReceiptUtils.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libs/ReceiptUtils.ts b/src/libs/ReceiptUtils.ts index bf153118ecfd..44e054b4edc7 100644 --- a/src/libs/ReceiptUtils.ts +++ b/src/libs/ReceiptUtils.ts @@ -7,7 +7,7 @@ import type {ReceiptError} from '@src/types/onyx/Transaction'; import {splitExtensionFromFileName} from './fileDownload/FileUtils'; type ThumbnailAndImageURI = { - image: string; + image?: string; thumbnail?: string; transaction?: Transaction; isLocalFile?: boolean; @@ -23,14 +23,13 @@ type ThumbnailAndImageURI = { * @param receiptFileName */ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string | null = null, receiptFileName: string | null = null): ThumbnailAndImageURI { - // URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg + if (Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) { + return {isThumbnail: true, isLocalFile: true}; + } // If there're errors, we need to display them in preview. We can store many files in errors, but we just need to get the last one const errors = _.findLast(transaction.errors) as ReceiptError | undefined; + // URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg const path = errors?.source ?? transaction?.receipt?.source ?? receiptPath ?? ''; - if (Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) { - return {isThumbnail: true, image: path, isLocalFile: true}; - } - // filename of uploaded image or last part of remote URI const filename = errors?.filename ?? transaction?.filename ?? receiptFileName ?? ''; const isReceiptImage = Str.isImage(filename); From 73f6495d8cf1d906e190a6461bf94aaa23007fd5 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Thu, 1 Feb 2024 16:31:38 +0300 Subject: [PATCH 026/504] fixed pending waypoints thumbnail display --- src/components/AttachmentModal.tsx | 6 ++---- src/components/ReportActionItem/ReportActionItemImage.tsx | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index f3e8ed316c52..ce1e3c99ac82 100755 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -519,10 +519,8 @@ function AttachmentModal({ setDownloadButtonVisibility={setDownloadButtonVisibility} /> ) : ( - !!sourceForAttachmentView && - shouldLoadAttachment && - !isLoading && - !shouldShowNotFoundPage && ( + ((TransactionUtils.isDistanceRequest(transaction) && Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) || + (!!sourceForAttachmentView && shouldLoadAttachment && !isLoading && !shouldShowNotFoundPage)) && ( Date: Thu, 1 Feb 2024 16:46:16 +0300 Subject: [PATCH 027/504] simplified condition --- src/components/AttachmentModal.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index ce1e3c99ac82..d355c6fc98bb 100755 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -519,8 +519,10 @@ function AttachmentModal({ setDownloadButtonVisibility={setDownloadButtonVisibility} /> ) : ( - ((TransactionUtils.isDistanceRequest(transaction) && Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) || - (!!sourceForAttachmentView && shouldLoadAttachment && !isLoading && !shouldShowNotFoundPage)) && ( + (!!sourceForAttachmentView || Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) && + shouldLoadAttachment && + !isLoading && + !shouldShowNotFoundPage && ( Date: Thu, 1 Feb 2024 19:33:12 +0300 Subject: [PATCH 028/504] changed to isReceiptThumbnail prop --- src/components/EReceiptThumbnail.tsx | 19 ++++++++++--------- src/components/ReceiptImage.tsx | 3 +-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index fa2607965b57..4ccb6cfc7243 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -28,8 +28,9 @@ type EReceiptThumbnailProps = EReceiptThumbnailOnyxProps & { transactionID: string; borderRadius?: number; fileExtension?: string; - isThumbnail?: boolean; - isStaticIconLayout?: boolean; + + /** Whether it is a receipt thumbnail we are displaying. */ + isReceiptThumbnail?: boolean; }; const backgroundImages = { @@ -41,7 +42,7 @@ const backgroundImages = { [CONST.ERECEIPT_COLORS.PINK]: eReceiptBGs.EReceiptBG_Pink, }; -function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnail = false, isStaticIconLayout = false}: EReceiptThumbnailProps) { +function EReceiptThumbnail({transaction, borderRadius, fileExtension, isReceiptThumbnail = false}: EReceiptThumbnailProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -71,11 +72,11 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnai let receiptIconHeight: number = variables.eReceiptIconHeight; let receiptMCCSize: number = variables.eReceiptMCCHeightWidth; - if (isSmall && !isStaticIconLayout) { + if (isSmall && !isReceiptThumbnail) { receiptIconWidth = variables.eReceiptIconWidthSmall; receiptIconHeight = variables.eReceiptIconHeightSmall; receiptMCCSize = variables.eReceiptMCCHeightWidthSmall; - } else if (isMedium || isStaticIconLayout) { + } else if (isMedium || isReceiptThumbnail) { receiptIconWidth = variables.eReceiptIconWidthMedium; receiptIconHeight = variables.eReceiptIconHeightMedium; receiptMCCSize = variables.eReceiptMCCHeightWidthMedium; @@ -88,10 +89,10 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isThumbnai primaryColor ? StyleUtils.getBackgroundColorStyle(primaryColor) : {}, styles.overflowHidden, styles.alignItemsCenter, - isStaticIconLayout || (containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint) ? styles.justifyContentCenter : {}, + isReceiptThumbnail || (containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint) ? styles.justifyContentCenter : {}, borderRadius ? {borderRadius} : {}, ]} - onLayout={isStaticIconLayout ? undefined : onContainerLayout} + onLayout={isReceiptThumbnail ? undefined : onContainerLayout} > - {isThumbnail && fileExtension && {fileExtension.toUpperCase()}} - {MCCIcon && !isThumbnail ? ( + {isReceiptThumbnail && fileExtension && {fileExtension.toUpperCase()}} + {MCCIcon && !isReceiptThumbnail ? ( ); From 1fb6284ff86d9b862605889ca0a9f4c9237616d2 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Mon, 5 Feb 2024 12:27:29 +0300 Subject: [PATCH 029/504] separated Ereceipt and thumbnail logic --- src/components/ReceiptImage.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 0b7155ee6597..5f15ea675ff4 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -22,13 +22,13 @@ function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumbnailIma const styles = useThemeStyles(); if (isEReceipt || isThumbnail) { + const props = !isEReceipt && {borderRadius: style?.borderRadius, fileExtension, isReceiptThumbnail: true}; return ( ); From 75ca883259e66cd565bd1b27f300119cb2333c3d Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Mon, 5 Feb 2024 14:44:03 +0300 Subject: [PATCH 030/504] minor lint fix --- src/components/ReportActionItem/ReportActionItemImage.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/ReportActionItem/ReportActionItemImage.tsx b/src/components/ReportActionItem/ReportActionItemImage.tsx index e32a67acb4fb..91f1e5310273 100644 --- a/src/components/ReportActionItem/ReportActionItemImage.tsx +++ b/src/components/ReportActionItem/ReportActionItemImage.tsx @@ -1,9 +1,6 @@ /* eslint-disable react/jsx-props-no-spreading */ import Str from 'expensify-common/lib/str'; import React from 'react'; -import type {ReactElement} from 'react'; -import type {ImageSourcePropType, ViewStyle} from 'react-native'; -import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import AttachmentModal from '@components/AttachmentModal'; import PressableWithoutFocus from '@components/Pressable/PressableWithoutFocus'; From ee4d711f9efcdafa5bbf63dabb587a3bba4a1e8f Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Mon, 5 Feb 2024 15:01:05 +0300 Subject: [PATCH 031/504] fix minor typescript issue --- src/components/ReportActionItem/ReportActionItemImage.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ReportActionItem/ReportActionItemImage.tsx b/src/components/ReportActionItem/ReportActionItemImage.tsx index 91f1e5310273..de12c15a0360 100644 --- a/src/components/ReportActionItem/ReportActionItemImage.tsx +++ b/src/components/ReportActionItem/ReportActionItemImage.tsx @@ -1,6 +1,7 @@ /* eslint-disable react/jsx-props-no-spreading */ import Str from 'expensify-common/lib/str'; import React from 'react'; +import type {ViewStyle} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import AttachmentModal from '@components/AttachmentModal'; import PressableWithoutFocus from '@components/Pressable/PressableWithoutFocus'; From 5f07c3970ce5a2889c428c3df65aeff7ba3b9f6d Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Tue, 6 Feb 2024 22:40:25 +0300 Subject: [PATCH 032/504] fix type --- src/types/onyx/Transaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index b559346a48de..8a1395d6d931 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -38,7 +38,7 @@ type Geometry = { type?: GeometryType; }; -type ReceiptSource = string | number; +type ReceiptSource = string; type Receipt = { receiptID?: number; From 8f8572152fc1bde10cccbddf69885eda5cc685e9 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Tue, 6 Feb 2024 23:22:16 +0300 Subject: [PATCH 033/504] fix based on comments --- src/components/EReceiptThumbnail.tsx | 6 +++++- src/components/ReceiptImage.tsx | 15 +++++++++++++++ src/styles/variables.ts | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index 4ccb6cfc7243..b5f709887478 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -26,7 +26,11 @@ type EReceiptThumbnailProps = EReceiptThumbnailOnyxProps & { /** TransactionID of the transaction this EReceipt corresponds to. It's used by withOnyx HOC */ // eslint-disable-next-line react/no-unused-prop-types transactionID: string; + + /** Border radius to be applied on the parent view. */ borderRadius?: number; + + /** The file extension of the receipt that the preview thumbnail is being displayed for. */ fileExtension?: string; /** Whether it is a receipt thumbnail we are displaying. */ @@ -89,7 +93,7 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isReceiptT primaryColor ? StyleUtils.getBackgroundColorStyle(primaryColor) : {}, styles.overflowHidden, styles.alignItemsCenter, - isReceiptThumbnail || (containerHeight && containerHeight < variables.eReceiptThumnailCenterReceiptBreakpoint) ? styles.justifyContentCenter : {}, + isReceiptThumbnail || (containerHeight && containerHeight < variables.eReceiptThumbnailCenterReceiptBreakpoint) ? styles.justifyContentCenter : {}, borderRadius ? {borderRadius} : {}, ]} onLayout={isReceiptThumbnail ? undefined : onContainerLayout} diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 5f15ea675ff4..9037fc29a4c0 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -8,13 +8,28 @@ import ThumbnailImage from './ThumbnailImage'; type Style = {height: number; borderRadius: number; margin: number}; type ReceiptImageProps = { + /** Transaction ID of the transaction the receipt belongs to. */ transactionID?: string; + + /** Whether it is receipt preview thumbnail we are displaying. */ isThumbnail?: boolean; + + /** Whether we should display the receipt with ThumbnailImage component */ shouldUseThumbnailImage?: boolean; + + /** Whether it is EReceipt */ isEReceipt?: boolean; + + /** Url of the receipt image */ source?: string; + + /** Whether the receipt image requires an authToken */ isAuthTokenRequired?: boolean; + + /** Any additional styles to apply */ style?: Style; + + /** The file extension of the receipt file */ fileExtension?: string; }; diff --git a/src/styles/variables.ts b/src/styles/variables.ts index 296780abf0ae..d5e930fc5bbc 100644 --- a/src/styles/variables.ts +++ b/src/styles/variables.ts @@ -163,7 +163,7 @@ export default { addBankAccountLeftSpacing: 3, eReceiptThumbnailSmallBreakpoint: 110, eReceiptThumbnailMediumBreakpoint: 335, - eReceiptThumnailCenterReceiptBreakpoint: 200, + eReceiptThumbnailCenterReceiptBreakpoint: 200, eReceiptIconHeight: 100, eReceiptIconWidth: 72, eReceiptMCCHeightWidth: 40, From 7b14b86bc6c7dd2b9e42990ae51c156b91d444c8 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Wed, 7 Feb 2024 17:24:56 +0300 Subject: [PATCH 034/504] fix type --- src/components/ReceiptImage.tsx | 36 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 9037fc29a4c0..f962b64ab7b9 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -7,22 +7,36 @@ import ThumbnailImage from './ThumbnailImage'; type Style = {height: number; borderRadius: number; margin: number}; -type ReceiptImageProps = { - /** Transaction ID of the transaction the receipt belongs to. */ - transactionID?: string; +type ReceiptImageProps = ( + | { + /** Transaction ID of the transaction the receipt belongs to */ + transactionID: string; - /** Whether it is receipt preview thumbnail we are displaying. */ - isThumbnail?: boolean; + /** Whether it is EReceipt */ + isEReceipt: boolean; + /** Whether it is receipt preview thumbnail we are displaying */ + isThumbnail?: boolean; + + /** Url of the receipt image */ + source?: string; + } + | { + transactionID: string; + isEReceipt?: boolean; + isThumbnail: boolean; + source?: string; + } + | { + transactionID?: string; + isEReceipt?: boolean; + isThumbnail?: boolean; + source: string; + } +) & { /** Whether we should display the receipt with ThumbnailImage component */ shouldUseThumbnailImage?: boolean; - /** Whether it is EReceipt */ - isEReceipt?: boolean; - - /** Url of the receipt image */ - source?: string; - /** Whether the receipt image requires an authToken */ isAuthTokenRequired?: boolean; From 2a1ddf3a50c5a6f02961c24d91b9893ce5e9bddc Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Wed, 7 Feb 2024 17:28:42 +0300 Subject: [PATCH 035/504] fix typescript --- src/components/ReportActionItem/ReportActionItemImage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportActionItemImage.tsx b/src/components/ReportActionItem/ReportActionItemImage.tsx index de12c15a0360..a1692a635a19 100644 --- a/src/components/ReportActionItem/ReportActionItemImage.tsx +++ b/src/components/ReportActionItem/ReportActionItemImage.tsx @@ -74,7 +74,7 @@ function ReportActionItemImage({ } else if (thumbnail && !isLocalFile && !Str.isPDF(imageSource)) { propsObj = {shouldUseThumbnailImage: true, source: thumbnailSource}; } else { - propsObj = {isThumbnail, fileExtension, transactionID: transaction?.transactionID, source: thumbnail ?? image}; + propsObj = {isThumbnail, fileExtension, transactionID: transaction?.transactionID, source: thumbnail ?? image ?? ''}; } if (enablePreviewModal) { From 6dfc00ba39dd529445e962455bec2caf2631a0a6 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Mon, 12 Feb 2024 23:59:10 +0300 Subject: [PATCH 036/504] minor change --- src/components/ReceiptImage.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index f962b64ab7b9..1f1cba77a873 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -2,6 +2,7 @@ import React from 'react'; import {View} from 'react-native'; import useThemeStyles from '@hooks/useThemeStyles'; import EReceiptThumbnail from './EReceiptThumbnail'; +import type {IconSize} from './EReceiptThumbnail'; import Image from './Image'; import ThumbnailImage from './ThumbnailImage'; @@ -20,6 +21,9 @@ type ReceiptImageProps = ( /** Url of the receipt image */ source?: string; + + /** number of images displayed in the same parent container */ + iconSize?: IconSize; } | { transactionID: string; From 4a086019a153bab8b3f7807cdfeba154a1a42466 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Tue, 13 Feb 2024 00:06:34 +0300 Subject: [PATCH 037/504] pass iconSize prop --- src/components/ReceiptImage.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 1f1cba77a873..4de2197b2b8c 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -21,9 +21,6 @@ type ReceiptImageProps = ( /** Url of the receipt image */ source?: string; - - /** number of images displayed in the same parent container */ - iconSize?: IconSize; } | { transactionID: string; @@ -49,13 +46,26 @@ type ReceiptImageProps = ( /** The file extension of the receipt file */ fileExtension?: string; + + /** number of images displayed in the same parent container */ + iconSize?: IconSize; }; -function ReceiptImage({transactionID, isThumbnail = false, shouldUseThumbnailImage = false, isEReceipt = false, source, isAuthTokenRequired, style, fileExtension}: ReceiptImageProps) { +function ReceiptImage({ + transactionID, + isThumbnail = false, + shouldUseThumbnailImage = false, + isEReceipt = false, + source, + isAuthTokenRequired, + style, + fileExtension, + iconSize, +}: ReceiptImageProps) { const styles = useThemeStyles(); if (isEReceipt || isThumbnail) { - const props = !isEReceipt && {borderRadius: style?.borderRadius, fileExtension, isReceiptThumbnail: true}; + const props = isEReceipt ? {iconSize} : {borderRadius: style?.borderRadius, fileExtension, isReceiptThumbnail: true}; return ( Date: Tue, 13 Feb 2024 22:07:54 +0300 Subject: [PATCH 038/504] use fetching waypoint function --- src/components/AttachmentModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index b1ec589a3d3e..6292dbed0a25 100755 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -523,7 +523,7 @@ function AttachmentModal({ setDownloadButtonVisibility={setDownloadButtonVisibility} /> ) : ( - (!!sourceForAttachmentView || Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) && + (!!sourceForAttachmentView || TransactionUtils.isFetchingWaypointsFromServer(transaction)) && shouldLoadAttachment && !isLoading && !shouldShowNotFoundPage && ( From 32268d427b0fa9ab3fff4f8232a3ae9541948f48 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 15 Feb 2024 14:11:29 +0100 Subject: [PATCH 039/504] ref: move TagPicker to TS --- src/ONYXKEYS.ts | 2 +- .../ReportActionItem/MoneyRequestView.tsx | 3 +- src/components/TagPicker/index.js | 94 ------------ src/components/TagPicker/index.tsx | 135 ++++++++++++++++++ .../TagPicker/tagPickerPropTypes.js | 41 ------ src/libs/OptionsListUtils.ts | 36 ++--- src/libs/PolicyUtils.ts | 7 +- src/types/onyx/PolicyTag.ts | 7 +- 8 files changed, 160 insertions(+), 165 deletions(-) delete mode 100644 src/components/TagPicker/index.js create mode 100644 src/components/TagPicker/index.tsx delete mode 100644 src/components/TagPicker/tagPickerPropTypes.js diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 5e41e08d0c78..d66182938465 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -429,7 +429,7 @@ type OnyxCollectionValuesMapping = { [ONYXKEYS.COLLECTION.POLICY]: OnyxTypes.Policy; [ONYXKEYS.COLLECTION.POLICY_DRAFTS]: OnyxTypes.Policy; [ONYXKEYS.COLLECTION.POLICY_CATEGORIES]: OnyxTypes.PolicyCategories; - [ONYXKEYS.COLLECTION.POLICY_TAGS]: OnyxTypes.PolicyTags; + [ONYXKEYS.COLLECTION.POLICY_TAGS]: OnyxTypes.PolicyTagList; [ONYXKEYS.COLLECTION.POLICY_MEMBERS]: OnyxTypes.PolicyMembers; [ONYXKEYS.COLLECTION.POLICY_MEMBERS_DRAFTS]: OnyxTypes.PolicyMember; [ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES]: OnyxTypes.RecentlyUsedCategories; diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 6b16f272e4c8..cc723b7288cb 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -55,7 +55,7 @@ type MoneyRequestViewOnyxPropsWithoutTransaction = { policyCategories: OnyxEntry; /** Collection of tags attached to a policy */ - policyTags: OnyxEntry; + policyTags: OnyxEntry; /** The expense report or iou report (only will have a value if this is a transaction thread) */ parentReport: OnyxEntry; @@ -155,7 +155,6 @@ function MoneyRequestView({ Navigation.dismissModal(); return; } - // @ts-expect-error: the type used across the app for policyTags is not what is returned by Onyx, PolicyTagList represents that, but existing policy tag utils need a refactor to fix this IOU.updateMoneyRequestBillable(transaction?.transactionID ?? '', report?.reportID, newBillable, policy, policyTags, policyCategories); Navigation.dismissModal(); }, diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js deleted file mode 100644 index e258472eae93..000000000000 --- a/src/components/TagPicker/index.js +++ /dev/null @@ -1,94 +0,0 @@ -import lodashGet from 'lodash/get'; -import React, {useMemo, useState} from 'react'; -import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; -import OptionsSelector from '@components/OptionsSelector'; -import useLocalize from '@hooks/useLocalize'; -import useStyleUtils from '@hooks/useStyleUtils'; -import useThemeStyles from '@hooks/useThemeStyles'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; -import * as PolicyUtils from '@libs/PolicyUtils'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import {defaultProps, propTypes} from './tagPickerPropTypes'; - -function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, shouldShowDisabledAndSelectedOption, insets, onSubmit}) { - const styles = useThemeStyles(); - const StyleUtils = useStyleUtils(); - const {translate} = useLocalize(); - const [searchValue, setSearchValue] = useState(''); - - const policyRecentlyUsedTagsList = lodashGet(policyRecentlyUsedTags, tag, []); - const policyTagList = PolicyUtils.getTagList(policyTags, tag); - const policyTagsCount = _.size(_.filter(policyTagList, (policyTag) => policyTag.enabled)); - const isTagsCountBelowThreshold = policyTagsCount < CONST.TAG_LIST_THRESHOLD; - - const shouldShowTextInput = !isTagsCountBelowThreshold; - - const selectedOptions = useMemo(() => { - if (!selectedTag) { - return []; - } - - return [ - { - name: selectedTag, - enabled: true, - accountID: null, - }, - ]; - }, [selectedTag]); - - const enabledTags = useMemo(() => { - if (!shouldShowDisabledAndSelectedOption) { - return policyTagList; - } - const selectedNames = _.map(selectedOptions, (s) => s.name); - const tags = [...selectedOptions, ..._.filter(policyTagList, (policyTag) => policyTag.enabled && !selectedNames.includes(policyTag.name))]; - return tags; - }, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]); - - const sections = useMemo( - () => OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, false, {}, [], true, enabledTags, policyRecentlyUsedTagsList, false).tagOptions, - [searchValue, enabledTags, selectedOptions, policyRecentlyUsedTagsList], - ); - - const headerMessage = OptionsListUtils.getHeaderMessageForNonUserList(lodashGet(sections, '[0].data.length', 0) > 0, searchValue); - - const selectedOptionKey = lodashGet(_.filter(lodashGet(sections, '[0].data', []), (policyTag) => policyTag.searchText === selectedTag)[0], 'keyForList'); - - return ( - - ); -} - -TagPicker.displayName = 'TagPicker'; -TagPicker.propTypes = propTypes; -TagPicker.defaultProps = defaultProps; - -export default withOnyx({ - policyTags: { - key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, - }, - policyRecentlyUsedTags: { - key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${policyID}`, - }, -})(TagPicker); diff --git a/src/components/TagPicker/index.tsx b/src/components/TagPicker/index.tsx new file mode 100644 index 000000000000..48ef977a1225 --- /dev/null +++ b/src/components/TagPicker/index.tsx @@ -0,0 +1,135 @@ +import React, {useMemo, useState} from 'react'; +import type {OnyxEntry} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; +import type {EdgeInsets} from 'react-native-safe-area-context'; +import OptionsSelector from '@components/OptionsSelector'; +import useLocalize from '@hooks/useLocalize'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useThemeStyles from '@hooks/useThemeStyles'; +import * as OptionsListUtils from '@libs/OptionsListUtils'; +import * as PolicyUtils from '@libs/PolicyUtils'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {PolicyTag, PolicyTagList, PolicyTags, RecentlyUsedTags} from '@src/types/onyx'; + +type SelectedTagOption = { + name: string; + enabled?: boolean; + accountID: number | null; +}; + +type TagPickerOnyxProps = { + /** Collection of tags attached to a policy */ + policyTags: OnyxEntry; + + /** List of recently used tags */ + policyRecentlyUsedTags: OnyxEntry; +}; + +type TagPickerProps = TagPickerOnyxProps & { + /** The policyID we are getting tags for */ + // It's used in withOnyx HOC. + // eslint-disable-next-line react/no-unused-prop-types + policyID: string; + + /** The selected tag of the money request */ + selectedTag: string; + + /** The name of tag list we are getting tags for */ + tag: string; + + /** Callback to submit the selected tag */ + onSubmit: () => void; + + /** + * Safe area insets required for reflecting the portion of the view, + * that is not covered by navigation bars, tab bars, toolbars, and other ancestor views. + */ + insets: EdgeInsets; + + /** Should show the selected option that is disabled? */ + shouldShowDisabledAndSelectedOption?: boolean; +}; + +function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, shouldShowDisabledAndSelectedOption = false, insets, onSubmit}: TagPickerProps) { + const styles = useThemeStyles(); + const StyleUtils = useStyleUtils(); + const {translate} = useLocalize(); + const [searchValue, setSearchValue] = useState(''); + + const policyTagList = PolicyUtils.getTagList(policyTags, tag); + const policyTagsCount = Object.values(policyTagList).filter((policyTag) => policyTag.enabled).length; + const isTagsCountBelowThreshold = policyTagsCount < CONST.TAG_LIST_THRESHOLD; + + const shouldShowTextInput = !isTagsCountBelowThreshold; + + const selectedOptions: SelectedTagOption[] = useMemo(() => { + if (!selectedTag) { + return []; + } + + return [ + { + name: selectedTag, + enabled: true, + accountID: null, + }, + ]; + }, [selectedTag]); + + const enabledTags: PolicyTags | Array = useMemo(() => { + if (!shouldShowDisabledAndSelectedOption) { + return policyTagList; + } + const selectedNames = selectedOptions.map((s) => s.name); + + return [...selectedOptions, ...Object.values(policyTagList).filter((policyTag) => policyTag.enabled && !selectedNames.includes(policyTag.name))]; + }, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]); + + const sections = useMemo(() => { + const policyRecentlyUsedTagsList = policyRecentlyUsedTags?.tag ?? []; + + return OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, false, {}, [], true, enabledTags, policyRecentlyUsedTagsList, false) + .tagOptions; + }, [searchValue, enabledTags, selectedOptions, policyRecentlyUsedTags?.tag]); + + const headerMessage = OptionsListUtils.getHeaderMessageForNonUserList((sections?.[0]?.data?.length ?? 0) > 0, searchValue); + + const selectedOptionKey = sections[0]?.data?.filter((policyTag) => policyTag.searchText === selectedTag)?.[0]?.keyForList; + + return ( + + ); +} + +TagPicker.displayName = 'TagPicker'; + +export default withOnyx({ + policyTags: { + key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, + }, + policyRecentlyUsedTags: { + key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${policyID}`, + }, +})(TagPicker); + +export type {SelectedTagOption}; diff --git a/src/components/TagPicker/tagPickerPropTypes.js b/src/components/TagPicker/tagPickerPropTypes.js deleted file mode 100644 index b98f7f6ef8e9..000000000000 --- a/src/components/TagPicker/tagPickerPropTypes.js +++ /dev/null @@ -1,41 +0,0 @@ -import PropTypes from 'prop-types'; -import tagPropTypes from '@components/tagPropTypes'; -import safeAreaInsetPropTypes from '@pages/safeAreaInsetPropTypes'; - -const propTypes = { - /** The policyID we are getting tags for */ - policyID: PropTypes.string.isRequired, - - /** The selected tag of the money request */ - selectedTag: PropTypes.string.isRequired, - - /** The name of tag list we are getting tags for */ - tag: PropTypes.string.isRequired, - - /** Callback to submit the selected tag */ - onSubmit: PropTypes.func.isRequired, - - /** - * Safe area insets required for reflecting the portion of the view, - * that is not covered by navigation bars, tab bars, toolbars, and other ancestor views. - */ - insets: safeAreaInsetPropTypes.isRequired, - - /* Onyx Props */ - /** Collection of tags attached to a policy */ - policyTags: tagPropTypes, - - /** List of recently used tags */ - policyRecentlyUsedTags: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.string)), - - /** Should show the selected option that is disabled? */ - shouldShowDisabledAndSelectedOption: PropTypes.bool, -}; - -const defaultProps = { - policyTags: {}, - policyRecentlyUsedTags: {}, - shouldShowDisabledAndSelectedOption: false, -}; - -export {propTypes, defaultProps}; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 346cc71953e6..30b022862987 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -7,6 +7,7 @@ import lodashSet from 'lodash/set'; import lodashSortBy from 'lodash/sortBy'; import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import type {SelectedTagOption} from '@components/TagPicker'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -19,6 +20,7 @@ import type { PolicyCategories, PolicyCategory, PolicyTag, + PolicyTags, Report, ReportAction, ReportActions, @@ -50,12 +52,6 @@ import * as TaskUtils from './TaskUtils'; import * as TransactionUtils from './TransactionUtils'; import * as UserUtils from './UserUtils'; -type Tag = { - enabled: boolean; - name: string; - accountID: number | null; -}; - type Option = Partial; type PayeePersonalDetails = { @@ -106,7 +102,7 @@ type GetOptionsConfig = { categories?: PolicyCategories; recentlyUsedCategories?: string[]; includeTags?: boolean; - tags?: Record; + tags?: PolicyTags | Array; recentlyUsedTags?: string[]; canInviteUser?: boolean; includeSelectedOptions?: boolean; @@ -866,16 +862,8 @@ function sortCategories(categories: Record): Category[] { /** * Sorts tags alphabetically by name. */ -function sortTags(tags: Record | Tag[]) { - let sortedTags; - - if (Array.isArray(tags)) { - sortedTags = tags.sort((a, b) => a.name.localeCompare(b.name)); - } else { - sortedTags = Object.values(tags).sort((a, b) => a.name.localeCompare(b.name)); - } - - return sortedTags; +function sortTags(tags: Array) { + return tags.sort((a, b) => a.name?.localeCompare(b.name)); } /** @@ -1038,7 +1026,7 @@ function getCategoryListSections( * * @param tags - an initial tag array */ -function getTagsOptions(tags: Category[]): Option[] { +function getTagsOptions(tags: Array>): Option[] { return tags.map((tag) => { // This is to remove unnecessary escaping backslash in tag name sent from backend. const cleanedName = PolicyUtils.getCleanedTagName(tag.name); @@ -1055,7 +1043,13 @@ function getTagsOptions(tags: Category[]): Option[] { /** * Build the section list for tags */ -function getTagListSections(tags: Tag[], recentlyUsedTags: string[], selectedOptions: Category[], searchInputValue: string, maxRecentReportsToShow: number) { +function getTagListSections( + tags: Array, + recentlyUsedTags: string[], + selectedOptions: SelectedTagOption[], + searchInputValue: string, + maxRecentReportsToShow: number, +) { const tagSections = []; const sortedTags = sortTags(tags); const enabledTags = sortedTags.filter((tag) => tag.enabled); @@ -1367,7 +1361,7 @@ function getOptions( } if (includeTags) { - const tagOptions = getTagListSections(Object.values(tags), recentlyUsedTags, selectedOptions as Category[], searchInputValue, maxRecentReportsToShow); + const tagOptions = getTagListSections(Object.values(tags), recentlyUsedTags, selectedOptions as SelectedTagOption[], searchInputValue, maxRecentReportsToShow); return { recentReports: [], @@ -1767,7 +1761,7 @@ function getFilteredOptions( categories: PolicyCategories = {}, recentlyUsedCategories: string[] = [], includeTags = false, - tags: Record = {}, + tags: PolicyTags | Array = {}, recentlyUsedTags: string[] = [], canInviteUser = true, includeSelectedOptions = false, diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 90dfa8fde339..d80bff0f43a3 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -3,7 +3,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTag, PolicyTags} from '@src/types/onyx'; +import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTag, PolicyTagList, PolicyTags} from '@src/types/onyx'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -155,13 +155,12 @@ function getIneligibleInvitees(policyMembers: OnyxEntry, personal /** * Gets the tag from policy tags, defaults to the first if no key is provided. */ -function getTag(policyTags: OnyxEntry, tagKey?: keyof typeof policyTags): PolicyTag | undefined | EmptyObject { +function getTag(policyTags: OnyxEntry, tagKey?: keyof typeof policyTags): PolicyTag | undefined | EmptyObject { if (isEmptyObject(policyTags)) { return {}; } const policyTagKey = tagKey ?? Object.keys(policyTags ?? {})[0]; - return policyTags?.[policyTagKey] ?? {}; } @@ -181,7 +180,7 @@ function getTagListName(policyTags: OnyxEntry) { /** * Gets the tags of a policy for a specific key. Defaults to the first tag if no key is provided. */ -function getTagList(policyTags: OnyxCollection, tagKey: string) { +function getTagList(policyTags: OnyxEntry, tagKey: string) { if (Object.keys(policyTags ?? {})?.length === 0) { return {}; } diff --git a/src/types/onyx/PolicyTag.ts b/src/types/onyx/PolicyTag.ts index ff688419605d..33e6ef4f7bb1 100644 --- a/src/types/onyx/PolicyTag.ts +++ b/src/types/onyx/PolicyTag.ts @@ -3,14 +3,17 @@ type PolicyTag = { name: string; /** Flag that determines if a tag is active and able to be selected */ - enabled: boolean; + enabled?: boolean; /** "General Ledger code" that corresponds to this tag in an accounting system. Similar to an ID. */ // eslint-disable-next-line @typescript-eslint/naming-convention - 'GL Code': string; + 'GL Code'?: string; /** Nested tags */ tags: PolicyTags; + + /** Flag that determines if a tag is required */ + required: boolean; }; type PolicyTags = Record; From b028f9d7fd2a5f4fe6cf0d78f28787d9fe009263 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 16 Feb 2024 11:46:10 +0700 Subject: [PATCH 040/504] display total and money request in offline --- src/pages/home/report/ReportActionsView.js | 49 +++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 064187855b57..8378cab1be8a 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -12,10 +12,13 @@ import useCopySelectionHelper from '@hooks/useCopySelectionHelper'; import useInitialValue from '@hooks/useInitialValue'; import usePrevious from '@hooks/usePrevious'; import compose from '@libs/compose'; +import DateUtils from '@libs/DateUtils'; import getIsReportFullyVisible from '@libs/getIsReportFullyVisible'; +import * as NumberUtils from '@libs/NumberUtils'; import Performance from '@libs/Performance'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import {isUserCreatedPolicyRoom} from '@libs/ReportUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import {didUserLogInDuringSession} from '@libs/SessionUtils'; import {ReactionListContext} from '@pages/home/ReportScreenContext'; import reportPropTypes from '@pages/reportPropTypes'; @@ -245,6 +248,50 @@ function ReportActionsView(props) { } }, [hasCachedActions]); + const reportActionsToDisplay = useMemo(() => { + if (!ReportUtils.isMoneyRequestReport(props.report) || !_.size(props.reportActions)) { + return props.reportActions; + } + + const actions = [...props.reportActions]; + + if (!ReportActionsUtils.isCreatedAction(_.last(props.reportActions))) { + const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction( + props.report.ownerAccountID, + DateUtils.subtractMillisecondsFromDateTime(_.last(props.reportActions).created, 1), + ); + actions.push(optimisticCreatedAction); + } + + if ( + props.report.total && + _.filter( + props.reportActions, + (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE, + ).length === 0 + ) { + const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( + CONST.IOU.REPORT_ACTION_TYPE.CREATE, + 0, + CONST.CURRENCY.USD, + '', + [], + NumberUtils.rand64(), + undefined, + props.report.reportID, + false, + false, + {}, + false, + DateUtils.subtractMillisecondsFromDateTime(_.last(actions).created, 1), + ); + + actions.splice(actions.length - 1, 0, optimisticIOUAction); + } + + return actions; + }, [props.reportActions, props.report]); + // Comments have not loaded at all yet do nothing if (!_.size(props.reportActions)) { return null; @@ -255,7 +302,7 @@ function ReportActionsView(props) { Date: Tue, 20 Feb 2024 23:18:37 +0300 Subject: [PATCH 041/504] fix type --- src/components/DistanceEReceipt.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/DistanceEReceipt.tsx b/src/components/DistanceEReceipt.tsx index ae6516edf266..b22d21ba8d8a 100644 --- a/src/components/DistanceEReceipt.tsx +++ b/src/components/DistanceEReceipt.tsx @@ -29,7 +29,7 @@ function DistanceEReceipt({transaction}: DistanceEReceiptProps) { const thumbnail = TransactionUtils.hasReceipt(transaction) ? ReceiptUtils.getThumbnailAndImageURIs(transaction).thumbnail : null; const {amount: transactionAmount, currency: transactionCurrency, merchant: transactionMerchant, created: transactionDate} = ReportUtils.getTransactionDetails(transaction) ?? {}; const formattedTransactionAmount = CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency); - const thumbnailSource = tryResolveUrlFromApiRoot((thumbnail as string) || ''); + const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail ?? ''); const waypoints = useMemo(() => transaction?.comment?.waypoints ?? {}, [transaction?.comment?.waypoints]); const sortedWaypoints = useMemo( () => From 4a490435850ad70029ec468d832781b496b2ef50 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 21 Feb 2024 16:25:25 +0700 Subject: [PATCH 042/504] add explain comment --- src/pages/home/report/ReportActionsView.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 8378cab1be8a..e7e5743ce0b0 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -248,6 +248,11 @@ function ReportActionsView(props) { } }, [hasCachedActions]); + // When we offline before opening a money request report, + // the total of the report and sometimes the money request aren't displayed because these actions aren't returned until `OpenReport` API is complete. + // We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data + // and we also generate a money request action if there is no such action to display at least one money request action to match the total data. + // For more details: https://github.com/Expensify/App/issues/26424#issuecomment-1869154198 const reportActionsToDisplay = useMemo(() => { if (!ReportUtils.isMoneyRequestReport(props.report) || !_.size(props.reportActions)) { return props.reportActions; From dd6fb2d3c991fc52b297c4ea6cfbd2a56bdfe06f Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 21 Feb 2024 16:45:14 +0700 Subject: [PATCH 043/504] fix lint --- src/pages/home/report/ReportActionsView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index e7e5743ce0b0..abdd0aa6386e 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -248,7 +248,7 @@ function ReportActionsView(props) { } }, [hasCachedActions]); - // When we offline before opening a money request report, + // When we offline before opening a money request report, // the total of the report and sometimes the money request aren't displayed because these actions aren't returned until `OpenReport` API is complete. // We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data // and we also generate a money request action if there is no such action to display at least one money request action to match the total data. From e154fea0ed57c106935d2558b6b1d26cc738f8de Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Wed, 21 Feb 2024 13:41:22 +0100 Subject: [PATCH 044/504] fix: missing value --- src/components/TagPicker/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/TagPicker/index.tsx b/src/components/TagPicker/index.tsx index 917351e68228..b553e183a37f 100644 --- a/src/components/TagPicker/index.tsx +++ b/src/components/TagPicker/index.tsx @@ -62,7 +62,7 @@ function TagPicker({selectedTag, tag, policyTags, tagIndex, policyRecentlyUsedTa const policyRecentlyUsedTagsList = useMemo(() => policyRecentlyUsedTags?.[tag] ?? [], [policyRecentlyUsedTags, tag]); const policyTagList = PolicyUtils.getTagList(policyTags, tagIndex); - const policyTagsCount = PolicyUtils.getCountOfEnabledTagsOfList(policyTagList); + const policyTagsCount = PolicyUtils.getCountOfEnabledTagsOfList(policyTagList.tags); const isTagsCountBelowThreshold = policyTagsCount < CONST.TAG_LIST_THRESHOLD; const shouldShowTextInput = !isTagsCountBelowThreshold; From c44b4309b00d1f91d8220a162513b05493491b81 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 21 Feb 2024 18:09:50 +0300 Subject: [PATCH 045/504] add fallbackIcon --- src/components/ReceiptImage.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index 4de2197b2b8c..f293d3b047d5 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -1,6 +1,7 @@ import React from 'react'; import {View} from 'react-native'; import useThemeStyles from '@hooks/useThemeStyles'; +import type IconAsset from '@src/types/utils/IconAsset'; import EReceiptThumbnail from './EReceiptThumbnail'; import type {IconSize} from './EReceiptThumbnail'; import Image from './Image'; @@ -49,6 +50,12 @@ type ReceiptImageProps = ( /** number of images displayed in the same parent container */ iconSize?: IconSize; + + /** If the image fails to load – show the provided fallback icon */ + fallbackIcon?: IconAsset; + + /** The size of the fallback icon */ + fallbackIconSize?: number; }; function ReceiptImage({ @@ -61,6 +68,8 @@ function ReceiptImage({ style, fileExtension, iconSize, + fallbackIcon, + fallbackIconSize, }: ReceiptImageProps) { const styles = useThemeStyles(); @@ -84,6 +93,8 @@ function ReceiptImage({ style={[styles.w100, styles.h100]} isAuthTokenRequired shouldDynamicallyResize={false} + fallbackIcon={fallbackIcon} + fallbackIconSize={fallbackIconSize} /> ); } From 7025bfa7b10a6c36d788f9804ac627d6156e7e67 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 21 Feb 2024 18:30:35 +0300 Subject: [PATCH 046/504] applied dynamic thumbnail icon size --- src/components/ReceiptImage.tsx | 3 ++- src/components/ReportActionItem/ReportActionItemImage.tsx | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index f293d3b047d5..cd70413b7a2e 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -74,11 +74,12 @@ function ReceiptImage({ const styles = useThemeStyles(); if (isEReceipt || isThumbnail) { - const props = isEReceipt ? {iconSize} : {borderRadius: style?.borderRadius, fileExtension, isReceiptThumbnail: true}; + const props = isThumbnail && {borderRadius: style?.borderRadius, fileExtension, isReceiptThumbnail: true}; return ( diff --git a/src/components/ReportActionItem/ReportActionItemImage.tsx b/src/components/ReportActionItem/ReportActionItemImage.tsx index 0f6131a61c05..cc84abccd6d1 100644 --- a/src/components/ReportActionItem/ReportActionItemImage.tsx +++ b/src/components/ReportActionItem/ReportActionItemImage.tsx @@ -86,7 +86,13 @@ function ReportActionItemImage({ fallbackIconSize: isSingleImage ? variables.iconSizeSuperLarge : variables.iconSizeExtraLarge, }; } else { - propsObj = {isThumbnail, fileExtension, transactionID: transaction?.transactionID, source: thumbnail ?? image ?? ''}; + propsObj = { + isThumbnail, + ...(isThumbnail && {iconSize: isSingleImage ? 'medium' : ('small' as IconSize)}), + fileExtension, + transactionID: transaction?.transactionID, + source: thumbnail ?? image ?? '', + }; } if (enablePreviewModal) { From d6493cf11cc65df8a3c216ebbf7ed7c7ff3296e3 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 22 Feb 2024 10:44:19 +0700 Subject: [PATCH 047/504] update logic to add money request action --- src/pages/home/report/ReportActionsView.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index abdd0aa6386e..29ce6af76a27 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -248,10 +248,11 @@ function ReportActionsView(props) { } }, [hasCachedActions]); - // When we offline before opening a money request report, + // When we are offline before opening a money request report, // the total of the report and sometimes the money request aren't displayed because these actions aren't returned until `OpenReport` API is complete. // We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data - // and we also generate a money request action if there is no such action to display at least one money request action to match the total data. + // and we also generate a money request action if If the number of money requests in reportActions is less than the total number of money requests + // to display at least one money request action to match the total data. // For more details: https://github.com/Expensify/App/issues/26424#issuecomment-1869154198 const reportActionsToDisplay = useMemo(() => { if (!ReportUtils.isMoneyRequestReport(props.report) || !_.size(props.reportActions)) { @@ -268,12 +269,14 @@ function ReportActionsView(props) { actions.push(optimisticCreatedAction); } + const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(props.report.chatReportID, props.report.reportID); + if ( props.report.total && _.filter( props.reportActions, (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE, - ).length === 0 + ).length < reportPreviewAction.childMoneyRequestCount ) { const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.CREATE, From e76216c619141ec2b0c8a504008b623a196aba1a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 23 Feb 2024 15:02:30 +0700 Subject: [PATCH 048/504] only grey out the total if have some requests are pending --- src/pages/home/report/ReportActionsView.js | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 29ce6af76a27..df487693e0cd 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -259,25 +259,24 @@ function ReportActionsView(props) { return props.reportActions; } - const actions = [...props.reportActions]; + let actions = [...props.reportActions]; if (!ReportActionsUtils.isCreatedAction(_.last(props.reportActions))) { const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction( props.report.ownerAccountID, DateUtils.subtractMillisecondsFromDateTime(_.last(props.reportActions).created, 1), ); + optimisticCreatedAction.pendingAction = null; actions.push(optimisticCreatedAction); } const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(props.report.chatReportID, props.report.reportID); + const moneyRequestActions = _.filter( + props.reportActions, + (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE, + ); - if ( - props.report.total && - _.filter( - props.reportActions, - (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE, - ).length < reportPreviewAction.childMoneyRequestCount - ) { + if (props.report.total && moneyRequestActions.length < reportPreviewAction.childMoneyRequestCount) { const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.CREATE, 0, @@ -293,11 +292,18 @@ function ReportActionsView(props) { false, DateUtils.subtractMillisecondsFromDateTime(_.last(actions).created, 1), ); - + moneyRequestActions.push(optimisticIOUAction); actions.splice(actions.length - 1, 0, optimisticIOUAction); } - return actions; + // Update pending action of created action if we have some requests that are pending + const createdAction = _.last(actions); + actions = _.without(actions, createdAction); + if (_.filter(moneyRequestActions, (action) => !!action.pendingAction).length > 0) { + createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE; + } + + return [...actions, createdAction]; }, [props.reportActions, props.report]); // Comments have not loaded at all yet do nothing From 9eb1edd18a8545774e4114ec3d35a6073be0e3ef Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Mon, 26 Feb 2024 12:22:43 +0300 Subject: [PATCH 049/504] use primary color for label text color --- src/components/EReceiptThumbnail.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index 5093e2853e18..f6d5beb7e24d 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -105,7 +105,9 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isReceiptT fill={secondaryColor} additionalStyles={[styles.fullScreen]} /> - {isReceiptThumbnail && fileExtension && {fileExtension.toUpperCase()}} + {isReceiptThumbnail && fileExtension && ( + {fileExtension.toUpperCase()} + )} {MCCIcon && !isReceiptThumbnail ? ( Date: Mon, 26 Feb 2024 15:26:54 +0100 Subject: [PATCH 050/504] feat: memoize SidebarLinksData --- src/pages/home/sidebar/SidebarLinksData.js | 41 ++++++++++++++-------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index c4cc0713c596..0c8125cae79f 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -2,7 +2,7 @@ import {deepEqual} from 'fast-equals'; import lodashGet from 'lodash/get'; import lodashMap from 'lodash/map'; import PropTypes from 'prop-types'; -import React, {useCallback, useEffect, useMemo, useRef} from 'react'; +import React, {memo, useCallback, useEffect, useMemo, useRef} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -136,18 +136,14 @@ function SidebarLinksData({ const reportIDsRef = useRef(null); const isLoading = isLoadingApp; + + const optionItemsMemoized = useMemo( + () => SidebarUtils.getOrderedReportIDs(null, chatReports, betas, policies, priorityMode, allReportActions, transactionViolations, activeWorkspaceID, policyMemberAccountIDs), + [chatReports, betas, policies, priorityMode, allReportActions, transactionViolations, activeWorkspaceID, policyMemberAccountIDs], + ); + const optionListItems = useMemo(() => { - const reportIDs = SidebarUtils.getOrderedReportIDs( - null, - chatReports, - betas, - policies, - priorityMode, - allReportActions, - transactionViolations, - activeWorkspaceID, - policyMemberAccountIDs, - ); + const reportIDs = optionItemsMemoized; if (deepEqual(reportIDsRef.current, reportIDs)) { return reportIDsRef.current; @@ -160,7 +156,7 @@ function SidebarLinksData({ reportIDsRef.current = reportIDs; } return reportIDsRef.current || []; - }, [chatReports, betas, policies, priorityMode, allReportActions, transactionViolations, activeWorkspaceID, policyMemberAccountIDs, isLoading, network.isOffline, prevPriorityMode]); + }, [optionItemsMemoized, priorityMode, isLoading, network.isOffline, prevPriorityMode]); // We need to make sure the current report is in the list of reports, but we do not want // to have to re-generate the list every time the currentReportID changes. To do that @@ -334,4 +330,21 @@ export default compose( initialValue: {}, }, }), -)(SidebarLinksData); +)( + memo( + SidebarLinksData, + (prevProps, nextProps) => + _.isEqual(prevProps.chatReports, nextProps.chatReports) && + _.isEqual(prevProps.allReportActions, nextProps.allReportActions) && + prevProps.isLoadingApp === nextProps.isLoadingApp && + prevProps.priorityMode === nextProps.priorityMode && + _.isEqual(prevProps.betas, nextProps.betas) && + _.isEqual(prevProps.policies, nextProps.policies) && + prevProps.network.isOffline === nextProps.network.isOffline && + _.isEqual(prevProps.insets, nextProps.insets) && + prevProps.onLinkClick === nextProps.onLinkClick && + _.isEqual(prevProps.policyMembers, nextProps.policyMembers) && + _.isEqual(prevProps.transactionViolations, nextProps.transactionViolations) && + _.isEqual(prevProps.currentUserPersonalDetails, nextProps.currentUserPersonalDetails), + ), +); From 79d94952cafce2cc05726e4fe29a397346945c13 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Mon, 26 Feb 2024 14:45:58 +0000 Subject: [PATCH 051/504] refactor(typescript): migrate multiple tests and utils --- src/libs/OptionsListUtils.ts | 2 +- src/libs/ReportUtils.ts | 2 +- .../output/{markdown.js => markdown.ts} | 51 ++- tests/e2e/compare/types.ts | 57 ++++ tests/e2e/measure/math.ts | 11 +- tests/e2e/utils/logger.js | 10 +- ...erf-test.js => SidebarLinks.perf-test.tsx} | 22 +- .../{DateUtilsTest.js => DateUtilsTest.ts} | 55 ++-- ...stUtilsTest.js => OptionsListUtilsTest.ts} | 307 ++++++++++++------ ...{ReportUtilsTest.js => ReportUtilsTest.ts} | 230 +++++++------ 10 files changed, 467 insertions(+), 280 deletions(-) rename tests/e2e/compare/output/{markdown.js => markdown.ts} (59%) create mode 100644 tests/e2e/compare/types.ts rename tests/perf-test/{SidebarLinks.perf-test.js => SidebarLinks.perf-test.tsx} (85%) rename tests/unit/{DateUtilsTest.js => DateUtilsTest.ts} (85%) rename tests/unit/{OptionsListUtilsTest.js => OptionsListUtilsTest.ts} (89%) rename tests/unit/{ReportUtilsTest.js => ReportUtilsTest.ts} (80%) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 97b4fc0144c8..e4ec9da4dc12 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2048,4 +2048,4 @@ export { getShareLogOptions, }; -export type {MemberForList, CategorySection, GetOptions}; +export type {MemberForList, CategorySection, GetOptions, PolicyTaxRateWithDefault, Tag}; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ae6e02e70d29..d981309f0285 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -938,7 +938,7 @@ function filterReportsByPolicyIDAndMemberAccountIDs(reports: Report[], policyMem /** * Given an array of reports, return them sorted by the last read timestamp. */ -function sortReportsByLastRead(reports: Report[], reportMetadata: OnyxCollection): Array> { +function sortReportsByLastRead(reports: Array>, reportMetadata: OnyxCollection): Array> { return reports .filter((report) => !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime)) .sort((a, b) => { diff --git a/tests/e2e/compare/output/markdown.js b/tests/e2e/compare/output/markdown.ts similarity index 59% rename from tests/e2e/compare/output/markdown.js rename to tests/e2e/compare/output/markdown.ts index 119830a5bb2c..07cf9897e570 100644 --- a/tests/e2e/compare/output/markdown.js +++ b/tests/e2e/compare/output/markdown.ts @@ -1,35 +1,34 @@ // From: https://raw.githubusercontent.com/callstack/reassure/main/packages/reassure-compare/src/output/markdown.ts import fs from 'node:fs/promises'; import path from 'path'; -import _ from 'underscore'; import * as Logger from '../../utils/logger'; +import type {AddedEntry, CompareEntry, CompareResult, PerformanceEntry, RemovedEntry} from '../types'; import * as format from './format'; import markdownTable from './markdownTable'; const tableHeader = ['Name', 'Duration']; -const collapsibleSection = (title, content) => `
\n${title}\n\n${content}\n
\n\n`; +const collapsibleSection = (title: string, content: string): string => `
\n${title}\n\n${content}\n
\n\n`; -const buildDurationDetails = (title, entry) => { +const buildDurationDetails = (title: string, entry: PerformanceEntry): string => { const relativeStdev = entry.stdev / entry.mean; - return _.filter( - [ - `**${title}**`, - `Mean: ${format.formatDuration(entry.mean)}`, - `Stdev: ${format.formatDuration(entry.stdev)} (${format.formatPercent(relativeStdev)})`, - entry.entries ? `Runs: ${entry.entries.join(' ')}` : '', - ], - Boolean, - ).join('
'); + return [ + `**${title}**`, + `Mean: ${format.formatDuration(entry.mean)}`, + `Stdev: ${format.formatDuration(entry.stdev)} (${format.formatPercent(relativeStdev)})`, + entry.entries ? `Runs: ${entry.entries.join(' ')}` : '', + ] + .filter(Boolean) + .join('
'); }; -const buildDurationDetailsEntry = (entry) => - _.filter(['baseline' in entry ? buildDurationDetails('Baseline', entry.baseline) : '', 'current' in entry ? buildDurationDetails('Current', entry.current) : ''], Boolean).join( - '

', - ); +const buildDurationDetailsEntry = (entry: CompareEntry | AddedEntry | RemovedEntry): string => + ['baseline' in entry ? buildDurationDetails('Baseline', entry.baseline) : '', 'current' in entry ? buildDurationDetails('Current', entry.current) : ''] + .filter(Boolean) + .join('

'); -const formatEntryDuration = (entry) => { +const formatEntryDuration = (entry: CompareEntry | AddedEntry | RemovedEntry): string => { if ('baseline' in entry && 'current' in entry) { return format.formatDurationDiffChange(entry); } @@ -42,39 +41,39 @@ const formatEntryDuration = (entry) => { return ''; }; -const buildDetailsTable = (entries) => { +const buildDetailsTable = (entries: Array): string => { if (!entries.length) { return ''; } - const rows = _.map(entries, (entry) => [entry.name, buildDurationDetailsEntry(entry)]); + const rows = entries.map((entry) => [entry.name, buildDurationDetailsEntry(entry)]); const content = markdownTable([tableHeader, ...rows]); return collapsibleSection('Show details', content); }; -const buildSummaryTable = (entries, collapse = false) => { +const buildSummaryTable = (entries: Array, collapse = false): string => { if (!entries.length) { return '_There are no entries_'; } - const rows = _.map(entries, (entry) => [entry.name, formatEntryDuration(entry)]); + const rows = entries.map((entry) => [entry.name, formatEntryDuration(entry)]); const content = markdownTable([tableHeader, ...rows]); return collapse ? collapsibleSection('Show entries', content) : content; }; -const buildMarkdown = (data) => { +const buildMarkdown = (data: CompareResult): string => { let result = '## Performance Comparison Report 📊'; - if (data.errors && data.errors.length) { + if (data.errors?.length) { result += '\n\n### Errors\n'; data.errors.forEach((message) => { result += ` 1. 🛑 ${message}\n`; }); } - if (data.warnings && data.warnings.length) { + if (data.warnings?.length) { result += '\n\n### Warnings\n'; data.warnings.forEach((message) => { result += ` 1. 🟡 ${message}\n`; @@ -92,7 +91,7 @@ const buildMarkdown = (data) => { return result; }; -const writeToFile = (filePath, content) => +const writeToFile = (filePath: string, content: string): Promise => fs .writeFile(filePath, content) .then(() => { @@ -106,7 +105,7 @@ const writeToFile = (filePath, content) => throw error; }); -const writeToMarkdown = (filePath, data) => { +const writeToMarkdown = (filePath: string, data: CompareResult): Promise => { const markdown = buildMarkdown(data); return writeToFile(filePath, markdown).catch((error) => { console.error(error); diff --git a/tests/e2e/compare/types.ts b/tests/e2e/compare/types.ts new file mode 100644 index 000000000000..e0be36716977 --- /dev/null +++ b/tests/e2e/compare/types.ts @@ -0,0 +1,57 @@ +type Entries = number[]; + +/** Metadata information for performance results. */ + +/** Entry in the performance results file. */ +type PerformanceEntry = { + /** Number of times the measurement test was run. */ + runs: number; + + /** Arithmetic average of measured render/execution durations for each run. */ + mean: number; + + /** Standard deviation of measured render/execution durations for each run. */ + stdev: number; + + /** Array of measured render/execution durations for each run. */ + entries: Entries; +}; + +/** + * Compare entry for tests that have both baseline and current entry + */ +type CompareEntry = { + name: string; + current: PerformanceEntry; + baseline: PerformanceEntry; + durationDiff: number; + relativeDurationDiff: number; +}; + +/** + * Compare entry for tests that have only current entry + */ +type AddedEntry = { + name: string; + current: PerformanceEntry; +}; + +/** + * Compare entry for tests that have only baseline entry + */ +type RemovedEntry = { + name: string; + baseline: PerformanceEntry; +}; + +/** Output of compare function. */ +type CompareResult = { + significance: CompareEntry[]; + meaningless: CompareEntry[]; + added: AddedEntry[]; + removed: RemovedEntry[]; + errors?: string[]; + warnings?: string[]; +}; + +export type {Entries, PerformanceEntry, CompareEntry, AddedEntry, RemovedEntry, CompareResult}; diff --git a/tests/e2e/measure/math.ts b/tests/e2e/measure/math.ts index e1c0cb981a0c..b5e303af7ea7 100644 --- a/tests/e2e/measure/math.ts +++ b/tests/e2e/measure/math.ts @@ -1,11 +1,4 @@ -type Entries = number[]; - -type Stats = { - mean: number; - stdev: number; - runs: number; - entries: Entries; -}; +import type {Entries, PerformanceEntry} from '../compare/types'; const filterOutliersViaIQR = (data: Entries): Entries => { let q1; @@ -35,7 +28,7 @@ const std = (arr: Entries): number => { return Math.sqrt(arr.map((i) => (i - avg) ** 2).reduce((a, b) => a + b) / arr.length); }; -const getStats = (entries: Entries): Stats => { +const getStats = (entries: Entries): PerformanceEntry => { const cleanedEntries = filterOutliersViaIQR(entries); const meanDuration = mean(cleanedEntries); const stdevDuration = std(cleanedEntries); diff --git a/tests/e2e/utils/logger.js b/tests/e2e/utils/logger.js index d0770b7aa8e4..6a39b4c10328 100644 --- a/tests/e2e/utils/logger.js +++ b/tests/e2e/utils/logger.js @@ -66,12 +66,4 @@ const error = (...args) => { log(...lines); }; -module.exports = { - log, - info, - warn, - note, - error, - success, - writeToLogFile, -}; +export {log, info, warn, note, error, success, writeToLogFile}; diff --git a/tests/perf-test/SidebarLinks.perf-test.js b/tests/perf-test/SidebarLinks.perf-test.tsx similarity index 85% rename from tests/perf-test/SidebarLinks.perf-test.js rename to tests/perf-test/SidebarLinks.perf-test.tsx index 0b10718fd0c4..c19a34517f45 100644 --- a/tests/perf-test/SidebarLinks.perf-test.js +++ b/tests/perf-test/SidebarLinks.perf-test.tsx @@ -1,23 +1,23 @@ import {fireEvent, screen} from '@testing-library/react-native'; import Onyx from 'react-native-onyx'; import {measurePerformance} from 'reassure'; -import _ from 'underscore'; -import CONST from '../../src/CONST'; -import ONYXKEYS from '../../src/ONYXKEYS'; -import variables from '../../src/styles/variables'; +import variables from '@styles/variables'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; -jest.mock('../../src/libs/Permissions'); -jest.mock('../../src/hooks/usePermissions.ts'); -jest.mock('../../src/libs/Navigation/Navigation'); -jest.mock('../../src/components/Icon/Expensicons'); +jest.mock('@libs/Permissions'); +jest.mock('@hooks/usePermissions.ts'); +jest.mock('@libs/Navigation/Navigation'); +jest.mock('@components/Icon/Expensicons'); jest.mock('@react-navigation/native'); const getMockedReportsMap = (length = 100) => { - const mockReports = Array.from({length}, (__, i) => { + // eslint-disable-next-line @typescript-eslint/naming-convention + const mockReports = Array.from({length}, (_, i) => { const reportID = i + 1; const participants = [1, 2]; const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; @@ -26,7 +26,7 @@ const getMockedReportsMap = (length = 100) => { return {[reportKey]: report}; }); - return _.assign({}, ...mockReports); + return {...mockReports}; }; const mockedResponseMap = getMockedReportsMap(500); @@ -36,11 +36,9 @@ describe('SidebarLinks', () => { Onyx.init({ keys: ONYXKEYS, safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], - registerStorageEventListener: () => {}, }); Onyx.multiSet({ - [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT, [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, [ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS], [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD, diff --git a/tests/unit/DateUtilsTest.js b/tests/unit/DateUtilsTest.ts similarity index 85% rename from tests/unit/DateUtilsTest.js rename to tests/unit/DateUtilsTest.ts index a752eea1a990..8758050e6f62 100644 --- a/tests/unit/DateUtilsTest.js +++ b/tests/unit/DateUtilsTest.ts @@ -1,9 +1,11 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import {addDays, addMinutes, format, setHours, setMinutes, subDays, subHours, subMinutes, subSeconds} from 'date-fns'; import {format as tzFormat, utcToZonedTime} from 'date-fns-tz'; import Onyx from 'react-native-onyx'; -import CONST from '../../src/CONST'; -import DateUtils from '../../src/libs/DateUtils'; -import ONYXKEYS from '../../src/ONYXKEYS'; +import DateUtils from '@libs/DateUtils'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {SelectedTimezone} from '@src/types/onyx/PersonalDetails'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; const LOCALE = CONST.LOCALES.EN; @@ -14,13 +16,14 @@ describe('DateUtils', () => { keys: ONYXKEYS, initialKeyStates: { [ONYXKEYS.SESSION]: {accountID: 999}, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: {999: {timezone: {selected: UTC}}}, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: {'999': {accountID: 999, timezone: {selected: 'Europe/London'}}}, }, }); return waitForBatchedUpdates(); }); afterEach(() => { + jest.restoreAllMocks(); jest.useRealTimers(); Onyx.clear(); }); @@ -53,32 +56,35 @@ describe('DateUtils', () => { }); it('should fallback to current date when getLocalDateFromDatetime is failing', () => { - const localDate = DateUtils.getLocalDateFromDatetime(LOCALE, undefined, 'InvalidTimezone'); + const localDate = DateUtils.getLocalDateFromDatetime(LOCALE, undefined, 'InvalidTimezone' as SelectedTimezone); expect(localDate.getTime()).not.toBeNaN(); }); it('should return the date in calendar time when calling datetimeToCalendarTime', () => { - const today = setMinutes(setHours(new Date(), 14), 32); + const today = setMinutes(setHours(new Date(), 14), 32).toString(); expect(DateUtils.datetimeToCalendarTime(LOCALE, today)).toBe('Today at 2:32 PM'); - const tomorrow = addDays(setMinutes(setHours(new Date(), 14), 32), 1); + const tomorrow = addDays(setMinutes(setHours(new Date(), 14), 32), 1).toString(); expect(DateUtils.datetimeToCalendarTime(LOCALE, tomorrow)).toBe('Tomorrow at 2:32 PM'); - const yesterday = setMinutes(setHours(subDays(new Date(), 1), 7), 43); + const yesterday = setMinutes(setHours(subDays(new Date(), 1), 7), 43).toString(); expect(DateUtils.datetimeToCalendarTime(LOCALE, yesterday)).toBe('Yesterday at 7:43 AM'); - const date = setMinutes(setHours(new Date('2022-11-05'), 10), 17); + const date = setMinutes(setHours(new Date('2022-11-05'), 10), 17).toString(); expect(DateUtils.datetimeToCalendarTime(LOCALE, date)).toBe('Nov 5, 2022 at 10:17 AM'); - const todayLowercaseDate = setMinutes(setHours(new Date(), 14), 32); + const todayLowercaseDate = setMinutes(setHours(new Date(), 14), 32).toString(); expect(DateUtils.datetimeToCalendarTime(LOCALE, todayLowercaseDate, false, undefined, true)).toBe('today at 2:32 PM'); }); it('should update timezone if automatic and selected timezone do not match', () => { - Intl.DateTimeFormat = jest.fn(() => ({ - resolvedOptions: () => ({timeZone: 'America/Chicago'}), - })); - Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {999: {timezone: {selected: UTC, automatic: true}}}).then(() => { + jest.spyOn(Intl, 'DateTimeFormat').mockImplementation( + () => + ({ + resolvedOptions: () => ({timeZone: 'America/Chicago'}), + } as Intl.DateTimeFormat), + ); + Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {'999': {accountID: 999, timezone: {selected: 'Europe/London', automatic: true}}}).then(() => { const result = DateUtils.getCurrentTimezone(); expect(result).toEqual({ selected: 'America/Chicago', @@ -88,10 +94,13 @@ describe('DateUtils', () => { }); it('should not update timezone if automatic and selected timezone match', () => { - Intl.DateTimeFormat = jest.fn(() => ({ - resolvedOptions: () => ({timeZone: UTC}), - })); - Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {999: {timezone: {selected: UTC, automatic: true}}}).then(() => { + jest.spyOn(Intl, 'DateTimeFormat').mockImplementation( + () => + ({ + resolvedOptions: () => ({timeZone: UTC}), + } as Intl.DateTimeFormat), + ); + Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {'999': {accountID: 999, timezone: {selected: 'Europe/London', automatic: true}}}).then(() => { const result = DateUtils.getCurrentTimezone(); expect(result).toEqual({ selected: UTC, @@ -102,7 +111,7 @@ describe('DateUtils', () => { it('canUpdateTimezone should return true when lastUpdatedTimezoneTime is more than 5 minutes ago', () => { // Use fake timers to control the current time - jest.useFakeTimers('modern'); + jest.useFakeTimers(); jest.setSystemTime(addMinutes(new Date(), 6)); const isUpdateTimezoneAllowed = DateUtils.canUpdateTimezone(); expect(isUpdateTimezoneAllowed).toBe(true); @@ -110,20 +119,20 @@ describe('DateUtils', () => { it('canUpdateTimezone should return false when lastUpdatedTimezoneTime is less than 5 minutes ago', () => { // Use fake timers to control the current time - jest.useFakeTimers('modern'); + jest.useFakeTimers(); jest.setSystemTime(addMinutes(new Date(), 4)); const isUpdateTimezoneAllowed = DateUtils.canUpdateTimezone(); expect(isUpdateTimezoneAllowed).toBe(false); }); it('should return the date in calendar time when calling datetimeToRelative', () => { - const aFewSecondsAgo = subSeconds(new Date(), 10); + const aFewSecondsAgo = subSeconds(new Date(), 10).toString(); expect(DateUtils.datetimeToRelative(LOCALE, aFewSecondsAgo)).toBe('less than a minute ago'); - const aMinuteAgo = subMinutes(new Date(), 1); + const aMinuteAgo = subMinutes(new Date(), 1).toString(); expect(DateUtils.datetimeToRelative(LOCALE, aMinuteAgo)).toBe('1 minute ago'); - const anHourAgo = subHours(new Date(), 1); + const anHourAgo = subHours(new Date(), 1).toString(); expect(DateUtils.datetimeToRelative(LOCALE, anHourAgo)).toBe('about 1 hour ago'); }); diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.ts similarity index 89% rename from tests/unit/OptionsListUtilsTest.js rename to tests/unit/OptionsListUtilsTest.ts index 00f1307ab59f..07dabf143110 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.ts @@ -1,30 +1,32 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import Onyx from 'react-native-onyx'; -import _ from 'underscore'; -import CONST from '../../src/CONST'; -import * as OptionsListUtils from '../../src/libs/OptionsListUtils'; -import * as ReportUtils from '../../src/libs/ReportUtils'; -import ONYXKEYS from '../../src/ONYXKEYS'; +import CONST from '@src/CONST'; +import type {PolicyTaxRateWithDefault, Tag} from '@src/libs/OptionsListUtils'; +import * as OptionsListUtils from '@src/libs/OptionsListUtils'; +import * as ReportUtils from '@src/libs/ReportUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {PolicyCategories, Report} from '@src/types/onyx'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; describe('OptionsListUtils', () => { // Given a set of reports with both single participants and multiple participants some pinned and some not - const REPORTS = { - 1: { + const REPORTS: Record = { + '1': { lastReadTime: '2021-01-14 11:25:39.295', lastVisibleActionCreated: '2022-11-22 03:26:02.015', isPinned: false, - reportID: 1, + reportID: '1', participantAccountIDs: [2, 1], visibleChatMemberAccountIDs: [2, 1], reportName: 'Iron Man, Mister Fantastic', hasDraft: true, type: CONST.REPORT.TYPE.CHAT, }, - 2: { + '2': { lastReadTime: '2021-01-14 11:25:39.296', lastVisibleActionCreated: '2022-11-22 03:26:02.016', isPinned: false, - reportID: 2, + reportID: '2', participantAccountIDs: [3], visibleChatMemberAccountIDs: [3], reportName: 'Spider-Man', @@ -32,41 +34,41 @@ describe('OptionsListUtils', () => { }, // This is the only report we are pinning in this test - 3: { + '3': { lastReadTime: '2021-01-14 11:25:39.297', lastVisibleActionCreated: '2022-11-22 03:26:02.170', isPinned: true, - reportID: 3, + reportID: '3', participantAccountIDs: [1], visibleChatMemberAccountIDs: [1], reportName: 'Mister Fantastic', type: CONST.REPORT.TYPE.CHAT, }, - 4: { + '4': { lastReadTime: '2021-01-14 11:25:39.298', lastVisibleActionCreated: '2022-11-22 03:26:02.180', isPinned: false, - reportID: 4, + reportID: '4', participantAccountIDs: [4], visibleChatMemberAccountIDs: [4], reportName: 'Black Panther', type: CONST.REPORT.TYPE.CHAT, }, - 5: { + '5': { lastReadTime: '2021-01-14 11:25:39.299', lastVisibleActionCreated: '2022-11-22 03:26:02.019', isPinned: false, - reportID: 5, + reportID: '5', participantAccountIDs: [5], visibleChatMemberAccountIDs: [5], reportName: 'Invisible Woman', type: CONST.REPORT.TYPE.CHAT, }, - 6: { + '6': { lastReadTime: '2021-01-14 11:25:39.300', lastVisibleActionCreated: '2022-11-22 03:26:02.020', isPinned: false, - reportID: 6, + reportID: '6', participantAccountIDs: [6], visibleChatMemberAccountIDs: [6], reportName: 'Thor', @@ -74,11 +76,11 @@ describe('OptionsListUtils', () => { }, // Note: This report has the largest lastVisibleActionCreated - 7: { + '7': { lastReadTime: '2021-01-14 11:25:39.301', lastVisibleActionCreated: '2022-11-22 03:26:03.999', isPinned: false, - reportID: 7, + reportID: '7', participantAccountIDs: [7], visibleChatMemberAccountIDs: [7], reportName: 'Captain America', @@ -86,11 +88,11 @@ describe('OptionsListUtils', () => { }, // Note: This report has no lastVisibleActionCreated - 8: { + '8': { lastReadTime: '2021-01-14 11:25:39.301', lastVisibleActionCreated: '2022-11-22 03:26:02.000', isPinned: false, - reportID: 8, + reportID: '8', participantAccountIDs: [12], visibleChatMemberAccountIDs: [12], reportName: 'Silver Surfer', @@ -98,23 +100,23 @@ describe('OptionsListUtils', () => { }, // Note: This report has an IOU - 9: { + '9': { lastReadTime: '2021-01-14 11:25:39.302', lastVisibleActionCreated: '2022-11-22 03:26:02.998', isPinned: false, - reportID: 9, + reportID: '9', participantAccountIDs: [8], visibleChatMemberAccountIDs: [8], reportName: 'Mister Sinister', - iouReportID: 100, + iouReportID: '100', type: CONST.REPORT.TYPE.CHAT, }, // This report is an archived room – it does not have a name and instead falls back on oldPolicyName - 10: { + '10': { lastReadTime: '2021-01-14 11:25:39.200', lastVisibleActionCreated: '2022-11-22 03:26:02.001', - reportID: 10, + reportID: '10', isPinned: false, participantAccountIDs: [2, 7], visibleChatMemberAccountIDs: [2, 7], @@ -133,69 +135,79 @@ describe('OptionsListUtils', () => { // And a set of personalDetails some with existing reports and some without const PERSONAL_DETAILS = { // These exist in our reports - 1: { + '1': { accountID: 1, displayName: 'Mister Fantastic', login: 'reedrichards@expensify.com', isSelected: true, + reportID: '1', }, - 2: { + '2': { accountID: 2, displayName: 'Iron Man', login: 'tonystark@expensify.com', + reportID: '1', }, - 3: { + '3': { accountID: 3, displayName: 'Spider-Man', login: 'peterparker@expensify.com', + reportID: '1', }, - 4: { + '4': { accountID: 4, displayName: 'Black Panther', login: 'tchalla@expensify.com', + reportID: '1', }, - 5: { + '5': { accountID: 5, displayName: 'Invisible Woman', login: 'suestorm@expensify.com', + reportID: '1', }, - 6: { + '6': { accountID: 6, displayName: 'Thor', login: 'thor@expensify.com', + reportID: '1', }, - 7: { + '7': { accountID: 7, displayName: 'Captain America', login: 'steverogers@expensify.com', + reportID: '1', }, - 8: { + '8': { accountID: 8, displayName: 'Mr Sinister', login: 'mistersinister@marauders.com', + reportID: '1', }, // These do not exist in reports at all - 9: { + '9': { accountID: 9, displayName: 'Black Widow', login: 'natasharomanoff@expensify.com', + reportID: '', }, - 10: { + '10': { accountID: 10, displayName: 'The Incredible Hulk', login: 'brucebanner@expensify.com', + reportID: '', }, }; const REPORTS_WITH_CONCIERGE = { ...REPORTS, - 11: { + '11': { lastReadTime: '2021-01-14 11:25:39.302', lastVisibleActionCreated: '2022-11-22 03:26:02.022', isPinned: false, - reportID: 11, + reportID: '11', participantAccountIDs: [999], visibleChatMemberAccountIDs: [999], reportName: 'Concierge', @@ -205,11 +217,11 @@ describe('OptionsListUtils', () => { const REPORTS_WITH_CHRONOS = { ...REPORTS, - 12: { + '12': { lastReadTime: '2021-01-14 11:25:39.302', lastVisibleActionCreated: '2022-11-22 03:26:02.022', isPinned: false, - reportID: 12, + reportID: '12', participantAccountIDs: [1000], visibleChatMemberAccountIDs: [1000], reportName: 'Chronos', @@ -219,11 +231,11 @@ describe('OptionsListUtils', () => { const REPORTS_WITH_RECEIPTS = { ...REPORTS, - 13: { + '13': { lastReadTime: '2021-01-14 11:25:39.302', lastVisibleActionCreated: '2022-11-22 03:26:02.022', isPinned: false, - reportID: 13, + reportID: '13', participantAccountIDs: [1001], visibleChatMemberAccountIDs: [1001], reportName: 'Receipts', @@ -233,11 +245,11 @@ describe('OptionsListUtils', () => { const REPORTS_WITH_WORKSPACE_ROOMS = { ...REPORTS, - 14: { + '14': { lastReadTime: '2021-01-14 11:25:39.302', lastVisibleActionCreated: '2022-11-22 03:26:02.022', isPinned: false, - reportID: 14, + reportID: '14', participantAccountIDs: [1, 10, 3], visibleChatMemberAccountIDs: [1, 10, 3], reportName: '', @@ -252,7 +264,7 @@ describe('OptionsListUtils', () => { const PERSONAL_DETAILS_WITH_CONCIERGE = { ...PERSONAL_DETAILS, - 999: { + '999': { accountID: 999, displayName: 'Concierge', login: 'concierge@expensify.com', @@ -262,7 +274,7 @@ describe('OptionsListUtils', () => { const PERSONAL_DETAILS_WITH_CHRONOS = { ...PERSONAL_DETAILS, - 1000: { + '1000': { accountID: 1000, displayName: 'Chronos', login: 'chronos@expensify.com', @@ -272,7 +284,7 @@ describe('OptionsListUtils', () => { const PERSONAL_DETAILS_WITH_RECEIPTS = { ...PERSONAL_DETAILS, - 1001: { + '1001': { accountID: 1001, displayName: 'Receipts', login: 'receipts@expensify.com', @@ -282,7 +294,7 @@ describe('OptionsListUtils', () => { const PERSONAL_DETAILS_WITH_PERIODS = { ...PERSONAL_DETAILS, - 1002: { + '1002': { accountID: 1002, displayName: 'The Flash', login: 'barry.allen@expensify.com', @@ -290,9 +302,14 @@ describe('OptionsListUtils', () => { }; const POLICY = { - policyID: 'ABC123', + id: 'ABC123', name: 'Hero Policy', - }; + role: 'user', + type: 'free', + owner: '', + outputCurrency: '', + isPolicyExpenseChatEnabled: false, + } as const; // Set the currently logged in user, report data, and personal details beforeAll(() => { @@ -300,11 +317,12 @@ describe('OptionsListUtils', () => { keys: ONYXKEYS, initialKeyStates: { [ONYXKEYS.SESSION]: {accountID: 2, email: 'tonystark@expensify.com'}, - [`${ONYXKEYS.COLLECTION.REPORT}100`]: { + [`${ONYXKEYS.COLLECTION.REPORT}100` as const]: { + reportID: '', ownerAccountID: 8, - total: '1000', + total: 1000, }, - [`${ONYXKEYS.COLLECTION.POLICY}${POLICY.policyID}`]: POLICY, + [`${ONYXKEYS.COLLECTION.POLICY}${POLICY.id}` as const]: POLICY, }, }); Onyx.registerLogger(() => {}); @@ -319,7 +337,7 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(2); // Then all of the reports should be shown including the archived rooms. - expect(results.recentReports.length).toBe(_.size(REPORTS)); + expect(results.recentReports.length).toBe(Object.values(REPORTS).length); // When we filter again but provide a searchValue results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, 'spider'); @@ -360,7 +378,7 @@ describe('OptionsListUtils', () => { // We should expect all personalDetails to be returned, // minus the currently logged in user and recent reports count - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 1 - MAX_RECENT_REPORTS); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS).length - 1 - MAX_RECENT_REPORTS); // We should expect personal details sorted alphabetically expect(results.personalDetails[0].text).toBe('Black Widow'); @@ -369,11 +387,11 @@ describe('OptionsListUtils', () => { expect(results.personalDetails[3].text).toBe('The Incredible Hulk'); // Then the result which has an existing report should also have the reportID attached - const personalDetailWithExistingReport = _.find(results.personalDetails, (personalDetail) => personalDetail.login === 'peterparker@expensify.com'); - expect(personalDetailWithExistingReport.reportID).toBe(2); + const personalDetailWithExistingReport = results.personalDetails.find((personalDetail) => personalDetail.login === 'peterparker@expensify.com'); + expect(personalDetailWithExistingReport?.reportID).toBe('2'); // When we only pass personal details - results = OptionsListUtils.getFilteredOptions([], PERSONAL_DETAILS, [], ''); + results = OptionsListUtils.getFilteredOptions({}, PERSONAL_DETAILS, [], ''); // We should expect personal details sorted alphabetically expect(results.personalDetails[0].text).toBe('Black Panther'); @@ -414,28 +432,28 @@ describe('OptionsListUtils', () => { // Concierge is included in the results by default. We should expect all the personalDetails to show // (minus the 5 that are already showing and the currently logged in user) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 1 - MAX_RECENT_REPORTS); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS_WITH_CONCIERGE).length - 1 - MAX_RECENT_REPORTS); expect(results.recentReports).toEqual(expect.arrayContaining([expect.objectContaining({login: 'concierge@expensify.com'})])); // Test by excluding Concierge from the results results = OptionsListUtils.getFilteredOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE]); // All the personalDetails should be returned minus the currently logged in user and Concierge - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 2 - MAX_RECENT_REPORTS); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS_WITH_CONCIERGE).length - 2 - MAX_RECENT_REPORTS); expect(results.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'concierge@expensify.com'})])); // Test by excluding Chronos from the results results = OptionsListUtils.getFilteredOptions(REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS]); // All the personalDetails should be returned minus the currently logged in user and Concierge - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 2 - MAX_RECENT_REPORTS); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS_WITH_CHRONOS).length - 2 - MAX_RECENT_REPORTS); expect(results.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'chronos@expensify.com'})])); // Test by excluding Receipts from the results results = OptionsListUtils.getFilteredOptions(REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS]); // All the personalDetails should be returned minus the currently logged in user and Concierge - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 2 - MAX_RECENT_REPORTS); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS_WITH_RECEIPTS).length - 2 - MAX_RECENT_REPORTS); expect(results.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'receipts@expensify.com'})])); }); @@ -448,7 +466,7 @@ describe('OptionsListUtils', () => { // And we should expect all the personalDetails to show (minus the 5 that are already // showing and the currently logged in user) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 6); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS).length - 6); // We should expect personal details sorted alphabetically expect(results.personalDetails[0].text).toBe('Black Widow'); @@ -457,8 +475,8 @@ describe('OptionsListUtils', () => { expect(results.personalDetails[3].text).toBe('The Incredible Hulk'); // And none of our personalDetails should include any of the users with recent reports - const reportLogins = _.map(results.recentReports, (reportOption) => reportOption.login); - const personalDetailsOverlapWithReports = _.every(results.personalDetails, (personalDetailOption) => _.contains(reportLogins, personalDetailOption.login)); + const reportLogins = results.recentReports.map((reportOption) => reportOption.login); + const personalDetailsOverlapWithReports = results.personalDetails.every((personalDetailOption) => reportLogins.includes(personalDetailOption.login)); expect(personalDetailsOverlapWithReports).toBe(false); // When we search for an option that is only in a personalDetail with no existing report @@ -487,15 +505,15 @@ describe('OptionsListUtils', () => { // Then one of our older report options (not in our five most recent) should appear in the personalDetails // but not in recentReports - expect(_.every(results.recentReports, (option) => option.login !== 'peterparker@expensify.com')).toBe(true); - expect(_.every(results.personalDetails, (option) => option.login !== 'peterparker@expensify.com')).toBe(false); + expect(results.recentReports.every((option) => option.login !== 'peterparker@expensify.com')).toBe(true); + expect(results.personalDetails.every((option) => option.login !== 'peterparker@expensify.com')).toBe(false); // When we provide a "selected" option to getFilteredOptions() results = OptionsListUtils.getFilteredOptions(REPORTS, PERSONAL_DETAILS, [], '', [{login: 'peterparker@expensify.com'}]); // Then the option should not appear anywhere in either list - expect(_.every(results.recentReports, (option) => option.login !== 'peterparker@expensify.com')).toBe(true); - expect(_.every(results.personalDetails, (option) => option.login !== 'peterparker@expensify.com')).toBe(true); + expect(results.recentReports.every((option) => option.login !== 'peterparker@expensify.com')).toBe(true); + expect(results.personalDetails.every((option) => option.login !== 'peterparker@expensify.com')).toBe(true); // When we add a search term for which no options exist and the searchValue itself // is not a potential email or phone @@ -531,7 +549,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports.length).toBe(0); expect(results.personalDetails.length).toBe(0); expect(results.userToInvite).not.toBe(null); - expect(results.userToInvite.login).toBe('+15005550006'); + expect(results.userToInvite?.login).toBe('+15005550006'); // When we add a search term for which no options exist and the searchValue itself // is a potential phone number with country code added @@ -542,7 +560,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports.length).toBe(0); expect(results.personalDetails.length).toBe(0); expect(results.userToInvite).not.toBe(null); - expect(results.userToInvite.login).toBe('+15005550006'); + expect(results.userToInvite?.login).toBe('+15005550006'); // When we add a search term for which no options exist and the searchValue itself // is a potential phone number with special characters added @@ -553,7 +571,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports.length).toBe(0); expect(results.personalDetails.length).toBe(0); expect(results.userToInvite).not.toBe(null); - expect(results.userToInvite.login).toBe('+18003243233'); + expect(results.userToInvite?.login).toBe('+18003243233'); // When we use a search term for contact number that contains alphabet characters results = OptionsListUtils.getFilteredOptions(REPORTS, PERSONAL_DETAILS, [], '998243aaaa'); @@ -568,7 +586,7 @@ describe('OptionsListUtils', () => { // Concierge is included in the results by default. We should expect all the personalDetails to show // (minus the 5 that are already showing and the currently logged in user) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 6); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS_WITH_CONCIERGE).length - 6); expect(results.recentReports).toEqual(expect.arrayContaining([expect.objectContaining({login: 'concierge@expensify.com'})])); // Test by excluding Concierge from the results @@ -576,7 +594,7 @@ describe('OptionsListUtils', () => { // We should expect all the personalDetails to show (minus the 5 that are already showing, // the currently logged in user and Concierge) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 7); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS_WITH_CONCIERGE).length - 7); expect(results.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'concierge@expensify.com'})])); expect(results.recentReports).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'concierge@expensify.com'})])); @@ -585,7 +603,7 @@ describe('OptionsListUtils', () => { // We should expect all the personalDetails to show (minus the 5 that are already showing, // the currently logged in user and Concierge) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 7); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS_WITH_CHRONOS).length - 7); expect(results.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'chronos@expensify.com'})])); expect(results.recentReports).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'chronos@expensify.com'})])); @@ -594,26 +612,25 @@ describe('OptionsListUtils', () => { // We should expect all the personalDetails to show (minus the 5 that are already showing, // the currently logged in user and Concierge) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 7); + expect(results.personalDetails.length).toBe(Object.values(PERSONAL_DETAILS_WITH_RECEIPTS).length - 7); expect(results.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'receipts@expensify.com'})])); expect(results.recentReports).not.toEqual(expect.arrayContaining([expect.objectContaining({login: 'receipts@expensify.com'})])); }); it('getShareDestinationsOptions()', () => { // Filter current REPORTS as we do in the component, before getting share destination options - const filteredReports = {}; - _.keys(REPORTS).forEach((reportKey) => { - if (!ReportUtils.canUserPerformWriteAction(REPORTS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS[reportKey])) { - return; + const filteredReports = Object.entries(REPORTS).reduce>((reports, [reportKey, report]) => { + if (!ReportUtils.canUserPerformWriteAction(report) || ReportUtils.isExpensifyOnlyParticipantInReport(report)) { + return reports; } - filteredReports[reportKey] = REPORTS[reportKey]; - }); + return {...reports, [reportKey]: report}; + }, {}); // When we pass an empty search value let results = OptionsListUtils.getShareDestinationOptions(filteredReports, PERSONAL_DETAILS, [], ''); // Then we should expect all the recent reports to show but exclude the archived rooms - expect(results.recentReports.length).toBe(_.size(REPORTS) - 1); + expect(results.recentReports.length).toBe(Object.values(REPORTS).length - 1); // When we pass a search value that doesn't match the group chat name results = OptionsListUtils.getShareDestinationOptions(filteredReports, PERSONAL_DETAILS, [], 'mutants'); @@ -628,20 +645,19 @@ describe('OptionsListUtils', () => { expect(results.recentReports.length).toBe(1); // Filter current REPORTS_WITH_WORKSPACE_ROOMS as we do in the component, before getting share destination options - const filteredReportsWithWorkspaceRooms = {}; - _.keys(REPORTS_WITH_WORKSPACE_ROOMS).forEach((reportKey) => { - if (!ReportUtils.canUserPerformWriteAction(REPORTS_WITH_WORKSPACE_ROOMS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS_WITH_WORKSPACE_ROOMS[reportKey])) { - return; + const filteredReportsWithWorkspaceRooms = Object.entries(REPORTS_WITH_WORKSPACE_ROOMS).reduce>((reports, [reportKey, report]) => { + if (!ReportUtils.canUserPerformWriteAction(report) || ReportUtils.isExpensifyOnlyParticipantInReport(report)) { + return reports; } - filteredReportsWithWorkspaceRooms[reportKey] = REPORTS_WITH_WORKSPACE_ROOMS[reportKey]; - }); + return {...reports, [reportKey]: report}; + }, {}); // When we also have a policy to return rooms in the results results = OptionsListUtils.getShareDestinationOptions(filteredReportsWithWorkspaceRooms, PERSONAL_DETAILS, [], ''); // Then we should expect the DMS, the group chats and the workspace room to show // We should expect all the recent reports to show, excluding the archived rooms - expect(results.recentReports.length).toBe(_.size(REPORTS_WITH_WORKSPACE_ROOMS) - 1); + expect(results.recentReports.length).toBe(Object.values(REPORTS_WITH_WORKSPACE_ROOMS).length - 1); // When we search for a workspace room results = OptionsListUtils.getShareDestinationOptions(filteredReportsWithWorkspaceRooms, PERSONAL_DETAILS, [], 'Avengers Room'); @@ -691,22 +707,38 @@ describe('OptionsListUtils', () => { enabled: true, }, ]; - const smallCategoriesList = { + const smallCategoriesList: PolicyCategories = { Taxi: { enabled: false, name: 'Taxi', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, Restaurant: { enabled: true, name: 'Restaurant', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, Food: { enabled: true, name: 'Food', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Food: Meat': { enabled: true, name: 'Food: Meat', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, }; const smallResultList = [ @@ -775,62 +807,118 @@ describe('OptionsListUtils', () => { data: [], }, ]; - const largeCategoriesList = { + const largeCategoriesList: PolicyCategories = { Taxi: { enabled: false, name: 'Taxi', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, Restaurant: { enabled: true, name: 'Restaurant', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, Food: { enabled: true, name: 'Food', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Food: Meat': { enabled: true, name: 'Food: Meat', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Food: Milk': { enabled: true, name: 'Food: Milk', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Food: Vegetables': { enabled: false, name: 'Food: Vegetables', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Cars: Audi': { enabled: true, name: 'Cars: Audi', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Cars: BMW': { enabled: false, name: 'Cars: BMW', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Cars: Mercedes-Benz': { enabled: true, name: 'Cars: Mercedes-Benz', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, Medical: { enabled: false, name: 'Medical', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Travel: Meals': { enabled: true, name: 'Travel: Meals', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Travel: Meals: Breakfast': { enabled: true, name: 'Travel: Meals: Breakfast', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Travel: Meals: Dinner': { enabled: false, name: 'Travel: Meals: Dinner', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, 'Travel: Meals: Lunch': { enabled: true, name: 'Travel: Meals: Lunch', + areCommentsRequired: false, + 'GL Code': '', + externalID: '', + origin: '', }, }; const largeResultList = [ @@ -1089,22 +1177,26 @@ describe('OptionsListUtils', () => { name: 'Medical', }, ]; - const smallTagsList = { + const smallTagsList: Record = { Engineering: { enabled: false, name: 'Engineering', + accountID: null, }, Medical: { enabled: true, name: 'Medical', + accountID: null, }, Accounting: { enabled: true, name: 'Accounting', + accountID: null, }, HR: { enabled: true, name: 'HR', + accountID: null, }, }; const smallResultList = [ @@ -1162,50 +1254,61 @@ describe('OptionsListUtils', () => { data: [], }, ]; - const largeTagsList = { + const largeTagsList: Record = { Engineering: { enabled: false, name: 'Engineering', + accountID: null, }, Medical: { enabled: true, name: 'Medical', + accountID: null, }, Accounting: { enabled: true, name: 'Accounting', + accountID: null, }, HR: { enabled: true, name: 'HR', + accountID: null, }, Food: { enabled: true, name: 'Food', + accountID: null, }, Traveling: { enabled: false, name: 'Traveling', + accountID: null, }, Cleaning: { enabled: true, name: 'Cleaning', + accountID: null, }, Software: { enabled: true, name: 'Software', + accountID: null, }, OfficeSupplies: { enabled: false, name: 'Office Supplies', + accountID: null, }, Taxes: { enabled: true, name: 'Taxes', + accountID: null, }, Benefits: { enabled: true, name: 'Benefits', + accountID: null, }, }; const largeResultList = [ @@ -2063,7 +2166,7 @@ describe('OptionsListUtils', () => { const emptySearch = ''; const wrongSearch = 'bla bla'; - const policyTaxRatesWithDefault = { + const policyTaxRatesWithDefault: PolicyTaxRateWithDefault = { name: 'Tax', defaultExternalID: 'CODE1', defaultValue: '0%', @@ -2072,14 +2175,20 @@ describe('OptionsListUtils', () => { CODE2: { name: 'Tax rate 2', value: '3%', + code: '', + modifiedName: '', }, CODE3: { name: 'Tax option 3', value: '5%', + code: '', + modifiedName: '', }, CODE1: { name: 'Tax exempt 1', value: '0%', + code: '', + modifiedName: '', }, }, }; @@ -2201,7 +2310,7 @@ describe('OptionsListUtils', () => { }); it('formatMemberForList()', () => { - const formattedMembers = _.map(PERSONAL_DETAILS, (personalDetail) => OptionsListUtils.formatMemberForList(personalDetail)); + const formattedMembers = Object.values(PERSONAL_DETAILS).map((personalDetail) => OptionsListUtils.formatMemberForList(personalDetail)); // We're only formatting items inside the array, so the order should be the same as the original PERSONAL_DETAILS array expect(formattedMembers[0].text).toBe('Mister Fantastic'); @@ -2212,9 +2321,9 @@ describe('OptionsListUtils', () => { expect(formattedMembers[0].isSelected).toBe(true); // And all the others to be unselected - expect(_.every(formattedMembers.slice(1), (personalDetail) => !personalDetail.isSelected)).toBe(true); + expect(formattedMembers.slice(1).every((personalDetail) => !personalDetail.isSelected)).toBe(true); // `isDisabled` is always false - expect(_.every(formattedMembers, (personalDetail) => !personalDetail.isDisabled)).toBe(true); + expect(formattedMembers.every((personalDetail) => !personalDetail.isDisabled)).toBe(true); }); }); diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.ts similarity index 80% rename from tests/unit/ReportUtilsTest.js rename to tests/unit/ReportUtilsTest.ts index a5b0a5d3c151..b8375700304c 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.ts @@ -1,52 +1,59 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import Onyx from 'react-native-onyx'; -import _ from 'underscore'; -import CONST from '../../src/CONST'; -import * as ReportUtils from '../../src/libs/ReportUtils'; -import ONYXKEYS from '../../src/ONYXKEYS'; +import * as ReportUtils from '@libs/ReportUtils'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {Report} from '@src/types/onyx'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; // Be sure to include the mocked permissions library or else the beta tests won't work -jest.mock('../../src/libs/Permissions'); +jest.mock('@libs/Permissions'); const currentUserEmail = 'bjorn@vikings.net'; const currentUserAccountID = 5; const participantsPersonalDetails = { - 1: { + '1': { accountID: 1, displayName: 'Ragnar Lothbrok', firstName: 'Ragnar', login: 'ragnar@vikings.net', }, - 2: { + '2': { accountID: 2, login: 'floki@vikings.net', displayName: 'floki@vikings.net', }, - 3: { + '3': { accountID: 3, displayName: 'Lagertha Lothbrok', firstName: 'Lagertha', login: 'lagertha@vikings.net', pronouns: 'She/her', }, - 4: { + '4': { accountID: 4, login: '+18332403627@expensify.sms', displayName: '(833) 240-3627', }, - 5: { + '5': { accountID: 5, displayName: 'Lagertha Lothbrok', firstName: 'Lagertha', login: 'lagertha2@vikings.net', pronouns: 'She/her', }, -}; +} as const; + const policy = { - policyID: 1, + id: '1', name: 'Vikings Policy', -}; + role: 'user', + type: 'free', + owner: '', + outputCurrency: '', + isPolicyExpenseChatEnabled: false, +} as const; Onyx.init({keys: ONYXKEYS}); @@ -56,7 +63,7 @@ describe('ReportUtils', () => { [ONYXKEYS.PERSONAL_DETAILS_LIST]: participantsPersonalDetails, [ONYXKEYS.SESSION]: {email: currentUserEmail, accountID: currentUserAccountID}, [ONYXKEYS.COUNTRY_CODE]: 1, - [`${ONYXKEYS.COLLECTION.POLICY}${policy.policyID}`]: policy, + [`${ONYXKEYS.COLLECTION.POLICY}${policy.id}` as const]: policy, }); return waitForBatchedUpdates(); }); @@ -106,6 +113,7 @@ describe('ReportUtils', () => { test('with displayName', () => { expect( ReportUtils.getReportName({ + reportID: '', participantAccountIDs: [currentUserAccountID, 1], }), ).toBe('Ragnar Lothbrok'); @@ -114,6 +122,7 @@ describe('ReportUtils', () => { test('no displayName', () => { expect( ReportUtils.getReportName({ + reportID: '', participantAccountIDs: [currentUserAccountID, 2], }), ).toBe('floki@vikings.net'); @@ -122,6 +131,7 @@ describe('ReportUtils', () => { test('SMS', () => { expect( ReportUtils.getReportName({ + reportID: '', participantAccountIDs: [currentUserAccountID, 4], }), ).toBe('(833) 240-3627'); @@ -131,6 +141,7 @@ describe('ReportUtils', () => { test('Group DM', () => { expect( ReportUtils.getReportName({ + reportID: '', participantAccountIDs: [currentUserAccountID, 1, 2, 3, 4], }), ).toBe('Ragnar, floki@vikings.net, Lagertha, (833) 240-3627'); @@ -138,6 +149,7 @@ describe('ReportUtils', () => { describe('Default Policy Room', () => { const baseAdminsRoom = { + reportID: '', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, reportName: '#admins', }; @@ -161,6 +173,7 @@ describe('ReportUtils', () => { describe('User-Created Policy Room', () => { const baseUserCreatedRoom = { + reportID: '', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, reportName: '#VikingsChat', }; @@ -187,8 +200,9 @@ describe('ReportUtils', () => { test('as member', () => { expect( ReportUtils.getReportName({ + reportID: '', chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, - policyID: policy.policyID, + policyID: policy.id, isOwnPolicyExpenseChat: true, ownerAccountID: 1, }), @@ -198,8 +212,9 @@ describe('ReportUtils', () => { test('as admin', () => { expect( ReportUtils.getReportName({ + reportID: '', chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, - policyID: policy.policyID, + policyID: policy.id, isOwnPolicyExpenseChat: false, ownerAccountID: 1, }), @@ -209,9 +224,10 @@ describe('ReportUtils', () => { describe('Archived', () => { const baseArchivedPolicyExpenseChat = { + reportID: '', chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, ownerAccountID: 1, - policyID: policy.policyID, + policyID: policy.id, oldPolicyName: policy.name, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, @@ -248,18 +264,18 @@ describe('ReportUtils', () => { describe('requiresAttentionFromCurrentUser', () => { it('returns false when there is no report', () => { - expect(ReportUtils.requiresAttentionFromCurrentUser()).toBe(false); + expect(ReportUtils.requiresAttentionFromCurrentUser(null)).toBe(false); }); it('returns false when the matched IOU report does not have an owner accountID', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), ownerAccountID: undefined, }; expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(false); }); it('returns false when the linked iou report has an oustanding IOU', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), iouReportID: '1', }; Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, { @@ -271,7 +287,7 @@ describe('ReportUtils', () => { }); it('returns false when the report has no outstanding IOU but is waiting for a bank account and the logged user is the report owner', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), ownerAccountID: currentUserAccountID, isWaitingOnBankAccount: true, }; @@ -279,7 +295,7 @@ describe('ReportUtils', () => { }); it('returns false when the report has outstanding IOU and is not waiting for a bank account and the logged user is the report owner', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), ownerAccountID: currentUserAccountID, isWaitingOnBankAccount: false, }; @@ -287,7 +303,7 @@ describe('ReportUtils', () => { }); it('returns false when the report has no oustanding IOU but is waiting for a bank account and the logged user is not the report owner', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), ownerAccountID: 97, isWaitingOnBankAccount: true, }; @@ -295,14 +311,14 @@ describe('ReportUtils', () => { }); it('returns true when the report has an unread mention', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), isUnreadWithMention: true, }; expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(true); }); it('returns true when the report is an outstanding task', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.TASK, managerID: currentUserAccountID, isUnreadWithMention: false, @@ -313,7 +329,7 @@ describe('ReportUtils', () => { }); it('returns true when the report has oustanding child request', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), ownerAccountID: 99, hasOutstandingChildRequest: true, isWaitingOnBankAccount: false, @@ -323,7 +339,7 @@ describe('ReportUtils', () => { }); describe('getMoneyRequestOptions', () => { - const participantsAccountIDs = _.keys(participantsPersonalDetails); + const participantsAccountIDs = Object.keys(participantsPersonalDetails).map(Number); beforeAll(() => { Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { @@ -338,8 +354,8 @@ describe('ReportUtils', () => { describe('return empty iou options if', () => { it('participants aray contains excluded expensify iou emails', () => { - const allEmpty = _.every(CONST.EXPENSIFY_ACCOUNT_IDS, (accountID) => { - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions({}, {}, [currentUserAccountID, accountID]); + const allEmpty = CONST.EXPENSIFY_ACCOUNT_IDS.every((accountID) => { + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(null, null, [currentUserAccountID, accountID]); return moneyRequestOptions.length === 0; }); expect(allEmpty).toBe(true); @@ -347,51 +363,51 @@ describe('ReportUtils', () => { it('it is a room with no participants except self', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); it('its not your policy expense chat', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: false, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); it('its paid IOU report', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.IOU, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); it('its approved Expense report', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.APPROVED, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); it('its paid Expense report', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.EXPENSE, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); @@ -401,11 +417,11 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: false, }).then(() => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), parentReportID: '100', type: CONST.REPORT.TYPE.EXPENSE, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); }); @@ -417,7 +433,7 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: true, }).then(() => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, @@ -425,7 +441,13 @@ describe('ReportUtils', () => { }; const paidPolicy = { type: CONST.POLICY.TYPE.TEAM, - }; + id: '', + name: '', + role: 'user', + owner: '', + outputCurrency: '', + isPolicyExpenseChatEnabled: false, + } as const; const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(0); }); @@ -434,47 +456,49 @@ describe('ReportUtils', () => { describe('return only iou split option if', () => { it('it is a chat room with more than one participant', () => { - const onlyHaveSplitOption = _.every( - [CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, CONST.REPORT.CHAT_TYPE.DOMAIN_ALL, CONST.REPORT.CHAT_TYPE.POLICY_ROOM], - (chatType) => { - const report = { - ...LHNTestUtils.getFakeReport(), - chatType, - }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID, participantsAccountIDs[0]]); - return moneyRequestOptions.length === 1 && moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT); - }, - ); + const onlyHaveSplitOption = [ + CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, + CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, + CONST.REPORT.CHAT_TYPE.DOMAIN_ALL, + CONST.REPORT.CHAT_TYPE.POLICY_ROOM, + ].every((chatType) => { + const report = { + ...(LHNTestUtils.getFakeReport() as Report), + chatType, + }; + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); + return moneyRequestOptions.length === 1 && moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT); + }); expect(onlyHaveSplitOption).toBe(true); }); it('has multiple participants excluding self', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID, ...participantsAccountIDs]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); }); it('user has send money permission', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID, ...participantsAccountIDs]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); }); it("it's a group DM report", () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.CHAT, participantsAccountIDs: [currentUserAccountID, ...participantsAccountIDs], }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID, ...participantsAccountIDs]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs.map(Number)]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); }); @@ -488,11 +512,11 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: true, }).then(() => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), parentReportID: '102', type: CONST.REPORT.TYPE.EXPENSE, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.REQUEST)).toBe(true); }); @@ -505,7 +529,7 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: true, }).then(() => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN, @@ -513,32 +537,38 @@ describe('ReportUtils', () => { }; const paidPolicy = { type: CONST.POLICY.TYPE.TEAM, - }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]], true); + id: '', + name: '', + role: 'user', + owner: '', + outputCurrency: '', + isPolicyExpenseChatEnabled: false, + } as const; + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); }); }); it('it is an IOU report in submitted state', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.REQUEST)).toBe(true); }); it('it is an IOU report in submitted state even with send money permissions', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.REQUEST)).toBe(true); }); @@ -547,11 +577,11 @@ describe('ReportUtils', () => { describe('return multiple money request option if', () => { it("it is user's own policy expense chat", () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: true, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID, ...participantsAccountIDs]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs]); expect(moneyRequestOptions.length).toBe(2); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.REQUEST)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); @@ -559,10 +589,10 @@ describe('ReportUtils', () => { it('it is a 1:1 DM', () => { const report = { - ...LHNTestUtils.getFakeReport(), + ...(LHNTestUtils.getFakeReport() as Report), type: CONST.REPORT.TYPE.CHAT, }; - const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, {}, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(2); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.REQUEST)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SEND)).toBe(true); @@ -589,20 +619,20 @@ describe('ReportUtils', () => { describe('sortReportsByLastRead', () => { it('should filter out report without reportID & lastReadTime and sort lastReadTime in ascending order', () => { const reports = [ - {reportID: 1, lastReadTime: '2023-07-08 07:15:44.030'}, - {reportID: 2, lastReadTime: null}, - {reportID: 3, lastReadTime: '2023-07-06 07:15:44.030'}, - {reportID: 4, lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU}, - {lastReadTime: '2023-07-09 07:15:44.030'}, - {reportID: 6}, - {}, + {reportID: '1', lastReadTime: '2023-07-08 07:15:44.030'}, + {reportID: '2', lastReadTime: undefined}, + {reportID: '3', lastReadTime: '2023-07-06 07:15:44.030'}, + {reportID: '4', lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU}, + {lastReadTime: '2023-07-09 07:15:44.030'} as Report, + {reportID: '6'}, + null, ]; const sortedReports = [ - {reportID: 3, lastReadTime: '2023-07-06 07:15:44.030'}, - {reportID: 4, lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU}, - {reportID: 1, lastReadTime: '2023-07-08 07:15:44.030'}, - ]; - expect(ReportUtils.sortReportsByLastRead(reports)).toEqual(sortedReports); + {reportID: '3', lastReadTime: '2023-07-06 07:15:44.030'}, + {reportID: '4', lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU}, + {reportID: '1', lastReadTime: '2023-07-08 07:15:44.030'}, + ] as const; + expect(ReportUtils.sortReportsByLastRead(reports, null)).toEqual(sortedReports); }); }); @@ -613,26 +643,26 @@ describe('ReportUtils', () => { {reportID: '3', lastReadTime: '2024-02-01 04:56:47.233', parentReportActionID: '2', parentReportID: '2', reportName: 'Report'}, {reportID: '4', lastReadTime: '2024-02-01 04:56:47.233', parentReportActionID: '3', parentReportID: '3', reportName: 'Report'}, {reportID: '5', lastReadTime: '2024-02-01 04:56:47.233', parentReportActionID: '4', parentReportID: '4', reportName: 'Report'}, - ]; + ] as const; const reportActions = [ - {reportActionID: '1', created: '2024-02-01 04:42:22.965'}, - {reportActionID: '2', created: '2024-02-01 04:42:28.003'}, - {reportActionID: '3', created: '2024-02-01 04:42:31.742'}, - {reportActionID: '4', created: '2024-02-01 04:42:35.619'}, - ]; + {reportActionID: '1', created: '2024-02-01 04:42:22.965', actionName: 'MARKEDREIMBURSED'}, + {reportActionID: '2', created: '2024-02-01 04:42:28.003', actionName: 'MARKEDREIMBURSED'}, + {reportActionID: '3', created: '2024-02-01 04:42:31.742', actionName: 'MARKEDREIMBURSED'}, + {reportActionID: '4', created: '2024-02-01 04:42:35.619', actionName: 'MARKEDREIMBURSED'}, + ] as const; beforeAll(() => { Onyx.multiSet({ - [`${ONYXKEYS.COLLECTION.REPORT}${reports[0].reportID}`]: reports[0], - [`${ONYXKEYS.COLLECTION.REPORT}${reports[1].reportID}`]: reports[1], - [`${ONYXKEYS.COLLECTION.REPORT}${reports[2].reportID}`]: reports[2], - [`${ONYXKEYS.COLLECTION.REPORT}${reports[3].reportID}`]: reports[3], - [`${ONYXKEYS.COLLECTION.REPORT}${reports[4].reportID}`]: reports[4], - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[0].reportID}`]: {[reportActions[0].reportActionID]: reportActions[0]}, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[1].reportID}`]: {[reportActions[1].reportActionID]: reportActions[1]}, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[2].reportID}`]: {[reportActions[2].reportActionID]: reportActions[2]}, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[3].reportID}`]: {[reportActions[3].reportActionID]: reportActions[3]}, + [`${ONYXKEYS.COLLECTION.REPORT}${reports[0].reportID}` as const]: reports[0], + [`${ONYXKEYS.COLLECTION.REPORT}${reports[1].reportID}` as const]: reports[1], + [`${ONYXKEYS.COLLECTION.REPORT}${reports[2].reportID}` as const]: reports[2], + [`${ONYXKEYS.COLLECTION.REPORT}${reports[3].reportID}` as const]: reports[3], + [`${ONYXKEYS.COLLECTION.REPORT}${reports[4].reportID}` as const]: reports[4], + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[0].reportID}` as const]: {[reportActions[0].reportActionID]: reportActions[0]}, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[1].reportID}` as const]: {[reportActions[1].reportActionID]: reportActions[1]}, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[2].reportID}` as const]: {[reportActions[2].reportActionID]: reportActions[2]}, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[3].reportID}` as const]: {[reportActions[3].reportActionID]: reportActions[3]}, }); return waitForBatchedUpdates(); }); From 88c5fd8e5c29cc7dc1b70d863483abe0fc7db86a Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Tue, 27 Feb 2024 11:53:59 +0100 Subject: [PATCH 052/504] add missing props to memo --- src/pages/home/sidebar/SidebarLinksData.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index 0c8125cae79f..59bf74586b4b 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -345,6 +345,7 @@ export default compose( prevProps.onLinkClick === nextProps.onLinkClick && _.isEqual(prevProps.policyMembers, nextProps.policyMembers) && _.isEqual(prevProps.transactionViolations, nextProps.transactionViolations) && - _.isEqual(prevProps.currentUserPersonalDetails, nextProps.currentUserPersonalDetails), + _.isEqual(prevProps.currentUserPersonalDetails, nextProps.currentUserPersonalDetails) && + prevProps.currentReportID === nextProps.currentReportID, ), ); From 3aa217604ce487b9748412e60d1827822c74f1f7 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Tue, 27 Feb 2024 14:13:51 +0100 Subject: [PATCH 053/504] chore: add comments for memoization --- src/pages/home/sidebar/SidebarLinksData.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index 59bf74586b4b..c5749893d7fb 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -331,6 +331,12 @@ export default compose( }, }), )( + /* + While working on audit on the App Start App metric we noticed that by memoizing SidebarLinksData we can avoid 1 additional run of getOrderedReportIDs. + With that we can reduce app start up time by ~2.5s on heavy account. + After finding and fixing core issues with getOrderedReportIDs performance we might remove the memoization + More details - https://github.com/Expensify/App/issues/35234#issuecomment-1926914534 + */ memo( SidebarLinksData, (prevProps, nextProps) => From 1a63d65a52d36c8bdf781711b4d9fc6095f6a820 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Wed, 28 Feb 2024 08:20:43 +0000 Subject: [PATCH 054/504] [TS migration] Migrate compare, currencyUtilsTest, IOUUtilsTest, SideBarTest and TestHelper --- tests/e2e/compare/{compare.js => compare.ts} | 60 +++-- tests/e2e/measure/math.ts | 1 + ...rencyUtilsTest.js => CurrencyUtilsTest.ts} | 17 +- .../unit/{IOUUtilsTest.js => IOUUtilsTest.ts} | 43 +-- tests/unit/{SidebarTest.js => SidebarTest.ts} | 86 +++--- tests/utils/TestHelper.js | 244 ------------------ tests/utils/TestHelper.ts | 242 +++++++++++++++++ 7 files changed, 356 insertions(+), 337 deletions(-) rename tests/e2e/compare/{compare.js => compare.ts} (68%) rename tests/unit/{CurrencyUtilsTest.js => CurrencyUtilsTest.ts} (92%) rename tests/unit/{IOUUtilsTest.js => IOUUtilsTest.ts} (81%) rename tests/unit/{SidebarTest.js => SidebarTest.ts} (62%) delete mode 100644 tests/utils/TestHelper.js create mode 100644 tests/utils/TestHelper.ts diff --git a/tests/e2e/compare/compare.js b/tests/e2e/compare/compare.ts similarity index 68% rename from tests/e2e/compare/compare.js rename to tests/e2e/compare/compare.ts index 7feaa8b266d1..cf74b1240bf8 100644 --- a/tests/e2e/compare/compare.js +++ b/tests/e2e/compare/compare.ts @@ -1,9 +1,25 @@ -import _ from 'underscore'; +import type {Stats} from '../measure/math'; import getStats from '../measure/math'; import * as math from './math'; import printToConsole from './output/console'; import writeToMarkdown from './output/markdown'; +type Entry = { + name: string; + baseline?: Stats; + current?: Stats; + diff?: number; + relativeDurationDiff?: number; + isDurationDiffOfSignificance?: boolean; + mean?: number; +}; + +type Result = { + name: string; + current?: Entry; + baseline?: Entry; +}; + /* * base implementation from: https://github.com/callstack/reassure/blob/main/packages/reassure-compare/src/compare.ts * This module reads from the baseline and compare files and compares the results. @@ -25,14 +41,7 @@ const PROBABILITY_CONSIDERED_SIGNIFICANCE = 0.02; */ const DURATION_DIFF_THRESHOLD_SIGNIFICANCE = 100; -/** - * - * @param {string} name - * @param {Object} compare - * @param {Object} baseline - * @returns {Object} - */ -function buildCompareEntry(name, compare, baseline) { +function buildCompareEntry(name: string, compare: Stats, baseline: Stats): Entry { const diff = compare.mean - baseline.mean; const relativeDurationDiff = diff / baseline.mean; @@ -53,20 +62,16 @@ function buildCompareEntry(name, compare, baseline) { /** * Compare results between baseline and current entries and categorize. - * - * @param {Object} compareEntries - * @param {Object} baselineEntries - * @returns {Object} */ -function compareResults(compareEntries, baselineEntries) { +function compareResults(compareEntries: Record, baselineEntries: Record) { // Unique test scenario names - const names = [...new Set([..._.keys(compareEntries), ..._.keys(baselineEntries || {})])]; + const names: string[] = [...new Set([...Object(compareEntries).keys(), ...Object(baselineEntries ?? {}).keys()])]; - const compared = []; - const added = []; - const removed = []; + const compared: Entry[] = []; + const added: Result[] = []; + const removed: Result[] = []; - names.forEach((name) => { + names.forEach((name: string) => { const current = compareEntries[name]; const baseline = baselineEntries[name]; @@ -88,15 +93,12 @@ function compareResults(compareEntries, baselineEntries) { } }); - const significance = _.chain(compared) - .filter((item) => item.isDurationDiffOfSignificance) - .value(); - const meaningless = _.chain(compared) - .filter((item) => !item.isDurationDiffOfSignificance) - .value(); + const significance = compared.filter((item) => item.isDurationDiffOfSignificance); - added.sort((a, b) => b.current.mean - a.current.mean); - removed.sort((a, b) => b.baseline.mean - a.baseline.mean); + const meaningless = compared.filter((item) => !item.isDurationDiffOfSignificance); + + added.sort((a, b) => (b?.current?.mean ?? 0) - (a.current?.mean ?? 0)); + removed.sort((a, b) => (b.baseline?.mean ?? 0) - (a.baseline?.mean ?? 0)); return { significance, @@ -106,7 +108,7 @@ function compareResults(compareEntries, baselineEntries) { }; } -export default (main, delta, outputFile, outputFormat = 'all') => { +export default (main: Record, delta: Record, outputFile: string, outputFormat = 'all') => { // IMPORTANT NOTE: make sure you are passing the delta/compare results first, then the main/baseline results: const outputData = compareResults(delta, main); @@ -118,3 +120,5 @@ export default (main, delta, outputFile, outputFormat = 'all') => { return writeToMarkdown(outputFile, outputData); } }; + +export type {Entry}; diff --git a/tests/e2e/measure/math.ts b/tests/e2e/measure/math.ts index e1c0cb981a0c..c9c0219ef1fd 100644 --- a/tests/e2e/measure/math.ts +++ b/tests/e2e/measure/math.ts @@ -49,3 +49,4 @@ const getStats = (entries: Entries): Stats => { }; export default getStats; +export type {Stats} diff --git a/tests/unit/CurrencyUtilsTest.js b/tests/unit/CurrencyUtilsTest.ts similarity index 92% rename from tests/unit/CurrencyUtilsTest.js rename to tests/unit/CurrencyUtilsTest.ts index 89e1e2ffb3be..246af64b1d87 100644 --- a/tests/unit/CurrencyUtilsTest.js +++ b/tests/unit/CurrencyUtilsTest.ts @@ -1,9 +1,9 @@ import Onyx from 'react-native-onyx'; -import _ from 'underscore'; -import CONST from '../../src/CONST'; -import * as CurrencyUtils from '../../src/libs/CurrencyUtils'; -import LocaleListener from '../../src/libs/Localize/LocaleListener'; -import ONYXKEYS from '../../src/ONYXKEYS'; +import CONST from '@src/CONST'; +import * as CurrencyUtils from '@src/libs/CurrencyUtils'; +import LocaleListener from '@src/libs/Localize/LocaleListener'; +import ONYXKEYS from '@src/ONYXKEYS'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; // This file can get outdated. In that case, you can follow these steps to update it: // - open your browser console and navigate to the Network tab @@ -13,7 +13,7 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; // - update currencyList.json import currencyList from './currencyList.json'; -const currencyCodeList = _.keys(currencyList); +const currencyCodeList = Object.keys(currencyList); const AVAILABLE_LOCALES = [CONST.LOCALES.EN, CONST.LOCALES.ES]; describe('CurrencyUtils', () => { @@ -37,7 +37,10 @@ describe('CurrencyUtils', () => { describe('getLocalizedCurrencySymbol', () => { test.each(AVAILABLE_LOCALES)('Returns non empty string for all currencyCode with preferredLocale %s', (prefrredLocale) => Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, prefrredLocale).then(() => { - _.forEach(currencyCodeList, (currencyCode) => { + if (isEmptyObject(currencyCodeList)) { + return; + } + currencyCodeList.forEach((currencyCode: string) => { const localizedSymbol = CurrencyUtils.getLocalizedCurrencySymbol(currencyCode); expect(localizedSymbol).toBeTruthy(); diff --git a/tests/unit/IOUUtilsTest.js b/tests/unit/IOUUtilsTest.ts similarity index 81% rename from tests/unit/IOUUtilsTest.js rename to tests/unit/IOUUtilsTest.ts index ac04b74a0ca5..b390d0cd70a3 100644 --- a/tests/unit/IOUUtilsTest.js +++ b/tests/unit/IOUUtilsTest.ts @@ -1,8 +1,10 @@ +import type {NullishDeep} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; -import * as IOUUtils from '../../src/libs/IOUUtils'; -import * as ReportUtils from '../../src/libs/ReportUtils'; -import * as TransactionUtils from '../../src/libs/TransactionUtils'; -import ONYXKEYS from '../../src/ONYXKEYS'; +import * as IOUUtils from '@src/libs/IOUUtils'; +import * as ReportUtils from '@src/libs/ReportUtils'; +import * as TransactionUtils from '@src/libs/TransactionUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type Transaction from '@src/types/onyx/Transaction'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import currencyList from './currencyList.json'; @@ -25,34 +27,35 @@ describe('IOUUtils', () => { }); test('Requesting money offline in a different currency will show the pending conversion message', () => { - const iouReport = ReportUtils.buildOptimisticIOUReport(1, 2, 100, 1, 'USD'); + const iouReport = ReportUtils.buildOptimisticIOUReport(1, 2, 100, '1', 'USD'); const usdPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', iouReport.reportID); const aedPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'AED', iouReport.reportID); + const MergeQueries: Record<`${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`, NullishDeep> = {}; + MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`] = usdPendingTransaction; + MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`] = aedPendingTransaction; - return Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, { - [`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`]: usdPendingTransaction, - [`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`]: aedPendingTransaction, - }).then(() => { + return Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, MergeQueries).then(() => { // We requested money offline in a different currency, we don't know the total of the iouReport until we're back online expect(IOUUtils.isIOUReportPendingCurrencyConversion(iouReport)).toBe(true); }); }); test('Requesting money online in a different currency will not show the pending conversion message', () => { - const iouReport = ReportUtils.buildOptimisticIOUReport(2, 3, 100, 1, 'USD'); + const iouReport = ReportUtils.buildOptimisticIOUReport(2, 3, 100, '1', 'USD'); const usdPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', iouReport.reportID); const aedPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'AED', iouReport.reportID); - return Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, { - [`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`]: { - ...usdPendingTransaction, - pendingAction: null, - }, - [`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`]: { - ...aedPendingTransaction, - pendingAction: null, - }, - }).then(() => { + const MergeQueries: Record<`${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`, NullishDeep> = {}; + MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`] = { + ...usdPendingTransaction, + pendingAction: null, + }; + MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`] = { + ...aedPendingTransaction, + pendingAction: null, + }; + + return Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, MergeQueries).then(() => { // We requested money online in a different currency, we know the iouReport total and there's no need to show the pending conversion message expect(IOUUtils.isIOUReportPendingCurrencyConversion(iouReport)).toBe(false); }); diff --git a/tests/unit/SidebarTest.js b/tests/unit/SidebarTest.ts similarity index 62% rename from tests/unit/SidebarTest.js rename to tests/unit/SidebarTest.ts index 6a813ef1fa8c..4a3be66ebe37 100644 --- a/tests/unit/SidebarTest.js +++ b/tests/unit/SidebarTest.ts @@ -1,35 +1,23 @@ import {cleanup, screen} from '@testing-library/react-native'; -import lodashGet from 'lodash/get'; +import type {NullishDeep} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; -import CONST from '../../src/CONST'; -import * as Localize from '../../src/libs/Localize'; +import CONST from '@src/CONST'; +import * as Localize from '@src/libs/Localize'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type * as OnyxTypes from '@src/types/onyx'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; // Be sure to include the mocked Permissions and Expensicons libraries as well as the usePermissions hook or else the beta tests won't work -jest.mock('../../src/libs/Permissions'); -jest.mock('../../src/hooks/usePermissions.ts'); -jest.mock('../../src/components/Icon/Expensicons'); - -const ONYXKEYS = { - PERSONAL_DETAILS_LIST: 'personalDetailsList', - IS_LOADING_APP: 'isLoadingApp', - NVP_PRIORITY_MODE: 'nvp_priorityMode', - SESSION: 'session', - BETAS: 'betas', - COLLECTION: { - REPORT: 'report_', - REPORT_ACTIONS: 'reportActions_', - }, - NETWORK: 'network', -}; +jest.mock('@src/libs/Permissions'); +jest.mock('@src/hooks/usePermissions.ts'); +jest.mock('@src/components/Icon/Expensicons'); describe('Sidebar', () => { beforeAll(() => Onyx.init({ keys: ONYXKEYS, - registerStorageEventListener: () => {}, safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], }), ); @@ -50,6 +38,7 @@ describe('Sidebar', () => { describe('archived chats', () => { it('renders the archive reason as the preview message of the chat', () => { const report = { + // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3, true), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, @@ -57,6 +46,7 @@ describe('Sidebar', () => { }; const action = { + // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. ...LHNTestUtils.getFakeReportAction('email1@test.com', 3, true), actionName: 'CLOSED', originalMessage: { @@ -70,29 +60,40 @@ describe('Sidebar', () => { return ( waitForBatchedUpdates() // When Onyx is updated with the data and the sidebar re-renders - .then(() => - Onyx.multiSet({ + .then(() => { + const reportCollection = { + // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + } as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}${string}`, NullishDeep>; + + const reportAction = { + // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionId]: action}, + } as Record<`${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS}${string}`, NullishDeep>; + + return Onyx.multiSet({ [ONYXKEYS.BETAS]: betas, [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD, [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, [ONYXKEYS.IS_LOADING_APP]: false, - [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionId]: action}, - }), - ) + ...reportCollection, + ...reportAction, + }); + }) .then(() => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); - expect(lodashGet(displayNames, [0, 'props', 'children', 0])).toBe('Report (archived)'); + expect(displayNames[0].props.children[0]).toBe('Report (archived)'); const hintMessagePreviewText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); const messagePreviewTexts = screen.queryAllByLabelText(hintMessagePreviewText); - expect(lodashGet(messagePreviewTexts, [0, 'props', 'children'])).toBe('This chat room has been archived.'); + expect(messagePreviewTexts[0].props.children).toBe('This chat room has been archived.'); }) ); }); it('renders the policy deleted archive reason as the preview message of the chat', () => { const report = { + // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3, true), policyName: 'Vikings Policy', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, @@ -100,6 +101,7 @@ describe('Sidebar', () => { stateNum: CONST.REPORT.STATE_NUM.APPROVED, }; const action = { + // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. ...LHNTestUtils.getFakeReportAction('email1@test.com', 3, true), actionName: 'CLOSED', originalMessage: { @@ -114,26 +116,34 @@ describe('Sidebar', () => { return ( waitForBatchedUpdates() // When Onyx is updated with the data and the sidebar re-renders - .then(() => - Onyx.multiSet({ + .then(() => { + const reportCollection = { + // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + } as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}${string}`, NullishDeep>; + + const reportAction = { + // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionId]: action}, + } as Record<`${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS}${string}`, NullishDeep>; + + return Onyx.multiSet({ [ONYXKEYS.BETAS]: betas, [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD, [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, [ONYXKEYS.IS_LOADING_APP]: false, - [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionId]: action}, - }), - ) + ...reportCollection, + ...reportAction, + }); + }) .then(() => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); - expect(lodashGet(displayNames, [0, 'props', 'children', 0])).toBe('Report (archived)'); + expect(displayNames[0].props.children[0]).toBe('Report (archived)'); const hintMessagePreviewText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); const messagePreviewTexts = screen.queryAllByLabelText(hintMessagePreviewText); - expect(lodashGet(messagePreviewTexts, [0, 'props', 'children'])).toBe( - 'This workspace chat is no longer active because Vikings Policy is no longer an active workspace.', - ); + expect(messagePreviewTexts[0].props.children).toBe('This workspace chat is no longer active because Vikings Policy is no longer an active workspace.'); }) ); }); diff --git a/tests/utils/TestHelper.js b/tests/utils/TestHelper.js deleted file mode 100644 index 9059041afd19..000000000000 --- a/tests/utils/TestHelper.js +++ /dev/null @@ -1,244 +0,0 @@ -import Str from 'expensify-common/lib/str'; -import Onyx from 'react-native-onyx'; -import _ from 'underscore'; -import CONST from '../../src/CONST'; -import * as Session from '../../src/libs/actions/Session'; -import HttpUtils from '../../src/libs/HttpUtils'; -import * as NumberUtils from '../../src/libs/NumberUtils'; -import ONYXKEYS from '../../src/ONYXKEYS'; -import waitForBatchedUpdates from './waitForBatchedUpdates'; - -/** - * @param {String} login - * @param {Number} accountID - * @param {String} [firstName] - * @returns {Object} - */ -function buildPersonalDetails(login, accountID, firstName = 'Test') { - return { - accountID, - login, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', - avatarThumbnail: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', - displayName: `${firstName} User`, - firstName, - lastName: 'User', - pronouns: '', - timezone: CONST.DEFAULT_TIME_ZONE, - phoneNumber: '', - }; -} - -/** - * Simulate signing in and make sure all API calls in this flow succeed. Every time we add - * a mockImplementationOnce() we are altering what Network.post() will return. - * - * @param {Number} [accountID] - * @param {String} [login] - * @param {String} [password] - * @param {String} [authToken] - * @param {String} [firstName] - * @return {Promise} - */ -function signInWithTestUser(accountID = 1, login = 'test@user.com', password = 'Password1', authToken = 'asdfqwerty', firstName = 'Test') { - const originalXhr = HttpUtils.xhr; - HttpUtils.xhr = jest.fn(); - HttpUtils.xhr.mockResolvedValue({ - onyxData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.CREDENTIALS, - value: { - login, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.ACCOUNT, - value: { - validated: true, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: { - [accountID]: buildPersonalDetails(login, accountID, firstName), - }, - }, - ], - jsonCode: 200, - }); - - // Simulate user entering their login and populating the credentials.login - Session.beginSignIn(login); - return waitForBatchedUpdates() - .then(() => { - // Response is the same for calls to Authenticate and BeginSignIn - HttpUtils.xhr.mockResolvedValue({ - onyxData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.SESSION, - value: { - authToken, - accountID, - email: login, - encryptedAuthToken: authToken, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.CREDENTIALS, - value: { - autoGeneratedLogin: Str.guid('expensify.cash-'), - autoGeneratedPassword: Str.guid(), - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.USER, - value: { - isUsingExpensifyCard: false, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.BETAS, - value: ['all'], - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID, - value: 'randomID', - }, - ], - jsonCode: 200, - }); - Session.signIn(password); - return waitForBatchedUpdates(); - }) - .then(() => { - HttpUtils.xhr = originalXhr; - }); -} - -function signOutTestUser() { - const originalXhr = HttpUtils.xhr; - HttpUtils.xhr = jest.fn(); - HttpUtils.xhr.mockResolvedValue({jsonCode: 200}); - Session.signOutAndRedirectToSignIn(); - return waitForBatchedUpdates().then(() => (HttpUtils.xhr = originalXhr)); -} - -/** - * Use for situations where fetch() is required. This mock is stateful and has some additional methods to control its behavior: - * - * - pause() – stop resolving promises until you call resume() - * - resume() - flush the queue of promises, and start resolving new promises immediately - * - fail() - start returning a failure response - * - success() - go back to returning a success response - * - * @example - * - * beforeAll(() => { - * global.fetch = TestHelper.getGlobalFetchMock(); - * }); - * - * @returns {Function} - */ -function getGlobalFetchMock() { - const queue = []; - let isPaused = false; - let shouldFail = false; - - const getResponse = () => - shouldFail - ? { - ok: true, - json: () => Promise.resolve({jsonCode: 400}), - } - : { - ok: true, - json: () => Promise.resolve({jsonCode: 200}), - }; - - const mockFetch = jest.fn().mockImplementation(() => { - if (!isPaused) { - return Promise.resolve(getResponse()); - } - return new Promise((resolve) => queue.push(resolve)); - }); - - mockFetch.pause = () => (isPaused = true); - mockFetch.resume = () => { - isPaused = false; - _.each(queue, (resolve) => resolve(getResponse())); - return waitForBatchedUpdates(); - }; - mockFetch.fail = () => (shouldFail = true); - mockFetch.succeed = () => (shouldFail = false); - - return mockFetch; -} - -/** - * @param {String} login - * @param {Number} accountID - * @returns {Promise} - */ -function setPersonalDetails(login, accountID) { - Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { - [accountID]: buildPersonalDetails(login, accountID), - }); - return waitForBatchedUpdates(); -} - -/** - * @param {String} created - * @param {Number} actorAccountID - * @param {String} actionID - * @returns {Object} - */ -function buildTestReportComment(created, actorAccountID, actionID = null) { - const reportActionID = actionID || NumberUtils.rand64(); - return { - actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, - person: [{type: 'TEXT', style: 'strong', text: 'User B'}], - created, - message: [{type: 'COMMENT', html: `Comment ${actionID}`, text: `Comment ${actionID}`}], - reportActionID, - actorAccountID, - }; -} - -function assertFormDataMatchesObject(formData, obj) { - expect(_.reduce(Array.from(formData.entries()), (memo, x) => ({...memo, [x[0]]: x[1]}), {})).toEqual(expect.objectContaining(obj)); -} - -/** - * This is a helper function to create a mock for the addListener function of the react-navigation library. - * The reason we need this is because we need to trigger the transitionEnd event in our tests to simulate - * the transitionEnd event that is triggered when the screen transition animation is completed. - * - * @returns {Object} An object with two functions: triggerTransitionEnd and addListener - */ -const createAddListenerMock = () => { - const transitionEndListeners = []; - const triggerTransitionEnd = () => { - transitionEndListeners.forEach((transitionEndListener) => transitionEndListener()); - }; - - const addListener = jest.fn().mockImplementation((listener, callback) => { - if (listener === 'transitionEnd') { - transitionEndListeners.push(callback); - } - return () => { - _.filter(transitionEndListeners, (cb) => cb !== callback); - }; - }); - - return {triggerTransitionEnd, addListener}; -}; - -export {getGlobalFetchMock, signInWithTestUser, signOutTestUser, setPersonalDetails, buildPersonalDetails, buildTestReportComment, assertFormDataMatchesObject, createAddListenerMock}; diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts new file mode 100644 index 000000000000..edef0bd55e5f --- /dev/null +++ b/tests/utils/TestHelper.ts @@ -0,0 +1,242 @@ +import Str from 'expensify-common/lib/str'; +import Onyx from 'react-native-onyx'; +import CONST from '@src/CONST'; +import * as Session from '@src/libs/actions/Session'; +import HttpUtils from '@src/libs/HttpUtils'; +import * as NumberUtils from '@src/libs/NumberUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {PersonalDetails, Report} from '@src/types/onyx'; +import waitForBatchedUpdates from './waitForBatchedUpdates'; + +type MockFetch = ReturnType & {pause?: () => void; fail?: () => void; succeed?: () => void; resume?: () => Promise}; + +type Response = {ok: boolean; json: () => Promise<{jsonCode: number}>}; +type QueueItem = (value: Response | PromiseLike) => void; + +type FormData = { + entries: () => Array<[string, string | Blob]>; +}; + +type Listener = () => void; + +function buildPersonalDetails(login: string, accountID: number, firstName = 'Test'): PersonalDetails { + return { + accountID, + login, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', + avatarThumbnail: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', + displayName: `${firstName} User`, + firstName, + lastName: 'User', + pronouns: '', + timezone: CONST.DEFAULT_TIME_ZONE, + phoneNumber: '', + }; +} + +/** + * Simulate signing in and make sure all API calls in this flow succeed. Every time we add + * a mockImplementationOnce() we are altering what Network.post() will return. + */ +function signInWithTestUser(accountID = 1, login = 'test@user.com', password = 'Password1', authToken = 'asdfqwerty', firstName = 'Test') { + const originalXhr = HttpUtils.xhr; + + HttpUtils.xhr = jest.fn().mockImplementation(() => { + // Your mocked response object + const mockedResponse = { + onyxData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.CREDENTIALS, + value: { + login, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.ACCOUNT, + value: { + validated: true, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [accountID]: buildPersonalDetails(login, accountID, firstName), + }, + }, + ], + jsonCode: 200, + }; + + // Return a Promise that resolves with the mocked response + return Promise.resolve(mockedResponse); + }); + + // Simulate user entering their login and populating the credentials.login + Session.beginSignIn(login); + return waitForBatchedUpdates() + .then(() => { + // Response is the same for calls to Authenticate and BeginSignIn + HttpUtils.xhr = jest.fn().mockImplementation(() => { + // Your mocked response object + const mockedResponse = { + onyxData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.SESSION, + value: { + authToken, + accountID, + email: login, + encryptedAuthToken: authToken, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.CREDENTIALS, + value: { + autoGeneratedLogin: Str.guid('expensify.cash-'), + autoGeneratedPassword: Str.guid(), + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.USER, + value: { + isUsingExpensifyCard: false, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.BETAS, + value: ['all'], + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID, + value: 'randomID', + }, + ], + jsonCode: 200, + }; + + // Return a Promise that resolves with the mocked response + return Promise.resolve(mockedResponse); + }); + Session.signIn(password); + return waitForBatchedUpdates(); + }) + .then(() => { + HttpUtils.xhr = originalXhr; + }); +} + +function signOutTestUser() { + const originalXhr = HttpUtils.xhr; + HttpUtils.xhr = jest.fn().mockImplementation(() => { + // Your mocked response object + const mockedResponse = { + jsonCode: 200, + }; + + // Return a Promise that resolves with the mocked response + return Promise.resolve(mockedResponse); + }); + Session.signOutAndRedirectToSignIn(); + return waitForBatchedUpdates().then(() => (HttpUtils.xhr = originalXhr)); +} + +/** + * Use for situations where fetch() is required. This mock is stateful and has some additional methods to control its behavior: + * + * - pause() – stop resolving promises until you call resume() + * - resume() - flush the queue of promises, and start resolving new promises immediately + * - fail() - start returning a failure response + * - success() - go back to returning a success response + */ +function getGlobalFetchMock() { + const queue: QueueItem[] = []; + let isPaused = false; + let shouldFail = false; + + const getResponse = () => + shouldFail + ? { + ok: true, + json: () => Promise.resolve({jsonCode: 400}), + } + : { + ok: true, + json: () => Promise.resolve({jsonCode: 200}), + }; + + const mockFetch: MockFetch = jest.fn().mockImplementation(() => { + if (!isPaused) { + return Promise.resolve(getResponse()); + } + return new Promise((resolve) => queue.push(resolve)); + }); + + mockFetch.pause = () => (isPaused = true); + mockFetch.resume = () => { + isPaused = false; + queue.forEach((resolve) => resolve(getResponse())); + return waitForBatchedUpdates(); + }; + mockFetch.fail = () => (shouldFail = true); + mockFetch.succeed = () => (shouldFail = false); + + return mockFetch; +} + +function setPersonalDetails(login: string, accountID: number) { + Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { + [accountID]: buildPersonalDetails(login, accountID), + }); + return waitForBatchedUpdates(); +} + +function buildTestReportComment(created: string, actorAccountID: number, actionID: string | null = null) { + const reportActionID = actionID ?? NumberUtils.rand64(); + return { + actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, + person: [{type: 'TEXT', style: 'strong', text: 'User B'}], + created, + message: [{type: 'COMMENT', html: `Comment ${actionID}`, text: `Comment ${actionID}`}], + reportActionID, + actorAccountID, + }; +} + +function assertFormDataMatchesObject(formData: FormData, obj: Report) { + expect(Array.from(formData.entries()).reduce((memo, x) => ({...memo, [x[0]]: x[1]}), {})).toEqual(expect.objectContaining(obj)); +} + +/** + * This is a helper function to create a mock for the addListener function of the react-navigation library. + * The reason we need this is because we need to trigger the transitionEnd event in our tests to simulate + * the transitionEnd event that is triggered when the screen transition animation is completed. + * + * @returns An object with two functions: triggerTransitionEnd and addListener + */ +const createAddListenerMock = () => { + const transitionEndListeners: Listener[] = []; + const triggerTransitionEnd = () => { + transitionEndListeners.forEach((transitionEndListener) => transitionEndListener()); + }; + + const addListener = jest.fn().mockImplementation((listener, callback) => { + if (listener === 'transitionEnd') { + transitionEndListeners.push(callback); + } + return () => { + transitionEndListeners.filter((cb) => cb !== callback); + }; + }); + + return {triggerTransitionEnd, addListener}; +}; + +export {getGlobalFetchMock, signInWithTestUser, signOutTestUser, setPersonalDetails, buildPersonalDetails, buildTestReportComment, assertFormDataMatchesObject, createAddListenerMock}; From 703bd25dd4354abcddac108d5f7b6384691d68c1 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Wed, 28 Feb 2024 18:31:21 +0000 Subject: [PATCH 055/504] [TS migration] Fixed compare --- tests/e2e/compare/compare.ts | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/tests/e2e/compare/compare.ts b/tests/e2e/compare/compare.ts index cf74b1240bf8..bc3d7fae23ea 100644 --- a/tests/e2e/compare/compare.ts +++ b/tests/e2e/compare/compare.ts @@ -14,11 +14,7 @@ type Entry = { mean?: number; }; -type Result = { - name: string; - current?: Entry; - baseline?: Entry; -}; +type Metric = Record; /* * base implementation from: https://github.com/callstack/reassure/blob/main/packages/reassure-compare/src/compare.ts @@ -63,13 +59,13 @@ function buildCompareEntry(name: string, compare: Stats, baseline: Stats): Entry /** * Compare results between baseline and current entries and categorize. */ -function compareResults(compareEntries: Record, baselineEntries: Record) { +function compareResults(compareEntries: Metric, baselineEntries: Metric) { // Unique test scenario names - const names: string[] = [...new Set([...Object(compareEntries).keys(), ...Object(baselineEntries ?? {}).keys()])]; + const compareKeys = Object.keys(compareEntries); + const baselineKeys = baselineEntries ? Object.keys(baselineEntries) : []; + const names = Array.from(new Set([...compareKeys, ...baselineKeys])); const compared: Entry[] = []; - const added: Result[] = []; - const removed: Result[] = []; names.forEach((name: string) => { const current = compareEntries[name]; @@ -80,16 +76,6 @@ function compareResults(compareEntries: Record, baselineEntries: if (baseline && current) { compared.push(buildCompareEntry(name, deltaStats, currentStats)); - } else if (current) { - added.push({ - name, - current, - }); - } else if (baseline) { - removed.push({ - name, - baseline, - }); } }); @@ -97,18 +83,13 @@ function compareResults(compareEntries: Record, baselineEntries: const meaningless = compared.filter((item) => !item.isDurationDiffOfSignificance); - added.sort((a, b) => (b?.current?.mean ?? 0) - (a.current?.mean ?? 0)); - removed.sort((a, b) => (b.baseline?.mean ?? 0) - (a.baseline?.mean ?? 0)); - return { significance, meaningless, - added, - removed, }; } -export default (main: Record, delta: Record, outputFile: string, outputFormat = 'all') => { +export default (main: Metric, delta: Metric, outputFile: string, outputFormat = 'all') => { // IMPORTANT NOTE: make sure you are passing the delta/compare results first, then the main/baseline results: const outputData = compareResults(delta, main); From 6b655b588b8c36e80909c6e12dd020ef46cfef39 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Thu, 29 Feb 2024 09:41:04 +0000 Subject: [PATCH 056/504] [TS migratio] Lint --- tests/e2e/measure/math.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/measure/math.ts b/tests/e2e/measure/math.ts index c9c0219ef1fd..1cb6661007ea 100644 --- a/tests/e2e/measure/math.ts +++ b/tests/e2e/measure/math.ts @@ -49,4 +49,4 @@ const getStats = (entries: Entries): Stats => { }; export default getStats; -export type {Stats} +export type {Stats}; From 4e3edb22f06a3c2a43afa5c34744f037ada71479 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 29 Feb 2024 13:41:52 +0100 Subject: [PATCH 057/504] fix: typecheck --- src/components/MoneyRequestConfirmationList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 773e98b6462e..ff355985b071 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -240,7 +240,7 @@ function MoneyRequestConfirmationList({ const taxRates = policy?.taxRates; // A flag for showing the categories field - const shouldShowCategories = isPolicyExpenseChat && (iouCategory || OptionsListUtils.hasEnabledOptions(Object.values(policyCategories ?? {}))); + const shouldShowCategories = isPolicyExpenseChat && (iouCategory || OptionsListUtils.hasEnabledOptions(policyCategories ?? {})); // A flag and a toggler for showing the rest of the form fields const [shouldExpandFields, toggleShouldExpandFields] = useReducer((state) => !state, false); From c66339c5ee848f074ef98f3e84a2267d9f98e05d Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Thu, 29 Feb 2024 17:02:27 +0000 Subject: [PATCH 058/504] refactor(typescript): apply pull request suggestions --- src/types/utils/CollectionDataSet.ts | 19 +++++ tests/perf-test/SidebarLinks.perf-test.tsx | 5 +- tests/unit/OptionsListUtilsTest.ts | 4 +- tests/unit/ReportUtilsTest.ts | 92 +++++++++++----------- 4 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/types/utils/CollectionDataSet.ts b/src/types/utils/CollectionDataSet.ts index fc95a69dc9bf..05a0843b6e9b 100644 --- a/src/types/utils/CollectionDataSet.ts +++ b/src/types/utils/CollectionDataSet.ts @@ -1,6 +1,25 @@ +import type {OnyxEntry} from 'react-native-onyx'; import type {OnyxCollectionKey, OnyxCollectionValuesMapping} from '@src/ONYXKEYS'; /** Helps with typing a collection item update inside Onyx.multiSet call */ type CollectionDataSet = Record<`${TCollectionKey}${string}`, OnyxCollectionValuesMapping[TCollectionKey]>; +const toCollectionDataSet = ( + collectionKey: TCollectionKey, + collection: Array>, + idSelector: (collectionValue: OnyxCollectionValuesMapping[TCollectionKey]) => string, +) => { + const collectionDataSet = collection.reduce>((result, collectionValue) => { + if (collectionValue) { + // eslint-disable-next-line no-param-reassign + result[`${collectionKey}${idSelector(collectionValue)}`] = collectionValue; + } + return result; + }, {} as CollectionDataSet); + + return collectionDataSet; +}; + export default CollectionDataSet; + +export {toCollectionDataSet}; diff --git a/tests/perf-test/SidebarLinks.perf-test.tsx b/tests/perf-test/SidebarLinks.perf-test.tsx index c19a34517f45..473e854322d5 100644 --- a/tests/perf-test/SidebarLinks.perf-test.tsx +++ b/tests/perf-test/SidebarLinks.perf-test.tsx @@ -16,9 +16,8 @@ jest.mock('@components/Icon/Expensicons'); jest.mock('@react-navigation/native'); const getMockedReportsMap = (length = 100) => { - // eslint-disable-next-line @typescript-eslint/naming-convention - const mockReports = Array.from({length}, (_, i) => { - const reportID = i + 1; + const mockReports = Array.from({length}, (value, index) => { + const reportID = index + 1; const participants = [1, 2]; const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; const report = LHNTestUtils.getFakeReport(participants, 1, true); diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index dfc953577bfa..02402e7d7bd2 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -623,7 +623,9 @@ describe('OptionsListUtils', () => { if (!ReportUtils.canUserPerformWriteAction(report) || ReportUtils.isExpensifyOnlyParticipantInReport(report)) { return reports; } - return {...reports, [reportKey]: report}; + // eslint-disable-next-line no-param-reassign + reports[reportKey] = report; + return reports; }, {}); // When we pass an empty search value diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index b8375700304c..ce60ffeaad68 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1,9 +1,11 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Report} from '@src/types/onyx'; +import type {Policy, Report, ReportAction} from '@src/types/onyx'; +import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -45,7 +47,7 @@ const participantsPersonalDetails = { }, } as const; -const policy = { +const policy: Policy = { id: '1', name: 'Vikings Policy', role: 'user', @@ -53,17 +55,18 @@ const policy = { owner: '', outputCurrency: '', isPolicyExpenseChatEnabled: false, -} as const; +}; Onyx.init({keys: ONYXKEYS}); describe('ReportUtils', () => { beforeAll(() => { + const policyCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.POLICY, [policy], (current) => current.id); Onyx.multiSet({ [ONYXKEYS.PERSONAL_DETAILS_LIST]: participantsPersonalDetails, [ONYXKEYS.SESSION]: {email: currentUserEmail, accountID: currentUserAccountID}, [ONYXKEYS.COUNTRY_CODE]: 1, - [`${ONYXKEYS.COLLECTION.POLICY}${policy.id}` as const]: policy, + ...policyCollectionDataSet, }); return waitForBatchedUpdates(); }); @@ -268,14 +271,14 @@ describe('ReportUtils', () => { }); it('returns false when the matched IOU report does not have an owner accountID', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), ownerAccountID: undefined, }; expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(false); }); it('returns false when the linked iou report has an oustanding IOU', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), iouReportID: '1', }; Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, { @@ -287,7 +290,7 @@ describe('ReportUtils', () => { }); it('returns false when the report has no outstanding IOU but is waiting for a bank account and the logged user is the report owner', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), ownerAccountID: currentUserAccountID, isWaitingOnBankAccount: true, }; @@ -295,7 +298,7 @@ describe('ReportUtils', () => { }); it('returns false when the report has outstanding IOU and is not waiting for a bank account and the logged user is the report owner', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), ownerAccountID: currentUserAccountID, isWaitingOnBankAccount: false, }; @@ -303,7 +306,7 @@ describe('ReportUtils', () => { }); it('returns false when the report has no oustanding IOU but is waiting for a bank account and the logged user is not the report owner', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), ownerAccountID: 97, isWaitingOnBankAccount: true, }; @@ -311,14 +314,14 @@ describe('ReportUtils', () => { }); it('returns true when the report has an unread mention', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), isUnreadWithMention: true, }; expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(true); }); it('returns true when the report is an outstanding task', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.TASK, managerID: currentUserAccountID, isUnreadWithMention: false, @@ -329,7 +332,7 @@ describe('ReportUtils', () => { }); it('returns true when the report has oustanding child request', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), ownerAccountID: 99, hasOutstandingChildRequest: true, isWaitingOnBankAccount: false, @@ -363,7 +366,7 @@ describe('ReportUtils', () => { it('it is a room with no participants except self', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID]); @@ -372,7 +375,7 @@ describe('ReportUtils', () => { it('its not your policy expense chat', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: false, }; @@ -382,7 +385,7 @@ describe('ReportUtils', () => { it('its paid IOU report', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.IOU, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED, }; @@ -392,7 +395,7 @@ describe('ReportUtils', () => { it('its approved Expense report', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.APPROVED, @@ -403,7 +406,7 @@ describe('ReportUtils', () => { it('its paid Expense report', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.EXPENSE, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED, }; @@ -417,7 +420,7 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: false, }).then(() => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), parentReportID: '100', type: CONST.REPORT.TYPE.EXPENSE, }; @@ -433,7 +436,7 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: true, }).then(() => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, @@ -463,7 +466,7 @@ describe('ReportUtils', () => { CONST.REPORT.CHAT_TYPE.POLICY_ROOM, ].every((chatType) => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), chatType, }; const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); @@ -474,7 +477,7 @@ describe('ReportUtils', () => { it('has multiple participants excluding self', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs]); @@ -484,7 +487,7 @@ describe('ReportUtils', () => { it('user has send money permission', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs]); @@ -494,7 +497,7 @@ describe('ReportUtils', () => { it("it's a group DM report", () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.CHAT, participantsAccountIDs: [currentUserAccountID, ...participantsAccountIDs], }; @@ -512,7 +515,7 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: true, }).then(() => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), parentReportID: '102', type: CONST.REPORT.TYPE.EXPENSE, }; @@ -529,7 +532,7 @@ describe('ReportUtils', () => { isOwnPolicyExpenseChat: true, }).then(() => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN, @@ -551,7 +554,7 @@ describe('ReportUtils', () => { it('it is an IOU report in submitted state', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, @@ -563,7 +566,7 @@ describe('ReportUtils', () => { it('it is an IOU report in submitted state even with send money permissions', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, @@ -577,7 +580,7 @@ describe('ReportUtils', () => { describe('return multiple money request option if', () => { it("it is user's own policy expense chat", () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: true, }; @@ -589,7 +592,7 @@ describe('ReportUtils', () => { it('it is a 1:1 DM', () => { const report = { - ...(LHNTestUtils.getFakeReport() as Report), + ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.CHAT, }; const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); @@ -618,7 +621,7 @@ describe('ReportUtils', () => { describe('sortReportsByLastRead', () => { it('should filter out report without reportID & lastReadTime and sort lastReadTime in ascending order', () => { - const reports = [ + const reports: Array> = [ {reportID: '1', lastReadTime: '2023-07-08 07:15:44.030'}, {reportID: '2', lastReadTime: undefined}, {reportID: '3', lastReadTime: '2023-07-06 07:15:44.030'}, @@ -627,42 +630,41 @@ describe('ReportUtils', () => { {reportID: '6'}, null, ]; - const sortedReports = [ + const sortedReports: Array> = [ {reportID: '3', lastReadTime: '2023-07-06 07:15:44.030'}, {reportID: '4', lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU}, {reportID: '1', lastReadTime: '2023-07-08 07:15:44.030'}, - ] as const; + ]; expect(ReportUtils.sortReportsByLastRead(reports, null)).toEqual(sortedReports); }); }); describe('getAllAncestorReportActions', () => { - const reports = [ + const reports: Report[] = [ {reportID: '1', lastReadTime: '2024-02-01 04:56:47.233', reportName: 'Report'}, {reportID: '2', lastReadTime: '2024-02-01 04:56:47.233', parentReportActionID: '1', parentReportID: '1', reportName: 'Report'}, {reportID: '3', lastReadTime: '2024-02-01 04:56:47.233', parentReportActionID: '2', parentReportID: '2', reportName: 'Report'}, {reportID: '4', lastReadTime: '2024-02-01 04:56:47.233', parentReportActionID: '3', parentReportID: '3', reportName: 'Report'}, {reportID: '5', lastReadTime: '2024-02-01 04:56:47.233', parentReportActionID: '4', parentReportID: '4', reportName: 'Report'}, - ] as const; + ]; - const reportActions = [ + const reportActions: ReportAction[] = [ {reportActionID: '1', created: '2024-02-01 04:42:22.965', actionName: 'MARKEDREIMBURSED'}, {reportActionID: '2', created: '2024-02-01 04:42:28.003', actionName: 'MARKEDREIMBURSED'}, {reportActionID: '3', created: '2024-02-01 04:42:31.742', actionName: 'MARKEDREIMBURSED'}, {reportActionID: '4', created: '2024-02-01 04:42:35.619', actionName: 'MARKEDREIMBURSED'}, - ] as const; + ]; beforeAll(() => { + const reportCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.REPORT, reports, (report) => report.reportID); + const reportActionCollectionDataSet = toCollectionDataSet( + ONYXKEYS.COLLECTION.REPORT_ACTIONS, + reportActions.map((reportAction) => ({[reportAction.reportActionID]: reportAction})), + (actions) => Object.values(actions)[0].reportActionID, + ); Onyx.multiSet({ - [`${ONYXKEYS.COLLECTION.REPORT}${reports[0].reportID}` as const]: reports[0], - [`${ONYXKEYS.COLLECTION.REPORT}${reports[1].reportID}` as const]: reports[1], - [`${ONYXKEYS.COLLECTION.REPORT}${reports[2].reportID}` as const]: reports[2], - [`${ONYXKEYS.COLLECTION.REPORT}${reports[3].reportID}` as const]: reports[3], - [`${ONYXKEYS.COLLECTION.REPORT}${reports[4].reportID}` as const]: reports[4], - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[0].reportID}` as const]: {[reportActions[0].reportActionID]: reportActions[0]}, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[1].reportID}` as const]: {[reportActions[1].reportActionID]: reportActions[1]}, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[2].reportID}` as const]: {[reportActions[2].reportActionID]: reportActions[2]}, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reports[3].reportID}` as const]: {[reportActions[3].reportActionID]: reportActions[3]}, + ...reportCollectionDataSet, + ...reportActionCollectionDataSet, }); return waitForBatchedUpdates(); }); From 2a76abbd50660501041cc54a1c32a594594b8036 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Thu, 29 Feb 2024 17:08:34 +0000 Subject: [PATCH 059/504] refactor(typescript): resolve type error --- src/libs/DateUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/DateUtils.ts b/src/libs/DateUtils.ts index 6da5c8af1ff2..0c8a32cbad23 100644 --- a/src/libs/DateUtils.ts +++ b/src/libs/DateUtils.ts @@ -265,7 +265,7 @@ function formatToLongDateWithWeekday(datetime: string | Date): string { * * @returns Sunday */ -function formatToDayOfWeek(datetime: Date): string { +function formatToDayOfWeek(datetime: string | Date): string { return format(new Date(datetime), CONST.DATE.WEEKDAY_TIME_FORMAT); } From af3fd5581859a9e408a15daba5a27d1c069e9186 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Fri, 1 Mar 2024 12:04:48 +0000 Subject: [PATCH 060/504] [TS migration][G3] Feedback --- src/types/onyx/ReportAction.ts | 6 +++++- src/types/onyx/Transaction.ts | 18 +++++++++++++++++- tests/e2e/compare/compare.ts | 5 ++--- tests/unit/CurrencyUtilsTest.ts | 4 ---- tests/unit/IOUUtilsTest.ts | 7 +++---- tests/unit/SidebarTest.ts | 30 ++++++++++++------------------ tests/utils/TestHelper.ts | 10 +++++++++- 7 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index bb5bf50ec6cf..0971fb6b77e1 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -2,6 +2,8 @@ import type {ValueOf} from 'type-fest'; import type {FileObject} from '@components/AttachmentModal'; import type {AvatarSource} from '@libs/UserUtils'; import type CONST from '@src/CONST'; +import type ONYXKEYS from '@src/ONYXKEYS'; +import type CollectionDataSet from '@src/types/utils/CollectionDataSet'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import type * as OnyxCommon from './OnyxCommon'; import type {Decision, Reaction} from './OriginalMessage'; @@ -224,5 +226,7 @@ type ReportAction = ReportActionBase & OriginalMessage; type ReportActions = Record; +type ReportActionCollectionDataSet = CollectionDataSet; + export default ReportAction; -export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage}; +export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage, ReportActionCollectionDataSet}; diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index 1a7541955720..709597c16140 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -1,5 +1,7 @@ import type {KeysOfUnion, ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; +import type ONYXKEYS from '@src/ONYXKEYS'; +import type CollectionDataSet from '@src/types/utils/CollectionDataSet'; import type {Participant, Split} from './IOU'; import type * as OnyxCommon from './OnyxCommon'; import type RecentWaypoint from './RecentWaypoint'; @@ -224,5 +226,19 @@ type AdditionalTransactionChanges = { type TransactionChanges = Partial & AdditionalTransactionChanges; +type TransactionCollectionDataSet = CollectionDataSet; + export default Transaction; -export type {WaypointCollection, Comment, Receipt, Waypoint, ReceiptError, ReceiptErrors, TransactionPendingFieldsKey, TransactionChanges, TaxRate, ReceiptSource}; +export type { + WaypointCollection, + Comment, + Receipt, + Waypoint, + ReceiptError, + ReceiptErrors, + TransactionPendingFieldsKey, + TransactionChanges, + TaxRate, + ReceiptSource, + TransactionCollectionDataSet, +}; diff --git a/tests/e2e/compare/compare.ts b/tests/e2e/compare/compare.ts index bc3d7fae23ea..2de54b416828 100644 --- a/tests/e2e/compare/compare.ts +++ b/tests/e2e/compare/compare.ts @@ -61,9 +61,8 @@ function buildCompareEntry(name: string, compare: Stats, baseline: Stats): Entry */ function compareResults(compareEntries: Metric, baselineEntries: Metric) { // Unique test scenario names - const compareKeys = Object.keys(compareEntries); - const baselineKeys = baselineEntries ? Object.keys(baselineEntries) : []; - const names = Array.from(new Set([...compareKeys, ...baselineKeys])); + const baselineKeys = Object.keys(baselineEntries ?? {}); + const names = Array.from(new Set([...baselineKeys])); const compared: Entry[] = []; diff --git a/tests/unit/CurrencyUtilsTest.ts b/tests/unit/CurrencyUtilsTest.ts index 246af64b1d87..a1e4b03fa715 100644 --- a/tests/unit/CurrencyUtilsTest.ts +++ b/tests/unit/CurrencyUtilsTest.ts @@ -3,7 +3,6 @@ import CONST from '@src/CONST'; import * as CurrencyUtils from '@src/libs/CurrencyUtils'; import LocaleListener from '@src/libs/Localize/LocaleListener'; import ONYXKEYS from '@src/ONYXKEYS'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; // This file can get outdated. In that case, you can follow these steps to update it: // - open your browser console and navigate to the Network tab @@ -37,9 +36,6 @@ describe('CurrencyUtils', () => { describe('getLocalizedCurrencySymbol', () => { test.each(AVAILABLE_LOCALES)('Returns non empty string for all currencyCode with preferredLocale %s', (prefrredLocale) => Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, prefrredLocale).then(() => { - if (isEmptyObject(currencyCodeList)) { - return; - } currencyCodeList.forEach((currencyCode: string) => { const localizedSymbol = CurrencyUtils.getLocalizedCurrencySymbol(currencyCode); diff --git a/tests/unit/IOUUtilsTest.ts b/tests/unit/IOUUtilsTest.ts index b390d0cd70a3..33dd1ff05e13 100644 --- a/tests/unit/IOUUtilsTest.ts +++ b/tests/unit/IOUUtilsTest.ts @@ -1,10 +1,9 @@ -import type {NullishDeep} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import * as IOUUtils from '@src/libs/IOUUtils'; import * as ReportUtils from '@src/libs/ReportUtils'; import * as TransactionUtils from '@src/libs/TransactionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import type Transaction from '@src/types/onyx/Transaction'; +import type {TransactionCollectionDataSet} from '@src/types/onyx/Transaction'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import currencyList from './currencyList.json'; @@ -30,7 +29,7 @@ describe('IOUUtils', () => { const iouReport = ReportUtils.buildOptimisticIOUReport(1, 2, 100, '1', 'USD'); const usdPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', iouReport.reportID); const aedPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'AED', iouReport.reportID); - const MergeQueries: Record<`${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`, NullishDeep> = {}; + const MergeQueries: TransactionCollectionDataSet = {}; MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`] = usdPendingTransaction; MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`] = aedPendingTransaction; @@ -45,7 +44,7 @@ describe('IOUUtils', () => { const usdPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', iouReport.reportID); const aedPendingTransaction = TransactionUtils.buildOptimisticTransaction(100, 'AED', iouReport.reportID); - const MergeQueries: Record<`${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`, NullishDeep> = {}; + const MergeQueries: TransactionCollectionDataSet = {}; MergeQueries[`${ONYXKEYS.COLLECTION.TRANSACTION}${usdPendingTransaction.transactionID}`] = { ...usdPendingTransaction, pendingAction: null, diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index 4a3be66ebe37..89e7a86e095a 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -5,6 +5,8 @@ import CONST from '@src/CONST'; import * as Localize from '@src/libs/Localize'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; +import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; +import type {ReportActionCollectionDataSet} from '@src/types/onyx/ReportAction'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; @@ -38,16 +40,14 @@ describe('Sidebar', () => { describe('archived chats', () => { it('renders the archive reason as the preview message of the chat', () => { const report = { - // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. - ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3, true), + ...LHNTestUtils.getFakeReport([1, 2], 3, true), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, }; const action = { - // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. - ...LHNTestUtils.getFakeReportAction('email1@test.com', 3, true), + ...LHNTestUtils.getFakeReportAction('email1@test.com', 3), actionName: 'CLOSED', originalMessage: { reason: CONST.REPORT.ARCHIVE_REASON.DEFAULT, @@ -62,14 +62,12 @@ describe('Sidebar', () => { // When Onyx is updated with the data and the sidebar re-renders .then(() => { const reportCollection = { - // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, - } as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}${string}`, NullishDeep>; + } as ReportCollectionDataSet; const reportAction = { - // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionId]: action}, - } as Record<`${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS}${string}`, NullishDeep>; + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action}, + } as ReportActionCollectionDataSet; return Onyx.multiSet({ [ONYXKEYS.BETAS]: betas, @@ -93,16 +91,14 @@ describe('Sidebar', () => { }); it('renders the policy deleted archive reason as the preview message of the chat', () => { const report = { - // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. - ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3, true), + ...LHNTestUtils.getFakeReport([1, 2], 3, true), policyName: 'Vikings Policy', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, }; const action = { - // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. - ...LHNTestUtils.getFakeReportAction('email1@test.com', 3, true), + ...LHNTestUtils.getFakeReportAction('email1@test.com', 3), actionName: 'CLOSED', originalMessage: { policyName: 'Vikings Policy', @@ -118,14 +114,12 @@ describe('Sidebar', () => { // When Onyx is updated with the data and the sidebar re-renders .then(() => { const reportCollection = { - // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, - } as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}${string}`, NullishDeep>; + } as ReportCollectionDataSet; const reportAction = { - // @ts-expect-error TODO: Remove this once LHNTestUtils (https://github.com/Expensify/App/issues/25320) is migrated to TypeScript. - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionId]: action}, - } as Record<`${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS}${string}`, NullishDeep>; + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action}, + } as ReportActionCollectionDataSet; return Onyx.multiSet({ [ONYXKEYS.BETAS]: betas, diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts index edef0bd55e5f..7f78d5080967 100644 --- a/tests/utils/TestHelper.ts +++ b/tests/utils/TestHelper.ts @@ -8,7 +8,15 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetails, Report} from '@src/types/onyx'; import waitForBatchedUpdates from './waitForBatchedUpdates'; -type MockFetch = ReturnType & {pause?: () => void; fail?: () => void; succeed?: () => void; resume?: () => Promise}; +type MockFetch = ReturnType & { + pause?: () => void; + + fail?: () => void; + + succeed?: () => void; + + resume?: () => Promise; +}; type Response = {ok: boolean; json: () => Promise<{jsonCode: number}>}; type QueueItem = (value: Response | PromiseLike) => void; From 8022a87f172b44351504cda0fc726745d3575e69 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Fri, 1 Mar 2024 12:12:10 +0000 Subject: [PATCH 061/504] [TS migration][G3] Lint fix --- tests/unit/SidebarTest.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index 89e7a86e095a..c913f5a2900d 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -1,10 +1,8 @@ import {cleanup, screen} from '@testing-library/react-native'; -import type {NullishDeep} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import CONST from '@src/CONST'; import * as Localize from '@src/libs/Localize'; import ONYXKEYS from '@src/ONYXKEYS'; -import type * as OnyxTypes from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import type {ReportActionCollectionDataSet} from '@src/types/onyx/ReportAction'; import * as LHNTestUtils from '../utils/LHNTestUtils'; From 77e3d046b51e8b48a655001432713b1dff794977 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Mon, 4 Mar 2024 10:30:46 +0100 Subject: [PATCH 062/504] fix: resolve comments --- src/components/TagPicker/index.tsx | 2 +- src/libs/OptionsListUtils.ts | 5 +++-- src/types/onyx/PolicyTag.ts | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/TagPicker/index.tsx b/src/components/TagPicker/index.tsx index b553e183a37f..f13c27beadc3 100644 --- a/src/components/TagPicker/index.tsx +++ b/src/components/TagPicker/index.tsx @@ -14,7 +14,7 @@ import type {PolicyTag, PolicyTagList, PolicyTags, RecentlyUsedTags} from '@src/ type SelectedTagOption = { name: string; - enabled?: boolean; + enabled: boolean; accountID: number | null; }; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 832e04d98051..fc765564c900 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -20,6 +20,7 @@ import type { PolicyCategories, PolicyTag, PolicyTagList, + PolicyTags, Report, ReportAction, ReportActions, @@ -125,7 +126,7 @@ type GetOptionsConfig = { categories?: PolicyCategories; recentlyUsedCategories?: string[]; includeTags?: boolean; - tags?: PolicyTagList | Array; + tags?: PolicyTags | Array; recentlyUsedTags?: string[]; canInviteUser?: boolean; includeSelectedOptions?: boolean; @@ -1814,7 +1815,7 @@ function getFilteredOptions( categories: PolicyCategories = {}, recentlyUsedCategories: string[] = [], includeTags = false, - tags: PolicyTagList | Array = {}, + tags: PolicyTags | Array = {}, recentlyUsedTags: string[] = [], canInviteUser = true, includeSelectedOptions = false, diff --git a/src/types/onyx/PolicyTag.ts b/src/types/onyx/PolicyTag.ts index 0b7ccd93fcc3..b2873538cb4d 100644 --- a/src/types/onyx/PolicyTag.ts +++ b/src/types/onyx/PolicyTag.ts @@ -3,13 +3,13 @@ type PolicyTag = { name: string; /** Flag that determines if a tag is active and able to be selected */ - enabled?: boolean; + enabled: boolean; /** "General Ledger code" that corresponds to this tag in an accounting system. Similar to an ID. */ // eslint-disable-next-line @typescript-eslint/naming-convention 'GL Code'?: string; - /** Nested tags */ + /** List of tags */ tags: PolicyTags; /** Flag that determines if a tag is required */ @@ -27,7 +27,7 @@ type PolicyTagList = Record< /** Flag that determines if tags are required */ required: boolean; - /** Nested tags */ + /** List of tags */ tags: PolicyTags; /** Index by which the tag appears in the hierarchy of tags */ From d64a9971a4c24b46b509015ddcc2401a853dfd7e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 4 Mar 2024 16:41:25 +0700 Subject: [PATCH 063/504] Migrate 'AttachmentPicker' component to TypeScript --- .../{index.native.js => index.native.tsx} | 198 ++++++++---------- .../AttachmentPicker/{index.js => index.tsx} | 34 +-- .../launchCamera.android.ts} | 7 +- .../launchCamera.ios.ts} | 0 .../launchCamera.ts} | 2 +- .../AttachmentPicker/launchCamera/types.ts | 47 +++++ ...{attachmentPickerPropTypes.js => types.ts} | 17 +- 7 files changed, 159 insertions(+), 146 deletions(-) rename src/components/AttachmentPicker/{index.native.js => index.native.tsx} (68%) rename src/components/AttachmentPicker/{index.js => index.tsx} (78%) rename src/components/AttachmentPicker/{launchCamera.android.js => launchCamera/launchCamera.android.ts} (88%) rename src/components/AttachmentPicker/{launchCamera.ios.js => launchCamera/launchCamera.ios.ts} (100%) rename src/components/AttachmentPicker/{launchCamera.js => launchCamera/launchCamera.ts} (66%) create mode 100644 src/components/AttachmentPicker/launchCamera/types.ts rename src/components/AttachmentPicker/{attachmentPickerPropTypes.js => types.ts} (58%) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.tsx similarity index 68% rename from src/components/AttachmentPicker/index.native.js rename to src/components/AttachmentPicker/index.native.tsx index 0387ee087127..dcc4296b71ac 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.tsx @@ -1,12 +1,9 @@ -import Str from 'expensify-common/lib/str'; import lodashCompact from 'lodash/compact'; -import PropTypes from 'prop-types'; import React, {useCallback, useMemo, useRef, useState} from 'react'; -import {Alert, Image as RNImage, View} from 'react-native'; +import {Alert, View} from 'react-native'; import RNFetchBlob from 'react-native-blob-util'; import RNDocumentPicker from 'react-native-document-picker'; import {launchImageLibrary} from 'react-native-image-picker'; -import _ from 'underscore'; import * as Expensicons from '@components/Icon/Expensicons'; import MenuItem from '@components/MenuItem'; import Popover from '@components/Popover'; @@ -17,19 +14,32 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as FileUtils from '@libs/fileDownload/FileUtils'; import CONST from '@src/CONST'; -import {defaultProps as baseDefaultProps, propTypes as basePropTypes} from './attachmentPickerPropTypes'; -import launchCamera from './launchCamera'; - -const propTypes = { - ...basePropTypes, - +import type {TranslationPaths} from '@src/languages/types'; +import type IconAsset from '@src/types/utils/IconAsset'; +import type {DocumentPickerOptions, DocumentPickerResponse} from 'react-native-document-picker' +import type {SupportedPlatforms} from 'react-native-document-picker/lib/typescript/fileTypes'; +import type {Asset, Callback, CameraOptions, ImagePickerResponse} from 'react-native-image-picker'; +import launchCamera from './launchCamera/launchCamera'; +import type BaseAttachmentPickerProps from './types'; + +type AttachmentPickerProps = BaseAttachmentPickerProps & { /** If this value is true, then we exclude Camera option. */ - shouldHideCameraOption: PropTypes.bool, + shouldHideCameraOption?: boolean; }; -const defaultProps = { - ...baseDefaultProps, - shouldHideCameraOption: false, +type Item = { + icon: IconAsset; + textTranslationKey: string; + pickAttachment: () => Promise; +}; + +type FileResult = { + name: string; + type: string; + width: number | undefined; + height: number | undefined; + uri: string; + size: number | null; }; /** @@ -45,10 +55,8 @@ const imagePickerOptions = { /** * Return imagePickerOptions based on the type - * @param {String} type - * @returns {Object} */ -const getImagePickerOptions = (type) => { +const getImagePickerOptions = (type: string): CameraOptions => { // mediaType property is one of the ImagePicker configuration to restrict types' const mediaType = type === CONST.ATTACHMENT_PICKER_TYPE.IMAGE ? 'photo' : 'mixed'; return { @@ -58,40 +66,26 @@ const getImagePickerOptions = (type) => { }; /** - * Return documentPickerOptions based on the type - * @param {String} type - * @returns {Object} + * See https://github.com/rnmods/react-native-document-picker#options for DocumentPicker configuration options */ - -const getDocumentPickerOptions = (type) => { - if (type === CONST.ATTACHMENT_PICKER_TYPE.IMAGE) { - return { - type: [RNDocumentPicker.types.images], - copyTo: 'cachesDirectory', - }; - } - return { - type: [RNDocumentPicker.types.allFiles], - copyTo: 'cachesDirectory', - }; -}; +const documentPickerOptions = { + type: [RNDocumentPicker.types.allFiles], + copyTo: 'cachesDirectory', +} satisfies DocumentPickerOptions; /** * The data returned from `show` is different on web and mobile, so use this function to ensure the data we * send to the xhr will be handled properly. - * - * @param {Object} fileData - * @return {Promise} */ -const getDataForUpload = (fileData) => { - const fileName = fileData.fileName || fileData.name || 'chat_attachment'; - const fileResult = { +const getDataForUpload = (fileData: Asset & DocumentPickerResponse): Promise => { + const fileName = fileData.fileName ?? fileData.name ?? 'chat_attachment'; + const fileResult: FileResult = { name: FileUtils.cleanFileName(fileName), type: fileData.type, width: fileData.width, height: fileData.height, - uri: fileData.fileCopyUri || fileData.uri, - size: fileData.fileSize || fileData.size, + uri: fileData.fileCopyUri ?? fileData.uri, + size: fileData.fileSize ?? fileData.size, }; if (fileResult.size) { @@ -109,16 +103,15 @@ const getDataForUpload = (fileData) => { * returns a "show attachment picker" method that takes * a callback. This is the ios/android implementation * opening a modal with attachment options - * @param {propTypes} props - * @returns {JSX.Element} */ -function AttachmentPicker({type, children, shouldHideCameraOption}) { +function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, shouldHideCameraOption = false}: AttachmentPickerProps) { const styles = useThemeStyles(); const [isVisible, setIsVisible] = useState(false); - const completeAttachmentSelection = useRef(); - const onModalHide = useRef(); - const onCanceled = useRef(); + const completeAttachmentSelection = useRef<(data: FileResult) => void>(() => {}); + const onModalHide = useRef<() => void>(() => {}); + const onCanceled = useRef<() => void>(() => {}); + const popoverRef = useRef(null); const {translate} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); @@ -126,20 +119,19 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { /** * A generic handling when we don't know the exact reason for an error */ - const showGeneralAlert = useCallback(() => { - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingAttachment')); + const showGeneralAlert = useCallback((message = '') => { + Alert.alert(translate('attachmentPicker.attachmentError'), `${message !== '' ? message : translate('attachmentPicker.errorWhileSelectingAttachment')}`); }, [translate]); /** * Common image picker handling * * @param {function} imagePickerFunc - RNImagePicker.launchCamera or RNImagePicker.launchImageLibrary - * @returns {Promise} */ const showImagePicker = useCallback( - (imagePickerFunc) => + (imagePickerFunc: (options: CameraOptions, callback: Callback) => Promise): Promise => new Promise((resolve, reject) => { - imagePickerFunc(getImagePickerOptions(type), (response) => { + imagePickerFunc(getImagePickerOptions(type), (response: ImagePickerResponse) => { if (response.didCancel) { // When the user cancelled resolve with no attachment return resolve(); @@ -166,11 +158,11 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { /** * Launch the DocumentPicker. Results are in the same format as ImagePicker * - * @returns {Promise} + * @returns {Promise} */ const showDocumentPicker = useCallback( - () => - RNDocumentPicker.pick(getDocumentPickerOptions(type)).catch((error) => { + (): Promise => + RNDocumentPicker.pick(documentPickerOptions).catch((error) => { if (RNDocumentPicker.isCancel(error)) { return; } @@ -178,10 +170,10 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { showGeneralAlert(error.message); throw error; }), - [showGeneralAlert, type], + [showGeneralAlert], ); - const menuItemData = useMemo(() => { + const menuItemData: Item[] = useMemo(() => { const data = lodashCompact([ !shouldHideCameraOption && { icon: Expensicons.Camera, @@ -193,7 +185,7 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { textTranslationKey: 'attachmentPicker.chooseFromGallery', pickAttachment: () => showImagePicker(launchImageLibrary), }, - { + type !== CONST.ATTACHMENT_PICKER_TYPE.IMAGE && { icon: Expensicons.Paperclip, textTranslationKey: 'attachmentPicker.chooseDocument', pickAttachment: showDocumentPicker, @@ -201,7 +193,7 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { ]); return data; - }, [showDocumentPicker, showImagePicker, shouldHideCameraOption]); + }, [showDocumentPicker, showImagePicker, type, shouldHideCameraOption]); const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({initialFocusedIndex: -1, maxIndex: menuItemData.length - 1, isActive: isVisible}); @@ -215,10 +207,10 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { /** * Opens the attachment modal * - * @param {function} onPickedHandler A callback that will be called with the selected attachment - * @param {function} onCanceledHandler A callback that will be called without a selected attachment + * @param onPickedHandler A callback that will be called with the selected attachment + * @param onCanceledHandler A callback that will be called without a selected attachment */ - const open = (onPickedHandler, onCanceledHandler = () => {}) => { + const open = (onPickedHandler: () => void, onCanceledHandler: () => void = () => {}) => { completeAttachmentSelection.current = onPickedHandler; onCanceled.current = onCanceledHandler; setIsVisible(true); @@ -232,15 +224,23 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { }; /** - * @param {Object} fileData - * @returns {Promise} + * Handles the image/document picker result and + * sends the selected attachment to the caller (parent component) */ - const validateAndCompleteAttachmentSelection = useCallback( - (fileData) => { + const pickAttachment = useCallback( + (attachments: Array = []): Promise => { + if (attachments.length === 0) { + onCanceled.current(); + return Promise.resolve(); + } + + const fileData = attachments[0]; + if (fileData.width === -1 || fileData.height === -1) { showImageCorruptionAlert(); return Promise.resolve(); } + return getDataForUpload(fileData) .then((result) => { completeAttachmentSelection.current(result); @@ -253,33 +253,6 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { [showGeneralAlert, showImageCorruptionAlert], ); - /** - * Handles the image/document picker result and - * sends the selected attachment to the caller (parent component) - * - * @param {Array} attachments - * @returns {Promise} - */ - const pickAttachment = useCallback( - (attachments = []) => { - if (attachments.length === 0) { - onCanceled.current(); - return Promise.resolve(); - } - const fileData = _.first(attachments); - if (Str.isImage(fileData.fileName || fileData.name)) { - RNImage.getSize(fileData.fileCopyUri || fileData.uri, (width, height) => { - fileData.width = width; - fileData.height = height; - return validateAndCompleteAttachmentSelection(fileData); - }); - } else { - return validateAndCompleteAttachmentSelection(fileData); - } - }, - [validateAndCompleteAttachmentSelection], - ); - /** * Setup native attachment selection to start after this popover closes * @@ -287,24 +260,24 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { * @param {Function} item.pickAttachment */ const selectItem = useCallback( - (item) => { + (item: Item) => { /* setTimeout delays execution to the frame after the modal closes * without this on iOS closing the modal closes the gallery/camera as well */ - onModalHide.current = () => - setTimeout( - () => - item - .pickAttachment() - .then(pickAttachment) - .catch(console.error) - .finally(() => delete onModalHide.current), - 200, - ); - + onModalHide.current = () => { + setTimeout(() => { + item + .pickAttachment() + .then(pickAttachment) + .catch(console.error) + .finally(() => delete onModalHide.current !== undefined); + }, 200); + }; + close(); }, [pickAttachment], ); + useKeyboardShortcut( CONST.KEYBOARD_SHORTCUTS.ENTER, @@ -322,10 +295,8 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { /** * Call the `children` renderProp with the interface defined in propTypes - * - * @returns {React.ReactNode} */ - const renderChildren = () => + const renderChildren = (): React.ReactNode => children({ openPicker: ({onPicked, onCanceled: newOnCanceled}) => open(onPicked, newOnCanceled), }); @@ -338,15 +309,16 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { onCanceled.current(); }} isVisible={isVisible} - anchorPosition={styles.createMenuPosition} + anchorRef={popoverRef} + // anchorPosition={styles.createMenuPosition} onModalHide={onModalHide.current} > - {_.map(menuItemData, (item, menuIndex) => ( + {menuItemData.map((item, menuIndex) => ( selectItem(item)} focused={focusedIndex === menuIndex} /> @@ -358,8 +330,6 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) { ); } -AttachmentPicker.propTypes = propTypes; -AttachmentPicker.defaultProps = defaultProps; AttachmentPicker.displayName = 'AttachmentPicker'; -export default AttachmentPicker; +export default AttachmentPicker; \ No newline at end of file diff --git a/src/components/AttachmentPicker/index.js b/src/components/AttachmentPicker/index.tsx similarity index 78% rename from src/components/AttachmentPicker/index.js rename to src/components/AttachmentPicker/index.tsx index 24024eae6515..9a372a9d4a48 100644 --- a/src/components/AttachmentPicker/index.js +++ b/src/components/AttachmentPicker/index.tsx @@ -1,14 +1,12 @@ import React, {useRef} from 'react'; import Visibility from '@libs/Visibility'; import CONST from '@src/CONST'; -import {defaultProps, propTypes} from './attachmentPickerPropTypes'; +import type AttachmentPickerProps from './types'; /** * Returns acceptable FileTypes based on ATTACHMENT_PICKER_TYPE - * @param {String} type - * @returns {String|undefined} Picker will accept all file types when its undefined */ -function getAcceptableFileTypes(type) { +function getAcceptableFileTypes(type: string): string | undefined { if (type !== CONST.ATTACHMENT_PICKER_TYPE.IMAGE) { return; } @@ -22,13 +20,11 @@ function getAcceptableFileTypes(type) { * a callback. This is the web/mWeb/desktop version since * on a Browser we must append a hidden input to the DOM * and listen to onChange event. - * @param {propTypes} props - * @returns {JSX.Element} */ -function AttachmentPicker(props) { - const fileInput = useRef(); - const onPicked = useRef(); - const onCanceled = useRef(() => {}); +function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}: AttachmentPickerProps): React.JSX.Element { + const fileInput = useRef(null); + const onPicked = useRef<(file: File) => void>(() => {}); + const onCanceled = useRef<() => void>(() => {}); return ( <> @@ -37,6 +33,10 @@ function AttachmentPicker(props) { type="file" ref={fileInput} onChange={(e) => { + if (!e.target.files) { + return; + } + const file = e.target.files[0]; if (file) { @@ -45,7 +45,9 @@ function AttachmentPicker(props) { } // Cleanup after selecting a file to start from a fresh state - fileInput.current.value = null; + if (fileInput.current) { + fileInput.current.value = ''; + } }} // We are stopping the event propagation because triggering the `click()` on the hidden input // causes the event to unexpectedly bubble up to anything wrapping this component e.g. Pressable @@ -72,12 +74,12 @@ function AttachmentPicker(props) { {once: true}, ); }} - accept={getAcceptableFileTypes(props.type)} + accept={getAcceptableFileTypes(type)} /> - {props.children({ + {children({ openPicker: ({onPicked: newOnPicked, onCanceled: newOnCanceled = () => {}}) => { onPicked.current = newOnPicked; - fileInput.current.click(); + fileInput.current?.click(); onCanceled.current = newOnCanceled; }, })} @@ -85,6 +87,4 @@ function AttachmentPicker(props) { ); } -AttachmentPicker.propTypes = propTypes; -AttachmentPicker.defaultProps = defaultProps; -export default AttachmentPicker; +export default AttachmentPicker; \ No newline at end of file diff --git a/src/components/AttachmentPicker/launchCamera.android.js b/src/components/AttachmentPicker/launchCamera/launchCamera.android.ts similarity index 88% rename from src/components/AttachmentPicker/launchCamera.android.js rename to src/components/AttachmentPicker/launchCamera/launchCamera.android.ts index b431c55e756d..cac42a874495 100644 --- a/src/components/AttachmentPicker/launchCamera.android.js +++ b/src/components/AttachmentPicker/launchCamera/launchCamera.android.ts @@ -1,15 +1,14 @@ import {PermissionsAndroid} from 'react-native'; import {launchCamera} from 'react-native-image-picker'; +import type {Callback, CameraOptions} from './types'; /** * Launching the camera for Android involves checking for permissions * And only then starting the camera * If the user deny permission the callback will be called with an error response * in the same format as the error returned by react-native-image-picker - * @param {CameraOptions} options - * @param {function} callback - callback called with the result */ -export default function launchCameraAndroid(options, callback) { +export default function launchCameraAndroid(options: CameraOptions, callback: Callback) { // Checks current camera permissions and prompts the user in case they aren't granted PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA) .then((permission) => { @@ -29,4 +28,4 @@ export default function launchCameraAndroid(options, callback) { errorCode: error.errorCode || 'others', }); }); -} +} \ No newline at end of file diff --git a/src/components/AttachmentPicker/launchCamera.ios.js b/src/components/AttachmentPicker/launchCamera/launchCamera.ios.ts similarity index 100% rename from src/components/AttachmentPicker/launchCamera.ios.js rename to src/components/AttachmentPicker/launchCamera/launchCamera.ios.ts diff --git a/src/components/AttachmentPicker/launchCamera.js b/src/components/AttachmentPicker/launchCamera/launchCamera.ts similarity index 66% rename from src/components/AttachmentPicker/launchCamera.js rename to src/components/AttachmentPicker/launchCamera/launchCamera.ts index dc1f921086de..d272e629f98f 100644 --- a/src/components/AttachmentPicker/launchCamera.js +++ b/src/components/AttachmentPicker/launchCamera/launchCamera.ts @@ -1,3 +1,3 @@ import {launchCamera} from 'react-native-image-picker'; -export default launchCamera; +export default launchCamera; \ No newline at end of file diff --git a/src/components/AttachmentPicker/launchCamera/types.ts b/src/components/AttachmentPicker/launchCamera/types.ts new file mode 100644 index 000000000000..c7f0481c7773 --- /dev/null +++ b/src/components/AttachmentPicker/launchCamera/types.ts @@ -0,0 +1,47 @@ +type Callback = (response: ImagePickerResponse) => void; +type OptionsCommon = { + mediaType: MediaType; + maxWidth?: number; + maxHeight?: number; + quality?: PhotoQuality; + videoQuality?: AndroidVideoOptions | IOSVideoOptions; + includeBase64?: boolean; + includeExtra?: boolean; + presentationStyle?: 'currentContext' | 'fullScreen' | 'pageSheet' | 'formSheet' | 'popover' | 'overFullScreen' | 'overCurrentContext'; +}; +type ImageLibraryOptions = OptionsCommon & { + selectionLimit?: number; +}; +type CameraOptions = OptionsCommon & { + durationLimit?: number; + saveToPhotos?: boolean; + cameraType?: CameraType; +}; +type Asset = { + base64?: string; + uri?: string; + width?: number; + height?: number; + fileSize?: number; + type?: string; + fileName?: string; + duration?: number; + bitrate?: number; + timestamp?: string; + id?: string; +}; +type ImagePickerResponse = { + didCancel?: boolean; + errorCode?: ErrorCode; + errorMessage?: string; + assets?: Asset[]; +}; +type PhotoQuality = 0 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1; +type CameraType = 'back' | 'front'; +type MediaType = 'photo' | 'video' | 'mixed'; +type AndroidVideoOptions = 'low' | 'high'; +type IOSVideoOptions = 'low' | 'medium' | 'high'; +type ErrorCode = 'camera_unavailable' | 'permission' | 'others'; +type ErrorLaunchCamera = Error & ErrorCode + +export type {CameraOptions, Callback, ErrorCode, ImagePickerResponse, Asset, ImageLibraryOptions}; \ No newline at end of file diff --git a/src/components/AttachmentPicker/attachmentPickerPropTypes.js b/src/components/AttachmentPicker/types.ts similarity index 58% rename from src/components/AttachmentPicker/attachmentPickerPropTypes.js rename to src/components/AttachmentPicker/types.ts index a3a346f5ea27..19b98d85f691 100644 --- a/src/components/AttachmentPicker/attachmentPickerPropTypes.js +++ b/src/components/AttachmentPicker/types.ts @@ -1,7 +1,8 @@ -import PropTypes from 'prop-types'; -import CONST from '@src/CONST'; +import type {ReactNode} from 'react'; +import type {ValueOf} from 'type-fest'; +import type CONST from '@src/CONST'; -const propTypes = { +type AttachmentPickerProps = { /** * A renderProp with the following interface * @@ -20,14 +21,10 @@ const propTypes = { * )} * * */ - children: PropTypes.func.isRequired, + children: (openPicker: ({onPicked, onCanceled}: {onPicked: (file: File) => void; onCanceled?: () => void}) => void) => ReactNode; /** The types of files that can be selected with this picker. */ - type: PropTypes.oneOf([CONST.ATTACHMENT_PICKER_TYPE.FILE, CONST.ATTACHMENT_PICKER_TYPE.IMAGE]), + type?: ValueOf; }; -const defaultProps = { - type: CONST.ATTACHMENT_PICKER_TYPE.FILE, -}; - -export {propTypes, defaultProps}; +export default AttachmentPickerProps; \ No newline at end of file From 1825d3a3c0357e6a2ef29d867758f843c9df66ec Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Mon, 4 Mar 2024 09:51:58 +0000 Subject: [PATCH 064/504] [TS migration][G3] Fixed lint issue --- tests/utils/TestHelper.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts index 7f78d5080967..165ffc670902 100644 --- a/tests/utils/TestHelper.ts +++ b/tests/utils/TestHelper.ts @@ -184,7 +184,10 @@ function getGlobalFetchMock() { if (!isPaused) { return Promise.resolve(getResponse()); } - return new Promise((resolve) => queue.push(resolve)); + return new Promise((resolve) => { + queue.push(resolve); + }); + }); mockFetch.pause = () => (isPaused = true); From de503429dfab4d0bd6d8d33460a4b52304e401a7 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Mon, 4 Mar 2024 10:04:26 +0000 Subject: [PATCH 065/504] [TS migration][G3] TS fix --- tests/e2e/compare/compare.ts | 13 +------------ tests/utils/TestHelper.ts | 1 - 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/e2e/compare/compare.ts b/tests/e2e/compare/compare.ts index 2de54b416828..443265802a98 100644 --- a/tests/e2e/compare/compare.ts +++ b/tests/e2e/compare/compare.ts @@ -1,19 +1,10 @@ import type {Stats} from '../measure/math'; import getStats from '../measure/math'; import * as math from './math'; +import type {Entry} from './output/console'; import printToConsole from './output/console'; import writeToMarkdown from './output/markdown'; -type Entry = { - name: string; - baseline?: Stats; - current?: Stats; - diff?: number; - relativeDurationDiff?: number; - isDurationDiffOfSignificance?: boolean; - mean?: number; -}; - type Metric = Record; /* @@ -100,5 +91,3 @@ export default (main: Metric, delta: Metric, outputFile: string, outputFormat = return writeToMarkdown(outputFile, outputData); } }; - -export type {Entry}; diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts index 165ffc670902..a9f72a40cf3f 100644 --- a/tests/utils/TestHelper.ts +++ b/tests/utils/TestHelper.ts @@ -187,7 +187,6 @@ function getGlobalFetchMock() { return new Promise((resolve) => { queue.push(resolve); }); - }); mockFetch.pause = () => (isPaused = true); From 049f95069ee50330c678076d1b4deadcc9aa389c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 4 Mar 2024 17:08:58 +0700 Subject: [PATCH 066/504] fix: type in launch camera --- .../AttachmentPicker/index.native.tsx | 23 ++++++++++--------- src/components/AttachmentPicker/index.tsx | 2 +- .../launchCamera/launchCamera.android.ts | 7 +++--- .../launchCamera/launchCamera.ios.ts | 11 ++++----- .../launchCamera/launchCamera.ts | 2 +- .../AttachmentPicker/launchCamera/types.ts | 11 +++++++-- src/components/AttachmentPicker/types.ts | 2 +- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.tsx b/src/components/AttachmentPicker/index.native.tsx index dcc4296b71ac..3aaaac1083a0 100644 --- a/src/components/AttachmentPicker/index.native.tsx +++ b/src/components/AttachmentPicker/index.native.tsx @@ -3,7 +3,10 @@ import React, {useCallback, useMemo, useRef, useState} from 'react'; import {Alert, View} from 'react-native'; import RNFetchBlob from 'react-native-blob-util'; import RNDocumentPicker from 'react-native-document-picker'; +import type {DocumentPickerOptions, DocumentPickerResponse} from 'react-native-document-picker'; +import type {SupportedPlatforms} from 'react-native-document-picker/lib/typescript/fileTypes'; import {launchImageLibrary} from 'react-native-image-picker'; +import type {Asset, Callback, CameraOptions, ImagePickerResponse} from 'react-native-image-picker'; import * as Expensicons from '@components/Icon/Expensicons'; import MenuItem from '@components/MenuItem'; import Popover from '@components/Popover'; @@ -16,9 +19,6 @@ import * as FileUtils from '@libs/fileDownload/FileUtils'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import type IconAsset from '@src/types/utils/IconAsset'; -import type {DocumentPickerOptions, DocumentPickerResponse} from 'react-native-document-picker' -import type {SupportedPlatforms} from 'react-native-document-picker/lib/typescript/fileTypes'; -import type {Asset, Callback, CameraOptions, ImagePickerResponse} from 'react-native-image-picker'; import launchCamera from './launchCamera/launchCamera'; import type BaseAttachmentPickerProps from './types'; @@ -119,9 +119,12 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s /** * A generic handling when we don't know the exact reason for an error */ - const showGeneralAlert = useCallback((message = '') => { - Alert.alert(translate('attachmentPicker.attachmentError'), `${message !== '' ? message : translate('attachmentPicker.errorWhileSelectingAttachment')}`); - }, [translate]); + const showGeneralAlert = useCallback( + (message = '') => { + Alert.alert(translate('attachmentPicker.attachmentError'), `${message !== '' ? message : translate('attachmentPicker.errorWhileSelectingAttachment')}`); + }, + [translate], + ); /** * Common image picker handling @@ -265,19 +268,17 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s * without this on iOS closing the modal closes the gallery/camera as well */ onModalHide.current = () => { setTimeout(() => { - item - .pickAttachment() + item.pickAttachment() .then(pickAttachment) .catch(console.error) .finally(() => delete onModalHide.current !== undefined); }, 200); }; - + close(); }, [pickAttachment], ); - useKeyboardShortcut( CONST.KEYBOARD_SHORTCUTS.ENTER, @@ -332,4 +333,4 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s AttachmentPicker.displayName = 'AttachmentPicker'; -export default AttachmentPicker; \ No newline at end of file +export default AttachmentPicker; diff --git a/src/components/AttachmentPicker/index.tsx b/src/components/AttachmentPicker/index.tsx index 9a372a9d4a48..e8a23e29f114 100644 --- a/src/components/AttachmentPicker/index.tsx +++ b/src/components/AttachmentPicker/index.tsx @@ -87,4 +87,4 @@ function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}: ); } -export default AttachmentPicker; \ No newline at end of file +export default AttachmentPicker; diff --git a/src/components/AttachmentPicker/launchCamera/launchCamera.android.ts b/src/components/AttachmentPicker/launchCamera/launchCamera.android.ts index cac42a874495..135b5dfd80e6 100644 --- a/src/components/AttachmentPicker/launchCamera/launchCamera.android.ts +++ b/src/components/AttachmentPicker/launchCamera/launchCamera.android.ts @@ -1,6 +1,7 @@ import {PermissionsAndroid} from 'react-native'; import {launchCamera} from 'react-native-image-picker'; import type {Callback, CameraOptions} from './types'; +import {ErrorLaunchCamera} from './types'; /** * Launching the camera for Android involves checking for permissions @@ -13,9 +14,7 @@ export default function launchCameraAndroid(options: CameraOptions, callback: Ca PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA) .then((permission) => { if (permission !== PermissionsAndroid.RESULTS.GRANTED) { - const error = new Error('User did not grant permissions'); - error.errorCode = 'permission'; - throw error; + throw new ErrorLaunchCamera('User did not grant permissions', 'permission'); } launchCamera(options, callback); @@ -28,4 +27,4 @@ export default function launchCameraAndroid(options: CameraOptions, callback: Ca errorCode: error.errorCode || 'others', }); }); -} \ No newline at end of file +} diff --git a/src/components/AttachmentPicker/launchCamera/launchCamera.ios.ts b/src/components/AttachmentPicker/launchCamera/launchCamera.ios.ts index d6e3518d7188..cffb00f39e4a 100644 --- a/src/components/AttachmentPicker/launchCamera/launchCamera.ios.ts +++ b/src/components/AttachmentPicker/launchCamera/launchCamera.ios.ts @@ -1,24 +1,21 @@ import {launchCamera} from 'react-native-image-picker'; import {PERMISSIONS, request, RESULTS} from 'react-native-permissions'; +import type {Callback, CameraOptions} from './types'; +import {ErrorLaunchCamera} from './types'; /** * Launching the camera for iOS involves checking for permissions * And only then starting the camera * If the user deny permission the callback will be called with an error response * in the same format as the error returned by react-native-image-picker - * @param {CameraOptions} options - * @param {function} callback - callback called with the result */ -export default function launchCameraIOS(options, callback) { +export default function launchCameraIOS(options: CameraOptions, callback: Callback) { // Checks current camera permissions and prompts the user in case they aren't granted request(PERMISSIONS.IOS.CAMERA) .then((permission) => { if (permission !== RESULTS.GRANTED) { - const error = new Error('User did not grant permissions'); - error.errorCode = 'permission'; - throw error; + throw new ErrorLaunchCamera('User did not grant permissions', 'permission'); } - launchCamera(options, callback); }) .catch((error) => { diff --git a/src/components/AttachmentPicker/launchCamera/launchCamera.ts b/src/components/AttachmentPicker/launchCamera/launchCamera.ts index d272e629f98f..dc1f921086de 100644 --- a/src/components/AttachmentPicker/launchCamera/launchCamera.ts +++ b/src/components/AttachmentPicker/launchCamera/launchCamera.ts @@ -1,3 +1,3 @@ import {launchCamera} from 'react-native-image-picker'; -export default launchCamera; \ No newline at end of file +export default launchCamera; diff --git a/src/components/AttachmentPicker/launchCamera/types.ts b/src/components/AttachmentPicker/launchCamera/types.ts index c7f0481c7773..1a3aae3f0ad7 100644 --- a/src/components/AttachmentPicker/launchCamera/types.ts +++ b/src/components/AttachmentPicker/launchCamera/types.ts @@ -42,6 +42,13 @@ type MediaType = 'photo' | 'video' | 'mixed'; type AndroidVideoOptions = 'low' | 'high'; type IOSVideoOptions = 'low' | 'medium' | 'high'; type ErrorCode = 'camera_unavailable' | 'permission' | 'others'; -type ErrorLaunchCamera = Error & ErrorCode +class ErrorLaunchCamera extends Error { + errorCode: ErrorCode; -export type {CameraOptions, Callback, ErrorCode, ImagePickerResponse, Asset, ImageLibraryOptions}; \ No newline at end of file + constructor(message: string, errorCode: ErrorCode) { + super(message); + this.errorCode = errorCode; + } +} +export {ErrorLaunchCamera}; +export type {CameraOptions, Callback, ErrorCode, ImagePickerResponse, Asset, ImageLibraryOptions}; diff --git a/src/components/AttachmentPicker/types.ts b/src/components/AttachmentPicker/types.ts index 19b98d85f691..b9974f4082b2 100644 --- a/src/components/AttachmentPicker/types.ts +++ b/src/components/AttachmentPicker/types.ts @@ -27,4 +27,4 @@ type AttachmentPickerProps = { type?: ValueOf; }; -export default AttachmentPickerProps; \ No newline at end of file +export default AttachmentPickerProps; From 451f83d3be867c631be0503e06dcfb12ad60753e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Mon, 4 Mar 2024 11:48:39 +0100 Subject: [PATCH 067/504] Fix resuming video after regaining internet connection --- src/components/VideoPlayer/BaseVideoPlayer.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/VideoPlayer/BaseVideoPlayer.js b/src/components/VideoPlayer/BaseVideoPlayer.js index 360095ec7eb4..8efc6604dfa1 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.js +++ b/src/components/VideoPlayer/BaseVideoPlayer.js @@ -8,6 +8,7 @@ import Hoverable from '@components/Hoverable'; import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback'; import {usePlaybackContext} from '@components/VideoPlayerContexts/PlaybackContext'; import VideoPopoverMenu from '@components/VideoPopoverMenu'; +import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import * as Browser from '@libs/Browser'; @@ -44,6 +45,7 @@ function BaseVideoPlayer({ const styles = useThemeStyles(); const {pauseVideo, playVideo, currentlyPlayingURL, updateSharedElements, sharedElement, originalParent, shareVideoPlayerElements, currentVideoPlayerRef, updateCurrentlyPlayingURL} = usePlaybackContext(); + const {isOffline} = useNetwork(); const [duration, setDuration] = useState(videoDuration * 1000); const [position, setPosition] = useState(0); const [isPlaying, setIsPlaying] = useState(false); @@ -214,13 +216,20 @@ function BaseVideoPlayer({ style={[styles.w100, styles.h100, videoPlayerStyle]} videoStyle={[styles.w100, styles.h100, videoStyle]} source={{ - uri: sourceURL, + // if video is loading and is offline, we want to change uri to null to + // reset the video player after connection is back + uri: !isLoading || (isLoading && !isOffline) ? sourceURL : null, }} shouldPlay={false} useNativeControls={false} resizeMode={resizeMode} isLooping={isLooping} - onReadyForDisplay={onVideoLoaded} + onReadyForDisplay={(e) => { + if (isCurrentlyURLSet) { + playVideo(); + } + onVideoLoaded(e); + }} onPlaybackStatusUpdate={handlePlaybackStatusUpdate} onFullscreenUpdate={handleFullscreenUpdate} /> From d104cb08a10e2404101752e15431128cb88ee083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Mon, 4 Mar 2024 11:54:07 +0100 Subject: [PATCH 068/504] Fix playing video in preview when uploading --- src/components/VideoPlayer/BaseVideoPlayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/VideoPlayer/BaseVideoPlayer.js b/src/components/VideoPlayer/BaseVideoPlayer.js index 8efc6604dfa1..16a210a398b4 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.js +++ b/src/components/VideoPlayer/BaseVideoPlayer.js @@ -225,7 +225,7 @@ function BaseVideoPlayer({ resizeMode={resizeMode} isLooping={isLooping} onReadyForDisplay={(e) => { - if (isCurrentlyURLSet) { + if (isCurrentlyURLSet && !isUploading) { playVideo(); } onVideoLoaded(e); From d34c62bd1aa9ab68b95f58bf37d8268111d0b72a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 5 Mar 2024 10:21:51 +0700 Subject: [PATCH 069/504] fix type select item function --- src/components/AttachmentPicker/index.native.tsx | 9 ++++----- src/components/AttachmentPicker/index.tsx | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.tsx b/src/components/AttachmentPicker/index.native.tsx index 3aaaac1083a0..e144a210fa7c 100644 --- a/src/components/AttachmentPicker/index.native.tsx +++ b/src/components/AttachmentPicker/index.native.tsx @@ -109,7 +109,7 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s const [isVisible, setIsVisible] = useState(false); const completeAttachmentSelection = useRef<(data: FileResult) => void>(() => {}); - const onModalHide = useRef<() => void>(() => {}); + const onModalHide = useRef<() => void>(); const onCanceled = useRef<() => void>(() => {}); const popoverRef = useRef(null); @@ -266,15 +266,14 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s (item: Item) => { /* setTimeout delays execution to the frame after the modal closes * without this on iOS closing the modal closes the gallery/camera as well */ - onModalHide.current = () => { + onModalHide.current = () => { setTimeout(() => { item.pickAttachment() - .then(pickAttachment) + .then((result) => pickAttachment(result as Array)) .catch(console.error) - .finally(() => delete onModalHide.current !== undefined); + .finally(() => delete onModalHide.current); }, 200); }; - close(); }, [pickAttachment], diff --git a/src/components/AttachmentPicker/index.tsx b/src/components/AttachmentPicker/index.tsx index e8a23e29f114..9a372a9d4a48 100644 --- a/src/components/AttachmentPicker/index.tsx +++ b/src/components/AttachmentPicker/index.tsx @@ -87,4 +87,4 @@ function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}: ); } -export default AttachmentPicker; +export default AttachmentPicker; \ No newline at end of file From e3c79db7b98918f70b23796604aa25afcb02af1d Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Tue, 5 Mar 2024 16:23:56 +0000 Subject: [PATCH 070/504] [TS migration] Migrate Storybook files --- .storybook/{main.js => main.ts} | 21 ++++++- .storybook/{manager.js => manager.ts} | 0 .storybook/{preview.js => preview.tsx} | 28 +++++---- .storybook/{theme.js => theme.ts} | 5 +- .storybook/webpack.config.js | 54 ------------------ .storybook/webpack.config.ts | 79 ++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 67 deletions(-) rename .storybook/{main.js => main.ts} (59%) rename .storybook/{manager.js => manager.ts} (100%) rename .storybook/{preview.js => preview.tsx} (51%) rename .storybook/{theme.js => theme.ts} (86%) delete mode 100644 .storybook/webpack.config.js create mode 100644 .storybook/webpack.config.ts diff --git a/.storybook/main.js b/.storybook/main.ts similarity index 59% rename from .storybook/main.js rename to .storybook/main.ts index 7d063fd6ffe1..0234f18ff488 100644 --- a/.storybook/main.js +++ b/.storybook/main.ts @@ -1,12 +1,29 @@ -module.exports = { +type Dir = { + from: string; + to: string; +}; + +type Main = { + stories: string[]; + addons: string[]; + staticDirs: Array; + core: { + builder: string; + }; + managerHead: (head: string) => string; +}; + +const main: Main = { stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], addons: ['@storybook/addon-essentials', '@storybook/addon-a11y', '@storybook/addon-react-native-web'], staticDirs: ['./public', {from: '../assets/css', to: 'css'}, {from: '../assets/fonts/web', to: 'fonts'}], core: { builder: 'webpack5', }, - managerHead: (head) => ` + managerHead: (head: string) => ` ${head} ${process.env.ENV === 'staging' ? '' : ''} `, }; + +export default main; diff --git a/.storybook/manager.js b/.storybook/manager.ts similarity index 100% rename from .storybook/manager.js rename to .storybook/manager.ts diff --git a/.storybook/preview.js b/.storybook/preview.tsx similarity index 51% rename from .storybook/preview.js rename to .storybook/preview.tsx index a89c720976c9..5ddb9d04d8ae 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.tsx @@ -2,16 +2,24 @@ import {PortalProvider} from '@gorhom/portal'; import React from 'react'; import Onyx from 'react-native-onyx'; import {SafeAreaProvider} from 'react-native-safe-area-context'; -import ComposeProviders from '../src/components/ComposeProviders'; -import HTMLEngineProvider from '../src/components/HTMLEngineProvider'; -import {LocaleContextProvider} from '../src/components/LocaleContextProvider'; -import OnyxProvider from '../src/components/OnyxProvider'; -import {EnvironmentProvider} from '../src/components/withEnvironment'; -import {KeyboardStateProvider} from '../src/components/withKeyboardState'; -import {WindowDimensionsProvider} from '../src/components/withWindowDimensions'; -import ONYXKEYS from '../src/ONYXKEYS'; +import ComposeProviders from '@src/components/ComposeProviders'; +import HTMLEngineProvider from '@src/components/HTMLEngineProvider'; +import {LocaleContextProvider} from '@src/components/LocaleContextProvider'; +import OnyxProvider from '@src/components/OnyxProvider'; +import {EnvironmentProvider} from '@src/components/withEnvironment'; +import {KeyboardStateProvider} from '@src/components/withKeyboardState'; +import {WindowDimensionsProvider} from '@src/components/withWindowDimensions'; +import ONYXKEYS from '@src/ONYXKEYS'; import './fonts.css'; +type Parameter = { + controls: { + matchers: { + color: RegExp; + }; + }; +}; + Onyx.init({ keys: ONYXKEYS, initialKeyStates: { @@ -20,7 +28,7 @@ Onyx.init({ }); const decorators = [ - (Story) => ( + (Story: React.ElementType) => ( @@ -29,7 +37,7 @@ const decorators = [ ), ]; -const parameters = { +const parameters: Parameter = { controls: { matchers: { color: /(background|color)$/i, diff --git a/.storybook/theme.js b/.storybook/theme.ts similarity index 86% rename from .storybook/theme.js rename to .storybook/theme.ts index 08d8b584d580..f1ace5dd37c0 100644 --- a/.storybook/theme.js +++ b/.storybook/theme.ts @@ -1,7 +1,8 @@ +import type {ThemeVars} from '@storybook/theming'; import {create} from '@storybook/theming'; import colors from '../src/styles/theme/colors'; -export default create({ +const theme: ThemeVars = create({ brandTitle: 'New Expensify UI Docs', brandImage: 'logomark.svg', fontBase: 'ExpensifyNeue-Regular', @@ -21,3 +22,5 @@ export default create({ appBorderRadius: 8, inputBorderRadius: 8, }); + +export default theme; diff --git a/.storybook/webpack.config.js b/.storybook/webpack.config.js deleted file mode 100644 index 204f70344b18..000000000000 --- a/.storybook/webpack.config.js +++ /dev/null @@ -1,54 +0,0 @@ -/* eslint-disable no-underscore-dangle */ -/* eslint-disable no-param-reassign */ -const path = require('path'); -const dotenv = require('dotenv'); -const _ = require('underscore'); - -let envFile; -switch (process.env.ENV) { - case 'production': - envFile = '.env.production'; - break; - case 'staging': - envFile = '.env.staging'; - break; - default: - envFile = '.env'; -} - -const env = dotenv.config({path: path.resolve(__dirname, `../${envFile}`)}); -const custom = require('../config/webpack/webpack.common')({ - envFile, -}); - -module.exports = ({config}) => { - config.resolve.alias = { - 'react-native-config': 'react-web-config', - 'react-native$': 'react-native-web', - '@react-native-community/netinfo': path.resolve(__dirname, '../__mocks__/@react-native-community/netinfo.ts'), - '@react-navigation/native': path.resolve(__dirname, '../__mocks__/@react-navigation/native'), - - // Module alias support for storybook files, coping from `webpack.common.js` - ...custom.resolve.alias, - }; - - // Necessary to overwrite the values in the existing DefinePlugin hardcoded to the Config staging values - const definePluginIndex = _.findIndex(config.plugins, (plugin) => plugin.constructor.name === 'DefinePlugin'); - config.plugins[definePluginIndex].definitions.__REACT_WEB_CONFIG__ = JSON.stringify(env); - config.resolve.extensions = custom.resolve.extensions; - - const babelRulesIndex = _.findIndex(custom.module.rules, (rule) => rule.loader === 'babel-loader'); - const babelRule = custom.module.rules[babelRulesIndex]; - config.module.rules.push(babelRule); - - // Allows loading SVG - more context here https://github.com/storybookjs/storybook/issues/6188 - const fileLoaderRule = _.find(config.module.rules, (rule) => rule.test && rule.test.test('.svg')); - fileLoaderRule.exclude = /\.svg$/; - config.module.rules.push({ - test: /\.svg$/, - enforce: 'pre', - loader: require.resolve('@svgr/webpack'), - }); - - return config; -}; diff --git a/.storybook/webpack.config.ts b/.storybook/webpack.config.ts new file mode 100644 index 000000000000..0c66e184c18f --- /dev/null +++ b/.storybook/webpack.config.ts @@ -0,0 +1,79 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +/* eslint-disable no-underscore-dangle */ + +/* eslint-disable no-param-reassign */ +import dotenv from 'dotenv'; +import path from 'path'; +import {DefinePlugin} from 'webpack'; +import type {Configuration, RuleSetRule} from 'webpack'; + +type CustomWebpackConfig = { + resolve: { + alias: Record; + extensions: string[]; + }; + module: { + rules: RuleSetRule[]; + }; +}; + +let envFile; +switch (process.env.ENV) { + case 'production': + envFile = '.env.production'; + break; + case 'staging': + envFile = '.env.staging'; + break; + default: + envFile = '.env'; +} + +const env = dotenv.config({path: path.resolve(__dirname, `../${envFile}`)}); +const custom: CustomWebpackConfig = require('../config/webpack/webpack.common')({ + envFile, +}); + +module.exports = ({config}: {config: Configuration}) => { + if (config.resolve && config.plugins && config.module) { + config.resolve.alias = { + 'react-native-config': 'react-web-config', + 'react-native$': 'react-native-web', + '@react-native-community/netinfo': path.resolve(__dirname, '../__mocks__/@react-native-community/netinfo.ts'), + '@react-navigation/native': path.resolve(__dirname, '../__mocks__/@react-navigation/native'), + ...custom.resolve.alias, + }; + + // Necessary to overwrite the values in the existing DefinePlugin hardcoded to the Config staging values + const definePluginIndex = config.plugins.findIndex((plugin) => plugin instanceof DefinePlugin); + if (definePluginIndex !== -1 && config.plugins[definePluginIndex] instanceof DefinePlugin) { + const definePlugin = config.plugins[definePluginIndex] as DefinePlugin; + if (definePlugin.definitions) { + definePlugin.definitions.__REACT_WEB_CONFIG__ = JSON.stringify(env); + } + } + config.resolve.extensions = custom.resolve.extensions; + + const babelRulesIndex = custom.module.rules.findIndex((rule) => rule.loader === 'babel-loader'); + const babelRule = custom.module.rules[babelRulesIndex]; + if (babelRule) { + config.module.rules?.push(babelRule); + } + + const fileLoaderRule = config.module.rules?.find( + (rule): rule is RuleSetRule => + typeof rule !== 'boolean' && typeof rule !== 'string' && typeof rule !== 'number' && !!rule?.test && rule.test instanceof RegExp && rule.test.test('.svg'), + ); + if (fileLoaderRule?.exclude) { + fileLoaderRule.exclude = /\.svg$/; + } + config.module.rules?.push({ + test: /\.svg$/, + enforce: 'pre', + loader: require.resolve('@svgr/webpack'), + }); + } + + return config; +}; From 6aa6a28e1e7c446442aea364ca06caf24bd217d4 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Tue, 5 Mar 2024 17:30:44 +0100 Subject: [PATCH 071/504] fix: remove unnecessary field from PolicyTag type --- src/types/onyx/PolicyTag.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/types/onyx/PolicyTag.ts b/src/types/onyx/PolicyTag.ts index b2873538cb4d..8c509c66825b 100644 --- a/src/types/onyx/PolicyTag.ts +++ b/src/types/onyx/PolicyTag.ts @@ -8,12 +8,6 @@ type PolicyTag = { /** "General Ledger code" that corresponds to this tag in an accounting system. Similar to an ID. */ // eslint-disable-next-line @typescript-eslint/naming-convention 'GL Code'?: string; - - /** List of tags */ - tags: PolicyTags; - - /** Flag that determines if a tag is required */ - required: boolean; }; type PolicyTags = Record; From cd2681e34826070baa28bafde8a7fd0eda10007e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 6 Mar 2024 10:13:31 +0700 Subject: [PATCH 072/504] fix type --- src/components/AttachmentPicker/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/AttachmentPicker/index.tsx b/src/components/AttachmentPicker/index.tsx index 9a372a9d4a48..dc5ce45153a3 100644 --- a/src/components/AttachmentPicker/index.tsx +++ b/src/components/AttachmentPicker/index.tsx @@ -76,13 +76,13 @@ function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}: }} accept={getAcceptableFileTypes(type)} /> - {children({ - openPicker: ({onPicked: newOnPicked, onCanceled: newOnCanceled = () => {}}) => { + {children( + ({onPicked: newOnPicked, onCanceled: newOnCanceled = () => {}}) => { onPicked.current = newOnPicked; fileInput.current?.click(); onCanceled.current = newOnCanceled; }, - })} + )} ); } From 2dda80fcfc839d3823f07882bde897b88cf8c3c2 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 6 Mar 2024 14:32:22 +0700 Subject: [PATCH 073/504] fix: type attachment --- src/components/AttachmentModal.tsx | 10 +++++----- .../AttachmentPicker/index.native.tsx | 20 ++++++------------- src/components/AttachmentPicker/index.tsx | 8 ++++---- src/components/AttachmentPicker/types.ts | 4 ++-- src/components/AvatarWithImagePicker.tsx | 18 +++++++---------- .../AttachmentPickerWithMenuItems.tsx | 1 - 6 files changed, 24 insertions(+), 37 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index eed40d75387e..2a6ebd12f143 100755 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -71,12 +71,12 @@ type Attachment = { }; type ImagePickerResponse = { - height: number; + height?: number; name: string; - size: number; + size?: number | null; type: string; uri: string; - width: number; + width?: number; }; type FileObject = File | ImagePickerResponse; @@ -292,14 +292,14 @@ function AttachmentModal({ }, [transaction, report]); const isValidFile = useCallback((fileObject: FileObject) => { - if (fileObject.size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { + if (fileObject.size && fileObject.size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { setIsAttachmentInvalid(true); setAttachmentInvalidReasonTitle('attachmentPicker.attachmentTooLarge'); setAttachmentInvalidReason('attachmentPicker.sizeExceeded'); return false; } - if (fileObject.size < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { + if (fileObject.size && fileObject.size < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { setIsAttachmentInvalid(true); setAttachmentInvalidReasonTitle('attachmentPicker.attachmentTooSmall'); setAttachmentInvalidReason('attachmentPicker.sizeNotMet'); diff --git a/src/components/AttachmentPicker/index.native.tsx b/src/components/AttachmentPicker/index.native.tsx index e144a210fa7c..7412c7382513 100644 --- a/src/components/AttachmentPicker/index.native.tsx +++ b/src/components/AttachmentPicker/index.native.tsx @@ -7,6 +7,7 @@ import type {DocumentPickerOptions, DocumentPickerResponse} from 'react-native-d import type {SupportedPlatforms} from 'react-native-document-picker/lib/typescript/fileTypes'; import {launchImageLibrary} from 'react-native-image-picker'; import type {Asset, Callback, CameraOptions, ImagePickerResponse} from 'react-native-image-picker'; +import type {FileObject} from '@components/AttachmentModal'; import * as Expensicons from '@components/Icon/Expensicons'; import MenuItem from '@components/MenuItem'; import Popover from '@components/Popover'; @@ -33,15 +34,6 @@ type Item = { pickAttachment: () => Promise; }; -type FileResult = { - name: string; - type: string; - width: number | undefined; - height: number | undefined; - uri: string; - size: number | null; -}; - /** * See https://github.com/react-native-image-picker/react-native-image-picker/#options * for ImagePicker configuration options @@ -77,9 +69,9 @@ const documentPickerOptions = { * The data returned from `show` is different on web and mobile, so use this function to ensure the data we * send to the xhr will be handled properly. */ -const getDataForUpload = (fileData: Asset & DocumentPickerResponse): Promise => { +const getDataForUpload = (fileData: Asset & DocumentPickerResponse): Promise => { const fileName = fileData.fileName ?? fileData.name ?? 'chat_attachment'; - const fileResult: FileResult = { + const fileResult: FileObject = { name: FileUtils.cleanFileName(fileName), type: fileData.type, width: fileData.width, @@ -108,7 +100,7 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s const styles = useThemeStyles(); const [isVisible, setIsVisible] = useState(false); - const completeAttachmentSelection = useRef<(data: FileResult) => void>(() => {}); + const completeAttachmentSelection = useRef<(data: FileObject) => void>(() => {}); const onModalHide = useRef<() => void>(); const onCanceled = useRef<() => void>(() => {}); const popoverRef = useRef(null); @@ -213,7 +205,7 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s * @param onPickedHandler A callback that will be called with the selected attachment * @param onCanceledHandler A callback that will be called without a selected attachment */ - const open = (onPickedHandler: () => void, onCanceledHandler: () => void = () => {}) => { + const open = (onPickedHandler: (file: FileObject) => void, onCanceledHandler: () => void = () => {}) => { completeAttachmentSelection.current = onPickedHandler; onCanceled.current = onCanceledHandler; setIsVisible(true); @@ -266,7 +258,7 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s (item: Item) => { /* setTimeout delays execution to the frame after the modal closes * without this on iOS closing the modal closes the gallery/camera as well */ - onModalHide.current = () => { + onModalHide.current = () => { setTimeout(() => { item.pickAttachment() .then((result) => pickAttachment(result as Array)) diff --git a/src/components/AttachmentPicker/index.tsx b/src/components/AttachmentPicker/index.tsx index dc5ce45153a3..e8a23e29f114 100644 --- a/src/components/AttachmentPicker/index.tsx +++ b/src/components/AttachmentPicker/index.tsx @@ -76,15 +76,15 @@ function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}: }} accept={getAcceptableFileTypes(type)} /> - {children( - ({onPicked: newOnPicked, onCanceled: newOnCanceled = () => {}}) => { + {children({ + openPicker: ({onPicked: newOnPicked, onCanceled: newOnCanceled = () => {}}) => { onPicked.current = newOnPicked; fileInput.current?.click(); onCanceled.current = newOnCanceled; }, - )} + })} ); } -export default AttachmentPicker; \ No newline at end of file +export default AttachmentPicker; diff --git a/src/components/AttachmentPicker/types.ts b/src/components/AttachmentPicker/types.ts index b9974f4082b2..66ee91b33c24 100644 --- a/src/components/AttachmentPicker/types.ts +++ b/src/components/AttachmentPicker/types.ts @@ -1,5 +1,6 @@ import type {ReactNode} from 'react'; import type {ValueOf} from 'type-fest'; +import type {FileObject} from '@components/AttachmentModal'; import type CONST from '@src/CONST'; type AttachmentPickerProps = { @@ -21,8 +22,7 @@ type AttachmentPickerProps = { * )} * * */ - children: (openPicker: ({onPicked, onCanceled}: {onPicked: (file: File) => void; onCanceled?: () => void}) => void) => ReactNode; - + children: (props: {openPicker: (options: {onPicked: (file: FileObject) => void; onCanceled?: () => void}) => void}) => ReactNode; /** The types of files that can be selected with this picker. */ type?: ValueOf; }; diff --git a/src/components/AvatarWithImagePicker.tsx b/src/components/AvatarWithImagePicker.tsx index 5755c69641c8..6c8b4e65ae93 100644 --- a/src/components/AvatarWithImagePicker.tsx +++ b/src/components/AvatarWithImagePicker.tsx @@ -15,7 +15,7 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type IconAsset from '@src/types/utils/IconAsset'; -import AttachmentModal from './AttachmentModal'; +import AttachmentModal, {FileObject} from './AttachmentModal'; import AttachmentPicker from './AttachmentPicker'; import Avatar from './Avatar'; import AvatarCropModal from './AvatarCropModal/AvatarCropModal'; @@ -34,7 +34,7 @@ type ErrorData = { }; type OpenPickerParams = { - onPicked: (image: File) => void; + onPicked: (image: FileObject) => void; }; type OpenPicker = (args: OpenPickerParams) => void; @@ -174,7 +174,7 @@ function AvatarWithImagePicker({ /** * Check if the attachment extension is allowed. */ - const isValidExtension = (image: File): boolean => { + const isValidExtension = (image: FileObject): boolean => { const {fileExtension} = FileUtils.splitExtensionFromFileName(image?.name ?? ''); return CONST.AVATAR_ALLOWED_EXTENSIONS.some((extension) => extension === fileExtension.toLowerCase()); }; @@ -182,12 +182,12 @@ function AvatarWithImagePicker({ /** * Check if the attachment size is less than allowed size. */ - const isValidSize = (image: File): boolean => (image?.size ?? 0) < CONST.AVATAR_MAX_ATTACHMENT_SIZE; + const isValidSize = (image: FileObject): boolean => (image?.size ?? 0) < CONST.AVATAR_MAX_ATTACHMENT_SIZE; /** * Check if the attachment resolution matches constraints. */ - const isValidResolution = (image: File): Promise => + const isValidResolution = (image: FileObject): Promise => getImageResolution(image).then( ({height, width}) => height >= CONST.AVATAR_MIN_HEIGHT_PX && width >= CONST.AVATAR_MIN_WIDTH_PX && height <= CONST.AVATAR_MAX_HEIGHT_PX && width <= CONST.AVATAR_MAX_WIDTH_PX, ); @@ -195,7 +195,7 @@ function AvatarWithImagePicker({ /** * Validates if an image has a valid resolution and opens an avatar crop modal */ - const showAvatarCropModal = (image: File) => { + const showAvatarCropModal = (image: FileObject) => { if (!isValidExtension(image)) { setError('avatarWithImagePicker.notAllowedExtension', {allowedExtensions: CONST.AVATAR_ALLOWED_EXTENSIONS}); return; @@ -343,11 +343,7 @@ function AvatarWithImagePicker({ maybeIcon={isUsingDefaultAvatar} > {({show}) => ( - - {/* @ts-expect-error TODO: Remove this once AttachmentPicker (https://github.com/Expensify/App/issues/25134) is migrated to TypeScript. */} + {({openPicker}) => { const menuItems = createMenuItems(openPicker); diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 68c7f0883683..b8b4693ac66e 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -185,7 +185,6 @@ function AttachmentPickerWithMenuItems({ return ( - {/* @ts-expect-error TODO: Remove this once AttachmentPicker (https://github.com/Expensify/App/issues/25134) is migrated to TypeScript. */} {({openPicker}) => { const triggerAttachmentPicker = () => { onTriggerAttachmentPicker(); From 9ac6e89085815d5c3f3064262fc3c37dde8206de Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 6 Mar 2024 14:38:28 +0700 Subject: [PATCH 074/504] fix lint --- src/components/AvatarWithImagePicker.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/AvatarWithImagePicker.tsx b/src/components/AvatarWithImagePicker.tsx index 6c8b4e65ae93..0e1a8d0e17a6 100644 --- a/src/components/AvatarWithImagePicker.tsx +++ b/src/components/AvatarWithImagePicker.tsx @@ -15,7 +15,8 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type IconAsset from '@src/types/utils/IconAsset'; -import AttachmentModal, {FileObject} from './AttachmentModal'; +import AttachmentModal from './AttachmentModal'; +import type {FileObject} from './AttachmentModal'; import AttachmentPicker from './AttachmentPicker'; import Avatar from './Avatar'; import AvatarCropModal from './AvatarCropModal/AvatarCropModal'; From 41c834697fbf9625de0072827e1912e88767eaa9 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 6 Mar 2024 17:39:23 +0700 Subject: [PATCH 075/504] Fix immediately prompt for Camera permission in scan request flow --- .../step/IOURequestStepScan/index.native.js | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.js b/src/pages/iou/request/step/IOURequestStepScan/index.native.js index 338444d473c6..de50d25a2e78 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.js +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.js @@ -65,18 +65,17 @@ function IOURequestStepScan({ const camera = useRef(null); const [flash, setFlash] = useState(false); const [cameraPermissionStatus, setCameraPermissionStatus] = useState(undefined); - const askedForPermission = useRef(false); const {translate} = useLocalize(); - const askForPermissions = (showPermissionsAlert = true) => { + const askForPermissions = () => { // There's no way we can check for the BLOCKED status without requesting the permission first // https://github.com/zoontek/react-native-permissions/blob/a836e114ce3a180b2b23916292c79841a267d828/README.md?plain=1#L670 CameraPermission.requestCameraPermission() .then((status) => { setCameraPermissionStatus(status); - if (status === RESULTS.BLOCKED && showPermissionsAlert) { + if (status === RESULTS.BLOCKED) { FileUtils.showCameraPermissionsAlert(); } }) @@ -121,22 +120,14 @@ function IOURequestStepScan({ }); useEffect(() => { - const refreshCameraPermissionStatus = (shouldAskForPermission = false) => { + const refreshCameraPermissionStatus = () => { CameraPermission.getCameraPermissionStatus() - .then((res) => { - // In android device app data, the status is not set to blocked until denied twice, - // due to that the app will ask for permission twice whenever users opens uses the scan tab - setCameraPermissionStatus(res); - if (shouldAskForPermission && !askedForPermission.current) { - askedForPermission.current = true; - askForPermissions(false); - } - }) + .then(setCameraPermissionStatus) .catch(() => setCameraPermissionStatus(RESULTS.UNAVAILABLE)); }; // Check initial camera permission status - refreshCameraPermissionStatus(true); + refreshCameraPermissionStatus(); // Refresh permission status when app gain focus const subscription = AppState.addEventListener('change', (appState) => { @@ -225,7 +216,7 @@ function IOURequestStepScan({ const capturePhoto = useCallback(() => { if (!camera.current && (cameraPermissionStatus === RESULTS.DENIED || cameraPermissionStatus === RESULTS.BLOCKED)) { - askForPermissions(cameraPermissionStatus !== RESULTS.DENIED); + askForPermissions(); return; } From d906791422db9dfcc0a3ca4c086dd78095f648b0 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Wed, 6 Mar 2024 14:55:47 +0000 Subject: [PATCH 076/504] [TS migration][Storybook] Feedback --- .storybook/main.ts | 13 ++----------- .storybook/preview.tsx | 11 ++--------- .storybook/webpack.config.ts | 8 +++++--- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/.storybook/main.ts b/.storybook/main.ts index 0234f18ff488..33f4befb0f40 100644 --- a/.storybook/main.ts +++ b/.storybook/main.ts @@ -1,17 +1,8 @@ -type Dir = { - from: string; - to: string; -}; +import type {StorybookConfig} from '@storybook/core-common'; type Main = { - stories: string[]; - addons: string[]; - staticDirs: Array; - core: { - builder: string; - }; managerHead: (head: string) => string; -}; +} & StorybookConfig; const main: Main = { stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index 5ddb9d04d8ae..4767c7d81343 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -1,4 +1,5 @@ import {PortalProvider} from '@gorhom/portal'; +import type {Parameters} from '@storybook/addons'; import React from 'react'; import Onyx from 'react-native-onyx'; import {SafeAreaProvider} from 'react-native-safe-area-context'; @@ -12,14 +13,6 @@ import {WindowDimensionsProvider} from '@src/components/withWindowDimensions'; import ONYXKEYS from '@src/ONYXKEYS'; import './fonts.css'; -type Parameter = { - controls: { - matchers: { - color: RegExp; - }; - }; -}; - Onyx.init({ keys: ONYXKEYS, initialKeyStates: { @@ -37,7 +30,7 @@ const decorators = [ ), ]; -const parameters: Parameter = { +const parameters: Parameters = { controls: { matchers: { color: /(background|color)$/i, diff --git a/.storybook/webpack.config.ts b/.storybook/webpack.config.ts index 0c66e184c18f..6f7ee023643c 100644 --- a/.storybook/webpack.config.ts +++ b/.storybook/webpack.config.ts @@ -1,8 +1,8 @@ -/* eslint-disable @typescript-eslint/naming-convention */ - /* eslint-disable no-underscore-dangle */ /* eslint-disable no-param-reassign */ + +/* eslint-disable @typescript-eslint/naming-convention */ import dotenv from 'dotenv'; import path from 'path'; import {DefinePlugin} from 'webpack'; @@ -35,7 +35,7 @@ const custom: CustomWebpackConfig = require('../config/webpack/webpack.common')( envFile, }); -module.exports = ({config}: {config: Configuration}) => { +const webpackConfig = ({config}: {config: Configuration}) => { if (config.resolve && config.plugins && config.module) { config.resolve.alias = { 'react-native-config': 'react-web-config', @@ -77,3 +77,5 @@ module.exports = ({config}: {config: Configuration}) => { return config; }; + +export default webpackConfig; From 2f5bf904096e487492bd5e4c6f2b66edd70d1d2e Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Wed, 6 Mar 2024 15:09:03 +0000 Subject: [PATCH 077/504] [TS migration][Storybook] Lint --- .storybook/theme.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/.storybook/theme.ts b/.storybook/theme.ts index f1ace5dd37c0..a28a0f031b0c 100644 --- a/.storybook/theme.ts +++ b/.storybook/theme.ts @@ -1,5 +1,6 @@ import type {ThemeVars} from '@storybook/theming'; import {create} from '@storybook/theming'; +// eslint-disable-next-line @dword-design/import-alias/prefer-alias import colors from '../src/styles/theme/colors'; const theme: ThemeVars = create({ From c90ce7e8d360788fa31be13fe94f31a123689a4f Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 6 Mar 2024 18:23:50 +0300 Subject: [PATCH 078/504] add Pdf thumbnail --- src/components/ReceiptImage.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/components/ReceiptImage.tsx b/src/components/ReceiptImage.tsx index cd70413b7a2e..8dc82cb53aea 100644 --- a/src/components/ReceiptImage.tsx +++ b/src/components/ReceiptImage.tsx @@ -5,6 +5,7 @@ import type IconAsset from '@src/types/utils/IconAsset'; import EReceiptThumbnail from './EReceiptThumbnail'; import type {IconSize} from './EReceiptThumbnail'; import Image from './Image'; +import PDFThumbnail from './PDFThumbnail'; import ThumbnailImage from './ThumbnailImage'; type Style = {height: number; borderRadius: number; margin: number}; @@ -22,18 +23,30 @@ type ReceiptImageProps = ( /** Url of the receipt image */ source?: string; + + /** Whether it is a pdf thumbnail we are displaying */ + isPDFThumbnail?: boolean; } | { transactionID: string; isEReceipt?: boolean; isThumbnail: boolean; source?: string; + isPDFThumbnail?: boolean; + } + | { + transactionID?: string; + isEReceipt?: boolean; + isThumbnail?: boolean; + source: string; + isPDFThumbnail?: boolean; } | { transactionID?: string; isEReceipt?: boolean; isThumbnail?: boolean; source: string; + isPDFThumbnail: string; } ) & { /** Whether we should display the receipt with ThumbnailImage component */ @@ -60,6 +73,7 @@ type ReceiptImageProps = ( function ReceiptImage({ transactionID, + isPDFThumbnail = false, isThumbnail = false, shouldUseThumbnailImage = false, isEReceipt = false, @@ -73,6 +87,15 @@ function ReceiptImage({ }: ReceiptImageProps) { const styles = useThemeStyles(); + if (isPDFThumbnail) { + return ( + + ); + } + if (isEReceipt || isThumbnail) { const props = isThumbnail && {borderRadius: style?.borderRadius, fileExtension, isReceiptThumbnail: true}; return ( From 9c2cf34bfe95a1d9e73ba4b711db484c0557ab4a Mon Sep 17 00:00:00 2001 From: Rohan Sasne Date: Wed, 6 Mar 2024 21:26:28 +0530 Subject: [PATCH 079/504] Update workspace creation to paid --- src/libs/actions/Policy.ts | 6 +++--- tests/actions/PolicyTest.js | 2 +- tests/unit/SidebarFilterTest.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index aa64611b210f..00acffb81f40 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1486,7 +1486,7 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol key: `${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`, value: { id: policyID, - type: CONST.POLICY.TYPE.FREE, + type: CONST.POLICY.TYPE.TEAM, name: workspaceName, role: CONST.POLICY.ROLE.ADMIN, owner: sessionEmail, @@ -1547,7 +1547,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { id: policyID, - type: CONST.POLICY.TYPE.FREE, + type: CONST.POLICY.TYPE.TEAM, name: workspaceName, role: CONST.POLICY.ROLE.ADMIN, owner: sessionEmail, @@ -1742,7 +1742,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName ownerEmail: policyOwnerEmail, makeMeAdmin, policyName: workspaceName, - type: CONST.POLICY.TYPE.FREE, + type: CONST.POLICY.TYPE.TEAM, announceCreatedReportActionID, adminsCreatedReportActionID, expenseCreatedReportActionID, diff --git a/tests/actions/PolicyTest.js b/tests/actions/PolicyTest.js index 5a994aaf600e..7b9a77a7e89b 100644 --- a/tests/actions/PolicyTest.js +++ b/tests/actions/PolicyTest.js @@ -52,7 +52,7 @@ describe('actions/Policy', () => { // check if policy was created with correct values expect(policy.id).toBe(policyID); expect(policy.name).toBe(WORKSPACE_NAME); - expect(policy.type).toBe(CONST.POLICY.TYPE.FREE); + expect(policy.type).toBe(CONST.POLICY.TYPE.TEAM); expect(policy.role).toBe(CONST.POLICY.ROLE.ADMIN); expect(policy.owner).toBe(ESH_EMAIL); expect(policy.isPolicyExpenseChatEnabled).toBe(true); diff --git a/tests/unit/SidebarFilterTest.ts b/tests/unit/SidebarFilterTest.ts index 58ec66698b83..05771980dcf3 100644 --- a/tests/unit/SidebarFilterTest.ts +++ b/tests/unit/SidebarFilterTest.ts @@ -238,7 +238,7 @@ xdescribe('Sidebar', () => { // and the user not being in any betas const policy = { policyID: '1', - type: CONST.POLICY.TYPE.FREE, + type: CONST.POLICY.TYPE.TEAM, }; const report: Report = { ...LHNTestUtils.getFakeReport(), From 9f38e25e51dcfa089429348fa683bd78f7a4ea88 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 6 Mar 2024 19:07:12 +0300 Subject: [PATCH 080/504] updated to fixed color code depending on file extensions --- src/components/EReceiptThumbnail.tsx | 5 +++-- src/styles/utils/index.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/EReceiptThumbnail.tsx b/src/components/EReceiptThumbnail.tsx index f6d5beb7e24d..fb1209aa6fed 100644 --- a/src/components/EReceiptThumbnail.tsx +++ b/src/components/EReceiptThumbnail.tsx @@ -56,10 +56,11 @@ const backgroundImages = { function EReceiptThumbnail({transaction, borderRadius, fileExtension, isReceiptThumbnail = false, centerIconV = true, iconSize = 'large'}: EReceiptThumbnailProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); + const colorCode = isReceiptThumbnail ? StyleUtils.getFileExtensionColorCode(fileExtension) : StyleUtils.getEReceiptColorCode(transaction); - const backgroundImage = useMemo(() => backgroundImages[StyleUtils.getEReceiptColorCode(transaction)], [StyleUtils, transaction]); + const backgroundImage = useMemo(() => backgroundImages[colorCode], [colorCode]); - const colorStyles = StyleUtils.getEReceiptColorStyles(StyleUtils.getEReceiptColorCode(transaction)); + const colorStyles = StyleUtils.getEReceiptColorStyles(colorCode); const primaryColor = colorStyles?.backgroundColor; const secondaryColor = colorStyles?.color; const transactionDetails = ReportUtils.getTransactionDetails(transaction); diff --git a/src/styles/utils/index.ts b/src/styles/utils/index.ts index 21af5398232f..5d3da627b411 100644 --- a/src/styles/utils/index.ts +++ b/src/styles/utils/index.ts @@ -287,6 +287,20 @@ function getEReceiptColorCode(transaction: OnyxEntry): EReceiptColo return eReceiptColors[colorHash]; } +/** + * Helper method to return eReceipt color code for Receipt Thumbnails + */ +function getFileExtensionColorCode(fileExtension?: string): EReceiptColorName { + switch (fileExtension) { + case CONST.IOU.FILE_TYPES.DOC: + return CONST.ERECEIPT_COLORS.PINK; + case CONST.IOU.FILE_TYPES.HTML: + return CONST.ERECEIPT_COLORS.TANGERINE; + default: + return CONST.ERECEIPT_COLORS.GREEN; + } +} + /** * Helper method to return eReceipt color styles */ @@ -1084,6 +1098,7 @@ const staticStyleUtils = { parseStyleFromFunction, getEReceiptColorStyles, getEReceiptColorCode, + getFileExtensionColorCode, getNavigationModalCardStyle, getCardStyles, getOpacityStyle, From 68c532703e40358c9e8ea387683ae6e54ccffa1b Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 7 Mar 2024 10:35:57 +0100 Subject: [PATCH 081/504] fix: changed prop name to tagListName --- src/components/TagPicker/index.tsx | 6 +++--- src/pages/EditRequestTagPage.js | 2 +- src/pages/iou/request/step/IOURequestStepTag.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/TagPicker/index.tsx b/src/components/TagPicker/index.tsx index f13c27beadc3..4998751309ee 100644 --- a/src/components/TagPicker/index.tsx +++ b/src/components/TagPicker/index.tsx @@ -36,7 +36,7 @@ type TagPickerProps = TagPickerOnyxProps & { selectedTag: string; /** The name of tag list we are getting tags for */ - tag: string; + tagListName: string; /** Callback to submit the selected tag */ onSubmit: () => void; @@ -54,13 +54,13 @@ type TagPickerProps = TagPickerOnyxProps & { tagIndex: number; }; -function TagPicker({selectedTag, tag, policyTags, tagIndex, policyRecentlyUsedTags, shouldShowDisabledAndSelectedOption = false, insets, onSubmit}: TagPickerProps) { +function TagPicker({selectedTag, tagListName, policyTags, tagIndex, policyRecentlyUsedTags, shouldShowDisabledAndSelectedOption = false, insets, onSubmit}: TagPickerProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); const [searchValue, setSearchValue] = useState(''); - const policyRecentlyUsedTagsList = useMemo(() => policyRecentlyUsedTags?.[tag] ?? [], [policyRecentlyUsedTags, tag]); + const policyRecentlyUsedTagsList = useMemo(() => policyRecentlyUsedTags?.[tagListName] ?? [], [policyRecentlyUsedTags, tagListName]); const policyTagList = PolicyUtils.getTagList(policyTags, tagIndex); const policyTagsCount = PolicyUtils.getCountOfEnabledTagsOfList(policyTagList.tags); const isTagsCountBelowThreshold = policyTagsCount < CONST.TAG_LIST_THRESHOLD; diff --git a/src/pages/EditRequestTagPage.js b/src/pages/EditRequestTagPage.js index 74643afa347f..762bb76a7f57 100644 --- a/src/pages/EditRequestTagPage.js +++ b/src/pages/EditRequestTagPage.js @@ -52,7 +52,7 @@ function EditRequestTagPage({defaultTag, policyID, tagName, tagIndex, onSubmit}) {translate('iou.tagSelection', {tagName: tagName || translate('common.tag')})} {translate('iou.tagSelection', {tagName: policyTagListName})} Date: Thu, 7 Mar 2024 16:36:41 +0100 Subject: [PATCH 082/504] Migrate AddPaymentMethodMenu.js to typescriptgpsup --- ...MethodMenu.js => AddPaymentMethodMenu.tsx} | 91 +++++++------------ src/components/KYCWall/BaseKYCWall.tsx | 3 +- 2 files changed, 35 insertions(+), 59 deletions(-) rename src/components/{AddPaymentMethodMenu.js => AddPaymentMethodMenu.tsx} (51%) diff --git a/src/components/AddPaymentMethodMenu.js b/src/components/AddPaymentMethodMenu.tsx similarity index 51% rename from src/components/AddPaymentMethodMenu.js rename to src/components/AddPaymentMethodMenu.tsx index 803b7f2cdabe..6f91c7ea1ec3 100644 --- a/src/components/AddPaymentMethodMenu.js +++ b/src/components/AddPaymentMethodMenu.tsx @@ -1,78 +1,55 @@ -import lodashGet from 'lodash/get'; -import PropTypes from 'prop-types'; +import type {RefObject} from 'react'; import React from 'react'; +import type {View} from 'react-native'; +import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; +import type {ValueOf} from 'type-fest'; import useLocalize from '@hooks/useLocalize'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; -import iouReportPropTypes from '@pages/iouReportPropTypes'; +import type {AnchorPosition} from '@styles/index'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {Report, Session} from '@src/types/onyx'; +import type AnchorAlignment from '@src/types/utils/AnchorAlignment'; import * as Expensicons from './Icon/Expensicons'; import PopoverMenu from './PopoverMenu'; -import refPropTypes from './refPropTypes'; -const propTypes = { - /** Should the component be visible? */ - isVisible: PropTypes.bool.isRequired, - - /** Callback to execute when the component closes. */ - onClose: PropTypes.func.isRequired, - - /** Callback to execute when the payment method is selected. */ - onItemSelected: PropTypes.func.isRequired, - - /** The IOU/Expense report we are paying */ - iouReport: iouReportPropTypes, - - /** Anchor position for the AddPaymentMenu. */ - anchorPosition: PropTypes.shape({ - horizontal: PropTypes.number, - vertical: PropTypes.number, - }), - - /** Where the popover should be positioned relative to the anchor points. */ - anchorAlignment: PropTypes.shape({ - horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)), - vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)), - }), - - /** Popover anchor ref */ - anchorRef: refPropTypes, - - /** Session info for the currently logged in user. */ - session: PropTypes.shape({ - /** Currently logged in user accountID */ - accountID: PropTypes.number, - }), - - /** Whether the personal bank account option should be shown */ - shouldShowPersonalBankAccountOption: PropTypes.bool, +type AddPaymentMethodMenuOnyxProps = { + session: OnyxEntry; }; -const defaultProps = { - iouReport: {}, - anchorPosition: {}, - anchorAlignment: { - horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, - vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM, - }, - anchorRef: () => {}, - session: {}, - shouldShowPersonalBankAccountOption: false, +type AddPaymentMethodMenuProps = AddPaymentMethodMenuOnyxProps & { + isVisible: boolean; + onClose: () => void; + onItemSelected: (paymentMethod: ValueOf) => void; + iouReport?: OnyxEntry; + anchorPosition: AnchorPosition; + anchorAlignment?: AnchorAlignment; + anchorRef: RefObject; + shouldShowPersonalBankAccountOption?: boolean; }; -function AddPaymentMethodMenu({isVisible, onClose, anchorPosition, anchorAlignment, anchorRef, iouReport, onItemSelected, session, shouldShowPersonalBankAccountOption}) { +function AddPaymentMethodMenu({ + isVisible, + onClose, + anchorPosition, + anchorAlignment, + anchorRef, + iouReport, + onItemSelected, + session, + shouldShowPersonalBankAccountOption = false, +}: AddPaymentMethodMenuProps) { const {translate} = useLocalize(); // Users can choose to pay with business bank account in case of Expense reports or in case of P2P IOU report // which then starts a bottom up flow and creates a Collect workspace where the payer is an admin and payee is an employee. + const isIOUReport = ReportUtils.isIOUReport(iouReport ?? {}); const canUseBusinessBankAccount = - ReportUtils.isExpenseReport(iouReport) || - (ReportUtils.isIOUReport(iouReport) && !ReportActionsUtils.hasRequestFromCurrentAccount(lodashGet(iouReport, 'reportID', 0), lodashGet(session, 'accountID', 0))); + ReportUtils.isExpenseReport(iouReport ?? {}) || (isIOUReport && !ReportActionsUtils.hasRequestFromCurrentAccount(iouReport?.reportID ?? '', session?.accountID ?? 0)); - const canUsePersonalBankAccount = shouldShowPersonalBankAccountOption || ReportUtils.isIOUReport(iouReport); + const canUsePersonalBankAccount = shouldShowPersonalBankAccountOption || isIOUReport; return ( ({ session: { key: ONYXKEYS.SESSION, }, diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index 33dfd2b920a9..e09e4ee7910a 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -18,6 +18,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {BankAccountList, FundList, ReimbursementAccount, UserWallet, WalletTerms} from '@src/types/onyx'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; import viewRef from '@src/types/utils/viewRef'; import type {AnchorPosition, DomRect, KYCWallProps, PaymentMethod} from './types'; @@ -246,7 +247,7 @@ function KYCWall({ <> setShouldShowAddPaymentMenu(false)} anchorRef={anchorRef} anchorPosition={{ From c49ce330283f31e3aebbfdbf750276f446cbb666 Mon Sep 17 00:00:00 2001 From: burczu Date: Wed, 6 Mar 2024 13:12:48 +0100 Subject: [PATCH 083/504] is selectable item property introduced --- src/components/SelectionList/BaseListItem.tsx | 2 +- src/components/SelectionList/BaseSelectionList.tsx | 3 ++- src/components/SelectionList/types.ts | 3 +++ src/pages/workspace/WorkspaceMembersPage.tsx | 7 +++---- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/SelectionList/BaseListItem.tsx b/src/components/SelectionList/BaseListItem.tsx index c032fe2d081b..3e8573888404 100644 --- a/src/components/SelectionList/BaseListItem.tsx +++ b/src/components/SelectionList/BaseListItem.tsx @@ -80,7 +80,7 @@ function BaseListItem({ diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index bcf45fb2e2f4..5646b993d135 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -111,7 +111,8 @@ function BaseSelectionList( }); // If disabled, add to the disabled indexes array - if (!!section.isDisabled || item.isDisabled) { + // eslint-disable-next-line + if (!!section.isDisabled || item.isDisabled || !item.isSelectable) { disabledOptionsIndexes.push(disabledIndex); } disabledIndex += 1; diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 005a8ab21cc1..a8addd8c68e6 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -58,6 +58,9 @@ type ListItem = { /** Whether this option is selected */ isSelected?: boolean; + /** Whether this option is selectable */ + isSelectable?: boolean; + /** Whether this option is disabled for selection */ isDisabled?: boolean; diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index 3970533870c1..6b886520336f 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -200,7 +200,7 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se * Add or remove all users passed from the selectedEmployees list */ const toggleAllUsers = (memberList: MemberOption[]) => { - const enabledAccounts = memberList.filter((member) => !member.isDisabled); + const enabledAccounts = memberList.filter((member) => !member.isDisabled && member.isSelectable); const everyoneSelected = enabledAccounts.every((member) => selectedEmployees.includes(member.accountID)); if (everyoneSelected) { @@ -337,11 +337,10 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se keyForList: accountIDKey, accountID, isSelected, + isSelectable: isPolicyAdmin && accountID !== session?.accountID && accountID !== policy?.ownerAccountID, isDisabled: isPolicyAdmin && - (accountID === session?.accountID || - accountID === policy?.ownerAccountID || - policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || + (policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || !isEmptyObject(policyMember.errors)), text: formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)), alternateText: formatPhoneNumber(details?.login ?? ''), From 2d361a8798936049716964c176d53541321b6616 Mon Sep 17 00:00:00 2001 From: burczu Date: Thu, 7 Mar 2024 11:43:47 +0100 Subject: [PATCH 084/504] showing disable icon when item is not selectable --- src/components/SelectionList/BaseListItem.tsx | 6 ++++-- src/components/SelectionList/BaseSelectionList.tsx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/SelectionList/BaseListItem.tsx b/src/components/SelectionList/BaseListItem.tsx index 3e8573888404..38998e745196 100644 --- a/src/components/SelectionList/BaseListItem.tsx +++ b/src/components/SelectionList/BaseListItem.tsx @@ -34,6 +34,8 @@ function BaseListItem({ const StyleUtils = useStyleUtils(); const {hovered, bind} = useHover(); + const isItemSelectable = item.isSelectable === undefined || item.isSelectable; + const rightHandSideComponentRender = () => { if (canSelectMultiple || !rightHandSideComponent) { return null; @@ -80,9 +82,9 @@ function BaseListItem({ {item.isSelected && ( diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index 5646b993d135..3fc586b5ed13 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -112,7 +112,7 @@ function BaseSelectionList( // If disabled, add to the disabled indexes array // eslint-disable-next-line - if (!!section.isDisabled || item.isDisabled || !item.isSelectable) { + if (!!section.isDisabled || item.isDisabled || (item.isSelectable !== undefined && !item.isSelectable)) { disabledOptionsIndexes.push(disabledIndex); } disabledIndex += 1; From 8d92c5e61f3849cf94901bdc2fcb258248b06a16 Mon Sep 17 00:00:00 2001 From: burczu Date: Fri, 8 Mar 2024 13:06:57 +0100 Subject: [PATCH 085/504] showing transfer owner button for owners opened by other admins --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + .../members/WorkspaceMemberDetailsPage.tsx | 37 +++++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 3575854ee7e2..956c7d5637de 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1813,6 +1813,7 @@ export default { removeMemberButtonTitle: 'Remove from workspace', removeMemberPrompt: ({memberName}) => `Are you sure you want to remove ${memberName}`, removeMemberTitle: 'Remove member', + transferOwner: 'Transfer owner', makeMember: 'Make member', makeAdmin: 'Make admin', selectAll: 'Select all', diff --git a/src/languages/es.ts b/src/languages/es.ts index 51a83e55fee2..832538e91951 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1837,6 +1837,7 @@ export default { removeMemberButtonTitle: 'Quitar del espacio de trabajo', removeMemberPrompt: ({memberName}) => `¿Estás seguro de que deseas eliminar a ${memberName}`, removeMemberTitle: 'Eliminar miembro', + transferOwner: 'Transferir la propiedad', makeMember: 'Hacer miembro', makeAdmin: 'Hacer administrador', selectAll: 'Seleccionar todo', diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index d44ff8baa08b..e6befe277d3c 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -30,6 +30,7 @@ import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {PersonalDetails, PersonalDetailsList} from '@src/types/onyx'; +import useCurrentUserPersonalDetails from "@hooks/useCurrentUserPersonalDetails"; type WorkspacePolicyOnyxProps = { /** Personal details of all users */ @@ -42,6 +43,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou const styles = useThemeStyles(); const {translate} = useLocalize(); const StyleUtils = useStyleUtils(); + const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const [isRemoveMemberConfirmModalVisible, setIsRemoveMemberConfirmModalVisible] = React.useState(false); @@ -54,6 +56,9 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou const avatar = details.avatar ?? UserUtils.getDefaultAvatar(); const fallbackIcon = details.fallbackIcon ?? ''; const displayName = details.displayName ?? ''; + const isOwner = policy?.owner === details.login; + const isCurrentUserAdmin = policyMembers?.[currentUserPersonalDetails?.accountID]?.role === CONST.POLICY.ROLE.ADMIN; + const isCurrentUserOwner = policy?.owner === currentUserPersonalDetails?.login; const askForConfirmationToRemove = () => { setIsRemoveMemberConfirmModalVisible(true); @@ -73,6 +78,10 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou Navigation.navigate(ROUTES.WORKSPACE_MEMBER_ROLE_SELECTION.getRoute(route.params.policyID, accountID, Navigation.getActiveRoute())); }, [accountID, route.params.policyID]); + const startChangeOwnershipFlow = useCallback(() => { + + }, []); + return ( @@ -101,14 +110,26 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou {displayName} )} - + ) : ( + + )} + From 732128ba2bdf7b182f6889d1d985c58ec8c3ce11 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 11 Mar 2024 15:09:36 +0100 Subject: [PATCH 109/504] [TS migration] Migrate 'reviewerChecklist.test.js' workflow test --- package-lock.json | 1460 +++-------------- package.json | 3 +- tsconfig.json | 2 +- workflow_tests/jest.config.js | 3 +- ...list.test.js => reviewerChecklist.test.ts} | 21 +- 5 files changed, 214 insertions(+), 1275 deletions(-) rename workflow_tests/{reviewerChecklist.test.js => reviewerChecklist.test.ts} (80%) diff --git a/package-lock.json b/package-lock.json index d009c9d3ad3c..209b2ee12676 100644 --- a/package-lock.json +++ b/package-lock.json @@ -236,6 +236,7 @@ "shellcheck": "^1.1.0", "style-loader": "^2.0.0", "time-analytics-webpack-plugin": "^0.1.17", + "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "type-fest": "^4.10.2", "typescript": "^5.3.2", @@ -5962,30 +5963,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/console/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/console/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/@jest/console/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -6101,30 +6078,6 @@ } } }, - "node_modules/@jest/core/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/core/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/@jest/core/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -6206,94 +6159,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/create-cache-key-function/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/create-cache-key-function/node_modules/@types/yargs": { - "version": "17.0.31", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.31.tgz", - "integrity": "sha512-bocYSx4DI8TmdlvxqGpVNXOgCNR1Jj0gNPhhAY+iz1rgKDAaYrAYdFYnhDV1IFuiuVc9HkOwyDcFxaTElF3/wg==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/@jest/create-cache-key-function/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@jest/create-cache-key-function/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/@jest/create-cache-key-function/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@jest/create-cache-key-function/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/@jest/create-cache-key-function/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/@jest/create-cache-key-function/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@jest/environment": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", @@ -6308,94 +6173,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/environment/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/environment/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/@jest/environment/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@jest/environment/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/@jest/environment/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@jest/environment/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/@jest/environment/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/@jest/environment/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@jest/expect": { "version": "29.6.2", "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.6.2.tgz", @@ -6435,94 +6212,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/fake-timers/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/fake-timers/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/@jest/fake-timers/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@jest/fake-timers/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/@jest/fake-timers/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@jest/fake-timers/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/@jest/fake-timers/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/@jest/fake-timers/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@jest/globals": { "version": "29.5.0", "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.5.0.tgz", @@ -6537,94 +6226,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/globals/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/globals/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/@jest/globals/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@jest/globals/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/@jest/globals/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@jest/globals/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/@jest/globals/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/@jest/globals/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@jest/reporters": { "version": "29.4.1", "license": "MIT", @@ -6666,30 +6267,6 @@ } } }, - "node_modules/@jest/reporters/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/reporters/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/@jest/reporters/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -6825,100 +6402,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/test-result/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/test-result/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/@jest/test-result/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@jest/test-result/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/@jest/test-result/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@jest/test-result/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "license": "MIT" - }, - "node_modules/@jest/test-result/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/@jest/test-result/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@jest/test-sequencer": { "version": "29.4.1", "license": "MIT", @@ -6957,30 +6440,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/transform/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/@jest/transform/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/@jest/transform/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -7063,19 +6522,19 @@ } }, "node_modules/@jest/types": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", - "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", - "license": "MIT", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", + "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", "dependencies": { + "@jest/schemas": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", "@types/node": "*", - "@types/yargs": "^15.0.0", + "@types/yargs": "^17.0.8", "chalk": "^4.0.0" }, "engines": { - "node": ">= 10.14.2" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/types/node_modules/ansi-styles": { @@ -9442,6 +8901,29 @@ "ws": "^7.5.1" } }, + "node_modules/@react-native-community/cli-server-api/node_modules/@jest/types": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", + "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "dependencies": { + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^3.0.0", + "@types/node": "*", + "@types/yargs": "^15.0.0", + "chalk": "^4.0.0" + }, + "engines": { + "node": ">= 10.14.2" + } + }, + "node_modules/@react-native-community/cli-server-api/node_modules/@types/yargs": { + "version": "15.0.19", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.19.tgz", + "integrity": "sha512-2XUaGVmyQjgyAZldf0D0c14vvo/yv0MhQBSTJcejMMaitsn3nxCB6TmH4G0ZQf+uxROOa9mpanoSm8h6SG/1ZA==", + "dependencies": { + "@types/yargs-parser": "*" + } + }, "node_modules/@react-native-community/cli-server-api/node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -9464,6 +8946,21 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/@react-native-community/cli-server-api/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@react-native-community/cli-server-api/node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -9480,6 +8977,14 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/@react-native-community/cli-server-api/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/@react-native-community/cli-server-api/node_modules/pretty-format": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", @@ -9499,6 +9004,17 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" }, + "node_modules/@react-native-community/cli-server-api/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/@react-native-community/cli-server-api/node_modules/ws": { "version": "7.5.9", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", @@ -21229,18 +20745,17 @@ } }, "node_modules/@types/yargs": { - "version": "15.0.15", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.15.tgz", - "integrity": "sha512-IziEYMU9XoVj8hWg7k+UJrXALkGFjWJhn5QFEv9q4p+v40oZhSuC135M38st8XPjICL7Ey4TV64ferBGUoJhBg==", + "version": "17.0.32", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", + "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", "dependencies": { "@types/yargs-parser": "*" } }, "node_modules/@types/yargs-parser": { - "version": "21.0.0", - "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz", - "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", - "license": "MIT" + "version": "21.0.3", + "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz", + "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==" }, "node_modules/@types/yauzl": { "version": "2.10.0", @@ -25048,6 +24563,18 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -35692,30 +35219,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-circus/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-circus/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-circus/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -35820,30 +35323,6 @@ } } }, - "node_modules/jest-cli/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-cli/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-cli/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -36006,30 +35485,6 @@ } } }, - "node_modules/jest-config/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-config/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-config/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -36208,30 +35663,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-each/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-each/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-each/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -36327,30 +35758,6 @@ } } }, - "node_modules/jest-environment-jsdom/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-environment-jsdom/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-environment-jsdom/node_modules/acorn": { "version": "8.11.3", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", @@ -36362,55 +35769,6 @@ "node": ">=0.4.0" } }, - "node_modules/jest-environment-jsdom/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/jest-environment-jsdom/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/jest-environment-jsdom/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/jest-environment-jsdom/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "license": "MIT" - }, "node_modules/jest-environment-jsdom/node_modules/cssstyle": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-2.3.0.tgz", @@ -36464,15 +35822,6 @@ "node": ">= 6" } }, - "node_modules/jest-environment-jsdom/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/jest-environment-jsdom/node_modules/html-encoding-sniffer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz", @@ -36539,18 +35888,6 @@ "url": "https://github.com/inikulin/parse5?sponsor=1" } }, - "node_modules/jest-environment-jsdom/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/jest-environment-jsdom/node_modules/tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", @@ -36628,94 +35965,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-environment-node/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-environment-node/node_modules/@types/yargs": { - "version": "17.0.31", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.31.tgz", - "integrity": "sha512-bocYSx4DI8TmdlvxqGpVNXOgCNR1Jj0gNPhhAY+iz1rgKDAaYrAYdFYnhDV1IFuiuVc9HkOwyDcFxaTElF3/wg==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/jest-environment-node/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/jest-environment-node/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/jest-environment-node/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/jest-environment-node/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/jest-environment-node/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/jest-environment-node/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/jest-expo": { "version": "50.0.1", "resolved": "https://registry.npmjs.org/jest-expo/-/jest-expo-50.0.1.tgz", @@ -36788,75 +36037,6 @@ "fsevents": "^2.3.2" } }, - "node_modules/jest-haste-map/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-haste-map/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/jest-haste-map/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/jest-haste-map/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/jest-haste-map/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/jest-haste-map/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, "node_modules/jest-haste-map/node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -36893,17 +36073,6 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, - "node_modules/jest-haste-map/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/jest-leak-detector": { "version": "29.4.1", "license": "MIT", @@ -37018,30 +36187,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-message-util/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-message-util/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-message-util/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -37119,94 +36264,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-mock/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-mock/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/jest-mock/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/jest-mock/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/jest-mock/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/jest-mock/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/jest-mock/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/jest-mock/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/jest-pnp-resolver": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.3.tgz", @@ -37361,30 +36418,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-runner/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-runner/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-runner/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -37526,30 +36559,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-runtime/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-runtime/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-runtime/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -37650,30 +36659,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-snapshot/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-snapshot/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-snapshot/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -37764,30 +36749,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-util/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-util/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-util/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -37868,30 +36829,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-validate/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-validate/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-validate/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -38212,30 +37149,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-watcher/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-watcher/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, "node_modules/jest-watcher/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -38353,100 +37266,6 @@ "node": ">=8" } }, - "node_modules/jest/node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest/node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/jest/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/jest/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/jest/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/jest/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "license": "MIT" - }, - "node_modules/jest/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/jest/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/jimp-compact": { "version": "0.16.1", "resolved": "https://registry.npmjs.org/jimp-compact/-/jimp-compact-0.16.1.tgz", @@ -39228,6 +38047,12 @@ "dev": true, "peer": true }, + "node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -45174,6 +43999,29 @@ "node": ">=8" } }, + "node_modules/react-native/node_modules/@jest/types": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", + "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "dependencies": { + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^3.0.0", + "@types/node": "*", + "@types/yargs": "^15.0.0", + "chalk": "^4.0.0" + }, + "engines": { + "node": ">= 10.14.2" + } + }, + "node_modules/react-native/node_modules/@types/yargs": { + "version": "15.0.19", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.19.tgz", + "integrity": "sha512-2XUaGVmyQjgyAZldf0D0c14vvo/yv0MhQBSTJcejMMaitsn3nxCB6TmH4G0ZQf+uxROOa9mpanoSm8h6SG/1ZA==", + "dependencies": { + "@types/yargs-parser": "*" + } + }, "node_modules/react-native/node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -45196,6 +44044,21 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/react-native/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/react-native/node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", @@ -45238,6 +44101,14 @@ "node": ">=18" } }, + "node_modules/react-native/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/react-native/node_modules/mkdirp": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", @@ -45292,6 +44163,17 @@ "loose-envify": "^1.1.0" } }, + "node_modules/react-native/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/react-native/node_modules/ws": { "version": "6.2.2", "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", @@ -50354,6 +49236,58 @@ "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==" }, + "node_modules/ts-jest": { + "version": "29.1.2", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.2.tgz", + "integrity": "sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g==", + "dev": true, + "dependencies": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^29.0.0", + "json5": "^2.2.3", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "^7.5.3", + "yargs-parser": "^21.0.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^16.10.0 || ^18.0.0 || >=20.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/types": "^29.0.0", + "babel-jest": "^29.0.0", + "jest": "^29.0.0", + "typescript": ">=4.3 <6" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/ts-node": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", diff --git a/package.json b/package.json index 62da9d177dca..20779c73e402 100644 --- a/package.json +++ b/package.json @@ -157,8 +157,8 @@ "react-native-plaid-link-sdk": "10.8.0", "react-native-qrcode-svg": "^6.2.0", "react-native-quick-sqlite": "^8.0.0-beta.2", - "react-native-release-profiler": "^0.1.6", "react-native-reanimated": "^3.7.2", + "react-native-release-profiler": "^0.1.6", "react-native-render-html": "6.3.1", "react-native-safe-area-context": "4.8.2", "react-native-screens": "3.29.0", @@ -287,6 +287,7 @@ "shellcheck": "^1.1.0", "style-loader": "^2.0.0", "time-analytics-webpack-plugin": "^0.1.17", + "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "type-fest": "^4.10.2", "typescript": "^5.3.2", diff --git a/tsconfig.json b/tsconfig.json index 30708f63d12b..79413fdd2ca7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -48,6 +48,6 @@ } }, "exclude": ["**/node_modules/*", "**/dist/*", ".github/actions/**/index.js", "**/docs/*"], - "include": ["src", "desktop", "web", "website", "docs", "assets", "config", "tests", "jest", "__mocks__", ".github/**/*", ".storybook/**/*"], + "include": ["src", "desktop", "web", "website", "docs", "assets", "config", "tests", "jest", "__mocks__", ".github/**/*", ".storybook/**/*", "workflow_tests"], "extends": "expo/tsconfig.base" } diff --git a/workflow_tests/jest.config.js b/workflow_tests/jest.config.js index c8a4534764e3..91857765b439 100644 --- a/workflow_tests/jest.config.js +++ b/workflow_tests/jest.config.js @@ -1,7 +1,8 @@ module.exports = { + preset: 'ts-jest', verbose: true, transform: { - '^.+\\.jsx?$': 'babel-jest', + '^.+\\.(js|jsx|ts|tsx)$': 'ts-jest', }, clearMocks: true, resetMocks: true, diff --git a/workflow_tests/reviewerChecklist.test.js b/workflow_tests/reviewerChecklist.test.ts similarity index 80% rename from workflow_tests/reviewerChecklist.test.js rename to workflow_tests/reviewerChecklist.test.ts index 9903c3eb4b8d..209e0974a8bf 100644 --- a/workflow_tests/reviewerChecklist.test.js +++ b/workflow_tests/reviewerChecklist.test.ts @@ -1,13 +1,14 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/reviewerChecklistAssertions'); -const mocks = require('./mocks/reviewerChecklistMocks'); -const eAct = require('./utils/ExtendedAct'); +import * as kieMockGithub from '@kie/mock-github'; +import type {CreateRepositoryFile, MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/reviewerChecklistAssertions'; +import mocks from './mocks/reviewerChecklistMocks'; +import eAct from './utils/ExtendedAct'; +import utils from './utils/utils'; jest.setTimeout(90 * 1000); -let mockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ +let mockGithub: MockGithub; +const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { src: path.resolve(__dirname, '..', '.github', 'workflows', 'reviewerChecklist.yml'), @@ -42,11 +43,12 @@ describe('test workflow reviewerChecklist', () => { }); describe('event is pull_request_review', () => { const event = 'pull_request_review'; - const eventOptions = {}; + const eventOptions: Record = {}; it('runs the workflow', async () => { const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); const testMockSteps = { checklist: mocks.REVIEWERCHECKLIST__CHECKLIST__STEP_MOCKS, @@ -66,6 +68,7 @@ describe('test workflow reviewerChecklist', () => { const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); const testMockSteps = { checklist: mocks.REVIEWERCHECKLIST__CHECKLIST__STEP_MOCKS, From 58113e2e412573b23f1884619aea84cf4369780b Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 11 Mar 2024 15:25:58 +0100 Subject: [PATCH 110/504] [TS migration] Migrate 'test.test.js' workflow test --- workflow_tests/reviewerChecklist.test.ts | 7 ++-- workflow_tests/{test.test.js => test.test.ts} | 36 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) rename workflow_tests/{test.test.js => test.test.ts} (82%) diff --git a/workflow_tests/reviewerChecklist.test.ts b/workflow_tests/reviewerChecklist.test.ts index 209e0974a8bf..e786e5466ec8 100644 --- a/workflow_tests/reviewerChecklist.test.ts +++ b/workflow_tests/reviewerChecklist.test.ts @@ -1,3 +1,4 @@ +import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types'; import * as kieMockGithub from '@kie/mock-github'; import type {CreateRepositoryFile, MockGithub} from '@kie/mock-github'; import path from 'path'; @@ -43,14 +44,14 @@ describe('test workflow reviewerChecklist', () => { }); describe('event is pull_request_review', () => { const event = 'pull_request_review'; - const eventOptions: Record = {}; + const eventOptions = {}; it('runs the workflow', async () => { const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { checklist: mocks.REVIEWERCHECKLIST__CHECKLIST__STEP_MOCKS, }; const result = await act.runEvent(event, { @@ -70,7 +71,7 @@ describe('test workflow reviewerChecklist', () => { let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { checklist: mocks.REVIEWERCHECKLIST__CHECKLIST__STEP_MOCKS, }; const result = await act.runEvent(event, { diff --git a/workflow_tests/test.test.js b/workflow_tests/test.test.ts similarity index 82% rename from workflow_tests/test.test.js rename to workflow_tests/test.test.ts index 6efe8d260928..56b9179dafa2 100644 --- a/workflow_tests/test.test.js +++ b/workflow_tests/test.test.ts @@ -1,13 +1,15 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/testAssertions'); -const mocks = require('./mocks/testMocks'); -const eAct = require('./utils/ExtendedAct'); +import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types'; +import * as kieMockGithub from '@kie/mock-github'; +import type {CreateRepositoryFile, MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/testAssertions'; +import mocks from './mocks/testMocks'; +import eAct from './utils/ExtendedAct'; +import utils from './utils/utils'; jest.setTimeout(90 * 1000); -let mockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ +let mockGithub: MockGithub; +const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { src: path.resolve(__dirname, '..', '.github', 'workflows', 'test.yml'), @@ -52,8 +54,9 @@ describe('test workflow test', () => { const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { jest: mocks.TEST__JEST__STEP_MOCKS, shellTests: mocks.TEST__SHELLTESTS__STEP_MOCKS, }; @@ -72,8 +75,9 @@ describe('test workflow test', () => { const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { jest: mocks.TEST__JEST__STEP_MOCKS, shellTests: mocks.TEST__SHELLTESTS__STEP_MOCKS, }; @@ -99,8 +103,9 @@ describe('test workflow test', () => { const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { jest: mocks.TEST__JEST__STEP_MOCKS, shellTests: mocks.TEST__SHELLTESTS__STEP_MOCKS, }; @@ -119,8 +124,9 @@ describe('test workflow test', () => { const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { jest: mocks.TEST__JEST__STEP_MOCKS, shellTests: mocks.TEST__SHELLTESTS__STEP_MOCKS, }; @@ -144,8 +150,9 @@ describe('test workflow test', () => { const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { jest: mocks.TEST__JEST__STEP_MOCKS, shellTests: mocks.TEST__SHELLTESTS__STEP_MOCKS, }; @@ -164,8 +171,9 @@ describe('test workflow test', () => { const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { jest: mocks.TEST__JEST__STEP_MOCKS, shellTests: mocks.TEST__SHELLTESTS__STEP_MOCKS, }; From 825c3b79e8daa6039046b59d19a22d0a9921e5fc Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 11 Mar 2024 15:36:20 +0100 Subject: [PATCH 111/504] Fix lint problems --- workflow_tests/reviewerChecklist.test.ts | 6 +++--- workflow_tests/test.test.ts | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/workflow_tests/reviewerChecklist.test.ts b/workflow_tests/reviewerChecklist.test.ts index e786e5466ec8..e34e6a0e07fd 100644 --- a/workflow_tests/reviewerChecklist.test.ts +++ b/workflow_tests/reviewerChecklist.test.ts @@ -21,7 +21,7 @@ describe('test workflow reviewerChecklist', () => { const githubToken = 'dummy_github_token'; const actor = 'Dummy Actor'; - beforeAll(async () => { + beforeAll(() => { // in case of the tests being interrupted without cleanup the mock repo directory may be left behind // which breaks the next test run, this removes any possible leftovers utils.removeMockRepoDir(); @@ -46,7 +46,7 @@ describe('test workflow reviewerChecklist', () => { const event = 'pull_request_review'; const eventOptions = {}; it('runs the workflow', async () => { - const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. @@ -66,7 +66,7 @@ describe('test workflow reviewerChecklist', () => { describe('actor is OSBotify', () => { const osbotifyActor = 'OSBotify'; it('does not run the workflow', async () => { - const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. diff --git a/workflow_tests/test.test.ts b/workflow_tests/test.test.ts index 56b9179dafa2..8e6258c09b8b 100644 --- a/workflow_tests/test.test.ts +++ b/workflow_tests/test.test.ts @@ -22,7 +22,7 @@ describe('test workflow test', () => { const actor = 'Dummy Actor'; const osbotifyActor = 'OSBotify'; - beforeAll(async () => { + beforeAll(() => { // in case of the tests being interrupted without cleanup the mock repo directory may be left behind // which breaks the next test run, this removes any possible leftovers utils.removeMockRepoDir(); @@ -51,7 +51,7 @@ describe('test workflow test', () => { action: 'opened', }; it('runs all tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. @@ -72,7 +72,7 @@ describe('test workflow test', () => { }); describe('actor is OSBotify', () => { it('does not run tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. @@ -100,7 +100,7 @@ describe('test workflow test', () => { action: 'synchronize', }; it('runs all tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. @@ -121,7 +121,7 @@ describe('test workflow test', () => { }); describe('actor is OSBotify', () => { it('does not run tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. @@ -147,7 +147,7 @@ describe('test workflow test', () => { const event = 'workflow_call'; const eventOptions = {}; it('runs all tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. @@ -168,7 +168,7 @@ describe('test workflow test', () => { }); describe('actor is OSBotify', () => { it('runs all tests normally', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. From ec0d55355e71ea71f81f29a013eb5185a34cf119 Mon Sep 17 00:00:00 2001 From: Julian Kobrynski Date: Mon, 11 Mar 2024 17:32:37 +0100 Subject: [PATCH 112/504] migrate bumpVersion.js to TypeScript --- .../{bumpVersion.js => bumpVersion.ts} | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) rename .github/actions/javascript/bumpVersion/{bumpVersion.js => bumpVersion.ts} (73%) diff --git a/.github/actions/javascript/bumpVersion/bumpVersion.js b/.github/actions/javascript/bumpVersion/bumpVersion.ts similarity index 73% rename from .github/actions/javascript/bumpVersion/bumpVersion.js rename to .github/actions/javascript/bumpVersion/bumpVersion.ts index 647c295fdc52..d08293c856be 100644 --- a/.github/actions/javascript/bumpVersion/bumpVersion.js +++ b/.github/actions/javascript/bumpVersion/bumpVersion.ts @@ -1,17 +1,16 @@ -const {promisify} = require('util'); -const fs = require('fs'); -const exec = promisify(require('child_process').exec); -const _ = require('underscore'); -const core = require('@actions/core'); -const versionUpdater = require('../../../libs/versionUpdater'); -const {updateAndroidVersion, updateiOSVersion, generateAndroidVersionCode} = require('../../../libs/nativeVersionUpdater'); +import * as core from '@actions/core'; +import {exec as originalExec} from 'child_process'; +import fs from 'fs'; +import {promisify} from 'util'; +import {generateAndroidVersionCode, updateAndroidVersion, updateiOSVersion} from '../../../libs/nativeVersionUpdater'; +import * as versionUpdater from '../../../libs/versionUpdater'; + +const exec = promisify(originalExec); /** * Update the native app versions. - * - * @param {String} version */ -function updateNativeVersions(version) { +function updateNativeVersions(version: string) { console.log(`Updating native versions to ${version}`); // Update Android @@ -28,7 +27,7 @@ function updateNativeVersions(version) { // Update iOS try { const cfBundleVersion = updateiOSVersion(version); - if (_.isString(cfBundleVersion) && cfBundleVersion.split('.').length === 4) { + if (typeof cfBundleVersion === 'string' && cfBundleVersion.split('.').length === 4) { core.setOutput('NEW_IOS_VERSION', cfBundleVersion); console.log('Successfully updated iOS!'); } else { @@ -36,17 +35,17 @@ function updateNativeVersions(version) { } } catch (err) { console.error('Error updating iOS'); - core.setFailed(err); + core.setFailed(err as string); } } -let semanticVersionLevel = core.getInput('SEMVER_LEVEL', {require: true}); -if (!semanticVersionLevel || !_.contains(versionUpdater.SEMANTIC_VERSION_LEVELS, semanticVersionLevel)) { +let semanticVersionLevel = core.getInput('SEMVER_LEVEL', {required: true}); +if (!semanticVersionLevel || !Object.keys(versionUpdater.SEMANTIC_VERSION_LEVELS).includes(semanticVersionLevel)) { semanticVersionLevel = versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD; console.log(`Invalid input for 'SEMVER_LEVEL': ${semanticVersionLevel}`, `Defaulting to: ${semanticVersionLevel}`); } -const {version: previousVersion} = JSON.parse(fs.readFileSync('./package.json')); +const {version: previousVersion} = JSON.parse(fs.readFileSync('./package.json').toString()); const newVersion = versionUpdater.incrementVersion(previousVersion, semanticVersionLevel); console.log(`Previous version: ${previousVersion}`, `New version: ${newVersion}`); From 7068222b62669118304ac6a424deda12388b695d Mon Sep 17 00:00:00 2001 From: Julian Kobrynski Date: Mon, 11 Mar 2024 17:33:05 +0100 Subject: [PATCH 113/504] start migrating markPullRequestsAsDeployed to TypeScript --- ...loyed.js => markPullRequestsAsDeployed.ts} | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) rename .github/actions/javascript/markPullRequestsAsDeployed/{markPullRequestsAsDeployed.js => markPullRequestsAsDeployed.ts} (84%) diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.js b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts similarity index 84% rename from .github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.js rename to .github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts index d03a947cdec8..cf132794ce46 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.js +++ b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts @@ -1,17 +1,15 @@ -const _ = require('underscore'); -const core = require('@actions/core'); -const {context} = require('@actions/github'); -const CONST = require('../../../libs/CONST'); -const ActionUtils = require('../../../libs/ActionUtils'); -const GithubUtils = require('../../../libs/GithubUtils'); +import core from '@actions/core'; +import {context} from '@actions/github'; +import * as ActionUtils from '../../../libs/ActionUtils'; +import CONST from '../../../libs/CONST'; +import * as GithubUtils from '../../../libs/GithubUtils'; + +type PlatformResult = 'success' | 'cancelled' | 'skipped' | 'failure'; /** * Return a nicely formatted message for the table based on the result of the GitHub action job - * - * @param {String} platformResult - * @returns {String} */ -function getDeployTableMessage(platformResult) { +function getDeployTableMessage(platformResult: PlatformResult) { switch (platformResult) { case 'success': return `${platformResult} ✅`; @@ -27,10 +25,6 @@ function getDeployTableMessage(platformResult) { /** * Comment Single PR - * - * @param {Number} PR - * @param {String} message - * @returns {Promise} */ async function commentPR(PR, message) { try { @@ -45,7 +39,7 @@ async function commentPR(PR, message) { const workflowURL = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; async function run() { - const prList = _.map(ActionUtils.getJSONInput('PR_LIST', {required: true}), (num) => Number.parseInt(num, 10)); + const prList = ActionUtils.getJSONInput('PR_LIST', {required: true}).map((num: string) => Number.parseInt(num, 10)); const isProd = ActionUtils.getJSONInput('IS_PRODUCTION_DEPLOY', {required: true}); const version = core.getInput('DEPLOY_VERSION', {required: true}); @@ -55,10 +49,10 @@ async function run() { const webResult = getDeployTableMessage(core.getInput('WEB', {required: true})); /** - * @param {String} deployer - * @param {String} deployVerb - * @param {String} prTitle - * @returns {String} + * @param deployer + * @param deployVerb + * @param prTitle + * @returns */ function getDeployMessage(deployer, deployVerb, prTitle) { let message = `🚀 [${deployVerb}](${workflowURL}) to ${isProd ? 'production' : 'staging'}`; @@ -83,7 +77,7 @@ async function run() { labels: CONST.LABELS.STAGING_DEPLOY, state: 'closed', }); - const previousChecklistID = _.first(deployChecklists).number; + const previousChecklistID = deployChecklists[0].number; // who closed the last deploy checklist? const deployer = await GithubUtils.getActorWhoClosedIssue(previousChecklistID); @@ -102,7 +96,7 @@ async function run() { repo: CONST.APP_REPO, per_page: 100, }); - const currentTag = _.find(recentTags, (tag) => tag.name === version); + const currentTag = recentTags.find((tag) => tag.name === version); if (!currentTag) { const err = `Could not find tag matching ${version}`; console.error(err); @@ -139,4 +133,4 @@ if (require.main === module) { run(); } -module.exports = run; +export default run; From 2260d2a4a9fcecb00e2dd2c64bcd3379b40a5c70 Mon Sep 17 00:00:00 2001 From: Julian Kobrynski Date: Mon, 11 Mar 2024 17:33:21 +0100 Subject: [PATCH 114/504] start migrating GithubUtils to TypeScript --- .../libs/{GithubUtils.js => GithubUtils.ts} | 235 +++++++++--------- 1 file changed, 120 insertions(+), 115 deletions(-) rename .github/libs/{GithubUtils.js => GithubUtils.ts} (71%) diff --git a/.github/libs/GithubUtils.js b/.github/libs/GithubUtils.ts similarity index 71% rename from .github/libs/GithubUtils.js rename to .github/libs/GithubUtils.ts index e988167850ec..046701a94a9c 100644 --- a/.github/libs/GithubUtils.js +++ b/.github/libs/GithubUtils.ts @@ -1,10 +1,12 @@ -const _ = require('underscore'); -const lodashGet = require('lodash/get'); -const core = require('@actions/core'); -const {GitHub, getOctokitOptions} = require('@actions/github/lib/utils'); -const {throttling} = require('@octokit/plugin-throttling'); -const {paginateRest} = require('@octokit/plugin-paginate-rest'); -const CONST = require('./CONST'); +import * as core from '@actions/core'; +import {getOctokitOptions, GitHub} from '@actions/github/lib/utils'; +import type {Octokit as OctokitCore} from '@octokit/core'; +import type {PaginateInterface} from '@octokit/plugin-paginate-rest'; +import {paginateRest} from '@octokit/plugin-paginate-rest'; +import {throttling} from '@octokit/plugin-throttling'; +import _ from 'underscore'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import CONST from './CONST'; const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); const PULL_REQUEST_REGEX = new RegExp(`${GITHUB_BASE_URL_REGEX.source}/.*/.*/pull/([0-9]+).*`); @@ -14,11 +16,14 @@ const ISSUE_OR_PULL_REQUEST_REGEX = new RegExp(`${GITHUB_BASE_URL_REGEX.source}/ /** * The standard rate in ms at which we'll poll the GitHub API to check for status changes. * It's 10 seconds :) - * @type {number} */ const POLL_RATE = 10000; +type OctokitOptions = {method: string; url: string; request: {retryCount: number}}; + class GithubUtils { + static internalOctokit: OctokitCore & {paginate: PaginateInterface}; + /** * Initialize internal octokit * @@ -33,7 +38,7 @@ class GithubUtils { getOctokitOptions(token, { throttle: { retryAfterBaseValue: 2000, - onRateLimit: (retryAfter, options) => { + onRateLimit: (retryAfter: number, options: OctokitOptions) => { console.warn(`Request quota exhausted for request ${options.method} ${options.url}`); // Retry five times when hitting a rate limit error, then give up @@ -42,7 +47,7 @@ class GithubUtils { return true; } }, - onAbuseLimit: (retryAfter, options) => { + onAbuseLimit: (retryAfter: number, options: OctokitOptions) => { // does not retry, only logs a warning console.warn(`Abuse detected for request ${options.method} ${options.url}`); }, @@ -98,7 +103,7 @@ class GithubUtils { /** * Finds one open `StagingDeployCash` issue via GitHub octokit library. * - * @returns {Promise} + * @returns */ static getStagingDeployCash() { return this.octokit.issues @@ -128,8 +133,8 @@ class GithubUtils { /** * Takes in a GitHub issue object and returns the data we want. * - * @param {Object} issue - * @returns {Object} + * @param issue + * @returns */ static getStagingDeployCashData(issue) { try { @@ -158,8 +163,8 @@ class GithubUtils { * * @private * - * @param {Object} issue - * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] + * @param issue + * @returns - [{url: String, number: Number, isVerified: Boolean}] */ static getStagingDeployCashPRList(issue) { let PRListSection = issue.body.match(/pull requests:\*\*\r?\n((?:-.*\r?\n)+)\r?\n\r?\n?/) || []; @@ -169,7 +174,7 @@ class GithubUtils { return []; } PRListSection = PRListSection[1]; - const PRList = _.map([...PRListSection.matchAll(new RegExp(`- \\[([ x])] (${PULL_REQUEST_REGEX.source})`, 'g'))], (match) => ({ + const PRList = [...PRListSection.matchAll(new RegExp(`- \\[([ x])] (${PULL_REQUEST_REGEX.source})`, 'g'))].map((match) => ({ url: match[2], number: Number.parseInt(match[3], 10), isVerified: match[1] === 'x', @@ -182,8 +187,8 @@ class GithubUtils { * * @private * - * @param {Object} issue - * @returns {Array} - [{URL: String, number: Number, isResolved: Boolean}] + * @param issue + * @returns - [{URL: String, number: Number, isResolved: Boolean}] */ static getStagingDeployCashDeployBlockers(issue) { let deployBlockerSection = issue.body.match(/Deploy Blockers:\*\*\r?\n((?:-.*\r?\n)+)/) || []; @@ -191,7 +196,7 @@ class GithubUtils { return []; } deployBlockerSection = deployBlockerSection[1]; - const deployBlockers = _.map([...deployBlockerSection.matchAll(new RegExp(`- \\[([ x])]\\s(${ISSUE_OR_PULL_REQUEST_REGEX.source})`, 'g'))], (match) => ({ + const deployBlockers = [...deployBlockerSection.matchAll(new RegExp(`- \\[([ x])]\\s(${ISSUE_OR_PULL_REQUEST_REGEX.source})`, 'g'))].map((match) => ({ url: match[2], number: Number.parseInt(match[3], 10), isResolved: match[1] === 'x', @@ -204,8 +209,8 @@ class GithubUtils { * * @private * - * @param {Object} issue - * @returns {Array} - [{URL: String, number: Number, isResolved: Boolean}] + * @param issue + * @returns - [{URL: String, number: Number, isResolved: Boolean}] */ static getStagingDeployCashInternalQA(issue) { let internalQASection = issue.body.match(/Internal QA:\*\*\r?\n((?:- \[[ x]].*\r?\n)+)/) || []; @@ -213,7 +218,7 @@ class GithubUtils { return []; } internalQASection = internalQASection[1]; - const internalQAPRs = _.map([...internalQASection.matchAll(new RegExp(`- \\[([ x])]\\s(${PULL_REQUEST_REGEX.source})`, 'g'))], (match) => ({ + const internalQAPRs = [...internalQASection.matchAll(new RegExp(`- \\[([ x])]\\s(${PULL_REQUEST_REGEX.source})`, 'g'))].map((match) => ({ url: match[2].split('-')[0].trim(), number: Number.parseInt(match[3], 10), isResolved: match[1] === 'x', @@ -224,54 +229,52 @@ class GithubUtils { /** * Generate the issue body for a StagingDeployCash. * - * @param {String} tag - * @param {Array} PRList - The list of PR URLs which are included in this StagingDeployCash - * @param {Array} [verifiedPRList] - The list of PR URLs which have passed QA. - * @param {Array} [deployBlockers] - The list of DeployBlocker URLs. - * @param {Array} [resolvedDeployBlockers] - The list of DeployBlockers URLs which have been resolved. - * @param {Array} [resolvedInternalQAPRs] - The list of Internal QA PR URLs which have been resolved. - * @param {Boolean} [isTimingDashboardChecked] - * @param {Boolean} [isFirebaseChecked] - * @param {Boolean} [isGHStatusChecked] - * @returns {Promise} + * @param tag + * @param PRList - The list of PR URLs which are included in this StagingDeployCash + * @param [verifiedPRList] - The list of PR URLs which have passed QA. + * @param [deployBlockers] - The list of DeployBlocker URLs. + * @param [resolvedDeployBlockers] - The list of DeployBlockers URLs which have been resolved. + * @param [resolvedInternalQAPRs] - The list of Internal QA PR URLs which have been resolved. + * @param [isTimingDashboardChecked] + * @param [isFirebaseChecked] + * @param [isGHStatusChecked] + * @returns */ static generateStagingDeployCashBody( - tag, - PRList, - verifiedPRList = [], - deployBlockers = [], - resolvedDeployBlockers = [], - resolvedInternalQAPRs = [], + tag: string, + PRList: string[], + verifiedPRList: string[] = [], + deployBlockers: string[] = [], + resolvedDeployBlockers: string[] = [], + resolvedInternalQAPRs: string[] = [], isTimingDashboardChecked = false, isFirebaseChecked = false, isGHStatusChecked = false, ) { - return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL)) + return this.fetchAllPullRequests(PRList.map(this.getPullRequestNumberFromURL)) .then((data) => { // The format of this map is following: // { // 'https://github.com/Expensify/App/pull/9641': 'PauloGasparSv', // 'https://github.com/Expensify/App/pull/9642': 'mountiny' // } - const internalQAPRMap = _.reduce( - _.filter(data, (pr) => !_.isEmpty(_.findWhere(pr.labels, {name: CONST.LABELS.INTERNAL_QA}))), - (map, pr) => { + const internalQAPRMap = data + .filter((pr) => !isEmptyObject(_.findWhere(pr.labels, {name: CONST.LABELS.INTERNAL_QA}))) + .reduce((map, pr) => { // eslint-disable-next-line no-param-reassign map[pr.html_url] = pr.merged_by.login; return map; - }, - {}, - ); + }, {}); console.log('Found the following Internal QA PRs:', internalQAPRMap); const noQAPRs = _.pluck( - _.filter(data, (PR) => /\[No\s?QA]/i.test(PR.title)), + data.filter((PR) => /\[No\s?QA]/i.test(PR.title)), 'html_url', ); console.log('Found the following NO QA PRs:', noQAPRs); const verifiedOrNoQAPRs = _.union(verifiedPRList, noQAPRs); - const sortedPRList = _.chain(PRList).difference(_.keys(internalQAPRMap)).unique().sortBy(GithubUtils.getPullRequestNumberFromURL).value(); + const sortedPRList = _.chain(PRList).difference(Object.keys(internalQAPRMap)).unique().sortBy(GithubUtils.getPullRequestNumberFromURL).value(); const sortedDeployBlockers = _.sortBy(_.unique(deployBlockers), GithubUtils.getIssueOrPullRequestNumberFromURL); // Tag version and comparison URL @@ -279,22 +282,22 @@ class GithubUtils { let issueBody = `**Release Version:** \`${tag}\`\r\n**Compare Changes:** https://github.com/Expensify/App/compare/production...staging\r\n`; // PR list - if (!_.isEmpty(sortedPRList)) { + if (!isEmptyObject(sortedPRList)) { issueBody += '\r\n**This release contains changes from the following pull requests:**\r\n'; - _.each(sortedPRList, (URL) => { - issueBody += _.contains(verifiedOrNoQAPRs, URL) ? '- [x]' : '- [ ]'; + sortedPRList.forEach((URL) => { + issueBody += verifiedOrNoQAPRs.includes(URL) ? '- [x]' : '- [ ]'; issueBody += ` ${URL}\r\n`; }); issueBody += '\r\n\r\n'; } // Internal QA PR list - if (!_.isEmpty(internalQAPRMap)) { + if (!isEmptyObject(internalQAPRMap)) { console.log('Found the following verified Internal QA PRs:', resolvedInternalQAPRs); issueBody += '**Internal QA:**\r\n'; - _.each(internalQAPRMap, (merger, URL) => { + internalQAPRMap.each((merger, URL) => { const mergerMention = `@${merger}`; - issueBody += `${_.contains(resolvedInternalQAPRs, URL) ? '- [x]' : '- [ ]'} `; + issueBody += `${resolvedInternalQAPRs.includes(URL) ? '- [x]' : '- [ ]'} `; issueBody += `${URL}`; issueBody += ` - ${mergerMention}`; issueBody += '\r\n'; @@ -303,10 +306,10 @@ class GithubUtils { } // Deploy blockers - if (!_.isEmpty(deployBlockers)) { + if (!isEmptyObject(deployBlockers)) { issueBody += '**Deploy Blockers:**\r\n'; - _.each(sortedDeployBlockers, (URL) => { - issueBody += _.contains(resolvedDeployBlockers, URL) ? '- [x] ' : '- [ ] '; + sortedDeployBlockers.forEach((URL) => { + issueBody += resolvedDeployBlockers.includes(URL) ? '- [x] ' : '- [ ] '; issueBody += URL; issueBody += '\r\n'; }); @@ -326,7 +329,7 @@ class GithubUtils { issueBody += `\r\n- [${isGHStatusChecked ? 'x' : ' '}] I checked [GitHub Status](https://www.githubstatus.com/) and verified there is no reported incident with Actions.`; issueBody += '\r\n\r\ncc @Expensify/applauseleads\r\n'; - const issueAssignees = _.values(internalQAPRMap); + const issueAssignees = Object.values(internalQAPRMap); const issue = {issueBody, issueAssignees}; return issue; }) @@ -335,12 +338,9 @@ class GithubUtils { /** * Fetch all pull requests given a list of PR numbers. - * - * @param {Array} pullRequestNumbers - * @returns {Promise} */ - static fetchAllPullRequests(pullRequestNumbers) { - const oldestPR = _.first(_.sortBy(pullRequestNumbers)); + static fetchAllPullRequests(pullRequestNumbers: number[]) { + const oldestPR = _.sortBy(pullRequestNumbers)[0]; return this.paginate( this.octokit.pulls.list, { @@ -352,19 +352,19 @@ class GithubUtils { per_page: 100, }, ({data}, done) => { - if (_.find(data, (pr) => pr.number === oldestPR)) { + if (data.find((pr) => pr.number === oldestPR)) { done(); } return data; }, ) - .then((prList) => _.filter(prList, (pr) => _.contains(pullRequestNumbers, pr.number))) + .then((prList) => prList.filter((pr) => pullRequestNumbers.includes(pr.number))) .catch((err) => console.error('Failed to get PR list', err)); } /** - * @param {Number} pullRequestNumber - * @returns {Promise} + * @param pullRequestNumber + * @returns */ static getPullRequestBody(pullRequestNumber) { return this.octokit.pulls @@ -377,8 +377,8 @@ class GithubUtils { } /** - * @param {Number} pullRequestNumber - * @returns {Promise} + * @param pullRequestNumber + * @returns */ static getAllReviewComments(pullRequestNumber) { return this.paginate( @@ -389,13 +389,13 @@ class GithubUtils { pull_number: pullRequestNumber, per_page: 100, }, - (response) => _.map(response.data, (review) => review.body), + (response) => response.data.map((review) => review.body), ); } /** - * @param {Number} issueNumber - * @returns {Promise} + * @param issueNumber + * @returns */ static getAllComments(issueNumber) { return this.paginate( @@ -406,17 +406,17 @@ class GithubUtils { issue_number: issueNumber, per_page: 100, }, - (response) => _.map(response.data, (comment) => comment.body), + (response) => response.data.map((comment) => comment.body), ); } /** * Create comment on pull request * - * @param {String} repo - The repo to search for a matching pull request or issue number - * @param {Number} number - The pull request or issue number - * @param {String} messageBody - The comment message - * @returns {Promise} + * @param repo - The repo to search for a matching pull request or issue number + * @param number - The pull request or issue number + * @param messageBody - The comment message + * @returns */ static createComment(repo, number, messageBody) { console.log(`Writing comment on #${number}`); @@ -431,50 +431,53 @@ class GithubUtils { /** * Get the most recent workflow run for the given New Expensify workflow. * - * @param {String} workflow - * @returns {Promise} + * @param workflow + * @returns */ static getLatestWorkflowRunID(workflow) { console.log(`Fetching New Expensify workflow runs for ${workflow}...`); - return this.octokit.actions - .listWorkflowRuns({ - owner: CONST.GITHUB_OWNER, - repo: CONST.APP_REPO, - workflow_id: workflow, - }) - .then((response) => lodashGet(response, 'data.workflow_runs[0].id')); + return ( + this.octokit.actions + .listWorkflowRuns({ + owner: CONST.GITHUB_OWNER, + repo: CONST.APP_REPO, + workflow_id: workflow, + }) + // .then((response) => lodashGet(response, 'data.workflow_runs[0].id')); + .then((response) => response.data.workflow_runs[0].id) + ); } /** * Generate the well-formatted body of a production release. * - * @param {Array} pullRequests - * @returns {String} + * @param pullRequests + * @returns */ static getReleaseBody(pullRequests) { - return _.map(pullRequests, (number) => `- ${this.getPullRequestURLFromNumber(number)}`).join('\r\n'); + return pullRequests.map((number) => `- ${this.getPullRequestURLFromNumber(number)}`).join('\r\n'); } /** * Generate the URL of an New Expensify pull request given the PR number. * - * @param {Number} number - * @returns {String} + * @param number + * @returns */ - static getPullRequestURLFromNumber(number) { - return `${CONST.APP_REPO_URL}/pull/${number}`; + static getPullRequestURLFromNumber(value: number): string { + return `${CONST.APP_REPO_URL}/pull/${value}`; } /** * Parse the pull request number from a URL. * - * @param {String} URL - * @returns {Number} + * @param URL + * @returns * @throws {Error} If the URL is not a valid Github Pull Request. */ - static getPullRequestNumberFromURL(URL) { + static getPullRequestNumberFromURL(URL: string): number { const matches = URL.match(PULL_REQUEST_REGEX); - if (!_.isArray(matches) || matches.length !== 2) { + if (!Array.isArray(matches) || matches.length !== 2) { throw new Error(`Provided URL ${URL} is not a Github Pull Request!`); } return Number.parseInt(matches[1], 10); @@ -483,13 +486,13 @@ class GithubUtils { /** * Parse the issue number from a URL. * - * @param {String} URL - * @returns {Number} + * @param URL + * @returns * @throws {Error} If the URL is not a valid Github Issue. */ static getIssueNumberFromURL(URL) { const matches = URL.match(ISSUE_REGEX); - if (!_.isArray(matches) || matches.length !== 2) { + if (!Array.isArray(matches) || matches.length !== 2) { throw new Error(`Provided URL ${URL} is not a Github Issue!`); } return Number.parseInt(matches[1], 10); @@ -498,13 +501,13 @@ class GithubUtils { /** * Parse the issue or pull request number from a URL. * - * @param {String} URL - * @returns {Number} + * @param URL + * @returns * @throws {Error} If the URL is not a valid Github Issue or Pull Request. */ static getIssueOrPullRequestNumberFromURL(URL) { const matches = URL.match(ISSUE_OR_PULL_REQUEST_REGEX); - if (!_.isArray(matches) || matches.length !== 2) { + if (!Array.isArray(matches) || matches.length !== 2) { throw new Error(`Provided URL ${URL} is not a valid Github Issue or Pull Request!`); } return Number.parseInt(matches[1], 10); @@ -513,18 +516,21 @@ class GithubUtils { /** * Return the login of the actor who closed an issue or PR. If the issue is not closed, return an empty string. * - * @param {Number} issueNumber - * @returns {Promise} + * @param issueNumber + * @returns */ static getActorWhoClosedIssue(issueNumber) { - return this.paginate(this.octokit.issues.listEvents, { - owner: CONST.GITHUB_OWNER, - repo: CONST.APP_REPO, - issue_number: issueNumber, - per_page: 100, - }) - .then((events) => _.filter(events, (event) => event.event === 'closed')) - .then((closedEvents) => lodashGet(_.last(closedEvents), 'actor.login', '')); + return ( + this.paginate(this.octokit.issues.listEvents, { + owner: CONST.GITHUB_OWNER, + repo: CONST.APP_REPO, + issue_number: issueNumber, + per_page: 100, + }) + .then((events) => events.filter((event) => event.event === 'closed')) + // .then((closedEvents) => lodashGet(_.last(closedEvents), 'actor.login', '')); + .then((closedEvents) => _.last(closedEvents).actor.login ?? '') + ); } static getArtifactByName(artefactName) { @@ -536,6 +542,5 @@ class GithubUtils { } } -module.exports = GithubUtils; -module.exports.ISSUE_OR_PULL_REQUEST_REGEX = ISSUE_OR_PULL_REQUEST_REGEX; -module.exports.POLL_RATE = POLL_RATE; +export default GithubUtils; +export {ISSUE_OR_PULL_REQUEST_REGEX, POLL_RATE}; From 50d4ce0ccb5e1e3491c70017d8f51747df216dfb Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 11 Mar 2024 18:19:17 +0100 Subject: [PATCH 115/504] [TS migration] Migrate 'lockDeploys.test.js' workflow test --- ...ockDeploys.test.js => lockDeploys.test.ts} | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 deletions(-) rename workflow_tests/{lockDeploys.test.js => lockDeploys.test.ts} (88%) diff --git a/workflow_tests/lockDeploys.test.js b/workflow_tests/lockDeploys.test.ts similarity index 88% rename from workflow_tests/lockDeploys.test.js rename to workflow_tests/lockDeploys.test.ts index a57ed8847fd3..b72db2c3bb85 100644 --- a/workflow_tests/lockDeploys.test.js +++ b/workflow_tests/lockDeploys.test.ts @@ -1,13 +1,15 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/lockDeploysAssertions'); -const mocks = require('./mocks/lockDeploysMocks'); -const eAct = require('./utils/ExtendedAct'); +import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types'; +import * as kieMockGithub from '@kie/mock-github'; +import type {CreateRepositoryFile, MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/lockDeploysAssertions'; +import mocks from './mocks/lockDeploysMocks'; +import eAct from './utils/ExtendedAct'; +import utils from './utils/utils'; jest.setTimeout(90 * 1000); -let mockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ +let mockGithub: MockGithub; +const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { src: path.resolve(__dirname, '..', '.github', 'workflows', 'lockDeploys.yml'), @@ -16,7 +18,7 @@ const FILES_TO_COPY_INTO_TEST_REPO = [ ]; describe('test workflow lockDeploys', () => { - beforeAll(async () => { + beforeAll(() => { // in case of the tests being interrupted without cleanup the mock repo directory may be left behind // which breaks the next test run, this removes any possible leftovers utils.removeMockRepoDir(); @@ -43,11 +45,12 @@ describe('test workflow lockDeploys', () => { describe('issue has StagingDeployCash', () => { describe('actor is not OSBotify', () => { it('job triggered, comment left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -71,7 +74,7 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; const result = await act.runEvent('issues', { @@ -85,11 +88,12 @@ describe('test workflow lockDeploys', () => { }); it('one step fails, comment not left in StagingDeployCash, announced failure in Slack', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -113,12 +117,13 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; testMockSteps.lockStagingDeploys[1] = utils.createMockStep( 'Wait for staging deploys to finish', 'Waiting for staging deploys to finish', + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'LOCKSTAGINGDEPLOYS', ['GITHUB_TOKEN'], [], @@ -139,11 +144,12 @@ describe('test workflow lockDeploys', () => { describe('actor is OSBotify', () => { it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -167,7 +173,7 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; const result = await act.runEvent('issues', { @@ -185,11 +191,12 @@ describe('test workflow lockDeploys', () => { describe('issue does not have StagingDeployCash', () => { describe('actor is not OSBotify', () => { it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -213,7 +220,7 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; const result = await act.runEvent('issues', { @@ -229,11 +236,12 @@ describe('test workflow lockDeploys', () => { describe('actor is OSBotify', () => { it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -257,7 +265,7 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; const result = await act.runEvent('issues', { @@ -277,11 +285,12 @@ describe('test workflow lockDeploys', () => { describe('issue has StagingDeployCash', () => { describe('actor is not OSBotify', () => { it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -305,7 +314,7 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; const result = await act.runEvent('issues', { @@ -321,11 +330,12 @@ describe('test workflow lockDeploys', () => { describe('actor is OSBotify', () => { it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -349,7 +359,7 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; const result = await act.runEvent('issues', { @@ -367,11 +377,12 @@ describe('test workflow lockDeploys', () => { describe('issue does not have StagingDeployCash', () => { describe('actor is not OSBotify', () => { it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -395,7 +406,7 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; const result = await act.runEvent('issues', { @@ -411,11 +422,12 @@ describe('test workflow lockDeploys', () => { describe('actor is OSBotify', () => { it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, + // @ts-expect-error TODO: Remove this once utils (https://github.com/Expensify/App/issues/32061) is migrated to TypeScript. 'issues', { action: 'labeled', @@ -439,7 +451,7 @@ describe('test workflow lockDeploys', () => { }, workflowPath, ); - const testMockSteps = { + const testMockSteps: MockStep = { lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, }; const result = await act.runEvent('issues', { From 7c1cf629aa902962e3f738c9f84669135c03afac Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Mon, 11 Mar 2024 20:55:23 +0300 Subject: [PATCH 116/504] fix typescript --- src/pages/TransactionReceiptPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/TransactionReceiptPage.tsx b/src/pages/TransactionReceiptPage.tsx index 8db9e05a5139..f6f2c90e5d2c 100644 --- a/src/pages/TransactionReceiptPage.tsx +++ b/src/pages/TransactionReceiptPage.tsx @@ -28,7 +28,7 @@ type TransactionReceiptProps = TransactionReceiptOnyxProps & StackScreenProps Date: Tue, 12 Mar 2024 05:23:14 +0530 Subject: [PATCH 117/504] setup theme for helpdot --- docs/_sass/_colors.scss | 58 +++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/docs/_sass/_colors.scss b/docs/_sass/_colors.scss index f0c89d31c580..c9473925d791 100644 --- a/docs/_sass/_colors.scss +++ b/docs/_sass/_colors.scss @@ -1,22 +1,46 @@ -// Product Color Spectrum -$color-product-dark-100: #061B09; -$color-product-dark-200: #072419; -$color-product-dark-300: #0A2E25; -$color-product-dark-400: #1A3D32; -$color-product-dark-500: #224F41; -$color-product-dark-600: #2A604F; -$color-product-dark-700: #8B9C8F; -$color-product-dark-800: #AFBBB0; -$color-product-dark-900: #E7ECE9; +@media (prefers-color-scheme: dark) { + // Product Color Spectrum + $color-product-dark-100: #061B09; + $color-product-dark-200: #072419; + $color-product-dark-300: #0A2E25; + $color-product-dark-400: #1A3D32; + $color-product-dark-500: #224F41; + $color-product-dark-600: #2A604F; + $color-product-dark-700: #8B9C8F; + $color-product-dark-800: #AFBBB0; + $color-product-dark-900: #E7ECE9; -// Colors for Links and Success -$color-blue200: #B0D9FF; -$color-blue300: #5AB0FF; -$color-green400: #03D47C; -$color-green500: #00a862; + // Colors for Links and Success + $color-blue200: #B0D9FF; + $color-blue300: #5AB0FF; + $color-green400: #03D47C; + $color-green500: #00a862; -// Overlay BG color -$color-overlay-background: rgba(26, 61, 50, 0.72); + // Overlay BG color + $color-overlay-background: rgba(26, 61, 50, 0.72); +} + +@media (prefers-color-scheme: light) { + // Product Color Spectrum + $color-product-dark-100: #061B09; + $color-product-dark-200: #072419; + $color-product-dark-300: #0A2E25; + $color-product-dark-400: #1A3D32; + $color-product-dark-500: #224F41; + $color-product-dark-600: #2A604F; + $color-product-dark-700: #8B9C8F; + $color-product-dark-800: #AFBBB0; + $color-product-dark-900: #E7ECE9; + + // Colors for Links and Success + $color-blue200: #B0D9FF; + $color-blue300: #5AB0FF; + $color-green400: #03D47C; + $color-green500: #00a862; + + // Overlay BG color + $color-overlay-background: rgba(26, 61, 50, 0.72); +} // UI Colors $color-text: $color-product-dark-900; From 283c4de6983d0fe856e280d068a2e2b320b329e1 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Tue, 12 Mar 2024 05:23:21 +0530 Subject: [PATCH 118/504] setup theme for helpdot --- docs/_sass/_colors.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/_sass/_colors.scss b/docs/_sass/_colors.scss index c9473925d791..22af28974281 100644 --- a/docs/_sass/_colors.scss +++ b/docs/_sass/_colors.scss @@ -58,3 +58,4 @@ $color-button-background: $color-product-dark-400; $color-button-background-hover: $color-product-dark-500; $color-button-success-background: $color-green400; $color-button-success-background-hover: $color-green500; +$color-overlay: $color-overlay-background; From efaa96a5f02d592032bb7ed48d2850dbd65a5be0 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Tue, 12 Mar 2024 05:23:25 +0530 Subject: [PATCH 119/504] setup theme for helpdot --- docs/_sass/_search-bar.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_sass/_search-bar.scss b/docs/_sass/_search-bar.scss index f414d25fc266..5c58d70b5851 100644 --- a/docs/_sass/_search-bar.scss +++ b/docs/_sass/_search-bar.scss @@ -67,7 +67,7 @@ left: 0; right: 0; bottom: 0; - background-color: $color-overlay-background; + background-color: $color-overlay; z-index: 1; } From a5131ed735744c847d4dd7f5351383a88b61f3b8 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Tue, 12 Mar 2024 03:20:52 +0000 Subject: [PATCH 120/504] refactor(typescript): resolve type issues --- tests/e2e/compare/output/console.ts | 4 +- tests/e2e/compare/output/markdown.ts | 27 ++++++------- tests/e2e/compare/types.ts | 57 ---------------------------- tests/e2e/measure/math.ts | 11 +++++- 4 files changed, 26 insertions(+), 73 deletions(-) delete mode 100644 tests/e2e/compare/types.ts diff --git a/tests/e2e/compare/output/console.ts b/tests/e2e/compare/output/console.ts index de8e5d913893..3da0100b603f 100644 --- a/tests/e2e/compare/output/console.ts +++ b/tests/e2e/compare/output/console.ts @@ -13,6 +13,8 @@ type Entry = { type Data = { significance: Entry[]; meaningless: Entry[]; + errors: string[]; + warnings: string[]; }; const printRegularLine = (entry: Entry) => { @@ -36,4 +38,4 @@ export default (data: Data) => { console.debug(''); }; -export type {Entry}; +export type {Data, Entry}; diff --git a/tests/e2e/compare/output/markdown.ts b/tests/e2e/compare/output/markdown.ts index 07cf9897e570..716dbd6d09a4 100644 --- a/tests/e2e/compare/output/markdown.ts +++ b/tests/e2e/compare/output/markdown.ts @@ -1,16 +1,17 @@ // From: https://raw.githubusercontent.com/callstack/reassure/main/packages/reassure-compare/src/output/markdown.ts import fs from 'node:fs/promises'; import path from 'path'; +import type {Stats} from 'tests/e2e/measure/math'; import * as Logger from '../../utils/logger'; -import type {AddedEntry, CompareEntry, CompareResult, PerformanceEntry, RemovedEntry} from '../types'; +import type {Data, Entry} from './console'; import * as format from './format'; import markdownTable from './markdownTable'; const tableHeader = ['Name', 'Duration']; -const collapsibleSection = (title: string, content: string): string => `
\n${title}\n\n${content}\n
\n\n`; +const collapsibleSection = (title: string, content: string) => `
\n${title}\n\n${content}\n
\n\n`; -const buildDurationDetails = (title: string, entry: PerformanceEntry): string => { +const buildDurationDetails = (title: string, entry: Stats) => { const relativeStdev = entry.stdev / entry.mean; return [ @@ -23,25 +24,25 @@ const buildDurationDetails = (title: string, entry: PerformanceEntry): string => .join('
'); }; -const buildDurationDetailsEntry = (entry: CompareEntry | AddedEntry | RemovedEntry): string => +const buildDurationDetailsEntry = (entry: Entry) => ['baseline' in entry ? buildDurationDetails('Baseline', entry.baseline) : '', 'current' in entry ? buildDurationDetails('Current', entry.current) : ''] .filter(Boolean) .join('

'); -const formatEntryDuration = (entry: CompareEntry | AddedEntry | RemovedEntry): string => { - if ('baseline' in entry && 'current' in entry) { +const formatEntryDuration = (entry: Entry) => { + if (entry.baseline && entry.current) { return format.formatDurationDiffChange(entry); } - if ('baseline' in entry) { + if (entry.baseline) { return format.formatDuration(entry.baseline.mean); } - if ('current' in entry) { + if (entry.current) { return format.formatDuration(entry.current.mean); } return ''; }; -const buildDetailsTable = (entries: Array): string => { +const buildDetailsTable = (entries: Entry[]) => { if (!entries.length) { return ''; } @@ -52,7 +53,7 @@ const buildDetailsTable = (entries: Array, collapse = false): string => { +const buildSummaryTable = (entries: Entry[], collapse = false) => { if (!entries.length) { return '_There are no entries_'; } @@ -63,7 +64,7 @@ const buildSummaryTable = (entries: Array { +const buildMarkdown = (data: Data) => { let result = '## Performance Comparison Report 📊'; if (data.errors?.length) { @@ -91,7 +92,7 @@ const buildMarkdown = (data: CompareResult): string => { return result; }; -const writeToFile = (filePath: string, content: string): Promise => +const writeToFile = (filePath: string, content: string) => fs .writeFile(filePath, content) .then(() => { @@ -105,7 +106,7 @@ const writeToFile = (filePath: string, content: string): Promise => throw error; }); -const writeToMarkdown = (filePath: string, data: CompareResult): Promise => { +const writeToMarkdown = (filePath: string, data: Data) => { const markdown = buildMarkdown(data); return writeToFile(filePath, markdown).catch((error) => { console.error(error); diff --git a/tests/e2e/compare/types.ts b/tests/e2e/compare/types.ts deleted file mode 100644 index e0be36716977..000000000000 --- a/tests/e2e/compare/types.ts +++ /dev/null @@ -1,57 +0,0 @@ -type Entries = number[]; - -/** Metadata information for performance results. */ - -/** Entry in the performance results file. */ -type PerformanceEntry = { - /** Number of times the measurement test was run. */ - runs: number; - - /** Arithmetic average of measured render/execution durations for each run. */ - mean: number; - - /** Standard deviation of measured render/execution durations for each run. */ - stdev: number; - - /** Array of measured render/execution durations for each run. */ - entries: Entries; -}; - -/** - * Compare entry for tests that have both baseline and current entry - */ -type CompareEntry = { - name: string; - current: PerformanceEntry; - baseline: PerformanceEntry; - durationDiff: number; - relativeDurationDiff: number; -}; - -/** - * Compare entry for tests that have only current entry - */ -type AddedEntry = { - name: string; - current: PerformanceEntry; -}; - -/** - * Compare entry for tests that have only baseline entry - */ -type RemovedEntry = { - name: string; - baseline: PerformanceEntry; -}; - -/** Output of compare function. */ -type CompareResult = { - significance: CompareEntry[]; - meaningless: CompareEntry[]; - added: AddedEntry[]; - removed: RemovedEntry[]; - errors?: string[]; - warnings?: string[]; -}; - -export type {Entries, PerformanceEntry, CompareEntry, AddedEntry, RemovedEntry, CompareResult}; diff --git a/tests/e2e/measure/math.ts b/tests/e2e/measure/math.ts index e632e9bec232..d444ab0e79da 100644 --- a/tests/e2e/measure/math.ts +++ b/tests/e2e/measure/math.ts @@ -1,4 +1,11 @@ -import type {Entries, PerformanceEntry} from '../compare/types'; +type Entries = number[]; + +type Stats = { + mean: number; + stdev: number; + runs: number; + entries: Entries; +}; const filterOutliersViaIQR = (data: Entries): Entries => { let q1; @@ -28,7 +35,7 @@ const std = (arr: Entries): number => { return Math.sqrt(arr.map((i) => (i - avg) ** 2).reduce((a, b) => a + b) / arr.length); }; -const getStats = (entries: Entries): PerformanceEntry => { +const getStats = (entries: Entries): Stats => { const cleanedEntries = filterOutliersViaIQR(entries); const meanDuration = mean(cleanedEntries); const stdevDuration = std(cleanedEntries); From 2e4c65f989ce4f835fe19c876e646ad4bf94d2db Mon Sep 17 00:00:00 2001 From: burczu Date: Tue, 12 Mar 2024 10:17:53 +0100 Subject: [PATCH 121/504] transfer balance confirmation copy handled --- src/languages/en.ts | 6 +++ src/languages/es.ts | 6 +++ .../members/WorkspaceMemberDetailsPage.tsx | 2 +- .../members/WorkspaceOwnerChangeCheckPage.tsx | 48 ++++++++++++++++--- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index e096aa091c95..51c3623aaaed 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1967,6 +1967,12 @@ export default { updateCurrencyPrompt: 'It looks like your Workspace is currently set to a different currency than USD. Please click the button below to update your currency to USD now.', updateToUSD: 'Update to USD', }, + changeOwner: { + changeOwnerPageTitle: 'Change owner', + outstandingBalance: 'Outstanding balance', + transferBalance: 'Transfer balance', + transferBalanceFirstParagraph: ({email, amount}) => `The account owing this workspace (${email}) has an outstanding balance.\n\nDo you want to transfer this amount ${amount} in order to take over billing for this workspace? Your payment card will be charged immediately.`, + } }, getAssistancePage: { title: 'Get assistance', diff --git a/src/languages/es.ts b/src/languages/es.ts index 99bb64e0af37..6c5b5c73e589 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1993,6 +1993,12 @@ export default { 'Parece que tu espacio de trabajo está configurado actualmente en una moneda diferente a USD. Por favor, haz clic en el botón de abajo para actualizar tu moneda a USD ahora.', updateToUSD: 'Actualizar a USD', }, + changeOwner: { + changeOwnerPageTitle: 'Cambio de propietario', + outstandingBalance: 'Saldo pendiente', + transferBalance: 'Transfer balance', + transferBalanceFirstParagraph: ({email, amount}) => `La cuenta que debe este espacio de trabajo (${email}) tiene un saldo pendiente.\n\n¿Desea transferir este monto ${amount} para hacerse cargo de la facturación de este espacio de trabajo? El cargo en su tarjeta de pago se realizará inmediatamente.`, + } }, getAssistancePage: { title: 'Obtener ayuda', diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index d12d0235a699..294138c7daa9 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -94,7 +94,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou }, [policyID]); const temporaryOpenCheckPage = () => { - Navigation.navigate(ROUTES.WORKSPACE_OWNER_CHANGE_CHECK.getRoute(policyID, CONST.POLICY.OWNERSHIP_ERRORS.NO_BILLING_CARD)); + Navigation.navigate(ROUTES.WORKSPACE_OWNER_CHANGE_CHECK.getRoute(policyID, CONST.POLICY.OWNERSHIP_ERRORS.AMOUNT_OWED)); }; return ( diff --git a/src/pages/workspace/members/WorkspaceOwnerChangeCheckPage.tsx b/src/pages/workspace/members/WorkspaceOwnerChangeCheckPage.tsx index 8ae4dc5a232a..f1a01366ad9a 100644 --- a/src/pages/workspace/members/WorkspaceOwnerChangeCheckPage.tsx +++ b/src/pages/workspace/members/WorkspaceOwnerChangeCheckPage.tsx @@ -1,5 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useCallback} from 'react'; +import React, {useCallback, useMemo} from 'react'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import Text from '@components/Text'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -9,9 +9,10 @@ import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAcce import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper'; import type SCREENS from '@src/SCREENS'; import CONST from "@src/CONST"; -import Button from "@components/Button"; +import Button from '@components/Button'; import {View} from "react-native"; import useThemeStyles from "@hooks/useThemeStyles"; +import useLocalize from "@hooks/useLocalize"; type WorkspaceMemberDetailsPageProps = StackScreenProps; @@ -24,6 +25,7 @@ const CONFIRMABLE_ERRORS: string[] = [ function WorkspaceOwnerChangeCheckPage({route}: WorkspaceMemberDetailsPageProps) { const styles = useThemeStyles(); + const {translate} = useLocalize(); const policyID = route.params.policyID; const error = route.params.error; @@ -35,29 +37,61 @@ function WorkspaceOwnerChangeCheckPage({route}: WorkspaceMemberDetailsPageProps) }, []); const cancel = useCallback(() => { - + }, []); + const confirmationTitle = useMemo(() => { + switch (error) { + case CONST.POLICY.OWNERSHIP_ERRORS.AMOUNT_OWED: + return translate('workspace.changeOwner.outstandingBalance'); + default: + return null; + } + }, [error, translate]); + + const confirmationButtonText = useMemo(() => { + switch (error) { + case CONST.POLICY.OWNERSHIP_ERRORS.AMOUNT_OWED: + return translate('workspace.changeOwner.transferBalance'); + default: + return ''; + } + }, [error, translate]); + + const confirmationText = useMemo(() => { + switch (error) { + case CONST.POLICY.OWNERSHIP_ERRORS.AMOUNT_OWED: + return translate('workspace.changeOwner.transferBalanceFirstParagraph', {email: 'test@test.com', amount: '$50.00'}); + default: + return null; + } + }, [error, translate]); + return ( Navigation.goBack()} /> - Current error: {error} + {confirmationTitle} + {confirmationText} {shouldAskForConfirmation ? ( + text={confirmationButtonText} + /> ) : ( + text={translate('common.buttonConfirm')} + /> )} From 000491f03e57981cc5a1ba6e7e1643f50458f428 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Tue, 12 Mar 2024 09:49:51 +0000 Subject: [PATCH 122/504] [TS migration][G3] Feedback --- tests/utils/TestHelper.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts index 097433e8813d..10313ad46d47 100644 --- a/tests/utils/TestHelper.ts +++ b/tests/utils/TestHelper.ts @@ -1,12 +1,11 @@ import Str from 'expensify-common/lib/str'; -import type {OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import CONST from '@src/CONST'; import * as Session from '@src/libs/actions/Session'; import HttpUtils from '@src/libs/HttpUtils'; import * as NumberUtils from '@src/libs/NumberUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetails, Report} from '@src/types/onyx'; +import type {Response as OnyxResponse, PersonalDetails, Report} from '@src/types/onyx'; import waitForBatchedUpdates from './waitForBatchedUpdates'; type MockFetch = ReturnType & { @@ -19,14 +18,7 @@ type MockFetch = ReturnType & { resume?: () => Promise; }; -type Response = { - ok?: boolean; - json?: () => Promise<{jsonCode: number}>; - jsonCode?: number; - onyxData?: OnyxUpdate[]; -}; - -type QueueItem = (value: Response | PromiseLike) => void; +type QueueItem = (value: Partial | PromiseLike>) => void; type FormData = { entries: () => Array<[string, string | Blob]>; @@ -58,7 +50,7 @@ function signInWithTestUser(accountID = 1, login = 'test@user.com', password = ' HttpUtils.xhr = jest.fn().mockImplementation(() => { // Your mocked response object - const mockedResponse: Response = { + const mockedResponse: OnyxResponse = { onyxData: [ { onyxMethod: Onyx.METHOD.MERGE, @@ -176,7 +168,7 @@ function getGlobalFetchMock() { let isPaused = false; let shouldFail = false; - const getResponse = () => + const getResponse = (): Partial => shouldFail ? { ok: true, @@ -256,4 +248,4 @@ const createAddListenerMock = () => { return {triggerTransitionEnd, addListener}; }; -export {getGlobalFetchMock, signInWithTestUser, signOutTestUser, setPersonalDetails, buildPersonalDetails, buildTestReportComment, assertFormDataMatchesObject, createAddListenerMock}; +export {assertFormDataMatchesObject, buildPersonalDetails, buildTestReportComment, createAddListenerMock, getGlobalFetchMock, setPersonalDetails, signInWithTestUser, signOutTestUser}; From 1acd6eaca8c525191a4a21f5b75a90132b66326d Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Tue, 12 Mar 2024 10:02:12 +0000 Subject: [PATCH 123/504] [TS migration][storybook] Fixed styling and feedback --- .storybook/webpack.config.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.storybook/webpack.config.ts b/.storybook/webpack.config.ts index 6f7ee023643c..bff8c3fa6747 100644 --- a/.storybook/webpack.config.ts +++ b/.storybook/webpack.config.ts @@ -1,7 +1,5 @@ /* eslint-disable no-underscore-dangle */ - /* eslint-disable no-param-reassign */ - /* eslint-disable @typescript-eslint/naming-convention */ import dotenv from 'dotenv'; import path from 'path'; @@ -18,7 +16,7 @@ type CustomWebpackConfig = { }; }; -let envFile; +let envFile: string | null; switch (process.env.ENV) { case 'production': envFile = '.env.production'; From 075f940a96e195fbb64ea73f825dbf68cc683b1c Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Tue, 12 Mar 2024 11:09:11 +0100 Subject: [PATCH 124/504] fix: adjust descriptions --- src/components/TagPicker/index.tsx | 2 +- src/pages/EditRequestTagPage.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/TagPicker/index.tsx b/src/components/TagPicker/index.tsx index 4998751309ee..f1700205f487 100644 --- a/src/components/TagPicker/index.tsx +++ b/src/components/TagPicker/index.tsx @@ -19,7 +19,7 @@ type SelectedTagOption = { }; type TagPickerOnyxProps = { - /** Collection of tags attached to a policy */ + /** Collection of tag list on a policy */ policyTags: OnyxEntry; /** List of recently used tags */ diff --git a/src/pages/EditRequestTagPage.js b/src/pages/EditRequestTagPage.js index 3eda5184263a..ca5bdc05530d 100644 --- a/src/pages/EditRequestTagPage.js +++ b/src/pages/EditRequestTagPage.js @@ -15,7 +15,7 @@ const propTypes = { /** The policyID we are getting tags for */ policyID: PropTypes.string.isRequired, - /** The tag name to which the default tag belongs to */ + /** The tag list name to which the default tag belongs to */ tagListName: PropTypes.string, /** The index of a tag list */ From fd7802b60ce2ca3348ae8d2a4bc77145777780d9 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Tue, 12 Mar 2024 10:21:44 +0000 Subject: [PATCH 125/504] [TS migration][G3] Feedback --- tests/unit/SidebarTest.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index fd068336d545..499af3031553 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -59,13 +59,13 @@ describe('Sidebar', () => { waitForBatchedUpdates() // When Onyx is updated with the data and the sidebar re-renders .then(() => { - const reportCollection: ReportActionCollectionDataSet = { + const reportCollection: ReportCollectionDataSet = { [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, - } as ReportCollectionDataSet; + } const reportAction: ReportActionCollectionDataSet = { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action}, - } as ReportActionCollectionDataSet; + } as ReportActionCollectionDataSet return Onyx.multiSet({ [ONYXKEYS.BETAS]: betas, @@ -113,11 +113,11 @@ describe('Sidebar', () => { .then(() => { const reportCollection: ReportCollectionDataSet = { [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, - } as ReportCollectionDataSet; + } const reportAction: ReportActionCollectionDataSet = { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action}, - } as ReportActionCollectionDataSet; + } as ReportActionCollectionDataSet return Onyx.multiSet({ [ONYXKEYS.BETAS]: betas, From 1fb509f9469de830ca27b66c644cb97df364c324 Mon Sep 17 00:00:00 2001 From: burczu Date: Tue, 12 Mar 2024 11:28:12 +0100 Subject: [PATCH 126/504] temporary copy added --- src/languages/en.ts | 18 ++++++++-- src/languages/es.ts | 19 +++++++++-- .../members/WorkspaceMemberDetailsPage.tsx | 7 +--- .../members/WorkspaceOwnerChangeCheckPage.tsx | 33 ++++++++++++++++--- 4 files changed, 61 insertions(+), 16 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 51c3623aaaed..37a2cfbd03e6 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1969,9 +1969,21 @@ export default { }, changeOwner: { changeOwnerPageTitle: 'Change owner', - outstandingBalance: 'Outstanding balance', - transferBalance: 'Transfer balance', - transferBalanceFirstParagraph: ({email, amount}) => `The account owing this workspace (${email}) has an outstanding balance.\n\nDo you want to transfer this amount ${amount} in order to take over billing for this workspace? Your payment card will be charged immediately.`, + amountOwedTitle: 'Amount owed title', + amountOwedButtonText: 'Amount owed button text', + amountOwedText: 'Amount owed paragraph text.', + ownerOwesAmountTitle: 'Owner owes amount title', + ownerOwesAmountButtonText: 'Owner owes amount button text', + ownerOwesAmountText: 'Owner owes amount paragraph text.', + subscriptionTitle: 'Subscription title', + subscriptionButtonText: 'Subscription button text', + subscriptionText: 'Subscription paragraph text.', + duplicateSubscriptionTitle: 'Duplicate subscription title', + duplicateSubscriptionButtonText: 'Duplicate subscription button text', + duplicateSubscriptionText: 'Duplicate subscription paragraph text.', + hasFailedSettlementsTitle: 'Has failed settlements title', + hasFailedSettlementsButtonText: 'Has failed settlements button text', + hasFailedSettlementsText: 'Has failed settlements paragraph text.', } }, getAssistancePage: { diff --git a/src/languages/es.ts b/src/languages/es.ts index 6c5b5c73e589..51701d38c501 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1995,9 +1995,22 @@ export default { }, changeOwner: { changeOwnerPageTitle: 'Cambio de propietario', - outstandingBalance: 'Saldo pendiente', - transferBalance: 'Transfer balance', - transferBalanceFirstParagraph: ({email, amount}) => `La cuenta que debe este espacio de trabajo (${email}) tiene un saldo pendiente.\n\n¿Desea transferir este monto ${amount} para hacerse cargo de la facturación de este espacio de trabajo? El cargo en su tarjeta de pago se realizará inmediatamente.`, + // TODO: add spanish translations below + amountOwedTitle: 'Amount owed title', + amountOwedButtonText: 'Amount owed button text', + amountOwedText: 'Amount owed paragraph text.', + ownerOwesAmountTitle: 'Owner owes amount title', + ownerOwesAmountButtonText: 'Owner owes amount button text', + ownerOwesAmountText: 'Owner owes amount paragraph text.', + subscriptionTitle: 'Subscription title', + subscriptionButtonText: 'Subscription button text', + subscriptionText: 'Subscription paragraph text.', + duplicateSubscriptionTitle: 'Duplicate subscription title', + duplicateSubscriptionButtonText: 'Duplicate subscription button text', + duplicateSubscriptionText: 'Duplicate subscription paragraph text.', + hasFailedSettlementTitle: 'Has failed settlement title', + hasFailedSettlementButtonText: 'Has failed settlement button text', + hasFailedSettlementText: 'Has failed settlement paragraph text.', } }, getAssistancePage: { diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index 294138c7daa9..f914d4697a31 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -93,10 +93,6 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou Policy.requestWorkspaceOwnerChange(policyID); }, [policyID]); - const temporaryOpenCheckPage = () => { - Navigation.navigate(ROUTES.WORKSPACE_OWNER_CHANGE_CHECK.getRoute(policyID, CONST.POLICY.OWNERSHIP_ERRORS.AMOUNT_OWED)); - }; - return ( @@ -128,8 +124,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou {isSelectedMemberOwner && isCurrentUserAdmin && !isCurrentUserOwner ? (