diff --git a/.eslintrc.js b/.eslintrc.js index cb1219533278..661a6aa286b9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -289,5 +289,11 @@ module.exports = { 'rulesdir/use-periods-for-error-messages': 'error', }, }, + { + files: ['*.ts', '*.tsx'], + rules: { + 'rulesdir/prefer-at': 'error', + }, + }, ], }; diff --git a/.github/actions/javascript/authorChecklist/authorChecklist.ts b/.github/actions/javascript/authorChecklist/authorChecklist.ts index f855c135cd39..5fdda5cb7285 100644 --- a/.github/actions/javascript/authorChecklist/authorChecklist.ts +++ b/.github/actions/javascript/authorChecklist/authorChecklist.ts @@ -54,7 +54,7 @@ function partitionWithChecklist(body: string): string[] { async function getNumberOfItemsFromAuthorChecklist(): Promise { const response = await fetch(pathToAuthorChecklist); const fileContents = await response.text(); - const checklist = partitionWithChecklist(fileContents)[1]; + const checklist = partitionWithChecklist(fileContents).at(1); const numberOfChecklistItems = (checklist.match(/\[ \]/g) ?? []).length; return numberOfChecklistItems; } diff --git a/.github/actions/javascript/createOrUpdateStagingDeploy/createOrUpdateStagingDeploy.ts b/.github/actions/javascript/createOrUpdateStagingDeploy/createOrUpdateStagingDeploy.ts index caff455e9fa5..ff6c94ae7930 100644 --- a/.github/actions/javascript/createOrUpdateStagingDeploy/createOrUpdateStagingDeploy.ts +++ b/.github/actions/javascript/createOrUpdateStagingDeploy/createOrUpdateStagingDeploy.ts @@ -29,9 +29,9 @@ async function run(): Promise { // Look at the state of the most recent StagingDeployCash, // if it is open then we'll update the existing one, otherwise, we'll create a new one. - const mostRecentChecklist = recentDeployChecklists[0]; + const mostRecentChecklist = recentDeployChecklists.at(0); const shouldCreateNewDeployChecklist = mostRecentChecklist.state !== 'open'; - const previousChecklist = shouldCreateNewDeployChecklist ? mostRecentChecklist : recentDeployChecklists[1]; + const previousChecklist = shouldCreateNewDeployChecklist ? mostRecentChecklist : recentDeployChecklists.at(1); if (shouldCreateNewDeployChecklist) { console.log('Latest StagingDeployCash is closed, creating a new one.', mostRecentChecklist); } else { diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts index 71a5c7d5c6ee..79d278b001c4 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts +++ b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts @@ -78,7 +78,7 @@ async function run() { labels: CONST.LABELS.STAGING_DEPLOY, state: 'closed', }); - const previousChecklistID = deployChecklists[0].number; + const previousChecklistID = deployChecklists.at(0).number; // who closed the last deploy checklist? const deployer = await GithubUtils.getActorWhoClosedIssue(previousChecklistID); diff --git a/.github/actions/javascript/proposalPoliceComment/proposalPoliceComment.ts b/.github/actions/javascript/proposalPoliceComment/proposalPoliceComment.ts index fa18ae833768..575deaadbadf 100644 --- a/.github/actions/javascript/proposalPoliceComment/proposalPoliceComment.ts +++ b/.github/actions/javascript/proposalPoliceComment/proposalPoliceComment.ts @@ -62,7 +62,7 @@ async function run() { if (assistantResponse.includes(`[${CONST.NO_ACTION}]`)) { // extract the text after [NO_ACTION] from assistantResponse since this is a // bot related action keyword - const noActionContext = assistantResponse.split(`[${CONST.NO_ACTION}] `)?.[1]?.replace('"', ''); + const noActionContext = assistantResponse.split(`[${CONST.NO_ACTION}] `).at(1)?.replace('"', ''); console.log('[NO_ACTION] w/ context: ', noActionContext); return; } @@ -86,10 +86,10 @@ async function run() { } else if (assistantResponse.includes('[EDIT_COMMENT]') && !payload.comment?.body.includes('Edited by **proposal-police**')) { // extract the text after [EDIT_COMMENT] from assistantResponse since this is a // bot related action keyword - let extractedNotice = assistantResponse.split('[EDIT_COMMENT] ')?.[1]?.replace('"', ''); + let extractedNotice = assistantResponse.split('[EDIT_COMMENT] ').at(1)?.replace('"', ''); // format the github's updated_at like: 2024-01-24 13:15:24 UTC not 2024-01-28 18:18:28.000 UTC const date = new Date(payload.comment?.updated_at ?? ''); - const formattedDate = `${date.toISOString()?.split('.')?.[0]?.replace('T', ' ')} UTC`; + const formattedDate = `${date.toISOString()?.split('.').at(0)?.replace('T', ' ')} UTC`; extractedNotice = extractedNotice.replace('{updated_timestamp}', formattedDate); console.log('ProposalPoliceā„¢ editing issue comment...', payload.comment.id); await GithubUtils.octokit.issues.updateComment({ diff --git a/.github/actions/javascript/reviewerChecklist/reviewerChecklist.ts b/.github/actions/javascript/reviewerChecklist/reviewerChecklist.ts index f57ef6c36a04..336055271330 100644 --- a/.github/actions/javascript/reviewerChecklist/reviewerChecklist.ts +++ b/.github/actions/javascript/reviewerChecklist/reviewerChecklist.ts @@ -55,7 +55,7 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems: number) { } const whitespace = /([\n\r])/gm; - const comment = combinedComments[i].replace(whitespace, ''); + const comment = combinedComments.at(i).replace(whitespace, ''); console.log(`Comment ${i} starts with: ${comment.slice(0, 20)}...`); diff --git a/.github/actions/javascript/validateReassureOutput/validateReassureOutput.ts b/.github/actions/javascript/validateReassureOutput/validateReassureOutput.ts index d843caf61518..d6b7f2c61b55 100644 --- a/.github/actions/javascript/validateReassureOutput/validateReassureOutput.ts +++ b/.github/actions/javascript/validateReassureOutput/validateReassureOutput.ts @@ -15,7 +15,7 @@ const run = (): boolean => { console.log(`Processing ${regressionOutput.countChanged.length} measurements...`); for (let i = 0; i < regressionOutput.countChanged.length; i++) { - const measurement = regressionOutput.countChanged[i]; + const measurement = regressionOutput.countChanged.at(i); const baseline: PerformanceEntry = measurement.baseline; const current: PerformanceEntry = measurement.current; diff --git a/.github/libs/GithubUtils.ts b/.github/libs/GithubUtils.ts index 36363684a351..eae037e30e5c 100644 --- a/.github/libs/GithubUtils.ts +++ b/.github/libs/GithubUtils.ts @@ -168,7 +168,7 @@ class GithubUtils { throw new Error(`Found more than one ${CONST.LABELS.STAGING_DEPLOY} issue.`); } - return this.getStagingDeployCashData(data[0]); + return this.getStagingDeployCashData(data.at(0)); }); } @@ -254,7 +254,7 @@ class GithubUtils { } internalQASection = internalQASection[1]; const internalQAPRs = [...internalQASection.matchAll(new RegExp(`- \\[([ x])]\\s(${CONST.PULL_REQUEST_REGEX.source})`, 'g'))].map((match) => ({ - url: match[2].split('-')[0].trim(), + url: match[2].split('-').at(0).trim(), number: Number.parseInt(match[3], 10), isResolved: match[1] === 'x', })); @@ -367,7 +367,7 @@ class GithubUtils { * Fetch all pull requests given a list of PR numbers. */ static fetchAllPullRequests(pullRequestNumbers: number[]): Promise { - const oldestPR = pullRequestNumbers.sort((a, b) => a - b)[0]; + const oldestPR = pullRequestNumbers.sort((a, b) => a - b).at(0); return this.paginate( this.octokit.pulls.list, { @@ -459,7 +459,7 @@ class GithubUtils { repo: CONST.APP_REPO, workflow_id: workflow, }) - .then((response) => response.data.workflow_runs[0]?.id); + .then((response) => response.data.workflow_runs.at(0)?.id); } /** @@ -533,7 +533,7 @@ class GithubUtils { per_page: 1, name: artifactName, }) - .then((response) => response.data.artifacts[0]); + .then((response) => response.data.artifacts.at(0)); } /** diff --git a/.github/libs/nativeVersionUpdater.ts b/.github/libs/nativeVersionUpdater.ts index 4ecf9d64966c..1684614b059e 100644 --- a/.github/libs/nativeVersionUpdater.ts +++ b/.github/libs/nativeVersionUpdater.ts @@ -59,7 +59,7 @@ function updateAndroidVersion(versionName: string, versionCode: string): Promise * Updates the CFBundleShortVersionString and the CFBundleVersion. */ function updateiOSVersion(version: string): string { - const shortVersion = version.split('-')[0]; + const shortVersion = version.split('-').at(0); const cfVersion = version.includes('-') ? version.replace('-', '.') : `${version}.0`; console.log('Updating iOS', `CFBundleShortVersionString: ${shortVersion}`, `CFBundleVersion: ${cfVersion}`); diff --git a/.github/scripts/createDocsRoutes.ts b/.github/scripts/createDocsRoutes.ts index a8ac3d511ff9..b61a1a44775c 100644 --- a/.github/scripts/createDocsRoutes.ts +++ b/.github/scripts/createDocsRoutes.ts @@ -93,7 +93,7 @@ function pushOrCreateEntry(hubs: Hub[], hub: string, } function getOrderFromArticleFrontMatter(path: string): number | undefined { - const frontmatter = fs.readFileSync(path, 'utf8').split('---')[1]; + const frontmatter = fs.readFileSync(path, 'utf8').split('---').at(1); const frontmatterObject = yaml.load(frontmatter) as Record; return frontmatterObject.order as number | undefined; } diff --git a/.storybook/webpack.config.ts b/.storybook/webpack.config.ts index 0aa38f2e3b82..20776f7c8082 100644 --- a/.storybook/webpack.config.ts +++ b/.storybook/webpack.config.ts @@ -67,8 +67,8 @@ const webpackConfig = ({config}: {config: Configuration}) => { // 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 (definePluginIndex !== -1 && config.plugins.at(definePluginIndex) instanceof DefinePlugin) { + const definePlugin = config.plugins.at(definePluginIndex) as DefinePlugin; if (definePlugin.definitions) { definePlugin.definitions.__REACT_WEB_CONFIG__ = JSON.stringify(env); } @@ -76,7 +76,7 @@ const webpackConfig = ({config}: {config: Configuration}) => { config.resolve.extensions = custom.resolve.extensions; const babelRulesIndex = custom.module.rules.findIndex((rule) => rule.loader === 'babel-loader'); - const babelRule = custom.module.rules[babelRulesIndex]; + const babelRule = custom.module.rules.at(babelRulesIndex); if (babelRule) { config.module.rules?.push(babelRule); } diff --git a/android/app/build.gradle b/android/app/build.gradle index 7309e57b1579..54429478889f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -108,8 +108,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled rootProject.ext.multiDexEnabled - versionCode 1009002100 - versionName "9.0.21-0" + versionCode 1009002006 + versionName "9.0.20-6" // Supported language variants must be declared here to avoid from being removed during the compilation. // This also helps us to not include unnecessary language variants in the APK. resConfigs "en", "es" diff --git a/assets/emojis/index.ts b/assets/emojis/index.ts index d230e8eec2be..4b05c8caddfa 100644 --- a/assets/emojis/index.ts +++ b/assets/emojis/index.ts @@ -33,7 +33,7 @@ const localeEmojis: LocaleEmojis = { }; const importEmojiLocale = (locale: Locale) => { - const normalizedLocale = locale.toLowerCase().split('-')[0] as Locale; + const normalizedLocale = locale.toLowerCase().split('-').at(0) as Locale; if (!localeEmojis[normalizedLocale]) { const emojiImportPromise = normalizedLocale === 'en' ? import('./en') : import('./es'); return emojiImportPromise.then((esEmojiModule) => { diff --git a/config/webpack/webpack.common.ts b/config/webpack/webpack.common.ts index 33fd9131eca0..3bc94224fc62 100644 --- a/config/webpack/webpack.common.ts +++ b/config/webpack/webpack.common.ts @@ -47,7 +47,7 @@ const environmentToLogoSuffixMap: Record = { }; function mapEnvironmentToLogoSuffix(environmentFile: string): string { - let environment = environmentFile.split('.')[2]; + let environment = environmentFile.split('.').at(2); if (typeof environment === 'undefined') { environment = 'dev'; } diff --git a/ios/NewExpensify/Info.plist b/ios/NewExpensify/Info.plist index 345af337154b..1bad0f3ab185 100644 --- a/ios/NewExpensify/Info.plist +++ b/ios/NewExpensify/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 9.0.21 + 9.0.20 CFBundleSignature ???? CFBundleURLTypes @@ -40,7 +40,7 @@ CFBundleVersion - 9.0.21.0 + 9.0.20.6 FullStory OrgId diff --git a/ios/NewExpensifyTests/Info.plist b/ios/NewExpensifyTests/Info.plist index b1d3b4e29036..53d9544bfa05 100644 --- a/ios/NewExpensifyTests/Info.plist +++ b/ios/NewExpensifyTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 9.0.21 + 9.0.20 CFBundleSignature ???? CFBundleVersion - 9.0.21.0 + 9.0.20.6 diff --git a/ios/NotificationServiceExtension/Info.plist b/ios/NotificationServiceExtension/Info.plist index adc814f6be99..29db10f90aea 100644 --- a/ios/NotificationServiceExtension/Info.plist +++ b/ios/NotificationServiceExtension/Info.plist @@ -11,9 +11,9 @@ CFBundleName $(PRODUCT_NAME) CFBundleShortVersionString - 9.0.21 + 9.0.20 CFBundleVersion - 9.0.21.0 + 9.0.20.6 NSExtension NSExtensionPointIdentifier diff --git a/jest/setup.ts b/jest/setup.ts index 19e20a6d0395..0308d021db84 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -34,7 +34,7 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({ // Turn off the console logs for timing events. They are not relevant for unit tests and create a lot of noise jest.spyOn(console, 'debug').mockImplementation((...params: string[]) => { - if (params[0].startsWith('Timing:')) { + if (params.at(0).startsWith('Timing:')) { return; } diff --git a/package-lock.json b/package-lock.json index cfb22a421d02..8069c8062ce8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "new.expensify", - "version": "9.0.21-0", + "version": "9.0.20-6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "new.expensify", - "version": "9.0.21-0", + "version": "9.0.20-6", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -217,7 +217,7 @@ "electron-builder": "25.0.0", "eslint": "^8.57.0", "eslint-config-airbnb-typescript": "^18.0.0", - "eslint-config-expensify": "^2.0.58", + "eslint-config-expensify": "^2.0.56", "eslint-config-prettier": "^9.1.0", "eslint-plugin-jest": "^28.6.0", "eslint-plugin-jsdoc": "^46.2.6", diff --git a/package.json b/package.json index c8a3968ad6c0..97c44a52a690 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "new.expensify", - "version": "9.0.21-0", + "version": "9.0.20-6", "author": "Expensify, Inc.", "homepage": "https://new.expensify.com", "description": "New Expensify is the next generation of Expensify: a reimagination of payments based atop a foundation of chat.", @@ -273,7 +273,7 @@ "electron-builder": "25.0.0", "eslint": "^8.57.0", "eslint-config-airbnb-typescript": "^18.0.0", - "eslint-config-expensify": "^2.0.58", + "eslint-config-expensify": "^2.0.56", "eslint-config-prettier": "^9.1.0", "eslint-plugin-jest": "^28.6.0", "eslint-plugin-jsdoc": "^46.2.6", diff --git a/scripts/release-profile.ts b/scripts/release-profile.ts index a83fb55fa5ff..615f009d743d 100755 --- a/scripts/release-profile.ts +++ b/scripts/release-profile.ts @@ -36,7 +36,7 @@ if (cpuProfiles.length === 0) { process.exit(1); } else { // Construct the command - const cpuprofileName = cpuProfiles[0]; + const cpuprofileName = cpuProfiles.at(0); const command = `npx react-native-release-profiler --local "${cpuprofileName}" --sourcemap-path "${sourcemapPath}"`; console.log(`Executing: ${command}`); diff --git a/src/components/AddPlaidBankAccount.tsx b/src/components/AddPlaidBankAccount.tsx index 4de286183ea8..11b0010ed253 100644 --- a/src/components/AddPlaidBankAccount.tsx +++ b/src/components/AddPlaidBankAccount.tsx @@ -173,7 +173,7 @@ function AddPlaidBankAccount({ const {icon, iconSize, iconStyles} = getBankIcon({styles}); const plaidErrors = plaidData?.errors; // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style - const plaidDataErrorMessage = !isEmptyObject(plaidErrors) ? (Object.values(plaidErrors)[0] as string) : ''; + const plaidDataErrorMessage = !isEmptyObject(plaidErrors) ? (Object.values(plaidErrors).at(0) as string) : ''; const bankName = plaidData?.bankName; /** diff --git a/src/components/AttachmentPicker/index.native.tsx b/src/components/AttachmentPicker/index.native.tsx index edcdabed9101..e6d6108d4016 100644 --- a/src/components/AttachmentPicker/index.native.tsx +++ b/src/components/AttachmentPicker/index.native.tsx @@ -177,7 +177,10 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s const uri = manipResult.uri; const convertedAsset = { uri, - name: uri.substring(uri.lastIndexOf('/') + 1).split('?')[0], + name: uri + .substring(uri.lastIndexOf('/') + 1) + .split('?') + .at(0), type: 'image/jpeg', width: manipResult.width, height: manipResult.height, @@ -363,7 +366,7 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s if (focusedIndex === -1) { return; } - selectItem(menuItemData[focusedIndex]); + selectItem(menuItemData.at(focusedIndex)); setFocusedIndex(-1); // Reset the focusedIndex on selecting any menu }, { diff --git a/src/components/Attachments/AttachmentCarousel/index.native.tsx b/src/components/Attachments/AttachmentCarousel/index.native.tsx index e0f7571af8c7..37be97ce660d 100644 --- a/src/components/Attachments/AttachmentCarousel/index.native.tsx +++ b/src/components/Attachments/AttachmentCarousel/index.native.tsx @@ -53,8 +53,8 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source, } // Update the parent modal's state with the source and name from the mapped attachments - if (targetAttachments[initialPage] !== undefined && onNavigate) { - onNavigate(targetAttachments[initialPage]); + if (targetAttachments.at(initialPage) !== undefined && onNavigate) { + onNavigate(targetAttachments.at(initialPage)); } } // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps @@ -66,7 +66,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source, Keyboard.dismiss(); setShouldShowArrows(true); - const item = attachments[newPageIndex]; + const item = attachments.at(newPageIndex); setPage(newPageIndex); setActiveSource(item.source); diff --git a/src/components/Attachments/AttachmentCarousel/index.tsx b/src/components/Attachments/AttachmentCarousel/index.tsx index f7ef2c6529ce..410527157ab1 100644 --- a/src/components/Attachments/AttachmentCarousel/index.tsx +++ b/src/components/Attachments/AttachmentCarousel/index.tsx @@ -101,8 +101,8 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source, } // Update the parent modal's state with the source and name from the mapped attachments - if (targetAttachments[initialPage] !== undefined && onNavigate) { - onNavigate(targetAttachments[initialPage]); + if (targetAttachments.at(initialPage) !== undefined && onNavigate) { + onNavigate(targetAttachments.at(initialPage)); } } }, [report.privateNotes, reportActions, parentReportActions, compareImage, report.parentReportActionID, attachments, setDownloadButtonVisibility, onNavigate, accountID, type]); @@ -129,7 +129,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source, // Since we can have only one item in view at a time, we can use the first item in the array // to get the index of the current page - const entry = viewableItems[0]; + const entry = viewableItems.at(0); if (!entry) { setActiveSource(null); return; @@ -156,7 +156,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source, } const nextIndex = page + deltaSlide; - const nextItem = attachments[nextIndex]; + const nextItem = attachments.at(nextIndex); if (!nextItem || !scrollRef.current) { return; diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.tsx b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.tsx index 8c4af3275bd8..4114f879f638 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.tsx +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.tsx @@ -33,8 +33,8 @@ function AttachmentViewPdf(props: AttachmentViewPdfProps) { .manualActivation(true) .onTouchesMove((evt) => { if (offsetX.value !== 0 && offsetY.value !== 0 && isScrollEnabled) { - const translateX = Math.abs(evt.allTouches[0].absoluteX - offsetX.value); - const translateY = Math.abs(evt.allTouches[0].absoluteY - offsetY.value); + const translateX = Math.abs(evt.allTouches.at(0).absoluteX - offsetX.value); + const translateY = Math.abs(evt.allTouches.at(0).absoluteY - offsetY.value); const allowEnablingScroll = !isPanGestureActive.value || isScrollEnabled.value; // if the value of X is greater than Y and the pdf is not zoomed in, @@ -49,8 +49,8 @@ function AttachmentViewPdf(props: AttachmentViewPdfProps) { } isPanGestureActive.value = true; - offsetX.value = evt.allTouches[0].absoluteX; - offsetY.value = evt.allTouches[0].absoluteY; + offsetX.value = evt.allTouches.at(0).absoluteX; + offsetY.value = evt.allTouches.at(0).absoluteY; }) .onTouchesUp(() => { isPanGestureActive.value = false; diff --git a/src/components/AvatarWithDisplayName.tsx b/src/components/AvatarWithDisplayName.tsx index 2ccdd47c3205..1ba1a6158505 100644 --- a/src/components/AvatarWithDisplayName.tsx +++ b/src/components/AvatarWithDisplayName.tsx @@ -121,8 +121,8 @@ function AvatarWithDisplayName({ {shouldShowSubscriptAvatar ? ( ) : ( diff --git a/src/components/ButtonWithDropdownMenu/index.tsx b/src/components/ButtonWithDropdownMenu/index.tsx index 943d6dbb5c16..bc432e66d232 100644 --- a/src/components/ButtonWithDropdownMenu/index.tsx +++ b/src/components/ButtonWithDropdownMenu/index.tsx @@ -50,7 +50,7 @@ function ButtonWithDropdownMenu({ const {windowWidth, windowHeight} = useWindowDimensions(); const dropdownAnchor = useRef(null); const dropdownButtonRef = isSplitButton ? buttonRef : mergeRefs(buttonRef, dropdownAnchor); - const selectedItem = options[selectedItemIndex] || options[0]; + const selectedItem = options.at(selectedItemIndex) ?? options.at(0); const innerStyleDropButton = StyleUtils.getDropDownButtonHeight(buttonSize); const isButtonSizeLarge = buttonSize === CONST.DROPDOWN_BUTTON_SIZE.LARGE; const nullCheckRef = (ref: MutableRefObject) => ref ?? null; @@ -85,7 +85,7 @@ function ButtonWithDropdownMenu({ } onPress(e, selectedItem?.value); } else { - onPress(e, options[0]?.value); + onPress(e, options.at(0)?.value); } }, { @@ -150,11 +150,11 @@ function ButtonWithDropdownMenu({ success={success} ref={buttonRef} pressOnEnter={pressOnEnter} - isDisabled={isDisabled || !!options[0].disabled} + isDisabled={isDisabled || !!options.at(0).disabled} style={[styles.w100, style]} isLoading={isLoading} text={selectedItem.text} - onPress={(event) => onPress(event, options[0].value)} + onPress={(event) => onPress(event, options.at(0).value)} large={isButtonSizeLarge} medium={!isButtonSizeLarge} innerStyles={[innerStyleDropButton]} diff --git a/src/components/CategoryPicker.tsx b/src/components/CategoryPicker.tsx index e5c85a8f5f6d..2b9ae25d2fca 100644 --- a/src/components/CategoryPicker.tsx +++ b/src/components/CategoryPicker.tsx @@ -62,7 +62,7 @@ function CategoryPicker({selectedCategory, policyCategories, policyRecentlyUsedC false, ); - const categoryData = categoryOptions?.[0]?.data ?? []; + const categoryData = categoryOptions.at(0)?.data ?? []; const header = OptionsListUtils.getHeaderMessageForNonUserList(categoryData.length > 0, debouncedSearchValue); const categoriesCount = OptionsListUtils.getEnabledCategoriesCount(categories); const isCategoriesCountBelowThreshold = categoriesCount < CONST.CATEGORY_LIST_THRESHOLD; @@ -71,7 +71,7 @@ function CategoryPicker({selectedCategory, policyCategories, policyRecentlyUsedC return [categoryOptions, header, showInput]; }, [policyRecentlyUsedCategories, debouncedSearchValue, selectedOptions, policyCategories, policyCategoriesDraft]); - const selectedOptionKey = useMemo(() => (sections?.[0]?.data ?? []).filter((category) => category.searchText === selectedCategory)[0]?.keyForList, [sections, selectedCategory]); + const selectedOptionKey = useMemo(() => (sections.at(0)?.data ?? []).filter((category) => category.searchText === selectedCategory).at(0)?.keyForList, [sections, selectedCategory]); return ( ) => { - const clipboardContent = e.nativeEvent.items[0]; + const clipboardContent = e.nativeEvent.items.at(0); if (clipboardContent.type === 'text/plain') { return; } diff --git a/src/components/ConfirmedRoute.tsx b/src/components/ConfirmedRoute.tsx index 315afd2dbddc..b6fa5e54db02 100644 --- a/src/components/ConfirmedRoute.tsx +++ b/src/components/ConfirmedRoute.tsx @@ -112,7 +112,7 @@ function ConfirmedRoute({mapboxAccessToken, transaction, isSmallerIcon, shouldHa pitchEnabled={false} initialState={{ zoom: CONST.MAPBOX.DEFAULT_ZOOM, - location: waypointMarkers?.[0]?.coordinate ?? (CONST.MAPBOX.DEFAULT_COORDINATE as [number, number]), + location: waypointMarkers.at(0)?.coordinate ?? (CONST.MAPBOX.DEFAULT_COORDINATE as [number, number]), }} directionCoordinates={coordinates as Array<[number, number]>} style={[styles.mapView, shouldHaveBorderRadius && styles.br4]} diff --git a/src/components/DatePicker/CalendarPicker/generateMonthMatrix.ts b/src/components/DatePicker/CalendarPicker/generateMonthMatrix.ts index 21e7ff752794..5fc03cba8656 100644 --- a/src/components/DatePicker/CalendarPicker/generateMonthMatrix.ts +++ b/src/components/DatePicker/CalendarPicker/generateMonthMatrix.ts @@ -51,8 +51,8 @@ export default function generateMonthMatrix(year: number, month: number) { } // Add null values for days before the first day of the month - for (let i = matrix[0].length; i < 7; i++) { - matrix[0].unshift(undefined); + for (let i = matrix.at(0).length; i < 7; i++) { + matrix.at(0).unshift(undefined); } return matrix; diff --git a/src/components/DatePicker/CalendarPicker/index.tsx b/src/components/DatePicker/CalendarPicker/index.tsx index 533586d4bdbf..69abb8f13073 100644 --- a/src/components/DatePicker/CalendarPicker/index.tsx +++ b/src/components/DatePicker/CalendarPicker/index.tsx @@ -170,7 +170,7 @@ function CalendarPicker({ testID="currentMonthText" accessibilityLabel={translate('common.currentMonth')} > - {monthNames[currentMonthView]} + {monthNames.at(currentMonthView)} diff --git a/src/components/DisplayNames/DisplayNamesWithTooltip.tsx b/src/components/DisplayNames/DisplayNamesWithTooltip.tsx index 0b0c3ddf27ca..2d3801733c73 100644 --- a/src/components/DisplayNames/DisplayNamesWithTooltip.tsx +++ b/src/components/DisplayNames/DisplayNamesWithTooltip.tsx @@ -31,13 +31,13 @@ function DisplayNamesWithToolTip({shouldUseFullTitle, fullTitle, displayNamesWit */ const getTooltipShiftX = useCallback((index: number) => { // Only shift the tooltip in case the containerLayout or Refs to the text node are available - if (!containerRef.current || !childRefs.current[index]) { + if (!containerRef.current || !childRefs.current.at(index)) { return 0; } const {width: containerWidth, left: containerLeft} = containerRef.current.getBoundingClientRect(); // We have to return the value as Number so we can't use `measureWindow` which takes a callback - const {width: textNodeWidth, left: textNodeLeft} = childRefs.current[index].getBoundingClientRect(); + const {width: textNodeWidth, left: textNodeLeft} = childRefs.current.at(index).getBoundingClientRect(); const tooltipX = textNodeWidth / 2 + textNodeLeft; const containerRight = containerWidth + containerLeft; const textNodeRight = textNodeWidth + textNodeLeft; diff --git a/src/components/DistanceRequest/DistanceRequestFooter.tsx b/src/components/DistanceRequest/DistanceRequestFooter.tsx index 43dd88f6e36c..f2cd79c1a013 100644 --- a/src/components/DistanceRequest/DistanceRequestFooter.tsx +++ b/src/components/DistanceRequest/DistanceRequestFooter.tsx @@ -107,7 +107,7 @@ function DistanceRequestFooter({waypoints, transaction, mapboxAccessToken, navig pitchEnabled={false} initialState={{ zoom: CONST.MAPBOX.DEFAULT_ZOOM, - location: waypointMarkers?.[0]?.coordinate ?? (CONST.MAPBOX.DEFAULT_COORDINATE as [number, number]), + location: waypointMarkers.at(0)?.coordinate ?? (CONST.MAPBOX.DEFAULT_COORDINATE as [number, number]), }} directionCoordinates={(transaction?.routes?.route0?.geometry?.coordinates as Array<[number, number]>) ?? []} style={[styles.mapView, styles.mapEditView]} diff --git a/src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx b/src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx index b5b4c2d7e71c..ef7ba482ceac 100644 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx @@ -96,7 +96,7 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r ); } - const emojiCode = typeof preferredSkinTone === 'number' && types?.[preferredSkinTone] ? types?.[preferredSkinTone] : code; + const emojiCode = typeof preferredSkinTone === 'number' && types?.[preferredSkinTone] ? types.at(preferredSkinTone) : code; const shouldEmojiBeHighlighted = !!activeEmoji && EmojiUtils.getRemovedSkinToneEmoji(emojiCode) === EmojiUtils.getRemovedSkinToneEmoji(activeEmoji); return ( diff --git a/src/components/EmojiPicker/EmojiPickerMenu/index.tsx b/src/components/EmojiPicker/EmojiPickerMenu/index.tsx index 5a59585ad72e..31bd8933f1bd 100755 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.tsx +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.tsx @@ -148,12 +148,12 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r indexToSelect = 0; } - const item = filteredEmojis[indexToSelect]; + const item = filteredEmojis.at(indexToSelect); if (!item) { return; } if ('types' in item || 'name' in item) { - const emoji = typeof preferredSkinTone === 'number' && item?.types?.[preferredSkinTone] ? item?.types?.[preferredSkinTone] : item.code; + const emoji = typeof preferredSkinTone === 'number' && item?.types?.[preferredSkinTone] ? item?.types.at(preferredSkinTone) : item.code; onEmojiSelected(emoji, item); } // On web, avoid this Enter default input action; otherwise, it will add a new line in the subsequently focused composer. @@ -257,7 +257,7 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r ); } - const emojiCode = typeof preferredSkinTone === 'number' && types?.[preferredSkinTone] ? types[preferredSkinTone] : code; + const emojiCode = typeof preferredSkinTone === 'number' && types?.[preferredSkinTone] ? types.at(preferredSkinTone) : code; const isEmojiFocused = index === focusedIndex && isUsingKeyboardMovement; const shouldEmojiBeHighlighted = diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.tsx index 7892d8624699..d36e13ab0136 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.tsx @@ -23,7 +23,7 @@ function AnchorRenderer({tnode, style, key}: AnchorRendererProps) { const {environmentURL} = useEnvironment(); // An auth token is needed to download Expensify chat attachments const isAttachment = !!htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]; - const tNodeChild = tnode?.domNode?.children?.[0]; + const tNodeChild = tnode?.domNode?.children.at(0); const displayName = tNodeChild && 'data' in tNodeChild && typeof tNodeChild.data === 'string' ? tNodeChild.data : ''; const parentStyle = tnode.parent?.styles?.nativeTextRet ?? {}; const attrHref = htmlAttribs.href || htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE] || ''; diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx index ffab2434c83c..8d8da136a5d7 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx @@ -53,7 +53,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona } // Otherwise, the emails must be of the same private domain, so we should remove the domain part - return displayText.split('@')[0]; + return displayText.split('@').at(0); }; if (!isEmpty(htmlAttribAccountID)) { @@ -68,7 +68,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona // We need to replace tnode.data here because we will pass it to TNodeChildrenRenderer below asMutable(tnodeClone).data = tnodeClone.data.replace(mentionDisplayText, Str.removeSMSDomain(getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID))); - accountID = PersonalDetailsUtils.getAccountIDsByLogins([mentionDisplayText])?.[0]; + accountID = PersonalDetailsUtils.getAccountIDsByLogins([mentionDisplayText]).at(0); navigationRoute = ROUTES.PROFILE.getRoute(accountID, undefined, mentionDisplayText); mentionDisplayText = Str.removeSMSDomain(mentionDisplayText); } else { diff --git a/src/components/InlineCodeBlock/WrappedText.tsx b/src/components/InlineCodeBlock/WrappedText.tsx index 3045c15c471b..00ab8ec20906 100644 --- a/src/components/InlineCodeBlock/WrappedText.tsx +++ b/src/components/InlineCodeBlock/WrappedText.tsx @@ -52,7 +52,7 @@ function WrappedText({children, wordStyles, textStyles}: WrappedTextProps) { return textMatrix.map((rowText, rowIndex) => ( {rowText.map((colText, colIndex) => ( // Outer View is important to vertically center the Text diff --git a/src/components/InteractiveStepSubHeader.tsx b/src/components/InteractiveStepSubHeader.tsx index d8899a317df5..adb569a9719d 100644 --- a/src/components/InteractiveStepSubHeader.tsx +++ b/src/components/InteractiveStepSubHeader.tsx @@ -70,7 +70,7 @@ function InteractiveStepSubHeader({stepNames, startStepIndex = 0, onStepSelected return; } setCurrentStep(index); - onStepSelected(stepNames[index]); + onStepSelected(stepNames.at(index)); }; return ( diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index b35b14016235..e98b3e116a7e 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -138,7 +138,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio const itemTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; const hasDraftComment = DraftCommentUtils.isValidDraftComment(draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`]); const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(itemReportActions); - const lastReportAction = sortedReportActions[0]; + const lastReportAction = sortedReportActions.at(0); // Get the transaction for the last report action let lastReportActionTransactionID = ''; diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index cee949133eb2..15786d275ddc 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -192,8 +192,8 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti (optionItem.shouldShowSubscript ? ( ) : ( diff --git a/src/components/MagicCodeInput.tsx b/src/components/MagicCodeInput.tsx index 79c2445f7ae7..bcd9b8295f4f 100644 --- a/src/components/MagicCodeInput.tsx +++ b/src/components/MagicCodeInput.tsx @@ -276,7 +276,7 @@ function MagicCodeInput( if (isDisableKeyboard && focusedIndex === undefined) { const indexBeforeLastEditIndex = editIndex === 0 ? editIndex : editIndex - 1; - const indexToFocus = numbers[editIndex] === CONST.MAGIC_CODE_EMPTY_CHAR ? indexBeforeLastEditIndex : editIndex; + const indexToFocus = numbers.at(editIndex) === CONST.MAGIC_CODE_EMPTY_CHAR ? indexBeforeLastEditIndex : editIndex; const formElement = inputRefs.current as HTMLFormElement | null; (formElement?.[indexToFocus] as HTMLInputElement)?.focus(); onChangeTextProp(value.substring(0, indexToFocus)); @@ -286,7 +286,7 @@ function MagicCodeInput( // If the currently focused index already has a value, it will delete // that value but maintain the focus on the same input. - if (focusedIndex !== undefined && numbers?.[focusedIndex] !== CONST.MAGIC_CODE_EMPTY_CHAR) { + if (focusedIndex !== undefined && numbers.at(focusedIndex) !== CONST.MAGIC_CODE_EMPTY_CHAR) { setInput(TEXT_INPUT_EMPTY_STATE); numbers = [...numbers.slice(0, focusedIndex), CONST.MAGIC_CODE_EMPTY_CHAR, ...numbers.slice(focusedIndex + 1, maxLength)]; setEditIndex(focusedIndex); @@ -420,7 +420,7 @@ function MagicCodeInput( focusedIndex === index ? styles.borderColorFocus : {}, ]} > - {decomposeString(value, maxLength)[index] || ''} + {decomposeString(value, maxLength).at(index) ?? ''} ))} diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx index 974f58636977..63f96d8cfc2c 100644 --- a/src/components/MapView/MapView.tsx +++ b/src/components/MapView/MapView.tsx @@ -119,7 +119,7 @@ const MapView = forwardRef( cameraRef.current?.setCamera({ zoomLevel: CONST.MAPBOX.SINGLE_MARKER_ZOOM, animationDuration: 1500, - centerCoordinate: waypoints[0].coordinate, + centerCoordinate: waypoints.at(0).coordinate, }); } else { const {southWest, northEast} = utils.getBounds( diff --git a/src/components/MapView/MapView.website.tsx b/src/components/MapView/MapView.website.tsx index 618dd5b24cf5..2079d63db02e 100644 --- a/src/components/MapView/MapView.website.tsx +++ b/src/components/MapView/MapView.website.tsx @@ -133,7 +133,7 @@ const MapView = forwardRef( if (waypoints.length === 1) { mapRef.flyTo({ - center: waypoints[0].coordinate, + center: waypoints.at(0).coordinate, zoom: CONST.MAPBOX.SINGLE_MARKER_ZOOM, }); return; diff --git a/src/components/MapView/utils.ts b/src/components/MapView/utils.ts index 04176d715281..165ec05a6d29 100644 --- a/src/components/MapView/utils.ts +++ b/src/components/MapView/utils.ts @@ -18,10 +18,10 @@ function getBounds(waypoints: Array<[number, number]>, directionCoordinates: und function haversineDistance(coordinate1: number[], coordinate2: number[]) { // Radius of the Earth in meters const R = 6371e3; - const lat1 = (coordinate1[0] * Math.PI) / 180; - const lat2 = (coordinate2[0] * Math.PI) / 180; - const deltaLat = ((coordinate2[0] - coordinate1[0]) * Math.PI) / 180; - const deltaLon = ((coordinate2[1] - coordinate1[1]) * Math.PI) / 180; + const lat1 = (coordinate1.at(0) * Math.PI) / 180; + const lat2 = (coordinate2.at(0) * Math.PI) / 180; + const deltaLat = ((coordinate2.at(0) - coordinate1.at(0)) * Math.PI) / 180; + const deltaLon = ((coordinate2.at(1) - coordinate1.at(1)) * Math.PI) / 180; // The square of half the chord length between the points const halfChordLengthSq = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2); diff --git a/src/components/MentionSuggestions.tsx b/src/components/MentionSuggestions.tsx index bdc19316d491..3b4583ed48b9 100644 --- a/src/components/MentionSuggestions.tsx +++ b/src/components/MentionSuggestions.tsx @@ -91,13 +91,13 @@ function MentionSuggestions({ {item.icons && !!item.icons.length && ( )} diff --git a/src/components/MenuItem.tsx b/src/components/MenuItem.tsx index 6757d0602691..fa0c8ffa5b66 100644 --- a/src/components/MenuItem.tsx +++ b/src/components/MenuItem.tsx @@ -760,8 +760,8 @@ function MenuItem( {shouldShowSubscriptRightAvatar ? ( ) : ( diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index dcd3fa4c2112..764c61fb26dd 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -641,7 +641,7 @@ function MoneyRequestConfirmationList({ if (iouCategory || !shouldShowCategories || enabledCategories.length !== 1 || !isCategoryRequired) { return; } - IOU.setMoneyRequestCategory(transactionID, enabledCategories[0].name); + IOU.setMoneyRequestCategory(transactionID, enabledCategories.at(0).name); // Keep 'transaction' out to ensure that we autoselect the option only once // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [shouldShowCategories, policyCategories, isCategoryRequired]); @@ -655,7 +655,7 @@ function MoneyRequestConfirmationList({ if (!isTagListRequired || enabledTags.length !== 1 || TransactionUtils.getTag(transaction, index)) { return; } - updatedTagsString = IOUUtils.insertTagIntoTransactionTagsString(updatedTagsString, enabledTags[0] ? enabledTags[0].name : '', index); + updatedTagsString = IOUUtils.insertTagIntoTransactionTagsString(updatedTagsString, enabledTags.at(0) ? enabledTags.at(0).name : '', index); }); if (updatedTagsString !== TransactionUtils.getTag(transaction) && updatedTagsString) { IOU.setMoneyRequestTag(transactionID, updatedTagsString); diff --git a/src/components/MultiGestureCanvas/usePanGesture.ts b/src/components/MultiGestureCanvas/usePanGesture.ts index fa27e48eea4c..28a539972d1c 100644 --- a/src/components/MultiGestureCanvas/usePanGesture.ts +++ b/src/components/MultiGestureCanvas/usePanGesture.ts @@ -177,8 +177,8 @@ const usePanGesture = ({ // TODO: this needs tuning to work properly if (!shouldDisableTransformationGestures.value && zoomScale.value === 1 && previousTouch.value !== null) { - const velocityX = Math.abs(evt.allTouches[0].x - previousTouch.value.x); - const velocityY = evt.allTouches[0].y - previousTouch.value.y; + const velocityX = Math.abs(evt.allTouches.at(0).x - previousTouch.value.x); + const velocityY = evt.allTouches.at(0).y - previousTouch.value.y; if (Math.abs(velocityY) > velocityX && velocityY > 20) { state.activate(); @@ -192,8 +192,8 @@ const usePanGesture = ({ if (previousTouch.value === null) { previousTouch.value = { - x: evt.allTouches[0].x, - y: evt.allTouches[0].y, + x: evt.allTouches.at(0).x, + y: evt.allTouches.at(0).y, }; } }) diff --git a/src/components/MultipleAvatars.tsx b/src/components/MultipleAvatars.tsx index 601b8f7edfed..3815d9655c5d 100644 --- a/src/components/MultipleAvatars.tsx +++ b/src/components/MultipleAvatars.tsx @@ -144,21 +144,21 @@ function MultipleAvatars({ if (icons.length === 1 && !shouldStackHorizontally) { return ( @@ -233,7 +233,7 @@ function MultipleAvatars({ // Set overlay background color with RGBA value so that the text will not inherit opacity StyleUtils.getBackgroundColorWithOpacityStyle(theme.overlay, variables.overlayOpacity), StyleUtils.getHorizontalStackedOverlayAvatarStyle(oneAvatarSize, oneAvatarBorderWidth), - icons[3].type === CONST.ICON_TYPE_WORKSPACE && StyleUtils.getAvatarBorderRadius(size, icons[3].type), + icons.at(3).type === CONST.ICON_TYPE_WORKSPACE && StyleUtils.getAvatarBorderRadius(size, icons.at(3).type), ]} > @@ -249,45 +249,45 @@ function MultipleAvatars({ )) ) : ( - + {/* View is necessary for tooltip to show for multiple avatars in LHN */} - + {icons.length === 2 ? ( diff --git a/src/components/OptionRow.tsx b/src/components/OptionRow.tsx index 029bd57cd876..10e0e68774d7 100644 --- a/src/components/OptionRow.tsx +++ b/src/components/OptionRow.tsx @@ -209,8 +209,8 @@ function OptionRow({ {!!option.icons?.length && (option.shouldShowSubscript ? ( diff --git a/src/components/OptionsList/BaseOptionsList.tsx b/src/components/OptionsList/BaseOptionsList.tsx index c08f1d697dad..fd2bfbed4745 100644 --- a/src/components/OptionsList/BaseOptionsList.tsx +++ b/src/components/OptionsList/BaseOptionsList.tsx @@ -138,10 +138,10 @@ function BaseOptionsList( */ // eslint-disable-next-line @typescript-eslint/naming-convention const getItemLayout = (_data: OptionsListDataWithIndexOffset[] | null, flatDataArrayIndex: number) => { - if (!flattenedData.current[flatDataArrayIndex]) { + if (!flattenedData.current.at(flatDataArrayIndex)) { flattenedData.current = buildFlatSectionArray(); } - const targetItem = flattenedData.current[flatDataArrayIndex]; + const targetItem = flattenedData.current.at(flatDataArrayIndex); return { length: targetItem.length, offset: targetItem.offset, diff --git a/src/components/Picker/BasePicker.tsx b/src/components/Picker/BasePicker.tsx index ddd6cd544f3e..131ad1c4f18e 100644 --- a/src/components/Picker/BasePicker.tsx +++ b/src/components/Picker/BasePicker.tsx @@ -59,7 +59,7 @@ function BasePicker( // When there is only 1 element in the selector, we do the user a favor and automatically select it for them // so they don't have to spend extra time selecting the only possible value. - onInputChange(items[0].value, 0); + onInputChange(items.at(0).value, 0); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [items]); diff --git a/src/components/PopoverMenu.tsx b/src/components/PopoverMenu.tsx index e9df68d43d06..780d22b91df6 100644 --- a/src/components/PopoverMenu.tsx +++ b/src/components/PopoverMenu.tsx @@ -122,7 +122,7 @@ function PopoverMenu({ const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({initialFocusedIndex: currentMenuItemsFocusedIndex, maxIndex: currentMenuItems.length - 1, isActive: isVisible}); const selectItem = (index: number) => { - const selectedItem = currentMenuItems[index]; + const selectedItem = currentMenuItems.at(index); if (selectedItem?.subMenuItems) { setCurrentMenuItems([...selectedItem.subMenuItems]); setEnteredSubMenuIndexes([...enteredSubMenuIndexes, index]); diff --git a/src/components/ProfilingToolMenu/BaseProfilingToolMenu.tsx b/src/components/ProfilingToolMenu/BaseProfilingToolMenu.tsx index d9e106ec3f52..a288396ad204 100644 --- a/src/components/ProfilingToolMenu/BaseProfilingToolMenu.tsx +++ b/src/components/ProfilingToolMenu/BaseProfilingToolMenu.tsx @@ -44,7 +44,7 @@ function formatBytes(bytes: number, decimals = 2) { const i = Math.floor(Math.log(bytes) / Math.log(k)); - return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`; + return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes.at(i)}`; } // WARNING: When changing this name make sure that the "scripts/symbolicate-profile.ts" script is still working! diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index fbf03821fa16..76f3e9297e0a 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -72,7 +72,7 @@ function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTo }, [policy, report]); const enabledReportFields = sortedPolicyReportFields.filter((reportField) => !ReportUtils.isReportFieldDisabled(report, reportField, policy)); - const isOnlyTitleFieldEnabled = enabledReportFields.length === 1 && ReportUtils.isReportFieldOfTypeTitle(enabledReportFields[0]); + const isOnlyTitleFieldEnabled = enabledReportFields.length === 1 && ReportUtils.isReportFieldOfTypeTitle(enabledReportFields.at(0)); const shouldShowReportField = !ReportUtils.isClosedExpenseReportWithNoExpenses(report) && ReportUtils.isPaidGroupPolicyExpenseReport(report) && (!isCombinedReport || !isOnlyTitleFieldEnabled); diff --git a/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx index 8597654576fc..4271f6cf409e 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx @@ -196,7 +196,7 @@ function MoneyRequestPreviewContent({ a.type === CONST.VIOLATION_TYPES.VIOLATION ? -1 : 0, ); if (violations?.[0]) { - const violationMessage = ViolationsUtils.getViolationTranslation(violations[0], translate); + const violationMessage = ViolationsUtils.getViolationTranslation(violations.at(0), translate); const violationsCount = violations.filter((v) => v.type === CONST.VIOLATION_TYPES.VIOLATION).length; const isTooLong = violationsCount > 1 || violationMessage.length > 15; const hasViolationsAndFieldErrors = violationsCount > 0 && hasFieldErrors; diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 13376c05a0f2..527063a813eb 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -332,7 +332,7 @@ function MoneyRequestView({ // Return violations if there are any if (hasViolations(field, data, policyHasDependentTags, tagValue)) { const violations = getViolationsForField(field, data, policyHasDependentTags, tagValue); - return ViolationsUtils.getViolationTranslation(violations[0], translate); + return ViolationsUtils.getViolationTranslation(violations.at(0), translate); } return ''; diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index dae33b438a43..3f98526960f3 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -173,10 +173,10 @@ function ReportPreview({ const lastThreeReceipts = lastThreeTransactionsWithReceipts.map((transaction) => ({...ReceiptUtils.getThumbnailAndImageURIs(transaction), transaction})); const showRTERViolationMessage = numberOfRequests === 1 && - TransactionUtils.hasPendingUI(allTransactions[0], TransactionUtils.getTransactionViolations(allTransactions[0]?.transactionID ?? '-1', transactionViolations)); + TransactionUtils.hasPendingUI(allTransactions.at(0), TransactionUtils.getTransactionViolations(allTransactions.at(0)?.transactionID ?? '-1', transactionViolations)); - let formattedMerchant = numberOfRequests === 1 ? TransactionUtils.getMerchant(allTransactions[0]) : null; - const formattedDescription = numberOfRequests === 1 ? TransactionUtils.getDescription(allTransactions[0]) : null; + let formattedMerchant = numberOfRequests === 1 ? TransactionUtils.getMerchant(allTransactions.at(0)) : null; + const formattedDescription = numberOfRequests === 1 ? TransactionUtils.getDescription(allTransactions.at(0)) : null; if (TransactionUtils.isPartialMerchant(formattedMerchant ?? '')) { formattedMerchant = null; diff --git a/src/components/ReportActionItem/TripDetailsView.tsx b/src/components/ReportActionItem/TripDetailsView.tsx index fe6831f72512..90d1d23c7b95 100644 --- a/src/components/ReportActionItem/TripDetailsView.tsx +++ b/src/components/ReportActionItem/TripDetailsView.tsx @@ -62,7 +62,7 @@ function ReservationView({reservation}: ReservationViewProps) { const formattedDate = getFormattedDate(); const bottomDescription = useMemo(() => { - const code = `${reservation.confirmations && reservation.confirmations?.length > 0 ? `${reservation.confirmations[0].value} ā€¢ ` : ''}`; + const code = `${reservation.confirmations && reservation.confirmations?.length > 0 ? `${reservation.confirmations.at(0).value} ā€¢ ` : ''}`; if (reservation.type === CONST.RESERVATION_TYPE.FLIGHT) { const longName = reservation.company?.longName ? `${reservation.company?.longName} ā€¢ ` : ''; const shortName = reservation?.company?.shortName ? `${reservation?.company?.shortName} ` : ''; diff --git a/src/components/RoomHeaderAvatars.tsx b/src/components/RoomHeaderAvatars.tsx index 8d8419efd698..cabfa9c27c3f 100644 --- a/src/components/RoomHeaderAvatars.tsx +++ b/src/components/RoomHeaderAvatars.tsx @@ -39,19 +39,19 @@ function RoomHeaderAvatars({icons, reportID}: RoomHeaderAvatarsProps) { return ( navigateToAvatarPage(icons[0])} + onPress={() => navigateToAvatarPage(icons.at(0))} accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON} - accessibilityLabel={icons[0].name ?? ''} - disabled={icons[0].source === Expensicons.FallbackAvatar} + accessibilityLabel={icons.at(0).name ?? ''} + disabled={icons.at(0).source === Expensicons.FallbackAvatar} > ); diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index 3a9437e16ec1..0f59e2edcff2 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -241,7 +241,7 @@ function BaseSelectionList( */ const scrollToIndex = useCallback( (index: number, animated = true) => { - const item = flattenedSections.allOptions[index]; + const item = flattenedSections.allOptions.at(index); if (!listRef.current || !item) { return; @@ -329,7 +329,7 @@ function BaseSelectionList( }; const selectFocusedOption = () => { - const focusedOption = flattenedSections.allOptions[focusedIndex]; + const focusedOption = flattenedSections.allOptions.at(focusedIndex); if (!focusedOption || (focusedOption.isDisabled && !focusedOption.isSelected)) { return; @@ -353,7 +353,7 @@ function BaseSelectionList( * [{header}, {sectionHeader}, {item}, {item}, {sectionHeader}, {item}, {item}, {footer}] */ const getItemLayout = (data: Array>> | null, flatDataArrayIndex: number) => { - const targetItem = flattenedSections.itemLayouts[flatDataArrayIndex]; + const targetItem = flattenedSections.itemLayouts.at(flatDataArrayIndex); if (!targetItem) { return { @@ -619,7 +619,7 @@ function BaseSelectionList( /** Selects row when pressing Enter */ useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ENTER, selectFocusedOption, { captureOnInputs: true, - shouldBubble: !flattenedSections.allOptions[focusedIndex], + shouldBubble: !flattenedSections.allOptions.at(focusedIndex), shouldStopPropagation, isActive: !disableKeyboardShortcuts && !disableEnterShortcut && isFocused, }); @@ -628,7 +628,7 @@ function BaseSelectionList( useKeyboardShortcut( CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER, (e) => { - const focusedOption = flattenedSections.allOptions[focusedIndex]; + const focusedOption = flattenedSections.allOptions.at(focusedIndex); if (onConfirm) { onConfirm(e, focusedOption); return; @@ -637,7 +637,7 @@ function BaseSelectionList( }, { captureOnInputs: true, - shouldBubble: !flattenedSections.allOptions[focusedIndex], + shouldBubble: !flattenedSections.allOptions.at(focusedIndex), isActive: !disableKeyboardShortcuts && isFocused, }, ); diff --git a/src/components/SelectionList/InviteMemberListItem.tsx b/src/components/SelectionList/InviteMemberListItem.tsx index 2b3c01c04a69..a0aceefaaf33 100644 --- a/src/components/SelectionList/InviteMemberListItem.tsx +++ b/src/components/SelectionList/InviteMemberListItem.tsx @@ -74,8 +74,8 @@ function InviteMemberListItem({ {!!item.icons && (item.shouldShowSubscript ? ( diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index 983e1415d776..edfeb0c56b46 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -100,7 +100,7 @@ function ReportListItem({ const participantToDisplayName = participantTo?.displayName ?? participantTo?.login ?? ''; if (reportItem.transactions.length === 1) { - const transactionItem = reportItem.transactions[0]; + const transactionItem = reportItem.transactions.at(0); return ( ({ {!!item.icons && (item.shouldShowSubscript ? ( diff --git a/src/components/SignInButtons/GetUserLanguage.ts b/src/components/SignInButtons/GetUserLanguage.ts index a1101e92f656..9fda67e1079b 100644 --- a/src/components/SignInButtons/GetUserLanguage.ts +++ b/src/components/SignInButtons/GetUserLanguage.ts @@ -10,7 +10,7 @@ type LocaleCode = ValueOf; const GetUserLanguage = (): LocaleCode => { const userLanguage = navigator.language || navigator.userLanguage; - const languageCode = userLanguage.split('-')[0] as LanguageCode; + const languageCode = userLanguage.split('-').at(0) as LanguageCode; return localeCodes[languageCode] || 'en_US'; }; diff --git a/src/components/TagPicker/index.tsx b/src/components/TagPicker/index.tsx index 8abcdb25aa60..fbafd375da0d 100644 --- a/src/components/TagPicker/index.tsx +++ b/src/components/TagPicker/index.tsx @@ -91,9 +91,9 @@ function TagPicker({selectedTag, tagListName, policyTags, tagListIndex, policyRe [searchValue, enabledTags, selectedOptions, policyRecentlyUsedTagsList], ); - const headerMessage = OptionsListUtils.getHeaderMessageForNonUserList((sections?.[0]?.data?.length ?? 0) > 0, searchValue); + const headerMessage = OptionsListUtils.getHeaderMessageForNonUserList((sections.at(0)?.data?.length ?? 0) > 0, searchValue); - const selectedOptionKey = sections[0]?.data?.filter((policyTag) => policyTag.searchText === selectedTag)?.[0]?.keyForList; + const selectedOptionKey = sections.at(0)?.data?.filter((policyTag) => policyTag.searchText === selectedTag)?.[0]?.keyForList; return ( 0, searchValue); + const headerMessage = OptionsListUtils.getHeaderMessageForNonUserList(sections.at(0).data.length > 0, searchValue); - const selectedOptionKey = useMemo(() => sections?.[0]?.data?.find((taxRate) => taxRate.searchText === selectedTaxRate)?.keyForList, [sections, selectedTaxRate]); + const selectedOptionKey = useMemo(() => sections.at(0)?.data?.find((taxRate) => taxRate.searchText === selectedTaxRate)?.keyForList, [sections, selectedTaxRate]); const handleSelectRow = useCallback( (newSelectedOption: OptionsListUtils.TaxRatesOption) => { diff --git a/src/hooks/useReviewDuplicatesNavigation.tsx b/src/hooks/useReviewDuplicatesNavigation.tsx index e14731024c17..d524682a3680 100644 --- a/src/hooks/useReviewDuplicatesNavigation.tsx +++ b/src/hooks/useReviewDuplicatesNavigation.tsx @@ -14,7 +14,7 @@ function useReviewDuplicatesNavigation(stepNames: string[], currentScreenName: S const currentIndex = intersection.indexOf(currentScreenName); const nextScreenIndex = currentIndex + 1; setCurrentScreenIndex(currentIndex); - setNextScreen(intersection[nextScreenIndex] ?? ''); + setNextScreen(intersection.at(nextScreenIndex) ?? ''); }, [currentScreenName, intersection]); const navigateToNextScreen = () => { diff --git a/src/hooks/useSubStep/index.ts b/src/hooks/useSubStep/index.ts index 43fc3061d968..846c758a8eec 100644 --- a/src/hooks/useSubStep/index.ts +++ b/src/hooks/useSubStep/index.ts @@ -56,7 +56,7 @@ export default function useSubStep({bodyContent, on }, [bodyContent]); return { - componentToRender: bodyContent[screenIndex], + componentToRender: bodyContent.at(screenIndex), isEditing: isEditing.current, screenIndex, prevScreen, diff --git a/src/hooks/useViolations.ts b/src/hooks/useViolations.ts index 44b8e982139e..dee0c5e0ce06 100644 --- a/src/hooks/useViolations.ts +++ b/src/hooks/useViolations.ts @@ -83,7 +83,11 @@ function useViolations(violations: TransactionViolation[], shouldShowOnlyViolati // someTagLevelsRequired has special logic becase data.errorIndexes is a bit unique in how it denotes the tag list that has the violation // tagListIndex can be 0 so we compare with undefined - if (currentViolations[0]?.name === CONST.VIOLATIONS.SOME_TAG_LEVELS_REQUIRED && data?.tagListIndex !== undefined && Array.isArray(currentViolations[0]?.data?.errorIndexes)) { + if ( + currentViolations.at(0)?.name === CONST.VIOLATIONS.SOME_TAG_LEVELS_REQUIRED && + data?.tagListIndex !== undefined && + Array.isArray(currentViolations.at(0)?.data?.errorIndexes) + ) { return currentViolations .filter((violation) => violation.data?.errorIndexes?.includes(data?.tagListIndex ?? -1)) .map((violation) => ({ @@ -97,12 +101,12 @@ function useViolations(violations: TransactionViolation[], shouldShowOnlyViolati // missingTag has special logic for policies with dependent tags, because only one violation is returned for all tags // when no tags are present, so the tag name isn't set in the violation data. That's why we add it here - if (policyHasDependentTags && currentViolations[0]?.name === CONST.VIOLATIONS.MISSING_TAG && data?.tagListName) { + if (policyHasDependentTags && currentViolations.at(0)?.name === CONST.VIOLATIONS.MISSING_TAG && data?.tagListName) { return [ { - ...currentViolations[0], + ...currentViolations.at(0), data: { - ...currentViolations[0].data, + ...currentViolations.at(0).data, tagName: data?.tagListName, }, }, @@ -110,13 +114,13 @@ function useViolations(violations: TransactionViolation[], shouldShowOnlyViolati } // tagOutOfPolicy has special logic because we have to account for multi-level tags and use tagName to find the right tag to put the violation on - if (currentViolations[0]?.name === CONST.VIOLATIONS.TAG_OUT_OF_POLICY && data?.tagListName !== undefined && currentViolations[0]?.data?.tagName) { + if (currentViolations.at(0)?.name === CONST.VIOLATIONS.TAG_OUT_OF_POLICY && data?.tagListName !== undefined && currentViolations.at(0)?.data?.tagName) { return currentViolations.filter((violation) => violation.data?.tagName === data?.tagListName); } // allTagLevelsRequired has special logic because it is returned when one but not all the tags are set, // so we need to return the violation for the tag fields without a tag set - if (currentViolations[0]?.name === CONST.VIOLATIONS.ALL_TAG_LEVELS_REQUIRED && tagValue) { + if (currentViolations.at(0)?.name === CONST.VIOLATIONS.ALL_TAG_LEVELS_REQUIRED && tagValue) { return currentViolations.filter((violation) => violation.data?.tagName === data?.tagListName); } diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 53b58d224e17..fb6802577f1e 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -275,4 +275,3 @@ export type {default as StartIssueNewCardFlowParams} from './StartIssueNewCardFl export type {default as ConfigureExpensifyCardsForPolicyParams} from './ConfigureExpensifyCardsForPolicyParams'; export type {default as CreateExpensifyCardParams} from './CreateExpensifyCardParams'; export type {default as UpdateExpensifyCardTitleParams} from './UpdateExpensifyCardTitleParams'; -export type {default as OpenCardDetailsPageParams} from './OpenCardDetailsPageParams'; diff --git a/src/libs/ActiveClientManager/index.ts b/src/libs/ActiveClientManager/index.ts index e93cdb07d084..159e81de4c1d 100644 --- a/src/libs/ActiveClientManager/index.ts +++ b/src/libs/ActiveClientManager/index.ts @@ -62,7 +62,7 @@ const isClientTheLeader: IsClientTheLeader = () => { return true; } - const lastActiveClient = activeClients.length && activeClients[activeClients.length - 1]; + const lastActiveClient = activeClients.length && activeClients.at(activeClients.length - 1); return lastActiveClient === clientID; }; diff --git a/src/libs/CollectionUtils.ts b/src/libs/CollectionUtils.ts index 9d0ff5425da2..2d94def3832f 100644 --- a/src/libs/CollectionUtils.ts +++ b/src/libs/CollectionUtils.ts @@ -17,7 +17,7 @@ function lastItem(object: Record = {}): T | undefined { * e.g. reportActions_1 -> 1 */ function extractCollectionItemID(key: `${OnyxCollectionKey}${string}`): string { - return key.split('_')[1]; + return key.split('_').at(1); } export {lastItem, extractCollectionItemID}; diff --git a/src/libs/CurrencyUtils.ts b/src/libs/CurrencyUtils.ts index c3b80797d750..792d67c2ba98 100644 --- a/src/libs/CurrencyUtils.ts +++ b/src/libs/CurrencyUtils.ts @@ -68,7 +68,7 @@ function isCurrencySymbolLTR(currencyCode: string): boolean { }); // Currency is LTR when the first part is of currency type. - return parts[0].type === 'currency'; + return parts.at(0).type === 'currency'; } /** diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index fa98cf32ee39..3f2405c4bade 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -82,14 +82,14 @@ function getDefaultMileageRate(policy: OnyxInputOrEntry): MileageRate | } const mileageRates = Object.values(getMileageRates(policy)); - const distanceRate = mileageRates.find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE) ?? mileageRates[0] ?? {}; + const distanceRate = mileageRates.find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE) ?? mileageRates.at(0) ?? {}; return { - customUnitRateID: distanceRate.customUnitRateID, - rate: distanceRate.rate, - currency: distanceRate.currency, + customUnitRateID: distanceRate?.customUnitRateID, + rate: distanceRate?.rate, + currency: distanceRate?.currency, unit: distanceUnit.attributes.unit, - name: distanceRate.name, + name: distanceRate?.name, }; } diff --git a/src/libs/E2E/tests/linkingTest.e2e.ts b/src/libs/E2E/tests/linkingTest.e2e.ts index 7e6c7ea697ba..782ef87e8afa 100644 --- a/src/libs/E2E/tests/linkingTest.e2e.ts +++ b/src/libs/E2E/tests/linkingTest.e2e.ts @@ -45,11 +45,11 @@ const test = (config: NativeConfig) => { const subscription = DeviceEventEmitter.addListener('onViewableItemsChanged', (res: ViewableItemResponse) => { console.debug('[E2E] Viewable items retrieved, verifying correct messageā€¦', res); - if (!!res && res?.[0]?.item?.reportActionID === linkedReportActionID) { + if (!!res && res.at(0)?.item?.reportActionID === linkedReportActionID) { appearMessageResolve(); subscription.remove(); } else { - console.debug(`[E2E] Provided message id '${res?.[0]?.item?.reportActionID}' doesn't match to an expected '${linkedReportActionID}'. Waiting for a next oneā€¦`); + console.debug(`[E2E] Provided message id '${res.at(0)?.item?.reportActionID}' doesn't match to an expected '${linkedReportActionID}'. Waiting for a next oneā€¦`); } }); diff --git a/src/libs/EmojiTrie.ts b/src/libs/EmojiTrie.ts index 88a1a7a275d4..c2648cc82a50 100644 --- a/src/libs/EmojiTrie.ts +++ b/src/libs/EmojiTrie.ts @@ -124,7 +124,7 @@ const emojiTrie: EmojiTrie = supportedLanguages.reduce((acc, lang) => { const buildEmojisTrie = (locale: Locale) => { // Normalize the locale to lowercase and take the first part before any dash - const normalizedLocale = locale.toLowerCase().split('-')[0]; + const normalizedLocale = locale.toLowerCase().split('-').at(0); const localeToUse = supportedLanguages.includes(normalizedLocale as SupportedLanguage) ? (normalizedLocale as SupportedLanguage) : undefined; if (!localeToUse || emojiTrie[localeToUse]) { diff --git a/src/libs/EmojiUtils.ts b/src/libs/EmojiUtils.ts index 22b1ee0bc010..751b90b32a82 100644 --- a/src/libs/EmojiUtils.ts +++ b/src/libs/EmojiUtils.ts @@ -267,7 +267,7 @@ const getEmojiCodeWithSkinColor = (item: Emoji, preferredSkinToneIndex: OnyxEntr const {code, types} = item; if (typeof preferredSkinToneIndex === 'number' && types?.[preferredSkinToneIndex]) { - return types[preferredSkinToneIndex]; + return types.at(preferredSkinToneIndex); } return code; @@ -462,7 +462,7 @@ const getPreferredSkinToneIndex = (value: OnyxEntry): number => */ const getPreferredEmojiCode = (emoji: Emoji, preferredSkinTone: OnyxEntry): string => { if (emoji.types && typeof preferredSkinTone === 'number') { - const emojiCodeWithSkinTone = emoji.types[preferredSkinTone]; + const emojiCodeWithSkinTone = emoji.types.at(preferredSkinTone); // Note: it can happen that preferredSkinTone has a outdated format, // so it makes sense to check if we actually got a valid emoji code back @@ -504,7 +504,7 @@ const enrichEmojiReactionWithTimestamps = (emoji: ReportActionReaction, emojiNam const usersWithTimestamps: UsersReactions = {}; Object.entries(emoji.users ?? {}).forEach(([id, user]) => { const userTimestamps = Object.values(user?.skinTones ?? {}); - const oldestUserTimestamp = userTimestamps.reduce((min, curr) => (curr < min ? curr : min), userTimestamps[0]); + const oldestUserTimestamp = userTimestamps.reduce((min, curr) => (curr < min ? curr : min), userTimestamps.at(0)); if (!oldestEmojiTimestamp || oldestUserTimestamp < oldestEmojiTimestamp) { oldestEmojiTimestamp = oldestUserTimestamp; diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index cf852e533a20..0db196b34850 100644 --- a/src/libs/ErrorUtils.ts +++ b/src/libs/ErrorUtils.ts @@ -77,8 +77,8 @@ function getLatestErrorMessage(onyxData: O return ''; } - const key = Object.keys(errors).sort().reverse()[0]; - return getErrorMessageWithTranslationData(errors[key] ?? ''); + const key = Object.keys(errors).sort().reverse().at(0); + return getErrorMessageWithTranslationData(errors.at(key) ?? ''); } function getLatestErrorMessageField(onyxData: OnyxEntry): Errors { @@ -88,9 +88,9 @@ function getLatestErrorMessageField(onyxDa return {}; } - const key = Object.keys(errors).sort().reverse()[0]; + const key = Object.keys(errors).sort().reverse().at(0); - return {key: errors[key]}; + return {key: errors.at(key)}; } type OnyxDataWithErrorFields = { @@ -104,8 +104,8 @@ function getLatestErrorField(onyxData return {}; } - const key = Object.keys(errorsForField).sort().reverse()[0]; - return {[key]: getErrorMessageWithTranslationData(errorsForField[key])}; + const key = Object.keys(errorsForField).sort().reverse().at(0); + return {[key]: getErrorMessageWithTranslationData(errorsForField.at(key))}; } function getEarliestErrorField(onyxData: OnyxEntry, fieldName: string): Errors { @@ -115,7 +115,7 @@ function getEarliestErrorField(onyxDa return {}; } - const key = Object.keys(errorsForField).sort()[0]; + const key = Object.keys(errorsForField).sort().at(0); return {[key]: getErrorMessageWithTranslationData(errorsForField[key])}; } diff --git a/src/libs/GooglePlacesUtils.ts b/src/libs/GooglePlacesUtils.ts index 312a0dc61c1f..39a9009525f4 100644 --- a/src/libs/GooglePlacesUtils.ts +++ b/src/libs/GooglePlacesUtils.ts @@ -45,7 +45,7 @@ function getPlaceAutocompleteTerms(addressTerms: AddressTerm[]): GetPlaceAutocom const result: GetPlaceAutocompleteTermsResult = {}; fieldsToExtract.forEach((fieldToExtract, index) => { const fieldTermIndex = addressTerms.length - (index + 1); - result[fieldToExtract] = fieldTermIndex >= 0 ? addressTerms[fieldTermIndex].value : ''; + result[fieldToExtract] = fieldTermIndex >= 0 ? addressTerms.at(fieldTermIndex).value : ''; }); return result; } diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index 986fd165d2d7..92f5297f31c1 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -139,7 +139,7 @@ function temporary_isValidMoneyRequestType(iouType: string): boolean { */ function insertTagIntoTransactionTagsString(transactionTags: string, tag: string, tagIndex: number): string { const tagArray = TransactionUtils.getTagArrayFromName(transactionTags); - tagArray[tagIndex] = tag; + tagArray.at(tagIndex) = tag; return tagArray .map((tagItem) => tagItem.trim()) diff --git a/src/libs/LocaleDigitUtils.ts b/src/libs/LocaleDigitUtils.ts index 0362f4aa963f..c4676a8d0c15 100644 --- a/src/libs/LocaleDigitUtils.ts +++ b/src/libs/LocaleDigitUtils.ts @@ -22,13 +22,13 @@ const getLocaleDigits = memoize( NumberFormatUtils.formatToParts(locale, 1000000.5).forEach((part) => { switch (part.type) { case 'decimal': - localeDigits[INDEX_DECIMAL] = part.value; + localeDigits.at(INDEX_DECIMAL) = part.value; break; case 'minusSign': - localeDigits[INDEX_MINUS_SIGN] = part.value; + localeDigits.at(INDEX_MINUS_SIGN) = part.value; break; case 'group': - localeDigits[INDEX_GROUP] = part.value; + localeDigits.at(INDEX_GROUP) = part.value; break; default: break; @@ -52,7 +52,7 @@ function toLocaleDigit(locale: Locale, digit: string): string { if (index < 0) { throw new Error(`"${digit}" must be in ${JSON.stringify(STANDARD_DIGITS)}`); } - return getLocaleDigits(locale)[index]; + return getLocaleDigits(locale).at(index); } /** @@ -68,7 +68,7 @@ function fromLocaleDigit(locale: Locale, localeDigit: string): string { if (index < 0) { throw new Error(`"${localeDigit}" must be in ${JSON.stringify(getLocaleDigits(locale))}`); } - return STANDARD_DIGITS[index]; + return STANDARD_DIGITS.at(index); } /** diff --git a/src/libs/Middleware/Pagination.ts b/src/libs/Middleware/Pagination.ts index ff5f5942674f..9d11df1988d5 100644 --- a/src/libs/Middleware/Pagination.ts +++ b/src/libs/Middleware/Pagination.ts @@ -108,10 +108,10 @@ const Pagination: Middleware = (requestResponse, request) => { // Detect if we are at the start of the list. This will always be the case for the initial request with no cursor. // For previous requests we check that no new data is returned. Ideally the server would return that info. - if ((type === 'initial' && !cursorID) || (type === 'next' && newPage.length === 1 && newPage[0] === cursorID)) { + if ((type === 'initial' && !cursorID) || (type === 'next' && newPage.length === 1 && newPage.at(0) === cursorID)) { newPage.unshift(CONST.PAGINATION_START_ID); } - if (isLastItem(sortedPageItems[sortedPageItems.length - 1])) { + if (isLastItem(sortedPageItems.at(sortedPageItems.length - 1))) { newPage.push(CONST.PAGINATION_END_ID); } diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 4a09660a7090..e17041319a41 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -214,8 +214,8 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr sortedTagKeys.forEach((policyTagKey, index) => { const policyTagListName = policyTags[policyTagKey].name || localizedTagListName; - const newTag = splittedTag[index] ?? ''; - const oldTag = splittedOldTag[index] ?? ''; + const newTag = splittedTag.at(index) ?? ''; + const oldTag = splittedOldTag.at(index) ?? ''; if (newTag !== oldTag) { buildMessageFragmentForValue( diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx index 89b83dae816c..e83fcc3c3c87 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx @@ -19,7 +19,7 @@ function getStateToRender(state: StackNavigationState): StackNavi // We need to render at least one HOME screen to make sure everything load properly. This may be not necessary after changing how IS_SIDEBAR_LOADED is handled. // Currently this value will be switched only after the first HOME screen is rendered. - if (routesToRender[0].name !== SCREENS.HOME) { + if (routesToRender.at(0).name !== SCREENS.HOME) { const routeToRender = state.routes.find((route) => route.name === SCREENS.HOME); if (routeToRender) { routesToRender.unshift(routeToRender); diff --git a/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/CustomFullScreenRouter.tsx b/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/CustomFullScreenRouter.tsx index 27e976d9be0c..7dc66d06fd4a 100644 --- a/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/CustomFullScreenRouter.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/CustomFullScreenRouter.tsx @@ -40,7 +40,7 @@ function adaptStateIfNecessary(state: StackState) { if (state.stale === true) { state.routes.push({ name: SCREENS.WORKSPACE.PROFILE, - params: state.routes[0]?.params, + params: state.routes.at(0)?.params, }); } } diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx index 310766f80e9d..3cc33da0281a 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx @@ -64,7 +64,7 @@ function ResponsiveStackNavigator(props: ResponsiveStackNavigatorProps) { if (isSmallScreenWidth) { const isSearchCentralPane = (route: RouteProp) => getTopmostCentralPaneRoute({routes: [route]} as State)?.name === SCREENS.SEARCH.CENTRAL_PANE; - const lastRoute = routes[routes.length - 1]; + const lastRoute = routes.at(routes.length - 1); const lastSearchCentralPane = isSearchCentralPane(lastRoute) ? lastRoute : undefined; const filteredRoutes = routes.filter((route) => !isSearchCentralPane(route)); @@ -74,7 +74,7 @@ function ResponsiveStackNavigator(props: ResponsiveStackNavigatorProps) { stateToRender: { ...state, index: 0, - routes: [filteredRoutes[0]], + routes: [filteredRoutes.at(0)], }, searchRoute: lastSearchCentralPane, }; diff --git a/src/libs/Navigation/OnyxTabNavigator.tsx b/src/libs/Navigation/OnyxTabNavigator.tsx index a1d9d1786dd2..bd8b2140b890 100644 --- a/src/libs/Navigation/OnyxTabNavigator.tsx +++ b/src/libs/Navigation/OnyxTabNavigator.tsx @@ -123,8 +123,8 @@ function OnyxTabNavigator({ const state = event.data.state; const index = state.index; const routeNames = state.routeNames; - Tab.setSelectedTab(id, routeNames[index] as SelectedTabRequest); - onTabSelected(routeNames[index] as IOURequestType); + Tab.setSelectedTab(id, routeNames.at(index) as SelectedTabRequest); + onTabSelected(routeNames.at(index) as IOURequestType); }, ...(screenListeners ?? {}), }} diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index 1e187330089f..2c0cc1732902 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -121,7 +121,7 @@ function getMatchingRootRouteForRHPRoute(route: NavigationPartialRoute): Navigat // If there is rhpNavigator in the state generated for backTo url, we want to get root route matching to this rhp screen. if (rhpNavigator && rhpNavigator.state) { - const isRHPinState = stateForBackTo.routes[0].name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR; + const isRHPinState = stateForBackTo.routes.at(0).name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR; if (isRHPinState) { return getMatchingRootRouteForRHPRoute(findFocusedRoute(stateForBackTo) as NavigationPartialRoute); @@ -337,7 +337,7 @@ function getAdaptedState(state: PartialState // - matching central pane on desktop layout // We want to make sure that the bottom tab search page is always pushed with matching central pane page. Even on the narrow layout. - if (isNarrowLayout && bottomTabNavigator.state?.routes[0].name !== SCREENS.SEARCH.BOTTOM_TAB) { + if (isNarrowLayout && bottomTabNavigator.state?.routes.at(0).name !== SCREENS.SEARCH.BOTTOM_TAB) { return { adaptedState: state, metainfo, diff --git a/src/libs/Navigation/linkingConfig/getMatchingCentralPaneRouteForState.ts b/src/libs/Navigation/linkingConfig/getMatchingCentralPaneRouteForState.ts index 0679bfa26285..3b554bf3d477 100644 --- a/src/libs/Navigation/linkingConfig/getMatchingCentralPaneRouteForState.ts +++ b/src/libs/Navigation/linkingConfig/getMatchingCentralPaneRouteForState.ts @@ -53,7 +53,7 @@ function getMatchingCentralPaneRouteForState(state: State, r return; } - const centralPaneName = TAB_TO_CENTRAL_PANE_MAPPING[topmostBottomTabRoute.name][0]; + const centralPaneName = TAB_TO_CENTRAL_PANE_MAPPING[topmostBottomTabRoute.name].at(0); if (topmostBottomTabRoute.name === SCREENS.SETTINGS.ROOT) { // When we go back to the settings tab without switching the workspace id, we want to return to the previously opened screen diff --git a/src/libs/Network/SequentialQueue.ts b/src/libs/Network/SequentialQueue.ts index 5646cb8956dd..a740a763bbf7 100644 --- a/src/libs/Network/SequentialQueue.ts +++ b/src/libs/Network/SequentialQueue.ts @@ -79,7 +79,7 @@ function process(): Promise { return Promise.resolve(); } - const requestToProcess = persistedRequests[0]; + const requestToProcess = persistedRequests.at(0); // Set the current request to a promise awaiting its processing so that getCurrentRequest can be used to take some action after the current request has processed. currentRequest = Request.processWithMiddleware(requestToProcess, true) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 544bc228fa70..1b1686a6e3c3 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -66,7 +66,7 @@ function getNextApproverDisplayName(policy: Policy, ownerAccountID: number, subm return ReportUtils.getDisplayNameForParticipant(submitToAccountID); } - const nextApproverEmail = approvalChain.length === 1 ? approvalChain[0] : approvalChain[approvalChain.indexOf(currentUserEmail) + 1]; + const nextApproverEmail = approvalChain.length === 1 ? approvalChain.at(0) : approvalChain[approvalChain.indexOf(currentUserEmail) + 1]; if (!nextApproverEmail) { return ReportUtils.getDisplayNameForParticipant(submitToAccountID); } diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 98274e829001..ce6ae5a52ece 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -221,7 +221,6 @@ type PreviewConfig = {showChatPreviewLine?: boolean; forcePolicyNamePreview?: bo type FilterOptionsConfig = Pick & { preferChatroomsOverThreads?: boolean; includeChatRoomsByParticipants?: boolean; - preferPolicyExpenseChat?: boolean; }; type HasText = { @@ -301,7 +300,7 @@ Onyx.connect({ // Iterate over the report actions to build the sorted and lastVisible report actions objects Object.entries(allReportActions).forEach((reportActions) => { - const reportID = reportActions[0].split('_')[1]; + const reportID = reportActions[0].split('_').at(1); const reportActionsArray = Object.values(reportActions[1] ?? {}); let sortedReportActions = ReportActionUtils.getSortedReportActions(reportActionsArray, true); allSortedReportActions[reportID] = sortedReportActions; @@ -314,7 +313,7 @@ Onyx.connect({ sortedReportActions = ReportActionUtils.getCombinedReportActions(sortedReportActions, transactionThreadReportID, transactionThreadReportActionsArray, reportID); } - lastReportActions[reportID] = sortedReportActions[0]; + lastReportActions[reportID] = sortedReportActions.at(0); // The report is only visible if it is the last action not deleted that // does not match a closed or created state. @@ -326,7 +325,7 @@ Onyx.connect({ reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !ReportActionUtils.isResolvedActionTrackExpense(reportAction), ); - lastVisibleReportActions[reportID] = reportActionsForDisplay[0]; + lastVisibleReportActions[reportID] = reportActionsForDisplay.at(0); }); }, }); @@ -600,7 +599,7 @@ function getAlternateText(option: ReportUtils.OptionData, {showChatPreviewLine = return showChatPreviewLine && option.lastMessageText ? option.lastMessageText - : LocalePhoneNumber.formatPhoneNumber(option.participantsList && option.participantsList.length > 0 ? option.participantsList[0].login ?? '' : ''); + : LocalePhoneNumber.formatPhoneNumber(option.participantsList && option.participantsList.length > 0 ? option.participantsList.at(0).login ?? '' : ''); } function isSearchStringMatchUserDetails(personalDetail: PersonalDetails, searchValue: string) { @@ -774,7 +773,7 @@ function createOption( const personalDetailMap = getPersonalDetailsForAccountIDs(accountIDs, personalDetails); const personalDetailList = Object.values(personalDetailMap).filter((details): details is PersonalDetails => !!details); - const personalDetail = personalDetailList[0]; + const personalDetail = personalDetailList.at(0); let hasMultipleParticipants = personalDetailList.length > 1; let subtitle; let reportName; @@ -832,12 +831,12 @@ function createOption( result.alternateText = showPersonalDetails && personalDetail?.login ? personalDetail.login : getAlternateText(result, {showChatPreviewLine, forcePolicyNamePreview}); reportName = showPersonalDetails - ? ReportUtils.getDisplayNameForParticipant(accountIDs[0]) || LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? '') + ? ReportUtils.getDisplayNameForParticipant(accountIDs.at(0)) || LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? '') : ReportUtils.getReportName(report); } else { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0]) || LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? ''); - result.keyForList = String(accountIDs[0]); + reportName = ReportUtils.getDisplayNameForParticipant(accountIDs.at(0)) || LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? ''); + result.keyForList = String(accountIDs.at(0)); result.alternateText = LocalePhoneNumber.formatPhoneNumber(personalDetails?.[accountIDs[0]]?.login ?? ''); } @@ -2416,7 +2415,7 @@ function getFirstKeyForList(data?: Option[] | null) { return ''; } - const firstNonEmptyDataObj = data[0]; + const firstNonEmptyDataObj = data.at(0); return firstNonEmptyDataObj.keyForList ? firstNonEmptyDataObj.keyForList : ''; } diff --git a/src/libs/PaginationUtils.ts b/src/libs/PaginationUtils.ts index a08868f5dcc1..f43d63c2fb0a 100644 --- a/src/libs/PaginationUtils.ts +++ b/src/libs/PaginationUtils.ts @@ -46,7 +46,7 @@ function findFirstItem(sortedItems: TResource[], page: string[], getI */ function findLastItem(sortedItems: TResource[], page: string[], getID: (item: TResource) => string): ItemWithIndex | null { for (let i = page.length - 1; i >= 0; i--) { - const id = page[i]; + const id = page.at(i); if (id === CONST.PAGINATION_END_ID) { return {id, index: sortedItems.length - 1}; } @@ -121,10 +121,10 @@ function mergeAndSortContinuousPages(sortedItems: TResource[], pages: return b.lastIndex - a.lastIndex; }); - const result = [sortedPages[0]]; + const result = [sortedPages.at(0)]; for (let i = 1; i < sortedPages.length; i++) { - const page = sortedPages[i]; - const prevPage = result[result.length - 1]; + const page = sortedPages.at(i); + const prevPage = result.at(result.length - 1); // Current page is inside the previous page, skip if (page.lastIndex <= prevPage.lastIndex && page.lastID !== CONST.PAGINATION_END_ID) { @@ -181,12 +181,12 @@ function getContinuousChain(sortedItems: TResource[], pages: Pages, g // If we are linked to an action in a gap return it by itself if (!linkedPage) { - return [sortedItems[index]]; + return [sortedItems.at(index)]; } page = linkedPage; } else { - page = pagesWithIndexes[0]; + page = pagesWithIndexes.at(0); } return page ? sortedItems.slice(page.firstIndex, page.lastIndex + 1) : sortedItems; diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 6f87e09a61d7..a15389a39d47 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -139,7 +139,7 @@ function getNewAccountIDsAndLogins(logins: string[], accountIDs: number[]) { const newAccountIDs: number[] = []; const newLogins: string[] = []; logins.forEach((login, index) => { - const accountID = accountIDs[index]; + const accountID = accountIDs.at(index); if (isEmptyObject(allPersonalDetails?.[accountID])) { newAccountIDs.push(accountID); newLogins.push(login); @@ -158,7 +158,7 @@ function getPersonalDetailsOnyxDataForOptimisticUsers(newLogins: string[], newAc const personalDetailsCleanup: PersonalDetailsList = {}; newLogins.forEach((login, index) => { - const accountID = newAccountIDs[index]; + const accountID = newAccountIDs.at(index); personalDetailsNew[accountID] = { login, accountID, @@ -222,7 +222,7 @@ function getFormattedStreet(street1 = '', street2 = '') { */ function getStreetLines(street = '') { const streets = street.split('\n'); - return [streets[0], streets[1]]; + return [streets.at(0), streets.at(1)]; } /** diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 3f3a2a96a1e1..778c68ca4c78 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -288,7 +288,7 @@ function getTagList(policyTagList: OnyxEntry, tagIndex: number): const tagLists = getTagLists(policyTagList); return ( - tagLists[tagIndex] ?? { + tagLists.at(tagIndex) ?? { name: '', required: false, tags: {}, @@ -483,12 +483,12 @@ function getDefaultApprover(policy: OnyxEntry): string { * Returns the accountID to whom the given employeeAccountID submits reports to in the given Policy. */ function getSubmitToAccountID(policy: OnyxEntry, employeeAccountID: number): number { - const employeeLogin = getLoginsByAccountIDs([employeeAccountID])[0]; + const employeeLogin = getLoginsByAccountIDs([employeeAccountID]).at(0); const defaultApprover = getDefaultApprover(policy); // For policy using the optional or basic workflow, the manager is the policy default approver. if (([CONST.POLICY.APPROVAL_MODE.OPTIONAL, CONST.POLICY.APPROVAL_MODE.BASIC] as Array>).includes(getApprovalWorkflow(policy))) { - return getAccountIDsByLogins([defaultApprover])[0]; + return getAccountIDsByLogins([defaultApprover]).at(0); } const employee = policy?.employeeList?.[employeeLogin]; @@ -496,12 +496,12 @@ function getSubmitToAccountID(policy: OnyxEntry, employeeAccountID: numb return -1; } - return getAccountIDsByLogins([employee.submitsTo ?? defaultApprover])[0]; + return getAccountIDsByLogins([employee.submitsTo ?? defaultApprover]).at(0); } function getSubmitToEmail(policy: OnyxEntry, employeeAccountID: number): string { const submitToAccountID = getSubmitToAccountID(policy, employeeAccountID); - return getLoginsByAccountIDs([submitToAccountID])[0] ?? ''; + return getLoginsByAccountIDs([submitToAccountID]).at(0) ?? ''; } /** @@ -530,7 +530,7 @@ function getForwardsToAccount(policy: OnyxEntry, employeeEmail: string, */ function getReimburserAccountID(policy: OnyxEntry): number { const reimburserEmail = policy?.achAccount?.reimburser ?? policy?.owner ?? ''; - return getAccountIDsByLogins([reimburserEmail])[0]; + return getAccountIDsByLogins([reimburserEmail]).at(0); } function getPersonalPolicy() { diff --git a/src/libs/Queue/Queue.ts b/src/libs/Queue/Queue.ts index 8b2011e64371..26586d8014a1 100644 --- a/src/libs/Queue/Queue.ts +++ b/src/libs/Queue/Queue.ts @@ -59,7 +59,7 @@ function createQueue(processItem: (item: T) => Promise): Queue { // Function to get the item at the front of the queue without removing it function peek(): T | undefined { - return elements.length > 0 ? elements[0] : undefined; + return elements.length > 0 ? elements.at(0) : undefined; } // Function to get the number of items in the queue diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index a731fab4ae05..75064ab21a8f 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -120,13 +120,13 @@ function isDeletedAction(reportAction: OnyxInputOrEntry): boolean { @@ -497,8 +497,8 @@ function findPreviousAction(reportActions: ReportAction[] | undefined, actionInd for (let i = actionIndex + 1; i < reportActions.length; i++) { // Find the next non-pending deletion report action, as the pending delete action means that it is not displayed in the UI, but still is in the report actions list. // If we are offline, all actions are pending but shown in the UI, so we take the previous action, even if it is a delete. - if (isNetworkOffline || reportActions[i].pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { - return reportActions[i]; + if (isNetworkOffline || reportActions.at(i).pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { + return reportActions.at(i); } } @@ -707,8 +707,8 @@ function replaceBaseURLInPolicyChangeLogAction(reportAction: ReportAction): Repo return updatedReportAction; } - if (Array.isArray(updatedReportAction.message) && updatedReportAction.message[0]) { - updatedReportAction.message[0].html = getReportActionHtml(reportAction)?.replace('%baseURL', environmentURL); + if (Array.isArray(updatedReportAction.message) && updatedReportAction.message.at(0)) { + updatedReportAction.message.at(0).html = getReportActionHtml(reportAction)?.replace('%baseURL', environmentURL); } return updatedReportAction; @@ -728,7 +728,7 @@ function getLastVisibleAction(reportID: string, actionsToMerge: Record !isDeletedAction(action) || (action?.childVisibleActionCount ?? 0) > 0 || isOffline); - return sortedFilterReportActions.length > 1 ? sortedFilterReportActions[sortedFilterReportActions.length - 2].reportActionID : ''; + return sortedFilterReportActions.length > 1 ? sortedFilterReportActions.at(sortedFilterReportActions.length - 2).reportActionID : ''; } /** @@ -1004,7 +1004,7 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn return; } - const singleAction = iouRequestActions[0]; + const singleAction = iouRequestActions.at(0); const originalMessage = getOriginalMessage(singleAction); // If there's only one IOU request action associated with the report but it's been deleted, then we don't consider this a oneTransaction report @@ -1400,7 +1400,7 @@ function isCurrentActionUnread(report: OnyxEntry, reportAction: ReportAc if (currentActionIndex === -1) { return false; } - const prevReportAction = sortedReportActions[currentActionIndex - 1]; + const prevReportAction = sortedReportActions.at(currentActionIndex - 1); return isReportActionUnread(reportAction, lastReadTime) && (!prevReportAction || !isReportActionUnread(prevReportAction, lastReadTime)); } @@ -1551,7 +1551,7 @@ function getExportIntegrationActionFragments(reportAction: OnyxEntry): boolean { const participantAccountIDs = Object.keys(report?.participants ?? {}) .map(Number) .filter((accountID) => accountID !== currentUserAccountID); - return isOptimisticPersonalDetail(participantAccountIDs[0]); + return isOptimisticPersonalDetail(participantAccountIDs.at(0)); } return false; } @@ -1323,7 +1323,7 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa // Filter out the systemChat report from the reports list, as we don't want to drop the user into that report over Concierge when they first log in reportsValues = reportsValues.filter((report) => !isSystemChat(report)) ?? []; if (reportsValues.length === 1) { - return reportsValues[0]; + return reportsValues.at(0); } return adminReport ?? reportsValues.find((report) => !isConciergeChatReport(report)); @@ -1580,7 +1580,7 @@ function isPayAtEndExpenseReport(reportID: string, transactions: Transaction[] | return false; } - return TransactionUtils.isPayAtEndExpense(transactions?.[0] ?? TransactionUtils.getAllReportTransactions(reportID)[0]); + return TransactionUtils.isPayAtEndExpense(transactions?.[0] ?? TransactionUtils.getAllReportTransactions(reportID).at(0)); } /** @@ -2160,7 +2160,7 @@ function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit .join(', '); } - return Localize.translateLocal('groupChat.defaultReportName', {displayName: getDisplayNameForParticipant(participantAccountIDs[0], false)}); + return Localize.translateLocal('groupChat.defaultReportName', {displayName: getDisplayNameForParticipant(participants[0], false)}); } function getParticipants(reportID: string) { @@ -3521,7 +3521,7 @@ function getAdminRoomInvitedParticipants(parentReportAction: OnyxEntry 1 ? participants.join(` ${Localize.translateLocal('common.and')} `) : participants[0]; + const users = participants.length > 1 ? participants.join(` ${Localize.translateLocal('common.and')} `) : participants.at(0); if (!users) { return parentReportActionMessage; } @@ -3589,7 +3589,7 @@ function parseReportActionHtmlToText(reportAction: OnyxEntry, repo const accountIDToName: Record = {}; const accountIDs = Array.from(html.matchAll(mentionUserRegex), (mention) => Number(mention[1])); const logins = PersonalDetailsUtils.getLoginsByAccountIDs(accountIDs); - accountIDs.forEach((id, index) => (accountIDToName[id] = logins[index])); + accountIDs.forEach((id, index) => (accountIDToName[id] = logins.at(index))); const textMessage = Str.removeSMSDomain(Parser.htmlToText(html, {reportIDToName, accountIDToName})); parsedReportActionMessageCache[key] = textMessage; @@ -3807,7 +3807,7 @@ function getPayeeName(report: OnyxEntry): string | undefined { if (participantsWithoutCurrentUser.length === 0) { return undefined; } - return getDisplayNameForParticipant(participantsWithoutCurrentUser[0], true); + return getDisplayNameForParticipant(participantsWithoutCurrentUser.at(0), true); } /** @@ -3883,7 +3883,7 @@ function navigateToDetailsPage(report: OnyxEntry) { const participantAccountID = getParticipantsAccountIDsForDisplay(report); if (isSelfDMReport || isOneOnOneChatReport) { - Navigation.navigate(ROUTES.PROFILE.getRoute(participantAccountID[0])); + Navigation.navigate(ROUTES.PROFILE.getRoute(participantAccountID.at(0))); return; } @@ -3900,7 +3900,7 @@ function goBackToDetailsPage(report: OnyxEntry) { const participantAccountID = getParticipantsAccountIDsForDisplay(report); if (isOneOnOneChatReport) { - Navigation.navigate(ROUTES.PROFILE.getRoute(participantAccountID[0])); + Navigation.navigate(ROUTES.PROFILE.getRoute(participantAccountID.at(0))); return; } @@ -3936,7 +3936,7 @@ function goBackFromPrivateNotes(report: OnyxEntry, session: OnyxEntry, sortedAndFiltered const newMarkerIndex = lodashFindLastIndex(sortedAndFilteredReportActions, (reportAction) => (reportAction.created ?? '') > (report?.lastReadTime ?? '')); - return 'reportActionID' in sortedAndFilteredReportActions[newMarkerIndex] ? sortedAndFilteredReportActions[newMarkerIndex].reportActionID : ''; + return 'reportActionID' in sortedAndFilteredReportActions.at(newMarkerIndex) ? sortedAndFilteredReportActions.at(newMarkerIndex).reportActionID : ''; } /** @@ -6223,7 +6223,7 @@ function parseReportRouteParams(route: string): ReportRouteParams { const pathSegments = parsingRoute.split('/'); - const reportIDSegment = pathSegments[1]; + const reportIDSegment = pathSegments.at(1); const hasRouteReportActionID = !Number.isNaN(Number(reportIDSegment)); // Check for "undefined" or any other unwanted string values @@ -6514,7 +6514,7 @@ function canLeaveRoom(report: OnyxEntry, isPolicyEmployee: boolean): boo } function isCurrentUserTheOnlyParticipant(participantAccountIDs?: number[]): boolean { - return !!(participantAccountIDs?.length === 1 && participantAccountIDs?.[0] === currentUserAccountID); + return !!(participantAccountIDs?.length === 1 && participantAccountIDs.at(0) === currentUserAccountID); } /** @@ -7246,13 +7246,13 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct const totalAncestor = ancestors.reportIDs.length; return Array.from(Array(totalAncestor), (_, index) => { - const ancestorReport = getReportOrDraftReport(ancestors.reportIDs[index]); + const ancestorReport = getReportOrDraftReport(ancestors.reportIDs.at(index)); if (!ancestorReport || isEmptyObject(ancestorReport)) { return null; } - const ancestorReportAction = ReportActionsUtils.getReportAction(ancestorReport.reportID, ancestors.reportActionsIDs[index]); + const ancestorReportAction = ReportActionsUtils.getReportAction(ancestorReport.reportID, ancestors.reportActionsIDs.at(index)); if (!ancestorReportAction || isEmptyObject(ancestorReportAction)) { return null; diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index bb49697a8345..c97f6465197c 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -11,7 +11,16 @@ import type {SearchAdvancedFiltersForm} from '@src/types/form'; import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm'; import type * as OnyxTypes from '@src/types/onyx'; import type SearchResults from '@src/types/onyx/SearchResults'; -import type {ListItemDataType, ListItemType, SearchDataTypes, SearchPersonalDetails, SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults'; +import type { + ListItemDataType, + ListItemType, + SearchAccountDetails, + SearchDataTypes, + SearchPersonalDetails, + SearchPolicyDetails, + SearchReport, + SearchTransaction, +} from '@src/types/onyx/SearchResults'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; import {translateLocal} from './Localize'; @@ -172,10 +181,11 @@ function getTransactionsSections(data: OnyxTypes.SearchResults['data'], metadata }); } -function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: SearchReport) { - const payerPersonalDetails = data.personalDetailsList?.[reportItem.managerID ?? 0]; - const payerName = payerPersonalDetails?.displayName ?? payerPersonalDetails?.login ?? translateLocal('common.hidden'); - const formattedAmount = CurrencyUtils.convertToDisplayString(reportItem.total ?? 0, reportItem.currency ?? CONST.CURRENCY.USD); +function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: SearchTransaction & Record & SearchPolicyDetails & SearchReport) { + const payerPersonalDetails = data.personalDetailsList?.[reportItem.managerID] as SearchAccountDetails; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const payerName = payerPersonalDetails?.name || payerPersonalDetails?.displayName || payerPersonalDetails?.login || translateLocal('common.hidden'); + const formattedAmount = CurrencyUtils.convertToDisplayString(reportItem.total ?? 0, reportItem?.currency ?? CONST.CURRENCY.USD); if (reportItem.action === CONST.SEARCH.ACTION_TYPES.VIEW) { return translateLocal('iou.payerOwesAmount', { payer: payerName, @@ -204,8 +214,13 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx const reportItem = {...data[key]}; const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportItem.reportID}`; const transactions = reportIDToTransactions[reportKey]?.transactions ?? []; + const isExpenseReport = reportItem.type === CONST.REPORT.TYPE.EXPENSE; const isIOUReport = reportItem.type === CONST.REPORT.TYPE.IOU; + const to = isExpenseReport + ? (data[`${ONYXKEYS.COLLECTION.POLICY}${reportItem.policyID}`] as SearchAccountDetails) + : (data.personalDetailsList?.[reportItem.managerID] as SearchAccountDetails); + reportIDToTransactions[reportKey] = { ...reportItem, keyForList: reportItem.reportID, @@ -547,7 +562,7 @@ function buildFilterString(filterName: string, queryFilters: QueryFilter[]) { let filterValueString = ''; queryFilters.forEach((queryFilter, index) => { // If the previous queryFilter has the same operator (this rule applies only to eq and neq operators) then append the current value - if ((queryFilter.operator === 'eq' && queryFilters[index - 1]?.operator === 'eq') || (queryFilter.operator === 'neq' && queryFilters[index - 1]?.operator === 'neq')) { + if ((queryFilter.operator === 'eq' && queryFilters.at(index - 1)?.operator === 'eq') || (queryFilter.operator === 'neq' && queryFilters.at(index - 1)?.operator === 'neq')) { filterValueString += ` ${sanitizeString(queryFilter.value.toString())}`; } else { filterValueString += ` ${filterName}${operatorToSignMap[queryFilter.operator]}${queryFilter.value}`; diff --git a/src/libs/SelectionScraper/index.ts b/src/libs/SelectionScraper/index.ts index 88726aa633b6..45540a33bacd 100644 --- a/src/libs/SelectionScraper/index.ts +++ b/src/libs/SelectionScraper/index.ts @@ -125,7 +125,7 @@ const replaceNodes = (dom: Node, isChildOfEditorElement: boolean): Node => { } else if (dom.name === 'div' && dom.children.length === 1 && isChildOfEditorElement) { // We are excluding divs that are children of our editor element and have only one child to prevent // additional newlines from being added in the HTML to Markdown conversion process. - return replaceNodes(dom.children[0], isChildOfEditorElement); + return replaceNodes(dom.children.at(0), isChildOfEditorElement); } // We need to preserve href attribute in order to copy links. diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 9ce8feb26868..2b5038be774f 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -49,7 +49,7 @@ Onyx.connect({ (reportAction) => ReportActionsUtils.shouldReportActionBeVisibleAsLastAction(reportAction) && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED, ); - visibleReportActionItems[reportID] = reportActionsForDisplay[reportActionsForDisplay.length - 1]; + visibleReportActionItems[reportID] = reportActionsForDisplay.at(reportActionsForDisplay.length - 1); }, }); @@ -294,7 +294,7 @@ function getOptionData({ const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); const participantPersonalDetailList = Object.values(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails)) as PersonalDetails[]; - const personalDetail = participantPersonalDetailList[0] ?? {}; + const personalDetail = participantPersonalDetailList.at(0) ?? {}; const hasErrors = Object.keys(result.allReportErrors ?? {}).length !== 0; result.isThread = ReportUtils.isChatThread(report); diff --git a/src/libs/StringUtils.ts b/src/libs/StringUtils.ts index 5cc80a9a9005..4754875d2067 100644 --- a/src/libs/StringUtils.ts +++ b/src/libs/StringUtils.ts @@ -94,7 +94,7 @@ function lineBreaksToSpaces(text = '') { function getFirstLine(text = '') { // Split the input string by newline characters and return the first element of the resulting array const lines = text.split('\n'); - return lines[0]; + return lines.at(0); } export default {sanitizeString, isEmptyString, removeInvisibleCharacters, normalizeAccents, normalizeCRLF, lineBreaksToSpaces, getFirstLine}; diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index a865b78a9bbf..d8c15433de7d 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -480,7 +480,7 @@ function getTagArrayFromName(tagName: string): string[] { function getTag(transaction: OnyxInputOrEntry, tagIndex?: number): string { if (tagIndex !== undefined) { const tagsArray = getTagArrayFromName(transaction?.tag ?? ''); - return tagsArray[tagIndex] ?? ''; + return tagsArray.at(tagIndex) ?? ''; } return transaction?.tag ?? ''; @@ -634,7 +634,7 @@ function getValidWaypoints(waypoints: WaypointCollection | undefined, reArrangeI let waypointIndex = -1; return waypointValues.reduce((acc, currentWaypoint, index) => { - const previousWaypoint = waypointValues[lastWaypointIndex]; + const previousWaypoint = waypointValues.at(lastWaypointIndex); // Check if the waypoint has a valid address if (!waypointHasValidAddress(currentWaypoint)) { @@ -961,7 +961,7 @@ function compareDuplicateTransactionFields(transactionID: string): {keep: Partia // Helper function to check if all fields are equal for a given key function areAllFieldsEqual(items: Array>, keyExtractor: (item: OnyxEntry) => string) { - const firstTransaction = transactions[0]; + const firstTransaction = transactions.at(0); return items.every((item) => keyExtractor(item) === keyExtractor(firstTransaction)); } @@ -976,7 +976,7 @@ function compareDuplicateTransactionFields(transactionID: string): {keep: Partia for (const fieldName in fieldsToCompare) { if (Object.prototype.hasOwnProperty.call(fieldsToCompare, fieldName)) { const keys = fieldsToCompare[fieldName]; - const firstTransaction = transactions[0]; + const firstTransaction = transactions.at(0); const isFirstTransactionCommentEmptyObject = typeof firstTransaction?.comment === 'object' && firstTransaction?.comment?.comment === ''; if (fieldName === 'description') { diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 3ac01c704443..3e0b33212f85 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -19,7 +19,7 @@ function getTagViolationsForSingleLevelTags( policyTagList: PolicyTagLists, ): TransactionViolation[] { const policyTagKeys = Object.keys(policyTagList); - const policyTagListName = policyTagKeys[0]; + const policyTagListName = policyTagKeys.at(0); const policyTags = policyTagList[policyTagListName]?.tags; const hasTagOutOfPolicyViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.TAG_OUT_OF_POLICY); const hasMissingTagViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.MISSING_TAG); @@ -93,8 +93,8 @@ function getTagViolationForIndependentTags(policyTagList: PolicyTagLists, transa const errorIndexes = []; for (let i = 0; i < policyTagKeys.length; i++) { const isTagRequired = policyTagList[policyTagKeys[i]].required ?? true; - const isTagSelected = !!selectedTags[i]; - if (isTagRequired && (!isTagSelected || (selectedTags.length === 1 && selectedTags[0] === ''))) { + const isTagSelected = !!selectedTags.at(i); + if (isTagRequired && (!isTagSelected || (selectedTags.length === 1 && selectedTags.at(0) === ''))) { errorIndexes.push(i); } } @@ -109,7 +109,7 @@ function getTagViolationForIndependentTags(policyTagList: PolicyTagLists, transa } else { let hasInvalidTag = false; for (let i = 0; i < policyTagKeys.length; i++) { - const selectedTag = selectedTags[i]; + const selectedTag = selectedTags.at(i); const tags = policyTagList[policyTagKeys[i]].tags; const isTagInPolicy = Object.values(tags).some((tag) => tag.name === selectedTag && !!tag.enabled); if (!isTagInPolicy && selectedTag) { @@ -117,7 +117,7 @@ function getTagViolationForIndependentTags(policyTagList: PolicyTagLists, transa name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY, type: CONST.VIOLATION_TYPES.VIOLATION, data: { - tagName: policyTagKeys[i], + tagName: policyTagKeys.at(i), }, }); hasInvalidTag = true; diff --git a/src/libs/WorkflowUtils.ts b/src/libs/WorkflowUtils.ts index d9a3782987f6..9bfd6e0ded5c 100644 --- a/src/libs/WorkflowUtils.ts +++ b/src/libs/WorkflowUtils.ts @@ -123,7 +123,7 @@ function convertPolicyEmployeesToApprovalWorkflows({employees, defaultApprover, return 1; } - return (a.approvers[0]?.displayName ?? '-1').localeCompare(b.approvers[0]?.displayName ?? '-1'); + return (a.approvers.at(0)?.displayName ?? '-1').localeCompare(b.approvers.at(0)?.displayName ?? '-1'); }); // Add a default workflow if one doesn't exist (no employees submit to the default approver) diff --git a/src/libs/actions/Card.ts b/src/libs/actions/Card.ts index 2356f125ff67..613684b2dd97 100644 --- a/src/libs/actions/Card.ts +++ b/src/libs/actions/Card.ts @@ -315,7 +315,7 @@ function clearIssueNewCardFlow() { }); } -function updateExpensifyCardLimit(workspaceAccountID: number, cardID: number, newLimit: number, newAvailableSpend: number, oldLimit?: number, oldAvailableSpend?: number) { +function updateExpensifyCardLimit(workspaceAccountID: number, cardID: number, newLimit: number, oldLimit?: number) { const authToken = NetworkStore.getAuthToken(); if (!authToken) { @@ -482,21 +482,6 @@ function issueExpensifyCard(policyID: string, feedCountry: string, data?: IssueN API.write(WRITE_COMMANDS.CREATE_ADMIN_ISSUED_VIRTUAL_CARD, parameters); } -function openCardDetailsPage(cardID: number) { - const authToken = NetworkStore.getAuthToken(); - - if (!authToken) { - return; - } - - const parameters: OpenCardDetailsPageParams = { - authToken, - cardID, - }; - - API.read(READ_COMMANDS.OPEN_CARD_DETAILS_PAGE, parameters); -} - export { requestReplacementExpensifyCard, activatePhysicalExpensifyCard, @@ -512,6 +497,5 @@ export { startIssueNewCardFlow, configureExpensifyCardsForPolicy, issueExpensifyCard, - openCardDetailsPage, }; export type {ReplacementReason}; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 9cc844849c89..b4f836fb8dc8 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3814,7 +3814,7 @@ function trackExpense( function getOrCreateOptimisticSplitChatReport(existingSplitChatReportID: string, participants: Participant[], participantAccountIDs: number[], currentUserAccountID: number) { // The existing chat report could be passed as reportID or exist on the sole "participant" (in this case a report option) - const existingChatReportID = existingSplitChatReportID || participants[0].reportID; + const existingChatReportID = existingSplitChatReportID || participants.at(0).reportID; // Check if the report is available locally if we do have one let existingSplitChatReport = existingChatReportID ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${existingChatReportID}`] : null; @@ -5087,7 +5087,7 @@ function createDistanceRequest( chatType: splitData.chatType, }; } else { - const participant = participants[0] ?? {}; + const participant = participants.at(0) ?? {}; const { iouReport, chatReport, @@ -5200,8 +5200,8 @@ function editRegularMoneyRequest( '', false, ); - updatedMoneyRequestReport.lastMessageText = ReportActionsUtils.getTextFromHtml(lastMessage[0].html); - updatedMoneyRequestReport.lastMessageHtml = lastMessage[0].html; + updatedMoneyRequestReport.lastMessageText = ReportActionsUtils.getTextFromHtml(lastMessage.at(0).html); + updatedMoneyRequestReport.lastMessageHtml = lastMessage.at(0).html; // Update the last message of the chat report const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(iouReport?.reportID); @@ -5563,9 +5563,9 @@ function prepareToCleanUpMoneyRequest(transactionID: string, reportAction: OnyxT }); if (ReportActionsUtils.getReportActionMessage(updatedReportPreviewAction)) { - if (Array.isArray(updatedReportPreviewAction?.message) && updatedReportPreviewAction.message?.[0]) { - updatedReportPreviewAction.message[0].text = messageText; - updatedReportPreviewAction.message[0].deleted = shouldDeleteIOUReport ? DateUtils.getDBTime() : ''; + if (Array.isArray(updatedReportPreviewAction?.message) && updatedReportPreviewAction.message.at(0)) { + updatedReportPreviewAction.message.at(0).text = messageText; + updatedReportPreviewAction.message.at(0).deleted = shouldDeleteIOUReport ? DateUtils.getDBTime() : ''; } else if (!Array.isArray(updatedReportPreviewAction.message) && updatedReportPreviewAction.message) { updatedReportPreviewAction.message.text = messageText; updatedReportPreviewAction.message.deleted = shouldDeleteIOUReport ? DateUtils.getDBTime() : ''; @@ -6367,7 +6367,7 @@ function getReportFromHoldRequestsOnyxData( failureData: OnyxUpdate[]; } { const {holdReportActions, holdTransactions} = getHoldReportActionsAndTransactions(iouReport.reportID); - const firstHoldTransaction = holdTransactions[0]; + const firstHoldTransaction = holdTransactions.at(0); const newParentReportActionID = rand64(); const optimisticExpenseReport = ReportUtils.buildOptimisticExpenseReport( @@ -6871,7 +6871,7 @@ function isLastApprover(approvalChain: string[]): boolean { if (approvalChain.length === 0) { return true; } - return approvalChain[approvalChain.length - 1] === currentUserEmail; + return approvalChain.at(approvalChain.length - 1) === currentUserEmail; } function approveMoneyRequest(expenseReport: OnyxEntry, full?: boolean) { @@ -7909,10 +7909,10 @@ function mergeDuplicates(params: TransactionMergeParams) { deleted: deletedTime, }, ...(Array.isArray(reportAction.message) && - !!reportAction.message[0] && { + !!reportAction.message.at(0) && { message: [ { - ...reportAction.message[0], + ...reportAction.message.at(0), deleted: deletedTime, }, ...reportAction.message.slice(1), diff --git a/src/libs/actions/OnyxUpdateManager/utils/index.ts b/src/libs/actions/OnyxUpdateManager/utils/index.ts index ffc8cbd989df..9957de512633 100644 --- a/src/libs/actions/OnyxUpdateManager/utils/index.ts +++ b/src/libs/actions/OnyxUpdateManager/utils/index.ts @@ -63,7 +63,7 @@ function detectGapsAndSplit(updates: DeferredUpdatesDictionary, clientLastUpdate // When "firstUpdateAfterGaps" is not set yet, we need to set it to the last update in the list, // because we will fetch all missing updates up to the previous one and can then always apply the last update in the deferred updates. - const firstUpdateAfterGapWithFallback = firstUpdateAfterGaps ?? Number(updateValues[updateValues.length - 1].lastUpdateID); + const firstUpdateAfterGapWithFallback = firstUpdateAfterGaps ?? Number(updateValues.at(updateValues.length - 1).lastUpdateID); let updatesAfterGaps: DeferredUpdatesDictionary = {}; if (gapExists) { diff --git a/src/libs/actions/Policy/DistanceRate.ts b/src/libs/actions/Policy/DistanceRate.ts index b81b180cca52..51dc2a1b035d 100644 --- a/src/libs/actions/Policy/DistanceRate.ts +++ b/src/libs/actions/Policy/DistanceRate.ts @@ -128,12 +128,12 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { if (!enabled) { const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; - const customUnitID = Object.keys(policy?.customUnits ?? {})[0]; + const customUnitID = Object.keys(policy?.customUnits ?? {}).at(0); const customUnit = customUnitID ? policy?.customUnits?.[customUnitID] : undefined; const rateEntries = Object.entries(customUnit?.rates ?? {}); // find the rate to be enabled after disabling the distance rate feature - const rateEntryToBeEnabled = rateEntries[0]; + const rateEntryToBeEnabled = rateEntries.at(0); onyxData.optimisticData?.push({ onyxMethod: Onyx.METHOD.MERGE, diff --git a/src/libs/actions/Policy/Member.ts b/src/libs/actions/Policy/Member.ts index 1b881f65c831..90a71a89c233 100644 --- a/src/libs/actions/Policy/Member.ts +++ b/src/libs/actions/Policy/Member.ts @@ -394,7 +394,7 @@ function removeMembers(accountIDs: number[], policyID: string) { optimisticClosedReportActions.forEach((reportAction, index) => { failureData.push({ onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChats?.[index]?.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChats.at(index)?.reportID}`, value: {[reportAction.reportActionID]: null}, }); }); @@ -483,7 +483,7 @@ function requestWorkspaceOwnerChange(policyID: string) { const changeOwnerErrors = Object.keys(policy?.errorFields?.changeOwner ?? {}); if (changeOwnerErrors && changeOwnerErrors.length > 0) { - const currentError = changeOwnerErrors[0]; + const currentError = changeOwnerErrors.at(0); if (currentError === CONST.POLICY.OWNERSHIP_ERRORS.AMOUNT_OWED) { ownershipChecks.shouldClearOutstandingBalance = true; } diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index d914e47e5204..b7a18d313559 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -208,7 +208,7 @@ function getPolicy(policyID: string | undefined): OnyxEntry { function getPrimaryPolicy(activePolicyID?: OnyxEntry): Policy | undefined { const activeAdminWorkspaces = PolicyUtils.getActiveAdminWorkspaces(allPolicies); const primaryPolicy: Policy | null | undefined = activeAdminWorkspaces.find((policy) => policy.id === activePolicyID); - return primaryPolicy ?? activeAdminWorkspaces[0]; + return primaryPolicy ?? activeAdminWorkspaces.at(0); } /** Check if the policy has invoicing company details */ @@ -1144,7 +1144,7 @@ function updateGeneralSettings(policyID: string, name: string, currencyValue?: s (request) => request.data?.policyID === policyID && request.command === WRITE_COMMANDS.CREATE_WORKSPACE && request.data?.policyName !== name, ); - const createWorkspaceRequest = persistedRequests[createWorkspaceRequestChangedIndex]; + const createWorkspaceRequest = persistedRequests.at(createWorkspaceRequestChangedIndex); if (createWorkspaceRequest) { const workspaceRequest: Request = { ...createWorkspaceRequest, @@ -1397,13 +1397,13 @@ function generateDefaultWorkspaceName(email = ''): string { if (!emailParts || emailParts.length !== 2) { return defaultWorkspaceName; } - const username = emailParts[0]; - const domain = emailParts[1]; + const username = emailParts.at(0); + const domain = emailParts.at(1); const userDetails = PersonalDetailsUtils.getPersonalDetailByEmail(sessionEmail); const displayName = userDetails?.displayName?.trim(); if (!PUBLIC_DOMAINS.some((publicDomain) => publicDomain === domain.toLowerCase())) { - defaultWorkspaceName = `${Str.UCFirst(domain.split('.')[0])}'s Workspace`; + defaultWorkspaceName = `${Str.UCFirst(domain.split('.').at(0))}'s Workspace`; } else if (displayName) { defaultWorkspaceName = `${Str.UCFirst(displayName)}'s Workspace`; } else if (PUBLIC_DOMAINS.some((publicDomain) => publicDomain === domain.toLowerCase())) { @@ -2314,7 +2314,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${announceChatReportID}`, value: { - [Object.keys(announceChatData)[0]]: { + [Object.keys(announceChatData).at(0)]: { pendingAction: null, }, }, @@ -2333,7 +2333,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`, value: { - [Object.keys(adminsChatData)[0]]: { + [Object.keys(adminsChatData).at(0)]: { pendingAction: null, }, }, @@ -2352,7 +2352,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChatReportID}`, value: { - [Object.keys(workspaceChatData)[0]]: { + [Object.keys(workspaceChatData).at(0)]: { pendingAction: null, }, }, diff --git a/src/libs/actions/Policy/ReportField.ts b/src/libs/actions/Policy/ReportField.ts index 9a56c719fd73..ee9d91ecf868 100644 --- a/src/libs/actions/Policy/ReportField.ts +++ b/src/libs/actions/Policy/ReportField.ts @@ -109,7 +109,7 @@ function createReportFieldsListValue(valueName: string) { */ function renameReportFieldsListValue(valueIndex: number, newValueName: string) { const listValuesCopy = [...listValues]; - listValuesCopy[valueIndex] = newValueName; + listValuesCopy.at(valueIndex) = newValueName; Onyx.merge(ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM_DRAFT, { [INPUT_IDS.LIST_VALUES]: listValuesCopy, @@ -123,7 +123,7 @@ function setReportFieldsListValueEnabled(valueIndexes: number[], enabled: boolea const disabledListValuesCopy = [...disabledListValues]; valueIndexes.forEach((valueIndex) => { - disabledListValuesCopy[valueIndex] = !enabled; + disabledListValuesCopy.at(valueIndex) = !enabled; }); Onyx.merge(ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM_DRAFT, { @@ -382,8 +382,8 @@ function updateReportFieldListValueEnabled(policyID: string, reportFieldID: stri const updatedReportField = cloneDeep(reportField); valueIndexes.forEach((valueIndex) => { - updatedReportField.disabledOptions[valueIndex] = !enabled; - const shouldResetDefaultValue = !enabled && reportField.defaultValue === reportField.values[valueIndex]; + updatedReportField.disabledOptions.at(valueIndex) = !enabled; + const shouldResetDefaultValue = !enabled && reportField.defaultValue === reportField.values.at(valueIndex); if (shouldResetDefaultValue) { updatedReportField.defaultValue = ''; @@ -460,7 +460,7 @@ function removeReportFieldListValue(policyID: string, reportFieldID: string, val valueIndexes .sort((a, b) => b - a) .forEach((valueIndex) => { - const shouldResetDefaultValue = reportField.defaultValue === reportField.values[valueIndex]; + const shouldResetDefaultValue = reportField.defaultValue === reportField.values.at(valueIndex); if (shouldResetDefaultValue) { updatedReportField.defaultValue = ''; diff --git a/src/libs/actions/Policy/Tag.ts b/src/libs/actions/Policy/Tag.ts index 49a285c12bbe..e528d007c211 100644 --- a/src/libs/actions/Policy/Tag.ts +++ b/src/libs/actions/Policy/Tag.ts @@ -115,7 +115,7 @@ function buildOptimisticPolicyRecentlyUsedTags(policyID?: string, transactionTag return; } - const tagListKey = policyTagKeys[index]; + const tagListKey = policyTagKeys.at(index) ?? ''; newOptimisticPolicyRecentlyUsedTags[tagListKey] = [...new Set([tag, ...(policyRecentlyUsedTags[tagListKey] ?? [])])]; }); @@ -123,7 +123,7 @@ function buildOptimisticPolicyRecentlyUsedTags(policyID?: string, transactionTag } function createPolicyTag(policyID: string, tagName: string) { - const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.[0] ?? {}; + const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {}).at(0) ?? {}; const newTagName = PolicyUtils.escapeTagName(tagName); const onyxData: OnyxData = { @@ -188,7 +188,7 @@ function createPolicyTag(policyID: string, tagName: string) { } function setWorkspaceTagEnabled(policyID: string, tagsToUpdate: Record, tagListIndex: number) { - const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.[tagListIndex] ?? {}; + const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {}).at(tagListIndex) ?? {}; const optimisticPolicyTagsData = { ...Object.keys(tagsToUpdate).reduce((acc, key) => { @@ -287,7 +287,7 @@ function setWorkspaceTagEnabled(policyID: string, tagsToUpdate: Record [ + Object.keys(policyTag?.tags).map((tagName) => [ tagName, { enabled: false, @@ -714,7 +714,7 @@ function setPolicyRequiresTag(policyID: string, requiresTag: boolean) { } function setPolicyTagsRequired(policyID: string, requiresTag: boolean, tagListIndex: number) { - const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.[tagListIndex] ?? {}; + const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {}).at(tagListIndex) ?? {}; if (!policyTag.name) { return; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 2611dae20d7e..9b70c716fd7b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -326,7 +326,7 @@ function subscribeToReportTypingEvents(reportID: string) { // login OR by 'Concierge'. If the pusher message comes from NewDot, it is keyed by accountID // since personal details are keyed by accountID. const normalizedTypingStatus = getNormalizedStatus(typingStatus); - const accountIDOrLogin = Object.keys(normalizedTypingStatus)[0]; + const accountIDOrLogin = Object.keys(normalizedTypingStatus).at(0); if (!accountIDOrLogin) { return; @@ -369,7 +369,7 @@ function subscribeToReportLeavingEvents(reportID: string) { // login OR by 'Concierge'. If the pusher message comes from NewDot, it is keyed by accountID // since personal details are keyed by accountID. const normalizedLeavingStatus = getNormalizedStatus(leavingStatus); - const accountIDOrLogin = Object.keys(normalizedLeavingStatus)[0]; + const accountIDOrLogin = Object.keys(normalizedLeavingStatus).at(0); if (!accountIDOrLogin) { return; @@ -852,8 +852,8 @@ function openReport( if (isCreatingNewReport) { // Change the method to set for new reports because it doesn't exist yet, is faster, // and we need the data to be available when we navigate to the chat page - optimisticData[0].onyxMethod = Onyx.METHOD.SET; - optimisticData[0].value = { + optimisticData.at(0).onyxMethod = Onyx.METHOD.SET; + optimisticData.at(0).value = { ...optimisticReport, reportName: CONST.REPORT.DEFAULT_REPORT_NAME, ...newReportObject, @@ -885,7 +885,7 @@ function openReport( const redundantParticipants: Record = {}; const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(participantLoginList); participantLoginList.forEach((login, index) => { - const accountID = participantAccountIDs[index]; + const accountID = participantAccountIDs.at(index); const isOptimisticAccount = !allPersonalDetails?.[accountID]; if (!isOptimisticAccount) { @@ -2059,7 +2059,7 @@ function updateDescription(reportID: string, previousValue: string, newValue: st pendingFields: {description: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, lastActorAccountID: currentUserAccountID, lastVisibleActionCreated: optimisticDescriptionUpdatedReportAction.created, - lastMessageText: (optimisticDescriptionUpdatedReportAction?.message as Message[])?.[0]?.text, + lastMessageText: optimisticDescriptionUpdatedReportAction?.message as Message[].at(0)?.text, }, }, { @@ -3326,7 +3326,7 @@ function completeOnboarding( // If the target report isn't opened, the permission field will not exist. So we should add the fallback permission for task report const fallbackPermission = isAccountIDOdd ? [CONST.REPORT.PERMISSIONS.READ] : [CONST.REPORT.PERMISSIONS.READ, CONST.REPORT.PERMISSIONS.WRITE]; - const actorAccountID = PersonalDetailsUtils.getAccountIDsByLogins([targetEmail])[0]; + const actorAccountID = PersonalDetailsUtils.getAccountIDsByLogins([targetEmail]).at(0); const targetChatReport = ReportUtils.getChatByParticipants([actorAccountID, currentUserAccountID]); const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {}; diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 6105b7cffd9e..d9678d1894d8 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -875,7 +875,7 @@ function getShareDestination(reportID: string, reports: OnyxCollection a.localeCompare(b))[0]; + const firstTaxID = Object.keys(policyTaxRates ?? {}) + .sort((a, b) => a.localeCompare(b)) + .at(0); if (!policyTaxRates) { console.debug('Policy or tax rates not found'); diff --git a/src/libs/actions/TeachersUnite.ts b/src/libs/actions/TeachersUnite.ts index ba67e579e95a..00b321e4783a 100644 --- a/src/libs/actions/TeachersUnite.ts +++ b/src/libs/actions/TeachersUnite.ts @@ -143,7 +143,7 @@ function addSchoolPrincipal(firstName: string, partnerUserID: string, lastName: onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseChatReportID}`, value: { - [Object.keys(expenseChatData)[0]]: { + [Object.keys(expenseChatData).at(0)]: { pendingAction: null, }, }, diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index d7223524b32b..2af45756a551 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -143,7 +143,7 @@ function removeWaypoint(transaction: OnyxEntry, currentIndex: strin return Promise.resolve(); } - const isRemovedWaypointEmpty = removed.length > 0 && !TransactionUtils.waypointHasValidAddress(removed[0] ?? {}); + const isRemovedWaypointEmpty = removed.length > 0 && !TransactionUtils.waypointHasValidAddress(removed.at(0) ?? {}); // When there are only two waypoints we are adding empty waypoint back if (totalWaypoints === 2 && (index === 0 || index === totalWaypoints - 1)) { @@ -311,7 +311,7 @@ function dismissDuplicateTransactionViolation(transactionIDs: string[], dissmiss onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID ?? '-1'}`, value: { - [optimisticDissmidedViolationReportActions[index].reportActionID]: optimisticDissmidedViolationReportActions[index] as ReportAction, + [optimisticDissmidedViolationReportActions.at(index).reportActionID]: optimisticDissmidedViolationReportActions.at(index) as ReportAction, }, })); const optimisticDataTransactionViolations: OnyxUpdate[] = currentTransactionViolations.map((transactionViolations) => ({ @@ -359,7 +359,7 @@ function dismissDuplicateTransactionViolation(transactionIDs: string[], dissmiss onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID ?? '-1'}`, value: { - [optimisticDissmidedViolationReportActions[index].reportActionID]: null, + [optimisticDissmidedViolationReportActions.at(index).reportActionID]: null, }, })); @@ -371,7 +371,7 @@ function dismissDuplicateTransactionViolation(transactionIDs: string[], dissmiss onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID ?? '-1'}`, value: { - [optimisticDissmidedViolationReportActions[index].reportActionID]: { + [optimisticDissmidedViolationReportActions.at(index).reportActionID]: { pendingAction: null, }, }, diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index 5e0b83f8521d..93dea1e2b80f 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -570,7 +570,7 @@ function playSoundForMessageType(pushJSON: OnyxServerUpdate[]) { const reportActionsOnly = pushJSON.filter((update) => update.key?.includes('reportActions_')); // "reportActions_5134363522480668" -> "5134363522480668" const reportID = reportActionsOnly - .map((value) => value.key.split('_')[1]) + .map((value) => value.key.split('_').at(1)) .find((reportKey) => reportKey === Navigation.getTopmostReportId() && Visibility.isVisible() && Visibility.hasFocus()); if (!reportID) { diff --git a/src/libs/actions/Workflow.ts b/src/libs/actions/Workflow.ts index 0b6c29c9890a..6ffabf9a23b7 100644 --- a/src/libs/actions/Workflow.ts +++ b/src/libs/actions/Workflow.ts @@ -119,7 +119,7 @@ function updateApprovalWorkflow(policyID: string, approvalWorkflow: ApprovalWork } const previousDefaultApprover = policy.approver ?? policy.owner; - const newDefaultApprover = approvalWorkflow.isDefault ? approvalWorkflow.approvers[0].email : undefined; + const newDefaultApprover = approvalWorkflow.isDefault ? approvalWorkflow.approvers.at(0).email : undefined; const previousEmployeeList = {...policy.employeeList}; const updatedEmployees = convertApprovalWorkflowToPolicyEmployees({approvalWorkflow, type: CONST.APPROVAL_WORKFLOW.TYPE.UPDATE, membersToRemove}); diff --git a/src/libs/fileDownload/FileUtils.ts b/src/libs/fileDownload/FileUtils.ts index c8520f3c66cd..bee731d08667 100644 --- a/src/libs/fileDownload/FileUtils.ts +++ b/src/libs/fileDownload/FileUtils.ts @@ -221,10 +221,10 @@ const readFileAsync: ReadFileAsync = (path, fileName, onSuccess, onFailure = () */ function base64ToFile(base64: string, filename: string): File { // Decode the base64 string - const byteString = atob(base64.split(',')[1]); + const byteString = atob(base64.split(',').at(1)); // Get the mime type from the base64 string - const mimeString = base64.split(',')[0].split(':')[1].split(';')[0]; + const mimeString = base64.split(',').at(0).split(':').at(1).split(';').at(0); // Convert byte string to Uint8Array const arrayBuffer = new ArrayBuffer(byteString.length); diff --git a/src/libs/fileDownload/index.desktop.ts b/src/libs/fileDownload/index.desktop.ts index de000f61b41b..a1909469c69c 100644 --- a/src/libs/fileDownload/index.desktop.ts +++ b/src/libs/fileDownload/index.desktop.ts @@ -25,7 +25,7 @@ const fileDownload: FileDownload = (url, fileName, successMessage, shouldOpenExt }, CONST.DOWNLOADS_TIMEOUT); const handleDownloadStatus = (...args: unknown[]) => { - const arg = Array.isArray(args) ? args[0] : null; + const arg = Array.isArray(args) ? args.at(0) : null; const eventUrl = arg && typeof arg === 'object' && 'url' in arg ? arg.url : null; if (eventUrl === url) { diff --git a/src/libs/mapChildrenFlat.ts b/src/libs/mapChildrenFlat.ts index 73009a3340d4..34527f4775c1 100644 --- a/src/libs/mapChildrenFlat.ts +++ b/src/libs/mapChildrenFlat.ts @@ -22,7 +22,7 @@ const mapChildrenFlat = (element: C, fn: (child: C, index: number) => T) = const mappedChildren = React.Children.map(element, fn); if (Array.isArray(mappedChildren) && mappedChildren.length === 1) { - return mappedChildren[0]; + return mappedChildren.at(0); } return mappedChildren; diff --git a/src/libs/memoize/cache/ArrayCache.ts b/src/libs/memoize/cache/ArrayCache.ts index 058efefdb1aa..bffe6462c7cf 100644 --- a/src/libs/memoize/cache/ArrayCache.ts +++ b/src/libs/memoize/cache/ArrayCache.ts @@ -16,7 +16,7 @@ function ArrayCache(config: CacheConfig): Cache { */ function getKeyIndex(key: K): number { for (let i = cache.length - 1; i >= 0; i--) { - if (keyComparator(cache[i][0], key)) { + if (keyComparator(cache.at(i)[0], key)) { return i; } } diff --git a/src/pages/EditReportFieldDropdown.tsx b/src/pages/EditReportFieldDropdown.tsx index ba6828eca782..7eb2c08cace6 100644 --- a/src/pages/EditReportFieldDropdown.tsx +++ b/src/pages/EditReportFieldDropdown.tsx @@ -102,7 +102,7 @@ function EditReportFieldDropdownPage({onSubmit, fieldKey, fieldValue, fieldOptio return [policyReportFieldOptions, header]; }, [recentlyUsedOptions, debouncedSearchValue, fieldValue, fieldOptions]); - const selectedOptionKey = useMemo(() => (sections?.[0]?.data ?? []).filter((option) => option.searchText === fieldValue)?.[0]?.keyForList, [sections, fieldValue]); + const selectedOptionKey = useMemo(() => (sections?.[0]?.data ?? []).filter((option) => option.searchText === fieldValue).at(0)?.keyForList, [sections, fieldValue]); return ( !reportField.disabledOptions[index])} + fieldOptions={reportField.values.filter((_value: string, index: number) => !reportField.disabledOptions.at(index))} onSubmit={handleReportFieldChange} /> )} diff --git a/src/pages/EnablePayments/IdologyQuestions.tsx b/src/pages/EnablePayments/IdologyQuestions.tsx index b9b0ac4eca34..1548337b3658 100644 --- a/src/pages/EnablePayments/IdologyQuestions.tsx +++ b/src/pages/EnablePayments/IdologyQuestions.tsx @@ -44,8 +44,8 @@ function IdologyQuestions({questions, idNumber}: IdologyQuestionsProps) { const [shouldHideSkipAnswer, setShouldHideSkipAnswer] = useState(false); const [userAnswers, setUserAnswers] = useState([]); - const currentQuestion = questions[currentQuestionIndex] || {}; - const possibleAnswers: Choice[] = currentQuestion.answer + const currentQuestion = questions.at(currentQuestionIndex) ?? {}; + const possibleAnswers: Choice[] = currentQuestion?.answer .map((answer) => { if (shouldHideSkipAnswer && answer === SKIP_QUESTION_TEXT) { return; @@ -61,7 +61,7 @@ function IdologyQuestions({questions, idNumber}: IdologyQuestionsProps) { const chooseAnswer = (answer: string) => { const tempAnswers: Answer[] = userAnswers.map((userAnswer) => ({...userAnswer})); - tempAnswers[currentQuestionIndex] = {question: currentQuestion.type, answer}; + tempAnswers.at(currentQuestionIndex) = {question: currentQuestion.type, answer}; setUserAnswers(tempAnswers); }; @@ -70,7 +70,7 @@ function IdologyQuestions({questions, idNumber}: IdologyQuestionsProps) { * Show next question or send all answers for Idology verifications when we've answered enough */ const submitAnswers = () => { - if (!userAnswers[currentQuestionIndex]) { + if (!userAnswers.at(currentQuestionIndex)) { return; } // Get the number of questions that were skipped by the user. @@ -83,7 +83,7 @@ function IdologyQuestions({questions, idNumber}: IdologyQuestionsProps) { // Auto skip any remaining questions if (tempAnswers.length < questions.length) { for (let i = tempAnswers.length; i < questions.length; i++) { - tempAnswers[i] = {question: questions[i].type, answer: SKIP_QUESTION_TEXT}; + tempAnswers.at(i) = {question: questions.at(i).type, answer: SKIP_QUESTION_TEXT}; } } diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 805fd90ab369..c34a88b48d16 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -214,7 +214,7 @@ function NewChatPage({isGroupChat}: NewChatPageProps) { if (option?.login) { login = option.login; } else if (selectedOptions.length === 1) { - login = selectedOptions[0].login ?? ''; + login = selectedOptions.at(0).login ?? ''; } if (!login) { Log.warn('Tried to create chat with empty login'); diff --git a/src/pages/ReimbursementAccount/BankAccountStep.tsx b/src/pages/ReimbursementAccount/BankAccountStep.tsx index 689b646f465a..3c59524cc2ee 100644 --- a/src/pages/ReimbursementAccount/BankAccountStep.tsx +++ b/src/pages/ReimbursementAccount/BankAccountStep.tsx @@ -187,8 +187,8 @@ function BankAccountStep({ { - const login = loginList?.[loginNames?.[0]] ?? {}; - Navigation.navigate(ROUTES.SETTINGS_CONTACT_METHOD_DETAILS.getRoute(login?.partnerUserID ?? loginNames?.[0])); + const login = loginList?.[loginNames.at(0)] ?? {}; + Navigation.navigate(ROUTES.SETTINGS_CONTACT_METHOD_DETAILS.getRoute(login?.partnerUserID ?? loginNames.at(0))); }} > {translate('bankAccount.validateAccountError.phrase4')} diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index de81d661cfff..9206d754f7b9 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -490,8 +490,8 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD if (isGroupChat && !isThread) { return ( SearchActions.updateAdvancedFilters({category: values}), []); - const safePaddingBottomStyle = useSafePaddingBottomStyle(); return ( - + (title ? Expensicons.Filters : popoverMenuItems[activeItemIndex]?.icon ?? Expensicons.Receipt), [activeItemIndex, popoverMenuItems, title]); - const menuTitle = useMemo(() => title ?? popoverMenuItems[activeItemIndex]?.text, [activeItemIndex, popoverMenuItems, title]); + const menuIcon = useMemo(() => (title ? Expensicons.Filters : popoverMenuItems.at(activeItemIndex)?.icon ?? Expensicons.Receipt), [activeItemIndex, popoverMenuItems, title]); + const menuTitle = useMemo(() => title ?? popoverMenuItems.at(activeItemIndex)?.text, [activeItemIndex, popoverMenuItems, title]); const titleViewStyles = title ? {...styles.flex1, ...styles.justifyContentCenter} : {}; return ( {shouldShowSubscript ? ( ) : ( diff --git a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.tsx b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.tsx index 3051bfb1689e..40d906d14d50 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.tsx +++ b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.tsx @@ -83,8 +83,8 @@ function SuggestionEmoji( const insertSelectedEmoji = useCallback( (highlightedEmojiIndexInner: number) => { const commentBeforeColon = value.slice(0, suggestionValues.colonIndex); - const emojiObject = suggestionValues.suggestedEmojis[highlightedEmojiIndexInner]; - const emojiCode = emojiObject.types?.[preferredSkinTone] ? emojiObject.types[preferredSkinTone] : emojiObject.code; + const emojiObject = suggestionValues.suggestedEmojis.at(highlightedEmojiIndexInner); + const emojiCode = emojiObject.types?.[preferredSkinTone] ? emojiObject.types.at(preferredSkinTone) : emojiObject.code; const commentAfterColonWithEmojiNameRemoved = value.slice(selection.end); updateComment(`${commentBeforeColon}${emojiCode} ${SuggestionsUtils.trimLeadingSpace(commentAfterColonWithEmojiNameRemoved)}`, true); diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx index 8d37a1915cbd..55c2cead443f 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx @@ -171,7 +171,7 @@ function SuggestionMention( } // Otherwise, the emails must be of the same private domain, so we should remove the domain part - return displayText.split('@')[0]; + return displayText.split('@').at(0); }, [currentUserPersonalDetails.login], ); @@ -193,7 +193,7 @@ function SuggestionMention( const insertSelectedMention = useCallback( (highlightedMentionIndexInner: number) => { const commentBeforeAtSign = value.slice(0, suggestionValues.atSignIndex); - const mentionObject = suggestionValues.suggestedMentions[highlightedMentionIndexInner]; + const mentionObject = suggestionValues.suggestedMentions.at(highlightedMentionIndexInner); const mentionCode = getMentionCode(mentionObject, suggestionValues.prefixType); const commentAfterMention = value.slice(suggestionValues.atSignIndex + suggestionValues.mentionPrefix.length + 1); @@ -357,7 +357,7 @@ function SuggestionMention( const leftString = newValue.substring(afterLastBreakLineIndex, selectionEnd); const words = leftString.split(CONST.REGEX.SPACE_OR_EMOJI); const lastWord: string = words.at(-1) ?? ''; - const secondToLastWord = words[words.length - 3]; + const secondToLastWord = words.at(words.length - 3); let atSignIndex: number | undefined; let suggestionWord = ''; diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 95a7332f0606..7b15d6823b0b 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -146,7 +146,7 @@ function ReportActionItemSingle({ const avatarIconIndex = report.isOwnPolicyExpenseChat || ReportUtils.isPolicyExpenseChat(report) ? 0 : 1; const reportIcons = ReportUtils.getIcons(report, {}); - secondaryAvatar = reportIcons[avatarIconIndex]; + secondaryAvatar = reportIcons.at(avatarIconIndex); } else { secondaryAvatar = {name: '', source: '', type: 'avatar'}; } diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index cb3db91e7bc8..9bbdb1aa0bda 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -223,7 +223,7 @@ function ReportActionsList({ */ const unreadMarkerReportActionID = useMemo(() => { const shouldDisplayNewMarker = (reportAction: OnyxTypes.ReportAction, index: number): boolean => { - const nextMessage = sortedVisibleReportActions[index + 1]; + const nextMessage = sortedVisibleReportActions.at(index + 1); const isCurrentMessageUnread = isMessageUnread(reportAction, unreadMarkerTime); const isNextMessageRead = !nextMessage || !isMessageUnread(nextMessage, unreadMarkerTime); let shouldDisplay = isCurrentMessageUnread && isNextMessageRead && !ReportActionsUtils.shouldHideNewMarker(reportAction); @@ -240,7 +240,7 @@ function ReportActionsList({ // Scan through each visible report action until we find the appropriate action to show the unread marker for (let index = 0; index < sortedVisibleReportActions.length; index++) { - const reportAction = sortedVisibleReportActions[index]; + const reportAction = sortedVisibleReportActions.at(index); if (shouldDisplayNewMarker(reportAction, index)) { return reportAction.reportActionID; } @@ -279,7 +279,7 @@ function ReportActionsList({ return; } - const mostRecentReportActionCreated = sortedVisibleReportActions[0]?.created ?? ''; + const mostRecentReportActionCreated = sortedVisibleReportActions.at(0)?.created ?? ''; if (mostRecentReportActionCreated <= unreadMarkerTime) { return; } @@ -290,14 +290,14 @@ function ReportActionsList({ // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [sortedVisibleReportActions]); - const lastActionIndex = sortedVisibleReportActions[0]?.reportActionID; + const lastActionIndex = sortedVisibleReportActions.at(0)?.reportActionID; const reportActionSize = useRef(sortedVisibleReportActions.length); - const hasNewestReportAction = sortedVisibleReportActions[0]?.created === report.lastVisibleActionCreated; + const hasNewestReportAction = sortedVisibleReportActions.at(0)?.created === report.lastVisibleActionCreated; const hasNewestReportActionRef = useRef(hasNewestReportAction); hasNewestReportActionRef.current = hasNewestReportAction; const previousLastIndex = useRef(lastActionIndex); - const isLastPendingActionIsDelete = sortedReportActions?.[0]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + const isLastPendingActionIsDelete = sortedReportActions.at(0)?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; const [isFloatingMessageCounterVisible, setIsFloatingMessageCounterVisible] = useState(false); const animatedStyles = useAnimatedStyle(() => ({ @@ -461,7 +461,7 @@ function ReportActionsList({ const firstVisibleReportActionID = useMemo(() => ReportActionsUtils.getFirstVisibleReportActionID(sortedReportActions, isOffline), [sortedReportActions, isOffline]); const shouldUseThreadDividerLine = useMemo(() => { - const topReport = sortedVisibleReportActions.length > 0 ? sortedVisibleReportActions[sortedVisibleReportActions.length - 1] : null; + const topReport = sortedVisibleReportActions.length > 0 ? sortedVisibleReportActions.at(sortedVisibleReportActions.length - 1) : null; if (topReport && topReport.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED) { return false; @@ -485,7 +485,7 @@ function ReportActionsList({ if (!isVisible || !isFocused) { if (!lastMessageTime.current) { - lastMessageTime.current = sortedVisibleReportActions[0]?.created ?? ''; + lastMessageTime.current = sortedVisibleReportActions.at(0)?.created ?? ''; } return; } diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index bc725d0f44b5..8199009993d6 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -165,7 +165,7 @@ function ReportActionsView({ } const actions = [...allReportActions]; - const lastAction = allReportActions[allReportActions.length - 1]; + const lastAction = allReportActions.at(allReportActions.length - 1); if (!ReportActionsUtils.isCreatedAction(lastAction)) { const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(String(report?.ownerAccountID), DateUtils.subtractMillisecondsFromDateTime(lastAction.created, 1)); @@ -198,7 +198,7 @@ function ReportActionsView({ false, false, false, - DateUtils.subtractMillisecondsFromDateTime(actions[actions.length - 1].created, 1), + DateUtils.subtractMillisecondsFromDateTime(actions.at(actions.length - 1).created, 1), ) as OnyxTypes.ReportAction; moneyRequestActions.push(optimisticIOUAction); actions.splice(actions.length - 1, 0, optimisticIOUAction); @@ -289,10 +289,10 @@ function ReportActionsView({ ); const hasMoreCached = reportActions.length < combinedReportActions.length; - const newestReportAction = useMemo(() => reportActions?.[0], [reportActions]); + const newestReportAction = useMemo(() => reportActions.at(0), [reportActions]); const mostRecentIOUReportActionID = useMemo(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActions), [reportActions]); const hasCachedActionOnFirstRender = useInitialValue(() => reportActions.length > 0); - const hasNewestReportAction = reportActions[0]?.created === report.lastVisibleActionCreated || reportActions[0]?.created === transactionThreadReport?.lastVisibleActionCreated; + const hasNewestReportAction = reportActions.at(0)?.created === report.lastVisibleActionCreated || reportActions.at(0)?.created === transactionThreadReport?.lastVisibleActionCreated; const oldestReportAction = useMemo(() => reportActions?.at(-1), [reportActions]); const hasCreatedAction = oldestReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED; diff --git a/src/pages/home/report/ReportTypingIndicator.tsx b/src/pages/home/report/ReportTypingIndicator.tsx index 3ff8f2b0eb8e..7a1c90ded34a 100755 --- a/src/pages/home/report/ReportTypingIndicator.tsx +++ b/src/pages/home/report/ReportTypingIndicator.tsx @@ -26,7 +26,7 @@ function ReportTypingIndicator({userTypingStatuses}: ReportTypingIndicatorProps) const styles = useThemeStyles(); const usersTyping = useMemo(() => Object.keys(userTypingStatuses ?? {}).filter((loginOrAccountID) => userTypingStatuses?.[loginOrAccountID]), [userTypingStatuses]); - const firstUserTyping = usersTyping[0]; + const firstUserTyping = usersTyping.at(0); const isUserTypingADisplayName = Number.isNaN(Number(firstUserTyping)); diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 8cad6d2fc45d..e41c8233e4ef 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -214,7 +214,7 @@ function FloatingActionButtonAndPopover( return ''; } if (quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && quickActionAvatars.length > 0) { - const name: string = ReportUtils.getDisplayNameForParticipant(+(quickActionAvatars[0]?.id ?? -1), true) ?? ''; + const name: string = ReportUtils.getDisplayNameForParticipant(+(quickActionAvatars.at(0)?.id ?? -1), true) ?? ''; return translate('quickAction.paySomeone', name); } const titleKey = getQuickActionTitle(quickAction?.action ?? ('' as QuickActionName)); @@ -228,7 +228,7 @@ function FloatingActionButtonAndPopover( if (quickActionAvatars.length === 0) { return false; } - const displayName = personalDetails?.[quickActionAvatars[0]?.id ?? -1]?.firstName ?? ''; + const displayName = personalDetails?.[quickActionAvatars.at(0)?.id ?? -1]?.firstName ?? ''; return quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && displayName.length === 0; }, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]); diff --git a/src/pages/iou/SplitBillDetailsPage.tsx b/src/pages/iou/SplitBillDetailsPage.tsx index 2f882d562b55..de2d30ee0ebb 100644 --- a/src/pages/iou/SplitBillDetailsPage.tsx +++ b/src/pages/iou/SplitBillDetailsPage.tsx @@ -71,7 +71,7 @@ function SplitBillDetailsPage({personalDetails, report, route, reportActions, tr let participants: Array; if (ReportUtils.isPolicyExpenseChat(report)) { participants = [ - OptionsListUtils.getParticipantsOption({accountID: participantAccountIDs[0], selected: true, reportID: ''}, personalDetails), + OptionsListUtils.getParticipantsOption({accountID: participantAccountIDs.at(0), selected: true, reportID: ''}, personalDetails), OptionsListUtils.getPolicyExpenseReportOption({...report, selected: true, reportID}), ]; } else { diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index 3d2f85ef6c62..c5259485e6e5 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -168,7 +168,7 @@ function MoneyRequestParticipantsSelector({participants = CONST.EMPTY_ARRAY, onF preferPolicyExpenseChat: isPaidGroupPolicy, }); return newOptions; - }, [areOptionsInitialized, defaultOptions, debouncedSearchTerm, participants, isPaidGroupPolicy]); + }, [areOptionsInitialized, defaultOptions, debouncedSearchTerm, participants]); /** * Returns the sections needed for the OptionsSelector diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 069f86ce0899..1ef904f8f8b4 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -214,11 +214,11 @@ function IOURequestStepAmount({ if (iouType === CONST.IOU.TYPE.PAY || iouType === CONST.IOU.TYPE.SEND) { if (paymentMethod && paymentMethod === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { - IOU.sendMoneyWithWallet(report, backendAmount, currency, '', currentUserPersonalDetails.accountID, participants[0]); + IOU.sendMoneyWithWallet(report, backendAmount, currency, '', currentUserPersonalDetails.accountID, participants.at(0)); return; } - IOU.sendMoneyElsewhere(report, backendAmount, currency, '', currentUserPersonalDetails.accountID, participants[0]); + IOU.sendMoneyElsewhere(report, backendAmount, currency, '', currentUserPersonalDetails.accountID, participants.at(0)); return; } if (iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.REQUEST) { @@ -230,7 +230,7 @@ function IOURequestStepAmount({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', {}, ); @@ -245,7 +245,7 @@ function IOURequestStepAmount({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', ); return; diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index b33ce6f56600..5b5d95710ef7 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -249,7 +249,7 @@ function IOURequestStepConfirmation({ transaction.merchant, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - selectedParticipants[0], + selectedParticipants.at(0), trimmedComment, receiptObj, transaction.category, @@ -283,7 +283,7 @@ function IOURequestStepConfirmation({ transaction.merchant, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - selectedParticipants[0], + selectedParticipants.at(0), trimmedComment, receiptObj, transaction.category, @@ -534,7 +534,7 @@ function IOURequestStepConfirmation({ (paymentMethod: PaymentMethodType | undefined) => { const currency = transaction?.currency; const trimmedComment = transaction?.comment?.comment?.trim() ?? ''; - const participant = participants?.[0]; + const participant = participants.at(0); if (!participant || !transaction?.amount || !currency) { return; diff --git a/src/pages/iou/request/step/IOURequestStepDistance.tsx b/src/pages/iou/request/step/IOURequestStepDistance.tsx index 1798a95490a7..8b55c0234d3a 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistance.tsx @@ -290,7 +290,7 @@ function IOURequestStepDistance({ translate('iou.fieldPending'), currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', {}, '', diff --git a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx index 81d9577d4d4d..39a23ae8931c 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx @@ -80,7 +80,7 @@ function IOURequestStepDistanceRate({ }; }); - const unit = (Object.values(rates)[0]?.unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? translate('common.mile') : translate('common.kilometer')) as Unit; + const unit = (Object.values(rates).at(0)?.unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? translate('common.mile') : translate('common.kilometer')) as Unit; const initiallyFocusedOption = sections.find((item) => item.isSelected)?.keyForList; diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index 7fbc8d260f8a..b02f8ea7e55a 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -47,7 +47,7 @@ function IOURequestStepParticipants({ const isFocused = useIsFocused(); // We need to set selectedReportID if user has navigated back from confirmation page and navigates to confirmation page with already selected participant - const selectedReportID = useRef(participants?.length === 1 ? participants[0]?.reportID ?? reportID : reportID); + const selectedReportID = useRef(participants?.length === 1 ? participants.at(0)?.reportID ?? reportID : reportID); const numberOfParticipants = useRef(participants?.length ?? 0); const iouRequestType = TransactionUtils.getRequestType(transaction); const isSplitRequest = iouType === CONST.IOU.TYPE.SPLIT; @@ -92,7 +92,7 @@ function IOURequestStepParticipants({ (val: Participant[]) => { HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); - const firstParticipantReportID = val[0]?.reportID ?? ''; + const firstParticipantReportID = val.at(0)?.reportID ?? ''; const rateID = DistanceRequestUtils.getCustomUnitRateID(firstParticipantReportID); const isInvoice = iouType === CONST.IOU.TYPE.INVOICE && ReportUtils.isInvoiceRoomWithID(firstParticipantReportID); numberOfParticipants.current = val.length; diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 528b3ab1e88f..858fecd384f0 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -277,7 +277,7 @@ function IOURequestStepScan({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', receipt, '', @@ -302,7 +302,7 @@ function IOURequestStepScan({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', receipt, '', @@ -332,7 +332,7 @@ function IOURequestStepScan({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', receipt, ); @@ -345,7 +345,7 @@ function IOURequestStepScan({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', receipt, ); diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 16e50fe5bc6c..2841dbb7030b 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -138,7 +138,7 @@ function IOURequestStepScan({ navigator.mediaDevices.enumerateDevices().then((devices) => { let lastBackDeviceId = ''; for (let i = devices.length - 1; i >= 0; i--) { - const device = devices[i]; + const device = devices.at(i); if (device.kind === 'videoinput') { lastBackDeviceId = device.deviceId; break; @@ -309,7 +309,7 @@ function IOURequestStepScan({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', receipt, '', @@ -334,7 +334,7 @@ function IOURequestStepScan({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', receipt, '', @@ -364,7 +364,7 @@ function IOURequestStepScan({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', receipt, ); @@ -377,7 +377,7 @@ function IOURequestStepScan({ '', currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, - participants[0], + participants.at(0), '', receipt, ); diff --git a/src/pages/settings/Wallet/ExpensifyCardPage.tsx b/src/pages/settings/Wallet/ExpensifyCardPage.tsx index 4fec05f51e13..5a26ff1ae679 100644 --- a/src/pages/settings/Wallet/ExpensifyCardPage.tsx +++ b/src/pages/settings/Wallet/ExpensifyCardPage.tsx @@ -134,8 +134,8 @@ function ExpensifyCardPage({ const hasDetectedDomainFraud = cardsToShow?.some((card) => card?.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN); const hasDetectedIndividualFraud = cardsToShow?.some((card) => card?.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.INDIVIDUAL); - const formattedAvailableSpendAmount = CurrencyUtils.convertToDisplayString(cardsToShow?.[0]?.availableSpend); - const {limitNameKey, limitTitleKey} = getLimitTypeTranslationKeys(cardsToShow?.[0]?.nameValuePairs?.limitType); + const formattedAvailableSpendAmount = CurrencyUtils.convertToDisplayString(cardsToShow.at(0)?.availableSpend); + const {limitNameKey, limitTitleKey} = getLimitTypeTranslationKeys(cardsToShow.at(0)?.nameValuePairs?.limitType); const goToGetPhysicalCardFlow = () => { let updatedDraftValues = draftValues; diff --git a/src/pages/settings/Wallet/PaymentMethodList.tsx b/src/pages/settings/Wallet/PaymentMethodList.tsx index 0d127e3346ae..e05d19413590 100644 --- a/src/pages/settings/Wallet/PaymentMethodList.tsx +++ b/src/pages/settings/Wallet/PaymentMethodList.tsx @@ -233,9 +233,9 @@ function PaymentMethodList({ // The card should be grouped to a specific domain and such domain already exists in a assignedCardsGrouped if (assignedCardsGrouped.some((item) => item.isGroupedCardDomain && item.description === card.domainName) && !isAdminIssuedVirtualCard) { const domainGroupIndex = assignedCardsGrouped.findIndex((item) => item.isGroupedCardDomain && item.description === card.domainName); - assignedCardsGrouped[domainGroupIndex].errors = {...assignedCardsGrouped[domainGroupIndex].errors, ...card.errors}; + assignedCardsGrouped.at(domainGroupIndex).errors = {...assignedCardsGrouped.at(domainGroupIndex).errors, ...card.errors}; if (card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN || card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.INDIVIDUAL) { - assignedCardsGrouped[domainGroupIndex].brickRoadIndicator = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; + assignedCardsGrouped.at(domainGroupIndex).brickRoadIndicator = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } return; } diff --git a/src/pages/settings/Wallet/TransferBalancePage.tsx b/src/pages/settings/Wallet/TransferBalancePage.tsx index a324c91ecb85..3d1a21d9cec1 100644 --- a/src/pages/settings/Wallet/TransferBalancePage.tsx +++ b/src/pages/settings/Wallet/TransferBalancePage.tsx @@ -96,7 +96,7 @@ function TransferBalancePage({bankAccountList, fundList, userWallet, walletTrans const filteredMethods = combinedPaymentMethods.filter((paymentMethod) => paymentMethod.accountType === filterPaymentMethodType); if (filteredMethods.length === 1) { - const account = filteredMethods[0]; + const account = filteredMethods.at(0); PaymentMethods.saveWalletTransferAccountTypeAndID(filterPaymentMethodType ?? '', account?.methodID?.toString() ?? '-1'); return; } diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 94fb454c4a2d..858a57f25aab 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -315,8 +315,8 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}: .filter((policy): policy is PolicyType => PolicyUtils.shouldShowPolicy(policy, !!isOffline)) .map((policy): WorkspaceItem => { if (policy?.isJoinRequestPending && policy?.policyDetailsForNonMembers) { - const policyInfo = Object.values(policy.policyDetailsForNonMembers)[0]; - const id = Object.keys(policy.policyDetailsForNonMembers)[0]; + const policyInfo = Object.values(policy.policyDetailsForNonMembers).at(0); + const id = Object.keys(policy.policyDetailsForNonMembers).at(0); return { title: policyInfo.name, icon: policyInfo.avatar ? policyInfo.avatar : ReportUtils.getDefaultWorkspaceAvatar(policy.name), diff --git a/src/pages/workspace/WorkspacesListRow.tsx b/src/pages/workspace/WorkspacesListRow.tsx index ac53252829fa..9f1984c20ebf 100644 --- a/src/pages/workspace/WorkspacesListRow.tsx +++ b/src/pages/workspace/WorkspacesListRow.tsx @@ -115,7 +115,7 @@ function WorkspacesListRow({ const threeDotsMenuContainerRef = useRef(null); const {shouldUseNarrowLayout} = useResponsiveLayout(); - const ownerDetails = ownerAccountID && PersonalDetailsUtils.getPersonalDetailsByIDs([ownerAccountID], currentUserPersonalDetails.accountID)[0]; + const ownerDetails = ownerAccountID && PersonalDetailsUtils.getPersonalDetailsByIDs([ownerAccountID], currentUserPersonalDetails.accountID).at(0); const userFriendlyWorkspaceType = useMemo(() => { switch (workspaceType) { diff --git a/src/pages/workspace/accounting/netsuite/NetSuiteSubsidiarySelector.tsx b/src/pages/workspace/accounting/netsuite/NetSuiteSubsidiarySelector.tsx index 21a3cadb95fb..4fd85238591b 100644 --- a/src/pages/workspace/accounting/netsuite/NetSuiteSubsidiarySelector.tsx +++ b/src/pages/workspace/accounting/netsuite/NetSuiteSubsidiarySelector.tsx @@ -91,7 +91,7 @@ function NetSuiteSubsidiarySelector({policy}: WithPolicyConnectionsProps) { listItem={RadioListItem} connectionName={CONST.POLICY.CONNECTIONS.NAME.NETSUITE} onSelectRow={updateSubsidiary} - initiallyFocusedOptionKey={netsuiteConfig?.subsidiaryID ?? subsidiaryListSections?.[0]?.keyForList} + initiallyFocusedOptionKey={netsuiteConfig?.subsidiaryID ?? subsidiaryListSections.at(0)?.keyForList} headerContent={listHeaderComponent} onBackButtonPress={() => Navigation.goBack()} title="workspace.netsuite.subsidiary" diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index a0b89e4e5baf..e73450933f10 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -116,7 +116,7 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID, - isSyncReimbursedSwitchOn ? '' : [...qboAccountOptions, ...invoiceAccountCollectionOptions][0].id, + isSyncReimbursedSwitchOn ? '' : [...qboAccountOptions, ...invoiceAccountCollectionOptions].at(0).id, ), pendingAction: pendingFields?.collectionAccountID, errors: ErrorUtils.getLatestErrorField(qboConfig ?? {}, CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID), diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksCompanyCardExpenseAccountSelectCardPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksCompanyCardExpenseAccountSelectCardPage.tsx index c36f7df6b245..4fef8922eb28 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksCompanyCardExpenseAccountSelectCardPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksCompanyCardExpenseAccountSelectCardPage.tsx @@ -71,7 +71,7 @@ function QuickbooksCompanyCardExpenseAccountSelectCardPage({policy}: WithPolicyC CONST.POLICY.CONNECTIONS.NAME.QBO, { [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION]: row.value, - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT]: row.accounts[0], + [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT]: row.accounts.at(0), [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: row.defaultVendor, }, { @@ -101,7 +101,7 @@ function QuickbooksCompanyCardExpenseAccountSelectCardPage({policy}: WithPolicyC ListItem={RadioListItem} onSelectRow={selectExportCompanyCard} shouldSingleExecuteRowSelect - initiallyFocusedOptionKey={sections[0].data.find((option) => option.isSelected)?.keyForList} + initiallyFocusedOptionKey={sections.at(0).data.find((option) => option.isSelected)?.keyForList} footerContent={ isLocationEnabled && {translate('workspace.qbo.companyCardsLocationEnabledDescription')} } diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksNonReimbursableDefaultVendorSelectPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksNonReimbursableDefaultVendorSelectPage.tsx index d57da414b57b..9f71e201e21b 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksNonReimbursableDefaultVendorSelectPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksNonReimbursableDefaultVendorSelectPage.tsx @@ -76,7 +76,7 @@ function QuickbooksNonReimbursableDefaultVendorSelectPage({policy}: WithPolicyCo ListItem={RadioListItem} onSelectRow={selectVendor} shouldSingleExecuteRowSelect - initiallyFocusedOptionKey={sections[0]?.data.find((mode) => mode.isSelected)?.keyForList} + initiallyFocusedOptionKey={sections.at(0)?.data.find((mode) => mode.isSelected)?.keyForList} listEmptyContent={listEmptyContent} /> diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksOutOfPocketExpenseEntitySelectPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksOutOfPocketExpenseEntitySelectPage.tsx index b0d8afa6d53b..fb6fcca5532b 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksOutOfPocketExpenseEntitySelectPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksOutOfPocketExpenseEntitySelectPage.tsx @@ -90,7 +90,7 @@ function QuickbooksOutOfPocketExpenseEntitySelectPage({policy}: WithPolicyConnec CONST.POLICY.CONNECTIONS.NAME.QBO, { [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION]: row.value, - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: row.accounts[0], + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: row.accounts.at(0), }, { [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION]: reimbursableExpensesExportDestination, diff --git a/src/pages/workspace/expensifyCard/WorkspaceCardsListLabel.tsx b/src/pages/workspace/expensifyCard/WorkspaceCardsListLabel.tsx index c0566d71f686..5cb6b770d734 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceCardsListLabel.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceCardsListLabel.tsx @@ -52,7 +52,7 @@ function WorkspaceCardsListLabel({type, value, style}: WorkspaceCardsListLabelPr const policyCurrency = useMemo(() => policy?.outputCurrency ?? CONST.CURRENCY.USD, [policy]); // TODO: instead of the first bankAccount on the list get settlementBankAccountID from the private_expensifyCardSettings NVP and check if that is connected via Plaid. - const isConnectedWithPlaid = useMemo(() => !!Object.values(bankAccountList ?? {})[0]?.accountData?.additionalData?.plaidAccountID, [bankAccountList]); + const isConnectedWithPlaid = useMemo(() => !!Object.values(bankAccountList ?? {}).at(0)?.accountData?.additionalData?.plaidAccountID, [bankAccountList]); useEffect(() => { if (!anchorRef.current || !isVisible) { diff --git a/src/pages/workspace/expensifyCard/WorkspaceEditCardLimitPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceEditCardLimitPage.tsx index 3b44654b754a..fe9a34a45959 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceEditCardLimitPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceEditCardLimitPage.tsx @@ -52,24 +52,16 @@ function WorkspaceEditCardLimitPage({route}: WorkspaceEditCardLimitPageProps) { } }, [card?.nameValuePairs?.limitType]); - const getNewAvailableSpend = (newLimit: number) => { - const currentLimit = card?.nameValuePairs?.unapprovedExpenseLimit ?? 0; - const currentSpend = currentLimit - (card?.availableSpend ?? 0); - - return newLimit - currentSpend; - }; - - const updateCardLimit = (newLimit: number) => { - const newAvailableSpend = getNewAvailableSpend(newLimit); - setIsConfirmModalVisible(false); - Card.updateExpensifyCardLimit(workspaceAccountID, Number(cardID), newLimit, newAvailableSpend, card?.nameValuePairs?.unapprovedExpenseLimit, card?.availableSpend); + Card.updateExpensifyCardLimit(workspaceAccountID, Number(cardID), Number(newLimit) * 100, card?.nameValuePairs?.unapprovedExpenseLimit); Navigation.goBack(); }; const submit = (values: FormOnyxValues) => { + const currentLimit = card?.nameValuePairs?.unapprovedExpenseLimit ?? 0; + const currentSpend = currentLimit - (card?.availableSpend ?? 0); const newLimit = Number(values[INPUT_IDS.LIMIT]) * 100; const newAvailableSpend = getNewAvailableSpend(newLimit); diff --git a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardDetailsPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardDetailsPage.tsx index 510a7a778100..49ac71ac5f1d 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardDetailsPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardDetailsPage.tsx @@ -45,6 +45,7 @@ function WorkspaceExpensifyCardDetailsPage({route}: WorkspaceExpensifyCardDetail const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); + // TODO: add an API call to load the card details data: https://github.com/Expensify/App/issues/47231 const card = cardsList?.[cardID]; const cardholder = personalDetails?.[card?.accountID ?? -1]; const isVirtual = !!card?.nameValuePairs?.isVirtual; @@ -53,14 +54,6 @@ function WorkspaceExpensifyCardDetailsPage({route}: WorkspaceExpensifyCardDetail const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(cardholder); const translationForLimitType = CardUtils.getTranslationKeyForLimitType(card?.nameValuePairs?.limitType); - const fetchCardDetails = useCallback(() => { - Card.openCardDetailsPage(Number(cardID)); - }, [cardID]); - - const {isOffline} = useNetwork({onReconnect: fetchCardDetails}); - - useEffect(() => fetchCardDetails(), [fetchCardDetails]); - const deactivateCard = () => { setIsDeactivateModalVisible(false); diff --git a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx index c27d5a7168ba..783b6ec42539 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx @@ -47,7 +47,17 @@ function WorkspaceExpensifyCardListPage({route, cardsList}: WorkspaceExpensifyCa const policyCurrency = useMemo(() => policy?.outputCurrency ?? CONST.CURRENCY.USD, [policy]); - const sortedCards = useMemo(() => CardUtils.sortCardsByCardholderName(cardsList, personalDetails), [cardsList, personalDetails]); + const sortedCards = useMemo( + () => + Object.values(cardsList ?? {}).sort((cardA: Card, cardB: Card) => { + const userA = personalDetails?.[cardA.accountID ?? '-1'] ?? {}; + const userB = personalDetails?.[cardB.accountID ?? '-1'] ?? {}; + const aName = PersonalDetailsUtils.getDisplayNameOrDefault(userA); + const bName = PersonalDetailsUtils.getDisplayNameOrDefault(userB); + return localeCompare(aName, bName); + }), + [cardsList, personalDetails], + ); const getHeaderButtons = () => ( diff --git a/src/pages/workspace/members/WorkspaceOwnerChangeCheck.tsx b/src/pages/workspace/members/WorkspaceOwnerChangeCheck.tsx index 52d60dbd618d..344aafeedde6 100644 --- a/src/pages/workspace/members/WorkspaceOwnerChangeCheck.tsx +++ b/src/pages/workspace/members/WorkspaceOwnerChangeCheck.tsx @@ -44,7 +44,7 @@ function WorkspaceOwnerChangeCheck({personalDetails, policy, accountID, error}: const updateDisplayTexts = useCallback(() => { const changeOwnerErrors = Object.keys(policy?.errorFields?.changeOwner ?? {}); - if (error !== changeOwnerErrors[0]) { + if (error !== changeOwnerErrors.at(0)) { return; } diff --git a/src/pages/workspace/members/WorkspaceOwnerChangeWrapperPage.tsx b/src/pages/workspace/members/WorkspaceOwnerChangeWrapperPage.tsx index f6ab69b1e9c5..0213b77158ae 100644 --- a/src/pages/workspace/members/WorkspaceOwnerChangeWrapperPage.tsx +++ b/src/pages/workspace/members/WorkspaceOwnerChangeWrapperPage.tsx @@ -51,7 +51,7 @@ function WorkspaceOwnerChangeWrapperPage({route, policy}: WorkspaceOwnerChangeWr const changeOwnerErrors = Object.keys(policy?.errorFields?.changeOwner ?? {}); if (changeOwnerErrors && changeOwnerErrors.length > 0) { - Navigation.navigate(ROUTES.WORKSPACE_OWNER_CHANGE_CHECK.getRoute(policyID, accountID, changeOwnerErrors[0] as ValueOf)); + Navigation.navigate(ROUTES.WORKSPACE_OWNER_CHANGE_CHECK.getRoute(policyID, accountID, changeOwnerErrors.at(0) as ValueOf)); } }, [accountID, policy, policy?.errorFields?.changeOwner, policyID]); diff --git a/src/pages/workspace/members/WorkspaceOwnerPaymentCardForm.tsx b/src/pages/workspace/members/WorkspaceOwnerPaymentCardForm.tsx index 91e22fd9fcd5..ef9fd84dee39 100644 --- a/src/pages/workspace/members/WorkspaceOwnerPaymentCardForm.tsx +++ b/src/pages/workspace/members/WorkspaceOwnerPaymentCardForm.tsx @@ -34,7 +34,7 @@ function WorkspaceOwnerPaymentCardForm({policy}: WorkspaceOwnerPaymentCardFormPr const checkIfCanBeRendered = useCallback(() => { const changeOwnerErrors = Object.keys(policy?.errorFields?.changeOwner ?? {}); - if (changeOwnerErrors[0] !== CONST.POLICY.OWNERSHIP_ERRORS.NO_BILLING_CARD) { + if (changeOwnerErrors.at(0) !== CONST.POLICY.OWNERSHIP_ERRORS.NO_BILLING_CARD) { setShouldShowPaymentCardForm(false); } diff --git a/src/pages/workspace/reportFields/InitialListValueSelector/ReportFieldsInitialListValuePicker.tsx b/src/pages/workspace/reportFields/InitialListValueSelector/ReportFieldsInitialListValuePicker.tsx index 4e6328bbc36b..5d138f98d1e4 100644 --- a/src/pages/workspace/reportFields/InitialListValueSelector/ReportFieldsInitialListValuePicker.tsx +++ b/src/pages/workspace/reportFields/InitialListValueSelector/ReportFieldsInitialListValuePicker.tsx @@ -22,7 +22,7 @@ function ReportFieldsInitialListValuePicker({listValues, disabledOptions, value, () => [ { data: Object.values(listValues ?? {}) - .filter((listValue, index) => !disabledOptions[index]) + .filter((listValue, index) => !disabledOptions.at(index)) .sort(localeCompare) .map((listValue) => ({ keyForList: listValue, @@ -40,7 +40,7 @@ function ReportFieldsInitialListValuePicker({listValues, disabledOptions, value, sections={listValueSections} ListItem={RadioListItem} onSelectRow={(item) => onValueChange(item.value)} - initiallyFocusedOptionKey={listValueSections[0].data.find((listValue) => listValue.isSelected)?.keyForList} + initiallyFocusedOptionKey={listValueSections.at(0).data.find((listValue) => listValue.isSelected)?.keyForList} /> ); } diff --git a/src/pages/workspace/reportFields/ReportFieldTypePicker/index.tsx b/src/pages/workspace/reportFields/ReportFieldTypePicker/index.tsx index 599d7ae0da99..0bec71bbff4a 100644 --- a/src/pages/workspace/reportFields/ReportFieldTypePicker/index.tsx +++ b/src/pages/workspace/reportFields/ReportFieldTypePicker/index.tsx @@ -48,7 +48,7 @@ function ReportFieldTypePicker({defaultValue, onOptionSelected}: ReportFieldType sections={typeSections} ListItem={RadioListItem} onSelectRow={onOptionSelected} - initiallyFocusedOptionKey={typeSections[0].data.find((reportField) => reportField.isSelected)?.keyForList} + initiallyFocusedOptionKey={typeSections.at(0).data.find((reportField) => reportField.isSelected)?.keyForList} /> ); } diff --git a/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx b/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx index 61967a729cd3..08bcbb094522 100644 --- a/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx +++ b/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx @@ -93,11 +93,11 @@ function ReportFieldsListValuesPage({ text: value, keyForList: value, isSelected: selectedValues[value] && canSelectMultiple, - enabled: !disabledListValues[index] ?? true, + enabled: !disabledListValues.at(index) ?? true, rightElement: ( ), })) @@ -187,13 +187,13 @@ function ReportFieldsListValuesPage({ } const enabledValues = selectedValuesArray.filter((valueName) => { const index = listValues?.indexOf(valueName) ?? -1; - return !disabledListValues?.[index]; + return !disabledListValues.at(index); }); if (enabledValues.length > 0) { const valuesToDisable = selectedValuesArray.reduce((acc, valueName) => { const index = listValues?.indexOf(valueName) ?? -1; - if (!disabledListValues?.[index] && index !== -1) { + if (!disabledListValues.at(index) && index !== -1) { acc.push(index); } @@ -219,13 +219,13 @@ function ReportFieldsListValuesPage({ const disabledValues = selectedValuesArray.filter((valueName) => { const index = listValues?.indexOf(valueName) ?? -1; - return disabledListValues?.[index]; + return disabledListValues.at(index); }); if (disabledValues.length > 0) { const valuesToEnable = selectedValuesArray.reduce((acc, valueName) => { const index = listValues?.indexOf(valueName) ?? -1; - if (disabledListValues?.[index] && index !== -1) { + if (disabledListValues.at(index) && index !== -1) { acc.push(index); } diff --git a/src/pages/workspace/reportFields/ReportFieldsValueSettingsPage.tsx b/src/pages/workspace/reportFields/ReportFieldsValueSettingsPage.tsx index 977e64c882f1..c888f86bb65c 100644 --- a/src/pages/workspace/reportFields/ReportFieldsValueSettingsPage.tsx +++ b/src/pages/workspace/reportFields/ReportFieldsValueSettingsPage.tsx @@ -47,8 +47,8 @@ function ReportFieldsValueSettingsPage({ if (reportFieldID) { const reportFieldKey = ReportUtils.getReportFieldKey(reportFieldID); - reportFieldValue = Object.values(policy?.fieldList?.[reportFieldKey]?.values ?? {})?.[valueIndex] ?? ''; - reportFieldDisabledValue = Object.values(policy?.fieldList?.[reportFieldKey]?.disabledOptions ?? {})?.[valueIndex] ?? false; + reportFieldValue = Object.values(policy?.fieldList?.[reportFieldKey]?.values ?? {}).at(valueIndex) ?? ''; + reportFieldDisabledValue = Object.values(policy?.fieldList?.[reportFieldKey]?.disabledOptions ?? {}).at(valueIndex) ?? false; } else { reportFieldValue = formDraft?.listValues?.[valueIndex] ?? ''; reportFieldDisabledValue = formDraft?.disabledListValues?.[valueIndex] ?? false; diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index adf200a99dd1..da1cc01bd99a 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -105,7 +105,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { ), })); } - const sortedTags = lodashSortBy(Object.values(policyTagLists[0]?.tags ?? {}), 'name', localeCompare) as PolicyTag[]; + const sortedTags = lodashSortBy(Object.values(policyTagLists.at(0)?.tags ?? {}), 'name', localeCompare) as PolicyTag[]; return sortedTags.map((tag) => ({ value: tag.name, text: PolicyUtils.getCleanedTagName(tag.name), diff --git a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx index 530554388285..d249a628687d 100644 --- a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx @@ -36,7 +36,7 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag const styles = useThemeStyles(); const {translate} = useLocalize(); const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]); - const isLoading = !PolicyUtils.getTagLists(policyTags)?.[0] || Object.keys(policyTags ?? {})[0] === 'undefined'; + const isLoading = !PolicyUtils.getTagLists(policyTags).at(0) || Object.keys(policyTags ?? {}).at(0) === 'undefined'; const {isOffline} = useNetwork(); const hasEnabledOptions = OptionsListUtils.hasEnabledOptions(Object.values(policyTags ?? {}).flatMap(({tags}) => Object.values(tags))); const updateWorkspaceRequiresTag = useCallback( @@ -67,15 +67,15 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag {!isMultiLevelTags && ( Tag.clearPolicyTagListErrors(policyID, policyTagLists[0].orderWeight)} - pendingAction={policyTags?.[policyTagLists[0]?.name]?.pendingAction} + errors={policyTags?.[policyTagLists.at(0)?.name]?.errors} + onClose={() => Tag.clearPolicyTagListErrors(policyID, policyTagLists.at(0).orderWeight)} + pendingAction={policyTags?.[policyTagLists.at(0)?.name]?.pendingAction} errorRowStyles={styles.mh5} > Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(policyID, policyTagLists[0].orderWeight))} + onPress={() => Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(policyID, policyTagLists.at(0).orderWeight))} shouldShowRightIcon /> diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index 18b1314c9b1e..adc96394edde 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -179,7 +179,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr > Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EDIT.getRoute(route.params.policyID, workflow.approvers[0].email))} + onPress={() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EDIT.getRoute(route.params.policyID, workflow.approvers.at(0).email))} /> ))} diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx index d127a13df240..bc937e85bc9c 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx @@ -137,7 +137,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, personalDetails, isLoadingR }, [formattedPolicyAdmins, formattedAuthorizedPayer, translate, searchTerm]); const headerMessage = useMemo( - () => (searchTerm && !sections[0].data.length ? translate('common.noResultsFound') : ''), + () => (searchTerm && !sections.at(0).data.length ? translate('common.noResultsFound') : ''), // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps [translate, sections], diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx index 545c09f75313..e2578997d211 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx @@ -220,7 +220,7 @@ function WorkspaceWorkflowsApprovalsApproverPageBeta({policy, personalDetails, i setSelectedApproverEmail(approver.login); }; - const headerMessage = useMemo(() => (searchTerm && !sections[0].data.length ? translate('common.noResultsFound') : ''), [searchTerm, sections, translate]); + const headerMessage = useMemo(() => (searchTerm && !sections.at(0).data.length ? translate('common.noResultsFound') : ''), [searchTerm, sections, translate]); return ( (searchTerm && !sections[0].data.length ? translate('common.noResultsFound') : ''), + () => (searchTerm && !sections.at(0).data.length ? translate('common.noResultsFound') : ''), // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps [translate, sections], diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx index 413a8787ee34..13d085b1b9c2 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx @@ -168,7 +168,7 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat setSelectedMembers(isAlreadySelected ? selectedMembers.filter((selectedOption) => selectedOption.login !== member.login) : [...selectedMembers, {...member, isSelected: true}]); }; - const headerMessage = useMemo(() => (searchTerm && !sections[0].data.length ? translate('common.noResultsFound') : ''), [searchTerm, sections, translate]); + const headerMessage = useMemo(() => (searchTerm && !sections.at(0).data.length ? translate('common.noResultsFound') : ''), [searchTerm, sections, translate]); return ( ): EReceiptColo const colorHash = UserUtils.hashText(transactionID.trim(), eReceiptColors.length); - return eReceiptColors[colorHash]; + return eReceiptColors.at(colorHash); } /** @@ -478,7 +478,7 @@ function getBackgroundColorWithOpacityStyle(backgroundColor: string, opacity: nu const result = hexadecimalToRGBArray(backgroundColor); if (result !== undefined) { return { - backgroundColor: `rgba(${result[0]}, ${result[1]}, ${result[2]}, ${opacity})`, + backgroundColor: `rgba(${result.at(0)}, ${result.at(1)}, ${result.at(2)}, ${opacity})`, }; } return {}; diff --git a/src/types/onyx/ExpensifyCardSettings.ts b/src/types/onyx/ExpensifyCardSettings.ts index 05c6667e7c05..e9eb94dbd8c4 100644 --- a/src/types/onyx/ExpensifyCardSettings.ts +++ b/src/types/onyx/ExpensifyCardSettings.ts @@ -9,7 +9,7 @@ type ExpensifyCardSettings = OnyxCommon.OnyxValueWithOfflineFeedback<{ remainingLimit?: number; /** The total amount of cash back earned thus far */ - earnedCashback?: number; + earnedCashback: number; /** The date of the last settlement */ monthlySettlementDate: Date; diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 228a49e263f7..3ce17c20e623 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -213,6 +213,10 @@ type SearchTransaction = { isFromOneTransactionReport?: boolean; }; + /** Whether the transaction report has only a single transaction */ + isFromOneTransactionReport?: boolean; +}; + /** Types of searchable transactions */ type SearchTransactionType = ValueOf; @@ -230,4 +234,16 @@ type SearchResults = { export default SearchResults; -export type {ListItemType, ListItemDataType, SearchTransaction, SearchTransactionType, SearchTransactionAction, SearchPersonalDetails, SearchDataTypes, SearchReport, SectionsType}; +export type { + ListItemType, + ListItemDataType, + SearchTransaction, + SearchTransactionType, + SearchTransactionAction, + SearchPersonalDetails, + SearchPolicyDetails, + SearchAccountDetails, + SearchDataTypes, + SearchReport, + SectionsType, +}; diff --git a/src/utils/arraysEqual.ts b/src/utils/arraysEqual.ts index 3a8111cc7bb7..1760cccc279f 100644 --- a/src/utils/arraysEqual.ts +++ b/src/utils/arraysEqual.ts @@ -15,7 +15,7 @@ function arraysEqual(a: T[], b: T[]): boolean { // you might want to clone your array first. for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) { + if (a.at(i) !== b.at(i)) { return false; } } diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 405760435d14..28b38a092745 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -94,9 +94,9 @@ describe('actions/IOU', () => { const iouReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.IOU); expect(Object.keys(chatReports).length).toBe(2); expect(Object.keys(iouReports).length).toBe(1); - const chatReport = chatReports[0]; - const transactionThreadReport = chatReports[1]; - const iouReport = iouReports[0]; + const chatReport = chatReports.at(0); + const transactionThreadReport = chatReports.at(1); + const iouReport = iouReports.at(0); iouReportID = iouReport?.reportID; transactionThread = transactionThreadReport; @@ -130,8 +130,8 @@ describe('actions/IOU', () => { ); expect(Object.values(createdActions).length).toBe(1); expect(Object.values(iouActions).length).toBe(1); - createdAction = createdActions?.[0] ?? null; - iouAction = iouActions?.[0] ?? null; + createdAction = createdActions.at(0) ?? null; + iouAction = iouActions.at(0) ?? null; const originalMessage = ReportActionsUtils.isMoneyRequestAction(iouAction) ? ReportActionsUtils.getOriginalMessage(iouAction) : undefined; // The CREATED action should not be created after the IOU action @@ -173,7 +173,7 @@ describe('actions/IOU', () => { (reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, ); expect(Object.values(createdActions).length).toBe(1); - transactionThreadCreatedAction = createdActions[0]; + transactionThreadCreatedAction = createdActions.at(0); expect(transactionThreadCreatedAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); resolve(); @@ -631,11 +631,11 @@ describe('actions/IOU', () => { const iouReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.IOU); expect(Object.values(chatReports).length).toBe(2); expect(Object.values(iouReports).length).toBe(1); - const chatReport = chatReports[0]; + const chatReport = chatReports.at(0); chatReportID = chatReport?.reportID; - transactionThreadReport = chatReports[1]; + transactionThreadReport = chatReports.at(1); - const iouReport = iouReports[0]; + const iouReport = iouReports.at(0); iouReportID = iouReport?.reportID; expect(iouReport?.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); @@ -669,8 +669,8 @@ describe('actions/IOU', () => { ) ?? null; expect(Object.values(createdActions).length).toBe(1); expect(Object.values(iouActions).length).toBe(1); - createdAction = createdActions[0]; - iouAction = iouActions[0]; + createdAction = createdActions.at(0); + iouAction = iouActions.at(0); const originalMessage = ReportActionsUtils.getOriginalMessage(iouAction); // The CREATED action should not be created after the IOU action @@ -776,7 +776,7 @@ describe('actions/IOU', () => { Onyx.disconnect(connectionID); expect(transaction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); expect(transaction?.errors).toBeTruthy(); - expect(Object.values(transaction?.errors ?? {})[0]).toEqual(Localize.translateLocal('iou.error.genericCreateFailureMessage')); + expect(Object.values(transaction?.errors ?? {}).at(0)).toEqual(Localize.translateLocal('iou.error.genericCreateFailureMessage')); resolve(); }, }); @@ -1427,7 +1427,7 @@ describe('actions/IOU', () => { expect(Object.values(allReports ?? {}).length).toBe(3); const chatReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.CHAT); - chatReport = chatReports[0]; + chatReport = chatReports.at(0); expect(chatReport).toBeTruthy(); expect(chatReport).toHaveProperty('reportID'); expect(chatReport).toHaveProperty('iouReportID'); @@ -1875,7 +1875,7 @@ describe('actions/IOU', () => { Onyx.disconnect(connectionID); const updatedAction = Object.values(allActions ?? {}).find((reportAction) => !isEmptyObject(reportAction)); expect(updatedAction?.actionName).toEqual('MODIFIEDEXPENSE'); - expect(Object.values(updatedAction?.errors ?? {})[0]).toEqual(Localize.translateLocal('iou.error.genericEditFailureMessage')); + expect(Object.values(updatedAction?.errors ?? {}).at(0)).toEqual(Localize.translateLocal('iou.error.genericEditFailureMessage')); resolve(); }, }); @@ -2097,7 +2097,7 @@ describe('actions/IOU', () => { callback: (allActions) => { Onyx.disconnect(connectionID); const erroredAction = Object.values(allActions ?? {}).find((action) => !isEmptyObject(action?.errors)); - expect(Object.values(erroredAction?.errors ?? {})[0]).toEqual(Localize.translateLocal('iou.error.other')); + expect(Object.values(erroredAction?.errors ?? {}).at(0)).toEqual(Localize.translateLocal('iou.error.other')); resolve(); }, }); diff --git a/tests/actions/PolicyCategoryTest.ts b/tests/actions/PolicyCategoryTest.ts index 3225942e8fa8..e9e9b544ee44 100644 --- a/tests/actions/PolicyCategoryTest.ts +++ b/tests/actions/PolicyCategoryTest.ts @@ -111,7 +111,7 @@ describe('actions/PolicyCategory', () => { it('Rename category', async () => { const fakePolicy = createRandomPolicy(0); const fakeCategories = createRandomPolicyCategories(3); - const oldCategoryName = Object.keys(fakeCategories)[0]; + const oldCategoryName = Object.keys(fakeCategories).at(0) ?? ''; const newCategoryName = 'Updated category'; mockFetch?.pause?.(); Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy); @@ -159,7 +159,7 @@ describe('actions/PolicyCategory', () => { it('Enable category', async () => { const fakePolicy = createRandomPolicy(0); const fakeCategories = createRandomPolicyCategories(3); - const categoryNameToUpdate = Object.keys(fakeCategories)[0]; + const categoryNameToUpdate = Object.keys(fakeCategories).at(0) ?? ''; const categoriesToUpdate = { [categoryNameToUpdate]: { name: categoryNameToUpdate, @@ -209,7 +209,7 @@ describe('actions/PolicyCategory', () => { it('Delete category', async () => { const fakePolicy = createRandomPolicy(0); const fakeCategories = createRandomPolicyCategories(3); - const categoryNameToDelete = Object.keys(fakeCategories)[0]; + const categoryNameToDelete = Object.keys(fakeCategories).at(0) ?? ''; const categoriesToDelete = [categoryNameToDelete]; mockFetch?.pause?.(); Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy); diff --git a/tests/actions/PolicyTagTest.ts b/tests/actions/PolicyTagTest.ts index 54b3d58785a0..f9e118c61c25 100644 --- a/tests/actions/PolicyTagTest.ts +++ b/tests/actions/PolicyTagTest.ts @@ -177,7 +177,7 @@ describe('actions/Policy', () => { newName: newTagListName, }, fakePolicyTags, - Object.values(fakePolicyTags)[0].orderWeight, + Object.values(fakePolicyTags).at(0).orderWeight, ); return waitForBatchedUpdates(); }) @@ -245,7 +245,7 @@ describe('actions/Policy', () => { newName: newTagListName, }, fakePolicyTags, - Object.values(fakePolicyTags)[0].orderWeight, + Object.values(fakePolicyTags).at(0).orderWeight, ); return waitForBatchedUpdates(); }) @@ -506,7 +506,7 @@ describe('actions/Policy', () => { const tagListName = 'Fake tag'; const fakePolicyTags = createRandomPolicyTags(tagListName, 2); - const oldTagName = Object.keys(fakePolicyTags?.[tagListName]?.tags)[0]; + const oldTagName = Object.keys(fakePolicyTags?.[tagListName]?.tags).at(0); const newTagName = 'New tag'; mockFetch?.pause?.(); @@ -574,7 +574,7 @@ describe('actions/Policy', () => { const tagListName = 'Fake tag'; const fakePolicyTags = createRandomPolicyTags(tagListName, 2); - const oldTagName = Object.keys(fakePolicyTags?.[tagListName]?.tags)[0]; + const oldTagName = Object.keys(fakePolicyTags?.[tagListName]?.tags).at(0); const newTagName = 'New tag'; mockFetch?.pause?.(); diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index e6ab31334bb1..2df5e73c6d8c 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -88,7 +88,7 @@ describe('actions/Report', () => { return waitForBatchedUpdates(); }) .then(() => { - const resultAction: OnyxEntry = Object.values(reportActions ?? {})[0]; + const resultAction: OnyxEntry = Object.values(reportActions ?? {}).at(0); reportActionID = resultAction.reportActionID; expect(resultAction.message).toEqual(REPORT_ACTION.message); @@ -186,7 +186,7 @@ describe('actions/Report', () => { .then(() => { // THEN only ONE call to AddComment will happen const URL_ARGUMENT_INDEX = 0; - const addCommentCalls = (global.fetch as jest.Mock).mock.calls.filter((callArguments: string[]) => callArguments[URL_ARGUMENT_INDEX].includes('AddComment')); + const addCommentCalls = (global.fetch as jest.Mock).mock.calls.filter((callArguments: string[]) => callArguments.at(URL_ARGUMENT_INDEX).includes('AddComment')); expect(addCommentCalls.length).toBe(1); }); }); @@ -584,7 +584,7 @@ describe('actions/Report', () => { return waitForBatchedUpdates(); }) .then(() => { - reportAction = Object.values(reportActions)[0]; + reportAction = Object.values(reportActions).at(0); reportActionID = reportAction.reportActionID; // Add a reaction to the comment @@ -592,7 +592,7 @@ describe('actions/Report', () => { return waitForBatchedUpdates(); }) .then(() => { - reportAction = Object.values(reportActions)[0]; + reportAction = Object.values(reportActions).at(0); // Expect the reaction to exist in the reportActionsReactions collection expect(reportActionsReactions).toHaveProperty(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`); @@ -616,20 +616,20 @@ describe('actions/Report', () => { expect(reportActionReaction?.[EMOJI.name].users[TEST_USER_ACCOUNT_ID]).toBeUndefined(); }) .then(() => { - reportAction = Object.values(reportActions)[0]; + reportAction = Object.values(reportActions).at(0); // Add the same reaction to the same report action with a different skintone Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionsReactions[0]); return waitForBatchedUpdates() .then(() => { - reportAction = Object.values(reportActions)[0]; + reportAction = Object.values(reportActions).at(0); const reportActionReaction = reportActionsReactions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`]; Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionReaction, EMOJI_SKIN_TONE); return waitForBatchedUpdates(); }) .then(() => { - reportAction = Object.values(reportActions)[0]; + reportAction = Object.values(reportActions).at(0); // Expect the reaction to exist in the reportActionsReactions collection expect(reportActionsReactions).toHaveProperty(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`); @@ -702,14 +702,14 @@ describe('actions/Report', () => { return waitForBatchedUpdates(); }) .then(() => { - resultAction = Object.values(reportActions)[0]; + resultAction = Object.values(reportActions).at(0); // Add a reaction to the comment Report.toggleEmojiReaction(REPORT_ID, resultAction, EMOJI, {}); return waitForBatchedUpdates(); }) .then(() => { - resultAction = Object.values(reportActions)[0]; + resultAction = Object.values(reportActions).at(0); // Now we toggle the reaction while the skin tone has changed. // As the emoji doesn't support skin tones, the emoji diff --git a/tests/e2e/compare/output/markdownTable.ts b/tests/e2e/compare/output/markdownTable.ts index 51f0beeb6979..17b42f4f02fe 100644 --- a/tests/e2e/compare/output/markdownTable.ts +++ b/tests/e2e/compare/output/markdownTable.ts @@ -200,27 +200,27 @@ function markdownTable(table: Array>, options: const sizes: number[] = []; let columnIndex = -1; - if (table[rowIndex].length > mostCellsPerRow) { - mostCellsPerRow = table[rowIndex].length; + if (table.at(rowIndex).length > mostCellsPerRow) { + mostCellsPerRow = table.at(rowIndex).length; } - while (++columnIndex < table[rowIndex].length) { - const cell = serialize(table[rowIndex][columnIndex]); + while (++columnIndex < table.at(rowIndex).length) { + const cell = serialize(table.at(rowIndex)[columnIndex]); if (options.alignDelimiters !== false) { const size = stringLength(cell); - sizes[columnIndex] = size; + sizes.at(columnIndex) = size; - if (longestCellByColumn[columnIndex] === undefined || size > longestCellByColumn[columnIndex]) { - longestCellByColumn[columnIndex] = size; + if (longestCellByColumn.at(columnIndex) === undefined || size > longestCellByColumn.at(columnIndex)) { + longestCellByColumn.at(columnIndex) = size; } } row.push(cell); } - cellMatrix[rowIndex] = row; - sizeMatrix[rowIndex] = sizes; + cellMatrix.at(rowIndex) = row; + sizeMatrix.at(rowIndex) = sizes; } // Figure out which alignments to use. @@ -228,13 +228,13 @@ function markdownTable(table: Array>, options: if (typeof align === 'object' && 'length' in align) { while (++columnIndex < mostCellsPerRow) { - alignments[columnIndex] = toAlignment(align[columnIndex]); + alignments.at(columnIndex) = toAlignment(align.at(columnIndex)); } } else { const code = toAlignment(align); while (++columnIndex < mostCellsPerRow) { - alignments[columnIndex] = code; + alignments.at(columnIndex) = code; } } @@ -244,7 +244,7 @@ function markdownTable(table: Array>, options: const sizes: number[] = []; while (++columnIndex < mostCellsPerRow) { - const code = alignments[columnIndex]; + const code = alignments.at(columnIndex); let before = ''; let after = ''; @@ -258,21 +258,21 @@ function markdownTable(table: Array>, options: } // There *must* be at least one hyphen-minus in each alignment cell. - let size = options.alignDelimiters === false ? 1 : Math.max(1, longestCellByColumn[columnIndex] - before.length - after.length); + let size = options.alignDelimiters === false ? 1 : Math.max(1, longestCellByColumn.at(columnIndex) - before.length - after.length); const cell = before + '-'.repeat(size) + after; if (options.alignDelimiters !== false) { size = before.length + size + after.length; - if (size > longestCellByColumn[columnIndex]) { - longestCellByColumn[columnIndex] = size; + if (size > longestCellByColumn.at(columnIndex)) { + longestCellByColumn.at(columnIndex) = size; } - sizes[columnIndex] = size; + sizes.at(columnIndex) = size; } - row[columnIndex] = cell; + row.at(columnIndex) = cell; } // Inject the alignment row. @@ -283,19 +283,19 @@ function markdownTable(table: Array>, options: const lines: string[] = []; while (++rowIndex < cellMatrix.length) { - const matrixRow = cellMatrix[rowIndex]; - const matrixSizes = sizeMatrix[rowIndex]; + const matrixRow = cellMatrix.at(rowIndex); + const matrixSizes = sizeMatrix.at(rowIndex); columnIndex = -1; const line: string[] = []; while (++columnIndex < mostCellsPerRow) { - const cell = matrixRow[columnIndex] || ''; + const cell = matrixRow.at(columnIndex) ?? ''; let before = ''; let after = ''; if (options.alignDelimiters !== false) { - const size = longestCellByColumn[columnIndex] - (matrixSizes[columnIndex] || 0); - const code = alignments[columnIndex]; + const size = longestCellByColumn.at(columnIndex) - (matrixSizes.at(columnIndex) ?? 0); + const code = alignments.at(columnIndex); if (code === 114 /* `r` */) { before = ' '.repeat(size); diff --git a/tests/e2e/measure/math.ts b/tests/e2e/measure/math.ts index 1cb6661007ea..2784383d6a96 100644 --- a/tests/e2e/measure/math.ts +++ b/tests/e2e/measure/math.ts @@ -14,8 +14,8 @@ const filterOutliersViaIQR = (data: Entries): Entries => { const values = data.slice().sort((a, b) => a - b); if ((values.length / 4) % 1 === 0) { - q1 = (1 / 2) * (values[values.length / 4] + values[values.length / 4 + 1]); - q3 = (1 / 2) * (values[values.length * (3 / 4)] + values[values.length * (3 / 4) + 1]); + q1 = (1 / 2) * (values.at(values.length / 4) + values.at(values.length / 4 + 1)); + q3 = (1 / 2) * (values.at(values.length * (3 / 4)) + values.at(values.length * (3 / 4) + 1)); } else { q1 = values[Math.floor(values.length / 4 + 1)]; q3 = values[Math.ceil(values.length * (3 / 4) + 1)]; diff --git a/tests/e2e/testRunner.ts b/tests/e2e/testRunner.ts index 2d78cf154ff1..1b5f257f42b8 100644 --- a/tests/e2e/testRunner.ts +++ b/tests/e2e/testRunner.ts @@ -43,7 +43,7 @@ const getArg = (argName: string): string | undefined => { if (argIndex === -1) { return undefined; } - return args[argIndex + 1]; + return args.at(argIndex + 1); }; let config = defaultConfig; @@ -217,7 +217,7 @@ const runTests = async (): Promise => { // Run the tests const tests = Object.keys(config.TESTS_CONFIG); for (let testIndex = 0; testIndex < tests.length; testIndex++) { - const test = Object.values(config.TESTS_CONFIG)[testIndex]; + const test = Object.values(config.TESTS_CONFIG).at(testIndex); // re-instal app for each new test suite await installApp(config.MAIN_APP_PACKAGE, mainAppPath); diff --git a/tests/e2e/utils/installApp.ts b/tests/e2e/utils/installApp.ts index 9c2f82e47336..3a4b34231ac9 100644 --- a/tests/e2e/utils/installApp.ts +++ b/tests/e2e/utils/installApp.ts @@ -26,7 +26,7 @@ export default function (packageName: string, path: string, platform = 'android' execAsync(`adb install ${path}`).then(() => // and grant push notifications permissions right away (the popup may block e2e tests sometimes) // eslint-disable-next-line @typescript-eslint/no-unused-vars - execAsync(`adb shell pm grant ${packageName.split('/')[0]} android.permission.POST_NOTIFICATIONS`).catch((_: ExecException) => + execAsync(`adb shell pm grant ${packageName.split('/').at(0)} android.permission.POST_NOTIFICATIONS`).catch((_: ExecException) => // in case of error - just log it and continue (if we request this permission on Android < 13 it'll fail because there is no such permission) Logger.warn( 'Failed to grant push notifications permissions. It might be due to the fact that push-notifications permission type is not supported on this OS version yet. Continue tests execution...', diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index 1d31a707d81d..db7466c84d5a 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -85,7 +85,7 @@ function navigateToSidebar(): Promise { async function navigateToSidebarOption(index: number): Promise { const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); const optionRows = screen.queryAllByAccessibilityHint(hintText); - fireEvent(optionRows[index], 'press'); + fireEvent(optionRows.at(index), 'press'); await waitForBatchedUpdatesWithAct(); } @@ -93,7 +93,7 @@ function areYouOnChatListScreen(): boolean { const hintText = Localize.translateLocal('sidebarScreen.listOfChats'); const sidebarLinks = screen.queryAllByLabelText(hintText); - return !sidebarLinks?.[0]?.props?.accessibilityElementsHidden; + return !sidebarLinks.at(0)?.props?.accessibilityElementsHidden; } const REPORT_ID = '1'; @@ -231,7 +231,7 @@ describe('Unread Indicators', () => { const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(1); - const reportActionID = unreadIndicator[0]?.props?.['data-action-id'] as string; + const reportActionID = unreadIndicator.at(0)?.props?.['data-action-id'] as string; expect(reportActionID).toBe('4'); // Scroll up and verify that the "New messages" badge appears scrollUpToRevealNewMessagesBadge(); @@ -349,11 +349,11 @@ describe('Unread Indicators', () => { const displayNameHintTexts = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNameTexts = screen.queryAllByLabelText(displayNameHintTexts); expect(displayNameTexts).toHaveLength(2); - const firstReportOption = displayNameTexts[0]; + const firstReportOption = displayNameTexts.at(0); expect((firstReportOption?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); expect(screen.getByText('C User')).toBeOnTheScreen(); - const secondReportOption = displayNameTexts[1]; + const secondReportOption = displayNameTexts.at(1); expect((secondReportOption?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); expect(screen.getByText('B User')).toBeOnTheScreen(); @@ -367,9 +367,9 @@ describe('Unread Indicators', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(2); - expect((displayNameTexts[0]?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.normal); - expect(screen.getAllByText('C User')[0]).toBeOnTheScreen(); - expect((displayNameTexts[1]?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); + expect((displayNameTexts.at(0)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.normal); + expect(screen.getAllByText('C User').at(0)).toBeOnTheScreen(); + expect((displayNameTexts.at(1)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); expect(screen.getByText('B User')).toBeOnTheScreen(); })); @@ -388,7 +388,7 @@ describe('Unread Indicators', () => { const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(1); - const reportActionID = unreadIndicator[0]?.props?.['data-action-id'] as string; + const reportActionID = unreadIndicator.at(0)?.props?.['data-action-id'] as string; expect(reportActionID).toBe('3'); // Scroll up and verify the new messages badge appears scrollUpToRevealNewMessagesBadge(); @@ -401,7 +401,7 @@ describe('Unread Indicators', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(1); - expect((displayNameTexts[0]?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); + expect((displayNameTexts.at(0)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); expect(screen.getByText('B User')).toBeOnTheScreen(); // Navigate to the report again and back to the sidebar @@ -413,7 +413,7 @@ describe('Unread Indicators', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(1); - expect((displayNameTexts[0]?.props?.style as TextStyle)?.fontWeight).toBe(undefined); + expect((displayNameTexts.at(0)?.props?.style as TextStyle)?.fontWeight).toBe(undefined); expect(screen.getByText('B User')).toBeOnTheScreen(); // Navigate to the report again and verify the new line indicator is missing @@ -528,7 +528,7 @@ describe('Unread Indicators', () => { expect(alternateText).toHaveLength(1); // This message is visible on the sidebar and the report screen, so there are two occurrences. - expect(screen.getAllByText('Current User Comment 1')[0]).toBeOnTheScreen(); + expect(screen.getAllByText('Current User Comment 1').at(0)).toBeOnTheScreen(); if (lastReportAction) { Report.deleteReportComment(REPORT_ID, lastReportAction); @@ -539,7 +539,7 @@ describe('Unread Indicators', () => { const hintText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); const alternateText = screen.queryAllByLabelText(hintText); expect(alternateText).toHaveLength(1); - expect(screen.getAllByText('Comment 9')[0]).toBeOnTheScreen(); + expect(screen.getAllByText('Comment 9').at(0)).toBeOnTheScreen(); }) ); }); diff --git a/tests/unit/APITest.ts b/tests/unit/APITest.ts index 74be6c742f51..5b0eea3decdf 100644 --- a/tests/unit/APITest.ts +++ b/tests/unit/APITest.ts @@ -148,7 +148,7 @@ describe('APITests', () => { }), ); - return promises.slice(-1)[0]; + return promises.slice(-1).at(0); }); // Given we have some requests made while we're offline @@ -168,7 +168,7 @@ describe('APITests', () => { // Then requests should remain persisted until the xhr call is resolved expect(PersistedRequests.getAll().length).toEqual(2); - xhrCalls[0].resolve({jsonCode: CONST.JSON_CODE.SUCCESS}); + xhrCalls.at(0).resolve({jsonCode: CONST.JSON_CODE.SUCCESS}); return waitForBatchedUpdates(); }) .then(waitForBatchedUpdates) @@ -177,7 +177,7 @@ describe('APITests', () => { expect(PersistedRequests.getAll()).toEqual([expect.objectContaining({command: 'mock command', data: expect.objectContaining({param2: 'value2'})})]); // When a request fails it should be retried - xhrCalls[1].reject(new Error(CONST.ERROR.FAILED_TO_FETCH)); + xhrCalls.at(1).reject(new Error(CONST.ERROR.FAILED_TO_FETCH)); return waitForBatchedUpdates(); }) .then(() => { @@ -191,7 +191,7 @@ describe('APITests', () => { }) .then(() => { // Finally, after it succeeds the queue should be empty - xhrCalls[2].resolve({jsonCode: CONST.JSON_CODE.SUCCESS}); + xhrCalls.at(2).resolve({jsonCode: CONST.JSON_CODE.SUCCESS}); return waitForBatchedUpdates(); }) .then(() => { @@ -353,13 +353,13 @@ describe('APITests', () => { // Then expect all 7 calls to have been made and for the Writes to be made in the order that we made them // The read command would have been made first (and would have failed in real-life) expect(xhr.mock.calls.length).toBe(7); - expect(xhr.mock.calls[0][1].content).toBe('not-persisted'); - expect(xhr.mock.calls[1][1].content).toBe('value1'); - expect(xhr.mock.calls[2][1].content).toBe('value2'); - expect(xhr.mock.calls[3][1].content).toBe('value3'); - expect(xhr.mock.calls[4][1].content).toBe('value4'); - expect(xhr.mock.calls[5][1].content).toBe('value5'); - expect(xhr.mock.calls[6][1].content).toBe('value6'); + expect(xhr.mock.calls.at(0)[1].content).toBe('not-persisted'); + expect(xhr.mock.calls.at(1)[1].content).toBe('value1'); + expect(xhr.mock.calls.at(2)[1].content).toBe('value2'); + expect(xhr.mock.calls.at(3)[1].content).toBe('value3'); + expect(xhr.mock.calls.at(4)[1].content).toBe('value4'); + expect(xhr.mock.calls.at(5)[1].content).toBe('value5'); + expect(xhr.mock.calls.at(6)[1].content).toBe('value6'); }); }); @@ -387,18 +387,18 @@ describe('APITests', () => { .then(() => { // Then expect only 8 calls to have been made total and for them to be made in the order that we made them despite requiring reauthentication expect(xhr.mock.calls.length).toBe(8); - expect(xhr.mock.calls[0][1].content).toBe('value1'); + expect(xhr.mock.calls.at(0)[1].content).toBe('value1'); // Our call to Authenticate will not have a "content" field - expect(xhr.mock.calls[1][1].content).not.toBeDefined(); + expect(xhr.mock.calls.at(1)[1].content).not.toBeDefined(); // Rest of the calls have the expected params and are called in sequence - expect(xhr.mock.calls[2][1].content).toBe('value1'); - expect(xhr.mock.calls[3][1].content).toBe('value2'); - expect(xhr.mock.calls[4][1].content).toBe('value3'); - expect(xhr.mock.calls[5][1].content).toBe('value4'); - expect(xhr.mock.calls[6][1].content).toBe('value5'); - expect(xhr.mock.calls[7][1].content).toBe('value6'); + expect(xhr.mock.calls.at(2)[1].content).toBe('value1'); + expect(xhr.mock.calls.at(3)[1].content).toBe('value2'); + expect(xhr.mock.calls.at(4)[1].content).toBe('value3'); + expect(xhr.mock.calls.at(5)[1].content).toBe('value4'); + expect(xhr.mock.calls.at(6)[1].content).toBe('value5'); + expect(xhr.mock.calls.at(7)[1].content).toBe('value6'); }); }); @@ -463,18 +463,18 @@ describe('APITests', () => { expect(NetworkStore.isOffline()).toBe(false); // First call to xhr is the AuthenticatePusher request that could not call Authenticate because we went offline - const [firstCommand] = xhr.mock.calls[0]; + const [firstCommand] = xhr.mock.calls.at(0); expect(firstCommand).toBe('AuthenticatePusher'); // Second call to xhr is the MockCommand that also failed with a 407 - const [secondCommand] = xhr.mock.calls[1]; + const [secondCommand] = xhr.mock.calls.at(1); expect(secondCommand).toBe('MockCommand'); // Third command should be the call to Authenticate - const [thirdCommand] = xhr.mock.calls[2]; + const [thirdCommand] = xhr.mock.calls.at(2); expect(thirdCommand).toBe('Authenticate'); - const [fourthCommand] = xhr.mock.calls[3]; + const [fourthCommand] = xhr.mock.calls.at(3); expect(fourthCommand).toBe('MockCommand'); // We are using the new authToken @@ -553,11 +553,11 @@ describe('APITests', () => { expect(PersistedRequests.getAll().length).toBe(0); // And our Write request should run before our non persistable one in a blocking way - const firstRequest = xhr.mock.calls[0]; + const firstRequest = xhr.mock.calls.at(0); const [firstRequestCommandName] = firstRequest; expect(firstRequestCommandName).toBe('MockCommandOne'); - const secondRequest = xhr.mock.calls[1]; + const secondRequest = xhr.mock.calls.at(1); const [secondRequestCommandName] = secondRequest; expect(secondRequestCommandName).toBe('MockCommandThree'); @@ -568,7 +568,7 @@ describe('APITests', () => { }) .then(() => { // THEN we should see that our third (non-persistable) request has run last - const thirdRequest = xhr.mock.calls[2]; + const thirdRequest = xhr.mock.calls.at(2); const [thirdRequestCommandName] = thirdRequest; expect(thirdRequestCommandName).toBe('MockCommandTwo'); }); diff --git a/tests/unit/CalendarPickerTest.tsx b/tests/unit/CalendarPickerTest.tsx index 9c471be5b035..079a109f348b 100644 --- a/tests/unit/CalendarPickerTest.tsx +++ b/tests/unit/CalendarPickerTest.tsx @@ -69,7 +69,7 @@ describe('CalendarPicker', () => { fireEvent.press(screen.getByTestId('next-month-arrow')); const nextMonth = addMonths(new Date(), 1).getMonth(); - expect(screen.getByText(monthNames[nextMonth])).toBeTruthy(); + expect(screen.getByText(monthNames.at(nextMonth))).toBeTruthy(); }); test('clicking previous month arrow updates the displayed month', () => { @@ -78,7 +78,7 @@ describe('CalendarPicker', () => { fireEvent.press(screen.getByTestId('prev-month-arrow')); const prevMonth = subMonths(new Date(), 1).getMonth(); - expect(screen.getByText(monthNames[prevMonth])).toBeTruthy(); + expect(screen.getByText(monthNames.at(prevMonth))).toBeTruthy(); }); test('clicking a day updates the selected date', () => { diff --git a/tests/unit/GithubUtilsTest.ts b/tests/unit/GithubUtilsTest.ts index 2bab87550357..2de95bf992f5 100644 --- a/tests/unit/GithubUtilsTest.ts +++ b/tests/unit/GithubUtilsTest.ts @@ -425,11 +425,11 @@ describe('GithubUtils', () => { // Valid output which will be reused in the deploy blocker tests const allVerifiedExpectedOutput = `${baseExpectedOutput}` + - `${closedCheckbox}${basePRList[2]}` + - `${lineBreak}${closedCheckbox}${basePRList[0]}` + - `${lineBreak}${closedCheckbox}${basePRList[1]}` + - `${lineBreak}${closedCheckbox}${basePRList[4]}` + - `${lineBreak}${closedCheckbox}${basePRList[5]}` + + `${closedCheckbox}${basePRList.at(2)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(0)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(1)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(4)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + `${lineBreak}`; test('Test no verified PRs', () => { @@ -439,11 +439,11 @@ describe('GithubUtils', () => { } expect(issue.issueBody).toBe( `${baseExpectedOutput}` + - `${openCheckbox}${basePRList[2]}` + - `${lineBreak}${openCheckbox}${basePRList[0]}` + - `${lineBreak}${openCheckbox}${basePRList[1]}` + - `${lineBreak}${closedCheckbox}${basePRList[4]}` + - `${lineBreak}${closedCheckbox}${basePRList[5]}` + + `${openCheckbox}${basePRList.at(2)}` + + `${lineBreak}${openCheckbox}${basePRList.at(0)}` + + `${lineBreak}${openCheckbox}${basePRList.at(1)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(4)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + `${lineBreak}${openCheckbox}${firebaseVerification}` + @@ -455,18 +455,18 @@ describe('GithubUtils', () => { }); test('Test some verified PRs', () => { - githubUtils.generateStagingDeployCashBodyAndAssignees(tag, basePRList, [basePRList[0]]).then((issue) => { + githubUtils.generateStagingDeployCashBodyAndAssignees(tag, basePRList, [basePRList.at(0)]).then((issue) => { if (typeof issue !== 'object') { return; } expect(issue.issueBody).toBe( `${baseExpectedOutput}` + - `${openCheckbox}${basePRList[2]}` + - `${lineBreak}${closedCheckbox}${basePRList[0]}` + - `${lineBreak}${openCheckbox}${basePRList[1]}` + - `${lineBreak}${closedCheckbox}${basePRList[4]}` + - `${lineBreak}${closedCheckbox}${basePRList[5]}` + + `${openCheckbox}${basePRList.at(2)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(0)}` + + `${lineBreak}${openCheckbox}${basePRList.at(1)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(4)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + `${lineBreak}${openCheckbox}${firebaseVerification}` + @@ -504,8 +504,8 @@ describe('GithubUtils', () => { expect(issue.issueBody).toBe( `${allVerifiedExpectedOutput}` + `${lineBreak}${deployBlockerHeader}` + - `${lineBreak}${openCheckbox}${baseDeployBlockerList[0]}` + - `${lineBreak}${openCheckbox}${baseDeployBlockerList[1]}` + + `${lineBreak}${openCheckbox}${baseDeployBlockerList.at(0)}` + + `${lineBreak}${openCheckbox}${baseDeployBlockerList.at(1)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + `${lineBreak}${openCheckbox}${firebaseVerification}` + @@ -517,7 +517,7 @@ describe('GithubUtils', () => { }); test('Test some resolved deploy blockers', () => { - githubUtils.generateStagingDeployCashBodyAndAssignees(tag, basePRList, basePRList, baseDeployBlockerList, [baseDeployBlockerList[0]]).then((issue) => { + githubUtils.generateStagingDeployCashBodyAndAssignees(tag, basePRList, basePRList, baseDeployBlockerList, [baseDeployBlockerList.at(0)]).then((issue) => { if (typeof issue !== 'object') { return; } @@ -525,8 +525,8 @@ describe('GithubUtils', () => { expect(issue.issueBody).toBe( `${allVerifiedExpectedOutput}` + `${lineBreak}${deployBlockerHeader}` + - `${lineBreak}${closedCheckbox}${baseDeployBlockerList[0]}` + - `${lineBreak}${openCheckbox}${baseDeployBlockerList[1]}` + + `${lineBreak}${closedCheckbox}${baseDeployBlockerList.at(0)}` + + `${lineBreak}${openCheckbox}${baseDeployBlockerList.at(1)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + `${lineBreak}${openCheckbox}${firebaseVerification}` + @@ -544,14 +544,14 @@ describe('GithubUtils', () => { } expect(issue.issueBody).toBe( `${baseExpectedOutput}` + - `${closedCheckbox}${basePRList[2]}` + - `${lineBreak}${closedCheckbox}${basePRList[0]}` + - `${lineBreak}${closedCheckbox}${basePRList[1]}` + - `${lineBreak}${closedCheckbox}${basePRList[4]}` + - `${lineBreak}${closedCheckbox}${basePRList[5]}` + + `${closedCheckbox}${basePRList.at(2)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(0)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(1)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(4)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + `${lineBreakDouble}${deployBlockerHeader}` + - `${lineBreak}${closedCheckbox}${baseDeployBlockerList[0]}` + - `${lineBreak}${closedCheckbox}${baseDeployBlockerList[1]}` + + `${lineBreak}${closedCheckbox}${baseDeployBlockerList.at(0)}` + + `${lineBreak}${closedCheckbox}${baseDeployBlockerList.at(1)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + `${lineBreak}${openCheckbox}${firebaseVerification}` + @@ -570,14 +570,14 @@ describe('GithubUtils', () => { expect(issue.issueBody).toBe( `${baseExpectedOutput}` + - `${openCheckbox}${basePRList[2]}` + - `${lineBreak}${openCheckbox}${basePRList[0]}` + - `${lineBreak}${openCheckbox}${basePRList[1]}` + - `${lineBreak}${closedCheckbox}${basePRList[4]}` + - `${lineBreak}${closedCheckbox}${basePRList[5]}` + + `${openCheckbox}${basePRList.at(2)}` + + `${lineBreak}${openCheckbox}${basePRList.at(0)}` + + `${lineBreak}${openCheckbox}${basePRList.at(1)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(4)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + `${lineBreak}${internalQAHeader}` + - `${lineBreak}${openCheckbox}${internalQAPRList[0]}${assignOctocat}` + - `${lineBreak}${openCheckbox}${internalQAPRList[1]}${assignOctocat}` + + `${lineBreak}${openCheckbox}${internalQAPRList.at(0)}${assignOctocat}` + + `${lineBreak}${openCheckbox}${internalQAPRList.at(1)}${assignOctocat}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + `${lineBreak}${openCheckbox}${firebaseVerification}` + @@ -589,21 +589,21 @@ describe('GithubUtils', () => { }); test('Test some verified internalQA PRs', () => { - githubUtils.generateStagingDeployCashBodyAndAssignees(tag, [...basePRList, ...internalQAPRList], [], [], [], [internalQAPRList[0]]).then((issue) => { + githubUtils.generateStagingDeployCashBodyAndAssignees(tag, [...basePRList, ...internalQAPRList], [], [], [], [internalQAPRList.at(0)]).then((issue) => { if (typeof issue !== 'object') { return; } expect(issue.issueBody).toBe( `${baseExpectedOutput}` + - `${openCheckbox}${basePRList[2]}` + - `${lineBreak}${openCheckbox}${basePRList[0]}` + - `${lineBreak}${openCheckbox}${basePRList[1]}` + - `${lineBreak}${closedCheckbox}${basePRList[4]}` + - `${lineBreak}${closedCheckbox}${basePRList[5]}` + + `${openCheckbox}${basePRList.at(2)}` + + `${lineBreak}${openCheckbox}${basePRList.at(0)}` + + `${lineBreak}${openCheckbox}${basePRList.at(1)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(4)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + `${lineBreak}${internalQAHeader}` + - `${lineBreak}${closedCheckbox}${internalQAPRList[0]}${assignOctocat}` + - `${lineBreak}${openCheckbox}${internalQAPRList[1]}${assignOctocat}` + + `${lineBreak}${closedCheckbox}${internalQAPRList.at(0)}${assignOctocat}` + + `${lineBreak}${openCheckbox}${internalQAPRList.at(1)}${assignOctocat}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + `${lineBreak}${openCheckbox}${firebaseVerification}` + diff --git a/tests/unit/MiddlewareTest.ts b/tests/unit/MiddlewareTest.ts index be13ded01342..a815e7c5da74 100644 --- a/tests/unit/MiddlewareTest.ts +++ b/tests/unit/MiddlewareTest.ts @@ -51,12 +51,12 @@ describe('Middleware', () => { expect(global.fetch).toHaveBeenCalledTimes(2); expect(global.fetch).toHaveBeenLastCalledWith('https://www.expensify.com.dev/api/AddComment?', expect.anything()); - TestHelper.assertFormDataMatchesObject(((global.fetch as jest.Mock).mock.calls[1] as FormDataObject[])[1].body, { + TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[1] as FormDataObject[][1].body, { reportID: '1234', reportActionID: '5678', }); expect(global.fetch).toHaveBeenNthCalledWith(1, 'https://www.expensify.com.dev/api/OpenReport?', expect.anything()); - TestHelper.assertFormDataMatchesObject(((global.fetch as jest.Mock).mock.calls[0] as FormDataObject[])[1].body, { + TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[0] as FormDataObject[][1].body, { reportID: '1234', }); }); @@ -100,12 +100,12 @@ describe('Middleware', () => { expect(global.fetch).toHaveBeenCalledTimes(2); expect(global.fetch).toHaveBeenLastCalledWith('https://www.expensify.com.dev/api/AddComment?', expect.anything()); - TestHelper.assertFormDataMatchesObject(((global.fetch as jest.Mock).mock.calls[1] as FormDataObject[])[1].body, { + TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[1] as FormDataObject[].at(1).body, { reportID: '5555', reportActionID: '5678', }); expect(global.fetch).toHaveBeenNthCalledWith(1, 'https://www.expensify.com.dev/api/OpenReport?', expect.anything()); - TestHelper.assertFormDataMatchesObject(((global.fetch as jest.Mock).mock.calls[0] as FormDataObject[])[1].body, {reportID: '1234'}); + TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[0] as FormDataObject[].at(1).body, {reportID: '1234'}); }); }); }); diff --git a/tests/unit/NetworkTest.ts b/tests/unit/NetworkTest.ts index e79a7c93c0e5..e7cb4f0c7ada 100644 --- a/tests/unit/NetworkTest.ts +++ b/tests/unit/NetworkTest.ts @@ -303,7 +303,7 @@ describe('NetworkTests', () => { return waitForBatchedUpdates(); }) .then(() => { - const response = onResolved.mock.calls[0][0]; + const response = onResolved.mock.calls.at(0)[0]; expect(onResolved).toHaveBeenCalled(); expect(response.jsonCode).toBe(CONST.JSON_CODE.UNABLE_TO_RETRY); }); diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 34a0a9af7383..a21f8e415be9 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -447,10 +447,10 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(Object.values(OPTIONS.personalDetails).length - 1 - MAX_RECENT_REPORTS); // We should expect personal details sorted alphabetically - expect(results.personalDetails[0].text).toBe('Black Widow'); - expect(results.personalDetails[1].text).toBe('Invisible Woman'); - expect(results.personalDetails[2].text).toBe('Spider-Man'); - expect(results.personalDetails[3].text).toBe('The Incredible Hulk'); + expect(results.personalDetails.at(0).text).toBe('Black Widow'); + expect(results.personalDetails.at(1).text).toBe('Invisible Woman'); + expect(results.personalDetails.at(2).text).toBe('Spider-Man'); + expect(results.personalDetails.at(3).text).toBe('The Incredible Hulk'); // Then the result which has an existing report should also have the reportID attached const personalDetailWithExistingReport = results.personalDetails.find((personalDetail) => personalDetail.login === 'peterparker@expensify.com'); @@ -460,10 +460,10 @@ describe('OptionsListUtils', () => { results = OptionsListUtils.getFilteredOptions([], OPTIONS.personalDetails, [], ''); // We should expect personal details sorted alphabetically - expect(results.personalDetails[0].text).toBe('Black Panther'); - expect(results.personalDetails[1].text).toBe('Black Widow'); - expect(results.personalDetails[2].text).toBe('Captain America'); - expect(results.personalDetails[3].text).toBe('Invisible Woman'); + expect(results.personalDetails.at(0).text).toBe('Black Panther'); + expect(results.personalDetails.at(1).text).toBe('Black Widow'); + expect(results.personalDetails.at(2).text).toBe('Captain America'); + expect(results.personalDetails.at(3).text).toBe('Invisible Woman'); // When we don't include personal detail to the result results = OptionsListUtils.getFilteredOptions( @@ -539,10 +539,10 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(Object.values(OPTIONS.personalDetails).length - 6); // We should expect personal details sorted alphabetically - expect(results.personalDetails[0].text).toBe('Black Widow'); - expect(results.personalDetails[1].text).toBe('Invisible Woman'); - expect(results.personalDetails[2].text).toBe('Spider-Man'); - expect(results.personalDetails[3].text).toBe('The Incredible Hulk'); + expect(results.personalDetails.at(0).text).toBe('Black Widow'); + expect(results.personalDetails.at(1).text).toBe('Invisible Woman'); + expect(results.personalDetails.at(2).text).toBe('Spider-Man'); + expect(results.personalDetails.at(3).text).toBe('The Incredible Hulk'); // And none of our personalDetails should include any of the users with recent reports const reportLogins = results.recentReports.map((reportOption) => reportOption.login); @@ -638,10 +638,10 @@ describe('OptionsListUtils', () => { const results = OptionsListUtils.getMemberInviteOptions(OPTIONS.personalDetails, [], ''); // We should expect personal details to be sorted alphabetically - expect(results.personalDetails[0].text).toBe('Black Panther'); - expect(results.personalDetails[1].text).toBe('Black Widow'); - expect(results.personalDetails[2].text).toBe('Captain America'); - expect(results.personalDetails[3].text).toBe('Invisible Woman'); + expect(results.personalDetails.at(0).text).toBe('Black Panther'); + expect(results.personalDetails.at(1).text).toBe('Black Widow'); + expect(results.personalDetails.at(2).text).toBe('Captain America'); + expect(results.personalDetails.at(3).text).toBe('Invisible Woman'); }); it('getFilteredOptions() for categories', () => { @@ -2611,12 +2611,12 @@ describe('OptionsListUtils', () => { 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'); - expect(formattedMembers[1].text).toBe('Iron Man'); - expect(formattedMembers[2].text).toBe('Spider-Man'); + expect(formattedMembers.at(0).text).toBe('Mister Fantastic'); + expect(formattedMembers.at(1).text).toBe('Iron Man'); + expect(formattedMembers.at(2).text).toBe('Spider-Man'); // We should expect only the first item to be selected - expect(formattedMembers[0].isSelected).toBe(true); + expect(formattedMembers.at(0).isSelected).toBe(true); // And all the others to be unselected expect(formattedMembers.slice(1).every((personalDetail) => !personalDetail.isSelected)).toBe(true); @@ -2639,11 +2639,11 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, searchText, {sortByReportTypeInSearch: true}); expect(filteredOptions.recentReports.length).toBe(5); - expect(filteredOptions.recentReports[0].text).toBe('Invisible Woman'); - expect(filteredOptions.recentReports[1].text).toBe('Spider-Man'); - expect(filteredOptions.recentReports[2].text).toBe('Black Widow'); - expect(filteredOptions.recentReports[3].text).toBe('Mister Fantastic, Invisible Woman'); - expect(filteredOptions.recentReports[4].text).toBe("SHIELD's workspace (archived)"); + expect(filteredOptions.recentReports.at(0).text).toBe('Invisible Woman'); + expect(filteredOptions.recentReports.at(1).text).toBe('Spider-Man'); + expect(filteredOptions.recentReports.at(2).text).toBe('Black Widow'); + expect(filteredOptions.recentReports.at(3).text).toBe('Mister Fantastic, Invisible Woman'); + expect(filteredOptions.recentReports.at(4).text).toBe("SHIELD's workspace (archived)"); }); it('should filter users by email', () => { @@ -2653,7 +2653,7 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, searchText); expect(filteredOptions.recentReports.length).toBe(1); - expect(filteredOptions.recentReports[0].text).toBe('Mr Sinister'); + expect(filteredOptions.recentReports.at(0).text).toBe('Mr Sinister'); }); it('should find archived chats', () => { @@ -2662,7 +2662,7 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, searchText); expect(filteredOptions.recentReports.length).toBe(1); - expect(filteredOptions.recentReports[0].isArchivedRoom).toBe(true); + expect(filteredOptions.recentReports.at(0).isArchivedRoom).toBe(true); }); it('should filter options by email if dot is skipped in the email', () => { @@ -2673,7 +2673,7 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, searchText, {sortByReportTypeInSearch: true}); expect(filteredOptions.recentReports.length).toBe(1); - expect(filteredOptions.recentReports[0].login).toBe('barry.allen@expensify.com'); + expect(filteredOptions.recentReports.at(0).login).toBe('barry.allen@expensify.com'); }); it('should include workspace rooms in the search results', () => { @@ -2683,7 +2683,7 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, searchText); expect(filteredOptions.recentReports.length).toBe(1); - expect(filteredOptions.recentReports[0].subtitle).toBe('Avengers Room'); + expect(filteredOptions.recentReports.at(0).subtitle).toBe('Avengers Room'); }); it('should put exact match by login on the top of the list', () => { @@ -2693,7 +2693,7 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, searchText); expect(filteredOptions.recentReports.length).toBe(2); - expect(filteredOptions.recentReports[0].login).toBe(searchText); + expect(filteredOptions.recentReports.at(0).login).toBe(searchText); }); it('should prioritize options with matching display name over chatrooms', () => { @@ -2704,7 +2704,7 @@ describe('OptionsListUtils', () => { const filterOptions = OptionsListUtils.filterOptions(options, searchText); expect(filterOptions.recentReports.length).toBe(2); - expect(filterOptions.recentReports[1].isChatRoom).toBe(true); + expect(filterOptions.recentReports.at(1).isChatRoom).toBe(true); }); it('should put the item with latest lastVisibleActionCreated on top when search value match multiple items', () => { @@ -2714,8 +2714,8 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, searchText); expect(filteredOptions.recentReports.length).toBe(2); - expect(filteredOptions.recentReports[0].text).toBe('Mister Fantastic'); - expect(filteredOptions.recentReports[1].text).toBe('Mister Fantastic, Invisible Woman'); + expect(filteredOptions.recentReports.at(0).text).toBe('Mister Fantastic'); + expect(filteredOptions.recentReports.at(1).text).toBe('Mister Fantastic, Invisible Woman'); }); it('should return the user to invite when the search value is a valid, non-existent email', () => { @@ -2784,7 +2784,7 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, 'peterparker@expensify.com'); expect(filteredOptions.personalDetails.length).toBe(1); - expect(filteredOptions.personalDetails[0].text).toBe('Spider-Man'); + expect(filteredOptions.personalDetails.at(0).text).toBe('Spider-Man'); }); it('should not show any recent reports if a search value does not match the group chat name (getShareDestinationsOptions)', () => { @@ -2841,7 +2841,7 @@ describe('OptionsListUtils', () => { expect(filteredOptions.recentReports.length).toBe(0); expect(filteredOptions.personalDetails.length).toBe(1); - expect(filteredOptions.personalDetails[0].login).toBe('brucebanner@expensify.com'); + expect(filteredOptions.personalDetails.at(0).login).toBe('brucebanner@expensify.com'); }); it('should return all matching reports and personal details (getFilteredOptions)', () => { @@ -2849,10 +2849,10 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, '.com'); expect(filteredOptions.recentReports.length).toBe(5); - expect(filteredOptions.recentReports[0].text).toBe('Captain America'); + expect(filteredOptions.recentReports.at(0).text).toBe('Captain America'); expect(filteredOptions.personalDetails.length).toBe(4); - expect(filteredOptions.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); + expect(filteredOptions.personalDetails.at(0).login).toBe('natasharomanoff@expensify.com'); }); it('should not return any options or user to invite if there are no search results and the string does not match a potential email or phone (getFilteredOptions)', () => { @@ -2931,7 +2931,7 @@ describe('OptionsListUtils', () => { const options = OptionsListUtils.getFilteredOptions(OPTIONS.reports, OPTIONS.personalDetails, [], ''); const filteredOptions = OptionsListUtils.filterOptions(options, 'peterparker@expensify.com', {sortByReportTypeInSearch: true}); expect(filteredOptions.recentReports.length).toBe(1); - expect(filteredOptions.recentReports[0].text).toBe('Spider-Man'); + expect(filteredOptions.recentReports.at(0).text).toBe('Spider-Man'); expect(filteredOptions.personalDetails.length).toBe(0); }); @@ -2941,10 +2941,10 @@ describe('OptionsListUtils', () => { expect(filteredOptions.personalDetails.length).toBe(4); expect(filteredOptions.recentReports.length).toBe(5); - expect(filteredOptions.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); - expect(filteredOptions.recentReports[0].text).toBe('Captain America'); - expect(filteredOptions.recentReports[1].text).toBe('Mr Sinister'); - expect(filteredOptions.recentReports[2].text).toBe('Black Panther'); + expect(filteredOptions.personalDetails.at(0).login).toBe('natasharomanoff@expensify.com'); + expect(filteredOptions.recentReports.at(0).text).toBe('Captain America'); + expect(filteredOptions.recentReports.at(1).text).toBe('Mr Sinister'); + expect(filteredOptions.recentReports.at(2).text).toBe('Black Panther'); }); it('should return matching option when searching (getSearchOptions)', () => { @@ -2952,7 +2952,7 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, 'spider'); expect(filteredOptions.recentReports.length).toBe(1); - expect(filteredOptions.recentReports[0].text).toBe('Spider-Man'); + expect(filteredOptions.recentReports.at(0).text).toBe('Spider-Man'); }); it('should return latest lastVisibleActionCreated item on top when search value matches multiple items (getSearchOptions)', () => { @@ -2960,8 +2960,8 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterOptions(options, 'fantastic'); expect(filteredOptions.recentReports.length).toBe(2); - expect(filteredOptions.recentReports[0].text).toBe('Mister Fantastic'); - expect(filteredOptions.recentReports[1].text).toBe('Mister Fantastic, Invisible Woman'); + expect(filteredOptions.recentReports.at(0).text).toBe('Mister Fantastic'); + expect(filteredOptions.recentReports.at(1).text).toBe('Mister Fantastic, Invisible Woman'); return waitForBatchedUpdates() .then(() => Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, PERSONAL_DETAILS_WITH_PERIODS)) @@ -2971,7 +2971,7 @@ describe('OptionsListUtils', () => { const filteredResults = OptionsListUtils.filterOptions(results, 'barry.allen@expensify.com', {sortByReportTypeInSearch: true}); expect(filteredResults.recentReports.length).toBe(1); - expect(filteredResults.recentReports[0].text).toBe('The Flash'); + expect(filteredResults.recentReports.at(0).text).toBe('The Flash'); }); }); }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 741b550e093d..1ca5bc0bb37d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -80,15 +80,15 @@ describe('ReportUtils', () => { const participants = ReportUtils.getIconsForParticipants([1, 2, 3, 4, 5], participantsPersonalDetails); expect(participants).toHaveLength(5); - expect(participants[0].source).toBeInstanceOf(Function); - expect(participants[0].name).toBe('(833) 240-3627'); - expect(participants[0].id).toBe(4); - expect(participants[0].type).toBe('avatar'); + expect(participants.at(0).source).toBeInstanceOf(Function); + expect(participants.at(0).name).toBe('(833) 240-3627'); + expect(participants.at(0).id).toBe(4); + expect(participants.at(0).type).toBe('avatar'); - expect(participants[1].source).toBeInstanceOf(Function); - expect(participants[1].name).toBe('floki@vikings.net'); - expect(participants[1].id).toBe(2); - expect(participants[1].type).toBe('avatar'); + expect(participants.at(1).source).toBeInstanceOf(Function); + expect(participants.at(1).name).toBe('floki@vikings.net'); + expect(participants.at(1).id).toBe(2); + expect(participants.at(1).type).toBe('avatar'); }); }); @@ -97,18 +97,18 @@ describe('ReportUtils', () => { const participants = ReportUtils.getDisplayNamesWithTooltips(participantsPersonalDetails, false); expect(participants).toHaveLength(5); - expect(participants[0].displayName).toBe('(833) 240-3627'); - expect(participants[0].login).toBe('+18332403627@expensify.sms'); + expect(participants.at(0).displayName).toBe('(833) 240-3627'); + expect(participants.at(0).login).toBe('+18332403627@expensify.sms'); - expect(participants[2].displayName).toBe('Lagertha Lothbrok'); - expect(participants[2].login).toBe('lagertha@vikings.net'); - expect(participants[2].accountID).toBe(3); - expect(participants[2].pronouns).toBe('She/her'); + expect(participants.at(2).displayName).toBe('Lagertha Lothbrok'); + expect(participants.at(2).login).toBe('lagertha@vikings.net'); + expect(participants.at(2).accountID).toBe(3); + expect(participants.at(2).pronouns).toBe('She/her'); - expect(participants[4].displayName).toBe('Ragnar Lothbrok'); - expect(participants[4].login).toBe('ragnar@vikings.net'); - expect(participants[4].accountID).toBe(1); - expect(participants[4].pronouns).toBeUndefined(); + expect(participants.at(4).displayName).toBe('Ragnar Lothbrok'); + expect(participants.at(4).login).toBe('ragnar@vikings.net'); + expect(participants.at(4).accountID).toBe(1); + expect(participants.at(4).pronouns).toBeUndefined(); }); }); @@ -503,7 +503,7 @@ describe('ReportUtils', () => { parentReportID: '101', policyID: paidPolicy.id, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0)]); expect(moneyRequestOptions.length).toBe(0); }); }); @@ -516,7 +516,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), chatType, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0)]); return moneyRequestOptions.length === 1 && moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT); }); expect(onlyHaveSplitOption).toBe(true); @@ -563,7 +563,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0)]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -576,7 +576,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0)]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -625,7 +625,7 @@ describe('ReportUtils', () => { outputCurrency: '', isPolicyExpenseChatEnabled: false, } as const; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0)]); expect(moneyRequestOptions.length).toBe(2); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); @@ -640,7 +640,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0)]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -653,7 +653,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0)]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -687,7 +687,7 @@ describe('ReportUtils', () => { policyID: paidPolicy.id, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0)]); expect(moneyRequestOptions.length).toBe(2); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); @@ -701,7 +701,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.CHAT, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0)]); expect(moneyRequestOptions.length).toBe(3); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); @@ -850,7 +850,7 @@ describe('ReportUtils', () => { const reportActionCollectionDataSet = toCollectionDataSet( ONYXKEYS.COLLECTION.REPORT_ACTIONS, reportActions.map((reportAction) => ({[reportAction.reportActionID]: reportAction})), - (actions) => Object.values(actions)[0].reportActionID, + (actions) => Object.values(actions).at(0).reportActionID, ); Onyx.multiSet({ ...reportCollectionDataSet, @@ -863,13 +863,13 @@ describe('ReportUtils', () => { it('should return correctly all ancestors of a thread report', () => { const resultAncestors = [ - {report: reports[0], reportAction: reportActions[0], shouldDisplayNewMarker: false}, - {report: reports[1], reportAction: reportActions[1], shouldDisplayNewMarker: false}, - {report: reports[2], reportAction: reportActions[2], shouldDisplayNewMarker: false}, - {report: reports[3], reportAction: reportActions[3], shouldDisplayNewMarker: false}, + {report: reports.at(0), reportAction: reportActions.at(0), shouldDisplayNewMarker: false}, + {report: reports.at(1), reportAction: reportActions.at(1), shouldDisplayNewMarker: false}, + {report: reports.at(2), reportAction: reportActions.at(2), shouldDisplayNewMarker: false}, + {report: reports.at(3), reportAction: reportActions.at(3), shouldDisplayNewMarker: false}, ]; - expect(ReportUtils.getAllAncestorReportActions(reports[4])).toEqual(resultAncestors); + expect(ReportUtils.getAllAncestorReportActions(reports.at(4))).toEqual(resultAncestors); }); }); diff --git a/tests/unit/RequestTest.ts b/tests/unit/RequestTest.ts index 74c42cdf02c4..0773cabb4fdb 100644 --- a/tests/unit/RequestTest.ts +++ b/tests/unit/RequestTest.ts @@ -23,7 +23,7 @@ test('Request.use() can register a middleware and it will run', () => { Request.processWithMiddleware(request, true); return waitForBatchedUpdates().then(() => { - const [promise, returnedRequest, isFromSequentialQueue] = testMiddleware.mock.calls[0]; + const [promise, returnedRequest, isFromSequentialQueue] = testMiddleware.mock.calls.at(0); expect(testMiddleware).toHaveBeenCalled(); expect(returnedRequest).toEqual(request); expect(isFromSequentialQueue).toBe(true); diff --git a/tests/unit/SidebarOrderTest.ts b/tests/unit/SidebarOrderTest.ts index b8a507289e8d..ba2fa842383f 100644 --- a/tests/unit/SidebarOrderTest.ts +++ b/tests/unit/SidebarOrderTest.ts @@ -148,9 +148,9 @@ describe('Sidebar', () => { const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('Three, Four'); - expect(displayNames[2]).toHaveTextContent('One, Two'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('Three, Four'); + expect(displayNames.at(2)).toHaveTextContent('One, Two'); }) ); }); @@ -201,9 +201,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('One, Two'); // this has `hasDraft` flag enabled so it will be on top - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('One, Two'); // this has `hasDraft` flag enabled so it will be on top + expect(displayNames.at(1)).toHaveTextContent('Five, Six'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); }) ); }); @@ -252,9 +252,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('One, Two'); - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('One, Two'); + expect(displayNames.at(1)).toHaveTextContent('Five, Six'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); }) ); }); @@ -306,10 +306,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent(taskReportName); - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); - expect(displayNames[3]).toHaveTextContent('One, Two'); + expect(displayNames.at(0)).toHaveTextContent(taskReportName); + expect(displayNames.at(1)).toHaveTextContent('Five, Six'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); + expect(displayNames.at(3)).toHaveTextContent('One, Two'); }) ); }); @@ -370,10 +370,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Email Two owes $100.00'); - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); - expect(displayNames[3]).toHaveTextContent('One, Two'); + expect(displayNames.at(0)).toHaveTextContent('Email Two owes $100.00'); + expect(displayNames.at(1)).toHaveTextContent('Five, Six'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); + expect(displayNames.at(3)).toHaveTextContent('One, Two'); }) ); }); @@ -438,10 +438,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Workspace owes $100.00'); - expect(displayNames[1]).toHaveTextContent('Email Five'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); - expect(displayNames[3]).toHaveTextContent('One, Two'); + expect(displayNames.at(0)).toHaveTextContent('Workspace owes $100.00'); + expect(displayNames.at(1)).toHaveTextContent('Email Five'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); + expect(displayNames.at(3)).toHaveTextContent('One, Two'); }) ); }); @@ -498,9 +498,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Three, Four'); - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('One, Two'); + expect(displayNames.at(0)).toHaveTextContent('Three, Four'); + expect(displayNames.at(1)).toHaveTextContent('Five, Six'); + expect(displayNames.at(2)).toHaveTextContent('One, Two'); }) ); }); @@ -655,9 +655,9 @@ describe('Sidebar', () => { expect(displayNames).toHaveLength(3); expect(screen.queryAllByTestId('Pin Icon')).toHaveLength(1); expect(screen.queryAllByTestId('Pencil Icon')).toHaveLength(1); - expect(displayNames[0]).toHaveTextContent('Email Two owes $100.00'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('Email Two owes $100.00'); + expect(displayNames.at(1)).toHaveTextContent('One, Two'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); }) ); }); @@ -707,9 +707,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('One, Two'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); }) // When a new report is added @@ -720,10 +720,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Seven, Eight'); - expect(displayNames[3]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('One, Two'); + expect(displayNames.at(2)).toHaveTextContent('Seven, Eight'); + expect(displayNames.at(3)).toHaveTextContent('Three, Four'); }) ); }); @@ -776,9 +776,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('One, Two'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); }) // When a new report is added @@ -796,10 +796,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Seven, Eight'); - expect(displayNames[3]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('One, Two'); + expect(displayNames.at(2)).toHaveTextContent('Seven, Eight'); + expect(displayNames.at(3)).toHaveTextContent('Three, Four'); }) ); }); @@ -851,9 +851,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('Three, Four'); - expect(displayNames[2]).toHaveTextContent('Report (archived)'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('Three, Four'); + expect(displayNames.at(2)).toHaveTextContent('Report (archived)'); }) ); }); @@ -891,9 +891,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('One, Two'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); }) // When a new report is added @@ -904,10 +904,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Seven, Eight'); - expect(displayNames[3]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('One, Two'); + expect(displayNames.at(2)).toHaveTextContent('Seven, Eight'); + expect(displayNames.at(3)).toHaveTextContent('Three, Four'); }) ); }); @@ -958,9 +958,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('Three, Four'); - expect(displayNames[2]).toHaveTextContent('Report (archived)'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('Three, Four'); + expect(displayNames.at(2)).toHaveTextContent('Report (archived)'); }) ); }); @@ -1098,11 +1098,11 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(5); - expect(displayNames[0]).toHaveTextContent('Email Five owes $100.00'); - expect(displayNames[1]).toHaveTextContent('Email Four owes $1,000.00'); - expect(displayNames[2]).toHaveTextContent('Email Six owes $100.00'); - expect(displayNames[3]).toHaveTextContent('Email Three owes $100.00'); - expect(displayNames[4]).toHaveTextContent('Email Two owes $100.00'); + expect(displayNames.at(0)).toHaveTextContent('Email Five owes $100.00'); + expect(displayNames.at(1)).toHaveTextContent('Email Four owes $1,000.00'); + expect(displayNames.at(2)).toHaveTextContent('Email Six owes $100.00'); + expect(displayNames.at(3)).toHaveTextContent('Email Three owes $100.00'); + expect(displayNames.at(4)).toHaveTextContent('Email Two owes $100.00'); }) ); }); @@ -1153,9 +1153,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames.at(0)).toHaveTextContent('Five, Six'); + expect(displayNames.at(1)).toHaveTextContent('One, Two'); + expect(displayNames.at(2)).toHaveTextContent('Three, Four'); }) ); }); diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index 6913d39b7f34..7ca1fc1b6ab8 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -82,11 +82,11 @@ describe('Sidebar', () => { .then(() => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames[0]).toHaveTextContent('Report (archived)'); + expect(displayNames.at(0)).toHaveTextContent('Report (archived)'); const hintMessagePreviewText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); const messagePreviewTexts = screen.queryAllByLabelText(hintMessagePreviewText); - expect(messagePreviewTexts[0]).toHaveTextContent('This chat room has been archived.'); + expect(messagePreviewTexts.at(0)).toHaveTextContent('This chat room has been archived.'); }) ); }); @@ -137,11 +137,11 @@ describe('Sidebar', () => { .then(() => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames[0]).toHaveTextContent('Report (archived)'); + expect(displayNames.at(0)).toHaveTextContent('Report (archived)'); const hintMessagePreviewText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); const messagePreviewTexts = screen.queryAllByLabelText(hintMessagePreviewText); - expect(messagePreviewTexts[0]).toHaveTextContent('This chat is no longer active because Vikings Policy is no longer an active workspace.'); + expect(messagePreviewTexts.at(0)).toHaveTextContent('This chat is no longer active because Vikings Policy is no longer an active workspace.'); }) ); }); diff --git a/tests/unit/WorkflowUtilsTest.ts b/tests/unit/WorkflowUtilsTest.ts index cc5649a24fcf..ec2e4ad03ac8 100644 --- a/tests/unit/WorkflowUtilsTest.ts +++ b/tests/unit/WorkflowUtilsTest.ts @@ -319,15 +319,15 @@ describe('WorkflowUtils', () => { const workflows = WorkflowUtils.convertPolicyEmployeesToApprovalWorkflows({employees, defaultApprover, personalDetails}); const defaultWorkflow = buildWorkflow([2, 3, 4], [1, 3, 4], {isDefault: true}); - defaultWorkflow.approvers[0].forwardsTo = '3@example.com'; - defaultWorkflow.approvers[1].forwardsTo = '4@example.com'; - defaultWorkflow.approvers[1].isInMultipleWorkflows = true; - defaultWorkflow.approvers[2].isInMultipleWorkflows = true; + defaultWorkflow.approvers.at(0).forwardsTo = '3@example.com'; + defaultWorkflow.approvers.at(1).forwardsTo = '4@example.com'; + defaultWorkflow.approvers.at(1).isInMultipleWorkflows = true; + defaultWorkflow.approvers.at(2).isInMultipleWorkflows = true; const secondWorkflow = buildWorkflow([1], [2, 3, 4]); - secondWorkflow.approvers[0].forwardsTo = '3@example.com'; - secondWorkflow.approvers[1].forwardsTo = '4@example.com'; - secondWorkflow.approvers[1].isInMultipleWorkflows = true; - secondWorkflow.approvers[2].isInMultipleWorkflows = true; + secondWorkflow.approvers.at(0).forwardsTo = '3@example.com'; + secondWorkflow.approvers.at(1).forwardsTo = '4@example.com'; + secondWorkflow.approvers.at(1).isInMultipleWorkflows = true; + secondWorkflow.approvers.at(2).isInMultipleWorkflows = true; expect(workflows).toEqual([defaultWorkflow, secondWorkflow]); }); @@ -371,8 +371,8 @@ describe('WorkflowUtils', () => { const defaultWorkflow = buildWorkflow([1, 4, 5, 6], [1], {isDefault: true}); const secondWorkflow = buildWorkflow([2, 3], [4, 5, 6]); - secondWorkflow.approvers[0].forwardsTo = '5@example.com'; - secondWorkflow.approvers[1].forwardsTo = '6@example.com'; + secondWorkflow.approvers.at(0).forwardsTo = '5@example.com'; + secondWorkflow.approvers.at(1).forwardsTo = '6@example.com'; expect(workflows).toEqual([defaultWorkflow, secondWorkflow]); }); }); diff --git a/tests/unit/createOrUpdateStagingDeployTest.ts b/tests/unit/createOrUpdateStagingDeployTest.ts index 8cd340f317c7..59ed5b247ca3 100644 --- a/tests/unit/createOrUpdateStagingDeployTest.ts +++ b/tests/unit/createOrUpdateStagingDeployTest.ts @@ -145,13 +145,13 @@ describe('createOrUpdateStagingDeployCash', () => { // eslint-disable-next-line max-len body: `${baseExpectedOutput('1.0.1-0')}` + - `${closedCheckbox}${basePRList[0]}` + - `${lineBreak}${closedCheckbox}${basePRList[1]}` + - `${lineBreak}${closedCheckbox}${basePRList[2]}${lineBreak}` + + `${closedCheckbox}${basePRList.at(0)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(1)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(2)}${lineBreak}` + `${lineBreakDouble}${deployBlockerHeader}` + - `${lineBreak}${closedCheckbox}${basePRList[0]}` + - `${lineBreak}${closedCheckbox}${basePRList[3]}` + - `${lineBreak}${closedCheckbox}${basePRList[4]}` + + `${lineBreak}${closedCheckbox}${basePRList.at(0)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(3)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(4)}` + `${lineBreakDouble}${ccApplauseLeads}`, }; @@ -194,9 +194,9 @@ describe('createOrUpdateStagingDeployCash', () => { assignees: [CONST.APPLAUSE_BOT], body: `${baseExpectedOutput()}` + - `${openCheckbox}${basePRList[5]}` + - `${lineBreak}${openCheckbox}${basePRList[6]}` + - `${lineBreak}${openCheckbox}${basePRList[7]}${lineBreak}` + + `${openCheckbox}${basePRList.at(5)}` + + `${lineBreak}${openCheckbox}${basePRList.at(6)}` + + `${lineBreak}${openCheckbox}${basePRList.at(7)}${lineBreak}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + `${lineBreak}${openCheckbox}${firebaseVerification}` + @@ -214,13 +214,13 @@ describe('createOrUpdateStagingDeployCash', () => { // eslint-disable-next-line max-len body: `${baseExpectedOutput()}` + - `${openCheckbox}${basePRList[5]}` + - `${lineBreak}${closedCheckbox}${basePRList[6]}` + - `${lineBreak}${openCheckbox}${basePRList[7]}${lineBreak}` + + `${openCheckbox}${basePRList.at(5)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(6)}` + + `${lineBreak}${openCheckbox}${basePRList.at(7)}${lineBreak}` + `${lineBreakDouble}${deployBlockerHeader}` + - `${lineBreak}${openCheckbox}${basePRList[5]}` + - `${lineBreak}${openCheckbox}${basePRList[8]}` + - `${lineBreak}${closedCheckbox}${basePRList[9]}${lineBreak}` + + `${lineBreak}${openCheckbox}${basePRList.at(5)}` + + `${lineBreak}${openCheckbox}${basePRList.at(8)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(9)}${lineBreak}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${closedCheckbox}${timingDashboardVerification}` + `${lineBreak}${closedCheckbox}${firebaseVerification}` + @@ -309,17 +309,17 @@ describe('createOrUpdateStagingDeployCash', () => { // eslint-disable-next-line max-len body: `${baseExpectedOutput('1.0.2-2')}` + - `${openCheckbox}${basePRList[5]}` + - `${lineBreak}${closedCheckbox}${basePRList[6]}` + - `${lineBreak}${openCheckbox}${basePRList[7]}` + - `${lineBreak}${openCheckbox}${basePRList[8]}` + - `${lineBreak}${openCheckbox}${basePRList[9]}${lineBreak}` + + `${openCheckbox}${basePRList.at(5)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(6)}` + + `${lineBreak}${openCheckbox}${basePRList.at(7)}` + + `${lineBreak}${openCheckbox}${basePRList.at(8)}` + + `${lineBreak}${openCheckbox}${basePRList.at(9)}${lineBreak}` + `${lineBreakDouble}${deployBlockerHeader}` + - `${lineBreak}${openCheckbox}${basePRList[5]}` + - `${lineBreak}${openCheckbox}${basePRList[8]}` + - `${lineBreak}${closedCheckbox}${basePRList[9]}` + - `${lineBreak}${openCheckbox}${baseIssueList[0]}` + - `${lineBreak}${openCheckbox}${baseIssueList[1]}${lineBreak}` + + `${lineBreak}${openCheckbox}${basePRList.at(5)}` + + `${lineBreak}${openCheckbox}${basePRList.at(8)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(9)}` + + `${lineBreak}${openCheckbox}${baseIssueList.at(0)}` + + `${lineBreak}${openCheckbox}${baseIssueList.at(1)}${lineBreak}` + `${lineBreakDouble}${deployerVerificationsHeader}` + // Note: these will be unchecked with a new app version, and that's intentional `${lineBreak}${openCheckbox}${timingDashboardVerification}` + @@ -385,15 +385,15 @@ describe('createOrUpdateStagingDeployCash', () => { // eslint-disable-next-line max-len body: `${baseExpectedOutput('1.0.2-1')}` + - `${openCheckbox}${basePRList[5]}` + - `${lineBreak}${closedCheckbox}${basePRList[6]}` + - `${lineBreak}${openCheckbox}${basePRList[7]}${lineBreak}` + + `${openCheckbox}${basePRList.at(5)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(6)}` + + `${lineBreak}${openCheckbox}${basePRList.at(7)}${lineBreak}` + `${lineBreakDouble}${deployBlockerHeader}` + - `${lineBreak}${closedCheckbox}${basePRList[5]}` + - `${lineBreak}${openCheckbox}${basePRList[8]}` + - `${lineBreak}${closedCheckbox}${basePRList[9]}` + - `${lineBreak}${openCheckbox}${baseIssueList[0]}` + - `${lineBreak}${openCheckbox}${baseIssueList[1]}${lineBreak}` + + `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + + `${lineBreak}${openCheckbox}${basePRList.at(8)}` + + `${lineBreak}${closedCheckbox}${basePRList.at(9)}` + + `${lineBreak}${openCheckbox}${baseIssueList.at(0)}` + + `${lineBreak}${openCheckbox}${baseIssueList.at(1)}${lineBreak}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${closedCheckbox}${timingDashboardVerification}` + `${lineBreak}${closedCheckbox}${firebaseVerification}` + diff --git a/tests/unit/generateMonthMatrixTest.ts b/tests/unit/generateMonthMatrixTest.ts index a0605204c1c1..9f6dd9bc6c09 100644 --- a/tests/unit/generateMonthMatrixTest.ts +++ b/tests/unit/generateMonthMatrixTest.ts @@ -130,6 +130,6 @@ describe('generateMonthMatrix', () => { it('returns a matrix with 6 rows and 7 columns for January 2022', () => { const matrix = generateMonthMatrix(2022, 0); expect(matrix.length).toBe(6); - expect(matrix[0].length).toBe(7); + expect(matrix.at(0).length).toBe(7); }); }); diff --git a/tests/unit/versionUpdaterTest.ts b/tests/unit/versionUpdaterTest.ts index 384395c4acef..d04dbcdb0a44 100644 --- a/tests/unit/versionUpdaterTest.ts +++ b/tests/unit/versionUpdaterTest.ts @@ -11,7 +11,7 @@ describe('versionUpdater', () => { it('should return build as zero if not present in string', () => { const versionWithZeroBuild = [VERSION_NUMBER[0], VERSION_NUMBER[1], VERSION_NUMBER[2], 0]; - expect(versionUpdater.getVersionNumberFromString(VERSION.split('-')[0])).toStrictEqual(versionWithZeroBuild); + expect(versionUpdater.getVersionNumberFromString(VERSION.split('-').at(0))).toStrictEqual(versionWithZeroBuild); }); }); @@ -61,7 +61,7 @@ describe('versionUpdater', () => { }); it('should add BUILD number if there is no BUILD number', () => { - expect(versionUpdater.incrementVersion(VERSION.split('-')[0], versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD)).toStrictEqual('2.3.9-1'); + expect(versionUpdater.incrementVersion(VERSION.split('-').at(0), versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD)).toStrictEqual('2.3.9-1'); }); it('should increment patch if MINOR is above max level', () => { diff --git a/tests/utils/LHNTestUtils.tsx b/tests/utils/LHNTestUtils.tsx index 7197529cd43c..c16d18455046 100644 --- a/tests/utils/LHNTestUtils.tsx +++ b/tests/utils/LHNTestUtils.tsx @@ -197,7 +197,7 @@ function getFakeReportWithPolicy(participantAccountIDs = [1, 2], millisecondsInT policyID: '08CE60F05A5D86E1', oldPolicyName: '', isOwnPolicyExpenseChat: false, - ownerAccountID: participantAccountIDs[0], + ownerAccountID: participantAccountIDs.at(0), }; } diff --git a/tests/utils/ReportTestUtils.ts b/tests/utils/ReportTestUtils.ts index deab909cd272..e14ad738c29d 100644 --- a/tests/utils/ReportTestUtils.ts +++ b/tests/utils/ReportTestUtils.ts @@ -55,7 +55,7 @@ const getMockedSortedReportActions = (length = 100): ReportAction[] => const getMockedReportActionsMap = (length = 100): ReportActions => { const mockReports: ReportActions[] = Array.from({length}, (element, index): ReportActions => { const reportID = index + 1; - const actionName: ReportActionName = index === 0 ? 'CREATED' : actionNames[index % actionNames.length]; + const actionName: ReportActionName = index === 0 ? 'CREATED' : actionNames.at(index % actionNames.length); const reportAction = { ...createRandomReportAction(reportID), actionName,