Skip to content

chore(compass-telemetry): add right-click telemetry events for Compass COMPASS-9660 #7168

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 6 commits into from
Aug 11, 2025

Conversation

gagik
Copy link
Contributor

@gagik gagik commented Aug 5, 2025

Adds telemetry events to right click menu actions.

Pending CI tests.

@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 10:31
@gagik gagik requested a review from a team as a code owner August 5, 2025 10:31
@@ -44,8 +44,7 @@ const tsxRules = {
'react-hooks/exhaustive-deps': [
'warn',
{
additionalHooks:
'(useTrackOnChange|useContextMenuItems|useContextMenuGroups)',
additionalHooks: '(useTrackOnChange|useContextMenuGroups)',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we seem to be converging on useContextMenuGroups so I'm removing the old useContextMenuItems syntax

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds telemetry tracking to context menu interactions in Compass by introducing event tracking for context menu openings and item clicks. The changes restructure the context menu system to support telemetry labels on menu groups and implement the tracking logic.

  • Refactors context menu API from item-based to group-based structure with telemetry labels
  • Adds telemetry event tracking for context menu opens and item clicks
  • Updates all context menu usage throughout the codebase to use the new group-based API

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/compass/src/app/components/home.tsx Adds telemetry tracking callbacks to the main Compass component
packages/compass-telemetry/src/telemetry-events.ts Defines new telemetry event types for context menu interactions
packages/compass-context-menu/src/use-context-menu.tsx Updates API from registerItems to registerItemGroups with telemetry support
packages/compass-context-menu/src/types.ts Adds ContextMenuItemGroup type with telemetry labels
packages/compass-context-menu/src/context-menu-provider.tsx Implements onContextMenuOpen callback support
packages/compass-components/src/components/context-menu.tsx Adds telemetry click tracking and removes deprecated useContextMenuItems
packages/compass-sidebar/src/components/multiple-connections/connections-navigation.tsx Migrates from useContextMenuItems to useContextMenuGroups
packages/compass-crud/src/components/use-document-item-context-menu.tsx Updates context menu structure with telemetry labels
packages/compass-crud/src/components/crud-toolbar.tsx Migrates to group-based context menu API
packages/compass-connections-navigation/src/context-menus.ts Adds telemetry label parameter to context menu helper
packages/compass-connections-navigation/src/connections-navigation-tree.tsx Provides telemetry labels for tree item context menus
packages/compass-components/src/components/workspace-tabs/tab.tsx Migrates tab context menu to new API
packages/compass-components/src/components/document-list/element.tsx Updates element field context menu with telemetry
packages/compass-components/src/components/compass-components-provider.tsx Adds telemetry callback props to the provider
configs/eslint-config-compass/index.js Removes deprecated useContextMenuItems from ESLint config
Comments suppressed due to low confidence (1)

packages/compass-crud/src/components/use-document-item-context-menu.tsx:57

  • The ternary operator condition isEditable is missing proper structure. The conditional item should be wrapped in brackets or properly structured as isEditable ? { ... } : undefined.
          isEditable

@gagik gagik added the no release notes Fix or feature not for release notes label Aug 5, 2025
],
},
{
telemetryLabel: 'Document Item Delete',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

intentionally moving this to its own group since we have this pattern of separating deletions into its own thing

@gagik gagik changed the title chore(compass-telemetry): add telemetry events for Compass chore(compass-telemetry): add telemetry events for Compass COMPASS-9660 Aug 5, 2025
Comment on lines +192 to +198
onContextMenuOpen={(itemGroups) => {
if (itemGroups.length > 0) {
track('Context Menu Opened', {
item_groups: itemGroups.map((group) => group.telemetryLabel),
});
}
}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is slightly annoying, but this only adds tracking on the compass desktop side, you'd want the same code on the compass-web side too (until we have time to deal with https://jira.mongodb.org/browse/COMPASS-7830)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@gribnoysup gribnoysup Aug 7, 2025

Choose a reason for hiding this comment

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

You don't need to do this in DE, this is something you have to do in the entrypoint in compass-web package 🙂

@@ -85,7 +94,7 @@ export function ContextMenuProvider({
capture: true,
});
};
}, [disabled, handleClosingEvent, parentContext]);
}, [disabled, handleClosingEvent, onContextMenuOpen, parentContext]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this an expected effect change here? Seems very easy to cause this effect to run on almost every render for no good reason. Your current callback implementation for example recreates functions every render and while in desktop this high level render is more or less stable, in compass-web we are quite some levels down, so React will be re-rendering compass-web quite often

@@ -100,7 +92,8 @@ export function ContextMenuProvider({
capture: true,
});
};
}, [disabled, handleClosingEvent, handleContextMenuOpen, parentContext]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [disabled, handleClosingEvent, parentContext]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gribnoysup is removing it from the dependencies a good enough solution? I was also thinking of wrapping it in a useCallback with [] but that doesn't seem any better. alternatively I could do a `useCallback on application-level

Copy link
Collaborator

Choose a reason for hiding this comment

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

In other parts of the app we use a useRef that updates in render to keep the latest stable reference to the prop (recent example). I personally do prefer this to just adding an exception (because an exception doesn't differenciate and if you change dependencies later you might miss actually important dependencies) and it means you are actually calling the latest version of the function, but an exception is also fine in this particular case, I'd just suggest to add a comment explaining why you are adding an exception here.

@gagik gagik requested a review from gribnoysup August 8, 2025 12:44
@gagik gagik force-pushed the gagik/rc-telemetry branch from 71b2cd4 to 9bcb7c0 Compare August 8, 2025 13:26
@gagik gagik force-pushed the gagik/rc-telemetry branch from 9bcb7c0 to 9014d4e Compare August 11, 2025 12:08
@gagik gagik merged commit f85f637 into main Aug 11, 2025
17 of 18 checks passed
@gagik gagik deleted the gagik/rc-telemetry branch August 11, 2025 13:10
@lerouxb lerouxb changed the title chore(compass-telemetry): add telemetry events for Compass COMPASS-9660 chore(compass-telemetry): add right-click telemetry events for Compass COMPASS-9660 Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants