Skip to content

auto select some values of transaction after deletion one of last 2 elements#86932

Merged
lakchote merged 44 commits into
Expensify:mainfrom
mukhrr:fix/86220
Jun 17, 2026
Merged

auto select some values of transaction after deletion one of last 2 elements#86932
lakchote merged 44 commits into
Expensify:mainfrom
mukhrr:fix/86220

Conversation

@mukhrr

@mukhrr mukhrr commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

We have fixed 8 bugs in total in this PR: #86220, #88338 and + 6 bugs found while implementing the PR.

Fixed Issues

$ #86220
#88338
PROPOSAL: #86220 (comment)

Tests

Bug 1:

  1. Create an expense in WS chat
  2. Go to WS settings
  3. Go offline
  4. Disable category
  5. Go back to expense
  • Verify there is "Category no longer valid" violation now

Bug 2:

  1. Create an expense with tag, category and NON-DEFAULT tax in WS chat
  2. Disable all from WS settings
  3. Go to expense details
  • Verify you see related errors in each of tag, category and tax rows
  • And also clicking them shows related Delete confirmation modals

Bug 3

  1. Create an expense with category and default tax in WS chat
  2. Go to WS settings
  3. Disable both category and tax
  4. Go to expense details
  • Verify there is Category no longer valid violation
  1. Click category -> delete row by clicking category
  2. Go to WS setting -> enable both
  3. Go to expense details
  • Verify there is Missing Category violation
  1. Click and select one category
  • Verify there is NO violation on Tax rate row until report loads

Bug 4

  1. Enable tax in WS settings
  2. Create an expense with NON-DEFAULT tax in WS chat
  3. Go to WS settings
  4. Disable tax
  5. Go offline
  6. Go to expense in chat
  • Verify there is "Tax no longer valid" error message in report preview

Bug 5

  1. Create an expense with a category in WS chat
  2. Unselect category
  • Note you see "Missing category" error message
  1. Go to WS settings and disable category
  2. Go to WS chat
  • Verify there is NO "Missing category" error in report preview

Bug 6

  1. Disable categories in WS settings
  2. Create an expense in WS chat
  3. Enable categories
  4. Go to WS chat
  • Verify there is "Missing category" message on report preview

#86220:
Preconditions:

  • Have a workspace with more than 2 tags and categories
  1. Create an expense with tag (for example, Tag 1) and category (Advertising)
  2. Go to WS tags
  3. Delete all tags except one last and make sure it's not in expense. I mean you should delete Tag 1 too
  4. Go to WS categories
  5. Delete all categories except one last and make sure it's not in expense. I mean you should delete Advertising too
  6. Go to expense
  • Verify both in preview and details page, tag and category are auto-selected to the last left tag/category

  • Verify that no errors appear in the JS console

Offline tests

#88338:

  1. Go to workspace settings > Tags
  2. Add "Tag A"
  3. Go to the workspace chat
  4. Create a manual expense using Tag A
  5. Go offline
  6. Go back to workspace settings > Tags and delete "Tag A"
  7. Go back to the workspace chat
  8. Click in the report preview
  9. Click on the back arrow to go back to the workspace chat
  • Verify you see 'Tag no longer valid' violation is not shown in the report preview or expense details.

QA Steps

The 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.mp4
Android: mWeb Chrome
android.mp4
iOS: Native
ios_app.mp4
iOS: mWeb Safari
ios_web.mp4
MacOS: Chrome / Safari
web.mp4

mukhrr added 4 commits April 4, 2026 10:55
# Conflicts:
#	src/libs/actions/TaxRate.ts
#	src/pages/workspace/distanceRates/PolicyDistanceRateDetailsPage.tsx
#	src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx
@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/libs/Violations/ViolationsUtils.ts 78.13% <100.00%> (+0.09%) ⬆️
src/libs/actions/IOU/UpdateMoneyRequest.ts 84.11% <100.00%> (+0.07%) ⬆️
src/libs/actions/Policy/Category.ts 53.04% <100.00%> (+0.43%) ⬆️
src/libs/actions/Policy/Tag.ts 67.84% <100.00%> (+0.34%) ⬆️
...ages/workspace/WorkspaceMoreFeaturesPage/index.tsx 69.20% <ø> (ø)
src/libs/actions/Policy/Policy.ts 71.69% <33.33%> (+0.10%) ⬆️
src/libs/ReportUtils.ts 84.94% <93.33%> (+0.13%) ⬆️
...c/components/ReportActionItem/MoneyRequestView.tsx 72.70% <20.00%> (-2.68%) ⬇️
... and 15 files with indirect coverage changes

@mukhrr mukhrr marked this pull request as ready for review April 27, 2026 05:35
@mukhrr mukhrr requested review from a team as code owners April 27, 2026 05:35
@melvin-bot melvin-bot Bot requested review from hoangzinh and joekaufmanexpensify and removed request for a team April 27, 2026 05:35
@melvin-bot

melvin-bot Bot commented Apr 27, 2026

Copy link
Copy Markdown

@hoangzinh 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 the request for review from a team April 27, 2026 05:35
Comment thread src/libs/ReportUtils.ts Outdated

@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: 84e8ff6d48

ℹ️ 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/ReportUtils.ts Outdated
Comment thread src/libs/ReportUtils.ts Outdated

@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

@hoangzinh

Copy link
Copy Markdown
Contributor

Is this PR ready for review? @mukhrr

@mukhrr

mukhrr commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

Is this PR ready for review? @mukhrr

@hoangzinh yes, it is!

Comment thread src/libs/actions/TaxRate.ts Outdated
@hoangzinh

Copy link
Copy Markdown
Contributor

@MelvinBot please review this PR

@MelvinBot

Copy link
Copy Markdown
Contributor

PR Review

Overall the implementation for category and tag auto-selection looks solid — correct gating on isOpenOrProcessingReport, proper optimistic + failure rollback Onyx updates, and good test coverage with both positive and negative cases (8 new tests). A few items to address:

1. Missing scope: tax rates and distance rates

The approved proposal explicitly covers four fields: categories, tags, distance rates, and tax rates. This PR only implements categories and tags — it looks like tax/distance rate support was added initially then removed. Is that planned for a follow-up PR? If so, please note that in the PR description. If it's expected in this PR, it still needs to be added.

2. !policy guard in TaxRate.ts (re: hoangzinh's comment)

The !policy addition at src/libs/actions/TaxRate.ts:297 is valid — policy is typed OnyxEntry<Policy> (nullable), and the function accesses policy.id and other properties below without a null check. However, this is unrelated to the category/tag auto-selection feature. If it stays, the commit message should note it as a separate fix.

3. Minor: gating comment accuracy

The inline comments say "gated to calls that actually mutate categories" but the check is !isCategoriesUpdateEmpty which triggers on any categoriesUpdate param, even one that only toggles enabled (not a deletion). This is actually correct behavior (the tests confirm it works for disable too), but the comment could be slightly more precise — e.g., "gated to calls that include category updates" rather than "mutate categories."

4. Test quality

The tests are thorough and well-structured — they cover:

  • Category auto-select on delete and disable
  • Single-level tag auto-select on delete and disable
  • No auto-select when >1 option remains
  • No auto-select on approved reports
  • No auto-select when only policy settings change (no category update)
  • No auto-select for multi-level dependent tags

One missing negative test: a transaction whose category is still valid (enabled) should not be auto-selected even when exactly one category remains. This would verify the !optimisticCategories[transaction.category]?.enabled guard.


Next Steps: Please clarify the tax rate / distance rate scope question, and address the minor items above. Reply with @MelvinBot <your feedback> if you'd like further review.

@mukhrr

mukhrr commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

@hoangzinh does Melvin's comment make sense? And are we okay to proceed or you want me to fix minor bugs it mentioned?

Comment thread src/libs/ReportUtils.ts Outdated
@hoangzinh

Copy link
Copy Markdown
Contributor

@hoangzinh does Melvin's comment make sense? And are we okay to proceed or you want me to fix minor bugs it mentioned?

@mukhrr can you check (2) and (3) in Melvin's review feeback?

Comment thread src/libs/actions/Policy/Policy.ts Outdated
// Recompute transaction violations so toggling tax tracking immediately clears/adds the tax violation,
// instead of leaving a stale one until the report reloads.
if (policyData) {
ReportUtils.pushTransactionViolationsOnyxData(onyxData, policyData, {tax: {trackingEnabled: enabled}});

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.

I think we need to pass the optimistic defaultTaxRates here if shouldAddDefaultTaxRatesData is true

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.

Good catch, done. When shouldAddDefaultTaxRatesData is true we optimistically write defaultTaxRates onto the policy, but the recompute was only getting {tax: {trackingEnabled: enabled}} — so getOptimisticPolicyState built a policy with tax tracking on but no rates, making isTaxInPolicy always false and flagging any transaction whose tax code is one of the new default rates as taxOutOfPolicy.

… to Onyx, so isTaxInPolicy is evaluated correctly.
@lakchote

Copy link
Copy Markdown
Contributor

@mukhrr lint is failing

@mukhrr

mukhrr commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

@lakchote done

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

@lakchote lakchote merged commit 68b6930 into Expensify:main Jun 17, 2026
33 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 @lakchote 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/lakchote in version: 9.4.10-0 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed the changes in this PR against the help site files under App/docs/articles.

Help site changes are required. Most of this PR is internal violation-recomputation logic (bug fixes for when categoryOutOfPolicy / tagOutOfPolicy / taxOutOfPolicy / missingCategory violations show or clear), which isn't documented per-violation on the help site. But the PR also adds two new user-facing alertscategoryDisabledAlert ("Category disabled") and tagDisabledAlert ("Tag disabled") — that mirror the existing taxDisabledAlert pattern.

The tax equivalent is already documented in Track Taxes ("What happens if an expense with tax is moved to a workspace where tax tracking is disabled?"), so I added parallel FAQ entries for categories and tags to keep the docs consistent.

Draft help site PR: #93865

It adds:

  • Create Expense Categories → new FAQ: "What happens to an expense if its category is disabled on the workspace?"
  • Create and Manage Expense Tags → new FAQ: "What happens to an expense if its tag is disabled on the workspace?"

⚠️ I couldn't auto-assign you to the draft PR — GitHub drops assignees who don't have write access to Expensify/App. Please self-assign if possible.

@mukhrr, 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 staging by https://github.com/lakchote in version: 9.4.12-0 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Docs review: no help site changes required.

I reviewed the changes in this PR against the help site articles under App/docs/articles and concluded that no updates to HelpDot are needed.

Why: This PR is a set of bug fixes to expense violation display logic plus two new edge-case confirmation modals (Category disabled / Tag disabled). Specifically it:

  • Corrects when Category no longer valid, Tag no longer valid, Missing category, and tax violations appear/clear when a category/tag/tax is disabled or deleted (online and offline).
  • Adds a delete-confirmation prompt when you interact with a category/tag on an expense after that feature has been disabled on the workspace.
  • Auto-selects the last remaining tag/category after the others are deleted.

These changes restore the intended/expected product behavior — they do not introduce, remove, or rename any documented feature, setting label, tab, or workflow. The relevant help articles (Create expense categories, Create and manage expense tags, Track taxes, Require tags and categories for expenses) document how to set up and enable/disable these features, but do not document the in-expense violation messaging or confirmation dialogs that this PR touches. Their content remains accurate, so there is nothing to add or correct.

@mukhrr, if you'd like the help site to start documenting the violation messages a member sees when a category/tag/tax becomes invalid (which would be a net-new doc rather than a change required by this PR), let me know and I can draft that separately. Otherwise, no draft help site PR was created since none is needed.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/lakchote in version: 9.4.14-0 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Correction to my previous comment — help site changes are required, and a draft PR already exists.

My earlier comment in this session (no help site changes required) was wrong. I missed that this PR's two new alerts — categoryDisabledAlert ("Category disabled") and tagDisabledAlert ("Tag disabled") — mirror the existing taxDisabledAlert, whose equivalent is already documented in Track Taxes ("What happens if an expense with tax is moved to a workspace where tax tracking is disabled?"). For consistency, the categories and tags articles should get parallel FAQ entries.

A draft help site PR covering exactly this already exists from a prior review and does not need to be recreated:

Draft help site PR: #93865

It adds:

  • Create Expense Categories → new FAQ: "What happens to an expense if its category is disabled on the workspace?"
  • Create and Manage Expense Tags → new FAQ: "What happens to an expense if its tag is disabled on the workspace?"

Please disregard my no changes required comment above — #93865 is the correct outcome.

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

@mitarachim

Copy link
Copy Markdown

@mukhrr This PR is failing in Bug 6 because of a regression issue #93932

Screenshot 2026-06-18 at 7 31 48 PM

The issue is reproducible in: Web, iOS

Bug7184205_1781750454261.Recording__2447.mp4

@mukhrr

mukhrr commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@mukhrr This PR is failing in Bug 6 because of a regression issue #93932

I believe this shouldn't be deploy blocker, since we already fixed original bug in this PR and this one #93932 as bug 6 was decided to fix relatively. What do you think, @lakchote ? cc @hoangzinh

@mitarachim

Copy link
Copy Markdown

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 9.4.14-1 🚀

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

lakchote pushed a commit that referenced this pull request Jul 8, 2026
- #93932: re-enabling categories now writes the missingCategory violation
  for existing "Uncategorized" expenses, so the error shows on the preview
  immediately instead of only after opening the expense. The sentinel is
  normalized to empty in pushTransactionViolationsOnyxData, scoped to
  category-requirement updates so unrelated toggles are unaffected.

- #93929: a disabled-but-not-deleted tax rate is now treated as out of
  policy, so deleting a tag offline no longer drops the "tax no longer
  valid" violation. getIsViolationFixed is aligned to the same check.

- #93945: multi-level (independent/dependent) tag fields now show the
  delete-confirmation modal after Tags is disabled, matching single-level
  tags, instead of opening the Tag RHP.
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.

8 participants