Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
58e977f
feat: [Insights] [Release 1] Top Categories - Add group-by:category
TaduJR Jan 23, 2026
4571bbb
feat: add GROUP_BY.CATEGORY support with sorting and column alignment
TaduJR Jan 23, 2026
e42a41a
fix: improve type safety and use CONST values in category grouping tests
TaduJR Jan 23, 2026
c219475
chore: run prettier
TaduJR Jan 23, 2026
97836f0
fix: resolve TypeScript and lint errors in category grouping tests
TaduJR Jan 23, 2026
17395a0
test: add coverage for large screen layout and expand/collapse in Cat…
TaduJR Jan 23, 2026
acd4da8
fix: add group-category parser mapping for column round-trip
TaduJR Jan 24, 2026
805a346
fix: use ref for searchContextData in clearSelectedTransactions to st…
TaduJR Jan 24, 2026
ec18923
Merge branch 'main' of https://github.com/TaduJR/App into feat-Insigh…
TaduJR Jan 24, 2026
e37af71
Merge branch 'Expensify:main' into feat-Insights-Release-1-Top-Catego…
TaduJR Jan 26, 2026
d229390
fix: remove category icons, enable sorting, and update empty category…
TaduJR Jan 26, 2026
678b5a9
fix: remove unnecessary fragment wrapper
TaduJR Jan 26, 2026
09d6496
fix: translation key path for uncategorized label
TaduJR Jan 26, 2026
8eeb3a8
fix: add category matching for new transaction detection in grouped s…
TaduJR Jan 26, 2026
a0a07b7
Merge branch 'main' of https://github.com/TaduJR/App into feat-Insigh…
TaduJR Jan 26, 2026
4d35ab1
Merge branch 'Expensify:main' into feat-Insights-Release-1-Top-Catego…
TaduJR Jan 26, 2026
e870ee5
Merge branch 'main' of https://github.com/TaduJR/App into feat-Insigh…
TaduJR Jan 26, 2026
d28536b
Merge branch 'Expensify:main' into feat-Insights-Release-1-Top-Catego…
TaduJR Jan 26, 2026
7d470dc
fix: Add 8px margin between category columns on mobile
TaduJR Jan 26, 2026
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
9 changes: 9 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6835,6 +6835,7 @@ const CONST = {
FROM: 'from',
CARD: 'card',
WITHDRAWAL_ID: 'withdrawal-id',
CATEGORY: 'category',
},
get TYPE_CUSTOM_COLUMNS() {
return {
Expand Down Expand Up @@ -6911,6 +6912,11 @@ const CONST = {
EXPENSES: this.TABLE_COLUMNS.GROUP_EXPENSES,
TOTAL: this.TABLE_COLUMNS.GROUP_TOTAL,
},
CATEGORY: {
CATEGORY: this.TABLE_COLUMNS.GROUP_CATEGORY,
EXPENSES: this.TABLE_COLUMNS.GROUP_EXPENSES,
TOTAL: this.TABLE_COLUMNS.GROUP_TOTAL,
},
};
},
get TYPE_DEFAULT_COLUMNS() {
Expand Down Expand Up @@ -6952,6 +6958,7 @@ const CONST = {
this.TABLE_COLUMNS.GROUP_EXPENSES,
this.TABLE_COLUMNS.GROUP_TOTAL,
],
CATEGORY: [this.TABLE_COLUMNS.GROUP_CATEGORY, this.TABLE_COLUMNS.GROUP_EXPENSES, this.TABLE_COLUMNS.GROUP_TOTAL],
};
},
BOOLEAN: {
Expand Down Expand Up @@ -7047,6 +7054,7 @@ const CONST = {
GROUP_BANK_ACCOUNT: 'groupBankAccount',
GROUP_WITHDRAWN: 'groupWithdrawn',
GROUP_WITHDRAWAL_ID: 'groupWithdrawalID',
GROUP_CATEGORY: 'groupCategory',
},
SYNTAX_OPERATORS: {
AND: 'and',
Expand Down Expand Up @@ -7227,6 +7235,7 @@ const CONST = {
[this.TABLE_COLUMNS.GROUP_BANK_ACCOUNT]: 'group-bank-account',
[this.TABLE_COLUMNS.GROUP_WITHDRAWN]: 'group-withdrawn',
[this.TABLE_COLUMNS.GROUP_WITHDRAWAL_ID]: 'group-withdrawal-id',
[this.TABLE_COLUMNS.GROUP_CATEGORY]: 'group-category',
Comment thread
TaduJR marked this conversation as resolved.
Resolved
};
},
NOT_MODIFIER: 'Not',
Expand Down
18 changes: 9 additions & 9 deletions src/components/Search/SearchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function SearchContextProvider({children}: ChildrenProps) {
const [searchContextData, setSearchContextData] = useState(defaultSearchContextData);
const areTransactionsEmpty = useRef(true);

// Use a ref to access searchContextData in callbacks without causing callback reference changes
const searchContextDataRef = useRef(searchContextData);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: iOS Selection Mode Bug Fix (Pre-existing)

Bug: Selection mode on iOS would immediately turn off after long-press on group-by views.

Root Cause: clearSelectedTransactions callback was unstable - it had searchContextData in its dependency array, causing reference changes on every selection. This triggered cleanup in effects that depend on this callback (here), which calls turnOffMobileSelectionMode(). On iOS, navigation transitions keep old component instances mounted longer, so stale instances would incorrectly turn off selection mode.

Fix: Used a ref to read searchContextData inside the callback, keeping the dependency array stable (ref declaration, usage).

searchContextDataRef.current = searchContextData;

const [snapshotSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${searchContextData.currentSearchHash}`, {canBeMissing: true});
const {todoSearchResultsData} = useTodos();

Expand Down Expand Up @@ -196,11 +200,13 @@ function SearchContextProvider({children}: ChildrenProps) {
return;
}

if (searchHashOrClearIDsFlag === searchContextData.currentSearchHash) {
const data = searchContextDataRef.current;

if (searchHashOrClearIDsFlag === data.currentSearchHash) {
return;
}

if (searchContextData.selectedReports.length === 0 && isEmptyObject(searchContextData.selectedTransactions) && !searchContextData.shouldTurnOffSelectionMode) {
if (data.selectedReports.length === 0 && isEmptyObject(data.selectedTransactions) && !data.shouldTurnOffSelectionMode) {
return;
}
setSearchContextData((prevState) => ({
Expand All @@ -214,13 +220,7 @@ function SearchContextProvider({children}: ChildrenProps) {
shouldShowSelectAllMatchingItems(false);
selectAllMatchingItems(false);
},
[
searchContextData.currentSearchHash,
searchContextData.selectedReports.length,
searchContextData.selectedTransactions,
searchContextData.shouldTurnOffSelectionMode,
setSelectedTransactions,
],
[setSelectedTransactions],
);

const removeTransaction: SearchContextProps['removeTransaction'] = useCallback(
Expand Down
4 changes: 4 additions & 0 deletions src/components/Search/SearchList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
ReportActionListItemType,
TaskListItemType,
TransactionCardGroupListItemType,
TransactionCategoryGroupListItemType,
TransactionGroupListItemType,
TransactionListItemType,
} from '@components/SelectionListWithSections/types';
Expand Down Expand Up @@ -153,6 +154,9 @@ function isTransactionMatchWithGroupItem(transaction: Transaction, groupItem: Se
if (groupBy === CONST.SEARCH.GROUP_BY.FROM) {
return !!transaction.transactionID;
}
if (groupBy === CONST.SEARCH.GROUP_BY.CATEGORY) {
return (transaction.category ?? '') === ((groupItem as TransactionCategoryGroupListItemType).category ?? '');
}
return false;
}

Expand Down
20 changes: 19 additions & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
isSearchResultsEmpty as isSearchResultsEmptyUtil,
isTaskListItemType,
isTransactionCardGroupListItemType,
isTransactionCategoryGroupListItemType,
isTransactionGroupListItemType,
isTransactionListItemType,
isTransactionMemberGroupListItemType,
Expand Down Expand Up @@ -213,6 +214,7 @@ function Search({
onDEWModalOpen,
}: SearchProps) {
const {type, status, sortBy, sortOrder, hash, similarSearchHash, groupBy} = queryJSON;

const {isOffline} = useNetwork();
const prevIsOffline = usePrevious(isOffline);
const {shouldUseNarrowLayout} = useResponsiveLayout();
Expand Down Expand Up @@ -770,6 +772,7 @@ function Search({
}

const currentTransactions = itemTransactions ?? item.transactions;

// Handle empty reports - treat the report itself as selectable
if (currentTransactions.length === 0 && isTransactionReportGroupListItemType(item)) {
const reportKey = item.keyForList;
Expand Down Expand Up @@ -799,6 +802,7 @@ function Search({
updateSelectAllMatchingItemsState(updatedTransactions);
return;
}

if (currentTransactions.some((transaction) => selectedTransactions[transaction.keyForList]?.isSelected)) {
const reducedSelectedTransactions: SelectedTransactions = {...selectedTransactions};

Expand Down Expand Up @@ -887,6 +891,20 @@ function Search({
return;
}

if (isTransactionCategoryGroupListItemType(item)) {
const categoryValue = item.category === '' ? CONST.SEARCH.CATEGORY_EMPTY_VALUE : item.category;
const newFlatFilters = queryJSON.flatFilters.filter((filter) => filter.key !== CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY);
newFlatFilters.push({key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, filters: [{operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO, value: categoryValue}]});
const newQueryJSON: SearchQueryJSON = {...queryJSON, groupBy: undefined, flatFilters: newFlatFilters};
const newQuery = buildSearchQueryString(newQueryJSON);
const newQueryJSONWithHash = buildSearchQueryJSON(newQuery);
if (!newQueryJSONWithHash) {
return;
}
handleSearch({queryJSON: newQueryJSONWithHash, searchKey, offset: 0, shouldCalculateTotals: false, isLoading: false});
return;
}
Comment on lines +894 to +906

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: This is getting repetitve. Maybe we can do this in a follow up?

Use transactionsQueryJSON from the item

You already compute transactionsQueryJSON in getCategorySections (and the other group section functions in SearchUIUtils.ts). Since each group item already has its drilldown query pre-computed, you could simplify even further:

// All group types have transactionsQueryJSON pre-computed
if (isTransactionMemberGroupListItemType(item) || isTransactionCardGroupListItemType(item) || 
    isTransactionWithdrawalIDGroupListItemType(item) || isTransactionCategoryGroupListItemType(item)) {
    if (item.transactionsQueryJSON) {
        handleSearch({queryJSON: item.transactionsQueryJSON, searchKey, offset: 0, shouldCalculateTotals: false, isLoading: false});
        return;
    }
}

This would be the cleanest solution since it reuses the query already built in SearchUIUtils.ts, avoiding duplicate logic entirely. You'd just need to verify all group item types have transactionsQueryJSON populated (which they should based on the getSections functions we looked at earlier).


let reportID = item.reportID;
if (isTransactionItem && item?.reportAction?.childReportID) {
const isFromSelfDM = item.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
Expand Down Expand Up @@ -1184,7 +1202,7 @@ function Search({
clearSelectedTransactions();
const newQuery = buildSearchQueryString({...queryJSON, sortBy: column, sortOrder: order});
onSortPressedCallback?.();
// We want to explicitly clear stale rawQuery since it’s only used for manually typed-in queries.
// We want to explicitly clear stale rawQuery since it's only used for manually typed-in queries.
navigation.setParams({q: newQuery, rawQuery: undefined});
};

Expand Down
3 changes: 2 additions & 1 deletion src/components/Search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ type SearchCustomColumnIds =
| ValueOf<typeof CONST.SEARCH.TYPE_CUSTOM_COLUMNS.EXPENSE_REPORT>
| ValueOf<typeof CONST.SEARCH.GROUP_CUSTOM_COLUMNS.CARD>
| ValueOf<typeof CONST.SEARCH.GROUP_CUSTOM_COLUMNS.FROM>
| ValueOf<typeof CONST.SEARCH.GROUP_CUSTOM_COLUMNS.WITHDRAWAL_ID>;
| ValueOf<typeof CONST.SEARCH.GROUP_CUSTOM_COLUMNS.WITHDRAWAL_ID>
| ValueOf<typeof CONST.SEARCH.GROUP_CUSTOM_COLUMNS.CATEGORY>;

type SearchContextData = {
currentSearchHash: number;
Expand Down

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB:follow-up:

All of these ListItemHeader components are very similar. I would like to see us refactor these to use a BaseListItemHeader component.

Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import React from 'react';
import {View} from 'react-native';
import Checkbox from '@components/Checkbox';
import type {SearchColumnType} from '@components/Search/types';
import type {ListItem, TransactionCategoryGroupListItemType} from '@components/SelectionListWithSections/types';
import TextWithTooltip from '@components/TextWithTooltip';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import ExpandCollapseArrowButton from './ExpandCollapseArrowButton';
import TextCell from './TextCell';
import TotalCell from './TotalCell';

type CategoryListItemHeaderProps<TItem extends ListItem> = {
/** The category currently being looked at */
category: TransactionCategoryGroupListItemType;

/** Callback to fire when a checkbox is pressed */
onCheckboxPress?: (item: TItem) => void;

/** Whether this section items disabled for selection */
isDisabled?: boolean | null;

/** Whether selecting multiple transactions at once is allowed */
canSelectMultiple: boolean | undefined;

/** Whether all transactions are selected */
isSelectAllChecked?: boolean;

/** Whether only some transactions are selected */
isIndeterminate?: boolean;

/** Callback for when the down arrow is clicked */
onDownArrowClick?: () => void;

/** Whether the down arrow is expanded */
isExpanded?: boolean;

/** The visible columns for the header */
columns?: SearchColumnType[];
};

function CategoryListItemHeader<TItem extends ListItem>({
category: categoryItem,
onCheckboxPress,
isDisabled,
canSelectMultiple,
isSelectAllChecked,
isIndeterminate,
isExpanded,
onDownArrowClick,
columns,
}: CategoryListItemHeaderProps<TItem>) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {isLargeScreenWidth} = useResponsiveLayout();
const {translate} = useLocalize();
// formattedCategory is pre-decoded in SearchUIUtils, just translate empty values
const rawCategory = categoryItem.formattedCategory ?? categoryItem.category;
const categoryName = !rawCategory || rawCategory === CONST.SEARCH.CATEGORY_EMPTY_VALUE ? translate('reportLayout.uncategorized') : rawCategory;

const columnComponents = {
[CONST.SEARCH.TABLE_COLUMNS.GROUP_CATEGORY]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.GROUP_CATEGORY}
style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.CATEGORY)}
>
<View style={[styles.gap1, styles.flexShrink1]}>
<TextWithTooltip
text={categoryName}
style={[styles.optionDisplayName, styles.sidebarLinkTextBold, styles.pre, styles.fontWeightNormal]}
/>
</View>
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.GROUP_EXPENSES]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.GROUP_EXPENSES}
style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.EXPENSES)}
>
<TextCell text={String(categoryItem.count)} />
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL}
style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TOTAL, false, false, false, false, false, false, false, true)}
>
<TotalCell
total={categoryItem.total}
currency={categoryItem.currency}
/>
</View>
),
};

return (
<View>
<View style={[styles.pv1Half, styles.pl3, styles.flexRow, styles.alignItemsCenter, isLargeScreenWidth ? styles.gap3 : styles.justifyContentStart]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mnh40, styles.flex1, styles.gap3]}>
{!!canSelectMultiple && (
<Checkbox
onPress={() => onCheckboxPress?.(categoryItem as unknown as TItem)}
isChecked={isSelectAllChecked}
isIndeterminate={isIndeterminate}
disabled={!!isDisabled || categoryItem.isDisabledCheckbox}
accessibilityLabel={translate('common.select')}
style={isLargeScreenWidth && styles.mr1}
/>
)}
{!isLargeScreenWidth && (
<View style={[styles.flexRow, styles.flex1, styles.gap3]}>
<View style={[styles.gap1, styles.flexShrink1]}>
<TextWithTooltip
text={categoryName}
style={[styles.optionDisplayName, styles.sidebarLinkTextBold, styles.pre, styles.fontWeightNormal]}
/>
</View>
</View>
)}
{isLargeScreenWidth && columns?.map((column) => columnComponents[column as keyof typeof columnComponents])}
</View>
{!isLargeScreenWidth && (
<View style={[styles.flexShrink0, styles.ml2, styles.mr3, styles.gap1]}>
<TotalCell
total={categoryItem.total}
currency={categoryItem.currency}
/>
{!!onDownArrowClick && (
<ExpandCollapseArrowButton
isExpanded={isExpanded}
onPress={onDownArrowClick}
/>
)}
</View>
)}
</View>
</View>
);
}

export default CategoryListItemHeader;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {SearchGroupBy} from '@components/Search/types';
import type {
ListItem,
TransactionCardGroupListItemType,
TransactionCategoryGroupListItemType,
TransactionGroupListItemProps,
TransactionGroupListItemType,
TransactionListItemType,
Expand All @@ -39,6 +40,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import {isActionLoadingSetSelector} from '@src/selectors/ReportMetaData';
import type {ReportAction, ReportActions} from '@src/types/onyx';
import CardListItemHeader from './CardListItemHeader';
import CategoryListItemHeader from './CategoryListItemHeader';
import MemberListItemHeader from './MemberListItemHeader';
import ReportListItemHeader from './ReportListItemHeader';
import TransactionGroupListExpandedItem from './TransactionGroupListExpanded';
Expand Down Expand Up @@ -66,6 +68,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
isDEWBetaEnabled,
}: TransactionGroupListItemProps<TItem>) {
const groupItem = item as unknown as TransactionGroupListItemType;

const theme = useTheme();
const styles = useThemeStyles();
const {translate, formatPhoneNumber} = useLocalize();
Expand Down Expand Up @@ -280,6 +283,19 @@ function TransactionGroupListItem<TItem extends ListItem>({
isExpanded={isExpanded}
/>
),
[CONST.SEARCH.GROUP_BY.CATEGORY]: (
<CategoryListItemHeader
category={groupItem as TransactionCategoryGroupListItemType}
onCheckboxPress={onCheckboxPress}
isDisabled={isDisabledOrEmpty}
columns={columns}
canSelectMultiple={canSelectMultiple}
isSelectAllChecked={isSelectAllChecked}
isIndeterminate={isIndeterminate}
onDownArrowClick={onExpandIconPress}
isExpanded={isExpanded}
/>
),
};

if (searchType === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) {
Expand Down
18 changes: 18 additions & 0 deletions src/components/SelectionListWithSections/SearchTableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ const getTransactionGroupHeaders = (groupBy: SearchGroupBy, icons: SearchHeaderI
translationKey: 'common.total',
},
];
case CONST.SEARCH.GROUP_BY.CATEGORY:
return [
{
columnName: CONST.SEARCH.TABLE_COLUMNS.GROUP_CATEGORY,
translationKey: 'common.category',
isColumnSortable: true,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.GROUP_EXPENSES,
translationKey: 'common.expenses',
isColumnSortable: true,
},
{
columnName: CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL,
translationKey: 'common.total',
isColumnSortable: true,
},
];
default:
return [];
}
Expand Down
Loading
Loading