Skip to content

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

Open
nkdengineer wants to merge 6 commits into
Expensify:mainfrom
nkdengineer:fix/100122-1
Open

Flag the group's own snapshot entry when a whole-group delete removes it#100675
nkdengineer wants to merge 6 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 DELETEOfflineWithFeedback 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 narrow layout no longer derives pending-delete from children.

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 wide-web header still has a children-derived pending-delete fallback, but only when the loaded children cover the whole group, 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 77.23% <100.00%> (+0.37%) ⬆️
...h/SearchList/ListItem/TransactionGroupListItem.tsx 77.20% <100.00%> (ø)
...m/shouldCollapseExpandedGroupAfterPendingDelete.ts 100.00% <100.00%> (ø)
src/hooks/useDeleteTransactions.ts 63.88% <ø> (ø)
src/libs/SearchUIUtils.ts 71.18% <ø> (ø)
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 75.36% <73.91%> (+3.34%) ⬆️
src/components/Search/selectionBuilders.ts 81.37% <79.31%> (+1.92%) ⬆️
src/hooks/useSearchBulkActions.ts 73.56% <87.23%> (+1.39%) ⬆️
... and 1 more
... and 63 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
Comment thread src/components/Search/ExpenseGroupedSearchView.tsx 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: 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 Outdated
Comment thread src/hooks/useDeleteTransactions.ts Outdated
Comment thread src/libs/actions/IOU/DeleteMoneyRequest.ts Outdated
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.

2 participants