Skip to content

Flag the group's own snapshot entry when a whole-group delete removes it - #100675

Merged
Beamanator merged 16 commits into
Expensify:mainfrom
nkdengineer:fix/100122-1
Sep 16, 2026
Merged

Beamanator merged 16 commits into
Expensify:mainfrom
nkdengineer:fix/100122-1

Conversation

@nkdengineer

@nkdengineer nkdengineer commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Deleting every expense in a group made the group row flash: it disappeared, came back, then disappeared again.

A grouped search reads from two Onyx keys. The main snapshot holds one group_<id> entry per group and nothing else — getMemberSections builds one row per group entry with transactions: []. Each group's children live under a separate hash, pulled in by useSearchSnapshot via useMultipleSnapshots.

The group row had no pendingAction of its own — it derived one from its children, and that derivation required transactions.length > 0. Since the two keys are cleared at different times, that produced three states:

  1. All children pending delete → group derives DELETE → OfflineWithFeedback hides the row's content. Row gone.
  2. Delete succeeds, children cleared from the sub-snapshot → transactions.length === 0, nothing left to derive from → pendingAction is undefined. Row back — the flash.
  3. The next Search response drops the group entry. Row gone for good.

The fix moves the delete state onto the group's own snapshot entry, which is the only thing that outlives its children:

  • pendingAction lives on a shared SearchGroupBase in SearchResults.ts, which also folds up the count/total/currency that all ten group models repeated.
  • getMemberSections already spreads the group entry into the row, so item.pendingAction lights up and the existing isRowDeleted checks just work. The header greys out from that flag only — there is no children-derived pending-delete fallback.

Which groups get that flag is coverage, not "clicked the group checkbox":

  • isSelectedViaGroup still means the user selected through the group header. Export uses it so a group-row click can export as a group even when limit: left children unloaded.
  • Delete uses getSelectedGroupKeys, which includes a group only when the selected children cover the group's snapshot count (or, when count is missing, when isEntireGroupSelected is set). Selecting every loaded child one by one is enough when that loaded set is the whole group. Clicking the group checkbox with limit: Y < X is not.
  • stampGroupCoverageFlags writes isEntireGroupSelected without touching isSelectedViaGroup.

A limit: smaller than the group count only deletes the loaded rows, so the group stays in the list. In that case:

  • The group is not flagged pending-delete, so remaining expenses stay visible.
  • If the group was expanded, it auto-collapses once every loaded child is pending-delete, instead of sitting open on an empty/deleted child list. Expanding again fetches the remaining expenses.
  • The header greys out from the group's own pendingAction only, so a truncated delete does not grey out a group that still has expenses.

The flag rides in the delete request's own optimisticData/failureData, so a failed delete puts the row back. Delete runs once per transaction, so all of a group's requests carry the same idempotent merge and any one failing restores the row.

No successData is needed: the Search response replaces the whole snapshot, so a surviving group loses the flag and a deleted group loses its entry.

The view drops flagged rows from the list when online so the row collapses away instead of leaving a zero-height wrapper; offline it stays put with the usual pending-delete styling.

One deliberate trade-off: a fully deleted group row now pops out rather than playing FadeOutUp, because it leaves the list on the same render the flag arrives. The surviving rows still slide up via LinearTransition, and the fade was mostly invisible anyway — hideChildren had already collapsed the row's content a step earlier.

Fixed Issues

$ #100122
PROPOSAL:

Tests

  • Delete all transactions in a group
  1. Open Spend
  2. Select any suggested group search
  3. Expand to fetch all transactions
  4. Click on the group checkbox/select each transaction
  5. Delete selected transactions
  6. Verify that the group disappears and doesn't flash again
  • Delete all views transactions
  1. Open Spend
  2. Select any suggested group search
  3. Set the limit result to less than the total expense in the group
  4. Click on the group checkbox/select each transaction
  5. Delete selected transactions
  6. Verify that the group doesn't disappear and the group is collapsed
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Same as test

  • 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
Screen.Recording.2026-09-09.at.15.25.42.mov
Android: mWeb Chrome
Screen.Recording.2026-09-09.at.15.22.49.mov
iOS: Native
Screen.Recording.2026-09-09.at.15.27.46.mov
iOS: mWeb Safari
Screen.Recording.2026-09-09.at.15.23.28.mov
MacOS: Chrome / Safari
Screen.Recording.2026-09-09.at.15.19.21.mov
Screen.Recording.2026-09-09.at.15.20.56.mov
Screen.Recording.2026-09-09.at.15.56.01.mov

@codecov

codecov Bot commented Sep 9, 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 Δ
...ponents/Search/SearchList/ListItem/GroupHeader.tsx 78.18% <100.00%> (-0.39%) ⬇️
...h/SearchList/ListItem/TransactionGroupListItem.tsx 77.03% <100.00%> (ø)
...m/shouldCollapseExpandedGroupAfterPendingDelete.ts 100.00% <100.00%> (ø)
src/hooks/useDeleteTransactions.ts 64.13% <ø> (ø)
src/libs/SearchUIUtils.ts 70.97% <ø> (ø)
src/libs/actions/IOU/SearchUpdate.ts 92.68% <100.00%> (+0.57%) ⬆️
src/libs/actions/IOU/DeleteMoneyRequest.ts 77.69% <50.00%> (-0.41%) ⬇️
...c/components/Search/SearchWriteActionsProvider.tsx 88.73% <90.00%> (+16.43%) ⬆️
src/components/Search/selectionBuilders.ts 82.72% <82.85%> (+2.72%) ⬆️
src/hooks/useSearchBulkActions.ts 76.04% <87.23%> (+1.28%) ⬆️
... and 1 more
... and 14 files with indirect coverage changes

@nkdengineer
nkdengineer marked this pull request as ready for review September 9, 2026 09:05
@nkdengineer
nkdengineer requested review from a team as code owners September 9, 2026 09:05
@melvin-bot
melvin-bot Bot requested review from cretadn22 and flaviadefaria and removed request for a team September 9, 2026 09:05
@melvin-bot

melvin-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

@cretadn22 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 September 9, 2026 09:05

@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: 19582b148a

ℹ️ 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/hooks/useSearchBulkActions.ts Resolved
Comment thread src/hooks/useDeleteTransactions.ts Resolved
@cretadn22

Copy link
Copy Markdown
Contributor

@nkdengineer The flicker still happens when deleting a group's last expense through its own thread

Screen.Recording.2026-09-12.at.17.05.01.mov

@cretadn22

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Screen.Recording.2026-09-12.at.17.32.07.mov
Android: mWeb Chrome
Screen.Recording.2026-09-12.at.17.35.52.mov
iOS: HybridApp
Screen.Recording.2026-09-12.at.17.36.22.mov
iOS: mWeb Safari
Screen.Recording.2026-09-12.at.17.34.05.mov
MacOS: Chrome / Safari
Screen.Recording.2026-09-12.at.17.30.05.mov

@cretadn22

Copy link
Copy Markdown
Contributor

I only noticed one bug (in this comment), the rest of the code changes are solid and testing well.

@nkdengineer

Copy link
Copy Markdown
Contributor Author

@cretadn22 I fixed this issue.

Co-authored-by: cretadn22 <168617111+cretadn22@users.noreply.github.com>
@cretadn22

Copy link
Copy Markdown
Contributor

@nkdengineer Please check again

@nkdengineer

Copy link
Copy Markdown
Contributor Author

@neil-marcellini All done.

@neil-marcellini neil-marcellini 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 to go, thanks for the updates!

AI found another possible issue, but we can fix it in a follow up.


One new issue, non-blocking. Making isEntireGroupSelected sufficient in getSelectedGroupKeys means a stale flag can now over-report. Reconcile copies the flag forward verbatim without re-evaluating it against the new data. So: on group-by:from, select a whole 2-expense group, then create a third expense that lands in that group (the create path bumps count and adds the row, but doesn't touch the selection). The two originals keep isEntireGroupSelected: true, delete flags the whole group, and the surviving third expense's group row vanishes until the next Search response. Before this commit the live selectedCount === groupCount check was self-correcting here.

Narrow, and the same staleness already existed for the unknown-count branch, so I'd treat it as a follow-up rather than a blocker. The clean fix is for reconcile to recompute the flag — it already has the group's transactions and count in hand at that point.

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

Thanks for the update!

Two more NAB comments from the AI. They can be addressed in a follow up. The first one is about performance so maybe not a problem unless we prove it's actually non-performant and under which conditions.


stampGroupCoverageFlags is called once per group with the entire accumulated newTransactionList, and it spreads and scans that object twice each time. With a select-all across many groups this goes quadratic in a hook that reruns on every filteredData change. The block already knows the group's own children, so computing the flag once and assigning it to those entries would avoid the whole-selection scans.

Line 219 deliberately leaves groupKey undefined for isExpenseReportType, and the new loop then sets it anyway for every group type. Downstream consumers all gate on the group_ prefix so I can't find a behavior change, but it reads like the guard was undone by accident — worth a word from the author on whether that's intended.

@neil-marcellini

Copy link
Copy Markdown
Contributor

Dang, since I authored some of the commits on this PR, we need another reviewer.

@neil-marcellini
neil-marcellini requested a review from a team September 16, 2026 18:00
@melvin-bot

melvin-bot Bot commented Sep 16, 2026

Copy link
Copy Markdown

@cretadn22 @neil-marcellini One of you needs to 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 September 16, 2026 18:00
@neil-marcellini

Copy link
Copy Markdown
Contributor

(Neil's AI agent)

@Beamanator you've been assigned as an independent reviewer here via PullerBear.

PullerBear wasn't working on this PR, so I ran it on a dummy PR in Web-Expensify instead and carried the result over: https://github.com/Expensify/Web-Expensify/pull/50616 (PullerBear picked Beamanator there, and that PR is now closed again).

Context on why another reviewer is needed: the Verify peer review check fails because I'm a commit author on this PR as well as an approver, so my approval doesn't count as independent.

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

@Beamanator
Beamanator merged commit 4c4c24b into Expensify:main Sep 16, 2026
36 of 39 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 Beamanator 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/Beamanator in version: 9.4.81-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Yes — help site changes were required. Draft PR: Docs updates for E/A#100675 deleting every expense in a group

This PR settles what a member sees on the Spend page when they delete expenses inside a grouped search, and none of it was documented. How-to-Delete-Expenses.md covered deleting one expense, deleting several, and deleting from a report — but never mentioned groups.

Added two sections to that article:

  • ## How to delete every expense in a group on the Spend page — the steps, including that a group row has its own checkbox selecting every expense the group is currently showing.
  • ## What happens after you delete every expense in a group — the four outcomes this PR defines: the group row leaves the results on a full delete; a truncated result set (a limit: below the group count) deletes only the selected expenses and leaves the group in place, collapsed; offline the row stays as pending; a failed delete puts the row back.

The truncated case is the one worth writing down — it reads as a bug to a member who deletes "everything" and watches the group survive, and it's now deliberate behavior.

One pre-existing fix included, not caused by this PR: the article called the bulk action button Selected in three places. The live UI renders it with the selection count (1 selected, 3 selected) per en.ts:4821-4824. Those now read X selected. Drop that part if you'd rather keep it out of scope — the same stale label appears in other articles and could be swept separately.

How the labels were verified

Driven in the live web app, not inferred from code: the Spend tab, the Expenses sub-tab, the group row checkbox, the X selected bulk action button, its menu options (Export, Hold, Move to report, Split, Duplicate expense, Delete), and the confirmation modal (Delete expense / Delete / Cancel).

Written against docs/HELPSITE_NAMING_CONVENTIONS.md, docs/HELP_AUTHORING_GUIDELINES.md, and docs/TEMPLATE.md: one # heading plus # FAQ, only ## below it, every new heading task-based and starting with a question word, exact bolded UI labels, and the cross-link kept outside the numbered steps.


@Beamanator, 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 production by https://github.com/luacmartins in version: 9.4.81-1 🚀

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 9.4.81-1 🚀

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

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.

6 participants