fix: show changed nodes in diff tree when their parent is unchanged

Merged
LA
4mo ago
+409-43

Why

On the branch/proposed-change diff Data view, the left-hand tree silently omitted changed nodes whenever their hierarchical parent had no changes of its own — while the right-hand diff list showed them correctly, so the two panes disagreed. The drop was transitive: a changed parent that was itself dropped took its changed children with it. Regression since #5676 (1c4a0f9ce), originally reported by a customer whose updated Loadbalancer Pool Member had no entry in the tree because its pool was unchanged.

This PR makes every changed node visible in the right-hand diff list also appear in the left tree, nested under its (unchanged) parent — as it did before the regression. Per review, it also fixes the same pane disagreement under the Conflicts filter (?status=CONFLICT), where unchanged ancestors were dropped because contains_conflict never propagates to them.

Non-goals: no backend or GraphQL changes (the backend already returns unchanged parents on purpose via include_parents: true), no change to contains_conflict semantics, no pagination changes.

Closes #10010

What changed

Behavioral changes:

  • The diff tree again renders UNCHANGED parent nodes as hierarchy context, so changed nodes nest under them instead of disappearing.
  • With the Conflicts filter active, the tree keeps conflicted nodes plus their ancestor chains, so a conflicted node under an unchanged parent stays anchored; the right pane shows only changed nodes with conflicts, as before.
  • The right-hand diff list and its empty state are otherwise unaffected: they still show only changed nodes.
  • Multi-level parent chains no longer depend on the order nodes arrive in: buildDiffTreeItems pre-creates one tree item per node in a Map keyed by uuid, so ancestors delivered after descendants (possible across infinite-query pages) no longer cause drops.

Implementation notes:

  • Root cause: #5676 moved the UNCHANGED filter from the right-pane render into the shared nodes computation feeding both panes, starving buildDiffTreeItems of the parents it needs to anchor children (if (!parentTreeItem) return acc; then silently dropped them).
  • Fix restores the pre-regression split of concerns in node-diff/index.tsx: the tree receives all nodes, a changedNodes list feeds the right pane. The client-side CONFLICT QSP filter is likewise split: contains_conflict filters only the right pane, while the tree keeps conflicted nodes plus their ancestor chains (keepConflictNodesWithAncestors: a Map of nodes by uuid, recursive marking of each conflicted node's parents, then a filter to the marked set).
  • buildDiffTreeItems pairs each node with its tree item upfront ({ node, treeItem }), indexes the items in a Map keyed by uuid, then attaches children in a single for...of pass — the parent item always exists in the Map regardless of input order, so no retry passes are needed.
  • Nodes whose parent genuinely never appears in the payload are still skipped, as before.

What stayed the same: no schema or API changes; no changes to DiffTree rendering — the UNCHANGED badge variant already existed from the pre-regression behavior.

How to review

  • frontend/app/src/entities/diff/ui/node-diff/index.tsx — the root-cause fix (filter split, for both the UNCHANGED and CONFLICT filters).
  • frontend/app/src/entities/diff/utils/build-diff-tree-items.ts — order-independent single-pass attach via a Map of pre-created tree items.
  • frontend/app/src/entities/diff/ui/node-diff/index.test.tsx — replication tests written first and verified failing before the fix (component-level, mocks only the two GraphQL API functions): changed node under unchanged parent, and conflicted node under unchanged parent with ?status=CONFLICT.
  • frontend/app/.betterer.results — mechanical fingerprint/line shifts for the edited files, no new type issues.

How to test

cd frontend/app && pnpm run test src/entities/diff

The new tests fail without the fix and pass on this branch. Manual verification: on a demo dataset, open Branches › jfk1-update-edge-ips › Data — the updated Interface L3 Ethernet1 nodes (under unchanged devices) and the updated/added IP prefixes (under an unchanged root prefix) now appear in the left tree.

Full gates run locally: frontend suite (118 files / 807 tests), backend unit tests (1400), biome ci, knip, betterer ci.

Impact & rollout

  • Backward compatibility: none — frontend-only rendering fix restoring intended behavior.
  • Deployment notes: safe to deploy.

Checklist

  • Tests added/updated
  • Changelog entry added (uv run towncrier create ...)
  • External docs updated (not needed — restores documented/expected behavior)
  • Internal .md docs updated (not needed — no architectural change)
  • I have reviewed AI generated content

🤖 Generated with Claude Code


Summary by cubic

Fixes the diff tree dropping changed nodes under UNCHANGED parents and keeps conflicted nodes anchored when the Conflicts filter is active. Children stay visible even if their parent arrives later. Addresses #10010.

  • Bug Fixes

    • Keep UNCHANGED parents in the tree; under ?status=CONFLICT, keep conflicted nodes with their ancestors. The right pane still shows only changed nodes (and only conflicted ones under the filter).
    • Attachment is order-independent across pages; sibling order follows input.
  • Refactors

    • Rewrote buildDiffTreeItems to a single pass with a Map keyed by uuid, removing the recursive lookup and a tracked type error; tests added/updated.
    • Formatted node-diff/index.tsx to match CI; updated Betterer results.