Skip to content

[Payment due @truph01] fix: Add Contains / Equal to match type for the Merchant filter [80823] - #83733

Merged
neil-marcellini merged 92 commits into
Expensify:mainfrom
HiepPP:fix/80823-merchant-contains-operator
Oct 14, 2026
Merged

neil-marcellini merged 92 commits into
Expensify:mainfrom
HiepPP:fix/80823-merchant-contains-operator

Conversation

@HiepPP

@HiepPP HiepPP commented Feb 27, 2026 •

Copy link
Copy Markdown

Fixed Issues

$ #80823
PROPOSAL: #80823 (comment)

Explanation of Change

Expenses with different merchants (e.g. "I" and "Ig") were grouped together in the Top Merchants view, because the merchant filter only did partial matching. This PR adds a match type to the Merchant filter so users can choose between a partial and an exact match.

Changes:

  1. Added a Contains / Equal to match type selector to the Merchant filter, both in the filter chip popup and on the advanced filters page. Contains is the default. The selector is hidden when the filter is negated ("Is not").
  2. Search syntax for merchant:
    • merchant= → exact match (Equal to)
    • merchant*: → partial match (Contains)
    • merchant: → still a partial match, so existing saved searches and typed queries keep their current behavior
    • -merchant: → unchanged (exclusion)
  3. Added the *: (contains) operator to the search parser grammar (baseRules.peggy, searchParser.peggy, autocompleteParser.peggy) and regenerated the parsers. *: is only accepted for merchant; on other keys it falls back to a keyword search.
  4. Merchant group drill-downs (Top Merchants chart and group rows) and merchant group exports now use merchant=, so a group only shows its own merchant.
  5. The filter chip shows the selected match type, e.g. Contains "Ig" or Equal to "Ig".
  6. Added unit and UI tests for the parser, query building, filter updates, the filter popup, and the advanced filters page.

Tests

Match type on the advanced filters page

  1. Go to Reports > Expenses.
  2. Create expenses with merchants "I", "Ig", and "Igloo".
  3. Click Filters > Merchant.
  4. Verify the match type list shows Contains (selected by default) and Equal to.
  5. Enter Ig, keep Contains, and save. Then click View results.
  6. Verify the search query contains merchant*:Ig (or merchant:Ig), and "Ig" and "Igloo" are shown.
  7. Open Filters > Merchant again, select Equal to, and save. Then click View results.
  8. Verify the query contains merchant=Ig and only "Ig" is shown.

Match type in the filter chip

  1. In the search filter bar, open the Merchant filter chip.
  2. Enter Ig, select Equal to, and apply.
  3. Verify the chip label shows Equal to "Ig" and only "Ig" is shown.
  4. Open the chip again, switch to Contains, and apply.
  5. Verify the chip label shows Contains "Ig", and "Ig" and "Igloo" are shown.

Negated filter

  1. Open Filters > Merchant and switch the filter to "Is not".
  2. Verify the match type list is hidden.
  3. Enter Ig and apply. Verify the query contains -merchant:Ig and "Ig" is excluded.

Merchant group drill-down

  1. Open a Top Merchants view (group by merchant).
  2. Click the "I" group.
  3. Verify only expenses with the merchant "I" are shown (not "Ig" or "Igloo"), and the query contains merchant="I".
  4. Go back, select the "I" group, and export it to CSV. Verify the file contains only "I" expenses.

Small screen with the keyboard open

  1. On a small screen, open the Merchant filter chip and focus the input so the keyboard opens.
  2. Verify the match type list and the input stay visible and can scroll.
  3. Repeat on Filters > Merchant on the advanced filters page.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline.
  2. Repeat the "Match type on the advanced filters page" and "Match type in the filter chip" steps.
  3. Verify the match type selection, the chip label, and the search query are updated.

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 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-chrome-compressed.mp4
iOS: Native
ios-native-compressed.mp4
iOS: mWeb Safari
ios-mweb-safari-compressed.mp4
MacOS: Chrome / Safari
macos-chrome-compressed.mp4

Switch merchant filter from : (eq) to *: (contains) operator to preserve
partial-matching UX when backend starts respecting eq vs contains distinction.

Changes:
- Add *: operator support to parser grammar (baseRules.peggy)
- Regenerate searchParser.js and autocompleteParser.js
- Update buildQueryStringFromFilterFormValues to use *: for merchant
- Update unit test expectations

Fixes Expensify#80823
@HiepPP
HiepPP requested review from a team as code owners February 27, 2026 17:17
@melvin-bot
melvin-bot Bot requested review from heyjennahay and removed request for a team February 27, 2026 17:17
@github-actions

github-actions Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@melvin-bot
melvin-bot Bot requested review from mollfpr and removed request for a team February 27, 2026 17:18
@melvin-bot

melvin-bot Bot commented Feb 27, 2026

Copy link
Copy Markdown

@mollfpr 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]

@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: e98c1cb565

ℹ️ 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/SearchParser/autocompleteParser.js Outdated
Comment thread src/libs/SearchQueryUtils.ts Outdated
@HiepPP

HiepPP commented Feb 27, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

CLABotify added a commit to Expensify/CLA that referenced this pull request Feb 27, 2026
@HiepPP HiepPP changed the title fix: Use contains operator for merchant filter [80823] fix: Use contains operator for merchant filter [80823] [No QA] Feb 27, 2026
@truph01

truph01 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

@HiepPP Please address all AI's suggestions above.

Also, your PR author checklist doesn't include videos. Please update it.

@truph01

truph01 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

@HiepPP Since it is your first PR, please follow this rule:

Contributors should not submit proposals on issues when they have assigned issues or PRs that are awaiting an action from them. If so, they will be in violation of Rule #1 (Get Shit Done) in our Code of Conduct and will receive a warning. Multiple warnings can lead to removal from the program.

@HiepPP

HiepPP commented Mar 2, 2026

Copy link
Copy Markdown
Author

@HiepPP Since it is your first PR, please follow this rule:

Contributors should not submit proposals on issues when they have assigned issues or PRs that are awaiting an action from them. If so, they will be in violation of Rule #1 (Get Shit Done) in our Code of Conduct and will receive a warning. Multiple warnings can lead to removal from the program.

Thank you for mentioning the rule. I will also update PR tonight.

@mollfpr
mollfpr requested review from truph01 and removed request for mollfpr March 2, 2026 14:28
@HiepPP

HiepPP commented Mar 3, 2026

Copy link
Copy Markdown
Author

@truph01 I've addressed your feedback:

  • ✅ Uploaded video demonstration showing Top Merchants fix
  • ✅ All Codex AI suggestions addressed in commit 0a79d4c
  • ✅ PR author checklist updated with video links

Please re-review when you have a chance. Thanks!!

@HiepPP

HiepPP commented Mar 9, 2026

Copy link
Copy Markdown
Author

Hi @heyjennahay and @truph01,

I wanted to follow up on PR #83733 which has been open for about a week. This PR fixes issue #80823 where expenses with different merchants (e.g., "I" and "Ig") were incorrectly grouped together in the "Top Merchants" view.

Summary of changes:

  • Added a new *: (contains) operator to the search parser for partial matching
  • Updated merchant filters to use merchant*:value instead of merchant:value
  • All 115 tests pass, including new tests for the sort reset functionality

CI status: All checks passing (CLA, license, security)

The PR is ready for review when you have a moment. Let me know if you need any clarification on the implementation.

Thanks!

@truph01

truph01 commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Switch merchant filter from : (eq) to *: (contains) operator to preserve
partial-matching UX when backend starts respecting eq vs contains distinction.

- Add *: operator support to parser grammar
- Update buildQueryStringFromFilterFormValues to use *: for merchant
- Update unit test expectations

Fixes Expensify#80823
@HiepPP
HiepPP force-pushed the fix/80823-merchant-contains-operator branch from 48d7f11 to 167132a Compare March 10, 2026 11:16
@HiepPP

HiepPP commented Mar 11, 2026

Copy link
Copy Markdown
Author

thank @truph01 I've signed the commit with GPG

@truph01

truph01 commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

@HiepPP Could you help to merge main?

@truph01

truph01 commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot This PR focuses on updating the merchant filter to take two operators: contains and eq. For the normal merchant filter to pass, it must contain. However, when searching for individual groups, we would pass the merchant eq.

Please help review it.

@MelvinBot

Copy link
Copy Markdown
Contributor

Code Review

I reviewed the hand-written changes in this PR (the grammar, query utils, and tests). Here are my findings:

Core Logic (SearchQueryUtils.ts) - Looks correct

The change at SearchQueryUtils.ts:691-698 correctly branches on the merchant filter:

  • Non-negated merchant → uses *: (contains) for partial matching in the Advanced Filters form
  • Negated merchant → uses : (eq) so the - prefix + eq correctly becomes neq in the parser

This handles the round-trip serialization properly - when parsed back, the contains operator maps back to *: via operatorToCharMap.

The "Top Merchants" group drill-down at SearchUIUtils.ts (buildSpecificGroupQuery) separately uses EQUAL_TO, so clicking a specific merchant group still produces an exact-match merchant: query. This is the correct distinction.

Grammar (baseRules.peggy) - Looks correct

The *: operator is added as a higher-priority alternative before ":" / "=" in the operator rule, and expectingNestedQuote is correctly updated to support quoted merchant names with the contains operator.

Concerns

  1. Peggy version upgrade (4.0.3 → 5.0.6): The generated parser files (autocompleteParser.js and searchParser.js) account for ~4,970 of the ~4,994 changed lines. The PR description does not mention this upgrade and package.json wasn't changed, so it appears the parsers were regenerated with a locally-installed Peggy 5.0.6 rather than the project's pinned version. This is risky because:

    • It makes reviewing the generated output essentially impossible (the diff is noise)
    • Peggy major/minor bumps can change parser behavior in subtle ways
    • Other contributors regenerating the parsers with the project's pinned Peggy version would produce different output

    Recommendation: Regenerate the parsers using the project's existing Peggy version (4.0.3) so the diff only reflects the *: grammar addition. If the Peggy upgrade is intentionally desired, it should be done as a separate PR with its own review.

  2. Missing test for negated merchant: The existing tests verify merchant*:Amazon for non-negated filters, but there's no test asserting that a negated merchant produces merchant:Amazon (with the : eq operator, not *:). Adding a test case for buildQueryStringFromFilterFormValues with a negated merchant filter value would protect the negation logic from regressions.

  3. buildFilterValuesString aggregation: The allowedOps set at line 197 only includes eq and neq. If multiple merchant values with the contains operator are present in the AST, they won't be comma-aggregated - each will produce its own merchant*:value segment. Verify this is the intended behavior for multi-value merchant filters.

Summary

The hand-written logic is sound and correctly addresses the issue. The main concern is the unintentional Peggy version upgrade inflating the diff. I'd recommend regenerating with the pinned Peggy 4.0.3 and adding a negated-merchant test case.

@HiepPP

HiepPP commented Oct 14, 2026

Copy link
Copy Markdown
Author

hi @neil-marcellini @luacmartins I merged the latest main and fixed the conflicts. Could you please review again? Thank you

@HiepPP
HiepPP requested a review from luacmartins October 14, 2026 09:45
@neil-marcellini

Copy link
Copy Markdown
Contributor

Shoot @HiepPP this is getting a lot of conflicts. I think we should coordinate on timing so we can get this merged without more back and forth.

I'm usually working 6:30 am to about 4:00 pm PDT. How about you and when would be a good time for you to update and for me to approve?

…ntains-operator

# Conflicts:
#	src/hooks/useSearchBulkActions.ts
@HiepPP

HiepPP commented Oct 14, 2026

Copy link
Copy Markdown
Author

hi @neil-marcellini I just merged the latest main and fixed the conflicts in 37fd19d, there are no conflicts right now

@neil-marcellini
neil-marcellini merged commit 0c38154 into Expensify:main Oct 14, 2026
36 of 37 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

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

@francoisl francoisl mentioned this pull request Oct 14, 2026
38 tasks done
@OSBotify

Copy link
Copy Markdown
Contributor

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

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

@MelvinBot

Copy link
Copy Markdown
Contributor

A help site update is needed. I opened a draft PR: Docs updates for E/A#83733 Document merchant= operator for exact merchant matches.

This PR adds a new feature with no beta gate: exact merchant matching with merchant= (the Equal to match type). In Use Search Operators to Filter and Analyze, the operator table listed only merchant:. The docs PR edits that one row to cover merchant: (contains) and merchant= (exact match). No other changes.

The docs PR has the HelpDot label. GitHub wouldn't let me assign it to HiepPP because the account isn't assignable on this repo. Comment on the docs PR or ask an internal engineer to assign it.

@HiepPP, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #104133 was identified to be related to this PR.

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #104147 was identified to be related to this PR.

@OSBotify

Copy link
Copy Markdown
Contributor

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

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

@MelvinBot

Copy link
Copy Markdown
Contributor

A help site update is needed, and the draft docs PR already exists: [No QA] Docs updates for E/A#83733 Document merchant= operator for exact merchant matches. I didn't open a second one.

It edits one row in the expense operators table of "Use Search Operators to Filter and Analyze". The row now covers merchant: (contains) and merchant= (exact match, the Equal to option). The PR is labeled HelpDot.

The two deploy blockers filed against this PR are bugs: [$175] Android - Spend - Merchant filter modal only shows Merchant title and Apply button and [$175] Spend-Expense appears in Spend results despite not matching the applied merchant filter. Neither changes the documented behavior, and the feature is still on main. If this PR is reverted, close the docs PR.

GitHub still won't let me assign the docs PR to HiepPP, because the account isn't assignable on this repo. A comment on the docs PR or an internal engineer can fix that.

@HiepPP, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.5.12-1 🚀

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

Bundle Size Analysis (Sentry):

@melvin-bot

melvin-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #104212

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.