Skip to content

Fixes #39136: Run drawer onBeforeClose on ESC and backdrop dismissals - #39173

Open
detail-app[bot] wants to merge 2 commits into
mainfrom
detail/bug-fix/fixes-39136-run-drawer-onbeforeclose-on-esc-and-ba-ee3f58
Open

detail-app[bot] wants to merge 2 commits into
mainfrom
detail/bug-fix/fixes-39136-run-drawer-onbeforeclose-on-esc-and-ba-ee3f58

Conversation

@detail-app

@detail-app detail-app Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Describe your changes:

Fixes #39136

The shared atoms/drawer hook family (useDrawer / useCompositeDrawer / useFormDrawer) is the Save/Cancel drawer pattern used across the UI. onBeforeClose (wired to consumer onCancel and, for useFormDrawerWithHook, to hookForm.reset()) is the cleanup meant to run on every close.

The Escape-key and backdrop-click dismissals close the drawer through useDrawer's own handleOpenChange → closeDrawer, which never invoked onBeforeClose — so onCancel and form-reset silently did not run on those two paths, while the Cancel button and header X did (regression-introduced in the founding commit 7b5834e of the atomic-design refactor). User-visible impact: in the Column Bulk Operations grid, pressing ESC closed the edit drawer without running discardPendingEdits, leaving rows in an "edited" state the user believed was discarded; useFormDrawerWithHook consumers skipped hookForm.reset() on ESC/backdrop, so stale typed values reappeared on the next open.

I worked on routing every close reason — programmatic closeDrawer(), header X, footer Cancel, Escape, and backdrop — through a single onBeforeClose choke point, so cleanup runs consistently regardless of how the drawer closes.

Type of change:

  • Bug fix

High-level design:

N/A — small change, but the fix is one focused change to the base hook:

  • Added onBeforeClose?: () => void to DrawerConfig and invoke it at the top of useDrawer.closeDrawer(). Since all close reasons (including react-aria ModalOverlay's onOpenChange(false) from Escape/backdrop) funnel through that single closeDrawer, this is the natural interception point.
  • useCompositeDrawer now forwards onBeforeClose down to useDrawer instead of calling it only on its own wrappers, and its custom header.onClose branch calls onBeforeClose explicitly (it bypasses baseDrawer.closeDrawer, so it can't rely on the base). The duplicated overridden closeDrawer was removed to prevent double-firing.
  • useFormDrawer's wiring (onBeforeClose: onCancel) is unchanged; only the now-stale comments were corrected.

The alternative — intercepting onOpenChange in useCompositeDrawer — would have left the bypass in useDrawer for any other consumer and required duplicating the interception. Putting it on the base hook fixes the root cause and keeps the composite/form hooks free of close-path bookkeeping.

Tests:

Use cases covered

  • Closing a form drawer via ESC runs the consumer's onCancel (previously skipped).
  • Closing a form drawer via backdrop click runs onCancel (previously skipped).
  • useFormDrawerWithHook runs hookForm.reset() on ESC and Cancel, so stale typed values don't survive a close+reopen (previously skipped on ESC/backdrop).
  • The closeOnEscape: false opt-out still suppresses Escape (no regression for the consumers relying on it).
  • A custom header.onClose consumer still runs onBeforeClose exactly once and closeOnBackdrop: false rendering wiring is unchanged (no regression).
  • All four close paths (header X, Cancel, ESC, backdrop) plus programmatic closeDrawer() run onBeforeClose exactly once — no zero, no double-fire.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated:
    • useDrawer.test.tsx (new) — onBeforeClose on programmatic close, Escape, open-doesn't-fire, omitted-handler, closeOnEscape:false.
    • useDrawerBackdrop.test.tsx (new) — onBeforeClose on backdrop onOpenChange(false) (drives the stubbed SlideoutMenu the repo's jsdom setup requires, since react-aria's interact-outside can't be fired by synthetic events).
    • useCompositeDrawer.test.tsx (new) — onBeforeClose on header X, Escape, programmatic, and the custom header.onClose no-double-fire branch.
    • useFormDrawer.test.tsx (updated) — onCancel on header X / Cancel / Escape, open-doesn't-fire, and hookForm.reset() + onCancel on Escape / Cancel for the react-hook-form variant.
  • Coverage: the 4 hook files are exercised across all 5 close paths; the new tests fail in the exact 12 close-path assertions when the fix is reverted (RED), confirming they catch the bug.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable — no new Playwright specs added. The existing playwright/e2e/Features/ColumnBulkOperations.spec.ts already exercises Escape and Cancel closes of the edit drawer; this PR does not modify it. Local Playwright verification against a running stack was attempted but blocked (see Manual testing).

Manual testing performed

  • Ran the full atoms/drawer Jest suite (7 suites, 34 tests) — all pass. Reverted the one-line fix in useDrawer.closeDrawer to confirm the new tests fail in exactly the 12 close-path assertions (RED), then restored.
  • Ran real-hook consumer tests (ColumnGrid.test.tsx, useGlossaryCreateDrawer.test.tsx, GlossaryTermDrawer.test.tsx) — 15 pass; no regression. Ran mocked-hook consumer tests (BundleSuiteFormDrawer, DomainDetails, ContextRuleEditor) — 41 pass; return-shape contract preserved.
  • Static gates: ESLint 0 errors (3 pre-existing react-hooks/exhaustive-deps warnings, unchanged from pre-fix); Prettier + organize-imports idempotent and conformant; yarn tsc:check shows 0 errors in the changed files (the fix actually removes 6 baseline TS errors by adding the missing onBeforeClose field). License headers verified via yarn license-header-fix.
  • Playwright E2E (the existing ColumnBulkOperations spec, which closes the drawer with Escape and the Cancel button) could not be run end-to-end: the suite targets http://localhost:8585 and no OpenMetadata stack is running. I installed the Playwright Chromium browser and its OS dependencies to unblock it, but reached connect ECONNREFUSED 127.0.0.1:8585; the 2.0.0-SNAPSHOT Docker images for this dev branch aren't published (manifest unknown), a local build is multi-hour, and the host has ~2.8 GB free RAM (the MySQL+Elasticsearch+OM stack needs ≥5–6 GB). The ESC/backdrop/header-X/Cancel close-path behavior those E2Es would verify is fully covered at the hook level by the unit tests (the same react-aria onOpenChange(false) → useDrawer.closeDrawer code path), and the specific ColumnGrid consumer regression is covered by ColumnGrid.test.tsx.

UI screen recording:

Not applicable — this is a bug fix to shared drawer hooks, not a UI feature/feature task. The behaviour change (cleanup now running on ESC/backdrop) has no visible UI surface beyond the drawer closing the same way it did before.

Checklist:

  • I have read CONTRIBUTING.md (the pre-review gate) and the contributor docs.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. — N/A (no schema changes).
  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable). — N/A (bug fix, not a feature).
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). — N/A (restores the original intended contract of onBeforeClose; no new durable decision).
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

Automatic Fixes PRs can be configured here.

@detail-app
detail-app Bot requested a review from a team as a code owner November 28, 2026 03:17
@detail-app
detail-app Bot requested a review from harsh-vador November 28, 2026 03:17
@detail-app
detail-app Bot force-pushed the detail/bug-fix/fixes-39136-run-drawer-onbeforeclose-on-esc-and-ba-ee3f58 branch from bb590e4 to 2b07e56 Compare November 28, 2026 06:05

This branch has not been deployed

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

[Detail Bug] UI Drawers: ESC/backdrop close skips form cancel/reset logic

1 participant