From fe433512fa1e9c941690746c44e8bc5fc623393e Mon Sep 17 00:00:00 2001 From: zfurtak Date: Tue, 1 Oct 2024 16:29:45 +0100 Subject: [PATCH] Adjusted to reviews --- ios/NewExpensify.xcodeproj/project.pbxproj | 6 +++--- package.json | 2 +- src/components/ButtonWithDropdownMenu/index.tsx | 2 +- .../EmojiPicker/EmojiPickerMenu/index.native.tsx | 2 +- .../EmojiPicker/EmojiPickerMenu/index.tsx | 2 +- src/components/LHNOptionsList/OptionRowLHN.tsx | 7 ++++--- src/components/MenuItem.tsx | 7 +++---- src/components/OptionRow.tsx | 6 +++--- src/hooks/useReviewDuplicatesNavigation.tsx | 2 +- src/hooks/useViolations.ts | 8 ++------ src/languages/en.ts | 2 +- src/languages/es.ts | 2 +- src/libs/ActiveClientManager/index.ts | 2 +- src/libs/IOUUtils.ts | 2 +- src/libs/Middleware/Pagination.ts | 2 +- .../createCustomStackNavigator/index.tsx | 2 +- src/libs/NextStepUtils.ts | 2 +- src/libs/PaginationUtils.ts | 2 +- src/libs/ReportUtils.ts | 6 ++++-- src/libs/SearchUtils.ts | 7 +++++-- src/libs/SidebarUtils.ts | 2 +- src/libs/actions/IOU.ts | 2 +- src/libs/actions/OnyxUpdateManager/utils/index.ts | 2 +- src/libs/actions/Policy/Category.ts | 2 +- src/libs/actions/Policy/Policy.ts | 2 +- src/libs/actions/Policy/Tag.ts | 2 +- src/libs/actions/Welcome/OnboardingFlow.ts | 2 +- src/pages/Search/SearchTypeMenuNarrow.tsx | 13 +++++-------- .../report/ReportActionCompose/SuggestionEmoji.tsx | 4 ++-- .../ReportActionCompose/SuggestionMention.tsx | 2 +- src/pages/home/report/ReportActionItemSingle.tsx | 2 +- src/pages/home/report/ReportActionsView.tsx | 4 ++-- 32 files changed, 55 insertions(+), 57 deletions(-) diff --git a/ios/NewExpensify.xcodeproj/project.pbxproj b/ios/NewExpensify.xcodeproj/project.pbxproj index 1a29a275b956..65a18af19a74 100644 --- a/ios/NewExpensify.xcodeproj/project.pbxproj +++ b/ios/NewExpensify.xcodeproj/project.pbxproj @@ -43,7 +43,7 @@ D27CE6B77196EF3EF450EEAC /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 0D3F9E814828D91464DF9D35 /* PrivacyInfo.xcprivacy */; }; DD79042B2792E76D004484B4 /* RCTBootSplash.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD79042A2792E76D004484B4 /* RCTBootSplash.mm */; }; DDCB2E57F334C143AC462B43 /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D20D83B0E39BA6D21761E72 /* ExpoModulesProvider.swift */; }; - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; E9DF872D2525201700607FDC /* AirshipConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = E9DF872C2525201700607FDC /* AirshipConfig.plist */; }; ED222ED90E074A5481A854FA /* ExpensifyNeue-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 8B28D84EF339436DBD42A203 /* ExpensifyNeue-BoldItalic.otf */; }; F0C450EA2705020500FD2970 /* colors.json in Resources */ = {isa = PBXBuildFile; fileRef = F0C450E92705020500FD2970 /* colors.json */; }; @@ -176,8 +176,8 @@ buildActionMask = 2147483647; files = ( 383643682B6D4AE2005BB9AE /* DeviceCheck.framework in Frameworks */, - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */, - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */, + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */, + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */, 8744C5400E24E379441C04A4 /* libPods-NewExpensify.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/package.json b/package.json index ac920465b47c..f4ac5dbe8c3b 100644 --- a/package.json +++ b/package.json @@ -377,4 +377,4 @@ "node": "20.15.1", "npm": "10.7.0" } -} \ No newline at end of file +} diff --git a/src/components/ButtonWithDropdownMenu/index.tsx b/src/components/ButtonWithDropdownMenu/index.tsx index f6d19f0789a9..e1d7beb850d0 100644 --- a/src/components/ButtonWithDropdownMenu/index.tsx +++ b/src/components/ButtonWithDropdownMenu/index.tsx @@ -110,7 +110,7 @@ function ButtonWithDropdownMenu({ if (!isSplitButton) { setIsMenuVisible(!isMenuVisible); } else if (selectedItem?.value) { - onPress(event, selectedItem?.value); + onPress(event, selectedItem.value); } }, [isMenuVisible, isSplitButton, onPress, selectedItem?.value], diff --git a/src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx b/src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx index ec3374670550..ee4858bb0be0 100644 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.native.tsx @@ -91,7 +91,7 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r ); } - const emojiCode = typeof preferredSkinTone === 'number' && types?.at(preferredSkinTone) ? types.at(preferredSkinTone) : code; + const emojiCode = typeof preferredSkinTone === 'number' && preferredSkinTone !== -1 && types?.at(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 7cd5c33792c9..0fd51651ab18 100755 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.tsx +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.tsx @@ -180,7 +180,7 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r return; } if ('types' in item || 'name' in item) { - const emoji = typeof preferredSkinTone === 'number' && item?.types?.at(preferredSkinTone) ? item.types.at(preferredSkinTone) : item.code; + const emoji = typeof preferredSkinTone === 'number' && preferredSkinTone !== -1 && item?.types?.at(preferredSkinTone) ? item.types.at(preferredSkinTone) : item.code; onEmojiSelected(emoji ?? '', item); } }, diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index 94469b10a713..c9c7227b493d 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -162,6 +162,8 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti const isStatusVisible = !!emojiCode && ReportUtils.isOneOnOneChat(!isEmptyObject(report) ? report : undefined); const subscriptAvatarBorderColor = isFocused ? focusedBackgroundColor : theme.sidebar; + const firstIcon = optionItem.icons?.at(0); + return ( {}, opti {!!optionItem.icons?.length && + firstIcon && (optionItem.shouldShowSubscript ? ( diff --git a/src/components/MenuItem.tsx b/src/components/MenuItem.tsx index d469c31b4dbe..f530e1781034 100644 --- a/src/components/MenuItem.tsx +++ b/src/components/MenuItem.tsx @@ -445,6 +445,7 @@ function MenuItem( const isDeleted = style && Array.isArray(style) ? style.includes(styles.offlineFeedback.deleted) : false; const descriptionVerticalMargin = shouldShowDescriptionOnTop ? styles.mb1 : styles.mt1; const fallbackAvatarSize = viewMode === CONST.OPTION_MODE.COMPACT ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT; + const firstIcon = floatRightAvatars.at(0); const combinedTitleTextStyle = StyleUtils.combineStyles( [ styles.flexShrink1, @@ -776,14 +777,12 @@ function MenuItem( {subtitle} )} - {floatRightAvatars?.length > 0 && ( + {floatRightAvatars?.length > 0 && firstIcon && ( {shouldShowSubscriptRightAvatar ? ( diff --git a/src/components/OptionRow.tsx b/src/components/OptionRow.tsx index 3770b277babb..1b6519f4fd44 100644 --- a/src/components/OptionRow.tsx +++ b/src/components/OptionRow.tsx @@ -146,6 +146,7 @@ function OptionRow({ const hoveredBackgroundColor = hoveredStyle?.backgroundColor ? (hoveredStyle.backgroundColor as string) : backgroundColor; const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; const shouldUseShortFormInTooltip = (option.participantsList?.length ?? 0) > 1; + const firstIcon = option?.icons?.at(0); // We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade. const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips((option.participantsList ?? (option.accountID ? [option] : [])).slice(0, 10), shouldUseShortFormInTooltip); @@ -207,11 +208,10 @@ function OptionRow({ {!!option.icons?.length && + firstIcon && (option.shouldShowSubscript ? ( { if (currentScreenName === 'confirmation') { - setPrevScreen(intersection.length > 0 ? intersection.at(intersection.length - 1) : undefined); + setPrevScreen(intersection.length > 0 ? intersection.at(-1) : undefined); return; } const currentIndex = intersection.indexOf(currentScreenName); diff --git a/src/hooks/useViolations.ts b/src/hooks/useViolations.ts index 37868903d130..5eb77f2d45e7 100644 --- a/src/hooks/useViolations.ts +++ b/src/hooks/useViolations.ts @@ -80,14 +80,11 @@ function useViolations(violations: TransactionViolation[], shouldShowOnlyViolati const getViolationsForField = useCallback( (field: ViolationField, data?: TransactionViolation['data'], policyHasDependentTags = false, tagValue?: string) => { const currentViolations = violationsByField.get(field) ?? []; + const firstViolation = currentViolations.at(0); // 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.at(0)?.name === CONST.VIOLATIONS.SOME_TAG_LEVELS_REQUIRED && - data?.tagListIndex !== undefined && - Array.isArray(currentViolations.at(0)?.data?.errorIndexes) - ) { + if (firstViolation?.name === CONST.VIOLATIONS.SOME_TAG_LEVELS_REQUIRED && data?.tagListIndex !== undefined && Array.isArray(firstViolation?.data?.errorIndexes)) { return currentViolations .filter((violation) => violation.data?.errorIndexes?.includes(data?.tagListIndex ?? -1)) .map((violation) => ({ @@ -98,7 +95,6 @@ function useViolations(violations: TransactionViolation[], shouldShowOnlyViolati }, })); } - const firstViolation = currentViolations.at(0); // 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 diff --git a/src/languages/en.ts b/src/languages/en.ts index 56015050da87..c223912cdd6e 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -4022,7 +4022,7 @@ const translations = { } else if (submittersNames.length === 2) { joinedNames = submittersNames.join(' and '); } else if (submittersNames.length > 2) { - joinedNames = `${submittersNames.slice(0, submittersNames.length - 1).join(', ')} and ${submittersNames.at(submittersNames.length - 1)}`; + joinedNames = `${submittersNames.slice(0, submittersNames.length - 1).join(', ')} and ${submittersNames.at(-1)}`; } return { one: `removed you from ${joinedNames}'s approval workflow and workspace chat. Previously submitted reports will remain available for approval in your Inbox.`, diff --git a/src/languages/es.ts b/src/languages/es.ts index c8ed5d16bc23..e9d4639f4681 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -4066,7 +4066,7 @@ const translations = { } else if (submittersNames.length === 2) { joinedNames = submittersNames.join(' y '); } else if (submittersNames.length > 2) { - joinedNames = `${submittersNames.slice(0, submittersNames.length - 1).join(', ')} y ${submittersNames.at(submittersNames.length - 1)}`; + joinedNames = `${submittersNames.slice(0, submittersNames.length - 1).join(', ')} y ${submittersNames.at(-1)}`; } return { one: `te eliminó del flujo de trabajo de aprobaciones y del chat del espacio de trabajo de ${joinedNames}. Los informes enviados anteriormente seguirán estando disponibles para su aprobación en tu bandeja de entrada.`, diff --git a/src/libs/ActiveClientManager/index.ts b/src/libs/ActiveClientManager/index.ts index 159e81de4c1d..55583cd0b083 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.at(activeClients.length - 1); + const lastActiveClient = activeClients.length && activeClients.at(-1); return lastActiveClient === clientID; }; diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index 95c12c52889a..cf2cfa10105c 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -141,7 +141,7 @@ function insertTagIntoTransactionTagsString(transactionTags: string, tag: string const tagArray = TransactionUtils.getTagArrayFromName(transactionTags); tagArray[tagIndex] = tag; - while (tagArray.length > 0 && !tagArray.at(tagArray.length - 1)) { + while (tagArray.length > 0 && !tagArray.at(-1)) { tagArray.pop(); } diff --git a/src/libs/Middleware/Pagination.ts b/src/libs/Middleware/Pagination.ts index 2b4d8de310af..80f36725611a 100644 --- a/src/libs/Middleware/Pagination.ts +++ b/src/libs/Middleware/Pagination.ts @@ -111,7 +111,7 @@ const Pagination: Middleware = (requestResponse, request) => { if ((type === 'initial' && !cursorID) || (type === 'next' && newPage.length === 1 && newPage.at(0) === cursorID)) { newPage.unshift(CONST.PAGINATION_START_ID); } - const pageItem = sortedPageItems.at(sortedPageItems.length - 1); + const pageItem = sortedPageItems.at(-1); if (pageItem && isLastItem(pageItem)) { newPage.push(CONST.PAGINATION_END_ID); } diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx index 04a457d66221..6c153b1b159e 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 (shouldUseNarrowLayout) { const isSearchCentralPane = (route: RouteProp) => getTopmostCentralPaneRoute({routes: [route]} as State)?.name === SCREENS.SEARCH.CENTRAL_PANE; - const lastRoute = routes.at(routes.length - 1); + const lastRoute = routes.at(-1); const lastSearchCentralPane = lastRoute && isSearchCentralPane(lastRoute) ? lastRoute : undefined; const filteredRoutes = routes.filter((route) => !isSearchCentralPane(route)); diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index fe8eb814c98f..4016e2418a50 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -43,7 +43,7 @@ function parseMessage(messages: Message[] | undefined) { let tagType = part.type ?? 'span'; let content = Str.safeEscape(part.text); - const previousPart = messages.at(index - 1); + const previousPart = index !== 0 ? messages.at(index - 1) : undefined; const nextPart = messages.at(index + 1); if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail) { diff --git a/src/libs/PaginationUtils.ts b/src/libs/PaginationUtils.ts index a1c9078898bf..2a214aaae19b 100644 --- a/src/libs/PaginationUtils.ts +++ b/src/libs/PaginationUtils.ts @@ -124,7 +124,7 @@ function mergeAndSortContinuousPages(sortedItems: TResource[], pages: const result = [sortedPages.at(0)]; for (let i = 1; i < sortedPages.length; i++) { const page = sortedPages.at(i); - const prevPage = result.at(result.length - 1); + const prevPage = result.at(-1); if (!page || !prevPage) { // eslint-disable-next-line no-continue diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 79a1a4532739..0bf7c24a7567 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2022,7 +2022,7 @@ function getWorkspaceIcon(report: OnyxInputOrEntry, policy?: OnyxInputOr * Gets the personal details for a login by looking in the ONYXKEYS.PERSONAL_DETAILS_LIST Onyx key (stored in the local variable, allPersonalDetails). If it doesn't exist in Onyx, * then a default object is constructed. */ -function getPersonalDetailsForAccountID(accountID?: number, personalDetailsData?: Partial): Partial { +function getPersonalDetailsForAccountID(accountID: number | undefined, personalDetailsData?: Partial): Partial { if (!accountID) { return {}; } @@ -6441,7 +6441,9 @@ function getNewMarkerReportActionID(report: OnyxEntry, sortedAndFiltered const newMarkerIndex = lodashFindLastIndex(sortedAndFilteredReportActions, (reportAction) => (reportAction.created ?? '') > (report?.lastReadTime ?? '')); - return 'reportActionID' in (sortedAndFilteredReportActions?.at(newMarkerIndex) ?? {}) ? sortedAndFilteredReportActions.at(newMarkerIndex)?.reportActionID ?? '' : ''; + return newMarkerIndex !== -1 && 'reportActionID' in (sortedAndFilteredReportActions?.at(newMarkerIndex) ?? {}) + ? sortedAndFilteredReportActions.at(newMarkerIndex)?.reportActionID ?? '' + : ''; } /** diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index f370cfa176e3..09e4e20668cd 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -743,7 +743,10 @@ function buildFilterString(filterName: string, queryFilters: QueryFilter[], deli 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?.at(index - 1)?.operator === 'eq') || (queryFilter.operator === 'neq' && queryFilters.at(index - 1)?.operator === 'neq')) { + if ( + index !== 0 && + ((queryFilter.operator === 'eq' && queryFilters?.at(index - 1)?.operator === 'eq') || (queryFilter.operator === 'neq' && queryFilters.at(index - 1)?.operator === 'neq')) + ) { filterValueString += `${delimiter}${sanitizeString(queryFilter.value.toString())}`; } else { filterValueString += ` ${filterName}${operatorToSignMap[queryFilter.operator]}${sanitizeString(queryFilter.value.toString())}`; @@ -774,7 +777,7 @@ function getSearchHeaderTitle( .filter(([, taxRateKeys]) => taxRateKeys.some((taxID) => taxRateIDs.includes(taxID))) .map(([taxRate]) => taxRate); displayQueryFilters = taxRateNames.map((taxRate) => ({ - operator: queryFilter.at(0)?.operator ?? 'and', + operator: queryFilter.at(0)?.operator ?? CONST.SEARCH.SYNTAX_OPERATORS.AND, value: taxRate, })); } else { diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index ebd927104473..2958006bb729 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, ); - const reportAction = reportActionsForDisplay.at(reportActionsForDisplay.length - 1); + const reportAction = reportActionsForDisplay.at(-1); if (!reportAction) { return; } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index a3bf320464f2..883b38cff1b5 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6998,7 +6998,7 @@ function isLastApprover(approvalChain: string[]): boolean { if (approvalChain.length === 0) { return true; } - return approvalChain.at(approvalChain.length - 1) === currentUserEmail; + return approvalChain.at(-1) === currentUserEmail; } function getNextApproverAccountID(report: OnyxEntry) { diff --git a/src/libs/actions/OnyxUpdateManager/utils/index.ts b/src/libs/actions/OnyxUpdateManager/utils/index.ts index bd3f5d33707b..9a527308034e 100644 --- a/src/libs/actions/OnyxUpdateManager/utils/index.ts +++ b/src/libs/actions/OnyxUpdateManager/utils/index.ts @@ -93,7 +93,7 @@ function detectGapsAndSplit(lastUpdateIDFromClient: number): DetectGapAndSplitRe if (gapExists) { // If there is a gap and we didn't detect two chained updates, "firstUpdateToBeAppliedAfterGap" will always be the the last deferred update. // We will fetch all missing updates up to the previous update and can always apply the last deferred update. - const firstUpdateToBeAppliedAfterGap = firstUpdateIDAfterGaps ?? Number(updateValues.at(updateValues.length - 1)?.lastUpdateID); + const firstUpdateToBeAppliedAfterGap = firstUpdateIDAfterGaps ?? Number(updateValues.at(-1)?.lastUpdateID); // Add all deferred updates after the gap(s) to "updatesAfterGaps". // If "firstUpdateToBeAppliedAfterGap" is set to the last deferred update, the array will be empty. diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 84da3be6a70d..51c3e29a741c 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -1279,7 +1279,7 @@ function setPolicyCategoryTax(policyID: string, categoryName: string, taxID: str const indexToUpdate = updatedExpenseRules.indexOf(existingCategoryExpenseRule); const expenseRule = updatedExpenseRules.at(indexToUpdate); - if (expenseRule) { + if (expenseRule && indexToUpdate !== -1) { expenseRule.tax.field_id_TAX.externalID = taxID; } } diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 492738b50ba9..38afb082d517 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -1260,7 +1260,7 @@ function updateGeneralSettings(policyID: string, name: string, currencyValue?: s ); const createWorkspaceRequest = persistedRequests.at(createWorkspaceRequestChangedIndex); - if (createWorkspaceRequest) { + if (createWorkspaceRequest && createWorkspaceRequestChangedIndex !== -1) { const workspaceRequest: Request = { ...createWorkspaceRequest, data: { diff --git a/src/libs/actions/Policy/Tag.ts b/src/libs/actions/Policy/Tag.ts index 650f297a967b..2a3080fc810f 100644 --- a/src/libs/actions/Policy/Tag.ts +++ b/src/libs/actions/Policy/Tag.ts @@ -240,7 +240,7 @@ function importPolicyTags(policyID: string, tags: PolicyTag[]) { function setWorkspaceTagEnabled(policyID: string, tagsToUpdate: Record, tagListIndex: number) { const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.at(tagListIndex); - if (!policyTag) { + if (!policyTag || tagListIndex === -1) { return; } diff --git a/src/libs/actions/Welcome/OnboardingFlow.ts b/src/libs/actions/Welcome/OnboardingFlow.ts index 4c275dfdd062..bc89effc9b50 100644 --- a/src/libs/actions/Welcome/OnboardingFlow.ts +++ b/src/libs/actions/Welcome/OnboardingFlow.ts @@ -47,7 +47,7 @@ function adaptOnboardingRouteState() { const adaptedState = rootState; const lastRouteIndex = (adaptedState?.routes?.length ?? 0) - 1; const onBoardingModalNavigatorState = adaptedState?.routes.at(lastRouteIndex)?.state; - if (!onBoardingModalNavigatorState || onBoardingModalNavigatorState?.routes?.length > 1) { + if (!onBoardingModalNavigatorState || onBoardingModalNavigatorState?.routes?.length > 1 || lastRouteIndex === -1) { return; } diff --git a/src/pages/Search/SearchTypeMenuNarrow.tsx b/src/pages/Search/SearchTypeMenuNarrow.tsx index b4f1f6815095..c72b4cf4ded7 100644 --- a/src/pages/Search/SearchTypeMenuNarrow.tsx +++ b/src/pages/Search/SearchTypeMenuNarrow.tsx @@ -101,24 +101,21 @@ function SearchTypeMenuNarrow({typeMenuItems, activeItemIndex, queryJSON, title, return items; }, [typeMenuItems, title, activeItemIndex, singleExecution, theme, policyID, closeMenu, currentSavedSearch]); - const menuIconAndTitle = useMemo(() => { + const {menuIcon, menuTitle} = useMemo(() => { if (title) { return { - icon: Expensicons.Filters, - title, + menuIcon: Expensicons.Filters, + menuTitle: title, }; } const item = activeItemIndex !== -1 ? popoverMenuItems.at(activeItemIndex) : undefined; return { - icon: item?.icon ?? Expensicons.Receipt, - title: item?.text, + menuIcon: item?.icon ?? Expensicons.Receipt, + menuTitle: item?.text, }; }, [activeItemIndex, popoverMenuItems, title]); - const menuIcon = menuIconAndTitle.icon; - const menuTitle = menuIconAndTitle.title; - const titleViewStyles = useMemo(() => (title ? {...styles.flex1, ...styles.justifyContentCenter} : {}), [title, styles]); const savedSearchItems = savedSearchesMenuItems.map((item) => ({ diff --git a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.tsx b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.tsx index c29eb44942b2..2850ed0538db 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.at(highlightedEmojiIndexInner); - const emojiCode = emojiObject?.types?.[preferredSkinTone] ? emojiObject?.types.at(preferredSkinTone) : emojiObject?.code; + const emojiObject = highlightedEmojiIndexInner !== -1 ? suggestionValues.suggestedEmojis.at(highlightedEmojiIndexInner) : undefined; + const emojiCode = emojiObject?.types?.at(preferredSkinTone) && preferredSkinTone !== -1 ? 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 3b94c1a733d9..151993411bd7 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.tsx @@ -194,7 +194,7 @@ function SuggestionMention( (highlightedMentionIndexInner: number) => { const commentBeforeAtSign = value.slice(0, suggestionValues.atSignIndex); const mentionObject = suggestionValues.suggestedMentions.at(highlightedMentionIndexInner); - if (!mentionObject) { + if (!mentionObject || highlightedMentionIndexInner === -1) { return; } const mentionCode = getMentionCode(mentionObject, suggestionValues.prefixType); diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index c8ab97d93bc6..ca11a1b02d26 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.at(avatarIconIndex) ?? {name: '', source: '', type: 'avatar'}; + secondaryAvatar = reportIcons.at(avatarIconIndex) ?? {name: '', source: '', type: CONST.ICON_TYPE_AVATAR}; } else { secondaryAvatar = {name: '', source: '', type: 'avatar'}; } diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 6794ffbefb8b..8f4395fdb715 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -150,7 +150,7 @@ function ReportActionsView({ } const actions = [...allReportActions]; - const lastAction = allReportActions.at(allReportActions.length - 1); + const lastAction = allReportActions.at(-1); if (lastAction && !ReportActionsUtils.isCreatedAction(lastAction)) { const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(String(report?.ownerAccountID), DateUtils.subtractMillisecondsFromDateTime(lastAction.created, 1)); @@ -183,7 +183,7 @@ function ReportActionsView({ false, false, false, - DateUtils.subtractMillisecondsFromDateTime(actions.at(actions.length - 1)?.created ?? '', 1), + DateUtils.subtractMillisecondsFromDateTime(actions.at(-1)?.created ?? '', 1), ) as OnyxTypes.ReportAction; moneyRequestActions.push(optimisticIOUAction); actions.splice(actions.length - 1, 0, optimisticIOUAction);