Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6478,7 +6478,6 @@ const CONST = {
ME: 'me',
DATA_TYPES: {
EXPENSE: 'expense',
EXPENSE_REPORT: 'expense-report',
INVOICE: 'invoice',
TASK: 'task',
TRIP: 'trip',
Expand Down Expand Up @@ -6536,6 +6535,7 @@ const CONST = {
DESC: 'desc',
},
GROUP_BY: {
REPORTS: 'reports',
FROM: 'from',
CARD: 'card',
WITHDRAWAL_ID: 'withdrawal-id',
Expand All @@ -6558,14 +6558,6 @@ const CONST = {
DONE: 'done',
PAID: 'paid',
},
EXPENSE_REPORT: {
ALL: '',
DRAFTS: 'drafts',
OUTSTANDING: 'outstanding',
APPROVED: 'approved',
DONE: 'done',
PAID: 'paid',
},
INVOICE: {
ALL: '',
OUTSTANDING: 'outstanding',
Expand Down Expand Up @@ -6719,6 +6711,7 @@ const CONST = {
get SEARCH_USER_FRIENDLY_VALUES_MAP() {
return {
[this.TRANSACTION_TYPE.PER_DIEM]: 'per-diem',
[this.GROUP_BY.REPORTS]: 'report',
[this.STATUS.EXPENSE.DRAFTS]: 'draft',
};
},
Expand Down
3 changes: 0 additions & 3 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ function SearchAutocompleteList({
case CONST.SEARCH.DATA_TYPES.EXPENSE:
suggestedStatuses = Object.values(CONST.SEARCH.STATUS.EXPENSE);
break;
case CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT:
suggestedStatuses = Object.values(CONST.SEARCH.STATUS.EXPENSE_REPORT);
break;
case CONST.SEARCH.DATA_TYPES.INVOICE:
suggestedStatuses = Object.values(CONST.SEARCH.STATUS.INVOICE);
break;
Expand Down
9 changes: 4 additions & 5 deletions src/components/Search/SearchList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function SearchList({
}: SearchListProps) {
const styles = useThemeStyles();

const {hash, groupBy, type} = queryJSON;
const {hash, groupBy} = queryJSON;
const flattenedItems = useMemo(() => {
if (groupBy) {
if (!isTransactionGroupListItemArray(data)) {
Expand Down Expand Up @@ -223,6 +223,7 @@ function SearchList({
const handleLongPressRow = useCallback(
(item: SearchListItem) => {
const currentRoute = navigationRef.current?.getCurrentRoute();
const isReadonlyGroupBy = groupBy && groupBy !== CONST.SEARCH.GROUP_BY.REPORTS;
if (currentRoute && route.key !== currentRoute.key) {
return;
}
Expand All @@ -232,7 +233,7 @@ function SearchList({
return;
}
// disable long press for empty expense reports
if ('transactions' in item && item.transactions.length === 0 && !groupBy) {
if ('transactions' in item && item.transactions.length === 0 && !isReadonlyGroupBy) {
return;
}
if (isMobileSelectionModeEnabled) {
Expand Down Expand Up @@ -318,7 +319,6 @@ function SearchList({
isDisabled={isDisabled}
allReports={allReports}
groupBy={groupBy}
searchType={type}
userWalletTierName={userWalletTierName}
isUserValidated={isUserValidated}
personalDetails={personalDetails}
Expand All @@ -333,7 +333,6 @@ function SearchList({
);
},
[
type,
groupBy,
newTransactions,
shouldAnimate,
Expand Down Expand Up @@ -362,7 +361,7 @@ function SearchList({
],
);

const tableHeaderVisible = (canSelectMultiple || !!SearchTableHeader) && (!groupBy || type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT);
const tableHeaderVisible = (canSelectMultiple || !!SearchTableHeader) && (!groupBy || groupBy === CONST.SEARCH.GROUP_BY.REPORTS);
const selectAllButtonVisible = canSelectMultiple && !SearchTableHeader;
const isSelectAllChecked = selectedItemsLength > 0 && selectedItemsLength === flattenedItemsWithoutPendingDelete.length;

Expand Down
6 changes: 3 additions & 3 deletions src/components/Search/SearchPageHeader/SearchFiltersBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ function SearchFiltersBar({
}, [flatFilters, allFeeds, allCards]);

const [statusOptions, status] = useMemo(() => {
const options = type ? getStatusOptions(type.value) : [];
const options = type ? getStatusOptions(type.value, groupBy?.value) : [];
const value = [
Array.isArray(unsafeStatus) ? options.filter((option) => unsafeStatus.includes(option.value)) : (options.find((option) => option.value === unsafeStatus) ?? []),
].flat();
return [options, value];
}, [unsafeStatus, type]);
}, [unsafeStatus, type, groupBy]);

const [hasOptions, has] = useMemo(() => {
const hasFilterValues = flatFilters.find((filter) => filter.key === CONST.SEARCH.SYNTAX_FILTER_KEYS.HAS)?.filters?.map((filter) => filter.value);
Expand Down Expand Up @@ -456,7 +456,7 @@ function SearchFiltersBar({
const filters = useMemo<FilterItem[]>(() => {
const fromValue = filterFormValues.from?.map((currentAccountID) => personalDetails?.[currentAccountID]?.displayName ?? currentAccountID) ?? [];

const shouldDisplayGroupByFilter = !!groupBy?.value;
const shouldDisplayGroupByFilter = !!groupBy?.value && groupBy?.value !== CONST.SEARCH.GROUP_BY.REPORTS;
const shouldDisplayGroupCurrencyFilter = shouldDisplayGroupByFilter && hasMultipleOutputCurrency;
const shouldDisplayFeedFilter = feedOptions.length > 1 && !!filterFormValues.feed;
const shouldDisplayPostedFilter = !!filterFormValues.feed && (!!filterFormValues.postedOn || !!filterFormValues.postedAfter || !!filterFormValues.postedBefore);
Expand Down
39 changes: 19 additions & 20 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);

const validGroupBy = groupBy && Object.values(CONST.SEARCH.GROUP_BY).includes(groupBy) ? groupBy : undefined;
const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtil(searchResults, validGroupBy);
const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtil(searchResults, groupBy);

useEffect(() => {
if (!isFocused) {
Expand Down Expand Up @@ -385,13 +384,13 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
// Group-by option cannot be used for chats or tasks
const isChat = type === CONST.SEARCH.DATA_TYPES.CHAT;
const isTask = type === CONST.SEARCH.DATA_TYPES.TASK;
if (validGroupBy && (isChat || isTask)) {
if (groupBy && (isChat || isTask)) {
return [[], 0];
}

const data1 = getSections(type, searchResults.data, accountID, formatPhoneNumber, validGroupBy, exportReportActions, searchKey, archivedReportsIdSet, queryJSON);
const data1 = getSections(type, searchResults.data, accountID, formatPhoneNumber, groupBy, exportReportActions, searchKey, archivedReportsIdSet, queryJSON);
return [data1, data1.length];
}, [searchKey, exportReportActions, validGroupBy, isDataLoaded, searchResults, type, archivedReportsIdSet, formatPhoneNumber, accountID, queryJSON]);
}, [searchKey, exportReportActions, groupBy, isDataLoaded, searchResults, type, archivedReportsIdSet, formatPhoneNumber, accountID, queryJSON]);

useEffect(() => {
/** We only want to display the skeleton for the status filters the first time we load them for a specific data type */
Expand Down Expand Up @@ -425,7 +424,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
return;
}
const newTransactionList: SelectedTransactions = {};
if (validGroupBy) {
if (groupBy) {
data.forEach((transactionGroup) => {
if (!Object.hasOwn(transactionGroup, 'transactions') || !('transactions' in transactionGroup)) {
return;
Expand Down Expand Up @@ -533,7 +532,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
if (!data.length || isRefreshingSelection.current) {
return;
}
const areItemsGrouped = !!validGroupBy;
const areItemsGrouped = !!groupBy;
const flattenedItems = areItemsGrouped ? (data as TransactionGroupListItemType[]).flatMap((item) => item.transactions) : data;
const areAllItemsSelected = flattenedItems.length === Object.keys(selectedTransactions).length;

Expand All @@ -543,7 +542,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
if (!areAllItemsSelected) {
selectAllMatchingItems(false);
}
}, [isFocused, data, searchResults?.search?.hasMoreResults, selectedTransactions, selectAllMatchingItems, shouldShowSelectAllMatchingItems, validGroupBy]);
}, [isFocused, data, searchResults?.search?.hasMoreResults, selectedTransactions, selectAllMatchingItems, shouldShowSelectAllMatchingItems, groupBy]);

const toggleTransaction = useCallback(
(item: SearchListItem, itemTransactions?: TransactionListItemType[]) => {
Expand Down Expand Up @@ -727,13 +726,12 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS

const isChat = type === CONST.SEARCH.DATA_TYPES.CHAT;
const isTask = type === CONST.SEARCH.DATA_TYPES.TASK;
const isExpenseReportType = type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT;
const canSelectMultiple = !isChat && !isTask && (!isSmallScreenWidth || isMobileSelectionModeEnabled) && validGroupBy !== CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID;
const ListItem = getListItem(type, status, validGroupBy);
const canSelectMultiple = !isChat && !isTask && (!isSmallScreenWidth || isMobileSelectionModeEnabled) && groupBy !== CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID;
const ListItem = getListItem(type, status, groupBy);

const sortedSelectedData = useMemo(
() =>
getSortedSections(type, status, data, localeCompare, sortBy, sortOrder, validGroupBy).map((item) => {
getSortedSections(type, status, data, localeCompare, sortBy, sortOrder, groupBy).map((item) => {
const baseKey = isChat
? `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${(item as ReportActionListItemType).reportActionID}`
: `${ONYXKEYS.COLLECTION.TRANSACTION}${(item as TransactionListItemType).transactionID}`;
Expand All @@ -754,7 +752,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS

return mapToItemWithAdditionalInfo(item, selectedTransactions, canSelectMultiple, shouldAnimateInHighlight, hash);
}),
[type, status, data, sortBy, sortOrder, validGroupBy, isChat, newSearchResultKey, selectedTransactions, canSelectMultiple, localeCompare, hash],
[type, status, data, sortBy, sortOrder, groupBy, isChat, newSearchResultKey, selectedTransactions, canSelectMultiple, localeCompare, hash],
);

const hasErrors = Object.keys(searchResults?.errors ?? {}).length > 0 && !isOffline;
Expand Down Expand Up @@ -782,7 +780,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
}, [isFocused, searchResults?.search?.hasMoreResults, shouldShowLoadingMoreItems, shouldShowLoadingState, offset, data.length]);

const toggleAllTransactions = useCallback(() => {
const areItemsGrouped = !!validGroupBy || isExpenseReportType;
const areItemsGrouped = !!groupBy;
const totalSelected = Object.keys(selectedTransactions).length;

if (totalSelected > 0) {
Expand Down Expand Up @@ -813,7 +811,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
),
data,
);
}, [clearSelectedTransactions, data, validGroupBy, reportActionsArray, selectedTransactions, setSelectedTransactions, outstandingReportsByPolicyID, isExpenseReportType]);
}, [clearSelectedTransactions, data, groupBy, reportActionsArray, selectedTransactions, setSelectedTransactions, outstandingReportsByPolicyID]);

const onLayout = useCallback(() => handleSelectionListScroll(sortedSelectedData, searchListRef.current), [handleSelectionListScroll, sortedSelectedData]);

Expand Down Expand Up @@ -862,6 +860,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
<EmptySearchView
similarSearchHash={similarSearchHash}
type={type}
groupBy={groupBy}
hasResults={searchResults?.search?.hasResults}
/>
</View>
Expand All @@ -876,9 +875,9 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS

const shouldShowYear = shouldShowYearUtil(searchResults?.data);
const {shouldShowAmountInWideColumn, shouldShowTaxAmountInWideColumn} = getWideAmountIndicators(searchResults?.data);
const shouldShowSorting = !validGroupBy;
const shouldShowTableHeader = isLargeScreenWidth && !isChat && !validGroupBy && !isExpenseReportType;
const tableHeaderVisible = (canSelectMultiple || shouldShowTableHeader) && (!validGroupBy || isExpenseReportType);
const shouldShowSorting = !groupBy;
const shouldShowTableHeader = isLargeScreenWidth && !isChat && !groupBy;
const tableHeaderVisible = (canSelectMultiple || shouldShowTableHeader) && (!groupBy || groupBy === CONST.SEARCH.GROUP_BY.REPORTS);

return (
<SearchScopeProvider>
Expand All @@ -898,7 +897,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
<SearchTableHeader
canSelectMultiple={canSelectMultiple}
columns={columnsToShow}
type={type}
type={searchResults?.search.type}
onSortPress={onSortPress}
sortOrder={sortOrder}
sortBy={sortBy}
Expand All @@ -907,7 +906,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
isTaxAmountColumnWide={shouldShowTaxAmountInWideColumn}
shouldShowSorting={shouldShowSorting}
areAllOptionalColumnsHidden={areAllOptionalColumnsHidden}
groupBy={validGroupBy}
groupBy={groupBy}
/>
)
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/Search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ type PaymentData = {
type SortOrder = ValueOf<typeof CONST.SEARCH.SORT_ORDER>;
type SearchColumnType = ValueOf<typeof CONST.SEARCH.TABLE_COLUMNS>;
type ExpenseSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.EXPENSE>;
type ExpenseReportSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.EXPENSE_REPORT>;
type InvoiceSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.INVOICE>;
type TripSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.TRIP>;
type TaskSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.TASK>;
type SingularSearchStatus = ExpenseSearchStatus | ExpenseReportSearchStatus | InvoiceSearchStatus | TripSearchStatus | TaskSearchStatus;
type SingularSearchStatus = ExpenseSearchStatus | InvoiceSearchStatus | TripSearchStatus | TaskSearchStatus;
type SearchStatus = SingularSearchStatus | SingularSearchStatus[];
type SearchGroupBy = ValueOf<typeof CONST.SEARCH.GROUP_BY>;
type TableColumnSize = ValueOf<typeof CONST.SEARCH.TABLE_COLUMN_SIZES>;
Expand Down
Loading
Loading