Skip to content

Fix: preserve untouched tag levels when bulk-editing a single tag level - #97951

Open
MelvinBot wants to merge 6 commits into
mainfrom
claude-fixBulkEditTagLevelWipe
Open

Fix: preserve untouched tag levels when bulk-editing a single tag level#97951
MelvinBot wants to merge 6 commits into
mainfrom
claude-fixBulkEditTagLevelWipe

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Bulk Edit multiple built a single flat tag string in the UI (seeded from only the common prefix shared by all selected expenses) and overwrote that same string onto every transaction. When expenses shared a parent tag level (e.g. Cost Center) but differed on child levels (Indication, Phase), the children were dropped from the common prefix before any edit and then wiped from every expense on save.

This change applies the tag edit per-transaction instead of precomputing one shared string:

  • The bulk tag picker now records the edit intent — the resolved value for each edited tag list index — into a new draft field bulkEditTagChanges, in addition to the flattened tag it still stores for the summary display.
  • At apply time, updateMultipleMoneyRequests reconstructs the tag from each transaction's own current tag by running the existing getUpdatedTransactionTag merge at the edited index, against that transaction's real workspace policy. Levels the user didn't touch are preserved (independent tags) or intentionally cleared below the edited level (dependent tags), matching single-expense editing.
  • The select-vs-deselect decision is resolved once in the picker (against the shared/common tag) and stored as the value, so the per-transaction merge can force-set the level without misfiring on an expense that already holds the selected value. This also fixes the first-interaction deselect-detection seeding bug where currentTag was read from the empty draft instead of the common tag.

The approach is level-count agnostic: for 3+ levels, editing a middle level preserves the parent(s) above at any depth (and, for dependent tags, clears the now-invalid child below by design).

New unit tests cover independent tags (children preserved) and dependent tags (parent preserved, dependent child cleared, middle-level edit).

Fixed Issues

$ #97356
PROPOSAL: #97356 (comment)

Tests

Precondition: Create workspace, import multi-level independent tags and create a report with at least two expenses.

  1. Open report
  2. Select all expenses in the report
  3. Click Edit multiple
  4. Update only the parent tag level.
  5. Save the changes
  6. Open the edited expenses and review the tag values
  7. Verify that only the parent tag level is updated, and the existing child tag levels on each expense remain unchanged.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Precondition: Create workspace, import multi-level independent tags and create a report with at least two expenses.

  1. Open report
  2. Select all expenses in the report
  3. Click Edit multiple
  4. Update only the parent tag level.
  5. Save the changes
  6. Open the edited expenses and review the tag values
  7. Verify that only the parent tag level is updated, and the existing child tag levels on each expense remain unchanged.
  • 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 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 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

Co-authored-by: Sobit Neupane <sobitneupane@users.noreply.github.com>
…pre-computes

Co-authored-by: Sobit Neupane <sobitneupane@users.noreply.github.com>
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/libs/DebugUtils.ts 68.92% <75.00%> (+0.09%) ⬆️
src/libs/actions/IOU/BulkEdit.ts 85.46% <85.71%> (+0.74%) ⬆️
...arch/SearchEditMultiple/SearchEditMultiplePage.tsx 0.00% <0.00%> (ø)
...h/SearchEditMultiple/SearchEditMultipleTagPage.tsx 0.00% <0.00%> (ø)
... and 569 files with indirect coverage changes

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fixed the failing spellcheck check.

The check flagged two non-dictionary words in tests/actions/IOUTest/BulkEditTest.ts:

  • indep — used in test fixture IDs (transaction-indep-1, iou-indep-1, thread-indep-1, etc.). Renamed to independent.
  • precomputes — in a comment. Reworded to pre-computes.

Spellcheck now passes locally and all 35 tests in BulkEditTest.ts still pass.

The other two failing checks — Check independent approval and checklist — are process/approval checks, not code issues, so no code change applies to them.

@sobitneupane

Copy link
Copy Markdown
Contributor

@MelvinBot Could you pease review #97951 (comment) and #97951 (comment) comment?

@sobitneupane

Copy link
Copy Markdown
Contributor

Screenshots/Videos

MacOS: Chrome / Safari
Screen.Recording.2026-08-06.at.17.20.51.mov
Screen.Recording.2026-08-06.at.17.22.42.mov

Co-authored-by: Sobit Neupane <sobitneupane@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

sobitneupane — reviewed both comments. Neither indicates a real problem; here's the breakdown, and I pushed a small test to clear the Codecov flag.

1. Codecov (coverage report) — no bug, and the core fix is actually better covered.

  • The bug-fix logic in BulkEdit.ts went up to 85.46% (+0.74%) — the two new per-transaction merge tests cover it.
  • The decrease came from two spots:
    • SearchEditMultipleTagPage.tsx at 0% — this is an RHP UI page; those aren't unit-tested in this repo, so it's expected.
    • DebugUtils.ts at -1.10% — the new validateStringRecord debug-panel validator was untested, even though all its siblings (validateArray, validateObject, …) are.
  • Action taken: I exported validateStringRecord and added a matching describe block to DebugUtilsTest.ts (7 cases: valid record, empty/undefined/null, and the non-object / array / non-string-value throw paths). This restores the DebugUtils.ts coverage. Pushed as 6265f5f. All 254 DebugUtilsTest tests pass; lint (0 errors), typecheck, and spellcheck are clean.

2. Spellcheck fix (my earlier comment) — verified correct.

  • indepindependent in the test fixture IDs and precomputespre-computes in the comment are the right calls; both were genuine non-dictionary words. Confirmed no indep- / precomputes remain in BulkEditTest.ts and all 35 tests there still pass. No further action needed.

Net: the only actionable item was the untested DebugUtils validator, which is now covered. The remaining 0% on the .tsx page is standard for UI pages here, not a gap I can meaningfully close with a unit test.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

The spellcheck fix from earlier is now passing, and the only remaining failing checks are non-code process checks that I can't resolve by pushing code:

  • checklist (PR Author Checklist) — reports "0 out of 38 checklist items" completed. The human co-author needs to fill out the checklist (and the Tests/QA sections) before this passes.
  • Check independent approval — an approval/review gate, resolved through the normal review process, not a code change.

All other real checks (spellcheck, ESLint, typecheck, Bun tests, build, etc.) are passing or still running. Nothing further for me to fix here.

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

Screenshots/Videos

Android: HybridApp
Screen.Recording.2026-08-07.at.17.10.38.mov
Android: mWeb Chrome
Screen.Recording.2026-08-07.at.17.08.28.mov
iOS: HybridApp
Screen.Recording.2026-08-07.at.17.47.52.mov
iOS: mWeb Safari
Screen.Recording.2026-08-07.at.17.51.19.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-07.at.17.04.48.mov

@MelvinBot

Copy link
Copy Markdown
Contributor Author

There's nothing for me to fix here — all the code, build, and test checks are green. The only failing checks are process checks that require human action, not a code change:

Failing check Workflow What it needs
checklist PR Author Checklist The human co-author must complete the author checklist (fill in Tests/QA steps and tick the boxes)
checklist PR Reviewer Checklist The reviewer must complete their checklist
Check independent approval Verify peer review An independent reviewer must approve the PR

I intentionally don't push commits for these — they're satisfied by people, not by MelvinBot. Once the checklists are filled out and the PR has an independent approval, these will go green.

For reference, everything else is passing: Bun tests, test (job 1–8), typecheck, ESLint check, Oxfmt check, Storybook tests, React Compiler Compliance, check, and the perf/build jobs.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Nothing has changed since my previous comment — there's still no code failure for me to fix. The only failing checks are process/human checks:

  • checklist (PR Author Checklist) — the human co-author needs to complete the author checklist (fill in Tests/QA steps and tick the boxes)
  • checklist (PR Reviewer Checklist) — the reviewer needs to complete their checklist
  • Check independent approval — an independent reviewer needs to approve the PR

These are satisfied by people, not by a commit, so there's nothing for me to push. Every code, build, and test check (Bun tests, test (job 1–8), typecheck, ESLint, Oxfmt, Storybook, React Compiler, check, perf/build) is passing.

@sobitneupane

Copy link
Copy Markdown
Contributor

@MelvinBot Please add the following steps under Tests and QA Steps:

  1. Log in to New Expensify
  2. Open report
  3. Select all expenses in the report
  4. Click Edit multiple
  5. Update only the parent tag level.
  6. Save the changes
  7. Open the edited expenses and review the tag values
  8. Verify that only the parent tag level is updated, and the existing child tag levels on each expense remain unchanged.

@MelvinBot Additionally, please update the PR Author Checklist and mark all items as completed.

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Done — updated the PR description:

  • Added your 8 steps under both the Tests and QA Steps sections.
  • Marked every item in the PR Author Checklist as completed.

One heads-up: the Screenshots/Videos section is still empty, so the "I included screenshots or videos for tests on all platforms" box now claims something the PR body doesn't yet show. Adding the platform screenshots/videos will keep that checkbox honest before the PR goes up for review.

@sobitneupane

Copy link
Copy Markdown
Contributor

@MelvinBot Mark this PR ready for review

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

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 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
    • 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
    • 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 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
Screen.Recording.2026-08-07.at.17.10.38.mov
Android: mWeb Chrome
Screen.Recording.2026-08-07.at.17.08.28.mov
iOS: HybridApp
Screen.Recording.2026-08-07.at.17.47.52.mov
iOS: mWeb Safari
Screen.Recording.2026-08-07.at.17.51.19.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-07.at.17.04.48.mov

@melvin-bot
melvin-bot Bot requested a review from NikkiWines August 10, 2026 07:47
@MelvinBot
MelvinBot marked this pull request as ready for review August 10, 2026 07:49
@MelvinBot
MelvinBot requested a review from a team as a code owner August 10, 2026 07:49
@melvin-bot
melvin-bot Bot requested a review from sobitneupane August 10, 2026 07:49
@melvin-bot

melvin-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

@sobitneupane 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 requested review from a team and trjExpensify and removed request for a team August 10, 2026 07:50
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Done — this PR is now marked Ready for review.

@melvin-bot
melvin-bot Bot requested a review from puneetlath August 10, 2026 07:50

@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: 6265f5f9b3

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

// Keep the flattened tag for the summary display, and record the per-level edit intent so
// apply time can merge it into each transaction's own tag instead of overwriting all levels.
tag: updatedTag,
bulkEditTagChanges: {[tagListIndex]: resolvedTagName},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear stale child tag edits when parents change

If a user edits a child tag level and then edits a parent level in the same bulk-edit draft, this merge writes only the new parent key and leaves the earlier child key in bulkEditTagChanges. Apply time sorts and replays all retained keys, so the stale child selection is applied after the parent change even though the displayed updatedTag cleared children; for dependent tags this can preserve or send an invalid child that the later parent edit was supposed to clear. Clear descendant entries (or replace the intent map) when saving a parent-level edit.

Useful? React with 👍 / 👎.

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 don’t think this is reproducible. With dependent tags, when the parent tag changes, the child tag is automatically deselected if it doesn’t belong to the selected parent’s branch.

// value (empty = clear) lets apply time force-set each transaction's level without re-deriving
// the toggle from that transaction's own value, which would misfire when an expense already
// has the selected value at this level.
const resolvedTagName = selectedTagName === currentTag ? '' : selectedTagName;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Carry tag clear intents when the tag becomes empty

When the user deselects the only tag, or clears the first level of a dependent tag, resolvedTagName becomes '' and updatedTag can also be ''. The save path only adds changes.tag for truthy draft tags, and updateMultipleMoneyRequests only reads bulkEditTagChanges inside its changes.tag branch, so this newly recorded clear intent is skipped (or the page dismisses as having no changes) instead of clearing the selected transactions' tags.

Useful? React with 👍 / 👎.

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 Could you please review above comment?

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.

🤖 I reviewed this comment — it's a valid concern (real bug), not a false positive.

When the bulk tag edit resolves to an empty string (deselecting the only tag on a single independent tag list, or clearing level 0 of a dependent tag), the recorded clear intent in bulkEditTagChanges never reaches the transactions because it's gated behind a truthy tag check at two points:

  1. Save handlerSearchEditMultiplePage.tsx:170: if (draftTransaction.tag) is falsy for '', so changes.tag is never set. If the tag was the only edit, SearchEditMultiplePage.tsx:183 then sees Object.keys(changes).length === 0 and dismisses with no update at all.
  2. ActionBulkEdit.ts:242: if (changes.tag && ...) guards the whole bulkEditTagChanges reconstruction block, so even when other fields are edited and the action does run, the empty clear intent is skipped.

The intent itself is recorded correctly (bulkEditTagChanges: {index: ''} in SearchEditMultipleTagPage.tsx:51) — it just can't get past the two truthy gates, so the selected transactions' tags are never cleared.

For comparison, category one line up uses changes.category !== undefined precisely so an empty value clears the field — tag needs the same treatment.

Suggested fix: treat "a bulkEditTagChanges entry exists" as reason to proceed even when the resolved tag is empty — set changes.tag in the save handler when bulkEditTagChanges is non-empty (even if tag === ''), and enter the tag branch in BulkEdit.ts when bulkEditTagChanges has keys rather than only when changes.tag is truthy.

Note this differs from the sibling comment you marked non-reproducible: the trigger here is deselecting down to an empty tag, which the picker does allow. If you'd like, reply @MelvinBot implement this and I'll push the fix + a unit test covering the clear-to-empty case.

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.

🤖 Implemented in 6322557.

The clear-to-empty edit was being dropped by three truthy tag checks, so I fixed all three so an empty resolved tag is treated as a real change (mirroring how category uses !== undefined):

  1. Save handlerSearchEditMultiplePage.tsx:170-176: now sets changes.tag whenever the draft recorded a bulkEditTagChanges intent, even when the resolved tag is ''.
  2. Action guardBulkEdit.ts:242-244: enters the tag branch on changes.tag !== undefined || editedTagIndexes.length > 0, so the per-transaction reconstruction still runs for an empty clear.
  3. Updates payloadBulkEdit.ts:305-307: if (transactionChanges.tag !== undefined) so the cleared '' is forwarded instead of leaving updates empty (which was causing the whole transaction to be skipped).

That last one wasn't in my earlier analysis — the empty tag would have been dropped there too, so I caught it while implementing.

Added a unit test covering deselecting the only tag on a single independent tag list (BulkEditTest.ts), asserting the update clears the tag to '' rather than being dropped.

⚠️ I couldn't run the Jest/typecheck/lint suite in this environment, so I'm relying on CI to validate the push. The change is a small, targeted gating fix mirroring the existing category pattern.

Comment thread tests/actions/IOUTest/BulkEditTest.ts Outdated
transactionIDs: [firstTransactionID, secondTransactionID],
// The bulk-edit page pre-computes a common-prefix display string (parent only)...
changes: {tag: 'CostCenterB'},
// ...but apply time uses the resolved per-level edit intent (index 0 -> CostCenterB) to

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-16 (docs)

This comment uses an arrow (->) inside its own sentence instead of writing the relationship out in words, which the plain-comment-style rule flags.

Rewrite the relationship in words, e.g.:

// ...but apply time uses the resolved per-level edit intent (index 0 maps to CostCenterB) to

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

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 in bb2787b — rewrote the arrow as (index 0 maps to CostCenterB).

Comment thread tests/actions/IOUTest/BulkEditTest.ts Outdated
getCurrencySymbol,
});

// Each transaction keeps its OWN Indication/Phase; only the shared parent level changed.

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-16 (docs)

This comment joins two independent clauses with a semicolon. Plain comment style prefers two separate sentences over a semicolon.

Split into two sentences, e.g.:

// Each transaction keeps its OWN Indication/Phase. Only the shared parent level changed.

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

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 in bb2787b — split into two sentences: Each transaction keeps its OWN Indication/Phase. Only the shared parent level changed.

Comment thread tests/actions/IOUTest/BulkEditTest.ts Outdated
getCurrencySymbol,
});

// Parent (CostCenter) preserved; the edited Indication level updated; dependent Phase cleared.

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-16 (docs)

This comment uses semicolons to string together three independent clauses. Plain comment style prefers separate sentences over semicolons.

Split into separate sentences, e.g.:

// The parent (CostCenter) is preserved. The edited Indication level is updated. The dependent Phase level is cleared.

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

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 in bb2787b — split into three sentences: Parent (CostCenter) is preserved. The edited Indication level is updated. The dependent Phase level is cleared.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

No failing checks to fix right now — every automated check on the PR is passing (Bun tests, ESLint, typecheck, all test jobs, Storybook, perf tests, etc.).

The only two not yet green are Check independent approval and review, and both are pending, not failed. Neither is fixable by a code push — Check independent approval just needs an independent reviewer to approve the PR, and review completes on reviewer action. No commit needed.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Still the same situation — the only failing check is Check independent approval (the "Verify peer review" step), which isn't fixable by pushing code. It just needs an independent reviewer to approve the PR.

Everything else is green, including review and validate, which were pending on my last check. No commit needed here; this check will clear once the PR gets an independent approval.

@sobitneupane

Copy link
Copy Markdown
Contributor

@MelvinBot Could you please review #97951 (comment), #97951 (comment) and #97951 (comment) comments?

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Same as before — the only failing check is Check independent approval (the "Verify peer review" step), and it can't be fixed by pushing code. It clears once the PR gets an independent reviewer's approval. All other checks are passing, so there's nothing for me to commit here.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Same as before: the only failing check is Check independent approval (the "Verify peer review" step), which requires an independent reviewer to approve the PR — not a code change. Every other check is now passing, including review and validate which were pending earlier.

Nothing for me to fix or push here; this clears once the PR gets an independent approval.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

There are no failing checks on the PR right now — nothing to fix.

Current status: 39 passing, 4 skipped, and 2 still in progress (Check independent approval and checklist). The Check independent approval check that was red earlier is now re-running; it goes green once the PR has an independent reviewer approval, which isn't something a code push can resolve.

No commit needed here.

Co-authored-by: Sobit Neupane <sobitneupane@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team as a code owner August 10, 2026 08:48
@melvin-bot
melvin-bot Bot requested a review from sobitneupane August 10, 2026 08:49
@melvin-bot

melvin-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

@sobitneupane 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 August 10, 2026 08:49
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Reviewed all three — they're the same automated CONSISTENCY-16 (plain-comment-style) nits on comments in tests/actions/IOUTest/BulkEditTest.ts, all valid. Applied the suggested rewrites and pushed in bb2787b:

  • (index 0 -> CostCenterB)(index 0 maps to CostCenterB) (no arrow in prose)
  • ...OWN Indication/Phase; only the shared parent... → split into two sentences
  • Parent (CostCenter) preserved; ...updated; ...cleared. → split into three sentences

All comment-text only — no logic or test behavior changed. I've replied in each thread as well.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Still nothing to fix by pushing code. A fresh CI run is in progress and all the real checks that have finished are green (ESLint, typecheck, test jobs, etc.); perf tests are still running but passed on the previous run.

The only failure is Check independent approval (run), which fails on its "Verify peer review" step. That's not a code issue — it just needs an independent reviewer to approve the PR, and it'll go green on its own once that happens.

When a bulk Edit multiple deselects the only tag (or clears level 0 of a
dependent tag), the edit resolved to an empty string and was silently dropped
by three truthy checks: the save handler skipped changes.tag, the action's tag
branch never ran, and the updates payload never included the empty tag. Gate
these on the recorded per-level edit intent / definedness (matching category)
so the clear reaches the transactions. Adds a unit test for the clear case.

Co-authored-by: Sobit Neupane <sobitneupane@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.

@sobitneupane

Copy link
Copy Markdown
Contributor

@codex review

@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: 6322557c34

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

// Keep the flattened tag for the summary display, and record the per-level edit intent so
// apply time can merge it into each transaction's own tag instead of overwriting all levels.
tag: updatedTag,
bulkEditTagChanges: {[tagListIndex]: resolvedTagName},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear stale child tag intents when saving parents

Fresh evidence after checking the current diff: this stores only the edited index into a draft object that is updated with Onyx.merge, while updateMultipleMoneyRequests later replays every retained bulkEditTagChanges key in ascending order. If a user first edits a dependent child level and then changes the parent before saving, the parent edit clears the displayed updatedTag, but the stale child key remains and is applied after the parent clear, so the saved transactions can keep/send a child value that no longer belongs to the selected parent. Replace the intent map when saving a parent level or clear descendant keys here.

Useful? React with 👍 / 👎.

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 This seems to be valid concern.

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.

🤖 Confirmed valid, fixed in 5166454.

The draft's bulkEditTagChanges is written with Onyx.merge, so it accumulates one key per edited level across the draft. If a user edits a child level and then a parent level, the map keeps both keys, and apply time replays them in ascending index order (BulkEdit.ts:256-266) — so the stale child is re-applied after the parent change, re-adding a child that no longer belongs under the new parent, even though the displayed updatedTag had already cleared it.

Fix: when recording an edit for a dependent-tag policy, drop any previously recorded child (deeper-index) intents from the draft (SearchEditMultipleTagPage.tsx:69-83), mirroring how updatedTag already clears the display. Independent tags are unaffected — each level stays independent, so all recorded levels are retained.

Verified typecheck, lint, and React Compiler compliance pass, and the existing BulkEditTest suite (36 tests) is still green. Note this scenario lives in the picker's draft-recording path rather than updateMultipleMoneyRequests, so it isn't covered by the action-layer suite — a component-level test for the multi-level edit sequence would be a good follow-up.

… in bulk edit

Co-authored-by: Sobit Neupane <sobitneupane@users.noreply.github.com>
@sobitneupane

Copy link
Copy Markdown
Contributor

@MelvinBot When I open the parent tag in “Edit Multiple,” it appears as already selected. However, I need to deselect and reselect it for the child tag menu to show up.

In staging, the behavior is different, already selected tags don’t appear as selected in the list when I first open “Edit Multiple.” Should we align this flow and follow the same approach?

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Good catch — this is a real side effect of one intentional line in this PR, and I'd not do a straight revert to staging's behavior, because staging's approach reintroduces the exact bug this line was added to fix.

The PR seeds currentTag from the shared/common tag instead of the empty draft (SearchEditMultipleTagPage.tsx:43-45), which both highlights the shared parent as "selected" on first open and makes the first tap on it resolve to a deselect. Since the child level is gated on the committed draftTransaction.tag, that first-tap clear is why the child menu only shows after you deselect-and-reselect.

Recommendation: Rather than aligning to staging, decouple the two things this one line currently conflates — keep highlighting the existing shared value (it's informative and matches single-expense editing), but drive the select-vs-deselect toggle off whether the value is actually committed in the draft rather than off the seeded common value. That fixes the child-navigation flow while still letting a second tap clear the level. Worth confirming the target matches the single-expense dependent-tag picker, which is the source of truth for consistency.

Why (mechanism + the tension)

On this PRcurrentTag is seeded from commonDependentTag when the draft has no tag yet (SearchEditMultipleTagPage.tsx:43-45). That value is passed to the picker as the highlighted option (so the parent looks selected), and it feeds the toggle at :57 (resolvedTagName = selectedTagName === currentTag ? '' : selectedTagName). On the first tap selectedTagName === currentTag, so getUpdatedTransactionTag clears the level (TagsOptionsListUtils.ts:298) and the draft's tag becomes ''.

The child (deeper) level only renders once the parent is present in the committed draft tag — shouldShowDependentTagList(tagListIndex, draftTransaction?.tag, …) (SearchEditMultiplePage.tsx:240). Because the first tap cleared it, the child stays hidden until a second tap actually commits the parent → the deselect-then-reselect you saw.

Why staging can't just be restored — Staging seeds currentTag from the empty draft, so on first open currentTag = ''. A first tap is then always non-empty !== '' → select, which is smoother for drilling into the child, but it also makes it impossible to deselect/clear a level all selected expenses share on the first tap. That is precisely the "first-interaction deselect-detection" bug the PR's seeding was added to fix, so a straight revert would bring it back. The two behaviors share one root cause, which is why they need to be decoupled rather than swapped.

(Mechanism confirmed by code trace; it's deterministic client-side logic, matching what you reproduced.)

@sobitneupane

Copy link
Copy Markdown
Contributor

Good catch — this is a real side effect of one intentional line in this PR, and I'd not do a straight revert to staging's behavior, because staging's approach reintroduces the exact bug this line was added to fix.

@MelvinBot Could you please clarify how not selecting any option (as in staging) would reintroduce the original bug?

Recommendation: Rather than aligning to staging, decouple the two things this one line currently conflates — keep highlighting the existing shared value (it's informative and matches single-expense editing), but drive the select-vs-deselect toggle off whether the value is actually committed in the draft rather than off the seeded common value.

Also, could you please elaborate a bit more on the two things you mentioned and how you are planning of decoupling them?

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Both good questions — and the second one made me tighten my own recommendation, because the "drive the toggle off the draft" phrasing I used would have partly reintroduced the bug. Details below.

Q1 — Why staging's "nothing selected" reintroduces the original bug

The only thing that produces a clear for dependent tags is isSelectedTag inside getUpdatedTransactionTag (tagParts.splice(tagListIndex)), and that flag is selectedTagName === currentTag, resolved at SearchEditMultipleTagPage.tsx:57.

Staging seeds currentTag from the empty draft, so on first open currentTag = ''. When every selected expense already shares a value (say CostCenter A) and the user wants to remove it, the first tap is "CostCenter A" === "" → false → select, so the merge re-applies CostCenter A instead of clearing it. With nothing highlighted there's no value for the tap to match, so the deselect branch can never fire on the first interaction — you can't clear a level that all the selected expenses share. That's exactly the "first-interaction deselect-detection" bug this PR's seed (SearchEditMultipleTagPage.tsx:42-45) was added to fix, so a straight revert brings it back.

Q2 — The two things this one line conflates, and the right way to decouple

The single common-seeded currentTag is doing two unrelated jobs:

  1. Highlight — it's passed to the picker as the pre-selected option, so the shared value shows as selected on open (informative, matches single-expense editing).
  2. Select-vs-deselect toggle:57 compares the tapped value against it to decide select vs clear.

Because both read the same value, the first tap on the highlighted parent resolves to a clear (A === A), and since the child level is gated on the committed draft tag (SearchEditMultiplePage.tsx:240), that first-tap clear is why the child menu only appears after deselect-and-reselect.

Correction to what I said earlier: I framed the fix as "drive the toggle off whether the value is committed in the draft." On a closer trace that's the wrong lever — with the toggle reading the (empty) draft, the first tap on the highlighted value becomes a no-op re-select and clearing a shared level would again take two taps, i.e. it re-introduces the Q1 limitation. So don't touch the toggle.

The clean decouple is to leave the toggle seeded from the common tag (keeps 1-tap deselect / the original fix intact) and fix what's actually broken — child-list visibility. It's currently gated on the committed draft (SearchEditMultiplePage.tsx:230 & :240), which is empty on open even though every selected expense shares the parent. Gate it on the effective shared tag instead — draftTransaction?.tag falling back to getCommonDependentTag(...). Then:

  • The child field shows immediately on open (the shared parent is present), so you never deselect-and-reselect to reach it — fixes your report.
  • The parent picker still highlights the shared value and one tap still clears the level (children included) — the deselect fix and single-expense parity are untouched.

Worth validating the target against the single-expense dependent-tag flow, which is the source of truth for how the highlight, one-tap clear, and child-field visibility should behave together.

If you'd like, reply @MelvinBot implement this and I'll make the child-visibility change plus a test covering "open → child field already visible for a shared parent."

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

  1. Log in to New Expensify
  2. Open report
  3. Select all expenses in the report
  4. Click Edit multiple
  5. Update only the parent tag level.
  6. Save the changes
  7. Open the edited expenses and review the tag values
  8. Verify that only the parent tag level is updated, and the existing child tag levels on each expense remain unchanged.

Might be best to write a test for dependent tags and independent tags? It's not super clear for Applause what to set up on a workspace to test this as written.

@puneetlath
puneetlath removed their request for review August 10, 2026 16:26
@sobitneupane

Copy link
Copy Markdown
Contributor

@MelvinBot Could you please update the test and QA steps to the following:

Precondition: Create workspace, import multi-level independent tags and create a report with at least two expenses.

  1. Open report
  2. Select all expenses in the report
  3. Click Edit multiple
  4. Update only the parent tag level.
  5. Save the changes
  6. Open the edited expenses and review the tag values
  7. Verify that only the parent tag level is updated, and the existing child tag levels on each expense remain unchanged.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Updated both the Tests and QA Steps sections to your steps:

Precondition: Create workspace, import multi-level independent tags and create a report with at least two expenses.

  1. Open report
  2. Select all expenses in the report
  3. Click Edit multiple
  4. Update only the parent tag level.
  5. Save the changes
  6. Open the edited expenses and review the tag values
  7. Verify that only the parent tag level is updated, and the existing child tag levels on each expense remain unchanged.

I kept the existing "Verify that no errors appear in the JS console" checkbox line under each section.

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