Skip to content

feat: [Insights] [Release 1] Top Categories - Add group-by:category#80333

Merged
neil-marcellini merged 19 commits intoExpensify:mainfrom
TaduJR:feat-Insights-Release-1-Top-Categories-Add-group-by-category
Jan 26, 2026
Merged

feat: [Insights] [Release 1] Top Categories - Add group-by:category#80333
neil-marcellini merged 19 commits intoExpensify:mainfrom
TaduJR:feat-Insights-Release-1-Top-Categories-Add-group-by-category

Conversation

@TaduJR
Copy link
Contributor

@TaduJR TaduJR commented Jan 23, 2026

Explanation of Change

This PR implements the groupBy:category functionality for the Search feature, allowing users to group expenses by category in the Insights view.

Fixed Issues

$ #80034
PROPOSAL: #80034 (comment)

Tests

Prerequisites:

  • Ensure you have expenses with different categories (e.g., "Travel", "Food & Drink", "Office Supplies")
  • Ensure you have some expenses without a category assigned

Test 1: Access Group by Category via Advanced Filters

  1. Open the app and navigate to the Reports page
  2. Go to Expense Section
  3. Tap the filter in the search header
  4. Tap on "Group by" option
  5. Verify "Category" appears in the list of group by options
  6. Select "Category"
  7. Tap "Save"
  8. Verify expenses are now grouped by category with headers showing:
    • Category name (or "No category" for uncategorized expenses)
    • Number of expenses in that category
    • Total amount for that category

Test 2: Verify Category Grouping Display (Large Screen)

  1. Open the app on desktop/web or tablet in landscape mode
  2. Go to Expense Section
  3. Navigate to Search and apply groupBy:category filter
  4. Verify the table header shows: Category icon | Category | Expenses | Total
  5. Verify each category row displays the folder icon, category name, expense count, and total amount
  6. Verify columns are properly aligned between header and rows

Test 3: Verify Category Grouping Display (Small Screen)

  1. Open the app on mobile device
  2. Go to Expense Section
  3. Navigate to Search and apply groupBy:category filter
  4. Verify each category shows the folder icon, category name, and total amount
  5. Tap the expand arrow on a category row
  6. Verify the individual transactions within that category are displayed

Test 4: Verify Empty/No Category Handling

  1. Create an expense without assigning a category
  2. Go to Expense Section
  3. Navigate to Search with groupBy:category
  4. Verify expenses without categories are grouped under "No category"

Test 5: Verify Category Expand/Collapse

  1. Navigate to Search with groupBy:category applied
  2. Tap/click on a category row (e.g., "Travel")
  3. Verify the category row expands to show individual transactions within that category
  4. Tap/click on the category row again
  5. Verify the category row collapses to hide the transactions

Test 6: Verify Sorting

  1. Navigate to Search with groupBy:category
  2. Click on the "Category" column header to sort
  3. Verify categories sort alphabetically (A-Z, then Z-A on second click)
  4. Click on the "Total" column header
  5. Verify categories sort by total amount

Test 7: Verify Multi-select Checkbox

  1. Navigate to Search with groupBy:category
  2. Enable selection mode (long press on mobile, or use bulk select)
  3. Tap the checkbox on a category header row
  4. Verify all transactions within that category become selected
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android-Native.mp4
Android: mWeb Chrome
Android-mWeb.mp4
iOS: Native
iOS-Native.mp4
iOS: mWeb Safari
iOS-Safari.mp4
MacOS: Chrome / Safari
Macbook-Chrome.mp4

@TaduJR TaduJR requested review from a team as code owners January 23, 2026 12:15
@melvin-bot melvin-bot bot requested a review from Ollyws January 23, 2026 12:15
@melvin-bot
Copy link

melvin-bot bot commented Jan 23, 2026

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@melvin-bot melvin-bot bot requested review from heyjennahay and removed request for a team January 23, 2026 12:15
@melvin-bot
Copy link

melvin-bot bot commented Jan 23, 2026

@Ollyws Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot removed the request for review from a team January 23, 2026 12:15
@TaduJR TaduJR marked this pull request as draft January 23, 2026 12:16
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/CONST/index.ts 83.89% <ø> (ø)
...ListWithSections/Search/CategoryListItemHeader.tsx 100.00% <100.00%> (ø)
...stWithSections/Search/TransactionGroupListItem.tsx 75.23% <ø> (ø)
src/pages/Search/SearchColumnsPage.tsx 0.00% <ø> (ø)
src/styles/utils/index.ts 49.41% <100.00%> (+0.66%) ⬆️
src/components/Search/SearchList/index.tsx 2.75% <0.00%> (-0.06%) ⬇️
...ts/SelectionListWithSections/SearchTableHeader.tsx 6.55% <0.00%> (-0.23%) ⬇️
src/components/Search/SearchContext.tsx 34.95% <40.00%> (-0.05%) ⬇️
src/components/Search/index.tsx 31.15% <0.00%> (-0.70%) ⬇️
src/libs/SearchUIUtils.ts 61.54% <61.90%> (+0.59%) ⬆️
... and 2 more
... and 30 files with indirect coverage changes

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 58e977f624

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@puneetlath
Copy link
Contributor

@TaduJR how's this going? Will we have it ready for review today?

@TaduJR
Copy link
Contributor Author

TaduJR commented Jan 23, 2026

@TaduJR how's this going? Will we have it ready for review today?

Yes, @puneetlath wrapping up, adding more unit tests, and reviewing.

Will make it ready in 1/1.5 hr

@TaduJR TaduJR marked this pull request as ready for review January 23, 2026 20:55
@TaduJR
Copy link
Contributor Author

TaduJR commented Jan 23, 2026

Tagging @Expensify/design team since there is usage of icons and other UI additions

@TaduJR
Copy link
Contributor Author

TaduJR commented Jan 23, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17395a0eb4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const areTransactionsEmpty = useRef(true);

// Use a ref to access searchContextData in callbacks without causing callback reference changes
const searchContextDataRef = useRef(searchContextData);
Copy link
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).

@lakchote
Copy link
Contributor

lakchote commented Jan 26, 2026

Getting some weird behavior when I select "Advertising" - it also selected the row for "Advertising renamed"?

Another BE bug

cc @JS00001 @luacmartins I find it odd that we need to modify this filter, given the maturity of the Search page and the impact this would bring (it's easy to now have edge cases if we only allow strict equality - we'd avoid returning results that may matter). Could you please give your opinion here?

@ShridharGoel
Copy link
Contributor

ShridharGoel commented Jan 26, 2026

Another bug, total expenses show 9 but the list has only 7. Might be some BE issue, I'm seeing a similar discrepancy when grouped by "From" as well.

Screenshot 2026-01-26 at 9 30 37 PM

@JS00001
Copy link
Contributor

JS00001 commented Jan 26, 2026

Hmm this is a good point. If we're using this for grouping, we would need to not match with LIKE when we expand the filter.

We're also going to have to consider this for merchant... I dont think we should be removing LIKE, especially for merchant, so we way need to think of a better way to implement this to work, while keeping the current functionality

@puneetlath
Copy link
Contributor

I agree, I think we should fix the BE for equality since we only want to group by distinct categories. But I think if that's the only blocker for this, we can merge this. And have that BE fix done today.

@melvin-bot melvin-bot bot requested a review from neil-marcellini January 26, 2026 22:16
Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

It all looks good to me. I have a couple suggestions to DRY this up for the future.

[CONST.SEARCH.TABLE_COLUMNS.AVATAR]: null,
[CONST.SEARCH.TABLE_COLUMNS.GROUP_BANK_ACCOUNT]: 'bankName' as const,
[CONST.SEARCH.TABLE_COLUMNS.GROUP_WITHDRAWN]: 'debitPosted' as const,
[CONST.SEARCH.TABLE_COLUMNS.WITHDRAWN]: 'debitPosted' as const,
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Why are we adding these?

Comment on lines +894 to +906
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;
}
Copy link
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).

Copy link
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.

@neil-marcellini neil-marcellini merged commit 00cd085 into Expensify:main Jan 26, 2026
32 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/neil-marcellini in version: 9.3.10-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@jponikarchuk
Copy link

This PR failing because of the issue
This issue is reproducible in: Web

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.10-6 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants