diff --git a/config/eslint/eslint.seatbelt.tsv b/config/eslint/eslint.seatbelt.tsv index 57557c64e0ce..2fec366097e9 100644 --- a/config/eslint/eslint.seatbelt.tsv +++ b/config/eslint/eslint.seatbelt.tsv @@ -378,6 +378,8 @@ "../../src/components/Search/SearchList/ListItem/ExpenseReportListItem.tsx" "@typescript-eslint/no-unsafe-type-assertion" 5 "../../src/components/Search/SearchList/ListItem/ExpenseReportListItemRow/ExpenseReportListItemRowWide.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchList/ListItem/MemberListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 +"../../src/components/Search/SearchList/ListItem/GroupChildrenContent.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4 +"../../src/components/Search/SearchList/ListItem/GroupHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 "../../src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4 "../../src/components/Search/SearchList/ListItem/TaskListItem.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 diff --git a/src/components/Search/SearchList/BaseSearchList/index.native.tsx b/src/components/Search/SearchList/BaseSearchList/index.native.tsx index ad5d017c708f..a6955e67be8b 100644 --- a/src/components/Search/SearchList/BaseSearchList/index.native.tsx +++ b/src/components/Search/SearchList/BaseSearchList/index.native.tsx @@ -18,6 +18,8 @@ function BaseSearchList({ onViewableItemsChanged, onLayout, contentContainerStyle, + stickyHeaderIndices, + getItemType, }: BaseSearchListProps) { const renderItemWithoutKeyboardFocus = useCallback( ({item, index}: {item: SearchListItem; index: number}) => { @@ -43,6 +45,8 @@ function BaseSearchList({ drawDistance={250} contentContainerStyle={contentContainerStyle} maintainVisibleContentPosition={{disabled: true}} + stickyHeaderIndices={stickyHeaderIndices} + getItemType={getItemType} /> ); } diff --git a/src/components/Search/SearchList/BaseSearchList/index.tsx b/src/components/Search/SearchList/BaseSearchList/index.tsx index cf25b14b1f8b..88c05b5ea273 100644 --- a/src/components/Search/SearchList/BaseSearchList/index.tsx +++ b/src/components/Search/SearchList/BaseSearchList/index.tsx @@ -62,6 +62,8 @@ function BaseSearchList({ selectedTransactions, isAttendeesEnabledForMovingPolicy, nonPersonalAndWorkspaceCards, + stickyHeaderIndices, + getItemType, }: BaseSearchListProps) { const hasKeyBeenPressed = useRef(false); const isFocused = useIsFocused(); @@ -183,6 +185,8 @@ function BaseSearchList({ drawDistance={250} contentContainerStyle={contentContainerStyle} maintainVisibleContentPosition={{disabled: true}} + stickyHeaderIndices={stickyHeaderIndices} + getItemType={getItemType} /> ); } diff --git a/src/components/Search/SearchList/BaseSearchList/types.ts b/src/components/Search/SearchList/BaseSearchList/types.ts index 63f60b5da280..f923f8cb736b 100644 --- a/src/components/Search/SearchList/BaseSearchList/types.ts +++ b/src/components/Search/SearchList/BaseSearchList/types.ts @@ -17,6 +17,7 @@ type BaseSearchListProps = Pick< | 'keyExtractor' | 'showsVerticalScrollIndicator' | 'onLayout' + | 'stickyHeaderIndices' > & { /** The data to display in the list */ data: SearchListItem[]; @@ -50,6 +51,9 @@ type BaseSearchListProps = Pick< /** Non-personal and workspace cards for triggering re-render via extraData */ nonPersonalAndWorkspaceCards?: CardList; + + /** Function to determine item type for FlashList recycling */ + getItemType?: (item: SearchListItem, index: number) => string | number | undefined; }; export default BaseSearchListProps; diff --git a/src/components/Search/SearchList/ListItem/GroupChildrenContainer.tsx b/src/components/Search/SearchList/ListItem/GroupChildrenContainer.tsx new file mode 100644 index 000000000000..63fa8911d25a --- /dev/null +++ b/src/components/Search/SearchList/ListItem/GroupChildrenContainer.tsx @@ -0,0 +1,72 @@ +import React from 'react'; +import {View} from 'react-native'; +import Animated from 'react-native-reanimated'; +import useExpandCollapseAnimation from '@hooks/useExpandCollapseAnimation'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; +import GroupChildrenContent from './GroupChildrenContent'; +import type {GroupChildrenContentProps} from './types'; + +type GroupChildrenContainerProps = GroupChildrenContentProps & { + isLastItem?: boolean; + isSelected?: boolean; +}; + +function GroupChildrenContainer({ + item, + isExpanded, + groupBy, + searchType, + columns, + canSelectMultiple, + onSelectRow, + onCheckboxPress, + onLongPressRow, + nonPersonalAndWorkspaceCards, + onUndelete, + isLastItem, + isSelected, + newTransactionID, + bankAccountList, + cardFeeds, + conciergeReportID, +}: GroupChildrenContainerProps) { + const theme = useTheme(); + const styles = useThemeStyles(); + const {isRendered, animatedStyle, onLayout} = useExpandCollapseAnimation(isExpanded); + + if (!isExpanded && !isRendered) { + return null; + } + + return ( + + + + + + + + ); +} + +export default GroupChildrenContainer; diff --git a/src/components/Search/SearchList/ListItem/GroupChildrenContent.tsx b/src/components/Search/SearchList/ListItem/GroupChildrenContent.tsx new file mode 100644 index 000000000000..6f876082cd80 --- /dev/null +++ b/src/components/Search/SearchList/ListItem/GroupChildrenContent.tsx @@ -0,0 +1,227 @@ +import {useIsFocused} from '@react-navigation/native'; +import React, {useEffect, useMemo, useState} from 'react'; +import {useSearchSelectionContext} from '@components/Search/SearchContext'; +import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useLocalize from '@hooks/useLocalize'; +import useNetwork from '@hooks/useNetwork'; +import useOnyx from '@hooks/useOnyx'; +import {search} from '@libs/actions/Search'; +import {getSections} from '@libs/SearchUIUtils'; +import {mergeProhibitedViolations, shouldShowViolation} from '@libs/TransactionUtils'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx'; +import TransactionGroupListExpandedItem from './TransactionGroupListExpanded'; +import type {GroupChildrenContentProps, TransactionListItemType} from './types'; + +function GroupChildrenContent({ + item, + isExpanded, + groupBy, + searchType, + columns, + canSelectMultiple, + onSelectRow, + onCheckboxPress, + onLongPressRow, + nonPersonalAndWorkspaceCards, + onUndelete, + newTransactionID, + bankAccountList, + cardFeeds, + conciergeReportID, +}: GroupChildrenContentProps) { + const {translate, formatPhoneNumber} = useLocalize(); + const {selectedTransactions} = useSearchSelectionContext(); + const currentUserDetails = useCurrentUserPersonalDetails(); + const isScreenFocused = useIsFocused(); + const {convertToDisplayString} = useCurrencyListActions(); + const {isOffline} = useNetwork(); + + const groupItem = item; + const isExpenseReportType = searchType === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT; + + const [transactionsSnapshot] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${groupItem.transactionsQueryJSON?.hash}`); + const [transactionsVisibleLimit, setTransactionsVisibleLimit] = useState(CONST.TRANSACTION.RESULTS_PAGE_SIZE); + const isActionLoadingSet = useActionLoadingReportIDs(); + const snapshotData = transactionsSnapshot?.data; + + const selectedTransactionIDsSet = useMemo(() => new Set(Object.keys(selectedTransactions)), [selectedTransactions]); + + const transactions: TransactionListItemType[] = useMemo(() => { + if (isExpenseReportType) { + return groupItem.transactions; + } + if (!snapshotData) { + return []; + } + const [sectionData] = getSections({ + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + data: snapshotData, + currentAccountID: currentUserDetails.accountID, + currentUserEmail: currentUserDetails.email ?? '', + translate, + formatPhoneNumber, + bankAccountList, + isActionLoadingSet, + cardFeeds, + conciergeReportID, + convertToDisplayString, + }) as [TransactionListItemType[], number, boolean]; + return sectionData.map((transactionItem) => ({ + ...transactionItem, + isSelected: selectedTransactionIDsSet.has(transactionItem.transactionID), + })); + }, [ + isExpenseReportType, + groupItem.transactions, + snapshotData, + currentUserDetails.accountID, + currentUserDetails.email, + translate, + formatPhoneNumber, + bankAccountList, + isActionLoadingSet, + cardFeeds, + conciergeReportID, + convertToDisplayString, + selectedTransactionIDsSet, + ]); + + const isEmpty = transactions.length === 0; + const shouldDisplayEmptyView = isEmpty && isExpenseReportType; + + const refreshTransactions = () => { + if (!groupItem.transactionsQueryJSON) { + return; + } + search({ + queryJSON: groupItem.transactionsQueryJSON, + searchKey: undefined, + offset: 0, + shouldCalculateTotals: false, + isLoading: !!transactionsSnapshot?.search?.isLoading, + isOffline, + }); + }; + + const searchTransactions = (pageSize = 0) => { + if (!groupItem.transactionsQueryJSON) { + return; + } + search({ + queryJSON: groupItem.transactionsQueryJSON, + searchKey: undefined, + offset: (transactionsSnapshot?.search?.offset ?? 0) + pageSize, + shouldCalculateTotals: false, + isLoading: !!transactionsSnapshot?.search?.isLoading, + isOffline, + }); + }; + + useEffect(() => { + if (!newTransactionID || !isExpanded) { + return; + } + refreshTransactions(); + // Only refresh when a new transaction is created in this group — refreshTransactions is excluded to avoid infinite loops + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [newTransactionID, isExpanded]); + + useEffect(() => { + if (!isExpanded || isExpenseReportType) { + return; + } + refreshTransactions(); + // Only fetch on expand — refreshTransactions and isExpenseReportType are excluded to prevent re-fetching on every render + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isExpanded]); + + const wasScreenFocusedRef = React.useRef(isScreenFocused); + useEffect(() => { + const didReturnToScreen = wasScreenFocusedRef.current === false && isScreenFocused === true; + wasScreenFocusedRef.current = isScreenFocused; + if (!didReturnToScreen || !isExpanded || isExpenseReportType) { + return; + } + refreshTransactions(); + // Only refresh when returning to this screen while expanded — other deps excluded to avoid redundant fetches + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isScreenFocused]); + + const filteredViolations: Record = useMemo(() => { + if (!snapshotData) { + return {}; + } + + const groupViolations: Record = {}; + for (const [key, value] of Object.entries(snapshotData)) { + if (key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS)) { + groupViolations[key] = value as TransactionViolations; + } + } + + const result: Record = {}; + for (const key of Object.keys(snapshotData)) { + if (!key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) { + continue; + } + const snapshotTransaction = snapshotData[key as keyof typeof snapshotData] as Transaction; + if (!snapshotTransaction || typeof snapshotTransaction !== 'object' || !('transactionID' in snapshotTransaction) || !('reportID' in snapshotTransaction)) { + continue; + } + + const report = snapshotData[`${ONYXKEYS.COLLECTION.REPORT}${snapshotTransaction.reportID}`]; + const policy = snapshotData[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; + + if (report && policy) { + const transactionViolations = groupViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${snapshotTransaction.transactionID}`]; + if (transactionViolations) { + const merged = mergeProhibitedViolations( + transactionViolations.filter((violation) => shouldShowViolation(report, policy, violation.name, currentUserDetails?.email ?? '', true, snapshotTransaction)), + ); + if (merged.length > 0) { + result[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${snapshotTransaction.transactionID}`] = merged; + } + } + } + } + return result; + }, [snapshotData, currentUserDetails.email]); + + const onExpandedRowLongPress = (transaction: TransactionListItemType) => { + onLongPressRow?.(transaction); + }; + + return ( + + ); +} + +export default GroupChildrenContent; diff --git a/src/components/Search/SearchList/ListItem/GroupHeader.tsx b/src/components/Search/SearchList/ListItem/GroupHeader.tsx new file mode 100644 index 000000000000..42afe29f4666 --- /dev/null +++ b/src/components/Search/SearchList/ListItem/GroupHeader.tsx @@ -0,0 +1,479 @@ +import React, {useMemo, useRef} from 'react'; +import {View} from 'react-native'; +import type {NativeSyntheticEvent} from 'react-native'; +import type {OnyxEntry} from 'react-native-onyx'; +// eslint-disable-next-line no-restricted-imports +import {useOnyx as originalUseOnyx} from 'react-native-onyx'; +import Animated from 'react-native-reanimated'; +import {getButtonRole} from '@components/Button/utils'; +import Icon from '@components/Icon'; +import OfflineWithFeedback from '@components/OfflineWithFeedback'; +import {PressableWithFeedback} from '@components/Pressable'; +import {useSearchSelectionContext} from '@components/Search/SearchContext'; +import SearchTableHeader from '@components/Search/SearchTableHeader'; +import type {SearchColumnType, SearchCustomColumnIds, SearchGroupBy} from '@components/Search/types'; +import type {ExtendedTargetedEvent} from '@components/SelectionList/ListItem/types'; +import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useExpandCollapseAnimation from '@hooks/useExpandCollapseAnimation'; +import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; +import useOnyx from '@hooks/useOnyx'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useSyncFocus from '@hooks/useSyncFocus'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; +import type {TransactionPreviewData} from '@libs/actions/Search'; +import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; +import type {ModifiedMouseEvent} from '@libs/Navigation/helpers/openInternalRouteInNewTab'; +import {getColumnsToShow} from '@libs/SearchUIUtils'; +import {isDeletedTransaction} from '@libs/TransactionUtils'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {ReportAction, ReportActions, Transaction} from '@src/types/onyx'; +import type {SearchDataTypes} from '@src/types/onyx/SearchResults'; +import CardListItemHeader from './CardListItemHeader'; +import CategoryListItemHeader from './CategoryListItemHeader'; +import MemberListItemHeader from './MemberListItemHeader'; +import MerchantListItemHeader from './MerchantListItemHeader'; +import MonthListItemHeader from './MonthListItemHeader'; +import QuarterListItemHeader from './QuarterListItemHeader'; +import ReportListItemHeader from './ReportListItemHeader'; +import TagListItemHeader from './TagListItemHeader'; +import type {GroupHeaderItemType, SearchListActionProps, SearchListItem, TransactionListItemType} from './types'; +import WeekListItemHeader from './WeekListItemHeader'; +import WithdrawalIDListItemHeader from './WithdrawalIDListItemHeader'; +import YearListItemHeader from './YearListItemHeader'; + +type GroupHeaderProps = SearchListActionProps & { + item: GroupHeaderItemType; + groupBy?: SearchGroupBy; + searchType?: SearchDataTypes; + columns?: SearchColumnType[]; + canSelectMultiple: boolean; + isExpanded: boolean; + onToggle: () => void; + onSelectRow: (item: SearchListItem, transactionPreviewData?: TransactionPreviewData, event?: ModifiedMouseEvent) => void; + onCheckboxPress: (item: GroupHeaderItemType, itemTransactions?: TransactionListItemType[]) => void; + onLongPressRow?: (item: SearchListItem, itemTransactions?: TransactionListItemType[]) => void; + onFocus?: (event: NativeSyntheticEvent) => void; + shouldSyncFocus?: boolean; + isFocused?: boolean; + isFirstItem: boolean; + isLastItem: boolean; + originalKey: string; + visibleColumns?: SearchCustomColumnIds[]; +}; + +function GroupHeader({ + item, + groupBy, + searchType, + columns, + canSelectMultiple, + isExpanded, + onToggle, + onSelectRow, + onCheckboxPress, + onLongPressRow, + onFocus, + shouldSyncFocus, + isFocused, + isFirstItem, + isLastItem, + originalKey, + lastPaymentMethod, + personalPolicyID, + userBillingGracePeriodEnds, + ownerBillingGracePeriodEnd, + visibleColumns, +}: GroupHeaderProps) { + const theme = useTheme(); + const styles = useThemeStyles(); + const StyleUtils = useStyleUtils(); + const {isLargeScreenWidth} = useResponsiveLayout(); + const {selectedTransactions} = useSearchSelectionContext(); + const expensifyIcons = useMemoizedLazyExpensifyIcons(['UpArrow', 'DownArrow']); + const currentUserDetails = useCurrentUserPersonalDetails(); + + const groupItem = item; + const isExpenseReportType = searchType === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT; + + const oneTransactionItem = groupItem.isOneTransactionReport ? groupItem.transactions.at(0) : undefined; + const oneTransactionReportID = getNonEmptyStringOnyxID(oneTransactionItem?.reportID); + const oneTransactionID = getNonEmptyStringOnyxID(oneTransactionItem?.transactionID); + const oneTransactionChildReportID = oneTransactionItem?.reportAction?.childReportID; + const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionReportID}`); + const [oneTransactionThreadReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionChildReportID}`); + const [oneTransaction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${oneTransactionID}`); + const parentReportActionSelector = (reportActions: OnyxEntry): OnyxEntry => reportActions?.[`${oneTransactionItem?.reportAction?.reportActionID}`]; + const [parentReportAction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${oneTransactionReportID}`, {selector: parentReportActionSelector}, [oneTransactionItem]); + const transactionPreviewData: TransactionPreviewData = useMemo( + () => ({ + hasParentReport: !!parentReport, + hasTransaction: !!oneTransaction, + hasParentReportAction: !!parentReportAction, + hasTransactionThreadReport: !!oneTransactionThreadReport, + }), + [parentReport, oneTransaction, parentReportAction, oneTransactionThreadReport], + ); + + const [transactionsSnapshot] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${groupItem.transactionsQueryJSON?.hash}`); + const snapshotData = transactionsSnapshot?.data; + const snapshotSearchType = transactionsSnapshot?.search.type; + + const subHeaderColumns = useMemo(() => { + if (isExpenseReportType) { + return columns ?? []; + } + if (!snapshotData) { + return []; + } + return getColumnsToShow({ + currentAccountID: currentUserDetails.accountID, + data: snapshotData, + visibleColumns, + type: snapshotSearchType, + }); + }, [isExpenseReportType, columns, snapshotData, snapshotSearchType, currentUserDetails.accountID, visibleColumns]); + + const {isSubHeaderAmountColumnWide, isSubHeaderTaxAmountColumnWide, shouldSubHeaderShowYear, isSubHeaderActionColumnWide} = useMemo(() => { + let amountWide = false; + let taxWide = false; + let showYear = false; + let actionWide = false; + for (const transaction of groupItem.transactions) { + if (transaction.isAmountColumnWide) { + amountWide = true; + } + if (transaction.isTaxAmountColumnWide) { + taxWide = true; + } + if (transaction.shouldShowYear) { + showYear = true; + } + if (transaction.isActionColumnWide || isDeletedTransaction(transaction)) { + actionWide = true; + } + if (amountWide && taxWide && showYear && actionWide) { + break; + } + } + return {isSubHeaderAmountColumnWide: amountWide, isSubHeaderTaxAmountColumnWide: taxWide, shouldSubHeaderShowYear: showYear, isSubHeaderActionColumnWide: actionWide}; + }, [groupItem.transactions]); + + const {isRendered: isSubHeaderRendered, animatedStyle: subHeaderAnimatedStyle, onLayout: onSubHeaderLayout} = useExpandCollapseAnimation(isExpanded); + + const hasSnapshotTransactions = !isExpenseReportType && !!snapshotData && Object.keys(snapshotData).some((key) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)); + const isEmpty = groupItem.transactions.length === 0 && !hasSnapshotTransactions; + const isDisabled = item.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + const isDisabledOrEmpty = isEmpty || isDisabled; + + const effectiveTransactions = useMemo((): TransactionListItemType[] => { + if (isExpenseReportType || groupItem.transactions.length > 0) { + return groupItem.transactions; + } + if (!snapshotData) { + return []; + } + const items: TransactionListItemType[] = []; + for (const key of Object.keys(snapshotData)) { + if (!key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) { + continue; + } + const transaction = snapshotData[key as keyof typeof snapshotData] as Transaction; + if (!transaction?.transactionID) { + continue; + } + const report = snapshotData[`${ONYXKEYS.COLLECTION.REPORT}${transaction.reportID}`]; + items.push({ + ...transaction, + keyForList: transaction.transactionID, + report, + } as TransactionListItemType); + } + return items; + }, [isExpenseReportType, groupItem.transactions, snapshotData]); + + const {isSelectAllChecked, isIndeterminate} = useMemo(() => { + const selectedTransactionIDsSet = new Set(Object.keys(selectedTransactions)); + const filteredTransactions = effectiveTransactions.filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); + const selectedCount = filteredTransactions.reduce((acc, transaction) => (selectedTransactionIDsSet.has(transaction.transactionID) ? acc + 1 : acc), 0); + const isEmptyReportSelected = isEmpty && originalKey && selectedTransactions[originalKey]?.isSelected; + const allChecked = !!isEmptyReportSelected || (selectedCount === filteredTransactions.length && filteredTransactions.length > 0); + const indeterminate = selectedCount > 0 && selectedCount !== filteredTransactions.length; + return {isSelectAllChecked: allChecked, isIndeterminate: indeterminate}; + }, [selectedTransactions, effectiveTransactions, isEmpty, originalKey]); + + const isItemSelected = isSelectAllChecked || item?.isSelected; + + const animatedHighlightStyle = useAnimatedHighlightStyle({ + shouldHighlight: item?.shouldAnimateInHighlight ?? false, + highlightColor: theme.messageHighlightBG, + backgroundColor: isItemSelected ? theme.activeComponentBG : theme.highlightBG, + shouldApplyOtherStyles: false, + }); + + const handleSelectionButtonPress = () => { + onCheckboxPress(item, isExpenseReportType ? undefined : effectiveTransactions); + }; + + const pendingAction = + item.pendingAction ?? + (groupItem.transactions.length > 0 && groupItem.transactions.every((transaction) => transaction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) + ? CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE + : undefined); + + const handleSelectRow = (rowItem: SearchListItem, event?: ModifiedMouseEvent) => { + onSelectRow(rowItem, transactionPreviewData, event); + }; + + const renderHeader = (hovered: boolean) => { + if (isExpenseReportType && 'groupedBy' in groupItem && groupItem.groupedBy === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) { + return ( + + ); + } + + if (!('groupedBy' in groupItem)) { + return null; + } + + const commonProps = { + onCheckboxPress: handleSelectionButtonPress, + isDisabled: isDisabledOrEmpty, + columns, + canSelectMultiple, + isSelectAllChecked, + isIndeterminate, + onDownArrowClick: onToggle, + isExpanded, + } as const; + + switch (groupItem.groupedBy) { + case CONST.SEARCH.GROUP_BY.FROM: + return ( + + ); + case CONST.SEARCH.GROUP_BY.CARD: + return ( + + ); + case CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID: + return ( + + ); + case CONST.SEARCH.GROUP_BY.CATEGORY: + return ( + + ); + case CONST.SEARCH.GROUP_BY.MERCHANT: + return ( + + ); + case CONST.SEARCH.GROUP_BY.TAG: + return ( + + ); + case CONST.SEARCH.GROUP_BY.MONTH: + return ( + + ); + case CONST.SEARCH.GROUP_BY.WEEK: + return ( + + ); + case CONST.SEARCH.GROUP_BY.YEAR: + return ( + + ); + case CONST.SEARCH.GROUP_BY.QUARTER: + return ( + + ); + default: + return null; + } + }; + + const isLastItemCollapsed = isLastItem && !isExpanded && !isSubHeaderRendered; + const pressableRef = useRef(null); + + useSyncFocus(pressableRef, !!isFocused, shouldSyncFocus); + + const pressableStyle = [ + styles.transactionGroupListItemStyle, + isLargeScreenWidth && { + ...styles.tableRowHeight, + borderRadius: 0, + ...(isLastItemCollapsed ? styles.tableBottomRadius : {}), + }, + isItemSelected && styles.activeComponentBG, + ]; + + const shouldDisplayEmptyView = isEmpty && isExpenseReportType; + + const handlePress = (event?: ModifiedMouseEvent) => { + if (isExpenseReportType) { + onSelectRow(item, transactionPreviewData, event); + } + if (!isExpenseReportType) { + onToggle(); + } + }; + + const handleLongPress = () => { + onLongPressRow?.(item, isExpenseReportType ? undefined : effectiveTransactions); + }; + + return ( + + e.preventDefault()} + id={item.keyForList ?? ''} + onFocus={onFocus} + style={[ + pressableStyle, + isFocused && StyleUtils.getItemBackgroundColorStyle(!!isItemSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), + ]} + wrapperStyle={[ + styles.mh5, + animatedHighlightStyle, + styles.userSelectNone, + isLargeScreenWidth + ? [StyleUtils.getSearchTableGroupRowBorderStyle(isFirstItem, isLastItemCollapsed, isItemSelected), isLastItemCollapsed && styles.overflowHidden] + : [ + isFirstItem && [styles.tableTopRadius, styles.overflowHidden], + isLastItemCollapsed && [styles.tableBottomRadius, styles.overflowHidden], + !isLastItemCollapsed && !isExpanded && StyleUtils.getSelectedBorderBottomStyle(isItemSelected), + ], + ]} + > + {({hovered}) => ( + + + {renderHeader(hovered)} + {isLargeScreenWidth && ( + { + if (isEmpty && !shouldDisplayEmptyView) { + handlePress(); + return; + } + onToggle(); + }} + style={[styles.p3Half, styles.justifyContentCenter, styles.alignItemsCenter, styles.pv2]} + accessibilityRole={CONST.ROLE.BUTTON} + accessibilityLabel={isExpanded ? CONST.ACCESSIBILITY_LABELS.COLLAPSE : CONST.ACCESSIBILITY_LABELS.EXPAND} + sentryLabel={CONST.SENTRY_LABEL.SEARCH.GROUP_EXPAND_TOGGLE} + > + {({hovered: arrowHovered}) => ( + + )} + + )} + + {isLargeScreenWidth && subHeaderColumns.length > 0 && ( + + {(isExpanded || isSubHeaderRendered) && ( + + + + + + {}} + sortOrder={undefined} + sortBy={undefined} + shouldShowYear={shouldSubHeaderShowYear} + isAmountColumnWide={isSubHeaderAmountColumnWide} + isTaxAmountColumnWide={isSubHeaderTaxAmountColumnWide} + shouldShowSorting={false} + columns={subHeaderColumns} + groupBy={groupBy} + isExpenseReportView + isActionColumnWide={isSubHeaderActionColumnWide} + /> + + + + + + )} + + )} + + )} + + + ); +} + +export default GroupHeader; diff --git a/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx b/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx index d9e4d018dcf3..fc8050baf190 100644 --- a/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx +++ b/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx @@ -64,6 +64,7 @@ function TransactionGroupListExpanded({ onLongPress, nonPersonalAndWorkspaceCards, onUndelete, + hideSearchTableHeader, }: TransactionGroupListExpandedProps) { const theme = useTheme(); const styles = useThemeStyles(); @@ -289,7 +290,7 @@ function TransactionGroupListExpanded({ const content = ( - {isLargeScreenWidth && !(isEmpty && shouldDisplayLoadingIndicator) && ( + {isLargeScreenWidth && !hideSearchTableHeader && !(isEmpty && shouldDisplayLoadingIndicator) && ( <> ({ const isSelectAllChecked = isEmptyReportSelected || (selectedItemsLength === transactionsWithoutPendingDelete.length && transactionsWithoutPendingDelete.length > 0); const isIndeterminate = selectedItemsLength > 0 && selectedItemsLength !== transactionsWithoutPendingDelete.length; + // Currently only the transaction report groups have transactions where the empty view makes sense const shouldDisplayEmptyView = isEmpty && isExpenseReportType; + const isDisabledOrEmpty = isEmpty || isDisabled; const refreshTransactions = () => { if (!groupItem.transactionsQueryJSON) { @@ -290,7 +292,7 @@ function TransactionGroupListItem({ }; const onPress = (event?: ModifiedMouseEvent) => { - if (isExpenseReportType) { + if (isExpenseReportType || transactions.length === 0) { onSelectRow(item, transactionPreviewData, event); } if (!isExpenseReportType) { @@ -325,7 +327,7 @@ function TransactionGroupListItem({ ({ ({ ({ ({ ({ ({ ({ ({ ({ = Pick< isInSingleTransactionReport: boolean; searchTransactions: (pageSize?: number) => void; onLongPress: (transaction: TransactionListItemType) => void; + hideSearchTableHeader?: boolean; +}; + +const GROUP_ITEM_TYPES = { + GROUP_HEADER: 'group_header', + CHILDREN_CONTAINER: 'children_container', +} as const; + +type GroupHeaderListItemType = {listItemType: typeof GROUP_ITEM_TYPES.GROUP_HEADER}; + +type GroupHeaderItemType = + | (TransactionReportGroupListItemType & GroupHeaderListItemType) + | (TransactionMemberGroupListItemType & GroupHeaderListItemType) + | (TransactionCardGroupListItemType & GroupHeaderListItemType) + | (TransactionWithdrawalIDGroupListItemType & GroupHeaderListItemType) + | (TransactionCategoryGroupListItemType & GroupHeaderListItemType) + | (TransactionMerchantGroupListItemType & GroupHeaderListItemType) + | (TransactionTagGroupListItemType & GroupHeaderListItemType) + | (TransactionMonthGroupListItemType & GroupHeaderListItemType) + | (TransactionWeekGroupListItemType & GroupHeaderListItemType) + | (TransactionYearGroupListItemType & GroupHeaderListItemType) + | (TransactionQuarterGroupListItemType & GroupHeaderListItemType) + | (TransactionGroupListItemType & GroupHeaderListItemType); + +type GroupChildrenContainerItemType = TransactionGroupListItemType & { + listItemType: typeof GROUP_ITEM_TYPES.CHILDREN_CONTAINER; +}; + +function isGroupHeaderItem(item: SearchListItem): item is GroupHeaderItemType { + return 'listItemType' in item && item.listItemType === GROUP_ITEM_TYPES.GROUP_HEADER; +} + +function isGroupChildrenContainerItem(item: SearchListItem): item is GroupChildrenContainerItemType { + return 'listItemType' in item && item.listItemType === GROUP_ITEM_TYPES.CHILDREN_CONTAINER; +} + +type GroupChildrenContentProps = { + item: GroupChildrenContainerItemType; + isExpanded: boolean; + groupBy?: SearchGroupBy; + searchType?: SearchDataTypes; + columns?: SearchColumnType[]; + canSelectMultiple: boolean; + onSelectRow: (item: SearchListItem, transactionPreviewData?: TransactionPreviewData, event?: ModifiedMouseEvent) => void; + onCheckboxPress: (item: SearchListItem, itemTransactions?: TransactionListItemType[]) => void; + onLongPressRow?: (item: SearchListItem, itemTransactions?: TransactionListItemType[]) => void; + nonPersonalAndWorkspaceCards?: CardList; + onUndelete?: (transaction: Transaction) => void; + newTransactionID?: string; + bankAccountList?: OnyxEntry; + cardFeeds?: OnyxCollection; + conciergeReportID?: string; }; type UnreportedExpenseListItemType = Transaction & { @@ -512,4 +568,9 @@ export type { TransactionListItemProps, ReportActionListItemType, UnreportedExpenseListItemType, + GroupHeaderItemType, + GroupChildrenContainerItemType, + GroupChildrenContentProps, }; + +export {GROUP_ITEM_TYPES, isGroupHeaderItem, isGroupChildrenContainerItem}; diff --git a/src/components/Search/SearchList/index.tsx b/src/components/Search/SearchList/index.tsx index 836af7e5bdcd..d3dd9cdbb75f 100644 --- a/src/components/Search/SearchList/index.tsx +++ b/src/components/Search/SearchList/index.tsx @@ -28,15 +28,18 @@ import {turnOnMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; import DateUtils from '@libs/DateUtils'; import type {ModifiedMouseEvent} from '@libs/Navigation/helpers/openInternalRouteInNewTab'; import navigationRef from '@libs/Navigation/navigationRef'; -import {getTableMinWidth} from '@libs/SearchUIUtils'; +import {getTableMinWidth, splitGroupsIntoPairs} from '@libs/SearchUIUtils'; import variables from '@styles/variables'; import type {TransactionPreviewData} from '@userActions/Search'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import {columnsSelector} from '@src/selectors/AdvancedSearchFiltersForm'; import type {CardList, Transaction} from '@src/types/onyx'; import BaseSearchList from './BaseSearchList'; import type ChatListItem from './ListItem/ChatListItem'; import type ExpenseReportListItem from './ListItem/ExpenseReportListItem'; +import GroupChildrenContainer from './ListItem/GroupChildrenContainer'; +import GroupHeader from './ListItem/GroupHeader'; import type TaskListItem from './ListItem/TaskListItem'; import type TransactionGroupListItem from './ListItem/TransactionGroupListItem'; import type TransactionListItem from './ListItem/TransactionListItem'; @@ -53,6 +56,7 @@ import type { TransactionWeekGroupListItemType, TransactionYearGroupListItemType, } from './ListItem/types'; +import {isGroupChildrenContainerItem, isGroupHeaderItem} from './ListItem/types'; import SearchSelectAllMenu from './SearchSelectAllMenu'; const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0); @@ -232,11 +236,11 @@ function SearchList({ return data; }, [data, groupBy, type]); const emptyReports = useMemo(() => { - if (isTransactionGroupListItemArray(data)) { - return data.filter((item) => item.transactions.length === 0 && item.keyForList); + if (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT && isTransactionGroupListItemArray(data)) { + return data.filter((item) => item.transactions.length === 0); } return []; - }, [data]); + }, [data, type]); const selectedItemsLength = useMemo(() => { const selectedTransactionsCount = flattenedItems.reduce((acc, item) => { @@ -244,7 +248,7 @@ function SearchList({ return acc + (isTransactionSelected ? 1 : 0); }, 0); - if (isTransactionGroupListItemArray(data)) { + if (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT && isTransactionGroupListItemArray(data)) { const selectedEmptyReports = emptyReports.reduce((acc, item) => { const isEmptyReportSelected = !!(item.keyForList && selectedTransactions[item.keyForList]?.isSelected); return acc + (isEmptyReportSelected ? 1 : 0); @@ -254,10 +258,10 @@ function SearchList({ } return selectedTransactionsCount; - }, [flattenedItems, data, emptyReports, selectedTransactions]); + }, [flattenedItems, type, data, emptyReports, selectedTransactions]); const totalItems = useMemo(() => { - if (isTransactionGroupListItemArray(data)) { + if (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT && isTransactionGroupListItemArray(data)) { const selectableEmptyReports = emptyReports.filter((item) => item.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); const selectableTransactions = flattenedItems.filter((item) => { if ('pendingAction' in item) { @@ -275,7 +279,7 @@ function SearchList({ return true; }); return selectableTransactions.length; - }, [data, flattenedItems, emptyReports]); + }, [data, type, flattenedItems, emptyReports]); const {translate} = useLocalize(); const {isOffline} = useNetwork(); @@ -294,10 +298,60 @@ function SearchList({ const hasItemsBeingRemoved = prevDataLength && prevDataLength > data.length; const {isEditingCell, wasRecentlyEditingCell} = useEditingCellState(); + const isGroupByActive = !!groupBy || type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT; + const [expandedGroups, setExpandedGroups] = useState>(() => new Set()); + + const onToggleGroup = useCallback((key: string) => { + setExpandedGroups((prev) => { + const next = new Set(prev); + if (next.has(key)) { + next.delete(key); + } else { + next.add(key); + } + return next; + }); + }, []); + + const shouldSplitGroups = isGroupByActive && isLargeScreenWidth; + + const {splitData: listData, stickyHeaderIndices} = useMemo(() => { + if (!shouldSplitGroups) { + return {splitData: data, stickyHeaderIndices: undefined}; + } + const {splitData, stickyHeaderIndices: allIndices} = splitGroupsIntoPairs(data); + const activeIndices = allIndices.filter((idx) => { + const item = splitData.at(idx); + const originalKey = item?.keyForList?.replace('header_', '') ?? ''; + return expandedGroups.has(originalKey); + }); + return {splitData, stickyHeaderIndices: activeIndices.length > 0 ? activeIndices : undefined}; + }, [data, shouldSplitGroups, expandedGroups]); + + const getItemType = useCallback( + (item: SearchListItem) => { + if (!shouldSplitGroups) { + return undefined; + } + if (isGroupHeaderItem(item)) { + return item.listItemType; + } + if (isGroupChildrenContainerItem(item)) { + return item.listItemType; + } + return 'default'; + }, + [shouldSplitGroups], + ); + const [lastPaymentMethod] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD); const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID); const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END); const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END); + const [visibleColumns] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {selector: columnsSelector}); + const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); + const [cardFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER); + const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); const undeleteTransactions = useUndeleteTransactions(); const handleUndelete = (transaction: Transaction) => undeleteTransactions([transaction]); @@ -395,16 +449,21 @@ function SearchList({ return; } - // Don't scroll while a cell is being edited - // as it can cause unwanted scrolling when the edit is dismissed - // See: https://github.com/Expensify/App/pull/83127#issuecomment-4064533155 if (isEditingCell || wasRecentlyEditingCell) { return; } - listRef.current.scrollToIndex({index, animated, viewOffset: -variables.contentHeaderHeight}); + let targetIndex = index; + if (shouldSplitGroups && item.keyForList) { + const splitIndex = listData.findIndex((li) => li.keyForList === `header_${item.keyForList}` || li.keyForList === item.keyForList); + if (splitIndex !== -1) { + targetIndex = splitIndex; + } + } + + listRef.current.scrollToIndex({index: targetIndex, animated, viewOffset: -variables.contentHeaderHeight}); }, - [data, isEditingCell, wasRecentlyEditingCell], + [data, isEditingCell, wasRecentlyEditingCell, shouldSplitGroups, listData], ); useFocusEffect( @@ -423,13 +482,81 @@ function SearchList({ useImperativeHandle(ref, () => ({scrollToIndex}), [scrollToIndex]); const isItemVisible = useCallback((item: SearchListItem) => item.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || isOffline, [isOffline]); - const firstVisibleIndex = useMemo(() => data.findIndex(isItemVisible), [data, isItemVisible]); - const lastVisibleIndex = useMemo(() => data.findLastIndex(isItemVisible), [data, isItemVisible]); + const firstVisibleIndex = useMemo(() => listData.findIndex(isItemVisible), [listData, isItemVisible]); + const lastVisibleIndex = useMemo(() => listData.findLastIndex(isItemVisible), [listData, isItemVisible]); const renderItem = useCallback( (item: SearchListItem, index: number, isItemFocused: boolean, onFocus?: (event: NativeSyntheticEvent) => void) => { + // Handle group header items (sticky) + if (isGroupHeaderItem(item)) { + const headerItem = item; + const originalKey = (item.keyForList ?? '').replace('header_', ''); + return ( + onToggleGroup(originalKey)} + onSelectRow={(rowItem, previewData, event) => onSelectRow({...rowItem, keyForList: originalKey}, previewData, event)} + onCheckboxPress={(val, itemTransactions) => onCheckboxPress({...val, keyForList: originalKey} as SearchListItem, itemTransactions)} + onLongPressRow={(rowItem, itemTransactions) => { + const fixedItem = {...rowItem, keyForList: originalKey} as SearchListItem; + if (isMobileSelectionModeEnabled) { + handleLongPressRowInMobileSelectionMode(fixedItem, itemTransactions); + } else { + handleLongPressRow(fixedItem, itemTransactions); + } + }} + onFocus={onFocus} + isFocused={isItemFocused} + isFirstItem={index === firstVisibleIndex} + isLastItem={index + 1 >= lastVisibleIndex && !ListFooterComponent} + originalKey={originalKey} + lastPaymentMethod={lastPaymentMethod} + personalPolicyID={personalPolicyID} + userBillingGracePeriodEnds={userBillingGracePeriodEnds} + ownerBillingGracePeriodEnd={ownerBillingGracePeriodEnd} + visibleColumns={visibleColumns} + /> + ); + } + + // Handle children container items (animated expand/collapse) + if (isGroupChildrenContainerItem(item)) { + const containerItem = item; + const originalKey = (item.keyForList ?? '').replace('children_', ''); + const containerNewTransactionID = item.keyForList ? newTransactionIDByItemKey.get(originalKey) : undefined; + const isContainerSelected = + !!containerItem.isSelected || (containerItem.transactions.length > 0 && containerItem.transactions.every((t) => selectedTransactions[t.transactionID]?.isSelected)); + return ( + + ); + } + + // Default rendering for non-group items const isDisabled = item.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - const shouldApplyAnimation = shouldAnimate && index < data.length - 1; + const shouldApplyAnimation = shouldAnimate && index < listData.length - 1; const newTransactionID = item.keyForList ? newTransactionIDByItemKey.get(item.keyForList) : undefined; @@ -473,7 +600,7 @@ function SearchList({ groupBy, newTransactionIDByItemKey, shouldAnimate, - data.length, + listData.length, styles.overflowHidden, hasItemsBeingRemoved, ListItem, @@ -494,6 +621,13 @@ function SearchList({ handleUndelete, firstVisibleIndex, lastVisibleIndex, + expandedGroups, + onToggleGroup, + bankAccountList, + cardFeeds, + conciergeReportID, + visibleColumns, + selectedTransactions, ], ); @@ -508,6 +642,7 @@ function SearchList({ style={[ styles.searchListHeaderContainerStyle, isLargeScreenWidth ? [styles.listTableHeaderCompact, styles.searchListHeaderTableStyle, styles.mh5] : styles.listTableHeader, + isLargeScreenWidth && shouldSplitGroups && styles.searchListHeaderTableStickyOverlap, ]} > {canSelectMultiple && ( @@ -522,10 +657,11 @@ function SearchList({ )} {SearchTableHeader} + {isLargeScreenWidth && shouldSplitGroups && } )} { + if (!contentHeight.get()) { + return 0; + } + const target = hasExpanded.get() ? contentHeight.get() : 0; + return withTiming(target, {duration: EXPAND_COLLAPSE_DURATION, easing}, (finished) => { + if (!finished || target) { + return; + } + scheduleOnRN(setIsRendered, false); + }); + }, []); + + const animatedStyle = useAnimatedStyle(() => ({ + height: animatedHeight.get(), + overflow: 'hidden', + })); + + const onLayout = (e: LayoutChangeEvent) => { + const height = e.nativeEvent.layout.height; + if (height) { + contentHeight.set(height); + } + }; + + return {isRendered, animatedStyle, onLayout}; +} + +export default useExpandCollapseAnimation; diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 4061fec21aa4..c21b00229715 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -17,6 +17,8 @@ import TransactionGroupListItem from '@components/Search/SearchList/ListItem/Tra import TransactionListItem from '@components/Search/SearchList/ListItem/TransactionListItem'; import type { ExpenseReportListItemType, + GroupChildrenContainerItemType, + GroupHeaderItemType, ReportActionListItemType, SearchListItem, TaskListItemType, @@ -34,6 +36,7 @@ import type { TransactionWithdrawalIDGroupListItemType, TransactionYearGroupListItemType, } from '@components/Search/SearchList/ListItem/types'; +import {GROUP_ITEM_TYPES} from '@components/Search/SearchList/ListItem/types'; import type { GroupedItem, QueryFilters, @@ -6208,6 +6211,24 @@ function hasFlexColumn(columns?: SearchColumnType[]): boolean { return !!columns?.some((col) => FLEX_COLUMNS.has(col)); } +function splitGroupsIntoPairs(data: SearchListItem[]): {splitData: SearchListItem[]; stickyHeaderIndices: number[]} { + const splitData: SearchListItem[] = []; + const stickyHeaderIndices: number[] = []; + + for (const item of data) { + if ('transactions' in item) { + const key = item.keyForList ?? ''; + stickyHeaderIndices.push(splitData.length); + splitData.push({...item, listItemType: GROUP_ITEM_TYPES.GROUP_HEADER, keyForList: `header_${key}`} as GroupHeaderItemType); + splitData.push({...item, listItemType: GROUP_ITEM_TYPES.CHILDREN_CONTAINER, keyForList: `children_${key}`} as GroupChildrenContainerItemType); + } else { + splitData.push(item); + } + } + + return {splitData, stickyHeaderIndices}; +} + export { getSearchBulkEditPolicyID, getSuggestedSearches, @@ -6293,6 +6314,7 @@ export { isPolicyEligibleForSpendOverTime, hasFlexColumn, isTransactionSearchType, + splitGroupsIntoPairs, SKIPPED_SEARCH_FILTERS, }; export type {SavedSearchMenuItem, SearchTypeMenuSection, SearchTypeMenuItem, SearchDateModifier, SearchDateModifierLower, SearchKey, ArchivedReportsIDSet, GroupBySection, SearchFilter}; diff --git a/src/styles/index.ts b/src/styles/index.ts index 2ca46949f522..3cee793677e4 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -3611,6 +3611,24 @@ const staticStyles = (theme: ThemeColors) => paddingBottom: 8, }, + searchListHeaderTableStickyOverlap: { + position: 'relative', + zIndex: 10, + }, + + searchListHeaderBorderCover: { + position: 'absolute', + bottom: -2, + left: 0, + right: 0, + height: 1, + backgroundColor: theme.highlightBG, + }, + + groupSubHeaderBorderOverlap: { + marginTop: -1, + }, + groupSearchListTableContainerStyle: { minHeight: variables.h28, paddingBottom: 0,