Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type CompassComponentsProviderProps = {
* zIndex for the stacked elements (modal, toast, popover)
*/
stackedElementsZIndex?: number;

/**
* Set to disable context menus in the application.
*/
disableContextMenus?: boolean;
} & {
onNextGuideGue?: GuideCueProviderProps['onNext'];
onNextGuideCueGroup?: GuideCueProviderProps['onNextGroup'];
Expand Down Expand Up @@ -100,6 +105,7 @@ export const CompassComponentsProvider = ({
utmMedium,
stackedElementsZIndex,
popoverPortalContainer: _popoverPortalContainer,
disableContextMenus,
...signalHooksProviderProps
}: CompassComponentsProviderProps) => {
const darkMode = useDarkMode(_darkMode);
Expand Down Expand Up @@ -136,7 +142,7 @@ export const CompassComponentsProvider = ({
>
<SignalHooksProvider {...signalHooksProviderProps}>
<ConfirmationModalArea>
<ContextMenuProvider>
<ContextMenuProvider disabled={disableContextMenus}>
<ToastArea>
{typeof children === 'function'
? children({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export type { ContextMenuItem } from '@mongodb-js/compass-context-menu';

export function ContextMenuProvider({
children,
disabled,
}: {
children: React.ReactNode;
disabled?: boolean;
}) {
return (
<ContextMenuProviderBase menuWrapper={ContextMenu}>
<ContextMenuProviderBase disabled={disabled} menuWrapper={ContextMenu}>
{children}
</ContextMenuProviderBase>
);
Expand Down
13 changes: 9 additions & 4 deletions packages/compass-context-menu/src/context-menu-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ import React, {
createContext,
useContext,
} from 'react';

import type { ContextMenuContextType, ContextMenuState } from './types';
import type { EnhancedMouseEvent } from './context-menu-content';
import { getContextMenuContent } from './context-menu-content';
import {
getContextMenuContent,
type EnhancedMouseEvent,
} from './context-menu-content';

export const ContextMenuContext = createContext<ContextMenuContextType | null>(
null
);

export function ContextMenuProvider({
disabled = false,
children,
menuWrapper,
}: {
disabled?: boolean;
children: React.ReactNode;
menuWrapper: React.ComponentType<{
menu: ContextMenuState & { close: () => void };
Expand Down Expand Up @@ -47,7 +52,7 @@ export function ContextMenuProvider({

useEffect(() => {
// Don't set up event listeners if we have a parent context
if (parentContext) return;
if (parentContext || disabled) return;

function handleContextMenu(event: MouseEvent) {
event.preventDefault();
Expand Down Expand Up @@ -76,7 +81,7 @@ export function ContextMenuProvider({
document.removeEventListener('contextmenu', handleContextMenu);
window.removeEventListener('resize', handleClosingEvent);
};
}, [handleClosingEvent, parentContext]);
}, [disabled, handleClosingEvent, parentContext]);

const value = useMemo(
() => ({
Expand Down
8 changes: 8 additions & 0 deletions packages/compass-preferences-model/src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type FeatureFlags = {
enableDataModeling: boolean;
enableIndexesGuidanceExp: boolean;
showIndexesGuidanceVariant: boolean;
enableContextMenus: boolean;
};

export const featureFlags: Required<{
Expand Down Expand Up @@ -140,4 +141,11 @@ export const featureFlags: Required<{
'Used to check if user is in the Indexes Guidance Experiment Variant',
},
},

enableContextMenus: {
stage: 'development',
description: {
short: 'Enable context (right-click) menus',
},
},
};
3 changes: 3 additions & 0 deletions packages/compass/src/app/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type { WorkspaceTab } from '@mongodb-js/compass-workspaces';
import { ConnectionStorageProvider } from '@mongodb-js/connection-storage/provider';
import { ConnectionImportExportProvider } from '@mongodb-js/compass-connection-import-export';
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
import { usePreference } from 'compass-preferences-model/provider';

resetGlobalCSS();

Expand Down Expand Up @@ -169,6 +170,7 @@ export default function ThemedHome(
props: HomeWithConnectionsProps
): ReturnType<typeof HomeWithConnections> {
const track = useTelemetry();
const disableContextMenus = !usePreference('enableContextMenus');
return (
<CompassComponentsProvider
onNextGuideGue={(cue) => {
Expand Down Expand Up @@ -204,6 +206,7 @@ export default function ThemedHome(
onSignalClose={(id) => {
track('Signal Closed', { id });
}}
disableContextMenus={disableContextMenus}
>
{({ darkMode, portalContainerRef }) => {
return (
Expand Down
Loading