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
36 changes: 24 additions & 12 deletions src/components/Search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ type SearchListProps = Pick<FlashListProps<SearchListItem>, 'onScroll' | 'conten

const keyExtractor = (item: SearchListItem, index: number) => item.keyForList ?? `${index}`;

function isTransactionGroupListItemArray(data: SearchListItem[]): data is TransactionGroupListItemType[] {
if (data.length <= 0) {
return false;
}
const firstElement = data.at(0);
return typeof firstElement === 'object' && 'transactions' in firstElement;
}

function SearchList(
{
data,
Expand Down Expand Up @@ -125,19 +133,23 @@ function SearchList(

const {initialHeight, initialWidth} = useInitialWindowDimensions();
const {hash, groupBy, type} = queryJSON;
const flattenedTransactions = groupBy ? (data as TransactionGroupListItemType[]).flatMap((item) => item.transactions) : data;

const flattenedTransactionWithoutPendingDelete = useMemo(
() => flattenedTransactions.filter((t) => t?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE),
[flattenedTransactions],
);
const flattenedItems = useMemo(() => {
if (groupBy) {
if (!isTransactionGroupListItemArray(data)) {
return data;
}
return data.flatMap((item) => item.transactions);
}
return data;
}, [data, groupBy]);
const flattenedItemsWithoutPendingDelete = useMemo(() => flattenedItems.filter((t) => t?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE), [flattenedItems]);

const selectedItemsLength = useMemo(
() =>
flattenedTransactions.reduce((acc, item) => {
flattenedItems.reduce((acc, item) => {
return item?.isSelected ? acc + 1 : acc;
}, 0),
[flattenedTransactions],
[flattenedItems],
);

const {translate} = useLocalize();
Expand Down Expand Up @@ -222,7 +234,7 @@ function SearchList(

const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
initialFocusedIndex: -1,
maxIndex: flattenedTransactions.length - 1,
maxIndex: flattenedItems.length - 1,
isActive: isFocused,
onFocusedIndexChange: (index: number) => {
scrollToIndex(index);
Expand Down Expand Up @@ -352,7 +364,7 @@ function SearchList(

const tableHeaderVisible = canSelectMultiple || !!SearchTableHeader;
const selectAllButtonVisible = canSelectMultiple && !SearchTableHeader;
const isSelectAllChecked = selectedItemsLength > 0 && selectedItemsLength === flattenedTransactionWithoutPendingDelete.length;
const isSelectAllChecked = selectedItemsLength > 0 && selectedItemsLength === flattenedItemsWithoutPendingDelete.length;

const getItemHeight = useMemo(
() =>
Expand Down Expand Up @@ -407,11 +419,11 @@ function SearchList(
<Checkbox
accessibilityLabel={translate('workspace.people.selectAll')}
isChecked={isSelectAllChecked}
isIndeterminate={selectedItemsLength > 0 && selectedItemsLength !== flattenedTransactionWithoutPendingDelete.length}
isIndeterminate={selectedItemsLength > 0 && selectedItemsLength !== flattenedItemsWithoutPendingDelete.length}
onPress={() => {
onAllCheckboxPress();
}}
disabled={flattenedTransactions.length === 0}
disabled={flattenedItems.length === 0}
/>
)}

Expand Down
7 changes: 7 additions & 0 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
return [];
}

// 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 (groupBy && (isChat || isTask)) {
return [];
}

return getSections(type, searchResults.data, searchResults.search, groupBy, exportReportActions, currentSearchKey);
}, [currentSearchKey, exportReportActions, groupBy, isDataLoaded, searchResults, type]);

Expand Down
Loading