From e00eda977d6561d4683b77f1a77ff5055b8722c5 Mon Sep 17 00:00:00 2001 From: Jack Senyitko Date: Wed, 27 May 2026 10:31:52 -0400 Subject: [PATCH 1/5] add card rule search --- src/components/SpendRules/SpendRulesSection.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/components/SpendRules/SpendRulesSection.tsx b/src/components/SpendRules/SpendRulesSection.tsx index 6471b7eca0c3..c489e896afc7 100644 --- a/src/components/SpendRules/SpendRulesSection.tsx +++ b/src/components/SpendRules/SpendRulesSection.tsx @@ -16,11 +16,13 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useOnyx from '@hooks/useOnyx'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import useSearchResults from '@hooks/useSearchResults'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {openPolicyExpensifyCardsPage} from '@libs/actions/Policy/Policy'; import Navigation from '@libs/Navigation/Navigation'; +import tokenizedSearch from '@libs/tokenizedSearch'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -45,6 +47,13 @@ function SpendRulesSection({policyID}: SpendRulesSectionProps) { const [expensifyCardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${defaultFundID}`); const {cardRules, isLoadingCardRules} = useExpensifyCardRules(policyID); + const filterCardRules = (cardRule: (typeof cardRules)[number], searchInput: string) => { + const results = tokenizedSearch([cardRule], searchInput, (option) => option.searchTokens); + return results.length > 0; + }; + + const [inputValue, setInputValue, filteredCardRules] = useSearchResults(cardRules, filterCardRules); + useEffect(() => { if (!defaultFundID || defaultFundID === CONST.DEFAULT_NUMBER_ID) { return; From f5cf09b7b7161e8898d735b280e95d0fd44c6dd4 Mon Sep 17 00:00:00 2001 From: Jack Senyitko Date: Wed, 27 May 2026 10:33:27 -0400 Subject: [PATCH 2/5] add the searchbar --- src/components/SpendRules/SpendRulesSection.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/components/SpendRules/SpendRulesSection.tsx b/src/components/SpendRules/SpendRulesSection.tsx index c489e896afc7..05425b80e24f 100644 --- a/src/components/SpendRules/SpendRulesSection.tsx +++ b/src/components/SpendRules/SpendRulesSection.tsx @@ -5,6 +5,7 @@ import Badge from '@components/Badge'; import Icon from '@components/Icon'; import MenuItem from '@components/MenuItem'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; +import SearchBar from '@components/SearchBar'; import Section from '@components/Section'; import Text from '@components/Text'; import useConfirmModal from '@hooks/useConfirmModal'; @@ -141,6 +142,14 @@ function SpendRulesSection({policyID}: SpendRulesSectionProps) { isCentralPane subtitleMuted > + {cardRules.length > CONST.STANDARD_LIST_ITEM_LIMIT && ( + + )} Date: Wed, 27 May 2026 10:35:08 -0400 Subject: [PATCH 3/5] finish styles off --- src/components/SpendRules/SpendRulesSection.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/SpendRules/SpendRulesSection.tsx b/src/components/SpendRules/SpendRulesSection.tsx index 05425b80e24f..4b1b3985a9ef 100644 --- a/src/components/SpendRules/SpendRulesSection.tsx +++ b/src/components/SpendRules/SpendRulesSection.tsx @@ -148,10 +148,11 @@ function SpendRulesSection({policyID}: SpendRulesSectionProps) { inputValue={inputValue} onChangeText={setInputValue} shouldShowEmptyState={!isLoadingCardRules && filteredCardRules.length === 0} + style={[styles.mb0, styles.mt5, styles.mh0]} /> )} ) : ( - cardRules.map((rule) => ( + filteredCardRules.map((rule) => ( Date: Wed, 27 May 2026 10:43:58 -0400 Subject: [PATCH 4/5] use gte instead of gt --- src/components/SpendRules/SpendRulesSection.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SpendRules/SpendRulesSection.tsx b/src/components/SpendRules/SpendRulesSection.tsx index 4b1b3985a9ef..2851c4a63b97 100644 --- a/src/components/SpendRules/SpendRulesSection.tsx +++ b/src/components/SpendRules/SpendRulesSection.tsx @@ -142,7 +142,7 @@ function SpendRulesSection({policyID}: SpendRulesSectionProps) { isCentralPane subtitleMuted > - {cardRules.length > CONST.STANDARD_LIST_ITEM_LIMIT && ( + {cardRules.length >= CONST.STANDARD_LIST_ITEM_LIMIT && ( Date: Wed, 27 May 2026 15:29:50 -0400 Subject: [PATCH 5/5] use tuple to union --- src/components/SpendRules/SpendRulesSection.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/SpendRules/SpendRulesSection.tsx b/src/components/SpendRules/SpendRulesSection.tsx index 2851c4a63b97..9a2ac9ac433f 100644 --- a/src/components/SpendRules/SpendRulesSection.tsx +++ b/src/components/SpendRules/SpendRulesSection.tsx @@ -1,5 +1,6 @@ import React, {useEffect} from 'react'; import {View} from 'react-native'; +import type {TupleToUnion} from 'type-fest'; import ActivityIndicator from '@components/ActivityIndicator'; import Badge from '@components/Badge'; import Icon from '@components/Icon'; @@ -48,7 +49,7 @@ function SpendRulesSection({policyID}: SpendRulesSectionProps) { const [expensifyCardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${defaultFundID}`); const {cardRules, isLoadingCardRules} = useExpensifyCardRules(policyID); - const filterCardRules = (cardRule: (typeof cardRules)[number], searchInput: string) => { + const filterCardRules = (cardRule: TupleToUnion, searchInput: string) => { const results = tokenizedSearch([cardRule], searchInput, (option) => option.searchTokens); return results.length > 0; };