Skip to content

Commit c6f516e

Browse files
authored
Merge pull request Expensify#60800 from software-mansion-labs/jnowakow/adjust-search-selection-mode
Adjust selection mode on search page
2 parents 8ccf622 + 9e2171e commit c6f516e

3 files changed

Lines changed: 57 additions & 39 deletions

File tree

src/components/Search/SearchList.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,14 @@ function SearchList(
169169
if (shouldPreventLongPressRow || !isSmallScreenWidth || item?.isDisabled || item?.isDisabledCheckbox || !isFocused) {
170170
return;
171171
}
172+
if (selectionMode?.isEnabled) {
173+
onCheckboxPress(item);
174+
return;
175+
}
172176
setLongPressedItem(item);
173177
setIsModalVisible(true);
174178
},
175-
[isFocused, isSmallScreenWidth, shouldPreventLongPressRow],
179+
[isFocused, isSmallScreenWidth, onCheckboxPress, selectionMode?.isEnabled, shouldPreventLongPressRow],
176180
);
177181

178182
const turnOnSelectionMode = useCallback(() => {
@@ -394,7 +398,7 @@ function SearchList(
394398
>
395399
<MenuItem
396400
title={translate('common.select')}
397-
icon={Expensicons.Checkmark}
401+
icon={Expensicons.CheckSquare}
398402
onPress={turnOnSelectionMode}
399403
/>
400404
</Modal>

src/components/Search/index.tsx

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,52 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
328328
}
329329
}, [isFocused, data, searchResults?.search?.hasMoreResults, selectedTransactions, setExportMode, setShouldShowExportModeOption, shouldGroupByReports]);
330330

331+
const toggleTransaction = useCallback(
332+
(item: SearchListItem) => {
333+
if (isReportActionListItemType(item)) {
334+
return;
335+
}
336+
if (isTaskListItemType(item)) {
337+
return;
338+
}
339+
if (isTransactionListItemType(item)) {
340+
if (!item.keyForList) {
341+
return;
342+
}
343+
344+
setSelectedTransactions(prepareTransactionsList(item, selectedTransactions), data);
345+
return;
346+
}
347+
348+
if (item.transactions.some((transaction) => selectedTransactions[transaction.keyForList]?.isSelected)) {
349+
const reducedSelectedTransactions: SelectedTransactions = {...selectedTransactions};
350+
351+
item.transactions.forEach((transaction) => {
352+
delete reducedSelectedTransactions[transaction.keyForList];
353+
});
354+
355+
setSelectedTransactions(reducedSelectedTransactions, data);
356+
return;
357+
}
358+
359+
setSelectedTransactions(
360+
{
361+
...selectedTransactions,
362+
...Object.fromEntries(item.transactions.map(mapTransactionItemToSelectedEntry)),
363+
},
364+
data,
365+
);
366+
},
367+
[data, selectedTransactions, setSelectedTransactions],
368+
);
369+
331370
const openReport = useCallback(
332371
(item: SearchListItem, isOpenedAsReport?: boolean) => {
372+
if (selectionMode?.isEnabled) {
373+
toggleTransaction(item);
374+
return;
375+
}
376+
333377
const isFromSelfDM = item.reportID === CONST.REPORT.UNREPORTED_REPORTID;
334378
const isTransactionItem = isTransactionListItemType(item);
335379

@@ -373,7 +417,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
373417

374418
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo}));
375419
},
376-
[canUseTableReportView, hash],
420+
[canUseTableReportView, hash, selectionMode?.isEnabled, toggleTransaction],
377421
);
378422

379423
const onViewableItemsChanged = useCallback(
@@ -459,42 +503,6 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
459503
);
460504
}
461505

462-
const toggleTransaction = (item: SearchListItem) => {
463-
if (isReportActionListItemType(item)) {
464-
return;
465-
}
466-
if (isTaskListItemType(item)) {
467-
return;
468-
}
469-
if (isTransactionListItemType(item)) {
470-
if (!item.keyForList) {
471-
return;
472-
}
473-
474-
setSelectedTransactions(prepareTransactionsList(item, selectedTransactions), data);
475-
return;
476-
}
477-
478-
if (item.transactions.some((transaction) => selectedTransactions[transaction.keyForList]?.isSelected)) {
479-
const reducedSelectedTransactions: SelectedTransactions = {...selectedTransactions};
480-
481-
item.transactions.forEach((transaction) => {
482-
delete reducedSelectedTransactions[transaction.keyForList];
483-
});
484-
485-
setSelectedTransactions(reducedSelectedTransactions, data);
486-
return;
487-
}
488-
489-
setSelectedTransactions(
490-
{
491-
...selectedTransactions,
492-
...Object.fromEntries(item.transactions.map(mapTransactionItemToSelectedEntry)),
493-
},
494-
data,
495-
);
496-
};
497-
498506
const fetchMoreResults = () => {
499507
if (!searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems) {
500508
return;

src/pages/Search/SearchSelectedNarrow.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Button from '@components/Button';
44
import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';
55
import MenuItem from '@components/MenuItem';
66
import Modal from '@components/Modal';
7+
import {useSearchContext} from '@components/Search/SearchContext';
78
import type {SearchHeaderOptionValue} from '@components/Search/SearchPageHeader/SearchPageHeader';
89
import useLocalize from '@hooks/useLocalize';
910
import useThemeStyles from '@hooks/useThemeStyles';
@@ -23,11 +24,15 @@ function SearchSelectedNarrow({options, itemsLength}: SearchSelectedNarrowProps)
2324
const openMenu = () => setIsModalVisible(true);
2425
const closeMenu = () => setIsModalVisible(false);
2526

27+
const {clearSelectedTransactions} = useSearchContext();
28+
2629
const handleOnModalHide = () => {
2730
if (selectedOptionIndexRef.current === -1) {
2831
return;
2932
}
33+
3034
options[selectedOptionIndexRef.current]?.onSelected?.();
35+
clearSelectedTransactions();
3136
};
3237

3338
const handleOnMenuItemPress = (option: DropdownOption<SearchHeaderOptionValue>, index: number) => {
@@ -37,6 +42,7 @@ function SearchSelectedNarrow({options, itemsLength}: SearchSelectedNarrowProps)
3742
return;
3843
}
3944
option?.onSelected?.();
45+
clearSelectedTransactions();
4046
};
4147

4248
const handleOnCloseMenu = () => {

0 commit comments

Comments
 (0)