Skip to content

Commit d834fa9

Browse files
committed
WIP
1 parent 66beb5b commit d834fa9

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

packages/compass-context-menu/src/context-menu-provider.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ import React, {
66
createContext,
77
useContext,
88
} from 'react';
9+
910
import type { ContextMenuContextType, ContextMenuState } from './types';
10-
import type { EnhancedMouseEvent } from './context-menu-content';
11-
import { getContextMenuContent } from './context-menu-content';
11+
import {
12+
getContextMenuContent,
13+
type EnhancedMouseEvent,
14+
} from './context-menu-content';
15+
16+
import { usePreference } from 'compass-preferences-model/provider';
1217

1318
export const ContextMenuContext = createContext<ContextMenuContextType | null>(
1419
null
@@ -45,9 +50,11 @@ export function ContextMenuProvider({
4550
[close]
4651
);
4752

53+
const enabled = usePreference('enableContextMenus');
54+
4855
useEffect(() => {
4956
// Don't set up event listeners if we have a parent context
50-
if (parentContext) return;
57+
if (parentContext || !enabled) return;
5158

5259
function handleContextMenu(event: MouseEvent) {
5360
event.preventDefault();
@@ -76,7 +83,7 @@ export function ContextMenuProvider({
7683
document.removeEventListener('contextmenu', handleContextMenu);
7784
window.removeEventListener('resize', handleClosingEvent);
7885
};
79-
}, [handleClosingEvent, parentContext]);
86+
}, [enabled, handleClosingEvent, parentContext]);
8087

8188
const value = useMemo(
8289
() => ({

packages/compass-preferences-model/src/feature-flags.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type FeatureFlags = {
2626
enableDataModeling: boolean;
2727
enableIndexesGuidanceExp: boolean;
2828
showIndexesGuidanceVariant: boolean;
29+
enableContextMenus: boolean;
2930
};
3031

3132
export const featureFlags: Required<{
@@ -140,4 +141,11 @@ export const featureFlags: Required<{
140141
'Used to check if user is in the Indexes Guidance Experiment Variant',
141142
},
142143
},
144+
145+
enableContextMenus: {
146+
stage: 'development',
147+
description: {
148+
short: 'Enable context (right-click) menus',
149+
},
150+
},
143151
};

packages/compass-welcome/src/components/desktop-welcome-tab.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
cx,
1515
useDarkMode,
1616
Icon,
17+
useContextMenuItems,
1718
} from '@mongodb-js/compass-components';
1819
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
1920
import { useConnectionActions } from '@mongodb-js/compass-connections/provider';
@@ -69,8 +70,14 @@ function AtlasHelpSection(): React.ReactElement {
6970
const track = useTelemetry();
7071
const darkMode = useDarkMode();
7172

73+
const menuRef = useContextMenuItems(
74+
() => [{ label: 'Click me', onAction() {} }],
75+
[]
76+
);
77+
7278
return (
7379
<div
80+
ref={menuRef}
7481
className={cx(
7582
sectionContainerStyles,
7683
atlasContainerStyles,

0 commit comments

Comments
 (0)