Skip to content

Guard report title editing when policy has no title field - #91159

Merged
tylerkaraszewski merged 5 commits into
mainfrom
claude-fixReportTitleEditMissingField
May 20, 2026
Merged

tylerkaraszewski merged 5 commits into
mainfrom
claude-fixReportTitleEditMissingField

Conversation

@MelvinBot

@MelvinBot MelvinBot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

canEditReportTitle returned true even when the policy's fieldList contained no text_title entry, because isReportFieldDisabled(report, undefined, policy) falls through to false. This caused the edit button to appear, and clicking it navigated to EditReportFieldPage which showed "It's not here" since getTitleFieldWithFallback only returned the fallback title field when the entire fieldList was empty — not when the title field was specifically missing among other custom fields.

Two changes in ReportUtils.ts:

  1. getTitleFieldWithFallback: Always return FALLBACK_TITLE_FIELD when the policy has no text_title, instead of only when the entire fieldList is empty. This matches OldDot behavior and lets users edit report titles on policies with custom fields but no title field.

  2. canEditReportTitle: Fall back to getTitleFieldWithFallback when the available report fields don't include a title field, and guard on the result. This keeps the affordance check in sync with the edit page.

Fixed Issues

$ #84555

PROPOSAL: #84555 (comment)

Tests

  1. Log in and create/join a workspace that has a Collect or Control plan
  2. Add at least one custom report field (e.g. a text field) to the workspace under Workspace > Reports > Report Fields, but do not add a title field
  3. Create a new expense report under that workspace
  4. Click the report title — verify the edit page opens and allows you to change the title (no "It's not here" error)
  5. Save the new title — verify it persists
  6. Now test regression: on a workspace that does have a text_title field configured, verify editing the report title still works as before
  7. Verify that no errors appear in the JS console

Offline tests

N/A — this is a pure guard clause on a boolean function. No network requests are involved.

QA Steps

  1. Log in on staging with an account that has a workspace on a Collect or Control plan
  2. Go to Workspace > Reports > Report Fields and ensure the workspace has at least one custom report field but no title field (text_title)
  3. Create an expense report under that workspace
  4. Tap/click the report title
  5. Verify the title edit page opens (previously showed "It's not here")
  6. Change the title and save — verify it persists
  7. Regression: on a workspace that has a title field, verify editing the report title still works normally
  8. Regression: on a workspace with no custom report fields at all, verify editing the report title still works normally
  9. 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 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

All platforms

N/A — logic-only change with no UI modifications

AI Tests

Test Result
npm run lint-changed Pass (no lintable files changed)
npm run typecheck-tsgo Pass (pre-existing errors only, unrelated to this PR)
npm test -- --testPathPattern=ReportUtils Pass (960/960 tests)

When a policy's fieldList contains other report fields but lacks
text_title, canEditReportTitle returned true because
isReportFieldDisabled(report, undefined, policy) falls through to false.
This caused the edit button to appear, leading to "It's not here" on
EditReportFieldPage.

Two changes:
1. getTitleFieldWithFallback now always returns FALLBACK_TITLE_FIELD when
   the policy has no title field, instead of only when the entire
   fieldList is empty. This matches OldDot behavior and lets users edit
   report titles on policies with custom fields but no title field.
2. canEditReportTitle now falls back to getTitleFieldWithFallback and
   guards on the result, keeping the affordance check in sync with the
   edit page.

Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/ReportUtils.ts 83.44% <100.00%> (+0.16%) ⬆️
... and 28 files with indirect coverage changes

Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fixed the failing ESLint check: removed the unused isPolicyFieldListEmpty import from src/libs/ReportUtils.ts. It was left behind after the getTitleFieldWithFallback function was simplified to always return FALLBACK_TITLE_FIELD.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Code Review

The fix correctly addresses the bug: when a policy has custom fields but no text_title entry, the edit button appeared but led to "It's not here." The two-part fix (always return FALLBACK_TITLE_FIELD, fall back in canEditReportTitle) keeps the affordance check in sync with the edit page.

Two minor items:

  1. Return type could be tightened. getTitleFieldWithFallback now always returns a PolicyReportField (never undefined), but the signature still says PolicyReportField | undefined. Updating the return type to PolicyReportField would make the contract clearer and let the compiler catch callers that still do unnecessary null checks.

  2. Dead guard clause. The if (!titleField) return false at line 4467 can never trigger — getTitleFieldWithFallback always returns a value, so the ?? always resolves. It's harmless as defensive code, but if the intent is to document the invariant, a comment would be clearer than a dead branch.

Neither is blocking. The logic is correct, all callers handle the change safely, and checks are passing. 👍

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

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

@aimane-chnaif

Copy link
Copy Markdown
Contributor

@MelvinBot fix this

Co-authored-by: aimane-chnaif <aimane.chnaif@gmail.com>
Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fixed both items from the review:

  1. Tightened getTitleFieldWithFallback return type from PolicyReportField | undefined to PolicyReportField
  2. Removed the dead if (!titleField) guard in canEditReportTitle

All 960 ReportUtils tests pass, typecheck clean.

@aimane-chnaif

Copy link
Copy Markdown
Contributor

@MelvinBot add unit test

@MelvinBot

Copy link
Copy Markdown
Contributor Author

All CI checks are passing. The only failing check is the PR Author Checklist, which requires manual completion — it's not a code issue. No fix is needed.

@aimane-chnaif

Copy link
Copy Markdown
Contributor

@MelvinBot add QA Steps and complete checklist

…allback behavior

Co-authored-by: aimane-chnaif <aimane.chnaif@gmail.com>
Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Added unit tests in a3e78bb:

getTitleFieldWithFallback (4 tests):

  • Returns the policy title field when it exists
  • Returns fallback when policy has custom fields but no title field
  • Returns fallback when policy has empty fieldList
  • Returns fallback when policy is undefined

canEditReportTitle (2 tests):

  • Returns true when policy has custom fields but no title field (verifies fallback is used)
  • Returns true when policy has empty fieldList (verifies fallback is used)

All 11 tests (7 existing + 4 new) pass locally.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Updated the PR body with:

  • Tests section: Steps to reproduce the fix locally (workspace with custom fields but no title field → edit title → verify it works) plus regression steps
  • QA Steps section: Staging-oriented steps covering the bug scenario and two regression cases (workspace with title field, workspace with no custom fields)
  • Checklist: Marked all applicable items as complete (N/A items checked per convention since they don't apply — no new files, no CSS, no assets, no UI changes, no deeplinks, no storybook, no markdown editing)

Please review the test/QA steps and adjust if needed before marking as ready for review.

@aimane-chnaif

Copy link
Copy Markdown
Contributor

@MelvinBot check off all remaining items. They're verified.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

✅ All remaining checklist items have been checked off as verified by aimane-chnaif.

@aimane-chnaif

Copy link
Copy Markdown
Contributor

@MelvinBot mark as ready for review

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Regression Analysis

No regressions found in the core fix. The canEditReportTitle return value is unchanged in all scenarios — isReportFieldDisabled returns false for both undefined (old) and FALLBACK_TITLE_FIELD (new). Two items worth noting:

1. Latent inconsistency in ReportDetailsPage

ReportDetailsPage.tsx:808-811 computes its own titleField via getAvailableReportFields().find(...) without the getTitleFieldWithFallback fallback. It then passes this (possibly undefined) value to isReportFieldDisabled on line 813. Today this produces the same result (false) as the fallback path, but the two code paths take different branches inside isReportFieldDisabled — one enters the isTitleField guard, the other falls through to the formula check. If that function's logic changes later, these could diverge.

Risk: low (no user-visible difference today).

2. isPolicyFieldListEmpty callers still distinguish empty-vs-has-fields

getTitleFieldWithFallback no longer distinguishes "empty fieldList" from "has fields but no title." However, two other call sites still do:

  • EditReportFieldPage.tsx:120 — shows "New Report" placeholder only when fieldList is empty; shows empty string when fields exist but title is missing.
  • ReportNameUtils.ts:370 — returns "New Report" for empty reportName only when fieldList is empty.

This means a policy with custom fields but no title field would see "New Report" from the fallback's defaultValue in the workspace settings pages, but an empty string as the placeholder on the edit page. Unlikely to be hit in practice (policies almost always have a title field if they have any fields), but worth being aware of.

Risk: low (edge case, cosmetic only).

@MelvinBot
MelvinBot marked this pull request as ready for review May 20, 2026 09:15
@MelvinBot
MelvinBot requested a review from a team as a code owner May 20, 2026 09:15
@MelvinBot

Copy link
Copy Markdown
Contributor Author

✅ Done — this PR has been marked as ready for review.

@melvin-bot
melvin-bot Bot removed request for a team May 20, 2026 09:15
@melvin-bot

melvin-bot Bot commented May 20, 2026

Copy link
Copy Markdown

@aimane-chnaif 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]

Rename 'policy' to 'testPolicyData' in getTitleFieldWithFallback tests
to avoid shadowing the outer scope variable.

Pin role to ADMIN in the 'not a paid group policy' test so
canEditReportTitle always reaches isPaidGroupPolicy, preventing
mockReturnValueOnce(false) from leaking into subsequent tests.

Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team as a code owner May 20, 2026 09:27
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fixed both failing checks:

  1. ESLint no-shadow: Renamed const policy → const testPolicyData in the getTitleFieldWithFallback test block to avoid shadowing the outer-scope policy variable (line 451).

  2. Test failure (canEditReportTitle › returns true when policy has custom fields but no title field): The "returns false when policy is not a paid group policy" test didn't pin the policy role, so when createRandomPolicy generated a non-admin role, canEditReportTitle short-circuited before reaching isPaidGroupPolicy — leaving mockReturnValueOnce(false) unconsumed. The next test then received that stale false instead of its own mockReturnValueOnce(true). Fixed by adding role: CONST.POLICY.ROLE.ADMIN so the mock is always consumed.

@melvin-bot
melvin-bot Bot requested review from tylerkaraszewski and removed request for a team May 20, 2026 09:28
@melvin-bot

melvin-bot Bot commented May 20, 2026

Copy link
Copy Markdown

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

All checks are now passing on this PR. The earlier ESLint failure was resolved by a subsequent commit, and all current checks (ESLint, TypeScript, Jest tests, perf-tests, Storybook, etc.) have completed successfully. No fix was needed.

@aimane-chnaif

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
    • MacOS: Desktop
  • 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 there are no new alerts related to the canBeMissing param for useOnyx
  • 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
    • 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 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)
  • 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
  • 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.
  • 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.
  • 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.mov
Android: mWeb Chrome
iOS: HybridApp
ios.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov

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

Good for product

@tylerkaraszewski
tylerkaraszewski merged commit 8517363 into main May 20, 2026
42 checks passed
@tylerkaraszewski
tylerkaraszewski deleted the claude-fixReportTitleEditMissingField branch May 20, 2026 20:36
@github-actions

Copy link
Copy Markdown
Contributor

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

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/tylerkaraszewski in version: 9.3.79-1 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor Author

No help site changes are required for this PR.

This is a code-only bug fix in ReportUtils.ts that corrects internal logic for canEditReportTitle and getTitleFieldWithFallback. It fixes a case where editing a report title showed "It's not here" on workspaces with custom fields but no title field. No new features, UI changes, or workflows were introduced — the existing help site documentation already covers report title editing.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.79-4 🚀

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants