From a3c3f00948b25fe773969f69084751abf590cefc Mon Sep 17 00:00:00 2001 From: KJ21-ENG <140263938+KJ21-ENG@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:17:24 +0000 Subject: [PATCH 1/5] Remove unsafe assertions from date filters, state selection, and account indicators Seatbelt-Operation: fresh-54053af7-sign-6824e9fc-fa97-471f-86fa-0e391484be1b --- .../FilterComponents/DatePresetFilterBase.tsx | 24 ++++- .../StatePicker/StateSelectorModal.tsx | 12 +-- src/hooks/useAccountIndicatorChecks.ts | 100 ++++++++++-------- ...resetFilterBaseCustomDateModifiersTest.tsx | 47 +++++++- tests/ui/StateSelectorModalTest.tsx | 54 +++++++++- tests/unit/useAccountIndicatorChecksTest.ts | 42 ++++++++ 6 files changed, 220 insertions(+), 59 deletions(-) diff --git a/src/components/Search/FilterComponents/DatePresetFilterBase.tsx b/src/components/Search/FilterComponents/DatePresetFilterBase.tsx index 7ba66d33a828..22beaf1536cf 100644 --- a/src/components/Search/FilterComponents/DatePresetFilterBase.tsx +++ b/src/components/Search/FilterComponents/DatePresetFilterBase.tsx @@ -11,7 +11,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import type {SearchDateValues} from '@libs/SearchQueryUtils'; import {getDateRangeDisplayValueFromFormValue, getEmptyDateValues, getRangeBoundariesFromFormValue, getRangeQueryValue, isSearchDatePreset} from '@libs/SearchQueryUtils'; -import type {SearchDateModifier, SearchDateModifierLower} from '@libs/SearchUIUtils'; +import type {SearchDateModifier} from '@libs/SearchUIUtils'; import CONST from '@src/CONST'; @@ -24,6 +24,14 @@ import RangeDatePicker from './RangeDatePicker'; type CustomDateModifier = Exclude; +const CUSTOM_DATE_MODIFIER_TRANSLATION_KEYS: { + [Modifier in CustomDateModifier]: Lowercase; +} = { + [CONST.SEARCH.DATE_MODIFIERS.ON]: 'on', + [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: 'before', + [CONST.SEARCH.DATE_MODIFIERS.AFTER]: 'after', +}; + const normalizeDateValues = (dateValues: Partial | SearchDateValues): SearchDateValues => ({ ...getEmptyDateValues(), ...dateValues, @@ -251,7 +259,10 @@ function DatePresetFilterBase({ [getInitialEphemeralDateValue], ); - const [rangeEphemeralValues, setRangeEphemeralValues] = useState<{from?: string; to?: string}>(() => getRangeEphemeralValuesFromDateValues(normalizedDefaultDateValues)); + const [rangeEphemeralValues, setRangeEphemeralValues] = useState<{ + from?: string; + to?: string; + }>(() => getRangeEphemeralValuesFromDateValues(normalizedDefaultDateValues)); // Synchronize dateValues when rangeEphemeralValues change, keeping the side effect // out of the setRangeEphemeralValues state updater to avoid unpredictable batching on Android. @@ -345,7 +356,10 @@ function DatePresetFilterBase({ } const currentDateValues = dateValuesRef.current; - updateDateValues({...currentDateValues, [selectedDateModifier]: undefined}); + updateDateValues({ + ...currentDateValues, + [selectedDateModifier]: undefined, + }); if (selectedDateModifier === CONST.SEARCH.DATE_MODIFIERS.RANGE) { setRangeEphemeralValues({}); @@ -390,7 +404,7 @@ function DatePresetFilterBase({ return undefined; } - return `${translate(`common.${customDateModifier.toLowerCase() as SearchDateModifierLower}`)} ${customDateValue}`; + return `${translate(`common.${CUSTOM_DATE_MODIFIER_TRANSLATION_KEYS[customDateModifier]}`)} ${customDateValue}`; }, [customDateModifier, dateDisplayValues, translate]); const handleSingleDateSelected = useCallback((date: string) => { setEphemeralDateValue(date); @@ -483,7 +497,7 @@ function DatePresetFilterBase({ showTooltip item={{ keyForList: dateModifier, - text: translate(`common.${dateModifier.toLowerCase() as SearchDateModifierLower}`), + text: translate(`common.${CUSTOM_DATE_MODIFIER_TRANSLATION_KEYS[dateModifier]}`), isSelected: selectedDateModifier === dateModifier, }} onSelectRow={() => selectDateModifier(dateModifier)} diff --git a/src/components/StatePicker/StateSelectorModal.tsx b/src/components/StatePicker/StateSelectorModal.tsx index 7dfe8c26ed9d..bf5425509b53 100644 --- a/src/components/StatePicker/StateSelectorModal.tsx +++ b/src/components/StatePicker/StateSelectorModal.tsx @@ -19,8 +19,6 @@ import CONST from '@src/CONST'; import {CONST as COMMON_CONST} from 'expensify-common'; import React, {useMemo} from 'react'; -type State = keyof typeof COMMON_CONST.STATES; - type StateSelectorModalProps = { isVisible: boolean; @@ -39,14 +37,16 @@ function StateSelectorModal({isVisible, currentState, onStateSelected, onClose, const {translate} = useLocalize(); const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState(''); const styles = useThemeStyles(); - const initialSelectedValue = useInitialSelection(currentState || undefined, {isVisible}); + const initialSelectedValue = useInitialSelection(currentState || undefined, { + isVisible, + }); const initialSelectedValues = initialSelectedValue ? [initialSelectedValue] : []; const countryStates = useMemo( () => - Object.keys(COMMON_CONST.STATES).map((state) => { - const stateName = translate(`allStates.${state as State}.stateName`); - const stateISO = translate(`allStates.${state as State}.stateISO`); + Object.values(COMMON_CONST.STATES).map(({stateISO: stateKey}) => { + const stateName = translate(`allStates.${stateKey}.stateName`); + const stateISO = translate(`allStates.${stateKey}.stateISO`); return { value: stateISO, keyForList: stateISO, diff --git a/src/hooks/useAccountIndicatorChecks.ts b/src/hooks/useAccountIndicatorChecks.ts index 82a139d19fc8..40c280b3521a 100644 --- a/src/hooks/useAccountIndicatorChecks.ts +++ b/src/hooks/useAccountIndicatorChecks.ts @@ -24,7 +24,9 @@ function useAccountIndicatorChecks(): AccountIndicatorChecksResult { const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS); - const [loginList] = useOnyx(ONYXKEYS.LOGINS, {selector: expensifyLoginsSelector}); + const [loginList] = useOnyx(ONYXKEYS.LOGINS, { + selector: expensifyLoginsSelector, + }); const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); const [allCards] = useOnyx(`${ONYXKEYS.CARD_LIST}`); const [stripeCustomerId] = useOnyx(ONYXKEYS.NVP_PRIVATE_STRIPE_CUSTOMER_ID); @@ -38,7 +40,9 @@ function useAccountIndicatorChecks(): AccountIndicatorChecksResult { const [session] = useOnyx(ONYXKEYS.SESSION); const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT); const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - const [hasDeviceManagementErrorValue] = useOnyx(ONYXKEYS.LOGINS, {selector: hasDeviceManagementError}); + const [hasDeviceManagementErrorValue] = useOnyx(ONYXKEYS.LOGINS, { + selector: hasDeviceManagementError, + }); const { companyCards: {shouldShowRBR: hasCompanyCardFeedErrors}, @@ -46,54 +50,60 @@ function useAccountIndicatorChecks(): AccountIndicatorChecksResult { const {isPolicyAdmin} = usePoliciesWithCardFeedErrors(); const {shouldShowAddHomeAddress} = useTimeSensitiveHomeAddress(); - const accountChecks: Partial> = { - [CONST.INDICATOR_STATUS.HAS_USER_WALLET_ERRORS]: Object.keys(userWallet?.errors ?? {}).length > 0, - [CONST.INDICATOR_STATUS.HAS_PAYMENT_METHOD_ERROR]: hasPaymentMethodError(bankAccountList, fundList, allCards, session, policies), - [CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_ERRORS]: hasSubscriptionRedDotError( - stripeCustomerId, - retryBillingSuccessful, - billingDisputePending, - retryBillingFailed, - fundList, - billingStatus, - amountOwed, - ownerBillingGracePeriodEnd, - ownerTravelBillingGracePeriodEnd, - ), - [CONST.INDICATOR_STATUS.HAS_REIMBURSEMENT_ACCOUNT_ERRORS]: Object.keys(reimbursementAccount?.errors ?? {}).length > 0, - [CONST.INDICATOR_STATUS.HAS_LOGIN_LIST_ERROR]: !!loginList && hasLoginListError(loginList), + const accountChecks: Array<[IndicatorStatus, boolean | undefined]> = [ + [CONST.INDICATOR_STATUS.HAS_USER_WALLET_ERRORS, Object.keys(userWallet?.errors ?? {}).length > 0], + [CONST.INDICATOR_STATUS.HAS_PAYMENT_METHOD_ERROR, hasPaymentMethodError(bankAccountList, fundList, allCards, session, policies)], + [ + CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_ERRORS, + hasSubscriptionRedDotError( + stripeCustomerId, + retryBillingSuccessful, + billingDisputePending, + retryBillingFailed, + fundList, + billingStatus, + amountOwed, + ownerBillingGracePeriodEnd, + ownerTravelBillingGracePeriodEnd, + ), + ], + [CONST.INDICATOR_STATUS.HAS_REIMBURSEMENT_ACCOUNT_ERRORS, Object.keys(reimbursementAccount?.errors ?? {}).length > 0], + [CONST.INDICATOR_STATUS.HAS_LOGIN_LIST_ERROR, !!loginList && hasLoginListError(loginList)], // Wallet term errors that are not caused by an IOU (we show the red brick indicator for those in the LHN instead) - [CONST.INDICATOR_STATUS.HAS_WALLET_TERMS_ERRORS]: Object.keys(walletTerms?.errors ?? {}).length > 0 && !walletTerms?.chatReportID, - [CONST.INDICATOR_STATUS.HAS_PHONE_NUMBER_ERROR]: !!privatePersonalDetails?.errorFields?.phoneNumber, - [CONST.INDICATOR_STATUS.HAS_EMPLOYEE_CARD_FEED_ERRORS]: !isPolicyAdmin ? hasCompanyCardFeedErrors : false, - [CONST.INDICATOR_STATUS.HAS_LOCKED_BANK_ACCOUNT]: Object.values(bankAccountList ?? {}).some((bankAccount) => bankAccount?.accountData?.state === CONST.BANK_ACCOUNT.STATE.LOCKED), - [CONST.INDICATOR_STATUS.HAS_DEVICE_MANAGEMENT_ERROR]: hasDeviceManagementErrorValue, - }; + [CONST.INDICATOR_STATUS.HAS_WALLET_TERMS_ERRORS, Object.keys(walletTerms?.errors ?? {}).length > 0 && !walletTerms?.chatReportID], + [CONST.INDICATOR_STATUS.HAS_PHONE_NUMBER_ERROR, !!privatePersonalDetails?.errorFields?.phoneNumber], + [CONST.INDICATOR_STATUS.HAS_EMPLOYEE_CARD_FEED_ERRORS, !isPolicyAdmin ? hasCompanyCardFeedErrors : false], + [CONST.INDICATOR_STATUS.HAS_LOCKED_BANK_ACCOUNT, Object.values(bankAccountList ?? {}).some((bankAccount) => bankAccount?.accountData?.state === CONST.BANK_ACCOUNT.STATE.LOCKED)], + [CONST.INDICATOR_STATUS.HAS_DEVICE_MANAGEMENT_ERROR, hasDeviceManagementErrorValue], + ]; - const infoChecks: Partial> = { - [CONST.INDICATOR_STATUS.HAS_LOGIN_LIST_INFO]: !!loginList && hasLoginListInfo(loginList, session?.email), - [CONST.INDICATOR_STATUS.HAS_HOME_ADDRESS_INFO]: shouldShowAddHomeAddress, - [CONST.INDICATOR_STATUS.HAS_PENDING_CARD_INFO]: hasPendingExpensifyCardAction(allCards, privatePersonalDetails) || hasCardPendingDigitalWalletApproval(allCards), - [CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_INFO]: hasSubscriptionGreenDotInfo( - stripeCustomerId, - retryBillingSuccessful, - billingDisputePending, - retryBillingFailed, - fundList, - billingStatus, - amountOwed, - ownerBillingGracePeriodEnd, - ownerTravelBillingGracePeriodEnd, - ), - [CONST.INDICATOR_STATUS.HAS_PARTIALLY_SETUP_BANK_ACCOUNT_INFO]: hasPartiallySetupBankAccount(bankAccountList) || hasPersonalBankAccountMissingInfo(bankAccountList), - }; + const infoChecks: Array<[IndicatorStatus, boolean]> = [ + [CONST.INDICATOR_STATUS.HAS_LOGIN_LIST_INFO, !!loginList && hasLoginListInfo(loginList, session?.email)], + [CONST.INDICATOR_STATUS.HAS_HOME_ADDRESS_INFO, shouldShowAddHomeAddress], + [CONST.INDICATOR_STATUS.HAS_PENDING_CARD_INFO, hasPendingExpensifyCardAction(allCards, privatePersonalDetails) || hasCardPendingDigitalWalletApproval(allCards)], + [ + CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_INFO, + hasSubscriptionGreenDotInfo( + stripeCustomerId, + retryBillingSuccessful, + billingDisputePending, + retryBillingFailed, + fundList, + billingStatus, + amountOwed, + ownerBillingGracePeriodEnd, + ownerTravelBillingGracePeriodEnd, + ), + ], + [CONST.INDICATOR_STATUS.HAS_PARTIALLY_SETUP_BANK_ACCOUNT_INFO, hasPartiallySetupBankAccount(bankAccountList) || hasPersonalBankAccountMissingInfo(bankAccountList)], + ]; - const [accountStatus] = Object.entries(accountChecks).find(([, value]) => value) ?? []; - const [infoStatus] = Object.entries(infoChecks).find(([, value]) => value) ?? []; + const accountStatus = accountChecks.find(([, value]) => value)?.[0]; + const infoStatus = infoChecks.find(([, value]) => value)?.[0]; return { - accountStatus: accountStatus as IndicatorStatus | undefined, - infoStatus: infoStatus as IndicatorStatus | undefined, + accountStatus, + infoStatus, }; } diff --git a/tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx b/tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx index d36c66c6cc2d..94c2742897b1 100644 --- a/tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx +++ b/tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx @@ -100,7 +100,10 @@ describe('DatePresetFilterBase allowedCustomDateModifiers', () => { it('offers a single-day calendar labelled Custom day when only On is allowed', () => { // Given the picker as Insights renders it, which only reports on closed periods const onSelectDateModifier = jest.fn(); - renderDatePresetFilterBase({allowedCustomDateModifiers: [CONST.SEARCH.DATE_MODIFIERS.ON], onSelectDateModifier}); + renderDatePresetFilterBase({ + allowedCustomDateModifiers: [CONST.SEARCH.DATE_MODIFIERS.ON], + onSelectDateModifier, + }); expect(screen.queryByText(CUSTOM_DATE)).not.toBeOnTheScreen(); // When the Custom day option is opened @@ -117,7 +120,10 @@ describe('DatePresetFilterBase allowedCustomDateModifiers', () => { // Given an unbounded Before date, which Insights does not support const onSelectDateModifier = jest.fn(); renderDatePresetFilterBase({ - defaultDateValues: {...emptyDateValues, [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: '2026-03-04'}, + defaultDateValues: { + ...emptyDateValues, + [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: '2026-03-04', + }, allowedCustomDateModifiers: [CONST.SEARCH.DATE_MODIFIERS.ON], onSelectDateModifier, }); @@ -128,4 +134,41 @@ describe('DatePresetFilterBase allowedCustomDateModifiers', () => { // Then the picker switches to On rather than reviving the Before modifier the caller ruled out expect(onSelectDateModifier).toHaveBeenCalledWith(CONST.SEARCH.DATE_MODIFIERS.ON); }); + + it('shows and selects After when it is the only allowed modifier', () => { + // Given a picker restricted to the After modifier + const onSelectDateModifier = jest.fn(); + renderDatePresetFilterBase({ + defaultDateValues: {...emptyDateValues, [CONST.SEARCH.DATE_MODIFIERS.AFTER]: '2026-03-04'}, + allowedCustomDateModifiers: [CONST.SEARCH.DATE_MODIFIERS.AFTER], + onSelectDateModifier, + }); + + expect(screen.getByText(/^(After|common\.after) 2026-03-04$/)).toBeOnTheScreen(); + + // When the custom date option is opened + fireEvent.press(screen.getByText(CUSTOM_DATE), PRESS_EVENT); + + // Then After is selected without offering the other modifier rows + expect(onSelectDateModifier).toHaveBeenCalledWith(CONST.SEARCH.DATE_MODIFIERS.AFTER); + for (const row of MODIFIER_ROWS) { + expect(screen.queryByText(row)).not.toBeOnTheScreen(); + } + }); + + it('uses the modifier translation in the custom date description', () => { + // Given a saved custom Before date + renderDatePresetFilterBase({ + defaultDateValues: { + ...emptyDateValues, + [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: '2026-03-04', + }, + }); + + // When the picker displays its collapsed custom date option + const description = screen.getByText(/^(Before|common\.before) 2026-03-04$/); + + // Then its description includes the translated modifier and stored date + expect(description).toBeOnTheScreen(); + }); }); diff --git a/tests/ui/StateSelectorModalTest.tsx b/tests/ui/StateSelectorModalTest.tsx index fc7ab7da0959..594eab0ba54b 100644 --- a/tests/ui/StateSelectorModalTest.tsx +++ b/tests/ui/StateSelectorModalTest.tsx @@ -69,8 +69,33 @@ describe('StateSelectorModal', () => { mockedSelectionList.mockClear(); }); - it('pins the saved state to the top on reopen', () => { + it('renders every installed state with its translated name and ISO', () => { + // Given the production state list and translation-backed modal render( + , + ); + + // When the modal builds the unfiltered list + const options = mockedSelectionList.mock.lastCall?.[0].data; + + // Then all 52 states appear in source order with translated names and codes + expect(options).toHaveLength(52); + expect(options?.map(({keyForList, text}) => ({keyForList, text}))).toEqual( + Object.values(mockStates).map(({stateISO, stateName}) => ({ + keyForList: stateISO, + text: stateName, + })), + ); + }); + + it('pins the saved state to the top on reopen', () => { + const {rerender} = render( { }), ); expect(selectionListProps?.initiallyFocusedItemKey).toBe('NY'); + + // Given a newly saved selection while the modal is closed + rerender( + , + ); + + // When the modal reopens + rerender( + , + ); + + // Then the changed selection is pinned and focused + const reopenedProps = mockedSelectionList.mock.lastCall?.[0]; + expect(reopenedProps?.data.at(0)).toEqual(expect.objectContaining({keyForList: 'CA', isSelected: true})); + expect(reopenedProps?.initiallyFocusedItemKey).toBe('CA'); }); it('keeps natural filtered ordering while search is active', () => { diff --git a/tests/unit/useAccountIndicatorChecksTest.ts b/tests/unit/useAccountIndicatorChecksTest.ts index 602f01920c8c..1db3445b4e96 100644 --- a/tests/unit/useAccountIndicatorChecksTest.ts +++ b/tests/unit/useAccountIndicatorChecksTest.ts @@ -512,6 +512,48 @@ describe('useAccountIndicatorChecks', () => { }); describe('error takes priority over info', () => { + it('returns the first truthy status in each category when multiple checks match', async () => { + // Given simultaneous wallet and bank-account errors, plus login and subscription info + await act(async () => { + await Onyx.multiSet( + createMock({ + [ONYXKEYS.USER_WALLET]: {errors: {error: 'Wallet error'}}, + [ONYXKEYS.BANK_ACCOUNT_LIST]: { + // eslint-disable-next-line @typescript-eslint/naming-convention + 12345: { + methodID: 12345, + errors: {error: 'Bank account error'}, + }, + }, + [ONYXKEYS.LOGINS]: { + // eslint-disable-next-line @typescript-eslint/naming-convention + '1_otheruser@expensify.com': { + partnerID: 1, + partnerUserID: 'different@expensify.com', + validatedDate: undefined, + }, + }, + [ONYXKEYS.REIMBURSEMENT_ACCOUNT]: {}, + [ONYXKEYS.WALLET_TERMS]: {}, + [ONYXKEYS.PRIVATE_PERSONAL_DETAILS]: {}, + [ONYXKEYS.CARD_LIST]: {}, + [ONYXKEYS.NVP_PRIVATE_BILLING_DISPUTE_PENDING]: 0, + [ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL]: true, + [ONYXKEYS.SESSION]: {email: userID}, + }), + ); + await waitForBatchedUpdatesWithAct(); + }); + + // When the real hook evaluates both ordered check lists + const {result} = renderHook(() => useAccountIndicatorChecks()); + await waitForBatchedUpdatesWithAct(); + + // Then the first matching error and info status win independently + expect(result.current.accountStatus).toBe(CONST.INDICATOR_STATUS.HAS_USER_WALLET_ERRORS); + expect(result.current.infoStatus).toBe(CONST.INDICATOR_STATUS.HAS_LOGIN_LIST_INFO); + }); + it('returns both accountStatus and infoStatus independently', async () => { await act(async () => { await Onyx.multiSet( From ab5c3f300732077d10f3376120fd741b3ca15fa9 Mon Sep 17 00:00:00 2001 From: KJ21-ENG <140263938+KJ21-ENG@users.noreply.github.com> Date: Tue, 6 Oct 2026 12:36:18 +0000 Subject: [PATCH 2/5] Restore canonical date modifier type usage Seatbelt-Operation: knip-54053af7-sign-5da5386e-1ae5-4b97-ac74-bbbeea894aa6 --- .../Search/FilterComponents/DatePresetFilterBase.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Search/FilterComponents/DatePresetFilterBase.tsx b/src/components/Search/FilterComponents/DatePresetFilterBase.tsx index 22beaf1536cf..1edc733734a8 100644 --- a/src/components/Search/FilterComponents/DatePresetFilterBase.tsx +++ b/src/components/Search/FilterComponents/DatePresetFilterBase.tsx @@ -11,7 +11,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import type {SearchDateValues} from '@libs/SearchQueryUtils'; import {getDateRangeDisplayValueFromFormValue, getEmptyDateValues, getRangeBoundariesFromFormValue, getRangeQueryValue, isSearchDatePreset} from '@libs/SearchQueryUtils'; -import type {SearchDateModifier} from '@libs/SearchUIUtils'; +import type {SearchDateModifier, SearchDateModifierLower} from '@libs/SearchUIUtils'; import CONST from '@src/CONST'; @@ -25,7 +25,7 @@ import RangeDatePicker from './RangeDatePicker'; type CustomDateModifier = Exclude; const CUSTOM_DATE_MODIFIER_TRANSLATION_KEYS: { - [Modifier in CustomDateModifier]: Lowercase; + [Modifier in CustomDateModifier]: Extract>; } = { [CONST.SEARCH.DATE_MODIFIERS.ON]: 'on', [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: 'before', From b13a7228d3214f50c815202db4616dfb0b026b70 Mon Sep 17 00:00:00 2001 From: KJ21-ENG <140263938+KJ21-ENG@users.noreply.github.com> Date: Mon, 2 Nov 2026 18:11:58 +0000 Subject: [PATCH 3/5] test: justify account indicator lint suppressions Add a reason to the two naming-convention suppressions this PR added. Comments only. Addresses https://github.com/Expensify/App/pull/103165#discussion_r4441968673 Seatbelt-Operation: repair-codex-103165-sign-628a2cdf-85b2-4ceb-9255-22d28c9062c0 Co-Authored-By: Claude Opus 5.5 --- tests/unit/useAccountIndicatorChecksTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/useAccountIndicatorChecksTest.ts b/tests/unit/useAccountIndicatorChecksTest.ts index 3f1524b4949b..5040717701a8 100644 --- a/tests/unit/useAccountIndicatorChecksTest.ts +++ b/tests/unit/useAccountIndicatorChecksTest.ts @@ -747,14 +747,14 @@ describe('useAccountIndicatorChecks', () => { createMock({ [ONYXKEYS.USER_WALLET]: {errors: {error: 'Wallet error'}}, [ONYXKEYS.BANK_ACCOUNT_LIST]: { - // eslint-disable-next-line @typescript-eslint/naming-convention + // eslint-disable-next-line @typescript-eslint/naming-convention -- This fixture key is a numeric bank account ID, so it cannot follow the naming rule. 12345: { methodID: 12345, errors: {error: 'Bank account error'}, }, }, [ONYXKEYS.LOGINS]: { - // eslint-disable-next-line @typescript-eslint/naming-convention + // eslint-disable-next-line @typescript-eslint/naming-convention -- This fixture key contains an email address, so it cannot follow the naming rule. '1_otheruser@expensify.com': { partnerID: 1, partnerUserID: 'different@expensify.com', From 489d7eeac2ca188f7dd9273e77ce3d57e47bdb52 Mon Sep 17 00:00:00 2001 From: KJ21-ENG <140263938+KJ21-ENG@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:08:35 +0000 Subject: [PATCH 4/5] style: revert unintended line wrapping Address review: keep the existing single-line formatting so the diff only holds the real changes. --- .../FilterComponents/DatePresetFilterBase.tsx | 10 ++-------- .../StatePicker/StateSelectorModal.tsx | 4 +--- src/hooks/useAccountIndicatorChecks.ts | 4 +--- ...resetFilterBaseCustomDateModifiersTest.tsx | 20 ++++--------------- tests/ui/StateSelectorModalTest.tsx | 7 +------ tests/unit/useAccountIndicatorChecksTest.ts | 8 ++------ 6 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/components/Search/FilterComponents/DatePresetFilterBase.tsx b/src/components/Search/FilterComponents/DatePresetFilterBase.tsx index 62d5522b95a6..9b062d8789a3 100644 --- a/src/components/Search/FilterComponents/DatePresetFilterBase.tsx +++ b/src/components/Search/FilterComponents/DatePresetFilterBase.tsx @@ -242,10 +242,7 @@ function DatePresetFilterBase({ const [ephemeralDateValue, setEphemeralDateValue] = useState(() => getInitialEphemeralDateValue(selectedDateModifier)); const resetEphemeralDateValue = (dateModifier: SearchDateModifier | null) => setEphemeralDateValue(getInitialEphemeralDateValue(dateModifier)); - const [rangeEphemeralValues, setRangeEphemeralValues] = useState<{ - from?: string; - to?: string; - }>(() => getRangeEphemeralValuesFromDateValues(normalizedDefaultDateValues)); + const [rangeEphemeralValues, setRangeEphemeralValues] = useState<{from?: string; to?: string}>(() => getRangeEphemeralValuesFromDateValues(normalizedDefaultDateValues)); // Synchronize dateValues when rangeEphemeralValues change, keeping the side effect // out of the setRangeEphemeralValues state updater to avoid unpredictable batching on Android. @@ -336,10 +333,7 @@ function DatePresetFilterBase({ } const currentDateValues = dateValuesRef.current; - updateDateValues({ - ...currentDateValues, - [selectedDateModifier]: undefined, - }); + updateDateValues({...currentDateValues, [selectedDateModifier]: undefined}); if (selectedDateModifier === CONST.SEARCH.DATE_MODIFIERS.RANGE) { setRangeEphemeralValues({}); diff --git a/src/components/StatePicker/StateSelectorModal.tsx b/src/components/StatePicker/StateSelectorModal.tsx index e8b8e4032d7c..20f8a782f977 100644 --- a/src/components/StatePicker/StateSelectorModal.tsx +++ b/src/components/StatePicker/StateSelectorModal.tsx @@ -37,9 +37,7 @@ function StateSelectorModal({isVisible, currentState, onStateSelected, onClose, const {translate} = useLocalize(); const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState(''); const styles = useThemeStyles(); - const initialSelectedValue = useInitialSelection(currentState || undefined, { - isVisible, - }); + const initialSelectedValue = useInitialSelection(currentState || undefined, {isVisible}); const initialSelectedValues = initialSelectedValue ? [initialSelectedValue] : []; const countryStates = Object.values(COMMON_CONST.STATES).map(({stateISO: stateKey}) => { diff --git a/src/hooks/useAccountIndicatorChecks.ts b/src/hooks/useAccountIndicatorChecks.ts index 72f0885dfdd1..7168e8001d0d 100644 --- a/src/hooks/useAccountIndicatorChecks.ts +++ b/src/hooks/useAccountIndicatorChecks.ts @@ -26,9 +26,7 @@ function useAccountIndicatorChecks(): AccountIndicatorChecksResult { const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS); - const [loginList] = useOnyx(ONYXKEYS.LOGINS, { - selector: expensifyLoginsSelector, - }); + const [loginList] = useOnyx(ONYXKEYS.LOGINS, {selector: expensifyLoginsSelector}); const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); const [allCards] = useOnyx(`${ONYXKEYS.CARD_LIST}`); const [stripeCustomerId] = useOnyx(ONYXKEYS.NVP_PRIVATE_STRIPE_CUSTOMER_ID); diff --git a/tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx b/tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx index dfa2f25da28c..2ef7be2a14ba 100644 --- a/tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx +++ b/tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx @@ -100,10 +100,7 @@ describe('DatePresetFilterBase allowedCustomDateModifiers', () => { it('offers a single-day calendar labelled Custom date when only On is allowed', () => { // Given the picker as Insights renders it, which only reports on closed periods const onSelectDateModifier = jest.fn(); - renderDatePresetFilterBase({ - allowedCustomDateModifiers: [CONST.SEARCH.DATE_MODIFIERS.ON], - onSelectDateModifier, - }); + renderDatePresetFilterBase({allowedCustomDateModifiers: [CONST.SEARCH.DATE_MODIFIERS.ON], onSelectDateModifier}); expect(screen.queryByText(CUSTOM_DAY)).not.toBeOnTheScreen(); // When the Custom date option is opened @@ -120,10 +117,7 @@ describe('DatePresetFilterBase allowedCustomDateModifiers', () => { // Given an unbounded Before date, which Insights does not support const onSelectDateModifier = jest.fn(); renderDatePresetFilterBase({ - defaultDateValues: { - ...emptyDateValues, - [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: '2026-03-04', - }, + defaultDateValues: {...emptyDateValues, [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: '2026-03-04'}, allowedCustomDateModifiers: [CONST.SEARCH.DATE_MODIFIERS.ON], onSelectDateModifier, }); @@ -139,10 +133,7 @@ describe('DatePresetFilterBase allowedCustomDateModifiers', () => { // Given a picker restricted to the After modifier const onSelectDateModifier = jest.fn(); renderDatePresetFilterBase({ - defaultDateValues: { - ...emptyDateValues, - [CONST.SEARCH.DATE_MODIFIERS.AFTER]: '2026-03-04', - }, + defaultDateValues: {...emptyDateValues, [CONST.SEARCH.DATE_MODIFIERS.AFTER]: '2026-03-04'}, allowedCustomDateModifiers: [CONST.SEARCH.DATE_MODIFIERS.AFTER], onSelectDateModifier, }); @@ -162,10 +153,7 @@ describe('DatePresetFilterBase allowedCustomDateModifiers', () => { it('uses the modifier translation in the custom date description', () => { // Given a saved custom Before date renderDatePresetFilterBase({ - defaultDateValues: { - ...emptyDateValues, - [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: '2026-03-04', - }, + defaultDateValues: {...emptyDateValues, [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: '2026-03-04'}, }); // When the picker displays its collapsed custom date option diff --git a/tests/ui/StateSelectorModalTest.tsx b/tests/ui/StateSelectorModalTest.tsx index 594eab0ba54b..acf95945740a 100644 --- a/tests/ui/StateSelectorModalTest.tsx +++ b/tests/ui/StateSelectorModalTest.tsx @@ -86,12 +86,7 @@ describe('StateSelectorModal', () => { // Then all 52 states appear in source order with translated names and codes expect(options).toHaveLength(52); - expect(options?.map(({keyForList, text}) => ({keyForList, text}))).toEqual( - Object.values(mockStates).map(({stateISO, stateName}) => ({ - keyForList: stateISO, - text: stateName, - })), - ); + expect(options?.map(({keyForList, text}) => ({keyForList, text}))).toEqual(Object.values(mockStates).map(({stateISO, stateName}) => ({keyForList: stateISO, text: stateName}))); }); it('pins the saved state to the top on reopen', () => { diff --git a/tests/unit/useAccountIndicatorChecksTest.ts b/tests/unit/useAccountIndicatorChecksTest.ts index 356ca4ba44b1..7d2ed774ee95 100644 --- a/tests/unit/useAccountIndicatorChecksTest.ts +++ b/tests/unit/useAccountIndicatorChecksTest.ts @@ -452,9 +452,7 @@ describe('useAccountIndicatorChecks', () => { cardID: 1, lastScrapeResult: 403, lastScrape: '2020-01-01 00:00:00', - errors: { - [Date.now() * 1000]: 'Failed to unassign this card.', - }, + errors: {[Date.now() * 1000]: 'Failed to unassign this card.'}, }, }, [ONYXKEYS.SESSION]: {email: userID}, @@ -487,9 +485,7 @@ describe('useAccountIndicatorChecks', () => { fundID: String(cardFeed.policyAccountID), lastScrapeResult: 403, lastScrape: '2020-01-01 00:00:00', - errors: { - [Date.now() * 1000]: 'Failed to unassign this card.', - }, + errors: {[Date.now() * 1000]: 'Failed to unassign this card.'}, }, }, [`${ONYXKEYS.COLLECTION.POLICY}1` as const]: { From 9a27a909cff2d362e43d019967ea4cbef804ad14 Mon Sep 17 00:00:00 2001 From: KJ21-ENG <140263938+KJ21-ENG@users.noreply.github.com> Date: Wed, 11 Nov 2026 10:20:29 +0000 Subject: [PATCH 5/5] fix: keep React Compiler caching in useAccountIndicatorChecks Move the first-match lookup into getFirstMatchingStatus. Calling find on the local check list let the compiler drop the cache for every check, so they ran on each render. With the helper they stay cached, as on main. --- src/hooks/useAccountIndicatorChecks.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/hooks/useAccountIndicatorChecks.ts b/src/hooks/useAccountIndicatorChecks.ts index 7168e8001d0d..4dd9360586ae 100644 --- a/src/hooks/useAccountIndicatorChecks.ts +++ b/src/hooks/useAccountIndicatorChecks.ts @@ -21,6 +21,11 @@ type AccountIndicatorChecksResult = { infoStatus: IndicatorStatus | undefined; }; +/** Returns the status of the first check that matches, so the order of the checks sets their priority. */ +function getFirstMatchingStatus(checks: Array<[IndicatorStatus, boolean | undefined]>): IndicatorStatus | undefined { + return checks.find(([, value]) => value)?.[0]; +} + function useAccountIndicatorChecks(): AccountIndicatorChecksResult { const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); @@ -100,8 +105,8 @@ function useAccountIndicatorChecks(): AccountIndicatorChecksResult { [CONST.INDICATOR_STATUS.HAS_WISE_MORE_INFO_NEEDED_INFO, wiseMoreInfoNeededBankAccounts.length > 0], ]; - const accountStatus = accountChecks.find(([, value]) => value)?.[0]; - const infoStatus = infoChecks.find(([, value]) => value)?.[0]; + const accountStatus = getFirstMatchingStatus(accountChecks); + const infoStatus = getFirstMatchingStatus(infoChecks); return { accountStatus,