Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Revert "Top bar for outstanding tab refuses to disappear when no transactions are found. " #56052

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
76 changes: 33 additions & 43 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,16 @@
import useSearchHighlightAndScroll from '@hooks/useSearchHighlightAndScroll';
import useThemeStyles from '@hooks/useThemeStyles';
import {turnOffMobileSelectionMode, turnOnMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import {createTransactionThread, search} from '@libs/actions/Search';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import * as SearchActions from '@libs/actions/Search';

Check failure on line 18 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as DeviceCapabilities from '@libs/DeviceCapabilities';

Check failure on line 19 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import Log from '@libs/Log';
import memoize from '@libs/memoize';
import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane';
import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types';
import {generateReportID} from '@libs/ReportUtils';
import {buildSearchQueryString} from '@libs/SearchQueryUtils';
import {
getListItem,
getSections,
getSortedSections,
isReportActionListItemType,
isReportListItemType,
isSearchResultsEmpty as isSearchResultsEmptyUtils,
isTransactionListItemType,
shouldShowYear as shouldShowYearUtils,
} from '@libs/SearchUIUtils';
import {isOnHold} from '@libs/TransactionUtils';
import * as ReportUtils from '@libs/ReportUtils';

Check failure on line 24 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as SearchQueryUtils from '@libs/SearchQueryUtils';

Check failure on line 25 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as SearchUIUtils from '@libs/SearchUIUtils';

Check failure on line 26 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as TransactionUtils from '@libs/TransactionUtils';

Check failure on line 27 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import Navigation from '@navigation/Navigation';
import type {AuthScreensParamList} from '@navigation/types';
import EmptySearchView from '@pages/Search/EmptySearchView';
Expand Down Expand Up @@ -66,7 +57,7 @@
isSelected: true,
canDelete: item.canDelete,
canHold: item.canHold,
isHeld: isOnHold(item),
isHeld: TransactionUtils.isOnHold(item),
canUnhold: item.canUnhold,
action: item.action,
reportID: item.reportID,
Expand All @@ -86,14 +77,14 @@
canSelectMultiple: boolean,
shouldAnimateInHighlight: boolean,
) {
if (isReportActionListItemType(item)) {
if (SearchUIUtils.isReportActionListItemType(item)) {
return {
...item,
shouldAnimateInHighlight,
};
}

return isTransactionListItemType(item)
return SearchUIUtils.isTransactionListItemType(item)
? mapToTransactionItemWithSelectionInfo(item, selectedTransactions, canSelectMultiple, shouldAnimateInHighlight)
: {
...item,
Expand All @@ -116,7 +107,7 @@
isSelected: true,
canDelete: item.canDelete,
canHold: item.canHold,
isHeld: isOnHold(item),
isHeld: TransactionUtils.isOnHold(item),
canUnhold: item.canUnhold,
action: item.action,
reportID: item.reportID,
Expand Down Expand Up @@ -185,12 +176,12 @@
return;
}

search({queryJSON, offset});
SearchActions.search({queryJSON, offset});
}, [isOffline, offset, queryJSON]);

const getItemHeight = useCallback(
(item: TransactionListItemType | ReportListItemType | ReportActionListItemType) => {
if (isTransactionListItemType(item) || isReportActionListItemType(item)) {
if (SearchUIUtils.isTransactionListItemType(item) || SearchUIUtils.isReportActionListItemType(item)) {
return isLargeScreenWidth ? variables.optionRowHeight + listItemPadding : transactionItemMobileHeight + listItemPadding;
}

Expand Down Expand Up @@ -238,14 +229,14 @@

const shouldShowLoadingState = !isOffline && !isDataLoaded;
const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0;
const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtils(searchResults);
const isPrevSearchResultsEmpty = usePrevious(isSearchResultsEmpty);
const isSearchResultsEmpty = !searchResults?.data || SearchUIUtils.isSearchResultsEmpty(searchResults);
const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty);

const data = useMemo(() => {
if (searchResults === undefined) {
return [];
}
return getSections(type, status, searchResults.data, searchResults.search);
return SearchUIUtils.getSections(type, status, searchResults.data, searchResults.search);
}, [searchResults, status, type]);

useEffect(() => {
Expand All @@ -269,7 +260,7 @@
newTransactionList[transaction.transactionID] = {
action: transaction.action,
canHold: transaction.canHold,
isHeld: isOnHold(transaction),
isHeld: TransactionUtils.isOnHold(transaction),
canUnhold: transaction.canUnhold,
isSelected: selectedTransactions[transaction.transactionID].isSelected,
canDelete: transaction.canDelete,
Expand All @@ -290,7 +281,7 @@
newTransactionList[transaction.transactionID] = {
action: transaction.action,
canHold: transaction.canHold,
isHeld: isOnHold(transaction),
isHeld: TransactionUtils.isOnHold(transaction),
canUnhold: transaction.canUnhold,
isSelected: selectedTransactions[transaction.transactionID].isSelected,
canDelete: transaction.canDelete,
Expand All @@ -306,11 +297,11 @@
}, [data, setSelectedTransactions]);

useEffect(() => {
if (!isSearchResultsEmpty || isPrevSearchResultsEmpty) {
if (!isSearchResultsEmpty || prevIsSearchResultEmpty) {
return;
}
turnOffMobileSelectionMode();
}, [isSearchResultsEmpty, isPrevSearchResultsEmpty]);
}, [isSearchResultsEmpty, prevIsSearchResultEmpty]);

useEffect(
() => () => {
Expand All @@ -337,8 +328,8 @@
return <FullPageOfflineBlockingView>{null}</FullPageOfflineBlockingView>;
}

const ListItem = getListItem(type, status);
const sortedData = getSortedSections(type, status, data, sortBy, sortOrder);
const ListItem = SearchUIUtils.getListItem(type, status);
const sortedData = SearchUIUtils.getSortedSections(type, status, data, sortBy, sortOrder);
const isChat = type === CONST.SEARCH.DATA_TYPES.CHAT;
const sortedSelectedData = sortedData.map((item) => {
const baseKey = isChat
Expand All @@ -359,7 +350,7 @@
return mapToItemWithSelectionInfo(item, selectedTransactions, canSelectMultiple, shouldAnimateInHighlight);
});

const shouldShowEmptyState = isSearchResultsEmpty || !isDataLoaded;
const shouldShowEmptyState = !isDataLoaded || data.length === 0;

if (shouldShowEmptyState) {
return (
Expand All @@ -373,10 +364,10 @@
}

const toggleTransaction = (item: TransactionListItemType | ReportListItemType | ReportActionListItemType) => {
if (isReportActionListItemType(item)) {
if (SearchUIUtils.isReportActionListItemType(item)) {
return;
}
if (isTransactionListItemType(item)) {
if (SearchUIUtils.isTransactionListItemType(item)) {
if (!item.keyForList) {
return;
}
Expand Down Expand Up @@ -407,21 +398,21 @@

const openReport = (item: TransactionListItemType | ReportListItemType | ReportActionListItemType) => {
const isFromSelfDM = item.reportID === CONST.REPORT.UNREPORTED_REPORTID;
let reportID = isTransactionListItemType(item) && (!item.isFromOneTransactionReport || isFromSelfDM) ? item.transactionThreadReportID : item.reportID;
let reportID = SearchUIUtils.isTransactionListItemType(item) && (!item.isFromOneTransactionReport || isFromSelfDM) ? item.transactionThreadReportID : item.reportID;

if (!reportID) {
return;
}

// If we're trying to open a legacy transaction without a transaction thread, let's create the thread and navigate the user
if (isTransactionListItemType(item) && reportID === '0' && item.moneyRequestReportActionID) {
reportID = generateReportID();
createTransactionThread(hash, item.transactionID, reportID, item.moneyRequestReportActionID);
if (SearchUIUtils.isTransactionListItemType(item) && reportID === '0' && item.moneyRequestReportActionID) {
reportID = ReportUtils.generateReportID();
SearchActions.createTransactionThread(hash, item.transactionID, reportID, item.moneyRequestReportActionID);
}

const backTo = Navigation.getActiveRoute();

if (isReportActionListItemType(item)) {
if (SearchUIUtils.isReportActionListItemType(item)) {
const reportActionID = item.reportActionID;
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, reportActionID, backTo}));
return;
Expand Down Expand Up @@ -457,14 +448,13 @@
};

const onSortPress = (column: SearchColumnType, order: SortOrder) => {
const newQuery = buildSearchQueryString({...queryJSON, sortBy: column, sortOrder: order});
const newQuery = SearchQueryUtils.buildSearchQueryString({...queryJSON, sortBy: column, sortOrder: order});
navigation.setParams({q: newQuery});
};

const shouldShowYear = SearchUIUtils.shouldShowYear(searchResults?.data);
const shouldShowSorting = !Array.isArray(status) && sortableSearchStatuses.includes(status);

const shouldShowYear = shouldShowYearUtils(searchResults?.data);

return (
<SelectionListWithModal<ReportListItemType | TransactionListItemType | ReportActionListItemType>
ref={handleSelectionListScroll(sortedSelectedData)}
Expand All @@ -487,7 +477,7 @@
)
}
isSelected={(item) =>
status !== CONST.SEARCH.STATUS.EXPENSE.ALL && isReportListItemType(item)
status !== CONST.SEARCH.STATUS.EXPENSE.ALL && SearchUIUtils.isReportListItemType(item)
? item.transactions.some((transaction) => selectedTransactions[transaction.keyForList]?.isSelected)
: !!item.isSelected
}
Expand All @@ -511,7 +501,7 @@
onSelectRow={openReport}
getItemHeight={getItemHeightMemoized}
shouldSingleExecuteRowSelect
shouldPreventDefaultFocusOnSelectRow={!canUseTouchScreen()}
shouldPreventDefaultFocusOnSelectRow={!DeviceCapabilities.canUseTouchScreen()}
shouldPreventDefault={false}
listHeaderWrapperStyle={[styles.ph8, styles.pt3]}
containerStyle={[styles.pv0, type === CONST.SEARCH.DATA_TYPES.CHAT && !isSmallScreenWidth && styles.pt3]}
Expand Down
Loading