The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Restrict AI and Settings access during layout editing (#25760)
Thomas des Francs94bd5864cb08
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useNavigateToAiChatPage.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useNavigateToAiChatPage.test.tsxnew file mode 100644index 00000000000..42ede01a9bb--- /dev/null+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useNavigateToAiChatPage.test.tsx@@ -0,0 +1,149 @@+import { act, renderHook } from '@testing-library/react';+import { Provider as JotaiProvider } from 'jotai';+import { type ReactNode } from 'react';+import { i18n } from '@lingui/core';+import { I18nProvider } from '@lingui/react';++import { useNavigateToAiChatPage } from '@/ai/hooks/useNavigateToAiChatPage';+import { useExpandAskAiSidePanelPage } from '@/side-panel/pages/ask-ai/hooks/useExpandAskAiSidePanelPage';+import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';+import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';++const navigateMock = jest.fn();+const closeSidePanelMenuMock = jest.fn();++jest.mock('react-router-dom', () => ({+ ...jest.requireActual('react-router-dom'),+ useNavigate: () => navigateMock,+}));++jest.mock('@/side-panel/hooks/useSidePanelMenu', () => ({+ useSidePanelMenu: () => ({ closeSidePanelMenu: closeSidePanelMenuMock }),+}));++const Wrapper = ({ children }: { children: ReactNode }) => (+ <I18nProvider i18n={i18n}>+ <JotaiProvider store={jotaiStore}>{children}</JotaiProvider>+ </I18nProvider>+);++describe('useNavigateToAiChatPage', () => {+ beforeEach(() => {+ jest.clearAllMocks();+ jotaiStore.set(isLayoutCustomizationModeEnabledState.atom, false);+ window.history.pushState({}, '', '/objects/people');+ });++ it('blocks an already-open chat from expanding until layout editing ends', () => {+ const { result } = renderHook(() => useExpandAskAiSidePanelPage(), {+ wrapper: Wrapper,+ });+ const expandBeforeEditing = result.current.expand;++ expect(result.current.disabledReason).toBeUndefined();++ act(() => {+ jotaiStore.set(isLayoutCustomizationModeEnabledState.atom, true);+ });++ expect(result.current.disabledReason).toBe(+ 'Finish editing the layout to expand chat',+ );++ act(() => {+ result.current.expand();+ expandBeforeEditing();+ });++ expect(navigateMock).not.toHaveBeenCalled();+ expect(closeSidePanelMenuMock).not.toHaveBeenCalled();++ act(() => {+ jotaiStore.set(isLayoutCustomizationModeEnabledState.atom, false);+ });++ expect(result.current.disabledReason).toBeUndefined();++ act(() => {+ result.current.expand();+ });++ expect(navigateMock).toHaveBeenCalledTimes(1);+ expect(closeSidePanelMenuMock).toHaveBeenCalledTimes(1);+ });++ it('should open a new chat and remember where to collapse back to', () => {+ const { result } = renderHook(() => useNavigateToAiChatPage(), {+ wrapper: Wrapper,+ });++ act(() => {+ result.current.navigateToAiChatPage();+ });++ expect(closeSidePanelMenuMock).toHaveBeenCalled();+ expect(navigateMock).toHaveBeenCalledWith('/chat', {+ state: { returnLocation: '/objects/people' },+ });+ });++ it('should keep the current view and query in the return location', () => {+ window.history.pushState({}, '', '/objects/people?viewId=42');++ const { result } = renderHook(() => useNavigateToAiChatPage(), {+ wrapper: Wrapper,+ });++ act(() => {+ result.current.navigateToAiChatPage();+ });++ expect(navigateMock).toHaveBeenCalledWith('/chat', {+ state: { returnLocation: '/objects/people?viewId=42' },+ });+ });++ it('should open an existing thread', () => {+ const { result } = renderHook(() => useNavigateToAiChatPage(), {+ wrapper: Wrapper,+ });++ act(() => {+ result.current.navigateToAiChatPage({+ threadId: '20202020-0000-4000-8000-000000000001',+ });+ });++ expect(navigateMock).toHaveBeenCalledWith(+ '/chat/20202020-0000-4000-8000-000000000001',+ expect.anything(),+ );+ });++ it('should ignore a draft thread that has no thread id yet', () => {+ const { result } = renderHook(() => useNavigateToAiChatPage(), {+ wrapper: Wrapper,+ });++ act(() => {+ result.current.navigateToAiChatPage({ threadId: 'new-thread-draft' });+ });++ expect(navigateMock).toHaveBeenCalledWith('/chat', expect.anything());+ });++ it('should not navigate while already on the AI chat page', () => {+ window.history.pushState({}, '', '/chat');++ const { result } = renderHook(() => useNavigateToAiChatPage(), {+ wrapper: Wrapper,+ });++ act(() => {+ result.current.navigateToAiChatPage();+ });++ expect(navigateMock).not.toHaveBeenCalled();+ expect(closeSidePanelMenuMock).not.toHaveBeenCalled();+ });+});diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useOpenAiChatPage.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useOpenAiChatPage.test.tsxdeleted file mode 100644index 3a547664ea0..00000000000--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useOpenAiChatPage.test.tsx+++ /dev/null@@ -1,104 +0,0 @@-import { act, renderHook } from '@testing-library/react';-import { Provider as JotaiProvider } from 'jotai';-import { type ReactNode } from 'react';--import { useOpenAiChatPage } from '@/ai/hooks/useOpenAiChatPage';-import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';--const navigateMock = jest.fn();-const closeSidePanelMenuMock = jest.fn();--jest.mock('react-router-dom', () => ({- ...jest.requireActual('react-router-dom'),- useNavigate: () => navigateMock,-}));--jest.mock('@/side-panel/hooks/useSidePanelMenu', () => ({- useSidePanelMenu: () => ({ closeSidePanelMenu: closeSidePanelMenuMock }),-}));--const Wrapper = ({ children }: { children: ReactNode }) => (- <JotaiProvider store={jotaiStore}>{children}</JotaiProvider>-);--describe('useOpenAiChatPage', () => {- beforeEach(() => {- jest.clearAllMocks();- window.history.pushState({}, '', '/objects/people');- });-- it('should open a new chat and remember where to collapse back to', () => {- const { result } = renderHook(() => useOpenAiChatPage(), {- wrapper: Wrapper,- });-- act(() => {- result.current.openAiChatPage();- });-- expect(closeSidePanelMenuMock).toHaveBeenCalled();- expect(navigateMock).toHaveBeenCalledWith('/chat', {- state: { returnLocation: '/objects/people' },- });- });-- it('should keep the current view and query in the return location', () => {- window.history.pushState({}, '', '/objects/people?viewId=42');-- const { result } = renderHook(() => useOpenAiChatPage(), {- wrapper: Wrapper,- });-- act(() => {- result.current.openAiChatPage();- });-- expect(navigateMock).toHaveBeenCalledWith('/chat', {- state: { returnLocation: '/objects/people?viewId=42' },- });- });-- it('should open an existing thread', () => {- const { result } = renderHook(() => useOpenAiChatPage(), {- wrapper: Wrapper,- });-- act(() => {- result.current.openAiChatPage({- threadId: '20202020-0000-4000-8000-000000000001',- });- });-- expect(navigateMock).toHaveBeenCalledWith(- '/chat/20202020-0000-4000-8000-000000000001',- expect.anything(),- );- });-- it('should ignore a draft thread that has no thread id yet', () => {- const { result } = renderHook(() => useOpenAiChatPage(), {- wrapper: Wrapper,- });-- act(() => {- result.current.openAiChatPage({ threadId: 'new-thread-draft' });- });-- expect(navigateMock).toHaveBeenCalledWith('/chat', expect.anything());- });-- it('should not navigate while already on the AI chat page', () => {- window.history.pushState({}, '', '/chat');-- const { result } = renderHook(() => useOpenAiChatPage(), {- wrapper: Wrapper,- });-- act(() => {- result.current.openAiChatPage();- });-- expect(navigateMock).not.toHaveBeenCalled();- expect(closeSidePanelMenuMock).not.toHaveBeenCalled();- });-});diff --git a/packages/twenty-front/src/modules/ai/hooks/useOpenAiChatPage.ts b/packages/twenty-front/src/modules/ai/hooks/useNavigateToAiChatPage.tssimilarity index 72%rename from packages/twenty-front/src/modules/ai/hooks/useOpenAiChatPage.tsrename to packages/twenty-front/src/modules/ai/hooks/useNavigateToAiChatPage.tsindex 124d929b886..c7cbc3f8bee 100644--- a/packages/twenty-front/src/modules/ai/hooks/useOpenAiChatPage.ts+++ b/packages/twenty-front/src/modules/ai/hooks/useNavigateToAiChatPage.ts@@ -1,20 +1,26 @@import { AppPath } from 'twenty-shared/types';import { isDefined, isValidUuid } from 'twenty-shared/utils';+import { useStore } from 'jotai';+import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';import { useNavigateApp } from '~/hooks/useNavigateApp';import { isCurrentPathAiChatPage } from '~/utils/isCurrentPathAiChatPage';-export const useOpenAiChatPage = () => {+export const useNavigateToAiChatPage = () => {+ const store = useStore();const navigate = useNavigateApp();const { closeSidePanelMenu } = useSidePanelMenu();- const openAiChatPage = ({+ const navigateToAiChatPage = ({threadId,}: {threadId?: string | null;} = {}) => {- if (isCurrentPathAiChatPage()) {+ if (+ store.get(isLayoutCustomizationModeEnabledState.atom) ||+ isCurrentPathAiChatPage()+ ) {return;}@@ -38,5 +44,5 @@ export const useOpenAiChatPage = () => {);};- return { openAiChatPage };+ return { navigateToAiChatPage };};diff --git a/packages/twenty-front/src/modules/ai/hooks/useSwitchToNewAiChat.ts b/packages/twenty-front/src/modules/ai/hooks/useSwitchToNewAiChat.tsindex 7649d709a8a..11a099b58b5 100644--- a/packages/twenty-front/src/modules/ai/hooks/useSwitchToNewAiChat.ts+++ b/packages/twenty-front/src/modules/ai/hooks/useSwitchToNewAiChat.ts@@ -1,6 +1,6 @@import { useStore } from 'jotai';-import { useOpenAiChatPage } from '@/ai/hooks/useOpenAiChatPage';+import { useNavigateToAiChatPage } from '@/ai/hooks/useNavigateToAiChatPage';import { useSelectAiChatThread } from '@/ai/hooks/useSelectAiChatThread';import { AGENT_CHAT_NEW_THREAD_DRAFT_KEY } from '@/ai/states/agentChatDraftsByThreadIdState';import { shouldFocusChatEditorState } from '@/ai/states/shouldFocusChatEditorState';@@ -22,7 +22,7 @@ export const useSwitchToNewAiChat = ({const { selectAiChatThread } = useSelectAiChatThread();const store = useStore();const { openAskAiPage } = useOpenAskAiPageInSidePanel();- const { openAiChatPage } = useOpenAiChatPage();+ const { navigateToAiChatPage } = useNavigateToAiChatPage();const switchToNewChat = () => {setThreadIdCreatedFromDraft(null);@@ -30,7 +30,7 @@ export const useSwitchToNewAiChat = ({selectAiChatThread(AGENT_CHAT_NEW_THREAD_DRAFT_KEY);if (shouldOpenInFullPage) {- openAiChatPage();+ navigateToAiChatPage();} else {openAskAiPage();}diff --git a/packages/twenty-front/src/modules/app/effect-components/GotoHotkeysEffectsProvider.tsx b/packages/twenty-front/src/modules/app/effect-components/GotoHotkeysEffectsProvider.tsxindex 3e4b68c1d15..ce100117ed8 100644--- a/packages/twenty-front/src/modules/app/effect-components/GotoHotkeysEffectsProvider.tsx+++ b/packages/twenty-front/src/modules/app/effect-components/GotoHotkeysEffectsProvider.tsx@@ -1,4 +1,6 @@import { GoToHotkeyItemEffect } from '@/app/effect-components/GoToHotkeyItemEffect';+import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';import { navigationDrawerExpandedMemorizedState } from '@/ui/navigation/states/navigationDrawerExpandedMemorizedState';@@ -13,9 +15,13 @@ export const GotoHotkeysEffectsProvider = () => {useFilteredObjectMetadataItems();const store = useStore();+ const isLayoutCustomizationModeEnabled = useAtomStateValue(+ isLayoutCustomizationModeEnabledState,+ );useGoToHotkeys({key: 's',+ isEnabled: !isLayoutCustomizationModeEnabled,location: getSettingsPath(SettingsPath.ProfilePage),preNavigateFunction: useCallback(() => {store.set(isNavigationDrawerExpandedState.atom, true);diff --git a/packages/twenty-front/src/modules/command-menu-item/components/StandalonePageCommandMenu.tsx b/packages/twenty-front/src/modules/command-menu-item/components/StandalonePageCommandMenu.tsxindex 8bbd4794d89..5dc5639f628 100644--- a/packages/twenty-front/src/modules/command-menu-item/components/StandalonePageCommandMenu.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/components/StandalonePageCommandMenu.tsx@@ -11,6 +11,7 @@ import { doesCommandMenuItemMatchObjectMetadataId } from '@/command-menu-item/utimport { doesCommandMenuItemMatchPageLayoutId } from '@/command-menu-item/utils/doesCommandMenuItemMatchPageLayoutId';import { resolveCommandMenuItemPinning } from '@/command-menu-item/utils/resolveCommandMenuItemPinning';import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';+import { useIsLayoutCustomizationAllowedOnCurrentPage } from '@/layout-customization/hooks/useIsLayoutCustomizationAllowedOnCurrentPage';import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';import { currentPageLayoutIdState } from '@/page-layout/states/currentPageLayoutIdState';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';@@ -21,10 +22,15 @@ import {type CommandMenuContextApi,} from 'twenty-shared/types';import { evaluateConditionalAvailabilityExpression } from 'twenty-shared/utils';-import { CommandMenuItemAvailabilityType } from '~/generated-metadata/graphql';+import {+ CommandMenuItemAvailabilityType,+ EngineComponentKey,+} from '~/generated-metadata/graphql';export const StandalonePageCommandMenu = () => {const store = useStore();+ const isLayoutCustomizationAllowedOnCurrentPage =+ useIsLayoutCustomizationAllowedOnCurrentPage();const commandMenuItems = useAtomStateValue(commandMenuItemsSelector);const currentWorkspace = useAtomStateValue(currentWorkspaceState);const currentUserWorkspace = useAtomStateValue(currentUserWorkspaceState);@@ -104,6 +110,12 @@ export const StandalonePageCommandMenu = () => {const filteredCommandMenuItems = useMemo(() => {return commandMenuItems+ .filter(+ (item) =>+ item.engineComponentKey !==+ EngineComponentKey.EDIT_RECORD_PAGE_LAYOUT ||+ isLayoutCustomizationAllowedOnCurrentPage,+ ).filter(doesCommandMenuItemMatchObjectMetadataId(undefined)).filter((item) =>@@ -123,7 +135,12 @@ export const StandalonePageCommandMenu = () => {.sort((firstItem, secondItem) => firstItem.position - secondItem.position,);- }, [commandMenuItems, commandMenuContextApi, currentPageLayoutId]);+ }, [+ commandMenuItems,+ commandMenuContextApi,+ currentPageLayoutId,+ isLayoutCustomizationAllowedOnCurrentPage,+ ]);return (<CommandMenuContext.Providerdiff --git a/packages/twenty-front/src/modules/command-menu-item/contexts/CommandMenuContextProviderContent.tsx b/packages/twenty-front/src/modules/command-menu-item/contexts/CommandMenuContextProviderContent.tsxindex a6523af3088..17880212136 100644--- a/packages/twenty-front/src/modules/command-menu-item/contexts/CommandMenuContextProviderContent.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/contexts/CommandMenuContextProviderContent.tsx@@ -9,6 +9,7 @@ import { doesCommandMenuItemMatchPageLayoutId } from '@/command-menu-item/utils/import { resolveCommandMenuItemPinning } from '@/command-menu-item/utils/resolveCommandMenuItemPinning';import { doesCommandMenuItemMatchPageType } from '@/command-menu-item/utils/doesCommandMenuItemMatchPageType';import { doesCommandMenuItemMatchSelectionState } from '@/command-menu-item/utils/doesCommandMenuItemMatchSelectionState';+import { useIsLayoutCustomizationAllowedOnCurrentPage } from '@/layout-customization/hooks/useIsLayoutCustomizationAllowedOnCurrentPage';import {currentPageLayoutIdState,PageLayoutIdContext,@@ -17,6 +18,7 @@ import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateimport { useContext, useMemo } from 'react';import { type CommandMenuContextApi } from 'twenty-shared/types';import { evaluateConditionalAvailabilityExpression } from 'twenty-shared/utils';+import { EngineComponentKey } from '~/generated-metadata/graphql';type CommandMenuContextProviderContentProps = {displayType: CommandMenuContextType['displayType'];@@ -34,6 +36,8 @@ export const CommandMenuContextProviderContent = ({isInPreviewMode,}: CommandMenuContextProviderContentProps) => {const commandMenuItems = useAtomStateValue(commandMenuItemsSelector);+ const isLayoutCustomizationAllowedOnCurrentPage =+ useIsLayoutCustomizationAllowedOnCurrentPage();const commandMenuItemsDraft = useAtomStateValue(commandMenuItemsDraftState);const currentPageLayoutId = useAtomStateValue(currentPageLayoutIdState);const pageLayoutIdFromContext = useContext(PageLayoutIdContext);@@ -52,6 +56,12 @@ export const CommandMenuContextProviderContent = ({: commandMenuItems;return commandMenuItemsToDisplay+ .filter(+ (item) =>+ item.engineComponentKey !==+ EngineComponentKey.EDIT_RECORD_PAGE_LAYOUT ||+ isLayoutCustomizationAllowedOnCurrentPage,+ ).filter(doesCommandMenuItemMatchObjectMetadataId(currentObjectMetadataItemId),)@@ -74,6 +84,7 @@ export const CommandMenuContextProviderContent = ({commandMenuItemsDraft,effectivePageLayoutId,isInPreviewMode,+ isLayoutCustomizationAllowedOnCurrentPage,]);return (diff --git a/packages/twenty-front/src/modules/command-menu-item/engine-command/global/components/EditLayoutCommand.tsx b/packages/twenty-front/src/modules/command-menu-item/engine-command/global/components/EditLayoutCommand.tsxindex e9c896e042c..07bb926b89d 100644--- a/packages/twenty-front/src/modules/command-menu-item/engine-command/global/components/EditLayoutCommand.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/engine-command/global/components/EditLayoutCommand.tsx@@ -2,14 +2,21 @@ import { useResetLocationHash } from 'twenty-ui/utilities';import { HeadlessEngineCommandWrapperEffect } from '@/command-menu-item/engine-command/components/HeadlessEngineCommandWrapperEffect';import { useEnterLayoutCustomizationMode } from '@/layout-customization/hooks/useEnterLayoutCustomizationMode';+import { useIsLayoutCustomizationAllowedOnCurrentPage } from '@/layout-customization/hooks/useIsLayoutCustomizationAllowedOnCurrentPage';import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';export const EditLayoutCommand = () => {+ const isLayoutCustomizationAllowedOnCurrentPage =+ useIsLayoutCustomizationAllowedOnCurrentPage();const { enterLayoutCustomizationMode } = useEnterLayoutCustomizationMode();const { closeSidePanelMenu } = useSidePanelMenu();const { resetLocationHash } = useResetLocationHash();const handleExecute = async () => {+ if (!isLayoutCustomizationAllowedOnCurrentPage) {+ return;+ }+await closeSidePanelMenu();enterLayoutCustomizationMode();diff --git a/packages/twenty-front/src/modules/layout-customization/hooks/__tests__/useIsLayoutCustomizationAllowedOnCurrentPage.test.tsx b/packages/twenty-front/src/modules/layout-customization/hooks/__tests__/useIsLayoutCustomizationAllowedOnCurrentPage.test.tsxnew file mode 100644index 00000000000..da56191b375--- /dev/null+++ b/packages/twenty-front/src/modules/layout-customization/hooks/__tests__/useIsLayoutCustomizationAllowedOnCurrentPage.test.tsx@@ -0,0 +1,27 @@+import { renderHook } from '@testing-library/react';+import { type ReactNode } from 'react';+import { MemoryRouter } from 'react-router-dom';++import { useIsLayoutCustomizationAllowedOnCurrentPage } from '@/layout-customization/hooks/useIsLayoutCustomizationAllowedOnCurrentPage';++describe('useIsLayoutCustomizationAllowedOnCurrentPage', () => {+ it.each([+ ['/chat', false],+ ['/chat/20202020-0000-4000-8000-000000000014', false],+ ['/settings/profile', false],+ ['/settings/objects/companies', false],+ ['/object/companies', true],+ ['/object/company/20202020-0000-4000-8000-000000000014', true],+ ])('allows layout customization on %s: %s', (pathname, expected) => {+ const { result } = renderHook(+ () => useIsLayoutCustomizationAllowedOnCurrentPage(),+ {+ wrapper: ({ children }: { children: ReactNode }) => (+ <MemoryRouter initialEntries={[pathname]}>{children}</MemoryRouter>+ ),+ },+ );++ expect(result.current).toBe(expected);+ });+});diff --git a/packages/twenty-front/src/modules/layout-customization/hooks/useIsLayoutCustomizationAllowedOnCurrentPage.ts b/packages/twenty-front/src/modules/layout-customization/hooks/useIsLayoutCustomizationAllowedOnCurrentPage.tsnew file mode 100644index 00000000000..bb0af0c67af--- /dev/null+++ b/packages/twenty-front/src/modules/layout-customization/hooks/useIsLayoutCustomizationAllowedOnCurrentPage.ts@@ -0,0 +1,10 @@+import { useLocation } from 'react-router-dom';++import { isAiChatPath } from '~/utils/isAiChatPath';+import { isSettingsPath } from '~/utils/isSettingsPath';++export const useIsLayoutCustomizationAllowedOnCurrentPage = () => {+ const { pathname } = useLocation();++ return !isAiChatPath(pathname) && !isSettingsPath(pathname);+};diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsxindex 92aaea93354..6317fcb966e 100644--- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx+++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx@@ -5,10 +5,13 @@ import { useContext, useId } from 'react';import { AppTooltip, TooltipDelay, TooltipPosition } from 'twenty-ui/surfaces';import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';+import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';import { useActiveNavigationDrawerMode } from '@/navigation/hooks/useActiveNavigationDrawerMode';import { useIsNavigationDrawerContentExpanded } from '@/navigation/hooks/useIsNavigationDrawerContentExpanded';import { useNavigationDrawerModes } from '@/navigation/hooks/useNavigationDrawerModes';import { useSwitchNavigationDrawerMode } from '@/navigation/hooks/useSwitchNavigationDrawerMode';+import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';// Expanded, the row is sized off the page card header beside it so the rules@@ -65,7 +68,12 @@ const StyledMode = styled.button<{ isActive: boolean; isExpanded: boolean }>`width: ${({ isExpanded }) =>isExpanded ? 'auto' : themeCssVariables.spacing[6]};- &:hover {+ &[aria-disabled='true'] {+ color: ${themeCssVariables.font.color.light};+ cursor: not-allowed;+ }++ &:hover:not([aria-disabled='true']) {background: ${({ isActive }) =>isActive? themeCssVariables.background.transparent.light@@ -96,6 +104,9 @@ export const MainNavigationDrawerModeSwitcher = () => {const { theme } = useContext(ThemeContext);const tooltipId = useId();+ const isLayoutCustomizationModeEnabled = useAtomStateValue(+ isLayoutCustomizationModeEnabledState,+ );const isMobile = useIsMobile();const isExpanded = useIsNavigationDrawerContentExpanded();const modes = useNavigationDrawerModes();@@ -118,6 +129,9 @@ export const MainNavigationDrawerModeSwitcher = () => {>{modes.map(({ Icon, label, mode }) => {const isActive = mode === activeNavigationDrawerMode;+ const isDisabled =+ mode !== NAVIGATION_DRAWER_TABS.NAVIGATION_MENU &&+ isLayoutCustomizationModeEnabled;return (<StyledMode@@ -128,7 +142,14 @@ export const MainNavigationDrawerModeSwitcher = () => {isExpanded={isExpanded}aria-label={label}aria-current={isActive}- onClick={() => switchNavigationDrawerMode(mode)}+ aria-disabled={isDisabled}+ onClick={() => {+ if (isDisabled) {+ return;+ }++ switchNavigationDrawerMode(mode);+ }}><StyledModeIcon><Icon size={theme.icon.size.md} />@@ -149,18 +170,33 @@ export const MainNavigationDrawerModeSwitcher = () => {);})}</StyledSwitcher>- {shouldShowTooltips &&- modes.map(({ label, mode }) => (+ {modes.map(({ label, mode }) => {+ const isDisabled =+ mode !== NAVIGATION_DRAWER_TABS.NAVIGATION_MENU &&+ isLayoutCustomizationModeEnabled;++ if (!shouldShowTooltips && !isDisabled) {+ return null;+ }++ return (<AppTooltipkey={mode}anchorSelect={`[data-tooltip-id='${tooltipId}-${mode}']`}- title={label}+ title={+ isDisabled+ ? mode === NAVIGATION_DRAWER_TABS.SETTINGS+ ? t`Finish editing the layout to open Settings`+ : t`Finish editing the layout to open AI`+ : label+ }delay={TooltipDelay.noDelay}- place={TooltipPosition.Right}+ place={isExpanded ? TooltipPosition.Bottom : TooltipPosition.Right}positionStrategy="fixed"noArrow/>- ))}+ );+ })}</>);};diff --git a/packages/twenty-front/src/modules/navigation/components/__tests__/MainNavigationDrawerModeSwitcher.test.tsx b/packages/twenty-front/src/modules/navigation/components/__tests__/MainNavigationDrawerModeSwitcher.test.tsxindex 0b3c9b050ca..ed30400738c 100644--- a/packages/twenty-front/src/modules/navigation/components/__tests__/MainNavigationDrawerModeSwitcher.test.tsx+++ b/packages/twenty-front/src/modules/navigation/components/__tests__/MainNavigationDrawerModeSwitcher.test.tsx@@ -1,14 +1,17 @@+import { createStore, Provider as JotaiProvider } from 'jotai';+import { i18n } from '@lingui/core';+import { I18nProvider } from '@lingui/react';+import { act, render, screen } from '@testing-library/react';+import userEvent from '@testing-library/user-event';+import { IconComment, IconHome, IconSettings } from 'twenty-ui/icon';++import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';import { MainNavigationDrawerModeSwitcher } from '@/navigation/components/MainNavigationDrawerModeSwitcher';import { useActiveNavigationDrawerMode } from '@/navigation/hooks/useActiveNavigationDrawerMode';import { useIsNavigationDrawerContentExpanded } from '@/navigation/hooks/useIsNavigationDrawerContentExpanded';import { useNavigationDrawerModes } from '@/navigation/hooks/useNavigationDrawerModes';import { useSwitchNavigationDrawerMode } from '@/navigation/hooks/useSwitchNavigationDrawerMode';import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';-import { i18n } from '@lingui/core';-import { I18nProvider } from '@lingui/react';-import { render, screen } from '@testing-library/react';-import userEvent from '@testing-library/user-event';-import { IconComment, IconHome, IconSettings } from 'twenty-ui/icon';jest.mock('@/navigation/hooks/useActiveNavigationDrawerMode');jest.mock('@/navigation/hooks/useIsNavigationDrawerContentExpanded');@@ -26,13 +29,25 @@ jest.mock('twenty-ui/surfaces', () => ({const mockSwitchNavigationDrawerMode = jest.fn();-const renderModeSwitcher = () =>+const renderModeSwitcher = (isLayoutCustomizationModeEnabled = false) => {+ const store = createStore();++ store.set(+ isLayoutCustomizationModeEnabledState.atom,+ isLayoutCustomizationModeEnabled,+ );+render(<I18nProvider i18n={i18n}>- <MainNavigationDrawerModeSwitcher />+ <JotaiProvider store={store}>+ <MainNavigationDrawerModeSwitcher />+ </JotaiProvider></I18nProvider>,);+ return { store };+};+describe('MainNavigationDrawerModeSwitcher', () => {beforeEach(() => {jest.clearAllMocks();@@ -87,6 +102,45 @@ describe('MainNavigationDrawerModeSwitcher', () => {);});+ it.each([+ [true, 'Settings', NAVIGATION_DRAWER_TABS.SETTINGS],+ [false, 'Settings', NAVIGATION_DRAWER_TABS.SETTINGS],+ [true, 'AI', NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY],+ [false, 'AI', NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY],+ ] as const)(+ 'disables navigation while editing layout with expanded=%s and mode=%s and restores it afterward',+ async (isExpanded, label, mode) => {+ jest+ .mocked(useIsNavigationDrawerContentExpanded)+ .mockReturnValue(isExpanded);+ const { store } = renderModeSwitcher(true);+ const settingsButton = screen.getByRole('button', { name: label });++ expect(settingsButton).toHaveAttribute('aria-disabled', 'true');+ expect(screen.getByRole('button', { name: 'Home' })).toBeEnabled();+ expect(screen.getByRole('button', { name: 'Home' })).toHaveAttribute(+ 'aria-disabled',+ 'false',+ );++ await userEvent.click(settingsButton);+ expect(settingsButton).toHaveFocus();+ await userEvent.keyboard('{Enter} ');++ expect(mockSwitchNavigationDrawerMode).not.toHaveBeenCalled();++ act(() => {+ store.set(isLayoutCustomizationModeEnabledState.atom, false);+ });++ expect(settingsButton).toHaveAttribute('aria-disabled', 'false');+ await userEvent.click(settingsButton);++ expect(mockSwitchNavigationDrawerMode).toHaveBeenCalledTimes(1);+ expect(mockSwitchNavigationDrawerMode).toHaveBeenCalledWith(mode);+ },+ );+it('renders nothing when no mode is available', () => {jest.mocked(useNavigationDrawerModes).mockReturnValue([]);diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelExpandButton.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelExpandButton.tsxindex 4ca63432b06..1f571967fd9 100644--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelExpandButton.tsx+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelExpandButton.tsx@@ -33,19 +33,23 @@ const SidePanelExpandButtonContent = () => {return null;}- const tooltipContent = expandTarget.hasExpandShortcut- ? `${expandTarget.label} | ${[getOsControlSymbol(), '⏎'].join(- getOsShortcutSeparator(),- )}`- : expandTarget.label;+ const isDisabled = isDefined(expandTarget.disabledReason);+ const tooltipContent =+ expandTarget.disabledReason ??+ (expandTarget.hasExpandShortcut+ ? `${expandTarget.label} | ${[getOsControlSymbol(), '⏎'].join(+ getOsShortcutSeparator(),+ )}`+ : expandTarget.label);return (<>- {expandTarget.hasExpandShortcut && (+ {expandTarget.hasExpandShortcut && !isDisabled && (<SidePanelExpandShortcutEffect expand={expandTarget.expand} />)}<IconButtonWithTooltiptooltipContent={tooltipContent}+ disabled={isDisabled}Icon={IconMaximize}size="small"variant="tertiary"diff --git a/packages/twenty-front/src/modules/side-panel/pages/ask-ai/hooks/useExpandAskAiSidePanelPage.ts b/packages/twenty-front/src/modules/side-panel/pages/ask-ai/hooks/useExpandAskAiSidePanelPage.tsindex 8c6e0a7e995..45a8e6e3aa6 100644--- a/packages/twenty-front/src/modules/side-panel/pages/ask-ai/hooks/useExpandAskAiSidePanelPage.ts+++ b/packages/twenty-front/src/modules/side-panel/pages/ask-ai/hooks/useExpandAskAiSidePanelPage.ts@@ -1,20 +1,27 @@import { useLingui } from '@lingui/react/macro';-import { useOpenAiChatPage } from '@/ai/hooks/useOpenAiChatPage';+import { useNavigateToAiChatPage } from '@/ai/hooks/useNavigateToAiChatPage';import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';+import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';import { type SidePanelExpandTarget } from '@/side-panel/types/SidePanelExpandTarget';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';export const useExpandAskAiSidePanelPage = (): SidePanelExpandTarget => {const { t } = useLingui();+ const isLayoutCustomizationModeEnabled = useAtomStateValue(+ isLayoutCustomizationModeEnabledState,+ );const currentAiChatThread = useAtomStateValue(currentAiChatThreadState);- const { openAiChatPage } = useOpenAiChatPage();+ const { navigateToAiChatPage } = useNavigateToAiChatPage();return {label: t`Expand chat`,+ disabledReason: isLayoutCustomizationModeEnabled+ ? t`Finish editing the layout to expand chat`+ : undefined,hasExpandShortcut: false,expand: () => {- openAiChatPage({ threadId: currentAiChatThread });+ navigateToAiChatPage({ threadId: currentAiChatThread });},};};diff --git a/packages/twenty-front/src/modules/side-panel/types/SidePanelExpandTarget.ts b/packages/twenty-front/src/modules/side-panel/types/SidePanelExpandTarget.tsindex 45fed7a724d..b6f04157597 100644--- a/packages/twenty-front/src/modules/side-panel/types/SidePanelExpandTarget.ts+++ b/packages/twenty-front/src/modules/side-panel/types/SidePanelExpandTarget.ts@@ -3,6 +3,7 @@// full screen overlay, or anything else, without the top bar knowing.export type SidePanelExpandTarget = {label: string;+ disabledReason?: string;expand: () => void;// Pages whose content owns cmd+enter, such as a composer, decline it.hasExpandShortcut: boolean;diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/MultiWorkspaceDropdownButton.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/MultiWorkspaceDropdownButton.tsxindex 04a6d6674af..df06dae3ef4 100644--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/MultiWorkspaceDropdownButton.tsx+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/MultiWorkspaceDropdownButton.tsx@@ -1,4 +1,3 @@-import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';import { MultiWorkspaceDropdownClickableComponent } from '@/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownClickableComponent';import { MultiWorkspaceDropdownDefaultComponents } from '@/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/internal/MultiWorkspaceDropdownDefaultComponents';@@ -10,7 +9,6 @@ import { MULTI_WORKSPACE_DROPDOWN_MOBILE_BOUNDARY_PADDING } from '@/ui/navigatioimport { multiWorkspaceDropdownState } from '@/ui/navigation/navigation-drawer/states/multiWorkspaceDropdownState';import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useMemo } from 'react';type MultiWorkspaceDropdownButtonProps = {@@ -23,9 +21,6 @@ export const MultiWorkspaceDropdownButton = ({const [multiWorkspaceDropdown, setMultiWorkspaceDropdown] = useAtomState(multiWorkspaceDropdownState,);- const isLayoutCustomizationModeEnabled = useAtomStateValue(- isLayoutCustomizationModeEnabledState,- );const isMobile = useIsMobile();const DropdownComponents = useMemo(() => {@@ -64,12 +59,10 @@ export const MultiWorkspaceDropdownButton = ({}clickableComponent={<MultiWorkspaceDropdownClickableComponent- disabled={isLayoutCustomizationModeEnabled}shouldHideLabel={shouldHideLabel}/>}clickableComponentWidth={shouldHideLabel ? 'auto' : '100%'}- disableClickForClickableComponent={isLayoutCustomizationModeEnabled}dropdownComponents={<DropdownComponents />}onClose={() => {setMultiWorkspaceDropdown('default');diff --git a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/__tests__/useGoToHotkeys.test.tsx b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/__tests__/useGoToHotkeys.test.tsxindex 6ca01186567..0bbfcaf8b08 100644--- a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/__tests__/useGoToHotkeys.test.tsx+++ b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/__tests__/useGoToHotkeys.test.tsx@@ -1,4 +1,5 @@import { act, fireEvent, renderHook } from '@testing-library/react';+import userEvent from '@testing-library/user-event';import { MemoryRouter, useLocation } from 'react-router-dom';import { useGoToHotkeys } from '@/ui/utilities/hotkey/hooks/useGoToHotkeys';@@ -39,4 +40,33 @@ describe('useGoToHotkeys', () => {expect(result.current.pathname).toBe('/three');});+ it('blocks navigation and side effects while disabled and restores them when enabled', async () => {+ const preNavigateFunction = jest.fn();+ const user = userEvent.setup();+ const { result, rerender } = renderHook(+ ({ isEnabled }) => {+ useGoToHotkeys({+ key: 's',+ location: '/three',+ isEnabled,+ preNavigateFunction,+ });++ return useLocation();+ },+ { ...renderHookConfig, initialProps: { isEnabled: false } },+ );++ await user.keyboard('gs');++ expect(result.current.pathname).toBe('/two');+ expect(preNavigateFunction).not.toHaveBeenCalled();++ rerender({ isEnabled: true });+ await user.keyboard('gs');++ expect(result.current.pathname).toBe('/three');+ expect(preNavigateFunction).toHaveBeenCalledTimes(1);+ expect(preNavigateFunction).toHaveBeenCalledWith();+ });});diff --git a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGoToHotkeys.ts b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGoToHotkeys.tsindex 2e50f6074c9..717612f1b89 100644--- a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGoToHotkeys.ts+++ b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/useGoToHotkeys.ts@@ -6,6 +6,7 @@ import { useGlobalHotkeysSequence } from '@/ui/utilities/hotkey/hooks/useGlobalHtype GoToHotkeysProps = {key: Keys;location: string;+ isEnabled?: boolean;preNavigateFunction?: () => void;};@@ -13,6 +14,7 @@ export const useGoToHotkeys = ({key,location,preNavigateFunction,+ isEnabled = true,}: GoToHotkeysProps) => {const navigate = useNavigate();@@ -20,6 +22,10 @@ export const useGoToHotkeys = ({'g',key,() => {+ if (!isEnabled) {+ return;+ }+preNavigateFunction?.();navigate(location);},@@ -28,6 +34,6 @@ export const useGoToHotkeys = ({enableOnFormTags: true,preventDefault: true,},- [navigate],+ [navigate, location, preNavigateFunction, isEnabled],);};diff --git a/packages/twenty-ui/src/input/IconButtonWithTooltip/IconButtonWithTooltip.tsx b/packages/twenty-ui/src/input/IconButtonWithTooltip/IconButtonWithTooltip.tsxindex 55291601a0b..e98711fe6c3 100644--- a/packages/twenty-ui/src/input/IconButtonWithTooltip/IconButtonWithTooltip.tsx+++ b/packages/twenty-ui/src/input/IconButtonWithTooltip/IconButtonWithTooltip.tsx@@ -7,7 +7,7 @@ import { useId } from 'react';export type IconButtonWithTooltipProps = Pick<IconButtonProps,- 'Icon' | 'ariaLabel' | 'onClick' | 'size' | 'variant'+ 'Icon' | 'ariaLabel' | 'onClick' | 'size' | 'variant' | 'disabled'> & {tooltipContent: string;tooltipPlace?: TooltipPosition;@@ -25,6 +25,7 @@ export const IconButtonWithTooltip = ({onClick,size,variant,+ disabled,}: IconButtonWithTooltipProps) => {const tooltipId = useId();@@ -37,10 +38,15 @@ export const IconButtonWithTooltip = ({onClick={onClick}size={size}variant={variant}+ disabled={disabled}/></div><AppTooltip- anchorSelect={`[data-tooltip-id='${tooltipId}'] > button`}+ anchorSelect={+ disabled+ ? `[data-tooltip-id='${tooltipId}']`+ : `[data-tooltip-id='${tooltipId}'] > button`+ }title={tooltipContent}delay={tooltipDelay}place={tooltipPlace}