Skip to content

[Payment due @Eskalifer1] Search - Load categories from all workspaces - #96460

Merged
JS00001 merged 32 commits into
Expensify:mainfrom
ShridharGoel:fix/661264-search-category-filters-app
Jul 29, 2026
Merged

JS00001 merged 32 commits into
Expensify:mainfrom
ShridharGoel:fix/661264-search-category-filters-app

Conversation

@ShridharGoel

@ShridharGoel ShridharGoel commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Load lightweight category data for every workspace only when the Category filter opens. Merge it with full category data already stored in Onyx so category rules and optimistic updates remain unchanged.

This makes categories from non-default workspaces available in the Spend filters without increasing the initial Search response. Only the category name and enabled state are merged into the existing policyCategories_ collection to keep the response small.

Companion Auth PR: https://github.com/Expensify/Auth/pull/23042

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/661264
PROPOSAL:

Tests

  1. Sign in with an account that belongs to multiple workspaces, has many categories and has a category unique to a non-default workspace
  2. Open Spend and select Filters > Category
  3. Verify the unique category appears without changing the default workspace
  4. Select one workspace in the Workspace filter
  5. Verify the Category filter only shows categories from that workspace
  6. Clear the Workspace filter and verify categories from all workspaces appear again
  • Verify that no errors appear in the JS console

Offline tests

  1. Complete the online steps so category filter data is stored in Onyx
  2. Go offline and reopen Spend > Filters > Category
  3. Verify the previously loaded categories remain available

QA Steps

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
  • 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 followed proper code patterns (see Reviewing the code)
    • 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 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)
  • 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 that component are working as expected)
  • 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 assets, 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 these changes do not break usages of that component in the rest of the App
  • If the PR modifies a component related to any 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 accessible by a direct deeplink, I verified the code functions as expected when the deeplink is used from logged-in and logged-out accounts.
  • If the PR modifies the UI or form input styles:
    • I verified that all inputs inside a form are aligned.
    • I added the Design label or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for this bug fix.
  • If main was merged into this PR after review, I tested again and verified the expected outcome.

Screenshots/Videos

MacOS: Chrome / Safari
Screen.Recording.2026-07-21.at.12.52.57.AM.mov

Use lightweight search data without replacing full category rules or optimistic state.

Refs Expensify/Expensify#661264
@codecov

codecov Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

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/ONYXKEYS.ts 100.00% <ø> (ø)
...nents/Search/FilterComponents/CategorySelector.tsx 72.72% <100.00%> (+72.72%) ⬆️
...h/SearchPageHeader/SearchAdvancedFiltersButton.tsx 68.00% <100.00%> (+6.09%) ⬆️
...ts/Search/SearchPageHeader/useSearchFiltersBar.tsx 23.43% <100.00%> (+5.10%) ⬆️
src/components/Search/SearchQueryProvider.tsx 100.00% <100.00%> (ø)
src/hooks/useAdvancedSearchFilters.ts 97.50% <100.00%> (-0.42%) ⬇️
src/hooks/useAutocompleteSuggestions.ts 62.94% <100.00%> (+0.18%) ⬆️
src/hooks/useLoadSearchCategoryData.ts 100.00% <100.00%> (ø)
src/hooks/useSearchFilterSync.ts 94.73% <100.00%> (+5.84%) ⬆️
src/libs/API/types.ts 100.00% <ø> (ø)
... and 4 more
... and 15 files with indirect coverage changes

@ShridharGoel
ShridharGoel marked this pull request as ready for review July 22, 2026 18:20
@ShridharGoel
ShridharGoel requested review from a team as code owners July 22, 2026 18:20
@melvin-bot
melvin-bot Bot requested review from Eskalifer1 and removed request for a team July 22, 2026 18:20
@melvin-bot

melvin-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

@Eskalifer1 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 requested review from heyjennahay and removed request for a team July 22, 2026 18:20
@Eskalifer1

Copy link
Copy Markdown
Contributor

Hi @ShridharGoel, let me know if you need my help

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

Copy link
Copy Markdown

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: 5737f96fd5

ℹ️ 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".

Comment thread src/components/Search/FilterComponents/CategorySelector.tsx Outdated
@ShridharGoel

Copy link
Copy Markdown
Contributor Author

@Eskalifer1 You can start reviewing whenever possible

@Eskalifer1

Copy link
Copy Markdown
Contributor

Oh, okay. If it's not urgent, I'll do the review tomorrow. Thanks for waiting!

@Eskalifer1

Copy link
Copy Markdown
Contributor

Hi @ShridharGoel, I wanted to ask if this is the expected behavior. If a user opens a page and immediately tries to enter a category from a non-default workspace in the search bar, nothing will be displayed. I understand that this is expected based on the code, since we load categories only after the filter has been opened, but perhaps this should be noted for the QA team?

2026-07-22.23.22.13.mov

@Eskalifer1

Copy link
Copy Markdown
Contributor

@codex review

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

Copy link
Copy Markdown

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: f3dab42174

ℹ️ 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".

Comment thread src/libs/actions/Search.ts Outdated
@Eskalifer1

Copy link
Copy Markdown
Contributor

This seems like rather strange behavior. If a user has two workspaces with no categories but they are enabled, the filter itself will be displayed, but once the categories are loaded, the filter will simply disappear from the list.

2026-07-22.23.37.39.mov

@Eskalifer1

Copy link
Copy Markdown
Contributor

I'm not sure if we want to fix this, so I'd like to hear your thoughts on it. Here’s what I’m talking about (for the best demonstration, it’s best to be on a slow internet connection, such as 3G):

A user has two workspaces, each with its own categories. If they try to load it for the first time but it fails (the request fails), only the categories from the default workspace will be displayed—as expected— but if they open the filter again later, additional categories will load, this time without any additional information (like a Loader), which cause some categories to simply appear out of nowhere. I think this is okay and not critical, given that it’s more of an edge case, but I’d like to hear your opinion, since you might have more context on this.

2026-07-22.23.45.27.mov

@Eskalifer1

Copy link
Copy Markdown
Contributor

This is also related to the search field, but in this case to the Suggestions. If a user has two workspaces (in my example, each workspace has only one category; the names make it clear which category belongs to which workspace) and they previously searched for both of them, after which the cache was cleared (or something else that caused the category data to be cleared), then when selecting this item from the Suggestions in the filter, only one value will be displayed—from the main workspace—even though the filtering logic actually applies to both categories. After that, if you open the filter, all categories will load, but the value in the filter will still not change

2026-07-23.00.01.44.mov

@Eskalifer1

Eskalifer1 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • 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 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)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
96460-android-native.mov
Android: mWeb Chrome
96460-android-web.mov
iOS: HybridApp
96460-ios-native.mov
iOS: mWeb Safari
96460-ios-web.mov
MacOS: Chrome / Safari
2026-07-27.17.20.45.mov

@ShridharGoel

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review.

If a user opens a page and immediately tries to enter a category from a non-default workspace in the search bar, nothing will be displayed.

  • OpenSearchPage and Search responses do not return all-workspace policyCategories_.
  • category: autocomplete only reads currently cached policyCategories_.
  • OpenSearchCategoryFiltersPage runs only when CategorySelector mounts.

@mountiny @JS00001 Do you know if we are okay with this behaviour? Else, we will need to have openSearchCategoryFiltersPage() when Category autocomplete becomes active.

If a user has two workspaces with no categories but they are enabled

Can you share how you reached this state? Looks like we can't have 0 categories if the categories feature is enabled (it doesn't allow deleting all the categories).

A user has two workspaces, each with its own categories. If they try to load it for the first time but it fails (the request fails), only the categories from the default workspace will be displayed—as expected— but if they open the filter again later, additional categories will load, this time without any additional information (like a Loader), which cause some categories to simply appear out of nowhere. I think this is okay and not critical, given that it’s more of an edge case, but I’d like to hear your opinion, since you might have more context on this.

Yes, I think it is okay. CC: @mountiny @JS00001

@Eskalifer1

Copy link
Copy Markdown
Contributor

Can you share how you reached this state? Looks like we can't have 0 categories if the categories feature is enabled (it doesn't allow deleting all the categories).

Hi @ShridharGoel! You need to disable the Members must categorize all expenses setting; then you'll be able to delete all categories

2026-07-23.09.08.01.mov

Comment thread src/libs/SearchFilterSyncState.ts Outdated
Comment on lines +24 to +26
function resetSearchFilterSyncState() {
lastSyncedQuerySignature = null;
}

@Eskalifer1 Eskalifer1 Jul 28, 2026 •

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.

Do we use resetSearchFilterSyncState only for test? It seems like a bad pattern

@Eskalifer1 Eskalifer1 left a comment •

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.

Is it to be expected that the filter button is now disabled every time a request is executed?

2026-07-28.20.17.01.mov

I don't think that's a good idea. If User has very poor conection he will not be able to open filters

@Eskalifer1

Copy link
Copy Markdown
Contributor

@codex review

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

Copy link
Copy Markdown

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: f80e2fb27f

ℹ️ 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".

Comment thread src/components/Search/FilterComponents/CategorySelector.tsx
Remove the test-only sync reset helper and use the existing signature setter for test isolation.
@ShridharGoel

Copy link
Copy Markdown
Contributor Author

Is it to be expected that the filter button is now disabled every time a request is executed?

Yeah it was done to handle an edge scenario but reverted it now. Should be fine.

@ShridharGoel
ShridharGoel requested a review from Eskalifer1 July 28, 2026 17:52
@Eskalifer1

Copy link
Copy Markdown
Contributor

@codex review

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

Copy link
Copy Markdown

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: 62aaab104c

ℹ️ 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".

Comment thread src/hooks/useLoadSearchCategoryData.ts
@ShridharGoel

Copy link
Copy Markdown
Contributor Author

@Eskalifer1 We can continue with the review, thanks

@Eskalifer1 Eskalifer1 left a comment

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.

Okay, if we are ok to move forward with the current code than LGTM!

@melvin-bot melvin-bot Bot changed the title Search - Load categories from all workspaces [Payment due @Eskalifer1] Search - Load categories from all workspaces Jul 29, 2026
@melvin-bot

melvin-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🎯 @Eskalifer1, thanks for reviewing and testing this PR! 🎉

A payment issue will be created for your review once this PR is deployed to production.
E/E issue linked to the PR - https://www.github.com/Expensify/Expensify/issues/661264.

If payment is not needed (e.g., regression PR review fix etc), react with 👎 to this comment to prevent the payment issue from being created.

Comment thread src/libs/SearchFilterSyncState.ts
@JS00001
JS00001 merged commit cb6715f into Expensify:main Jul 29, 2026
46 checks passed
@OSBotify

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

@github-actions

Copy link
Copy Markdown
Contributor

🚧 JS00001 has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.4.46-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed this PR against the help site articles under docs/articles and no HelpDot changes are required, so I have not created a draft PR.

Why: This change is an internal data-loading optimization — it lazily loads lightweight category data (name + enabled state) from every workspace when the Category filter opens, so categories from non-default workspaces show up in the Spend filters. The diff touches only hooks, actions, ONYXKEYS, and tests; there are no new or renamed UI elements, buttons, tabs, settings, or documented workflows.

The relevant help article — Getting-Started-with-the-Spend-Page.md — already describes the Category filter generically ("Available filters vary based on the selected Type") and never documents a per-workspace limitation. Nothing in the current docs contradicts the new behavior, so there is no claim to correct and no new workflow to add. The same is true for Use-Search-Operators-to-Filter-and-Analyze.md, which documents the category: operator conceptually.

@ShridharGoel, since no docs changes are required, there's no linked help site PR to review. If you'd like the article to explicitly call out that the Category filter now spans all of your workspaces, reply with @MelvinBot create the docs PR and I'll draft that copy and open a draft PR — but it isn't necessary to keep the docs accurate.

@jponikarchuk

Copy link
Copy Markdown

This PR failing because of the issue #97456
This issue is reproducible in: Android ans iOS app

@Eskalifer1

Copy link
Copy Markdown
Contributor

I don't think this is a regression from our PR. I checked, and this bug is reproducible in production—and it only occurs in the mobile layout—so it's an existing bug, not one introduced by this PR.

cc: @ShridharGoel

@ShridharGoel

Copy link
Copy Markdown
Contributor Author

Yeah, that's anyways not marked as a deploy blocker

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.4.46-10 🚀

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

Bundle Size Analysis (Sentry):

@melvin-bot

melvin-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #97539

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