From 6313f337f78e548e3b1730b6f79b4546e94ac37d Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Fri, 20 Jun 2025 17:43:06 +0100 Subject: [PATCH 01/46] added Accounting section --- src/libs/SearchUIUtils.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index e7dce4c232cc..d554e152ff1f 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1392,6 +1392,41 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies typeMenuSections.push(section); } + const accountingSection: SearchTypeMenuSection = { + translationPath: 'workspace.common.accounting', + menuItems: [], + }; + + const showShowStatementsSuggesion = false; // s77rt + const showShowUnapprovedSuggesion = true; // s77rt + const showShowUnapprovedCashSuggesion = false; // s77rt + const showShowUnapprovedCompanyCardsSuggesion = false; // s77rt + const showShowReconciliationSuggesion = false; // s77rt + + if (showShowStatementsSuggesion) { + // s77rt TODO + } + + if (showShowUnapprovedSuggesion) { + // s77rt TODO + } + + if (showShowUnapprovedCashSuggesion) { + // s77rt TODO + } + + if (showShowUnapprovedCompanyCardsSuggesion) { + // s77rt TODO + } + + if (showShowReconciliationSuggesion) { + // s77rt TODO + } + + if (accountingSection.menuItems.length > 0) { + typeMenuSections.push(accountingSection); + } + return typeMenuSections; } From fd2bd4a626a46348638fde10fa801131ad546a1d Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Fri, 20 Jun 2025 17:57:15 +0100 Subject: [PATCH 02/46] lock accounting section behind email check --- src/libs/SearchUIUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index d554e152ff1f..0395c5494c78 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1423,7 +1423,7 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies // s77rt TODO } - if (accountingSection.menuItems.length > 0) { + if (accountingSection.menuItems.length > 0 && session?.email?.endsWith('@abdelhafidh.com')) { typeMenuSections.push(accountingSection); } From c01c955c4543d1dc6243a8ba29a84ad7ecb48628 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Fri, 20 Jun 2025 22:34:57 +0100 Subject: [PATCH 03/46] added accounting unapproved menu items --- src/CONST/index.ts | 1 + src/hooks/useSearchTypeMenu.tsx | 2 +- src/languages/en.ts | 7 ++ src/libs/SearchUIUtils.ts | 136 +++++++++++++++++++++---- src/pages/Search/EmptySearchView.tsx | 8 +- src/pages/Search/SearchTypeMenu.tsx | 4 +- tests/unit/Search/SearchUIUtilsTest.ts | 4 +- 7 files changed, 138 insertions(+), 24 deletions(-) diff --git a/src/CONST/index.ts b/src/CONST/index.ts index f179535f6fd2..407fc686462e 100755 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -6579,6 +6579,7 @@ const CONST = { }, GROUP_BY: { REPORTS: 'reports', + MEMBERS: 'members', }, BOOLEAN: { YES: 'yes', diff --git a/src/hooks/useSearchTypeMenu.tsx b/src/hooks/useSearchTypeMenu.tsx index 10a19d046bf7..9d372adfa402 100644 --- a/src/hooks/useSearchTypeMenu.tsx +++ b/src/hooks/useSearchTypeMenu.tsx @@ -49,7 +49,7 @@ export default function useSearchTypeMenu(queryJSON: SearchQueryJSON) { const cardFeedNamesWithType = useMemo(() => getCardFeedNamesWithType({workspaceCardFeeds, translate}), [workspaceCardFeeds, translate]); - const typeMenuSections = useMemo(() => createTypeMenuSections(session, allPolicies), [allPolicies, session]); + const typeMenuSections = useMemo(() => createTypeMenuSections(session, allPolicies, allCards), [allPolicies, session, allCards]); // this is a performance fix, rendering popover menu takes a lot of time and we don't need this component initially, that's why we postpone rendering it until everything else is rendered const [delayPopoverMenuFirstRender, setDelayPopoverMenuFirstRender] = useState(true); diff --git a/src/languages/en.ts b/src/languages/en.ts index 3e457c764842..821b31001003 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -5577,7 +5577,14 @@ const translations = { title: 'No expenses to export', subtitle: 'Time to take it easy, nice work.', }, + emptyUnapprovedResults: { + title: 'No expenses to approve', + subtitle: 'Zero expenses. Maximum chill. Well done!', + }, }, + unapproved: 'Unapproved', + unapprovedCash: 'Unapproved cash', + unapprovedCompanyCards: 'Unapproved company cards', saveSearch: 'Save search', deleteSavedSearch: 'Delete saved search', deleteSavedSearchConfirm: 'Are you sure you want to delete this search?', diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 0395c5494c78..5b160645a2e8 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -43,7 +43,7 @@ import {translateLocal} from './Localize'; import Navigation from './Navigation/Navigation'; import Parser from './Parser'; import {getDisplayNameOrDefault} from './PersonalDetailsUtils'; -import {canSendInvoice, getActivePolicy, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy} from './PolicyUtils'; +import {arePaymentsEnabled, canSendInvoice, getActivePolicy, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy} from './PolicyUtils'; import {getOriginalMessage, isCreatedAction, isDeletedAction, isMoneyRequestAction, isResolvedActionableWhisper, isWhisperActionTargetedToOthers} from './ReportActionsUtils'; import {canReview} from './ReportPreviewActionUtils'; import { @@ -1163,8 +1163,9 @@ function isCorrectSearchUserName(displayName?: string) { return displayName && displayName.toUpperCase() !== CONST.REPORT.OWNER_EMAIL_FAKE; } -function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies: OnyxCollection = {}): SearchTypeMenuSection[] { +function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies: OnyxCollection = {}, cards: OnyxTypes.CardList): SearchTypeMenuSection[] { const email = session?.email; + const hasCardFeed = Object.keys(cards).length > 0; // Start building the sections by requiring the following sections to always be present const typeMenuSections: SearchTypeMenuSection[] = [ @@ -1397,32 +1398,133 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies menuItems: [], }; - const showShowStatementsSuggesion = false; // s77rt - const showShowUnapprovedSuggesion = true; // s77rt - const showShowUnapprovedCashSuggesion = false; // s77rt - const showShowUnapprovedCompanyCardsSuggesion = false; // s77rt - const showShowReconciliationSuggesion = false; // s77rt + let maybeHaveUnapprovedOutOfPocketExpenses = false; + let maybeHaveUnapprovedCompanyCardExpenses = false; - if (showShowStatementsSuggesion) { - // s77rt TODO - } + let shouldShowStatementsSuggesion = false, + shouldShowUnapprovedSuggesion = false, + shouldShowReconciliationSuggesion = false; - if (showShowUnapprovedSuggesion) { - // s77rt TODO - } + Object.values(policies).some((policy) => { + if (!policy || !isPaidGroupPolicy(policy)) { + return false; + } - if (showShowUnapprovedCashSuggesion) { + const isAdmin = policy.role === CONST.POLICY.ROLE.ADMIN; + const isApprovalEnabled = policy.approvalMode ? policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL : false; + const isPaymentEnabled = arePaymentsEnabled(policy); + + maybeHaveUnapprovedOutOfPocketExpenses ||= isPaymentEnabled; + maybeHaveUnapprovedCompanyCardExpenses ||= (policy.areCompanyCardsEnabled === true || policy.areExpensifyCardsEnabled === true) && hasCardFeed; + + shouldShowStatementsSuggesion ||= false; // s77rt + shouldShowUnapprovedSuggesion ||= isAdmin && isApprovalEnabled && (maybeHaveUnapprovedOutOfPocketExpenses || maybeHaveUnapprovedCompanyCardExpenses); + shouldShowReconciliationSuggesion ||= false; // s77rt + + // If all search variables are true return early to avoid redundant iterations + return ( + maybeHaveUnapprovedOutOfPocketExpenses && + maybeHaveUnapprovedCompanyCardExpenses && + shouldShowStatementsSuggesion && + shouldShowUnapprovedSuggesion && + shouldShowReconciliationSuggesion + ); + }); + + if (shouldShowStatementsSuggesion) { // s77rt TODO } - if (showShowUnapprovedCompanyCardsSuggesion) { - // s77rt TODO + if (shouldShowUnapprovedSuggesion) { + if (maybeHaveUnapprovedOutOfPocketExpenses && maybeHaveUnapprovedCompanyCardExpenses) { + accountingSection.menuItems.push( + { + translationPath: 'search.unapprovedCash', + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + icon: Expensicons.MoneySearch, // s77rt + emptyState: { + headerMedia: DotLottieAnimations.Fireworks, + title: 'search.searchResults.emptyUnapprovedResults.title', + subtitle: 'search.searchResults.emptyUnapprovedResults.subtitle', + }, + getSearchQuery: () => { + const queryString = buildQueryStringFromFilterFormValues({ + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + groupBy: CONST.SEARCH.GROUP_BY.REPORTS, + status: [CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], + reimbursable: CONST.SEARCH.BOOLEAN.YES, + }); + return queryString; + }, + }, + { + translationPath: 'search.unapprovedCompanyCards', + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + icon: Expensicons.CreditCardHourglass, + emptyState: { + headerMedia: DotLottieAnimations.Fireworks, + title: 'search.searchResults.emptyUnapprovedResults.title', + subtitle: 'search.searchResults.emptyUnapprovedResults.subtitle', + }, + getSearchQuery: () => { + const queryString = buildQueryStringFromFilterFormValues({ + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + groupBy: CONST.SEARCH.GROUP_BY.MEMBERS, + feed: [CONST.COMPANY_CARDS.BANKS.BANK_OF_AMERICA], + status: [CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], + }); + return queryString; + }, + }, + ); + } else if (maybeHaveUnapprovedOutOfPocketExpenses) { + accountingSection.menuItems.push({ + translationPath: 'search.unapproved', + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + icon: Expensicons.Hourglass, + emptyState: { + headerMedia: DotLottieAnimations.Fireworks, + title: 'search.searchResults.emptyUnapprovedResults.title', + subtitle: 'search.searchResults.emptyUnapprovedResults.subtitle', + }, + getSearchQuery: () => { + const queryString = buildQueryStringFromFilterFormValues({ + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + groupBy: CONST.SEARCH.GROUP_BY.REPORTS, + status: [CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], + reimbursable: CONST.SEARCH.BOOLEAN.YES, + }); + return queryString; + }, + }); + } else { + accountingSection.menuItems.push({ + translationPath: 'search.unapproved', + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + icon: Expensicons.Hourglass, + emptyState: { + headerMedia: DotLottieAnimations.Fireworks, + title: 'search.searchResults.emptyUnapprovedResults.title', + subtitle: 'search.searchResults.emptyUnapprovedResults.subtitle', + }, + getSearchQuery: () => { + const queryString = buildQueryStringFromFilterFormValues({ + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + groupBy: CONST.SEARCH.GROUP_BY.MEMBERS, + feed: [CONST.COMPANY_CARDS.BANKS.BANK_OF_AMERICA], + status: [CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], + }); + return queryString; + }, + }); + } } - if (showShowReconciliationSuggesion) { + if (shouldShowReconciliationSuggesion) { // s77rt TODO } + // s77rt (remove email lock) if (accountingSection.menuItems.length > 0 && session?.email?.endsWith('@abdelhafidh.com')) { typeMenuSections.push(accountingSection); } diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index e4feca3ba7b4..801bf2b8496a 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -28,6 +28,7 @@ import {startMoneyRequest} from '@libs/actions/IOU'; import {openOldDotLink} from '@libs/actions/Link'; import {createNewReport} from '@libs/actions/Report'; import {completeTestDriveTask} from '@libs/actions/Task'; +import {mergeCardListWithWorkspaceFeeds} from '@libs/CardUtils'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; import Navigation from '@libs/Navigation/Navigation'; import {hasSeenTourSelector} from '@libs/onboardingSelectors'; @@ -85,6 +86,9 @@ function EmptySearchView({hash, type, groupBy, hasResults}: EmptySearchViewProps const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); + const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true}); + const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true}); + const allCards = useMemo(() => mergeCardListWithWorkspaceFeeds(workspaceCardFeeds ?? CONST.EMPTY_OBJECT, userCardList), [userCardList, workspaceCardFeeds]); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true}); const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true}); @@ -99,10 +103,10 @@ function EmptySearchView({hash, type, groupBy, hasResults}: EmptySearchViewProps }, [allPolicies]); const typeMenuItems = useMemo(() => { - return createTypeMenuSections(session, allPolicies) + return createTypeMenuSections(session, allPolicies, allCards) .map((section) => section.menuItems) .flat(); - }, [session, allPolicies]); + }, [session, allPolicies, allCards]); const tripViewChildren = useMemo(() => { const onLongPress = (event: GestureResponderEvent | MouseEvent) => { diff --git a/src/pages/Search/SearchTypeMenu.tsx b/src/pages/Search/SearchTypeMenu.tsx index 6e028cbd21ab..086d24ce59ab 100644 --- a/src/pages/Search/SearchTypeMenu.tsx +++ b/src/pages/Search/SearchTypeMenu.tsx @@ -77,7 +77,7 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) { }, [translate, workspaceCardFeeds]); const typeMenuSections: SearchTypeMenuSection[] = useMemo(() => { - const sections = createTypeMenuSections(session, allPolicies); + const sections = createTypeMenuSections(session, allPolicies, allCards); // The first time we render all of the sections the user can see, we need to mark these as 'rendered', such that we dont animate them in // We only animate in items that a user gains access to later on @@ -86,7 +86,7 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) { } return sections; - }, [session, allPolicies]); + }, [session, allPolicies, allCards]); const getOverflowMenu = useCallback((itemName: string, itemHash: number, itemQuery: string) => getOverflowMenuUtil(itemName, itemHash, itemQuery, showDeleteModal), [showDeleteModal]); const createSavedSearchMenuItem = useCallback( diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index bfdf2494a263..1f23366be168 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1262,7 +1262,7 @@ describe('SearchUIUtils', () => { describe('Test createTypeMenuItems', () => { it('should return the default menu items', () => { - const menuItems = SearchUIUtils.createTypeMenuSections(undefined, {}) + const menuItems = SearchUIUtils.createTypeMenuSections(undefined, {}, {}) .map((section) => section.menuItems) .flat(); @@ -1289,7 +1289,7 @@ describe('SearchUIUtils', () => { }); it('should generate correct routes', () => { - const menuItems = SearchUIUtils.createTypeMenuSections(undefined, {}) + const menuItems = SearchUIUtils.createTypeMenuSections(undefined, {}, {}) .map((section) => section.menuItems) .flat(); From dc5eda2bfa3c36ae66d990c97fa0020233ade726 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 08:10:32 +0100 Subject: [PATCH 04/46] simplify should show suggestions logic --- src/libs/SearchUIUtils.ts | 124 +++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 68 deletions(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 5b160645a2e8..0d08eb19ca76 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1398,11 +1398,9 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies menuItems: [], }; - let maybeHaveUnapprovedOutOfPocketExpenses = false; - let maybeHaveUnapprovedCompanyCardExpenses = false; - let shouldShowStatementsSuggesion = false, - shouldShowUnapprovedSuggesion = false, + showShowUnapprovedCashSuggesion = false, + showShowUnapprovedCompanyCardsSuggesion = false, shouldShowReconciliationSuggesion = false; Object.values(policies).some((policy) => { @@ -1414,74 +1412,25 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies const isApprovalEnabled = policy.approvalMode ? policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL : false; const isPaymentEnabled = arePaymentsEnabled(policy); - maybeHaveUnapprovedOutOfPocketExpenses ||= isPaymentEnabled; - maybeHaveUnapprovedCompanyCardExpenses ||= (policy.areCompanyCardsEnabled === true || policy.areExpensifyCardsEnabled === true) && hasCardFeed; - shouldShowStatementsSuggesion ||= false; // s77rt - shouldShowUnapprovedSuggesion ||= isAdmin && isApprovalEnabled && (maybeHaveUnapprovedOutOfPocketExpenses || maybeHaveUnapprovedCompanyCardExpenses); + showShowUnapprovedCashSuggesion ||= isAdmin && isApprovalEnabled && isPaymentEnabled; + showShowUnapprovedCompanyCardsSuggesion ||= isAdmin && isApprovalEnabled && (policy.areCompanyCardsEnabled === true || policy.areExpensifyCardsEnabled === true) && hasCardFeed; shouldShowReconciliationSuggesion ||= false; // s77rt // If all search variables are true return early to avoid redundant iterations - return ( - maybeHaveUnapprovedOutOfPocketExpenses && - maybeHaveUnapprovedCompanyCardExpenses && - shouldShowStatementsSuggesion && - shouldShowUnapprovedSuggesion && - shouldShowReconciliationSuggesion - ); + return shouldShowStatementsSuggesion && showShowUnapprovedCashSuggesion && showShowUnapprovedCompanyCardsSuggesion && shouldShowReconciliationSuggesion; }); if (shouldShowStatementsSuggesion) { // s77rt TODO } - if (shouldShowUnapprovedSuggesion) { - if (maybeHaveUnapprovedOutOfPocketExpenses && maybeHaveUnapprovedCompanyCardExpenses) { - accountingSection.menuItems.push( - { - translationPath: 'search.unapprovedCash', - type: CONST.SEARCH.DATA_TYPES.EXPENSE, - icon: Expensicons.MoneySearch, // s77rt - emptyState: { - headerMedia: DotLottieAnimations.Fireworks, - title: 'search.searchResults.emptyUnapprovedResults.title', - subtitle: 'search.searchResults.emptyUnapprovedResults.subtitle', - }, - getSearchQuery: () => { - const queryString = buildQueryStringFromFilterFormValues({ - type: CONST.SEARCH.DATA_TYPES.EXPENSE, - groupBy: CONST.SEARCH.GROUP_BY.REPORTS, - status: [CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], - reimbursable: CONST.SEARCH.BOOLEAN.YES, - }); - return queryString; - }, - }, - { - translationPath: 'search.unapprovedCompanyCards', - type: CONST.SEARCH.DATA_TYPES.EXPENSE, - icon: Expensicons.CreditCardHourglass, - emptyState: { - headerMedia: DotLottieAnimations.Fireworks, - title: 'search.searchResults.emptyUnapprovedResults.title', - subtitle: 'search.searchResults.emptyUnapprovedResults.subtitle', - }, - getSearchQuery: () => { - const queryString = buildQueryStringFromFilterFormValues({ - type: CONST.SEARCH.DATA_TYPES.EXPENSE, - groupBy: CONST.SEARCH.GROUP_BY.MEMBERS, - feed: [CONST.COMPANY_CARDS.BANKS.BANK_OF_AMERICA], - status: [CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], - }); - return queryString; - }, - }, - ); - } else if (maybeHaveUnapprovedOutOfPocketExpenses) { - accountingSection.menuItems.push({ - translationPath: 'search.unapproved', + if (showShowUnapprovedCashSuggesion && showShowUnapprovedCompanyCardsSuggesion) { + accountingSection.menuItems.push( + { + translationPath: 'search.unapprovedCash', type: CONST.SEARCH.DATA_TYPES.EXPENSE, - icon: Expensicons.Hourglass, + icon: Expensicons.MoneySearch, // s77rt emptyState: { headerMedia: DotLottieAnimations.Fireworks, title: 'search.searchResults.emptyUnapprovedResults.title', @@ -1496,12 +1445,11 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies }); return queryString; }, - }); - } else { - accountingSection.menuItems.push({ - translationPath: 'search.unapproved', + }, + { + translationPath: 'search.unapprovedCompanyCards', type: CONST.SEARCH.DATA_TYPES.EXPENSE, - icon: Expensicons.Hourglass, + icon: Expensicons.CreditCardHourglass, emptyState: { headerMedia: DotLottieAnimations.Fireworks, title: 'search.searchResults.emptyUnapprovedResults.title', @@ -1516,8 +1464,48 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies }); return queryString; }, - }); - } + }, + ); + } else if (showShowUnapprovedCashSuggesion) { + accountingSection.menuItems.push({ + translationPath: 'search.unapproved', + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + icon: Expensicons.Hourglass, + emptyState: { + headerMedia: DotLottieAnimations.Fireworks, + title: 'search.searchResults.emptyUnapprovedResults.title', + subtitle: 'search.searchResults.emptyUnapprovedResults.subtitle', + }, + getSearchQuery: () => { + const queryString = buildQueryStringFromFilterFormValues({ + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + groupBy: CONST.SEARCH.GROUP_BY.REPORTS, + status: [CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], + reimbursable: CONST.SEARCH.BOOLEAN.YES, + }); + return queryString; + }, + }); + } else if (showShowUnapprovedCompanyCardsSuggesion) { + accountingSection.menuItems.push({ + translationPath: 'search.unapproved', + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + icon: Expensicons.Hourglass, + emptyState: { + headerMedia: DotLottieAnimations.Fireworks, + title: 'search.searchResults.emptyUnapprovedResults.title', + subtitle: 'search.searchResults.emptyUnapprovedResults.subtitle', + }, + getSearchQuery: () => { + const queryString = buildQueryStringFromFilterFormValues({ + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + groupBy: CONST.SEARCH.GROUP_BY.MEMBERS, + feed: [CONST.COMPANY_CARDS.BANKS.BANK_OF_AMERICA], + status: [CONST.SEARCH.STATUS.EXPENSE.DRAFTS, CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING], + }); + return queryString; + }, + }); } if (shouldShowReconciliationSuggesion) { From b50b5071b19a005355d938f3e7821cce6c614e8b Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 09:41:23 +0100 Subject: [PATCH 05/46] add group by filter --- .../SearchPageHeader/SearchFiltersBar.tsx | 25 ++++++++++++++++++- src/languages/en.ts | 5 ++++ src/libs/SearchUIUtils.ts | 7 +++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx b/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx index 304933dd0e86..8653051f9c60 100644 --- a/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx +++ b/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx @@ -31,7 +31,7 @@ import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; import {getAllTaxRates} from '@libs/PolicyUtils'; import {buildFilterFormValuesFromQuery, buildQueryStringFromFilterFormValues, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; -import {getStatusOptions, getTypeOptions} from '@libs/SearchUIUtils'; +import {getGroupByOptions, getStatusOptions, getTypeOptions} from '@libs/SearchUIUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -123,6 +123,24 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro [translate, type, typeOptions, updateFilterForm], ); + const groupByComponent = useCallback( + ({closeOverlay}: PopoverComponentProps) => { + const items = getGroupByOptions(); + const value = items.find((option) => option.value === groupBy) ?? null; + + return ( + updateFilterForm({groupBy: item?.value})} + /> + ); + }, + [translate, groupBy, updateFilterForm], + ); + const statusComponent = useCallback( ({closeOverlay}: PopoverComponentProps) => { const items = getStatusOptions(type, groupBy); @@ -210,6 +228,11 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro PopoverComponent: typeComponent, value: translate(`common.${type}`), }, + { + label: translate('search.groupBy'), + PopoverComponent: groupByComponent, + value: groupBy ? translate(`search.filters.groupBy.${groupBy}`) : null, + }, { label: translate('common.status'), PopoverComponent: statusComponent, diff --git a/src/languages/en.ts b/src/languages/en.ts index 821b31001003..6c51be6a50d7 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -5637,7 +5637,12 @@ const translations = { posted: 'Posted date', billable: 'Billable', reimbursable: 'Reimbursable', + groupBy: { + reports: 'Report', // s77rt use singular key name + members: 'Member', // s77rt use singular key name + }, }, + groupBy: 'Group by', moneyRequestReport: { emptyStateTitle: 'This report has no expenses.', emptyStateSubtitle: 'You can add expenses to this report \n using the button above.', diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 0d08eb19ca76..cb9b14727de1 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1565,7 +1565,7 @@ function getStatusOptions(type: SearchDataTypes, groupBy: SearchGroupBy | undefi return taskStatusOptions; case CONST.SEARCH.DATA_TYPES.EXPENSE: default: - return groupBy === CONST.SEARCH.GROUP_BY.REPORTS ? expenseReportStatusOptions : expenseStatusOptions; + return groupBy === CONST.SEARCH.GROUP_BY.REPORTS ? expenseReportStatusOptions : expenseStatusOptions; // s77rt (to check group by) } } @@ -1583,6 +1583,10 @@ function getTypeOptions(policies: OnyxCollection, currentUserL return shouldHideInvoiceOption ? typeOptions.filter((typeOption) => typeOption.value !== CONST.SEARCH.DATA_TYPES.INVOICE) : typeOptions; } +function getGroupByOptions() { + return Object.values(CONST.SEARCH.GROUP_BY).map>((value) => ({translation: `search.filters.groupBy.${value}`, value})); +} + export { getListItem, getSections, @@ -1606,6 +1610,7 @@ export { isSearchDataLoaded, getStatusOptions, getTypeOptions, + getGroupByOptions, getWideAmountIndicators, isTransactionAmountTooLong, isTransactionTaxAmountTooLong, From 3015760d337cd1d03d7e09219e5ea5dfc5ad4f05 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 11:00:34 +0100 Subject: [PATCH 06/46] rename ReportListItem to TransactionGroupListItem --- src/components/Search/SearchList.tsx | 4 ++-- ...rtListItem.tsx => TransactionGroupListItem.tsx} | 6 +++--- src/components/SelectionList/types.ts | 4 ++-- src/libs/SearchUIUtils.ts | 4 ++-- .../Search/SearchTransactionsChangeReport.tsx | 4 ++-- .../iou/request/step/IOURequestEditReport.tsx | 4 ++-- .../request/step/IOURequestEditReportCommon.tsx | 6 +++--- .../iou/request/step/IOURequestStepReport.tsx | 4 ++-- src/types/onyx/SearchResults.ts | 4 ++-- tests/unit/Search/SearchUIUtilsTest.ts | 14 +++++++------- 10 files changed, 27 insertions(+), 27 deletions(-) rename src/components/SelectionList/Search/{ReportListItem.tsx => TransactionGroupListItem.tsx} (98%) diff --git a/src/components/Search/SearchList.tsx b/src/components/Search/SearchList.tsx index d346682d6eb0..4fd979bbc094 100644 --- a/src/components/Search/SearchList.tsx +++ b/src/components/Search/SearchList.tsx @@ -12,8 +12,8 @@ import MenuItem from '@components/MenuItem'; import Modal from '@components/Modal'; import {PressableWithFeedback} from '@components/Pressable'; import type ChatListItem from '@components/SelectionList/ChatListItem'; -import type ReportListItem from '@components/SelectionList/Search/ReportListItem'; import type TaskListItem from '@components/SelectionList/Search/TaskListItem'; +import type TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import type TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; import type {ExtendedTargetedEvent, ReportActionListItemType, ReportListItemType, TaskListItemType, TransactionListItemType} from '@components/SelectionList/types'; import Text from '@components/Text'; @@ -34,7 +34,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; type SearchListItem = TransactionListItemType | ReportListItemType | ReportActionListItemType | TaskListItemType; -type SearchListItemComponentType = typeof TransactionListItem | typeof ChatListItem | typeof ReportListItem | typeof TaskListItem; +type SearchListItemComponentType = typeof TransactionListItem | typeof ChatListItem | typeof TransactionGroupListItem | typeof TaskListItem; type SearchListHandle = { scrollAndHighlightItem?: (items: string[]) => void; diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx similarity index 98% rename from src/components/SelectionList/Search/ReportListItem.tsx rename to src/components/SelectionList/Search/TransactionGroupListItem.tsx index 93a8c41c0c63..73018ea0f1de 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -22,7 +22,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import ReportListItemHeader from './ReportListItemHeader'; -function ReportListItem({ +function TransactionGroupListItem({ item, isFocused, showTooltip, @@ -179,6 +179,6 @@ function ReportListItem({ ); } -ReportListItem.displayName = 'ReportListItem'; +TransactionGroupListItem.displayName = 'TransactionGroupListItem'; -export default ReportListItem; +export default TransactionGroupListItem; diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 5039022561e9..3d832a768f50 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -33,8 +33,8 @@ import type IconAsset from '@src/types/utils/IconAsset'; import type ChatListItem from './ChatListItem'; import type InviteMemberListItem from './InviteMemberListItem'; import type RadioListItem from './RadioListItem'; -import type ReportListItem from './Search/ReportListItem'; import type SearchQueryListItem from './Search/SearchQueryListItem'; +import type TransactionGroupListItem from './Search/TransactionGroupListItem'; import type TransactionListItem from './Search/TransactionListItem'; import type TableListItem from './TableListItem'; import type TravelDomainListItem from './TravelDomainListItem'; @@ -468,7 +468,7 @@ type ValidListItem = | typeof TableListItem | typeof InviteMemberListItem | typeof TransactionListItem - | typeof ReportListItem + | typeof TransactionGroupListItem | typeof ChatListItem | typeof SearchQueryListItem | typeof SearchRouterItem diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index cb9b14727de1..6a9b2e402bca 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -9,8 +9,8 @@ import type {MultiSelectItem} from '@components/Search/FilterDropdowns/MultiSele import type {SingleSelectItem} from '@components/Search/FilterDropdowns/SingleSelectPopup'; import type {SearchColumnType, SearchGroupBy, SearchQueryJSON, SearchQueryString, SearchStatus, SingularSearchStatus, SortOrder} from '@components/Search/types'; import ChatListItem from '@components/SelectionList/ChatListItem'; -import ReportListItem from '@components/SelectionList/Search/ReportListItem'; import TaskListItem from '@components/SelectionList/Search/TaskListItem'; +import TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; import type {ListItem, ReportActionListItemType, ReportListItemType, SearchListItem, TaskListItemType, TransactionListItemType} from '@components/SelectionList/types'; import * as Expensicons from '@src/components/Icon/Expensicons'; @@ -951,7 +951,7 @@ function getListItem(type: SearchDataTypes, status: SearchStatus, shouldGroupByR if (!shouldGroupByReports) { return TransactionListItem; } - return ReportListItem; + return TransactionGroupListItem; } /** diff --git a/src/pages/Search/SearchTransactionsChangeReport.tsx b/src/pages/Search/SearchTransactionsChangeReport.tsx index 79c3a33a31be..9155e647fd68 100644 --- a/src/pages/Search/SearchTransactionsChangeReport.tsx +++ b/src/pages/Search/SearchTransactionsChangeReport.tsx @@ -8,7 +8,7 @@ import IOURequestEditReportCommon from '@pages/iou/request/step/IOURequestEditRe import ONYXKEYS from '@src/ONYXKEYS'; import type {Report} from '@src/types/onyx'; -type ReportListItem = ListItem & { +type TransactionGroupListItem = ListItem & { /** reportID of the report */ value: string; }; @@ -29,7 +29,7 @@ function SearchTransactionsChangeReport() { return [...reports]; }, [allReports, selectedTransactions]); - const selectReport = (item: ReportListItem) => { + const selectReport = (item: TransactionGroupListItem) => { if (selectedTransactionsKeys.length === 0) { return; } diff --git a/src/pages/iou/request/step/IOURequestEditReport.tsx b/src/pages/iou/request/step/IOURequestEditReport.tsx index 6257cf5926ab..095853581990 100644 --- a/src/pages/iou/request/step/IOURequestEditReport.tsx +++ b/src/pages/iou/request/step/IOURequestEditReport.tsx @@ -10,7 +10,7 @@ import IOURequestEditReportCommon from './IOURequestEditReportCommon'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; -type ReportListItem = ListItem & { +type TransactionGroupListItem = ListItem & { /** reportID of the report */ value: string; }; @@ -24,7 +24,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) { const [transactionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: false}); - const selectReport = (item: ReportListItem) => { + const selectReport = (item: TransactionGroupListItem) => { if (selectedTransactionIDs.length === 0 || item.value === reportID) { Navigation.dismissModal(); return; diff --git a/src/pages/iou/request/step/IOURequestEditReportCommon.tsx b/src/pages/iou/request/step/IOURequestEditReportCommon.tsx index c618db5fd930..3701dafef8eb 100644 --- a/src/pages/iou/request/step/IOURequestEditReportCommon.tsx +++ b/src/pages/iou/request/step/IOURequestEditReportCommon.tsx @@ -17,7 +17,7 @@ import type {Report} from '@src/types/onyx'; import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems'; import StepScreenWrapper from './StepScreenWrapper'; -type ReportListItem = ListItem & { +type TransactionGroupListItem = ListItem & { /** reportID of the report */ value: string; }; @@ -40,7 +40,7 @@ const reportSelector = (report: OnyxEntry): OnyxEntry => type Props = { backTo: Route | undefined; transactionsReports: Report[]; - selectReport: (item: ReportListItem) => void; + selectReport: (item: TransactionGroupListItem) => void; }; function IOURequestEditReportCommon({backTo, transactionsReports, selectReport}: Props) { @@ -70,7 +70,7 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport}: [allReports, currentUserPersonalDetails.accountID, transactionsReports, allPoliciesID, reportNameValuePairs], ); - const reportOptions: ReportListItem[] = useMemo(() => { + const reportOptions: TransactionGroupListItem[] = useMemo(() => { if (!allReports) { return []; } diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 3dc0cc33f72e..2d775916f47b 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -12,7 +12,7 @@ import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNo import withWritableReportOrNotFound from './withWritableReportOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; -type ReportListItem = ListItem & { +type TransactionGroupListItem = ListItem & { /** reportID of the report */ value: string; }; @@ -26,7 +26,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { const isEditing = action === CONST.IOU.ACTION.EDIT; - const selectReport = (item: ReportListItem) => { + const selectReport = (item: TransactionGroupListItem) => { if (!transaction) { return; } diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 8fce5ca0fb90..cc61d28b8a76 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -1,7 +1,7 @@ import type {ValueOf} from 'type-fest'; import type {SearchStatus} from '@components/Search/types'; import type ChatListItem from '@components/SelectionList/ChatListItem'; -import type ReportListItem from '@components/SelectionList/Search/ReportListItem'; +import type TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import type TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; import type {ReportActionListItemType, ReportListItemType, TaskListItemType, TransactionListItemType} from '@components/SelectionList/types'; import type CONST from '@src/CONST'; @@ -22,7 +22,7 @@ type ListItemType = C extends ? typeof ChatListItem : T extends typeof CONST.SEARCH.STATUS.EXPENSE.ALL ? typeof TransactionListItem - : typeof ReportListItem; + : typeof TransactionGroupListItem; /** Model of search list item data type */ type ListItemDataType = C extends typeof CONST.SEARCH.DATA_TYPES.CHAT diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 1f23366be168..63f31f51a653 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1,6 +1,6 @@ import Onyx from 'react-native-onyx'; import ChatListItem from '@components/SelectionList/ChatListItem'; -import ReportListItem from '@components/SelectionList/Search/ReportListItem'; +import TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; import type {ReportActionListItemType, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; import * as Expensicons from '@src/components/Icon/Expensicons'; @@ -1172,16 +1172,16 @@ describe('SearchUIUtils', () => { expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', false)).toStrictEqual(TransactionListItem); }); - it('should return ReportListItem when type is EXPENSE and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', true)).toStrictEqual(ReportListItem); + it('should return TransactionGroupListItem when type is EXPENSE and shouldGroupByReports is true', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', true)).toStrictEqual(TransactionGroupListItem); }); - it('should return ReportListItem when type is TRIP and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.TRIP, 'all', true)).toStrictEqual(ReportListItem); + it('should return TransactionGroupListItem when type is TRIP and shouldGroupByReports is true', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.TRIP, 'all', true)).toStrictEqual(TransactionGroupListItem); }); - it('should return ReportListItem when type is INVOICE and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', true)).toStrictEqual(ReportListItem); + it('should return TransactionGroupListItem when type is INVOICE and shouldGroupByReports is true', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', true)).toStrictEqual(TransactionGroupListItem); }); }); From 85f8bc85184fe8b76ad733f5a891ab174a55e0cf Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 12:28:51 +0100 Subject: [PATCH 07/46] replace ReportListItemType with TransactionGroupListItemType and prepare for member grouping sections --- src/components/Search/SearchContext.tsx | 4 +- src/components/Search/SearchList.tsx | 22 ++--- src/components/Search/index.tsx | 87 ++++++++--------- src/components/Search/types.ts | 4 +- .../BaseSelectionListItemRenderer.tsx | 4 +- .../Search/ReportListItemHeader.tsx | 8 +- .../Search/TransactionGroupListItem.tsx | 4 +- .../Search/UserInfoAndActionButtonRow.tsx | 4 +- src/components/SelectionList/types.ts | 6 +- src/hooks/useSearchHighlightAndScroll.ts | 10 +- src/libs/SearchUIUtils.ts | 58 ++++++----- src/libs/actions/Search.ts | 10 +- src/types/onyx/SearchResults.ts | 4 +- tests/ui/ReportListItemHeaderTest.tsx | 6 +- tests/unit/Search/SearchUIUtilsTest.ts | 96 ++++++++++++++----- .../Search/handleActionButtonPressTest.ts | 4 +- 16 files changed, 188 insertions(+), 143 deletions(-) diff --git a/src/components/Search/SearchContext.tsx b/src/components/Search/SearchContext.tsx index 6e3df8f1d58c..e8afa1a8dd1a 100644 --- a/src/components/Search/SearchContext.tsx +++ b/src/components/Search/SearchContext.tsx @@ -1,6 +1,6 @@ import React, {useCallback, useContext, useMemo, useRef, useState} from 'react'; import {isMoneyRequestReport} from '@libs/ReportUtils'; -import {isReportListItemType, isTransactionListItemType} from '@libs/SearchUIUtils'; +import {isTransactionGroupListItemType, isTransactionListItemType} from '@libs/SearchUIUtils'; import CONST from '@src/CONST'; import type ChildrenProps from '@src/types/utils/ChildrenProps'; import type {SearchContext, SearchContextData} from './types'; @@ -63,7 +63,7 @@ function SearchContextProvider({children}: ChildrenProps) { // When selecting transactions, we also need to manage the reports to which these transactions belong. This is done to ensure proper exporting to CSV. let selectedReports: SearchContext['selectedReports'] = []; - if (data.length && data.every(isReportListItemType)) { + if (data.length && data.every(isTransactionGroupListItemType)) { selectedReports = data .filter((item) => isMoneyRequestReport(item) && item.transactions.every(({keyForList}) => selectedTransactions[keyForList]?.isSelected)) .map(({reportID, action = CONST.SEARCH.ACTION_TYPES.VIEW, total = CONST.DEFAULT_NUMBER_ID, policyID}) => ({reportID, action, total, policyID})); diff --git a/src/components/Search/SearchList.tsx b/src/components/Search/SearchList.tsx index 4fd979bbc094..8d7716545a98 100644 --- a/src/components/Search/SearchList.tsx +++ b/src/components/Search/SearchList.tsx @@ -15,7 +15,7 @@ import type ChatListItem from '@components/SelectionList/ChatListItem'; import type TaskListItem from '@components/SelectionList/Search/TaskListItem'; import type TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import type TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; -import type {ExtendedTargetedEvent, ReportActionListItemType, ReportListItemType, TaskListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ExtendedTargetedEvent, ReportActionListItemType, TaskListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import Text from '@components/Text'; import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager'; import useKeyboardShortcut from '@hooks/useKeyboardShortcut'; @@ -32,8 +32,9 @@ import {addKeyDownPressListener, removeKeyDownPressListener} from '@libs/Keyboar import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {SearchQueryJSON} from './types'; -type SearchListItem = TransactionListItemType | ReportListItemType | ReportActionListItemType | TaskListItemType; +type SearchListItem = TransactionListItemType | TransactionGroupListItemType | ReportActionListItemType | TaskListItemType; type SearchListItemComponentType = typeof TransactionListItem | typeof ChatListItem | typeof TransactionGroupListItem | typeof TaskListItem; type SearchListHandle = { @@ -70,11 +71,8 @@ type SearchListProps = Pick, 'onScroll' /** Whether to prevent long press of options */ shouldPreventLongPressRow?: boolean; - /** The hash of the queryJSON */ - queryJSONHash: number; - - /** Whether to group the list by reports */ - shouldGroupByReports?: boolean; + /** The search query */ + queryJSON: SearchQueryJSON; /** Called when the viewability of rows changes, as defined by the viewabilityConfig prop. */ onViewableItemsChanged?: (info: {changed: ViewToken[]; viewableItems: ViewToken[]}) => void; @@ -102,15 +100,15 @@ function SearchList( ListFooterComponent, shouldPreventDefaultFocusOnSelectRow, shouldPreventLongPressRow, - queryJSONHash, - shouldGroupByReports, + queryJSON, onViewableItemsChanged, onLayout, }: SearchListProps, ref: ForwardedRef, ) { const styles = useThemeStyles(); - const flattenedTransactions = shouldGroupByReports ? (data as ReportListItemType[]).flatMap((item) => item.transactions) : data; + const {hash, groupBy} = queryJSON; + const flattenedTransactions = groupBy ? (data as TransactionGroupListItemType[]).flatMap((item) => item.transactions) : data; const flattenedTransactionWithoutPendingDelete = flattenedTransactions.filter((t) => t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); const selectedItemsLength = flattenedTransactions.reduce((acc, item) => { return item?.isSelected ? acc + 1 : acc; @@ -336,7 +334,7 @@ function SearchList( ...item, }} shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow} - queryJSONHash={queryJSONHash} + queryJSONHash={hash} policies={policies} isDisabled={isDisabled} allReports={allReports} @@ -352,7 +350,7 @@ function SearchList( onCheckboxPress, onSelectRow, policies, - queryJSONHash, + hash, setFocusedIndex, shouldPreventDefaultFocusOnSelectRow, allReports, diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index f01411780ef6..ad47dbc87929 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -6,7 +6,7 @@ import {useOnyx} from 'react-native-onyx'; import FullPageErrorView from '@components/BlockingViews/FullPageErrorView'; import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; import SearchTableHeader from '@components/SelectionList/SearchTableHeader'; -import type {ReportActionListItemType, ReportListItemType, SearchListItem, SelectionListHandle, TransactionListItemType} from '@components/SelectionList/types'; +import type {ReportActionListItemType, SearchListItem, SelectionListHandle, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton'; import useLocalize from '@hooks/useLocalize'; import useMobileSelectionMode from '@hooks/useMobileSelectionMode'; @@ -30,10 +30,10 @@ import { getSortedSections, getWideAmountIndicators, isReportActionListItemType, - isReportListItemType, isSearchDataLoaded, isSearchResultsEmpty as isSearchResultsEmptyUtil, isTaskListItemType, + isTransactionGroupListItemType, isTransactionListItemType, shouldShowEmptyState, shouldShowYear as shouldShowYearUtil, @@ -174,8 +174,6 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS const {translate} = useLocalize(); const searchListRef = useRef(null); - const shouldGroupByReports = groupBy === CONST.SEARCH.GROUP_BY.REPORTS; - useEffect(() => { if (!isFocused) { return; @@ -252,8 +250,8 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS if (searchResults === undefined || !isDataLoaded) { return []; } - return getSections(type, status, searchResults.data, searchResults.search, shouldGroupByReports); - }, [searchResults, isDataLoaded, type, status, shouldGroupByReports]); + return getSections(type, status, searchResults.data, searchResults.search, groupBy); + }, [searchResults, isDataLoaded, type, status, groupBy]); useEffect(() => { /** We only want to display the skeleton for the status filters the first time we load them for a specific data type */ @@ -268,7 +266,31 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS return; } const newTransactionList: SelectedTransactions = {}; - if (!shouldGroupByReports) { + if (groupBy) { + data.forEach((transactionGroup) => { + if (!Object.hasOwn(transactionGroup, 'transactions') || !('transactions' in transactionGroup)) { + return; + } + transactionGroup.transactions.forEach((transaction) => { + if (!Object.keys(selectedTransactions).includes(transaction.transactionID) && !isExportMode) { + return; + } + newTransactionList[transaction.transactionID] = { + action: transaction.action, + canHold: transaction.canHold, + isHeld: isOnHold(transaction), + canUnhold: transaction.canUnhold, + canChangeReport: canEditFieldOfMoneyRequest(getIOUActionForTransactionID(reportActionsArray, transaction.transactionID), CONST.EDIT_REQUEST_FIELD.REPORT), + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + isSelected: isExportMode || selectedTransactions[transaction.transactionID].isSelected, + canDelete: transaction.canDelete, + reportID: transaction.reportID, + policyID: transaction.policyID, + amount: transaction.modifiedAmount ?? transaction.amount, + }; + }); + }); + } else { data.forEach((transaction) => { if (!Object.hasOwn(transaction, 'transactionID') || !('transactionID' in transaction)) { return; @@ -290,30 +312,6 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS amount: transaction.modifiedAmount ?? transaction.amount, }; }); - } else { - data.forEach((report) => { - if (!Object.hasOwn(report, 'transactions') || !('transactions' in report)) { - return; - } - report.transactions.forEach((transaction) => { - if (!Object.keys(selectedTransactions).includes(transaction.transactionID) && !isExportMode) { - return; - } - newTransactionList[transaction.transactionID] = { - action: transaction.action, - canHold: transaction.canHold, - isHeld: isOnHold(transaction), - canUnhold: transaction.canUnhold, - canChangeReport: canEditFieldOfMoneyRequest(getIOUActionForTransactionID(reportActionsArray, transaction.transactionID), CONST.EDIT_REQUEST_FIELD.REPORT), - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - isSelected: isExportMode || selectedTransactions[transaction.transactionID].isSelected, - canDelete: transaction.canDelete, - reportID: transaction.reportID, - policyID: transaction.policyID, - amount: transaction.modifiedAmount ?? transaction.amount, - }; - }); - }); } setSelectedTransactions(newTransactionList, data); @@ -348,15 +346,15 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS if (!data.length || isRefreshingSelection.current || !isFocused) { return; } - const areItemsOfReportType = shouldGroupByReports; - const flattenedItems = areItemsOfReportType ? (data as ReportListItemType[]).flatMap((item) => item.transactions) : data; + const areItemsGrouped = !!groupBy; + const flattenedItems = areItemsGrouped ? (data as TransactionGroupListItemType[]).flatMap((item) => item.transactions) : data; const isAllSelected = flattenedItems.length === Object.keys(selectedTransactions).length; setShouldShowExportModeOption(!!(isAllSelected && searchResults?.search?.hasMoreResults)); if (!isAllSelected) { setExportMode(false); } - }, [isFocused, data, searchResults?.search?.hasMoreResults, selectedTransactions, setExportMode, setShouldShowExportModeOption, shouldGroupByReports]); + }, [isFocused, data, searchResults?.search?.hasMoreResults, selectedTransactions, setExportMode, setShouldShowExportModeOption, groupBy]); const toggleTransaction = useCallback( (item: SearchListItem) => { @@ -422,7 +420,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS const backTo = Navigation.getActiveRoute(); - if (isReportListItemType(item)) { + if (isTransactionGroupListItemType(item)) { Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID, backTo})); return; } @@ -484,8 +482,8 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS return {null}; } - const ListItem = getListItem(type, status, shouldGroupByReports); - const sortedData = getSortedSections(type, status, data, sortBy, sortOrder, shouldGroupByReports); + const ListItem = getListItem(type, status, groupBy); + const sortedData = getSortedSections(type, status, data, sortBy, sortOrder, groupBy); const isChat = type === CONST.SEARCH.DATA_TYPES.CHAT; const isTask = type === CONST.SEARCH.DATA_TYPES.TASK; @@ -497,10 +495,10 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS : `${ONYXKEYS.COLLECTION.TRANSACTION}${(item as TransactionListItemType).transactionID}`; // Check if the base key matches the newSearchResultKey (TransactionListItemType) const isBaseKeyMatch = baseKey === newSearchResultKey; - // Check if any transaction within the transactions array (ReportListItemType) matches the newSearchResultKey + // Check if any transaction within the transactions array (TransactionGroupListItemType) matches the newSearchResultKey const isAnyTransactionMatch = !isChat && - (item as ReportListItemType)?.transactions?.some((transaction) => { + (item as TransactionGroupListItemType)?.transactions?.some((transaction) => { const transactionKey = `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`; return transactionKey === newSearchResultKey; }); @@ -547,7 +545,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS }; const toggleAllTransactions = () => { - const areItemsOfReportType = shouldGroupByReports; + const areItemsGrouped = !!groupBy; const totalSelected = Object.keys(selectedTransactions).length; if (totalSelected > 0) { @@ -555,10 +553,10 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS return; } - if (areItemsOfReportType) { + if (areItemsGrouped) { setSelectedTransactions( Object.fromEntries( - (data as ReportListItemType[]).flatMap((item) => + (data as TransactionGroupListItemType[]).flatMap((item) => item.transactions.filter((t) => !isTransactionPendingDelete(t)).map((transactionItem) => mapTransactionItemToSelectedEntry(transactionItem, reportActionsArray)), ), ), @@ -585,7 +583,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS const shouldShowYear = shouldShowYearUtil(searchResults?.data); const {shouldShowAmountInWideColumn, shouldShowTaxAmountInWideColumn} = getWideAmountIndicators(searchResults?.data); - const shouldShowSorting = !Array.isArray(status) && !shouldGroupByReports; + const shouldShowSorting = !Array.isArray(status) && !groupBy; const shouldShowTableHeader = isLargeScreenWidth && !isChat; return ( @@ -618,7 +616,6 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS contentContainerStyle={[contentContainerStyle, styles.pb3]} containerStyle={[styles.pv0, type === CONST.SEARCH.DATA_TYPES.CHAT && !isSmallScreenWidth && styles.pt3]} shouldPreventDefaultFocusOnSelectRow={!canUseTouchScreen()} - shouldGroupByReports={shouldGroupByReports} onScroll={onSearchListScroll} onEndReachedThreshold={0.75} onEndReached={fetchMoreResults} @@ -630,7 +627,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS /> ) : undefined } - queryJSONHash={hash} + queryJSON={queryJSON} onViewableItemsChanged={onViewableItemsChanged} onLayout={() => handleSelectionListScroll(sortedSelectedData, searchListRef.current)} /> diff --git a/src/components/Search/types.ts b/src/components/Search/types.ts index 11f492ab8015..643dd24220da 100644 --- a/src/components/Search/types.ts +++ b/src/components/Search/types.ts @@ -1,5 +1,5 @@ import type {ValueOf} from 'type-fest'; -import type {ReportActionListItemType, ReportListItemType, TaskListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ReportActionListItemType, TaskListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import type CONST from '@src/CONST'; import type {SearchDataTypes} from '@src/types/onyx/SearchResults'; @@ -80,7 +80,7 @@ type SearchContext = SearchContextData & { /** If you want to set `selectedTransactionIDs`, pass an array as the first argument, object/record otherwise */ setSelectedTransactions: { (selectedTransactionIDs: string[], unused?: undefined): void; - (selectedTransactions: SelectedTransactions, data: TransactionListItemType[] | ReportListItemType[] | ReportActionListItemType[] | TaskListItemType[]): void; + (selectedTransactions: SelectedTransactions, data: TransactionListItemType[] | TransactionGroupListItemType[] | ReportActionListItemType[] | TaskListItemType[]): void; }; /** If you want to clear `selectedTransactionIDs`, pass `true` as the first argument */ clearSelectedTransactions: { diff --git a/src/components/SelectionList/BaseSelectionListItemRenderer.tsx b/src/components/SelectionList/BaseSelectionListItemRenderer.tsx index 2dacd5e0a8b2..fa96e7c02db5 100644 --- a/src/components/SelectionList/BaseSelectionListItemRenderer.tsx +++ b/src/components/SelectionList/BaseSelectionListItemRenderer.tsx @@ -3,7 +3,7 @@ import type {NativeSyntheticEvent, StyleProp, TextStyle, ViewStyle} from 'react- import type useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager'; import type useSingleExecution from '@hooks/useSingleExecution'; import {isMobileChrome} from '@libs/Browser'; -import {isReportListItemType} from '@libs/SearchUIUtils'; +import {isTransactionGroupListItemType} from '@libs/SearchUIUtils'; import type {BaseListItemProps, ExtendedTargetedEvent, ListItem, SelectionListProps} from './types'; type BaseSelectionListItemRendererProps = Omit, 'onSelectRow'> & @@ -46,7 +46,7 @@ function BaseSelectionListItemRenderer({ shouldUseDefaultRightHandSideCheckmark, }: BaseSelectionListItemRendererProps) { const handleOnCheckboxPress = () => { - if (isReportListItemType(item)) { + if (isTransactionGroupListItemType(item)) { return onCheckboxPress; } return onCheckboxPress ? () => onCheckboxPress(item) : undefined; diff --git a/src/components/SelectionList/Search/ReportListItemHeader.tsx b/src/components/SelectionList/Search/ReportListItemHeader.tsx index d595559b8cd1..9b79bc049161 100644 --- a/src/components/SelectionList/Search/ReportListItemHeader.tsx +++ b/src/components/SelectionList/Search/ReportListItemHeader.tsx @@ -5,7 +5,7 @@ import type {OnyxEntry} from 'react-native-onyx'; import Checkbox from '@components/Checkbox'; import ReportSearchHeader from '@components/ReportSearchHeader'; import {useSearchContext} from '@components/Search/SearchContext'; -import type {ListItem, ReportListItemType} from '@components/SelectionList/types'; +import type {ListItem, TransactionGroupListItemType} from '@components/SelectionList/types'; import TextWithTooltip from '@components/TextWithTooltip'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useStyleUtils from '@hooks/useStyleUtils'; @@ -20,7 +20,7 @@ import UserInfoAndActionButtonRow from './UserInfoAndActionButtonRow'; type ReportListItemHeaderProps = { /** The report currently being looked at */ - report: ReportListItemType; + report: TransactionGroupListItemType; /** The policy tied to the expense report */ policy: OnyxEntry; @@ -46,7 +46,7 @@ type ReportListItemHeaderProps = { type FirstRowReportHeaderProps = { /** The report currently being looked at */ - report: ReportListItemType; + report: TransactionGroupListItemType; /** The policy tied to the expense report */ policy: OnyxEntry; @@ -73,7 +73,7 @@ type FirstRowReportHeaderProps = { type ReportCellProps = { showTooltip: boolean; isLargeScreenWidth: boolean; - reportItem: ReportListItemType; + reportItem: TransactionGroupListItemType; }; function TotalCell({showTooltip, isLargeScreenWidth, reportItem}: ReportCellProps) { diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index 73018ea0f1de..afaf7d10ea38 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -3,7 +3,7 @@ import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import BaseListItem from '@components/SelectionList/BaseListItem'; -import type {ListItem, ReportListItemProps, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ListItem, ReportListItemProps, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import Text from '@components/Text'; import TransactionItemRow from '@components/TransactionItemRow'; import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; @@ -34,7 +34,7 @@ function TransactionGroupListItem({ onLongPressRow, shouldSyncFocus, }: ReportListItemProps) { - const reportItem = item as unknown as ReportListItemType; + const reportItem = item as unknown as TransactionGroupListItemType; const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); diff --git a/src/components/SelectionList/Search/UserInfoAndActionButtonRow.tsx b/src/components/SelectionList/Search/UserInfoAndActionButtonRow.tsx index 5915b7d6785f..9cc075f7f614 100644 --- a/src/components/SelectionList/Search/UserInfoAndActionButtonRow.tsx +++ b/src/components/SelectionList/Search/UserInfoAndActionButtonRow.tsx @@ -1,6 +1,6 @@ import React from 'react'; import {View} from 'react-native'; -import type {ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {isCorrectSearchUserName} from '@libs/SearchUIUtils'; @@ -14,7 +14,7 @@ function UserInfoAndActionButtonRow({ handleActionButtonPress, shouldShowUserInfo, }: { - item: ReportListItemType | TransactionListItemType; + item: TransactionGroupListItemType | TransactionListItemType; handleActionButtonPress: () => void; shouldShowUserInfo: boolean; }) { diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 3d832a768f50..995a4be50c8a 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -316,7 +316,7 @@ type TaskListItemType = ListItem & shouldShowYear: boolean; }; -type ReportListItemType = ListItem & +type TransactionGroupListItemType = ListItem & SearchReport & { /** The personal details of the user requesting money */ from: SearchPersonalDetails; @@ -845,7 +845,7 @@ type SectionListDataType = ExtendedSectionListData transaction?.transactionID === newID); } @@ -224,9 +224,9 @@ function extractTransactionIDsFromSearchResults(searchResultsData: Partial { + // Check for transactions array within the item (TransactionGroupListItemType) + if (Array.isArray((item as TransactionGroupListItemType)?.transactions)) { + (item as TransactionGroupListItemType).transactions.forEach((transaction) => { if (!transaction?.transactionID) { return; } diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 6a9b2e402bca..3c0ed03bd43e 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -12,7 +12,7 @@ import ChatListItem from '@components/SelectionList/ChatListItem'; import TaskListItem from '@components/SelectionList/Search/TaskListItem'; import TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; -import type {ListItem, ReportActionListItemType, ReportListItemType, SearchListItem, TaskListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ListItem, ReportActionListItemType, SearchListItem, TaskListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import * as Expensicons from '@src/components/Icon/Expensicons'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -285,9 +285,9 @@ function getShouldShowMerchant(data: OnyxTypes.SearchResults['data']): boolean { } /** - * Type guard that checks if something is a ReportListItemType + * Type guard that checks if something is a TransactionGroupListItemType */ -function isReportListItemType(item: ListItem): item is ReportListItemType { +function isTransactionGroupListItemType(item: ListItem): item is TransactionGroupListItemType { return 'transactions' in item; } @@ -331,7 +331,7 @@ function isTransactionTaxAmountTooLong(transactionItem: TransactionListItemType return isAmountTooLong(taxAmount); } -function getWideAmountIndicators(data: TransactionListItemType[] | ReportListItemType[] | TaskListItemType[] | OnyxTypes.SearchResults['data']): { +function getWideAmountIndicators(data: TransactionListItemType[] | TransactionGroupListItemType[] | TaskListItemType[] | OnyxTypes.SearchResults['data']): { shouldShowAmountInWideColumn: boolean; shouldShowTaxAmountInWideColumn: boolean; } { @@ -345,7 +345,7 @@ function getWideAmountIndicators(data: TransactionListItemType[] | ReportListIte if (Array.isArray(data)) { data.some((item) => { - if (isReportListItemType(item)) { + if (isTransactionGroupListItemType(item)) { const transactions = item.transactions ?? []; for (const transaction of transactions) { processTransaction(transaction); @@ -377,18 +377,18 @@ function getWideAmountIndicators(data: TransactionListItemType[] | ReportListIte /** * Checks if the date of transactions or reports indicate the need to display the year because they are from a past year. */ -function shouldShowYear(data: TransactionListItemType[] | ReportListItemType[] | TaskListItemType[] | OnyxTypes.SearchResults['data']) { +function shouldShowYear(data: TransactionListItemType[] | TransactionGroupListItemType[] | TaskListItemType[] | OnyxTypes.SearchResults['data']) { const currentYear = new Date().getFullYear(); if (Array.isArray(data)) { - return data.some((item: TransactionListItemType | ReportListItemType | TaskListItemType) => { + return data.some((item: TransactionListItemType | TransactionGroupListItemType | TaskListItemType) => { if (isTaskListItemType(item)) { const taskYear = new Date(item.created).getFullYear(); return taskYear !== currentYear; } - if (isReportListItemType(item)) { - // If the item is a ReportListItemType, iterate over its transactions and check them + if (isTransactionGroupListItemType(item)) { + // If the item is a TransactionGroupListItemType, iterate over its transactions and check them return item.transactions.some((transaction) => { const transactionYear = new Date(getTransactionCreatedDate(transaction)).getFullYear(); return transactionYear !== currentYear; @@ -859,11 +859,11 @@ function getReportActionsSections(data: OnyxTypes.SearchResults['data']): Report /** * @private - * Organizes data into List Sections for display, for the ReportListItemType of Search Results. + * Organizes data into List Sections for display, for the TransactionGroupListItemType of Search Results. * * Do not use directly, use only via `getSections()` facade. */ -function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): ReportListItemType[] { +function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): TransactionGroupListItemType[] { const shouldShowMerchant = getShouldShowMerchant(data); const doesDataContainAPastYearTransaction = shouldShowYear(data); @@ -872,7 +872,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx // Get violations - optimize by using a Map for faster lookups const allViolations = getViolations(data); - const reportIDToTransactions: Record = {}; + const reportIDToTransactions: Record = {}; for (const key in data) { if (isReportEntry(key) && (data[key].type === CONST.REPORT.TYPE.IOU || data[key].type === CONST.REPORT.TYPE.EXPENSE || data[key].type === CONST.REPORT.TYPE.INVOICE)) { const reportItem = {...data[key]}; @@ -941,34 +941,37 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx /** * Returns the appropriate list item component based on the type and status of the search data. */ -function getListItem(type: SearchDataTypes, status: SearchStatus, shouldGroupByReports = false): ListItemType { +function getListItem(type: SearchDataTypes, status: SearchStatus, groupBy?: SearchGroupBy): ListItemType { if (type === CONST.SEARCH.DATA_TYPES.CHAT) { return ChatListItem; } if (type === CONST.SEARCH.DATA_TYPES.TASK) { return TaskListItem; } - if (!shouldGroupByReports) { - return TransactionListItem; + if (groupBy) { + return TransactionGroupListItem; } - return TransactionGroupListItem; + return TransactionListItem; } /** * Organizes data into appropriate list sections for display based on the type of search results. */ -function getSections(type: SearchDataTypes, status: SearchStatus, data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search'], shouldGroupByReports = false) { +function getSections(type: SearchDataTypes, status: SearchStatus, data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search'], groupBy?: SearchGroupBy) { if (type === CONST.SEARCH.DATA_TYPES.CHAT) { return getReportActionsSections(data); } if (type === CONST.SEARCH.DATA_TYPES.TASK) { return getTaskSections(data); } - if (!shouldGroupByReports) { - return getTransactionsSections(data, metadata); + if (groupBy === CONST.SEARCH.GROUP_BY.REPORTS) { + return getReportSections(data, metadata); + } + if (groupBy === CONST.SEARCH.GROUP_BY.MEMBERS) { + // s77rt TODO } - return getReportSections(data, metadata); + return getTransactionsSections(data, metadata); } /** @@ -980,7 +983,7 @@ function getSortedSections( data: ListItemDataType, sortBy?: SearchColumnType, sortOrder?: SortOrder, - shouldGroupByReports = false, + groupBy?: SearchGroupBy, ) { if (type === CONST.SEARCH.DATA_TYPES.CHAT) { return getSortedReportActionData(data as ReportActionListItemType[]); @@ -988,10 +991,13 @@ function getSortedSections( if (type === CONST.SEARCH.DATA_TYPES.TASK) { return getSortedTaskData(data as TaskListItemType[], sortBy, sortOrder); } - if (!shouldGroupByReports) { - return getSortedTransactionData(data as TransactionListItemType[], sortBy, sortOrder); + if (groupBy === CONST.SEARCH.GROUP_BY.REPORTS) { + return getSortedReportData(data as TransactionGroupListItemType[]); + } + if (groupBy === CONST.SEARCH.GROUP_BY.MEMBERS) { + // s77rt TODO } - return getSortedReportData(data as ReportListItemType[]); + return getSortedTransactionData(data as TransactionListItemType[], sortBy, sortOrder); } /** @@ -1064,7 +1070,7 @@ function getSortedTaskData(data: TaskListItemType[], sortBy?: SearchColumnType, * @private * Sorts report sections based on a specified column and sort order. */ -function getSortedReportData(data: ReportListItemType[]) { +function getSortedReportData(data: TransactionGroupListItemType[]) { for (const report of data) { report.transactions = getSortedTransactionData(report.transactions, CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.SORT_ORDER.DESC); } @@ -1592,7 +1598,7 @@ export { getSections, getShouldShowMerchant, getSortedSections, - isReportListItemType, + isTransactionGroupListItemType, isSearchResultsEmpty, isTransactionListItemType, isReportActionListItemType, diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 9727da39a594..8ad432f620ad 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -3,7 +3,7 @@ import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {FormOnyxValues} from '@components/Form/types'; import type {PaymentData, SearchQueryJSON} from '@components/Search/types'; -import type {ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import * as API from '@libs/API'; import type {ExportSearchItemsToCSVParams, SubmitReportParams} from '@libs/API/parameters'; import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; @@ -14,7 +14,7 @@ import enhanceParameters from '@libs/Network/enhanceParameters'; import {rand64} from '@libs/NumberUtils'; import {getSubmitToAccountID} from '@libs/PolicyUtils'; import {hasHeldExpenses} from '@libs/ReportUtils'; -import {isReportListItemType, isTransactionListItemType} from '@libs/SearchUIUtils'; +import {isTransactionGroupListItemType, isTransactionListItemType} from '@libs/SearchUIUtils'; import playSound, {SOUNDS} from '@libs/Sound'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -40,11 +40,11 @@ Onyx.connect({ waitForCollectionCallback: true, }); -function handleActionButtonPress(hash: number, item: TransactionListItemType | ReportListItemType, goToItem: () => void, isInMobileSelectionMode: boolean) { +function handleActionButtonPress(hash: number, item: TransactionListItemType | TransactionGroupListItemType, goToItem: () => void, isInMobileSelectionMode: boolean) { // The transactionIDList is needed to handle actions taken on `status:all` where transactions on single expense reports can be approved/paid. // We need the transactionID to display the loading indicator for that list item's action. const transactionID = isTransactionListItemType(item) ? [item.transactionID] : undefined; - const allReportTransactions = (isReportListItemType(item) ? item.transactions : [item]) as SearchTransaction[]; + const allReportTransactions = (isTransactionGroupListItemType(item) ? item.transactions : [item]) as SearchTransaction[]; const hasHeldExpense = hasHeldExpenses('', allReportTransactions); if (hasHeldExpense || isInMobileSelectionMode) { @@ -83,7 +83,7 @@ function getLastPolicyPaymentMethod(policyID: string | undefined, lastPaymentMet return lastPolicyPaymentMethod; } -function getPayActionCallback(hash: number, item: TransactionListItemType | ReportListItemType, goToItem: () => void) { +function getPayActionCallback(hash: number, item: TransactionListItemType | TransactionGroupListItemType, goToItem: () => void) { const lastPolicyPaymentMethod = getLastPolicyPaymentMethod(item.policyID, lastPaymentMethod); if (!lastPolicyPaymentMethod) { diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index cc61d28b8a76..ba399adc28f7 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -3,7 +3,7 @@ import type {SearchStatus} from '@components/Search/types'; import type ChatListItem from '@components/SelectionList/ChatListItem'; import type TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import type TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; -import type {ReportActionListItemType, ReportListItemType, TaskListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ReportActionListItemType, TaskListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import type CONST from '@src/CONST'; import type ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxCommon from './OnyxCommon'; @@ -31,7 +31,7 @@ type ListItemDataType = C ext ? TaskListItemType[] : T extends typeof CONST.SEARCH.STATUS.EXPENSE.ALL ? TransactionListItemType[] - : ReportListItemType[]; + : TransactionGroupListItemType[]; /** Model of columns to show for search results */ type ColumnsToShow = { diff --git a/tests/ui/ReportListItemHeaderTest.tsx b/tests/ui/ReportListItemHeaderTest.tsx index 4bca82f89001..a230b12e5244 100644 --- a/tests/ui/ReportListItemHeaderTest.tsx +++ b/tests/ui/ReportListItemHeaderTest.tsx @@ -7,7 +7,7 @@ import {LocaleContextProvider} from '@components/LocaleContextProvider'; import OnyxProvider from '@components/OnyxProvider'; import {Context as SearchContext} from '@components/Search/SearchContext'; import ReportListItemHeader from '@components/SelectionList/Search/ReportListItemHeader'; -import type {ReportListItemType} from '@components/SelectionList/types'; +import type {TransactionGroupListItemType} from '@components/SelectionList/types'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {SearchPersonalDetails} from '@src/types/onyx/SearchResults'; @@ -58,7 +58,7 @@ const mockPersonalDetails: Record = { }; const mockPolicy = createRandomPolicy(1); -const createReportListItem = (type: ValueOf, from?: string, to?: string, options: Partial = {}): ReportListItemType => ({ +const createReportListItem = (type: ValueOf, from?: string, to?: string, options: Partial = {}): TransactionGroupListItemType => ({ shouldAnimateInHighlight: false, action: 'view' as const, chatReportID: '123', @@ -87,7 +87,7 @@ const createReportListItem = (type: ValueOf, from?: st }); // Helper function to wrap component with context -const renderReportListItemHeader = (reportItem: ReportListItemType) => { +const renderReportListItemHeader = (reportItem: TransactionGroupListItemType) => { return render( {/* @ts-expect-error - Disable TypeScript errors to simplify the test */} diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 63f31f51a653..08d057977872 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -2,7 +2,7 @@ import Onyx from 'react-native-onyx'; import ChatListItem from '@components/SelectionList/ChatListItem'; import TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; -import type {ReportActionListItemType, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ReportActionListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import * as Expensicons from '@src/components/Icon/Expensicons'; import CONST from '@src/CONST'; import TranslationStore from '@src/languages/TranslationStore'; @@ -950,7 +950,7 @@ const reportsListItems = [ }, transactions: [transactionsListItems.at(2), transactionsListItems.at(3)], }, -] as ReportListItemType[]; +] as TransactionGroupListItemType[]; describe('SearchUIUtils', () => { beforeAll(async () => { @@ -1168,20 +1168,32 @@ describe('SearchUIUtils', () => { expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.CHAT, 'all')).toStrictEqual(ChatListItem); }); - it('should return TransactionListItem when shouldGroupByReports is false', () => { - expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', false)).toStrictEqual(TransactionListItem); + it('should return TransactionListItem when groupBy is undefined', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', undefined)).toStrictEqual(TransactionListItem); }); - it('should return TransactionGroupListItem when type is EXPENSE and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', true)).toStrictEqual(TransactionGroupListItem); + it('should return TransactionGroupListItem when type is EXPENSE and groupBy is report', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(TransactionGroupListItem); }); - it('should return TransactionGroupListItem when type is TRIP and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.TRIP, 'all', true)).toStrictEqual(TransactionGroupListItem); + it('should return TransactionGroupListItem when type is TRIP and groupBy is report', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.TRIP, 'all', CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(TransactionGroupListItem); }); - it('should return TransactionGroupListItem when type is INVOICE and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', true)).toStrictEqual(TransactionGroupListItem); + it('should return TransactionGroupListItem when type is INVOICE and groupBy is report', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(TransactionGroupListItem); + }); + + it('should return TransactionGroupListItem when type is EXPENSE and groupBy is member', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual(TransactionGroupListItem); + }); + + it('should return TransactionGroupListItem when type is TRIP and groupBy is member', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.TRIP, 'all', CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual(TransactionGroupListItem); + }); + + it('should return TransactionGroupListItem when type is INVOICE and groupBy is member', () => { + expect(SearchUIUtils.getListItem(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual(TransactionGroupListItem); }); }); @@ -1190,20 +1202,40 @@ describe('SearchUIUtils', () => { expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.CHAT, 'all', searchResults.data, searchResults.search)).toStrictEqual(reportActionListItems); }); - it('should return getTransactionsSections result when shouldGroupByReports is false', () => { - expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', searchResults.data, searchResults.search, false)).toStrictEqual(transactionsListItems); + it('should return getTransactionsSections result when groupBy is undefined', () => { + expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', searchResults.data, searchResults.search, undefined)).toStrictEqual(transactionsListItems); + }); + + it('should return getReportSections result when type is EXPENSE and groupBy is report', () => { + expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual( + reportsListItems, + ); + }); + + it('should return getReportSections result when type is TRIP and groupBy is report', () => { + expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.TRIP, 'all', searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(reportsListItems); }); - it('should return getReportSections result when type is EXPENSE and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', searchResults.data, searchResults.search, true)).toStrictEqual(reportsListItems); + it('should return getReportSections result when type is INVOICE and groupBy is report', () => { + expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual( + reportsListItems, + ); + }); + + it('should return getMemberSections result when type is EXPENSE and groupBy is member', () => { + expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual( + reportsListItems, + ); }); - it('should return getReportSections result when type is TRIP and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.TRIP, 'all', searchResults.data, searchResults.search, true)).toStrictEqual(reportsListItems); + it('should return getMemberSections result when type is TRIP and groupBy is member', () => { + expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.TRIP, 'all', searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual(reportsListItems); }); - it('should return getReportSections result when type is INVOICE and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', searchResults.data, searchResults.search, true)).toStrictEqual(reportsListItems); + it('should return getMemberSections result when type is INVOICE and groupBy is member', () => { + expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual( + reportsListItems, + ); }); }); @@ -1243,20 +1275,32 @@ describe('SearchUIUtils', () => { ]); }); - it('should return getSortedTransactionData result when shouldGroupByReports is false', () => { - expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', transactionsListItems, 'date', 'asc', false)).toStrictEqual(transactionsListItems); + it('should return getSortedTransactionData result when groupBy is undefined', () => { + expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', transactionsListItems, 'date', 'asc', undefined)).toStrictEqual(transactionsListItems); + }); + + it('should return getSortedReportData result when type is EXPENSE and groupBy is report', () => { + expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', reportsListItems, 'date', 'asc', CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(reportsListItems); + }); + + it('should return getSortedReportData result when type is TRIP and groupBy is report', () => { + expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.TRIP, 'all', reportsListItems, 'date', 'asc', CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(reportsListItems); + }); + + it('should return getSortedReportData result when type is INVOICE and groupBy is report', () => { + expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', reportsListItems, 'date', 'asc', CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(reportsListItems); }); - it('should return getSortedReportData result when type is EXPENSE and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', reportsListItems, 'date', 'asc', true)).toStrictEqual(reportsListItems); + it('should return getSortedMemberData result when type is EXPENSE and groupBy is member', () => { + expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.EXPENSE, 'all', reportsListItems, 'date', 'asc', CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual(reportsListItems); }); - it('should return getSortedReportData result when type is TRIP and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.TRIP, 'all', reportsListItems, 'date', 'asc', true)).toStrictEqual(reportsListItems); + it('should return getSortedMemberData result when type is TRIP and groupBy is member', () => { + expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.TRIP, 'all', reportsListItems, 'date', 'asc', CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual(reportsListItems); }); - it('should return getSortedReportData result when type is INVOICE and shouldGroupByReports is true', () => { - expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', reportsListItems, 'date', 'asc', true)).toStrictEqual(reportsListItems); + it('should return getSortedMemberData result when type is INVOICE and groupBy is member', () => { + expect(SearchUIUtils.getSortedSections(CONST.SEARCH.DATA_TYPES.INVOICE, 'all', reportsListItems, 'date', 'asc', CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual(reportsListItems); }); }); diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index de311cf12e3c..532f5a5b219e 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import type {ReportListItemType} from '@components/SelectionList/types'; +import type {TransactionGroupListItemType} from '@components/SelectionList/types'; import {handleActionButtonPress} from '@libs/actions/Search'; jest.mock('@src/components/ConfirmedRoute.tsx'); @@ -190,7 +190,7 @@ const mockReportItemWithHold = { }, ], isSelected: false, -} as ReportListItemType; +} as TransactionGroupListItemType; const updatedMockReportItem = { ...mockReportItemWithHold, From ae1c39cc4395f1772f39fd98ef5f33eb95d7783e Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 12:39:24 +0100 Subject: [PATCH 08/46] lint --- .../Search/SearchPageHeader/SearchFiltersBar.tsx | 1 + src/libs/SearchUIUtils.ts | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx b/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx index 8653051f9c60..11e08a4c368d 100644 --- a/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx +++ b/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx @@ -260,6 +260,7 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro filterFormValues.from, translate, typeComponent, + groupByComponent, statusComponent, datePickerComponent, userPickerComponent, diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 3c0ed03bd43e..ecac9d22a566 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1169,7 +1169,7 @@ function isCorrectSearchUserName(displayName?: string) { return displayName && displayName.toUpperCase() !== CONST.REPORT.OWNER_EMAIL_FAKE; } -function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies: OnyxCollection = {}, cards: OnyxTypes.CardList): SearchTypeMenuSection[] { +function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies: OnyxCollection = {}, cards: OnyxTypes.CardList = {}): SearchTypeMenuSection[] { const email = session?.email; const hasCardFeed = Object.keys(cards).length > 0; @@ -1404,10 +1404,10 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies menuItems: [], }; - let shouldShowStatementsSuggesion = false, - showShowUnapprovedCashSuggesion = false, - showShowUnapprovedCompanyCardsSuggesion = false, - shouldShowReconciliationSuggesion = false; + let shouldShowStatementsSuggesion = false; + let showShowUnapprovedCashSuggesion = false; + let showShowUnapprovedCompanyCardsSuggesion = false; + let shouldShowReconciliationSuggesion = false; Object.values(policies).some((policy) => { if (!policy || !isPaidGroupPolicy(policy)) { From 704c71452a52543f1f772c5a02ce3b5458b54a01 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 12:50:09 +0100 Subject: [PATCH 09/46] spell check --- src/libs/SearchUIUtils.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index ecac9d22a566..bd9126b933f1 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1404,10 +1404,10 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies menuItems: [], }; - let shouldShowStatementsSuggesion = false; - let showShowUnapprovedCashSuggesion = false; - let showShowUnapprovedCompanyCardsSuggesion = false; - let shouldShowReconciliationSuggesion = false; + let shouldShowStatementsSuggestion = false; + let showShowUnapprovedCashSuggestion = false; + let showShowUnapprovedCompanyCardsSuggestion = false; + let shouldShowReconciliationSuggestion = false; Object.values(policies).some((policy) => { if (!policy || !isPaidGroupPolicy(policy)) { @@ -1418,20 +1418,20 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies const isApprovalEnabled = policy.approvalMode ? policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL : false; const isPaymentEnabled = arePaymentsEnabled(policy); - shouldShowStatementsSuggesion ||= false; // s77rt - showShowUnapprovedCashSuggesion ||= isAdmin && isApprovalEnabled && isPaymentEnabled; - showShowUnapprovedCompanyCardsSuggesion ||= isAdmin && isApprovalEnabled && (policy.areCompanyCardsEnabled === true || policy.areExpensifyCardsEnabled === true) && hasCardFeed; - shouldShowReconciliationSuggesion ||= false; // s77rt + shouldShowStatementsSuggestion ||= false; // s77rt + showShowUnapprovedCashSuggestion ||= isAdmin && isApprovalEnabled && isPaymentEnabled; + showShowUnapprovedCompanyCardsSuggestion ||= isAdmin && isApprovalEnabled && (policy.areCompanyCardsEnabled === true || policy.areExpensifyCardsEnabled === true) && hasCardFeed; + shouldShowReconciliationSuggestion ||= false; // s77rt // If all search variables are true return early to avoid redundant iterations - return shouldShowStatementsSuggesion && showShowUnapprovedCashSuggesion && showShowUnapprovedCompanyCardsSuggesion && shouldShowReconciliationSuggesion; + return shouldShowStatementsSuggestion && showShowUnapprovedCashSuggestion && showShowUnapprovedCompanyCardsSuggestion && shouldShowReconciliationSuggestion; }); - if (shouldShowStatementsSuggesion) { + if (shouldShowStatementsSuggestion) { // s77rt TODO } - if (showShowUnapprovedCashSuggesion && showShowUnapprovedCompanyCardsSuggesion) { + if (showShowUnapprovedCashSuggestion && showShowUnapprovedCompanyCardsSuggestion) { accountingSection.menuItems.push( { translationPath: 'search.unapprovedCash', @@ -1472,7 +1472,7 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies }, }, ); - } else if (showShowUnapprovedCashSuggesion) { + } else if (showShowUnapprovedCashSuggestion) { accountingSection.menuItems.push({ translationPath: 'search.unapproved', type: CONST.SEARCH.DATA_TYPES.EXPENSE, @@ -1492,7 +1492,7 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies return queryString; }, }); - } else if (showShowUnapprovedCompanyCardsSuggesion) { + } else if (showShowUnapprovedCompanyCardsSuggestion) { accountingSection.menuItems.push({ translationPath: 'search.unapproved', type: CONST.SEARCH.DATA_TYPES.EXPENSE, @@ -1514,7 +1514,7 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies }); } - if (shouldShowReconciliationSuggesion) { + if (shouldShowReconciliationSuggestion) { // s77rt TODO } From 737d0188ec7049599345dddc5d631c0bb4e9275b Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 15:18:22 +0100 Subject: [PATCH 10/46] rename ReportListItemProps to TransactionGroupListItemProps --- .../Search/TransactionGroupListItem.tsx | 4 ++-- src/components/SelectionList/types.ts | 5 ++-- src/libs/SearchUIUtils.ts | 24 ++++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index afaf7d10ea38..7d0108117b3e 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -3,7 +3,7 @@ import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import BaseListItem from '@components/SelectionList/BaseListItem'; -import type {ListItem, ReportListItemProps, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ListItem, TransactionGroupListItemProps, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import Text from '@components/Text'; import TransactionItemRow from '@components/TransactionItemRow'; import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; @@ -33,7 +33,7 @@ function TransactionGroupListItem({ onFocus, onLongPressRow, shouldSyncFocus, -}: ReportListItemProps) { +}: TransactionGroupListItemProps) { const reportItem = item as unknown as TransactionGroupListItemType; const theme = useTheme(); const styles = useThemeStyles(); diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 995a4be50c8a..3e44cbbf1ddf 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -316,6 +316,7 @@ type TaskListItemType = ListItem & shouldShowYear: boolean; }; +// s77rt remove SearchReport type? type TransactionGroupListItemType = ListItem & SearchReport & { /** The personal details of the user requesting money */ @@ -450,7 +451,7 @@ type TaskListItemProps = ListItemProps & { isLoading?: boolean; }; -type ReportListItemProps = ListItemProps; +type TransactionGroupListItemProps = ListItemProps; type ChatListItemProps = ListItemProps & { queryJSONHash?: number; @@ -860,7 +861,7 @@ export type { RadioListItemProps, SingleSelectListItemProps, MultiSelectListItemProps, - ReportListItemProps, + TransactionGroupListItemProps, TransactionGroupListItemType, Section, SectionListDataType, diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index bd9126b933f1..d56f298f2634 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -859,7 +859,7 @@ function getReportActionsSections(data: OnyxTypes.SearchResults['data']): Report /** * @private - * Organizes data into List Sections for display, for the TransactionGroupListItemType of Search Results. + * Organizes data into List Sections grouped by report for display, for the TransactionGroupListItemType of Search Results. * * Do not use directly, use only via `getSections()` facade. */ @@ -938,6 +938,16 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx return Object.values(reportIDToTransactions); } +/** + * @private + * Organizes data into List Sections grouped by member for display, for the TransactionGroupListItemType of Search Results. + * + * Do not use directly, use only via `getSections()` facade. + */ +function getMemberSections(_data: OnyxTypes.SearchResults['data'], _metadata: OnyxTypes.SearchResults['search']): TransactionGroupListItemType[] { + return []; // s77rt +} + /** * Returns the appropriate list item component based on the type and status of the search data. */ @@ -968,7 +978,7 @@ function getSections(type: SearchDataTypes, status: SearchStatus, data: OnyxType return getReportSections(data, metadata); } if (groupBy === CONST.SEARCH.GROUP_BY.MEMBERS) { - // s77rt TODO + return getMemberSections(data, metadata); } return getTransactionsSections(data, metadata); @@ -995,7 +1005,7 @@ function getSortedSections( return getSortedReportData(data as TransactionGroupListItemType[]); } if (groupBy === CONST.SEARCH.GROUP_BY.MEMBERS) { - // s77rt TODO + return getSortedMemberData(data as TransactionGroupListItemType[]); } return getSortedTransactionData(data as TransactionListItemType[], sortBy, sortOrder); } @@ -1086,6 +1096,14 @@ function getSortedReportData(data: TransactionGroupListItemType[]) { }); } +/** + * @private + * Sorts report sections based on a specified column and sort order. + */ +function getSortedMemberData(_data: TransactionGroupListItemType[]) { + return []; // s77rt +} + /** * @private * Sorts report actions sections based on a specified column and sort order. From bd8c14a4d316a6a6caa585186a037e4b3885eb3e Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 19:57:39 +0100 Subject: [PATCH 11/46] added TransactionReportGroupListItemType and TransactionMemberGroupListItemType --- src/components/Search/SearchContext.tsx | 11 ++- src/components/Search/SearchList.tsx | 1 + .../Search/ReportListItemHeader.tsx | 8 +- .../Search/TransactionGroupListItem.tsx | 73 +++++++++++-------- .../Search/UserInfoAndActionButtonRow.tsx | 4 +- src/components/SelectionList/types.ts | 21 ++++-- src/libs/SearchUIUtils.ts | 29 +++++++- src/libs/actions/Search.ts | 6 +- tests/ui/ReportListItemHeaderTest.tsx | 11 ++- tests/unit/Search/SearchUIUtilsTest.ts | 4 +- .../Search/handleActionButtonPressTest.ts | 4 +- 11 files changed, 116 insertions(+), 56 deletions(-) diff --git a/src/components/Search/SearchContext.tsx b/src/components/Search/SearchContext.tsx index e8afa1a8dd1a..63cd05727a73 100644 --- a/src/components/Search/SearchContext.tsx +++ b/src/components/Search/SearchContext.tsx @@ -1,6 +1,6 @@ import React, {useCallback, useContext, useMemo, useRef, useState} from 'react'; import {isMoneyRequestReport} from '@libs/ReportUtils'; -import {isTransactionGroupListItemType, isTransactionListItemType} from '@libs/SearchUIUtils'; +import {isTransactionGroupListItemType, isTransactionListItemType, isTransactionMemberGroupListItemType, isTransactionReportGroupListItemType} from '@libs/SearchUIUtils'; import CONST from '@src/CONST'; import type ChildrenProps from '@src/types/utils/ChildrenProps'; import type {SearchContext, SearchContextData} from './types'; @@ -63,12 +63,19 @@ function SearchContextProvider({children}: ChildrenProps) { // When selecting transactions, we also need to manage the reports to which these transactions belong. This is done to ensure proper exporting to CSV. let selectedReports: SearchContext['selectedReports'] = []; - if (data.length && data.every(isTransactionGroupListItemType)) { + if (data.length && data.every(isTransactionReportGroupListItemType)) { selectedReports = data .filter((item) => isMoneyRequestReport(item) && item.transactions.every(({keyForList}) => selectedTransactions[keyForList]?.isSelected)) .map(({reportID, action = CONST.SEARCH.ACTION_TYPES.VIEW, total = CONST.DEFAULT_NUMBER_ID, policyID}) => ({reportID, action, total, policyID})); } + if (data.length && data.every(isTransactionMemberGroupListItemType)) { + selectedReports = data + .flatMap((item) => item.transactions) + .filter(({keyForList}) => !!keyForList && selectedTransactions[keyForList]?.isSelected) + .map(({reportID, action = CONST.SEARCH.ACTION_TYPES.VIEW, amount: total = CONST.DEFAULT_NUMBER_ID, policyID}) => ({reportID, action, total, policyID})); + } + if (data.length && data.every(isTransactionListItemType)) { selectedReports = data .filter(({keyForList}) => !!keyForList && selectedTransactions[keyForList]?.isSelected) diff --git a/src/components/Search/SearchList.tsx b/src/components/Search/SearchList.tsx index 8d7716545a98..85d2b90d00c4 100644 --- a/src/components/Search/SearchList.tsx +++ b/src/components/Search/SearchList.tsx @@ -338,6 +338,7 @@ function SearchList( policies={policies} isDisabled={isDisabled} allReports={allReports} + groupBy={groupBy} /> ); }, diff --git a/src/components/SelectionList/Search/ReportListItemHeader.tsx b/src/components/SelectionList/Search/ReportListItemHeader.tsx index 9b79bc049161..0e8de51825da 100644 --- a/src/components/SelectionList/Search/ReportListItemHeader.tsx +++ b/src/components/SelectionList/Search/ReportListItemHeader.tsx @@ -5,7 +5,7 @@ import type {OnyxEntry} from 'react-native-onyx'; import Checkbox from '@components/Checkbox'; import ReportSearchHeader from '@components/ReportSearchHeader'; import {useSearchContext} from '@components/Search/SearchContext'; -import type {ListItem, TransactionGroupListItemType} from '@components/SelectionList/types'; +import type {ListItem, TransactionReportGroupListItemType} from '@components/SelectionList/types'; import TextWithTooltip from '@components/TextWithTooltip'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useStyleUtils from '@hooks/useStyleUtils'; @@ -20,7 +20,7 @@ import UserInfoAndActionButtonRow from './UserInfoAndActionButtonRow'; type ReportListItemHeaderProps = { /** The report currently being looked at */ - report: TransactionGroupListItemType; + report: TransactionReportGroupListItemType; /** The policy tied to the expense report */ policy: OnyxEntry; @@ -46,7 +46,7 @@ type ReportListItemHeaderProps = { type FirstRowReportHeaderProps = { /** The report currently being looked at */ - report: TransactionGroupListItemType; + report: TransactionReportGroupListItemType; /** The policy tied to the expense report */ policy: OnyxEntry; @@ -73,7 +73,7 @@ type FirstRowReportHeaderProps = { type ReportCellProps = { showTooltip: boolean; isLargeScreenWidth: boolean; - reportItem: TransactionGroupListItemType; + reportItem: TransactionReportGroupListItemType; }; function TotalCell({showTooltip, isLargeScreenWidth, reportItem}: ReportCellProps) { diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index 7d0108117b3e..08ae0a7395ea 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -1,9 +1,10 @@ -import React, {useMemo} from 'react'; +import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import {SearchGroupBy} from '@components/Search/types'; import BaseListItem from '@components/SelectionList/BaseListItem'; -import type {ListItem, TransactionGroupListItemProps, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ListItem, TransactionGroupListItemProps, TransactionGroupListItemType, TransactionListItemType, TransactionReportGroupListItemType} from '@components/SelectionList/types'; import Text from '@components/Text'; import TransactionItemRow from '@components/TransactionItemRow'; import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; @@ -33,27 +34,28 @@ function TransactionGroupListItem({ onFocus, onLongPressRow, shouldSyncFocus, + groupBy, }: TransactionGroupListItemProps) { - const reportItem = item as unknown as TransactionGroupListItemType; + const groupItem = item as unknown as TransactionGroupListItemType; const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}, canBeMissing: true}); - const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportItem?.policyID}`]; - const isEmptyReport = reportItem.transactions.length === 0; - const isDisabledOrEmpty = isEmptyReport || isDisabled; + const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${groupItem?.policyID}`]; + const isEmpty = groupItem.transactions.length === 0; + const isDisabledOrEmpty = isEmpty || isDisabled; const {isLargeScreenWidth} = useResponsiveLayout(); const {amountColumnSize, dateColumnSize, taxAmountColumnSize} = useMemo(() => { - const isAmountColumnWide = reportItem.transactions.some((transaction) => isTransactionAmountTooLong(transaction)); - const isTaxAmountColumnWide = reportItem.transactions.some((transaction) => isTransactionTaxAmountTooLong(transaction)); - const shouldShowYearForSomeTransaction = reportItem.transactions.some((transaction) => shouldShowTransactionYear(transaction)); + const isAmountColumnWide = groupItem.transactions.some((transaction) => isTransactionAmountTooLong(transaction)); + const isTaxAmountColumnWide = groupItem.transactions.some((transaction) => isTransactionTaxAmountTooLong(transaction)); + const shouldShowYearForSomeTransaction = groupItem.transactions.some((transaction) => shouldShowTransactionYear(transaction)); return { amountColumnSize: isAmountColumnWide ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL, taxAmountColumnSize: isTaxAmountColumnWide ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL, dateColumnSize: shouldShowYearForSomeTransaction ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL, }; - }, [reportItem.transactions]); + }, [groupItem.transactions]); const animatedHighlightStyle = useAnimatedHighlightStyle({ borderRadius: variables.componentBorderRadius, @@ -77,7 +79,7 @@ function TransactionGroupListItem({ const backTo = Navigation.getActiveRoute(); const reportID = getReportIDForTransaction(transactionItem); - const siblingTransactionThreadIDs = reportItem.transactions.map(getReportIDForTransaction); + const siblingTransactionThreadIDs = groupItem.transactions.map(getReportIDForTransaction); // When opening the transaction thread in RHP we need to find every other ID for the rest of transactions // to display prev/next arrows in RHP for navigation @@ -86,11 +88,7 @@ function TransactionGroupListItem({ }); }; - if (!reportItem?.reportName && reportItem.transactions.length > 1) { - return null; - } - - const sampleTransaction = reportItem.transactions.at(0); + const sampleTransaction = groupItem.transactions.at(0); const {COLUMNS} = CONST.REPORT.TRANSACTION_LIST; const columns = [ @@ -107,6 +105,32 @@ function TransactionGroupListItem({ COLUMNS.ACTION, ] satisfies Array>; + const getHeader = useCallback( + (isHovered: boolean) => { + switch (groupBy) { + case CONST.SEARCH.GROUP_BY.REPORTS: + return ( + + ); + case CONST.SEARCH.GROUP_BY.MEMBERS: + // s77rt + return null; + default: + return null; + } + }, + [groupBy, groupItem, canSelectMultiple, isDisabledOrEmpty, isFocused, onCheckboxPress, onSelectRow, policy], + ); + return ( ({ > {(hovered) => ( - - {isEmptyReport ? ( + {getHeader(hovered)} + {isEmpty ? ( ({ ) : ( - reportItem.transactions.map((transaction) => ( + groupItem.transactions.map((transaction) => ( ({ isParentHovered={hovered} columnWrapperStyles={[styles.ph3, styles.pv1half]} isReportItemChild - isInSingleTransactionReport={reportItem.transactions.length === 1} + isInSingleTransactionReport={groupItem.transactions.length === 1} /> )) diff --git a/src/components/SelectionList/Search/UserInfoAndActionButtonRow.tsx b/src/components/SelectionList/Search/UserInfoAndActionButtonRow.tsx index 9cc075f7f614..ef12633d27a8 100644 --- a/src/components/SelectionList/Search/UserInfoAndActionButtonRow.tsx +++ b/src/components/SelectionList/Search/UserInfoAndActionButtonRow.tsx @@ -1,6 +1,6 @@ import React from 'react'; import {View} from 'react-native'; -import type {TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {TransactionListItemType, TransactionReportGroupListItemType} from '@components/SelectionList/types'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {isCorrectSearchUserName} from '@libs/SearchUIUtils'; @@ -14,7 +14,7 @@ function UserInfoAndActionButtonRow({ handleActionButtonPress, shouldShowUserInfo, }: { - item: TransactionGroupListItemType | TransactionListItemType; + item: TransactionReportGroupListItemType | TransactionListItemType; handleActionButtonPress: () => void; shouldShowUserInfo: boolean; }) { diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 3e44cbbf1ddf..896a8a858bcb 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -15,7 +15,7 @@ import type { import type {OnyxCollection} from 'react-native-onyx'; import type {AnimatedStyle} from 'react-native-reanimated'; import type {SearchRouterItem} from '@components/Search/SearchAutocompleteList'; -import type {SearchColumnType} from '@components/Search/types'; +import type {SearchColumnType, SearchGroupBy} from '@components/Search/types'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import type UnreportedExpenseListItem from '@pages/UnreportedExpenseListItem'; import type SpendCategorySelectorListItem from '@pages/workspace/categories/SpendCategorySelectorListItem'; @@ -316,19 +316,22 @@ type TaskListItemType = ListItem & shouldShowYear: boolean; }; -// s77rt remove SearchReport type? -type TransactionGroupListItemType = ListItem & +type TransactionGroupListItemType = ListItem & { + /** List of grouped transactions */ + transactions: TransactionListItemType[]; +}; + +type TransactionReportGroupListItemType = TransactionGroupListItemType & SearchReport & { /** The personal details of the user requesting money */ from: SearchPersonalDetails; /** The personal details of the user paying the request */ to: SearchPersonalDetails; - - /** List of transactions that belong to this report */ - transactions: TransactionListItemType[]; }; +type TransactionMemberGroupListItemType = TransactionGroupListItemType & SearchPersonalDetails; + type ListItemProps = CommonListItemProps & { /** The section list item */ item: TItem; @@ -451,7 +454,9 @@ type TaskListItemProps = ListItemProps & { isLoading?: boolean; }; -type TransactionGroupListItemProps = ListItemProps; +type TransactionGroupListItemProps = ListItemProps & { + groupBy?: SearchGroupBy; +}; type ChatListItemProps = ListItemProps & { queryJSONHash?: number; @@ -863,6 +868,8 @@ export type { MultiSelectListItemProps, TransactionGroupListItemProps, TransactionGroupListItemType, + TransactionReportGroupListItemType, + TransactionMemberGroupListItemType, Section, SectionListDataType, SectionWithIndexOffset, diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index d56f298f2634..27e2ecff1b49 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -12,7 +12,16 @@ import ChatListItem from '@components/SelectionList/ChatListItem'; import TaskListItem from '@components/SelectionList/Search/TaskListItem'; import TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; -import type {ListItem, ReportActionListItemType, SearchListItem, TaskListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type { + ListItem, + ReportActionListItemType, + SearchListItem, + TaskListItemType, + TransactionGroupListItemType, + TransactionListItemType, + TransactionMemberGroupListItemType, + TransactionReportGroupListItemType, +} from '@components/SelectionList/types'; import * as Expensicons from '@src/components/Icon/Expensicons'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -291,6 +300,20 @@ function isTransactionGroupListItemType(item: ListItem): item is TransactionGrou return 'transactions' in item; } +/** + * Type guard that checks if something is a TransactionReportGroupListItemType + */ +function isTransactionReportGroupListItemType(item: ListItem): item is TransactionReportGroupListItemType { + return isTransactionGroupListItemType(item) && 'reportID' in item; +} + +/** + * Type guard that checks if something is a TransactionMemberGroupListItemType + */ +function isTransactionMemberGroupListItemType(item: ListItem): item is TransactionMemberGroupListItemType { + return isTransactionGroupListItemType(item) && 'accountID' in item; +} + /** * Type guard that checks if something is a TransactionListItemType */ @@ -872,7 +895,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx // Get violations - optimize by using a Map for faster lookups const allViolations = getViolations(data); - const reportIDToTransactions: Record = {}; + const reportIDToTransactions: Record = {}; for (const key in data) { if (isReportEntry(key) && (data[key].type === CONST.REPORT.TYPE.IOU || data[key].type === CONST.REPORT.TYPE.EXPENSE || data[key].type === CONST.REPORT.TYPE.INVOICE)) { const reportItem = {...data[key]}; @@ -1617,6 +1640,8 @@ export { getShouldShowMerchant, getSortedSections, isTransactionGroupListItemType, + isTransactionReportGroupListItemType, + isTransactionMemberGroupListItemType, isSearchResultsEmpty, isTransactionListItemType, isReportActionListItemType, diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 8ad432f620ad..f3caab59ad18 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -3,7 +3,7 @@ import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {FormOnyxValues} from '@components/Form/types'; import type {PaymentData, SearchQueryJSON} from '@components/Search/types'; -import type {TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {TransactionListItemType, TransactionReportGroupListItemType} from '@components/SelectionList/types'; import * as API from '@libs/API'; import type {ExportSearchItemsToCSVParams, SubmitReportParams} from '@libs/API/parameters'; import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; @@ -40,7 +40,7 @@ Onyx.connect({ waitForCollectionCallback: true, }); -function handleActionButtonPress(hash: number, item: TransactionListItemType | TransactionGroupListItemType, goToItem: () => void, isInMobileSelectionMode: boolean) { +function handleActionButtonPress(hash: number, item: TransactionListItemType | TransactionReportGroupListItemType, goToItem: () => void, isInMobileSelectionMode: boolean) { // The transactionIDList is needed to handle actions taken on `status:all` where transactions on single expense reports can be approved/paid. // We need the transactionID to display the loading indicator for that list item's action. const transactionID = isTransactionListItemType(item) ? [item.transactionID] : undefined; @@ -83,7 +83,7 @@ function getLastPolicyPaymentMethod(policyID: string | undefined, lastPaymentMet return lastPolicyPaymentMethod; } -function getPayActionCallback(hash: number, item: TransactionListItemType | TransactionGroupListItemType, goToItem: () => void) { +function getPayActionCallback(hash: number, item: TransactionListItemType | TransactionReportGroupListItemType, goToItem: () => void) { const lastPolicyPaymentMethod = getLastPolicyPaymentMethod(item.policyID, lastPaymentMethod); if (!lastPolicyPaymentMethod) { diff --git a/tests/ui/ReportListItemHeaderTest.tsx b/tests/ui/ReportListItemHeaderTest.tsx index a230b12e5244..328243ef9c0b 100644 --- a/tests/ui/ReportListItemHeaderTest.tsx +++ b/tests/ui/ReportListItemHeaderTest.tsx @@ -7,7 +7,7 @@ import {LocaleContextProvider} from '@components/LocaleContextProvider'; import OnyxProvider from '@components/OnyxProvider'; import {Context as SearchContext} from '@components/Search/SearchContext'; import ReportListItemHeader from '@components/SelectionList/Search/ReportListItemHeader'; -import type {TransactionGroupListItemType} from '@components/SelectionList/types'; +import type {TransactionReportGroupListItemType} from '@components/SelectionList/types'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {SearchPersonalDetails} from '@src/types/onyx/SearchResults'; @@ -58,7 +58,12 @@ const mockPersonalDetails: Record = { }; const mockPolicy = createRandomPolicy(1); -const createReportListItem = (type: ValueOf, from?: string, to?: string, options: Partial = {}): TransactionGroupListItemType => ({ +const createReportListItem = ( + type: ValueOf, + from?: string, + to?: string, + options: Partial = {}, +): TransactionReportGroupListItemType => ({ shouldAnimateInHighlight: false, action: 'view' as const, chatReportID: '123', @@ -87,7 +92,7 @@ const createReportListItem = (type: ValueOf, from?: st }); // Helper function to wrap component with context -const renderReportListItemHeader = (reportItem: TransactionGroupListItemType) => { +const renderReportListItemHeader = (reportItem: TransactionReportGroupListItemType) => { return render( {/* @ts-expect-error - Disable TypeScript errors to simplify the test */} diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 08d057977872..5f98b2b044fc 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -2,7 +2,7 @@ import Onyx from 'react-native-onyx'; import ChatListItem from '@components/SelectionList/ChatListItem'; import TransactionGroupListItem from '@components/SelectionList/Search/TransactionGroupListItem'; import TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; -import type {ReportActionListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; +import type {ReportActionListItemType, TransactionListItemType, TransactionReportGroupListItemType} from '@components/SelectionList/types'; import * as Expensicons from '@src/components/Icon/Expensicons'; import CONST from '@src/CONST'; import TranslationStore from '@src/languages/TranslationStore'; @@ -950,7 +950,7 @@ const reportsListItems = [ }, transactions: [transactionsListItems.at(2), transactionsListItems.at(3)], }, -] as TransactionGroupListItemType[]; +] as TransactionReportGroupListItemType[]; describe('SearchUIUtils', () => { beforeAll(async () => { diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index 532f5a5b219e..844feac76064 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import type {TransactionGroupListItemType} from '@components/SelectionList/types'; +import type {TransactionReportGroupListItemType} from '@components/SelectionList/types'; import {handleActionButtonPress} from '@libs/actions/Search'; jest.mock('@src/components/ConfirmedRoute.tsx'); @@ -190,7 +190,7 @@ const mockReportItemWithHold = { }, ], isSelected: false, -} as TransactionGroupListItemType; +} as TransactionReportGroupListItemType; const updatedMockReportItem = { ...mockReportItemWithHold, From dfd08e3869f70b4885c1ae0365a83fec880743cb Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 20:07:04 +0100 Subject: [PATCH 12/46] better types + lint --- src/components/Search/SearchContext.tsx | 2 +- .../Search/TransactionGroupListItem.tsx | 1 - src/libs/SearchUIUtils.ts | 12 ++++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/Search/SearchContext.tsx b/src/components/Search/SearchContext.tsx index 63cd05727a73..9f825de4fdaf 100644 --- a/src/components/Search/SearchContext.tsx +++ b/src/components/Search/SearchContext.tsx @@ -1,6 +1,6 @@ import React, {useCallback, useContext, useMemo, useRef, useState} from 'react'; import {isMoneyRequestReport} from '@libs/ReportUtils'; -import {isTransactionGroupListItemType, isTransactionListItemType, isTransactionMemberGroupListItemType, isTransactionReportGroupListItemType} from '@libs/SearchUIUtils'; +import {isTransactionListItemType, isTransactionMemberGroupListItemType, isTransactionReportGroupListItemType} from '@libs/SearchUIUtils'; import CONST from '@src/CONST'; import type ChildrenProps from '@src/types/utils/ChildrenProps'; import type {SearchContext, SearchContextData} from './types'; diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index 08ae0a7395ea..cce8c57f7388 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -2,7 +2,6 @@ import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; -import {SearchGroupBy} from '@components/Search/types'; import BaseListItem from '@components/SelectionList/BaseListItem'; import type {ListItem, TransactionGroupListItemProps, TransactionGroupListItemType, TransactionListItemType, TransactionReportGroupListItemType} from '@components/SelectionList/types'; import Text from '@components/Text'; diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 27e2ecff1b49..9715785d9c27 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -886,7 +886,7 @@ function getReportActionsSections(data: OnyxTypes.SearchResults['data']): Report * * Do not use directly, use only via `getSections()` facade. */ -function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): TransactionGroupListItemType[] { +function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): TransactionReportGroupListItemType[] { const shouldShowMerchant = getShouldShowMerchant(data); const doesDataContainAPastYearTransaction = shouldShowYear(data); @@ -967,7 +967,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx * * Do not use directly, use only via `getSections()` facade. */ -function getMemberSections(_data: OnyxTypes.SearchResults['data'], _metadata: OnyxTypes.SearchResults['search']): TransactionGroupListItemType[] { +function getMemberSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): TransactionMemberGroupListItemType[] { return []; // s77rt } @@ -1025,10 +1025,10 @@ function getSortedSections( return getSortedTaskData(data as TaskListItemType[], sortBy, sortOrder); } if (groupBy === CONST.SEARCH.GROUP_BY.REPORTS) { - return getSortedReportData(data as TransactionGroupListItemType[]); + return getSortedReportData(data as TransactionReportGroupListItemType[]); } if (groupBy === CONST.SEARCH.GROUP_BY.MEMBERS) { - return getSortedMemberData(data as TransactionGroupListItemType[]); + return getSortedMemberData(data as TransactionMemberGroupListItemType[]); } return getSortedTransactionData(data as TransactionListItemType[], sortBy, sortOrder); } @@ -1103,7 +1103,7 @@ function getSortedTaskData(data: TaskListItemType[], sortBy?: SearchColumnType, * @private * Sorts report sections based on a specified column and sort order. */ -function getSortedReportData(data: TransactionGroupListItemType[]) { +function getSortedReportData(data: TransactionReportGroupListItemType[]) { for (const report of data) { report.transactions = getSortedTransactionData(report.transactions, CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.SORT_ORDER.DESC); } @@ -1123,7 +1123,7 @@ function getSortedReportData(data: TransactionGroupListItemType[]) { * @private * Sorts report sections based on a specified column and sort order. */ -function getSortedMemberData(_data: TransactionGroupListItemType[]) { +function getSortedMemberData(data: TransactionMemberGroupListItemType[]) { return []; // s77rt } From 56fd3cf1b32e6beb1890b68dddb64ad815846846 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 23:27:26 +0100 Subject: [PATCH 13/46] added MemberListItemHeader --- .../Search/MemberListItemHeader.tsx | 83 +++++++++++++++++++ .../Search/TransactionGroupListItem.tsx | 22 +++-- src/styles/utils/spacing.ts | 6 +- 3 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 src/components/SelectionList/Search/MemberListItemHeader.tsx diff --git a/src/components/SelectionList/Search/MemberListItemHeader.tsx b/src/components/SelectionList/Search/MemberListItemHeader.tsx new file mode 100644 index 000000000000..1e5499f1d871 --- /dev/null +++ b/src/components/SelectionList/Search/MemberListItemHeader.tsx @@ -0,0 +1,83 @@ +import React from 'react'; +import {View} from 'react-native'; +import Avatar from '@components/Avatar'; +import Checkbox from '@components/Checkbox'; +import type {ListItem, TransactionMemberGroupListItemType} from '@components/SelectionList/types'; +import Text from '@components/Text'; +import TextWithTooltip from '@components/TextWithTooltip'; +import UserDetailsTooltip from '@components/UserDetailsTooltip'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; +import CONST from '@src/CONST'; + +type MemberListItemHeaderProps = { + /** The member currently being looked at */ + member: TransactionMemberGroupListItemType; + + /** Callback to fire when a checkbox is pressed */ + onCheckboxPress?: (item: TItem) => void; + + /** Whether this section items disabled for selection */ + isDisabled?: boolean | null; + + /** Whether selecting multiple transactions at once is allowed */ + canSelectMultiple: boolean | undefined; +}; + +function MemberListItemHeader({member: memberItem, onCheckboxPress, isDisabled, canSelectMultiple}: MemberListItemHeaderProps) { + const styles = useThemeStyles(); + const StyleUtils = useStyleUtils(); + const theme = useTheme(); + const {isLargeScreenWidth} = useResponsiveLayout(); + const shouldShowAction = isLargeScreenWidth; + + return ( + + + + {!!canSelectMultiple && ( + onCheckboxPress?.(memberItem as unknown as TItem)} + isChecked={memberItem.isSelected} + disabled={!!isDisabled || memberItem.isDisabledCheckbox} + accessibilityLabel={memberItem.text ?? ''} + /> + )} + + + + + + + + + + + + + Total s77rt + {shouldShowAction && Action s77rt} + + + + + + ); +} + +MemberListItemHeader.displayName = 'MemberListItemHeader'; + +export default MemberListItemHeader; diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index cce8c57f7388..64d69a5af3b6 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -3,7 +3,14 @@ import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import BaseListItem from '@components/SelectionList/BaseListItem'; -import type {ListItem, TransactionGroupListItemProps, TransactionGroupListItemType, TransactionListItemType, TransactionReportGroupListItemType} from '@components/SelectionList/types'; +import type { + ListItem, + TransactionGroupListItemProps, + TransactionGroupListItemType, + TransactionListItemType, + TransactionMemberGroupListItemType, + TransactionReportGroupListItemType, +} from '@components/SelectionList/types'; import Text from '@components/Text'; import TransactionItemRow from '@components/TransactionItemRow'; import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; @@ -20,6 +27,7 @@ import {setActiveTransactionThreadIDs} from '@userActions/TransactionThreadNavig import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import MemberListItemHeader from './MemberListItemHeader'; import ReportListItemHeader from './ReportListItemHeader'; function TransactionGroupListItem({ @@ -65,7 +73,7 @@ function TransactionGroupListItem({ const listItemPressableStyle = [ styles.selectionListPressableItemWrapper, - styles.pv1half, + styles.pv2, styles.ph0, styles.overflowHidden, // Removing background style because they are added to the parent OpacityView via animatedHighlightStyle @@ -121,8 +129,12 @@ function TransactionGroupListItem({ /> ); case CONST.SEARCH.GROUP_BY.MEMBERS: - // s77rt - return null; + ; default: return null; } @@ -180,7 +192,7 @@ function TransactionGroupListItem({ openReportInRHP(transaction); }} isParentHovered={hovered} - columnWrapperStyles={[styles.ph3, styles.pv1half]} + columnWrapperStyles={[styles.ph3, styles.pv1Half]} isReportItemChild isInSingleTransactionReport={groupItem.transactions.length === 1} /> diff --git a/src/styles/utils/spacing.ts b/src/styles/utils/spacing.ts index c1bfcbac5095..c1b09191ca71 100644 --- a/src/styles/utils/spacing.ts +++ b/src/styles/utils/spacing.ts @@ -459,7 +459,7 @@ export default { paddingVertical: 4, }, - pv1half: { + pv1Half: { paddingVertical: 6, }, @@ -723,6 +723,10 @@ export default { gap: 4, }, + gapHalf: { + gap: 2, + }, + gap2: { gap: 8, }, From 8663dc8720b3227ef6819d7efe98310a5054a66d Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 21 Jun 2025 23:38:43 +0100 Subject: [PATCH 14/46] lint --- .../Search/MemberListItemHeader.tsx | 18 +++++------------- .../Search/TransactionGroupListItem.tsx | 14 ++++++++------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/components/SelectionList/Search/MemberListItemHeader.tsx b/src/components/SelectionList/Search/MemberListItemHeader.tsx index 1e5499f1d871..5815bf1da9e0 100644 --- a/src/components/SelectionList/Search/MemberListItemHeader.tsx +++ b/src/components/SelectionList/Search/MemberListItemHeader.tsx @@ -3,12 +3,8 @@ import {View} from 'react-native'; import Avatar from '@components/Avatar'; import Checkbox from '@components/Checkbox'; import type {ListItem, TransactionMemberGroupListItemType} from '@components/SelectionList/types'; -import Text from '@components/Text'; import TextWithTooltip from '@components/TextWithTooltip'; import UserDetailsTooltip from '@components/UserDetailsTooltip'; -import useResponsiveLayout from '@hooks/useResponsiveLayout'; -import useStyleUtils from '@hooks/useStyleUtils'; -import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import CONST from '@src/CONST'; @@ -28,10 +24,8 @@ type MemberListItemHeaderProps = { function MemberListItemHeader({member: memberItem, onCheckboxPress, isDisabled, canSelectMultiple}: MemberListItemHeaderProps) { const styles = useThemeStyles(); - const StyleUtils = useStyleUtils(); - const theme = useTheme(); - const {isLargeScreenWidth} = useResponsiveLayout(); - const shouldShowAction = isLargeScreenWidth; + + // s77rt add total cell and action cell return ( @@ -51,25 +45,23 @@ function MemberListItemHeader({member: memberItem, onChe - Total s77rt - {shouldShowAction && Action s77rt} diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index 64d69a5af3b6..1c9023215d08 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -129,12 +129,14 @@ function TransactionGroupListItem({ /> ); case CONST.SEARCH.GROUP_BY.MEMBERS: - ; + return ( + + ); default: return null; } From b23016a7ee10b37ee0552e2ac01df1073ab08fda Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sun, 22 Jun 2025 09:49:19 +0100 Subject: [PATCH 15/46] better type-safe headers --- .../Search/TransactionGroupListItem.tsx | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index 1c9023215d08..4f0050decea2 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -2,6 +2,7 @@ import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import {SearchGroupBy} from '@components/Search/types'; import BaseListItem from '@components/SelectionList/BaseListItem'; import type { ListItem, @@ -112,37 +113,36 @@ function TransactionGroupListItem({ COLUMNS.ACTION, ] satisfies Array>; - const getHeader = useCallback( - (isHovered: boolean) => { - switch (groupBy) { - case CONST.SEARCH.GROUP_BY.REPORTS: - return ( - - ); - case CONST.SEARCH.GROUP_BY.MEMBERS: - return ( - - ); - default: - return null; - } - }, - [groupBy, groupItem, canSelectMultiple, isDisabledOrEmpty, isFocused, onCheckboxPress, onSelectRow, policy], - ); + const getHeader = (isHovered: boolean) => { + const headers: Record = { + [CONST.SEARCH.GROUP_BY.REPORTS]: ( + + ), + [CONST.SEARCH.GROUP_BY.MEMBERS]: ( + + ), + }; + + if (!groupBy) { + return null; + } + + return headers[groupBy]; + }; return ( Date: Sun, 22 Jun 2025 09:50:15 +0100 Subject: [PATCH 16/46] lint --- .../SelectionList/Search/TransactionGroupListItem.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index 4f0050decea2..f5bcd66c3e4e 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -1,8 +1,8 @@ -import React, {useCallback, useMemo} from 'react'; +import React, {useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; -import {SearchGroupBy} from '@components/Search/types'; +import type {SearchGroupBy} from '@components/Search/types'; import BaseListItem from '@components/SelectionList/BaseListItem'; import type { ListItem, From c753b3a9f9b808850a23a9ce109cae471dcf8762 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sun, 22 Jun 2025 19:28:45 +0100 Subject: [PATCH 17/46] implemented SearchDatePresetFilterBase (most of it) --- src/CONST/index.ts | 5 +- .../Search/SearchDatePresetFilterBase.tsx | 187 ++++++++++++++++++ src/components/Search/types.ts | 2 + src/languages/en.ts | 6 +- src/libs/SearchQueryUtils.ts | 2 +- src/libs/SearchUIUtils.ts | 9 +- src/pages/Search/AdvancedSearchFilters.tsx | 4 +- .../CalendarView.tsx | 2 +- .../SearchFiltersExportedPage/RootView.tsx | 6 +- .../SearchFiltersExportedPage/index.tsx | 4 +- .../SearchFiltersPostedPage.tsx | 4 +- 11 files changed, 216 insertions(+), 15 deletions(-) create mode 100644 src/components/Search/SearchDatePresetFilterBase.tsx diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 407fc686462e..8232b10ac0dc 100755 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -6540,7 +6540,6 @@ const CONST = { }, SEARCH: { - NEVER: 'never', RESULTS_PAGE_SIZE: 50, DATA_TYPES: { EXPENSE: 'expense', @@ -6736,6 +6735,10 @@ const CONST = { AFTER: 'After', ON: 'On', }, + DATE_PRESETS: { + NEVER: 'never', + LAST_MONTH: 'last-month', + }, SNAPSHOT_ONYX_KEYS: [ ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.POLICY, diff --git a/src/components/Search/SearchDatePresetFilterBase.tsx b/src/components/Search/SearchDatePresetFilterBase.tsx new file mode 100644 index 000000000000..100cb8ca9f40 --- /dev/null +++ b/src/components/Search/SearchDatePresetFilterBase.tsx @@ -0,0 +1,187 @@ +import {format} from 'date-fns'; +import React, {useCallback, useMemo, useState} from 'react'; +import {useOnyx} from 'react-native-onyx'; +import Button from '@components/Button'; +import DatePicker from '@components/DatePicker'; +import CalendarPicker from '@components/DatePicker/CalendarPicker'; +import FormProvider from '@components/Form/FormProvider'; +import InputWrapper from '@components/Form/InputWrapper'; +import type {FormOnyxValues} from '@components/Form/types'; +import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; +import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import MenuItem from '@components/MenuItem'; +import ScreenWrapper from '@components/ScreenWrapper'; +import ScrollView from '@components/ScrollView'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import {updateAdvancedFilters} from '@libs/actions/Search'; +import Navigation from '@libs/Navigation/Navigation'; +import {isSearchDatePreset} from '@libs/SearchUIUtils'; +import type {SearchDateModifier, SearchDateModifierLower} from '@libs/SearchUIUtils'; +import CONST from '@src/CONST'; +import type {TranslationPaths} from '@src/languages/types'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; +import type {SearchDateFilterKeys} from './types'; + +type SearchDatePresetFilterBaseProps = { + /** Key used for the date filter */ + dateKey: SearchDateFilterKeys; + + /** The translation key for the page title */ + titleKey: TranslationPaths; + + // s77rt add presets prop +}; + +function SearchDatePresetFilterBase({dateKey, titleKey}: SearchDatePresetFilterBaseProps) { + const styles = useThemeStyles(); + const {translate} = useLocalize(); + const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true}); + const [selectedDateModifier, setSelectedDateModifier] = useState(null); + + const [dateValues, setDateValues] = useState>(() => ({ + [CONST.SEARCH.DATE_MODIFIERS.ON]: searchAdvancedFiltersForm?.[`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.ON}`], + [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: searchAdvancedFiltersForm?.[`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.BEFORE}`], + [CONST.SEARCH.DATE_MODIFIERS.AFTER]: searchAdvancedFiltersForm?.[`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.AFTER}`], + })); + + const setDateValue = useCallback((dateModifier: SearchDateModifier, value: string | undefined) => { + setDateValues((prevDateValues) => { + // s77rt + return {...prevDateValues, [dateModifier]: value}; + }); + }, []); + + const dateDisplayValues = useMemo>(() => { + const dateOn = dateValues[CONST.SEARCH.DATE_MODIFIERS.ON]; + const dateBefore = dateValues[CONST.SEARCH.DATE_MODIFIERS.BEFORE]; + const dateAfter = dateValues[CONST.SEARCH.DATE_MODIFIERS.AFTER]; + + return { + // dateOn could be a preset e.g. Last month which should not be displayed as the On field + [CONST.SEARCH.DATE_MODIFIERS.ON]: dateOn && !isSearchDatePreset(dateOn) ? dateOn : undefined, + [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: dateBefore, + [CONST.SEARCH.DATE_MODIFIERS.AFTER]: dateAfter, + }; + }, [dateValues]); + + const getInitialEphemeralDateValue = useCallback((dateModifier: SearchDateModifier | null) => (dateModifier ? dateDisplayValues[dateModifier] : undefined), [dateDisplayValues]); + const [ephemeralDateValue, setEphemeralDateValue] = useState(() => getInitialEphemeralDateValue(selectedDateModifier)); + + const chooseDateModifier = useCallback( + (dateModifier: SearchDateModifier) => { + setSelectedDateModifier(dateModifier); + setEphemeralDateValue(getInitialEphemeralDateValue(dateModifier)); + }, + [getInitialEphemeralDateValue], + ); + + const goBack = useCallback(() => { + if (!selectedDateModifier) { + Navigation.goBack(ROUTES.SEARCH_ADVANCED_FILTERS); + return; + } + + setSelectedDateModifier(null); + setEphemeralDateValue(getInitialEphemeralDateValue(null)); + }, [selectedDateModifier, getInitialEphemeralDateValue]); + + const reset = useCallback(() => { + if (!selectedDateModifier) { + setDateValues({[CONST.SEARCH.DATE_MODIFIERS.ON]: undefined, [CONST.SEARCH.DATE_MODIFIERS.BEFORE]: undefined, [CONST.SEARCH.DATE_MODIFIERS.AFTER]: undefined}); + return; + } + + setDateValue(selectedDateModifier, undefined); + goBack(); + }, [selectedDateModifier, setDateValue, goBack]); + + const save = useCallback(() => { + if (!selectedDateModifier) { + updateAdvancedFilters({ + [`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.ON}`]: dateValues[CONST.SEARCH.DATE_MODIFIERS.ON] ?? null, + [`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.BEFORE}`]: dateValues[CONST.SEARCH.DATE_MODIFIERS.BEFORE] ?? null, + [`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.AFTER}`]: dateValues[CONST.SEARCH.DATE_MODIFIERS.AFTER] ?? null, + }); + goBack(); + return; + } + + setDateValue(selectedDateModifier, ephemeralDateValue); + goBack(); + }, [selectedDateModifier, setDateValue, goBack, ephemeralDateValue, dateKey, dateValues]); + + const title = useMemo(() => { + if (!selectedDateModifier) { + return translate(titleKey); + } + + return translate(`common.${selectedDateModifier.toLowerCase() as SearchDateModifierLower}`); + }, [selectedDateModifier, titleKey, translate]); + + return ( + + + + {!selectedDateModifier ? ( + <> + chooseDateModifier(CONST.SEARCH.DATE_MODIFIERS.ON)} + /> + chooseDateModifier(CONST.SEARCH.DATE_MODIFIERS.BEFORE)} + /> + chooseDateModifier(CONST.SEARCH.DATE_MODIFIERS.AFTER)} + /> + + ) : ( + + )} + +