Skip to content

Fix custom report field disappearing for submitter after report approval#95337

Open
MelvinBot wants to merge 5 commits into
mainfrom
claude-reportFieldsDisappearAfterApproval
Open

Fix custom report field disappearing for submitter after report approval#95337
MelvinBot wants to merge 5 commits into
mainfrom
claude-reportFieldsDisappearAfterApproval

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

A custom report field disappeared for the submitter once a single-expense report was approved.

For a single-expense report, MoneyReportView is mounted with isCombinedReport = true, and the whole report-fields block is gated by (!isCombinedReport || !isOnlyTitleFieldEnabled). The problem was that isOnlyTitleFieldEnabled was derived from enabledReportFields, which filtered fields by editability (isReportFieldDisabled) rather than presence:

  • After approval, isReportFieldDisabled returns true for every field for a non-admin submitter (the isApproved branch), so the custom (non-formula) field was dropped from enabledReportFields.
  • The default title field is a FORMULA field, which survives via the || type === FORMULA clause, so enabledReportFields collapsed to just the title → isOnlyTitleFieldEnabled flipped to true → the combined-view gate hid the entire section, including the still-present custom field.

The field data was never lost — this was purely a display gate that conflated "field is editable" with "field should be shown". A field that merely became read-only after approval should still display.

Fix: compute isOnlyTitleFieldEnabled from field presence using the already-imported shouldHideSingleReportField predicate (which hides the title field and list fields with no enabled option) instead of from editability. This is the same predicate the render loop and the existing shouldShowReportField divider check already use, so the section now stays visible with a still-present custom field (shown read-only) after approval, while a workspace whose only configured field is the title still correctly hides the redundant section in the combined view. The same change is applied to the sibling MoneyRequestViewReportFields for consistency. Removing the editability dependency also made the || type === FORMULA special-case and the isReportFieldDisabled/isReportFieldOfTypeTitle imports unnecessary in these components.

Added regression tests in tests/ui/MoneyReportViewTest.tsx that assert a custom field stays visible for a non-admin submitter on an approved combined report, and that a title-only workspace still hides the section in the combined view.

Fixed Issues

$ #93824
PROPOSAL: #93824 (comment)

Tests

  1. Set up two accounts (an approver and an employee) on a workspace that has a custom report field enabled.
  2. As the employee, create a new single-expense report and select a value for the custom field.
  3. Submit the report and confirm the custom field is still shown.
  4. As the approver, approve the report.
  5. As the submitter, open the report and verify the custom report field is still displayed (read-only) and did not disappear.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests.

QA Steps

  1. Set up two accounts (an approver and an employee) on a workspace that has a custom report field enabled.
  2. As the employee, create a new single-expense report and select a value for the custom field, then submit it.
  3. As the approver, approve the report.
  4. As the submitter, open the report and verify the custom report field is still displayed (read-only) and did not disappear.
  • 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 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 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 Avatar are working as expected)
  • 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.
  • 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: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

MelvinBot and others added 3 commits July 5, 2026 13:11
Co-authored-by: Pujan Shah <Pujan92@users.noreply.github.com>
Co-authored-by: Pujan Shah <Pujan92@users.noreply.github.com>
Co-authored-by: Pujan Shah <Pujan92@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I looked into the failing checks. No code fix is needed — every functional check passes.

The only failing check is checklist (PR Author Checklist), which fails because the checklist boxes in the PR description aren't ticked:

You completed 0 out of 41 checklist items with 41 unfinished items
PR Author Checklist is not completely filled out.

This isn't a code issue and pushing a commit won't resolve it — it just needs you (the PR author) to review and check the boxes in the PR description. Once they're filled in, this check will pass.

All other checks are green: typecheck, all 8 test jobs, build variants, ESLint, Oxfmt, Storybook tests, perf tests, spellcheck, and Bun tests.

Comment on lines 167 to 168

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.

Suggested change
!sortedPolicyReportFields.every(shouldHideSingleReportField)

@MelvinBot can we simplify these conditions?

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.

(!isCombinedReport || !isOnlyTitleFieldEnabled) && !sortedPolicyReportFields.every(shouldHideSingleReportField);

I mean, we may not need two conditions as a single condition looks to cover both cases(combine or not-combine reports)

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.

Yes — your suggestion is correct, it's the absorption law. Since isOnlyTitleFieldEnabled is defined as sortedPolicyReportFields.every(shouldHideSingleReportField), the last two clauses of shouldShowReportField are:

(!isCombinedReport || !isOnlyTitleFieldEnabled) && !isOnlyTitleFieldEnabled

which collapses to just !isOnlyTitleFieldEnabled ((A || B) && B === B). So rather than re-inlining the .every(...), I'd reuse the named variable:

Suggested change
!isOnlyTitleFieldEnabled;

giving:

const shouldShowReportField =
    !isClosedExpenseReportWithNoExpenses &&
    (isGroupPolicyExpenseReport || isInvoiceReport) &&
    !!policy?.areReportFieldsEnabled &&
    !isOnlyTitleFieldEnabled;

Bonus — the sibling can be simplified further. In MoneyRequestViewReportFields.tsx, sortedPolicyReportFields is already .filter(field => !shouldHideSingleReportField(field)), so isOnlyTitleFieldEnabled is true only when the array is empty — i.e. it's identical to !sortedPolicyReportFields.length, which is already checked in the early return. Working through the same absorption, the isCombinedReport term and isOnlyTitleFieldEnabled are both redundant, and it reduces to:

const shouldDisplayReportFields = (isGroupPolicyExpenseReport || isInvoiceReport) && !!policy?.areReportFieldsEnabled;

if (!shouldDisplayReportFields || !sortedPolicyReportFields.length) {
    return null;
}

letting you drop isOnlyTitleFieldEnabled entirely there.

Want me to push these? Reply @MelvinBot implement this and I'll apply both.

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.

@MelvinBot implement this

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.

Done — pushed in ff93af8.

  • MoneyReportView.tsx: shouldShowReportField now ends in !isOnlyTitleFieldEnabled (the (!isCombinedReport || …) clause was absorbed).
  • MoneyRequestViewReportFields.tsx: dropped isOnlyTitleFieldEnabled entirely — since sortedPolicyReportFields is pre-filtered, the empty-list early return already covers it. No caller ever passed isCombinedReport, so I removed that dead prop too.

Verified: oxfmt, eslint (both files), typecheck-tsgo, React Compiler compliance, and tests/ui/MoneyReportViewTest.tsx (13/13 passing).

@MelvinBot

Copy link
Copy Markdown
Contributor Author

I re-checked — the situation is unchanged. The only failing check is still checklist (PR Author Checklist), and it's not a code issue that a commit can fix.

This check fails because the author checklist boxes in the PR description aren't ticked ("You completed 0 out of 41 checklist items"). It will keep failing on every re-run until you (the PR author) review and check the boxes in the PR description.

Every functional check is green: typecheck, all 8 test jobs, all build variants, ESLint, Oxfmt, Storybook tests, perf tests, spellcheck, and Bun tests. There's nothing for me to push.

@MelvinBot MelvinBot marked this pull request as ready for review July 5, 2026 14:05
@MelvinBot MelvinBot requested a review from a team as a code owner July 5, 2026 14:05
@melvin-bot melvin-bot Bot requested review from Pujan92 and heyjennahay July 5, 2026 14:05
@melvin-bot

melvin-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

@Pujan92 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 request for a team July 5, 2026 14:05
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Done — PR #95337 is now marked Ready for review. PullerBear will assign the engineering reviewer.

A heads-up for the reviewer: the human-only sections of the PR body still have unchecked boxes (the Tests/QA step confirmations, PR Author Checklist, and platform screenshots). Those should be completed/verified before merge.

// and list fields with no enabled option, so if it's true for every field then only the title field remains.
const isOnlyTitleFieldEnabled = sortedPolicyReportFields.every(shouldHideSingleReportField);
const isClosedExpenseReportWithNoExpenses = isClosedExpenseReportWithNoExpensesReportUtils(report);
const isGroupPolicyExpenseReport = isGroupPolicyExpenseReportUtils(report);

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.

❌ CONSISTENCY-3 (docs)

After this change isOnlyTitleFieldEnabled is defined as sortedPolicyReportFields.every(shouldHideSingleReportField), which is exactly the expression still repeated inside shouldShowReportField on the line !sortedPolicyReportFields.every(shouldHideSingleReportField). That term now duplicates the derived isOnlyTitleFieldEnabled — and the same shouldShowReportField expression already includes !isOnlyTitleFieldEnabled, so the .every(...) call recomputes an identical predicate over the same array.

Reuse the derived value instead of recomputing it. Since shouldShowReportField already contains (!isCombinedReport || !isOnlyTitleFieldEnabled), the extra .every(...) term collapses to !isOnlyTitleFieldEnabled and can be dropped:

const isOnlyTitleFieldEnabled = sortedPolicyReportFields.every(shouldHideSingleReportField);
// ...
const shouldShowReportField =
    !isClosedExpenseReportWithNoExpenses &&
    (isGroupPolicyExpenseReport || isInvoiceReport) &&
    !!policy?.areReportFieldsEnabled &&
    (!isCombinedReport || !isOnlyTitleFieldEnabled) &&
    !isOnlyTitleFieldEnabled;

(the last two lines can be merged into a single !isOnlyTitleFieldEnabled).


Reviewed at: 42604eb | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Collapse the redundant report-field-visibility clauses. In MoneyReportView,
(!isCombinedReport || !isOnlyTitleFieldEnabled) && !every(shouldHideSingleReportField)
reduces to !isOnlyTitleFieldEnabled by absorption. In MoneyRequestViewReportFields,
sortedPolicyReportFields is already filtered by shouldHideSingleReportField and
isCombinedReport is never passed, so isOnlyTitleFieldEnabled and the unused
isCombinedReport prop are dropped; the empty-list early return covers the case.

Co-authored-by: Pujan Shah <Pujan92@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner July 5, 2026 14:18
@melvin-bot melvin-bot Bot requested review from JS00001 and removed request for a team July 5, 2026 14:19
@melvin-bot

melvin-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

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

@Pujan92

Pujan92 commented Jul 5, 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 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 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 and each prop has a /** comment above it */
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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 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 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
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-07-06.at.16.03.59.mov

Comment on lines +154 to +157
// Whether the only report field configured for this report is the title field. This must be based on which fields are
// present/displayable, not on which are currently editable: after approval every field becomes read-only for the
// submitter, but a still-present custom field should keep showing. `shouldHideSingleReportField` hides the title field
// and list fields with no enabled option, so if it's true for every field then only the title field remains.

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.

@MelvinBot remove the comment from here and also from MoneyRequestViewReportFields as I think it is not needed

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.

Done — removed both comments in 7ddf814.

Comment-only change, no logic touched.

Co-authored-by: Pujan Shah <Pujan92@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

⚠️ MelvinBot CI Fix Loop Detected

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.

1 similar comment
@MelvinBot

Copy link
Copy Markdown
Contributor Author

⚠️ MelvinBot CI Fix Loop Detected

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.

@Pujan92 Pujan92 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.

LGTM!

@JS00001

JS00001 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@Pujan92 please complete author checklist

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.

3 participants