@@ -41,6 +41,7 @@ import {isSplitAction} from '@libs/ReportSecondaryActionUtils';
4141import { canEditFieldOfMoneyRequest , canHoldUnholdReportAction , canRejectReportAction , isOneTransactionReport , selectFilteredReportActions } from '@libs/ReportUtils' ;
4242import { buildCannedSearchQuery , buildSearchQueryJSON , buildSearchQueryString } from '@libs/SearchQueryUtils' ;
4343import {
44+ adjustTimeRangeToDateFilters ,
4445 createAndOpenSearchTransactionThread ,
4546 getColumnsToShow ,
4647 getListItem ,
@@ -60,6 +61,7 @@ import {
6061 isTransactionMerchantGroupListItemType ,
6162 isTransactionMonthGroupListItemType ,
6263 isTransactionTagGroupListItemType ,
64+ isTransactionWeekGroupListItemType ,
6365 isTransactionWithdrawalIDGroupListItemType ,
6466 shouldShowEmptyState ,
6567 shouldShowYear as shouldShowYearUtil ,
@@ -547,7 +549,7 @@ function Search({
547549
548550 // For expense reports: when ANY transaction is selected, we want ALL transactions in the report selected.
549551 // This ensures report-level selection persists when new transactions are added.
550- const hasAnySelected = isExpenseReportType && transactionGroup . transactions . some ( ( transaction ) => transaction . transactionID in selectedTransactions ) ;
552+ const hasAnySelected = isExpenseReportType && transactionGroup . transactions . some ( ( transaction : TransactionListItemType ) => transaction . transactionID in selectedTransactions ) ;
551553
552554 for ( const transactionItem of transactionGroup . transactions ) {
553555 const isSelected = transactionItem . transactionID in selectedTransactions ;
@@ -907,13 +909,46 @@ function Search({
907909 return ;
908910 }
909911
910- let reportID = item . reportID ;
911- if ( isTransactionItem && item ?. reportAction ?. childReportID ) {
912- const isFromSelfDM = item . reportID === CONST . REPORT . UNREPORTED_REPORT_ID ;
913- const isFromOneTransactionReport = isOneTransactionReport ( item . report ) ;
912+ if ( isTransactionWeekGroupListItemType ( item ) ) {
913+ if ( ! item . week ) {
914+ return ;
915+ }
916+ // Extract the existing date filter to check for year-to-date or other date limits
917+ const existingDateFilter = queryJSON . flatFilters . find ( ( filter ) => filter . key === CONST . SEARCH . SYNTAX_FILTER_KEYS . DATE ) ;
918+ const { start : weekStart , end : weekEnd } = adjustTimeRangeToDateFilters ( DateUtils . getWeekDateRange ( item . week ) , existingDateFilter ) ;
919+ const newFlatFilters = queryJSON . flatFilters . filter ( ( filter ) => filter . key !== CONST . SEARCH . SYNTAX_FILTER_KEYS . DATE ) ;
920+ newFlatFilters . push ( {
921+ key : CONST . SEARCH . SYNTAX_FILTER_KEYS . DATE ,
922+ filters : [
923+ { operator : CONST . SEARCH . SYNTAX_OPERATORS . GREATER_THAN_OR_EQUAL_TO , value : weekStart } ,
924+ { operator : CONST . SEARCH . SYNTAX_OPERATORS . LOWER_THAN_OR_EQUAL_TO , value : weekEnd } ,
925+ ] ,
926+ } ) ;
927+ const newQueryJSON : SearchQueryJSON = { ...queryJSON , groupBy : undefined , flatFilters : newFlatFilters } ;
928+ const newQuery = buildSearchQueryString ( newQueryJSON ) ;
929+ const newQueryJSONWithHash = buildSearchQueryJSON ( newQuery ) ;
930+ if ( ! newQueryJSONWithHash ) {
931+ return ;
932+ }
933+ handleSearch ( { queryJSON : newQueryJSONWithHash , searchKey, offset : 0 , shouldCalculateTotals : false , isLoading : false } ) ;
934+ return ;
935+ }
936+
937+ // After handling all group types, item should be TransactionListItemType, ReportActionListItemType, or TransactionGroupListItemType
938+ if ( ! isTransactionItem && ! isReportActionListItemType ( item ) && ! isTransactionGroupListItemType ( item ) ) {
939+ return ;
940+ }
941+
942+ const transactionItem = item as TransactionListItemType ;
943+ const reportActionItem = item as ReportActionListItemType ;
944+
945+ let reportID = transactionItem . reportID ?? reportActionItem . reportID ;
946+ if ( isTransactionItem && transactionItem ?. reportAction ?. childReportID ) {
947+ const isFromSelfDM = transactionItem . reportID === CONST . REPORT . UNREPORTED_REPORT_ID ;
948+ const isFromOneTransactionReport = isOneTransactionReport ( transactionItem . report ) ;
914949
915950 if ( isFromSelfDM || ! isFromOneTransactionReport ) {
916- reportID = item ?. reportAction ?. childReportID ;
951+ reportID = transactionItem ?. reportAction ?. childReportID ;
917952 }
918953 }
919954
@@ -929,16 +964,17 @@ function Search({
929964 } ) ;
930965
931966 if ( isTransactionGroupListItemType ( item ) ) {
932- const firstTransaction = item . transactions . at ( 0 ) ;
933- if ( item . isOneTransactionReport && firstTransaction && transactionPreviewData ) {
967+ const groupItem = item as TransactionGroupListItemType ;
968+ const firstTransaction = groupItem . transactions . at ( 0 ) ;
969+ if ( groupItem . isOneTransactionReport && firstTransaction && transactionPreviewData ) {
934970 if ( ! firstTransaction ?. reportAction ?. childReportID ) {
935971 createAndOpenSearchTransactionThread ( firstTransaction , backTo , firstTransaction ?. reportAction ?. childReportID , transactionPreviewData , false ) ;
936972 } else {
937973 setOptimisticDataForTransactionThreadPreview ( firstTransaction , transactionPreviewData , firstTransaction ?. reportAction ?. childReportID ) ;
938974 }
939975 }
940976
941- if ( item . transactions . length > 1 ) {
977+ if ( groupItem . transactions . length > 1 ) {
942978 markReportIDAsMultiTransactionExpense ( reportID ) ;
943979 } else {
944980 unmarkReportIDAsMultiTransactionExpense ( reportID ) ;
@@ -949,15 +985,15 @@ function Search({
949985 }
950986
951987 if ( isReportActionListItemType ( item ) ) {
952- const reportActionID = item . reportActionID ;
988+ const reportActionID = reportActionItem . reportActionID ;
953989 Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID, reportActionID, backTo} ) ) ;
954990 return ;
955991 }
956992
957993 markReportIDAsExpense ( reportID ) ;
958994
959995 if ( isTransactionItem && transactionPreviewData ) {
960- setOptimisticDataForTransactionThreadPreview ( item , transactionPreviewData , item ?. reportAction ?. childReportID ) ;
996+ setOptimisticDataForTransactionThreadPreview ( transactionItem , transactionPreviewData , transactionItem ?. reportAction ?. childReportID ) ;
961997 }
962998
963999 requestAnimationFrame ( ( ) => Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID, backTo} ) ) ) ;
0 commit comments