Skip to content

fix: Schema Diff filter chip toggle broadcasting stale empty selection#10172

Open
kundansable wants to merge 1 commit into
pgadmin-org:masterfrom
kundansable:fix-10102-schemadiff-filter
Open

fix: Schema Diff filter chip toggle broadcasting stale empty selection#10172
kundansable wants to merge 1 commit into
pgadmin-org:masterfrom
kundansable:fix-10102-schemadiff-filter

Conversation

@kundansable

@kundansable kundansable commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #10102 — in Tools → Schema Diff, toggling a result-status filter chip off and back on shows "No difference found" even when real differences exist, until the whole comparison is re-run.

Root Cause

selectFilterOption() computed the new chip selection (newOptions) inside the functional form of setSelectedFilters(prev => {...}), then immediately used that same newOptions variable to dispatch TRIGGER_CHANGE_FILTER synchronously in the same tick. React's functional state updater runs lazily during the next render — so at the point the event was dispatched, newOptions was still its initial empty array. Every chip toggle therefore broadcast an empty filter, prepareRows() had nothing to render, and the tree went blank. The initial "Compare" click worked fine only because it reads selectedFilters state directly rather than going through this buggy path.

Fix

Compute the new filter selection synchronously from the current selectedFilters state (not from inside the setSelectedFilters updater callback), and use that same synchronously-computed array both to update state and to dispatch the change event — so the event and the state always agree.

Test Steps

  1. Tools → Schema Diff → pick a source/target database or schema pair with real differences (some objects "Source Only", "Target Only", and "Different").
  2. Click Compare — confirm the results tree shows non-zero counts.
  3. Open the Filter dropdown, click a status chip to deselect it (e.g. "Identical").
  4. Click the same chip again to re-enable it.
  5. Expected: the results tree restores exactly the rows that match the now-active filters, with correct counts at every level — no "No difference found" flash, no need to re-run Compare.
  6. Repeat with multiple chips toggled in different orders to confirm no combination re-breaks it.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed schema diff filter selection so applied filters are consistently reflected immediately.
    • Corrected filter change notifications to report the current selection accurately when toggling options.

selectFilterOption() read newOptions from inside the functional
setSelectedFilters(prev => {...}) updater and used it to dispatch
TRIGGER_CHANGE_FILTER synchronously in the same tick. React's
functional updater runs lazily during render, so newOptions was still
its initial [] value when the event fired — every chip toggle
broadcast an empty filter, so prepareRows() returned nothing and the
results tree showed "No difference found" until the whole comparison
was re-run.

Compute the new selection synchronously from the current
selectedFilters state and use that same array for both the state
update and the dispatched event, so the filter chips and the results
grid stay in sync on every toggle.

Fixes pgadmin-org#10102
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Schema Diff filter toggling now computes the next selected filter array synchronously, uses it for the state update, and emits the same selection in the filter-change event.

Changes

Schema Diff filter behavior

Layer / File(s) Summary
Synchronous filter selection update
web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx
selectFilterOption derives the next filter selection before updating state and dispatches TRIGGER_CHANGE_FILTER with that computed selection.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main Schema Diff filter toggle fix.
Linked Issues check ✅ Passed The code change matches the reported filter-chip bug by syncing the emitted selection with the current toggle state.
Out of Scope Changes check ✅ Passed The diff is narrowly scoped to the Schema Diff filter toggle fix with no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

🧹 Nitpick comments (1)
web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx (1)

115-130: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for filter-toggle synchronization.

The implementation correctly sends the synchronously computed selection, but add tests covering off→on restoration, multiple toggle orders, correct hierarchy counts, and ensuring TRIGGER_COMPARE_DIFF is not emitted during filter changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx`
around lines 115 - 130, Add regression tests for the filter-toggle flow around
the SchemaDiffButtonComponent selection handler, covering off-to-on restoration,
multiple toggle orders, and accurate hierarchy counts. Also assert that filter
changes emit TRIGGER_CHANGE_FILTER with the computed selection without emitting
TRIGGER_COMPARE_DIFF.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx`:
- Around line 115-130: Add regression tests for the filter-toggle flow around
the SchemaDiffButtonComponent selection handler, covering off-to-on restoration,
multiple toggle orders, and accurate hierarchy counts. Also assert that filter
changes emit TRIGGER_CHANGE_FILTER with the computed selection without emitting
TRIGGER_COMPARE_DIFF.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb86f777-ed03-4034-a3e3-6e5e03eb2b5c

📥 Commits

Reviewing files that changed from the base of the PR and between b15c745 and e0c191e.

📒 Files selected for processing (1)
  • web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx

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.

Issue with Schema Diff filter

1 participant