Skip to content

fix(insights): Do not close UnitPicker modal when clicking inside it #31024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 11, 2025

Conversation

ordehi
Copy link
Contributor

@ordehi ordehi commented Apr 9, 2025

Problem

The UnitPicker component has a modal interaction issue where clicking inside the Custom prefix/postfix modal causes the parent dropdown to close unexpectedly. This happens because the modal is rendered in a Portal (outside the DOM hierarchy), but the dropdown's click detection still registers clicks inside the modal as "outside clicks" that should close the dropdown.

The issue creates a frustrating user experience as users are unable to effectively configure custom units for their visualizations.

Closes #31011

Changes

The solution completely redesigns the modal architecture to use global state management instead of relying on DOM event propagation:

  • Created a centralized Kea logic (unitPickerModalLogic) to manage the modal state
  • Implemented a global modal component (GlobalCustomUnitModal) that's mounted at app level
  • Modified the UnitPicker to trigger the global modal through state rather than rendering its own modal
  • Deleted the local modal implementation that was causing conflicts

This approach is more robust because it completely avoids the event bubbling conflicts by separating the modal from the dropdown DOM hierarchy.

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Tested locally and it works, should not change code that affects any other components but this custom modal.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR refactors the custom unit modal in UnitPicker to address unexpected dropdown closures by moving the modal to a global level.

  • Introduced /frontend/src/lib/components/UnitPicker/GlobalCustomUnitModal.tsx to handle modal rendering globally.
  • Updated /frontend/src/lib/components/UnitPicker/UnitPicker.tsx to trigger modal actions via the new global logic.
  • Added /frontend/src/lib/components/UnitPicker/unitPickerModalLogic.ts for centralized modal state management.
  • Removed the obsolete /frontend/src/lib/components/UnitPicker/CustomUnitModal.tsx component.
  • Integrated the global modal in /frontend/src/layout/GlobalModals.tsx.

5 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

github-actions bot commented Apr 9, 2025

Size Change: -282 B (0%)

Total Size: 13.2 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 13.2 MB -282 B (0%)

compressed-size-action

@raquelmsmith raquelmsmith requested a review from a team April 10, 2025 19:31
Copy link
Contributor

@anirudhpillai anirudhpillai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

@ordehi ordehi enabled auto-merge (squash) April 11, 2025 13:13
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 5)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 5)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 5)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 5)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@ordehi ordehi disabled auto-merge April 11, 2025 14:57
@ordehi ordehi enabled auto-merge (squash) April 11, 2025 14:57
@ordehi ordehi merged commit cee187d into master Apr 11, 2025
107 of 109 checks passed
@ordehi ordehi deleted the fix/unitpicker-clicks branch April 11, 2025 15:21
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.

Bug: Clicking anywhere in the custom prefix/postfix modal closes it
3 participants