Skip to content

chore: support cmd click on all clickable items#10350

Merged
YounixM merged 14 commits intomainfrom
chore/support-cmd-click
Mar 30, 2026
Merged

chore: support cmd click on all clickable items#10350
YounixM merged 14 commits intomainfrom
chore/support-cmd-click

Conversation

@YounixM
Copy link
Copy Markdown
Member

@YounixM YounixM commented Feb 18, 2026

Pull Request


Summary

Why does this change exist?
What problem does it solve, and why is this the right approach?

Users expect Cmd+Click (Mac) / Ctrl+Click (Windows/Linux) on clickable items to open the target in a new browser tab - a universal web convention. Currently, SPA navigation via safeNavigate always replaces the current page, ignoring modifier keys. Several components (e.g. DashboardsList, ListAlert) had ad-hoc event.metaKey || event.ctrlKey checks with window.open, leading to duplicated logic and inconsistent coverage.

This PR centralizes modifier-key detection in useSafeNavigate by accepting an optional event parameter. When a click event is provided and Cmd/Ctrl is held, the hook automatically opens the target in a new tab instead of performing SPA navigation. A shared utils/navigation.ts module provides the low-level helpers (isModifierKeyPressed, openInNewTab, navigateToPage) for cases outside the hook.

50 files are updated to thread the mouse event from click handlers into safeNavigate, covering: homepage service tables, infra monitoring K8s lists (Pods, Nodes, Clusters, Deployments, etc.), hosts list, alert rules, dashboards list, metrics explorer, side nav, onboarding flows, messaging queues, breadcrumbs, and more. Two files (DashboardsList, ListAlert) that had duplicated manual Cmd/Ctrl detection were refactored to use the centralized approach.

Screenshots / Screen Recordings (if applicable)

N/A - behavioral change: hold Cmd/Ctrl while clicking any navigable row, link, or button to open in a new tab.

Issues closed by this PR


Change Type

Select all that apply

  • Feature
  • Bug fix
  • Refactor
  • Infra / Tooling
  • Test-only

Bug Context

N/A - this is a new feature / UX enhancement, not a bug fix.


Testing Strategy

How was this change validated?

  • Tests added/updated:
    • src/utils/__tests__/navigation.test.ts - 15 tests covering isModifierKeyPressed, openInNewTab, and navigateToPage with various modifier key combinations, edge cases (both metaKey and ctrlKey), and fallback to SPA navigation.
    • src/hooks/__tests__/useSafeNavigate.test.ts - 9 tests verifying the mock contract accepts event and newTab options, and that the shouldOpenNewTab decision logic correctly combines explicit newTab with modifier-key detection.
  • Manual verification: Cmd+Click on service rows, dashboard list items, alert rule links, K8s resource tables, side nav items, and breadcrumbs all open in a new tab. Normal clicks continue to use SPA navigation.
  • Edge cases covered: Both metaKey (Mac) and ctrlKey (Windows/Linux), newTab: true without event, event without modifier keys, both newTab and modifier keys simultaneously.

Risk & Impact Assessment

What could break? How do we recover?

  • Blast radius: Frontend-only. Affects click behavior across ~50 components. No backend changes.
  • Potential regressions:
    • A click handler that previously ignored the event parameter now passes it through - if any component has an onClick that provides a non-standard event shape, isModifierKeyPressed will safely return false (checking metaKey/ctrlKey on undefined returns falsy).
    • Factory functions in MetricsApplication/Tabs/util.ts changed return type from VoidFunction to (e?: React.MouseEvent) => void - callers passing these as onClick handlers are compatible since React's onClick provides the event as the first argument.
  • Rollback plan: Revert the single commit. No data migration or API changes involved.

Changelog

Field Value
Deployment Type Cloud / OSS / Enterprise
Change Type Feature
Description Cmd/Ctrl+Click on navigable items (table rows, links, buttons) now opens the target in a new browser tab instead of replacing the current page.

Checklist

  • Tests added or explicitly not required
  • Manually tested
  • Breaking changes documented
  • Backward compatibility considered

Notes for Reviewers

Core changes (read first):

  • src/utils/navigation.ts - new shared helpers for modifier-key detection
  • src/hooks/useSafeNavigate.ts - accepts event option, auto-detects Cmd/Ctrl
  • __mocks__/useSafeNavigate.ts - mock updated to match new interface

Pattern across all 50 files:

  1. Add React import (for React.MouseEvent type)
  2. Thread mouse event from onClick handler into safeNavigate(..., { event })
  3. For table onRow handlers: change callback signature to accept (record, event) and pass event through

Refactored duplicated logic:

  • DashboardsList.tsx - removed manual event.metaKey || event.ctrlKey + window.open (6 lines to 1 line)
  • ListAlert.tsx - replaced openInNewTab: boolean parameter with { event?, newTab? } options object, removed manual window.open branch

Intentionally not changed - safeNavigate calls inside useEffect, onSuccess mutation callbacks, setTimeout, drag handlers, and pagination onChange handlers where no MouseEvent is available. These are programmatic navigations where Cmd+Click does not apply.

@YounixM YounixM marked this pull request as ready for review February 25, 2026 07:29
@YounixM YounixM requested review from a team and makeavish as code owners February 25, 2026 07:29
@YounixM YounixM force-pushed the chore/support-cmd-click branch from 330e2d2 to ec5b542 Compare February 25, 2026 07:29
@YounixM YounixM requested a review from H4ad February 25, 2026 07:55
@YounixM YounixM force-pushed the chore/support-cmd-click branch from ec5b542 to 32d7216 Compare March 9, 2026 14:07
H4ad
H4ad previously approved these changes Mar 9, 2026
H4ad
H4ad previously approved these changes Mar 18, 2026
@YounixM YounixM added this pull request to the merge queue Mar 30, 2026
Merged via the queue into main with commit 198b542 Mar 30, 2026
17 checks passed
@YounixM YounixM deleted the chore/support-cmd-click branch March 30, 2026 08:53
tushar-signoz pushed a commit that referenced this pull request Mar 30, 2026
* chore: support cmd click on all clickable items

* chore: update test cases

* feat: address review comments

* feat: enhance navigation tests for middle mouse button interactions

* refactor: update navigation handling to use safeNavigate with newTab option

* feat: support opening links in new tab with modifier key in K8sPodsList and SideNav

* chore: clean up environment variable usage in login utility and remove unused test file

* refactor: update import order and adjust navigation call in AlertNotFound tests

* chore: remove eslint disable

* chore: move isModiferKey to app util file

* feat: update buildAbsolutePath to handle empty relative path

* chore: fix import error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore staging:kind-snipe Staging Env - Yunus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants