Skip to content

The open alternative to Salesforce, designed for AI.

Let Cmd+J toggle the log console on settings pages (#27973)

martmull3ce79b6bf388
diff --git a/packages/twenty-front/src/modules/log-console/components/LogConsoleToggleHotkeyEffect.tsx b/packages/twenty-front/src/modules/log-console/components/LogConsoleToggleHotkeyEffect.tsx
index 12c99fe702f..e2f096e6a38 100644
--- a/packages/twenty-front/src/modules/log-console/components/LogConsoleToggleHotkeyEffect.tsx
+++ b/packages/twenty-front/src/modules/log-console/components/LogConsoleToggleHotkeyEffect.tsx
@@ -11,6 +11,7 @@ export const LogConsoleToggleHotkeyEffect = ({
keys: ['ctrl+j', 'meta+j'],
callback: onToggle,
containsModifier: true,
+ enableOnSettingsPage: true,
dependencies: [onToggle],
});
diff --git a/packages/twenty-front/src/modules/log-console/components/__tests__/LogConsole.test.tsx b/packages/twenty-front/src/modules/log-console/components/__tests__/LogConsole.test.tsx
index be9129788a3..956733ddc6d 100644
--- a/packages/twenty-front/src/modules/log-console/components/__tests__/LogConsole.test.tsx
+++ b/packages/twenty-front/src/modules/log-console/components/__tests__/LogConsole.test.tsx
@@ -19,7 +19,11 @@ import { logConsoleActiveSourceIdState } from '@/log-console/states/logConsoleAc
import { logConsoleDisplayModeState } from '@/log-console/states/logConsoleDisplayModeState';
import { logConsoleHeightState } from '@/log-console/states/logConsoleHeightState';
import { useSetAdvancedMode } from '@/navigation/hooks/useSetAdvancedMode';
+import { PageFocusId } from '@/types/PageFocusId';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
+import { focusStackState } from '@/ui/utilities/focus/states/focusStackState';
+import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
+import { type FocusStackItem } from '@/ui/utilities/focus/types/FocusStackItem';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import {
jotaiStore,
@@ -58,6 +62,18 @@ jest.mock('@/log-console/components/LogConsoleDetailPanel', () => ({
LogConsoleDetailPanel: () => null,
}));
+const SETTINGS_PAGE_FOCUS_STACK_ITEM: FocusStackItem = {
+ focusId: PageFocusId.Settings,
+ componentInstance: {
+ componentType: FocusComponentType.PAGE,
+ componentInstanceId: PageFocusId.Settings,
+ },
+ globalHotkeysConfig: {
+ enableGlobalHotkeysWithModifiers: false,
+ enableGlobalHotkeysConflictingWithKeyboard: false,
+ },
+};
+
const DeveloperModeSwitch = () => {
const isAdvancedModeEnabled = useAtomStateValue(isAdvancedModeEnabledState);
const { setAdvancedMode } = useSetAdvancedMode();
@@ -308,6 +324,49 @@ describe('LogConsole', () => {
expect(jotaiStore.get(logConsoleActiveSourceIdState.atom)).toBe('app-logs');
});
+ it('toggles with Mod+J on a page that turns off modifier hotkeys', async () => {
+ renderWithLogsFeatureFlag(true);
+ act(() => {
+ jotaiStore.set(isAdvancedModeEnabledState.atom, true);
+ jotaiStore.set(focusStackState.atom, [SETTINGS_PAGE_FOCUS_STACK_ITEM]);
+ jotaiStore.set(logConsoleDisplayModeState.atom, 'collapsed');
+ });
+
+ await userEvent.keyboard('{Control>}j{/Control}');
+
+ expect(jotaiStore.get(logConsoleDisplayModeState.atom)).toBe('open');
+
+ await userEvent.keyboard('{Meta>}j{/Meta}');
+
+ expect(jotaiStore.get(logConsoleDisplayModeState.atom)).toBe('collapsed');
+ });
+
+ it('ignores Mod+J while a dialog turns off modifier hotkeys', async () => {
+ renderWithLogsFeatureFlag(true);
+ act(() => {
+ jotaiStore.set(isAdvancedModeEnabledState.atom, true);
+ jotaiStore.set(focusStackState.atom, [
+ SETTINGS_PAGE_FOCUS_STACK_ITEM,
+ {
+ focusId: 'dialog',
+ componentInstance: {
+ componentType: FocusComponentType.MODAL,
+ componentInstanceId: 'dialog',
+ },
+ globalHotkeysConfig: {
+ enableGlobalHotkeysWithModifiers: false,
+ enableGlobalHotkeysConflictingWithKeyboard: false,
+ },
+ },
+ ]);
+ jotaiStore.set(logConsoleDisplayModeState.atom, 'collapsed');
+ });
+
+ await userEvent.keyboard('{Control>}j{/Control}');
+
+ expect(jotaiStore.get(logConsoleDisplayModeState.atom)).toBe('collapsed');
+ });
+
it('stays hidden when the logs feature flag is off', async () => {
renderWithLogsFeatureFlag(false);
diff --git a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGlobalHotkeys.ts b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGlobalHotkeys.ts
index f6e7d145303..c207249c171 100644
--- a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGlobalHotkeys.ts
+++ b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGlobalHotkeys.ts
@@ -17,12 +17,14 @@ export const useGlobalHotkeys = ({
keys,
callback,
containsModifier,
+ enableOnSettingsPage,
dependencies,
options,
}: {
keys: Keys;
callback: HotkeyCallback;
containsModifier: boolean;
+ enableOnSettingsPage?: boolean;
dependencies?: unknown[];
options?: UseHotkeysOptionsWithoutBuggyOptions;
}) => {
@@ -70,6 +72,7 @@ export const useGlobalHotkeys = ({
},
preventDefault,
containsModifier,
+ enableOnSettingsPage,
});
},
{
diff --git a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGlobalHotkeysCallback.ts b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGlobalHotkeysCallback.ts
index 2c794b1ec3d..1badf6ea4f1 100644
--- a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGlobalHotkeysCallback.ts
+++ b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGlobalHotkeysCallback.ts
@@ -1,7 +1,9 @@
import { useCallback } from 'react';
+import { PageFocusId } from '@/types/PageFocusId';
import { DEBUG_FOCUS_STACK } from '@/ui/utilities/focus/constants/DebugFocusStack';
import { currentGlobalHotkeysConfigSelector } from '@/ui/utilities/focus/states/currentGlobalHotkeysConfigSelector';
+import { focusStackState } from '@/ui/utilities/focus/states/focusStackState';
import { isKeyboardEventComposing } from '@/ui/utilities/hotkey/utils/isKeyboardEventComposing';
import { useStore } from 'jotai';
import { Key } from 'ts-key-enum';
@@ -25,20 +27,28 @@ export const useGlobalHotkeysCallback = (
hotkeysEvent,
keyboardEvent,
preventDefault,
+ enableOnSettingsPage,
}: {
keyboardEvent: KeyboardEvent;
hotkeysEvent: Hotkey;
containsModifier: boolean;
callback: (keyboardEvent: KeyboardEvent, hotkeysEvent: Hotkey) => void;
preventDefault?: boolean;
+ enableOnSettingsPage?: boolean;
}) => {
const currentGlobalHotkeysConfig = store.get(
currentGlobalHotkeysConfigSelector.atom,
);
+ const isEnabledOnSettingsPage =
+ enableOnSettingsPage === true &&
+ store.get(focusStackState.atom).at(-1)?.focusId ===
+ PageFocusId.Settings;
+
if (
containsModifier &&
- !currentGlobalHotkeysConfig.enableGlobalHotkeysWithModifiers
+ !currentGlobalHotkeysConfig.enableGlobalHotkeysWithModifiers &&
+ !isEnabledOnSettingsPage
) {
if (DEBUG_FOCUS_STACK) {
logDebug(
@@ -61,7 +71,8 @@ export const useGlobalHotkeysCallback = (
if (
!containsModifier &&
!currentGlobalHotkeysConfig.enableGlobalHotkeysConflictingWithKeyboard &&
- !isAllowedGlobalEscapeHotkey
+ !isAllowedGlobalEscapeHotkey &&
+ !isEnabledOnSettingsPage
) {
if (DEBUG_FOCUS_STACK) {
logDebug(