Skip to content

The open alternative to Salesforce, designed for AI.

Close the inbox conversation pane (#28716)

Raphaël Bosieaead64e2fd1
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxConversationCloseEffect.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxConversationCloseEffect.tsx
new file mode 100644
index 00000000000..a0596fc0a57
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxConversationCloseEffect.tsx
@@ -0,0 +1,29 @@
+import { useStore } from 'jotai';
+import { useLayoutEffect } from 'react';
+
+import { closingAiChatInboxThreadIdState } from '@/ai/states/closingAiChatInboxThreadIdState';
+import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
+import { resetClosingAiChatInboxThread } from '@/ai/utils/resetClosingAiChatInboxThread';
+
+type AiChatInboxConversationCloseEffectProps = {
+ isPresent: boolean;
+};
+
+export const AiChatInboxConversationCloseEffect = ({
+ isPresent,
+}: AiChatInboxConversationCloseEffectProps) => {
+ const store = useStore();
+
+ useLayoutEffect(() => {
+ store.set(
+ closingAiChatInboxThreadIdState.atom,
+ isPresent ? null : store.get(currentAiChatThreadState.atom),
+ );
+ }, [isPresent, store]);
+
+ useLayoutEffect(() => {
+ return () => resetClosingAiChatInboxThread(store);
+ }, [store]);
+
+ return null;
+};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxConversationPane.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxConversationPane.tsx
new file mode 100644
index 00000000000..33958cb14c1
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxConversationPane.tsx
@@ -0,0 +1,59 @@
+import { useLingui } from '@lingui/react/macro';
+import { styled } from '@linaria/react';
+import { motion, useIsPresent, useReducedMotion } from 'framer-motion';
+import { type ReactNode } from 'react';
+import { ANIMATION } from 'twenty-ui/theme';
+
+import { AiChatInboxConversationCloseEffect } from '@/ai/components/AiChatInboxConversationCloseEffect';
+
+const StyledPane = styled(motion.div)`
+ bottom: 0;
+ display: flex;
+ flex: 1;
+ min-height: 0;
+ min-width: 0;
+ position: relative;
+ right: 0;
+ top: 0;
+ width: 100%;
+
+ &[data-split-view='true'] {
+ position: absolute;
+ width: calc(100% - var(--inbox-list-pane-width));
+ }
+`;
+
+type AiChatInboxConversationPaneProps = {
+ children: ReactNode;
+ isSplitView: boolean;
+};
+
+export const AiChatInboxConversationPane = ({
+ children,
+ isSplitView,
+}: AiChatInboxConversationPaneProps) => {
+ const { t } = useLingui();
+ const isPresent = useIsPresent();
+ const shouldReduceMotion = useReducedMotion();
+ const shouldAnimate = isSplitView && !shouldReduceMotion;
+
+ return (
+ <StyledPane
+ data-split-view={isSplitView}
+ role="region"
+ aria-label={t`Conversation`}
+ aria-hidden={!isPresent}
+ inert={!isPresent || undefined}
+ initial={{ x: shouldAnimate ? '100%' : 0 }}
+ animate={{ x: 0 }}
+ exit={{ x: shouldAnimate ? '100%' : 0 }}
+ transition={{
+ duration: shouldAnimate ? ANIMATION.duration.normal : 0,
+ ease: 'easeInOut',
+ }}
+ >
+ <AiChatInboxConversationCloseEffect isPresent={isPresent} />
+ {children}
+ </StyledPane>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxListHeader.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxListHeader.tsx
index 294cb7e8068..ea839fbaa1b 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatInboxListHeader.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxListHeader.tsx
@@ -7,7 +7,6 @@ import { useIsMobile } from 'twenty-ui/utilities';
import { AiChatInboxLayoutDropdown } from '@/ai/components/AiChatInboxLayoutDropdown';
import { AiChatInboxTriageCommandMenuItems } from '@/ai/components/AiChatInboxTriageCommandMenuItems';
import { useAgentChatInboxViewHeading } from '@/ai/hooks/useAgentChatInboxViewHeading';
-import { useIsAiChatInboxSplitView } from '@/ai/hooks/useIsAiChatInboxSplitView';
import { useSwitchToNewAiChat } from '@/ai/hooks/useSwitchToNewAiChat';
import { CommandMenuContextProvider } from '@/command-menu-item/contexts/CommandMenuContextProvider';
import { PinnedCommandMenuItemButtons } from '@/command-menu-item/display/components/PinnedCommandMenuItemButtons';
@@ -19,16 +18,17 @@ import { PageCardHeader } from '@/ui/layout/page/components/PageCardHeader';
type AiChatInboxListHeaderProps = {
selectedThreadCount: number;
+ isSecondaryPaneShown: boolean;
};
export const AiChatInboxListHeader = ({
selectedThreadCount,
+ isSecondaryPaneShown,
}: AiChatInboxListHeaderProps) => {
const { t } = useLingui();
const theme = useTheme();
const { HeadingIcon, headingLabel } = useAgentChatInboxViewHeading();
const isMobile = useIsMobile();
- const isSplitView = useIsAiChatInboxSplitView();
const { switchToNewChat } = useSwitchToNewAiChat({
shouldOpenInFullPage: true,
});
@@ -73,8 +73,7 @@ export const AiChatInboxListHeader = ({
>
{t`New chat`}
</Button>
- {/* In split view the chat beside the list has the command menu */}
- {!isSplitView && <SidePanelToggleButton />}
+ {!isSecondaryPaneShown && <SidePanelToggleButton />}
</>
)
}
diff --git a/packages/twenty-front/src/modules/ai/constants/AiChatInboxListPaneWidth.ts b/packages/twenty-front/src/modules/ai/constants/AiChatInboxListPaneWidth.ts
new file mode 100644
index 00000000000..e84e4acfb0e
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/constants/AiChatInboxListPaneWidth.ts
@@ -0,0 +1 @@
+export const AI_CHAT_INBOX_LIST_PANE_WIDTH = 400;
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useProjectAiChatThreadToUrl.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useProjectAiChatThreadToUrl.test.tsx
index 51530e3e2a2..c02f5b2519f 100644
--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useProjectAiChatThreadToUrl.test.tsx
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useProjectAiChatThreadToUrl.test.tsx
@@ -82,7 +82,9 @@ describe('useProjectAiChatThreadToUrl', () => {
`/inbox/${AI_CHAT_NEW_THREAD_PATH_SEGMENT}`,
);
- const { result } = renderHook(() => useProjectAiChatThreadToUrl());
+ const { result } = renderHook(() =>
+ useProjectAiChatThreadToUrl({ shouldPreserveClosedInbox: true }),
+ );
act(() => {
result.current.projectAiChatThreadToUrl(THREAD_A);
@@ -151,4 +153,56 @@ describe('useProjectAiChatThreadToUrl', () => {
expect(navigateAppMock).not.toHaveBeenCalled();
});
+
+ it('preserves the closed inbox when an automatic projection finishes after closing', () => {
+ window.history.pushState(null, '', `/inbox/${THREAD_A}`);
+
+ const { result } = renderHook(() =>
+ useProjectAiChatThreadToUrl({ shouldPreserveClosedInbox: true }),
+ );
+
+ window.history.pushState(null, '', '/inbox');
+
+ act(() => {
+ result.current.projectAiChatThreadToUrl(THREAD_A);
+ });
+
+ expect(navigateAppMock).not.toHaveBeenCalled();
+ });
+
+ it('opens an explicitly selected chat from the closed inbox in a new history entry', () => {
+ window.history.pushState(null, '', '/inbox');
+
+ const { result } = renderHook(() => useProjectAiChatThreadToUrl());
+
+ act(() => {
+ result.current.projectAiChatThreadToUrl(THREAD_A);
+ });
+
+ expect(navigateAppMock).toHaveBeenCalledWith(
+ AppPath.AiChatInbox,
+ { threadId: THREAD_A },
+ undefined,
+ { replace: false, state: null },
+ );
+ });
+
+ it('opens a new chat from the closed inbox in a new history entry', () => {
+ window.history.pushState(null, '', '/inbox');
+
+ const { result } = renderHook(() => useProjectAiChatThreadToUrl());
+
+ act(() => {
+ result.current.projectAiChatThreadToUrl(
+ getDefaultStore().get(newAiChatThreadIdState.atom),
+ );
+ });
+
+ expect(navigateAppMock).toHaveBeenCalledWith(
+ AppPath.AiChatInbox,
+ { threadId: AI_CHAT_NEW_THREAD_PATH_SEGMENT },
+ undefined,
+ { replace: false, state: null },
+ );
+ });
});
diff --git a/packages/twenty-front/src/modules/ai/hooks/useAgentChat.ts b/packages/twenty-front/src/modules/ai/hooks/useAgentChat.ts
index 376b62b8af3..cfaf1223a17 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useAgentChat.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useAgentChat.ts
@@ -65,7 +65,9 @@ export const useAgentChat = () => {
const apolloClient = useApolloClient();
const { enqueueToast } = useToast();
const setCurrentAiChatThread = useSetAtomState(currentAiChatThreadState);
- const { projectAiChatThreadToUrl } = useProjectAiChatThreadToUrl();
+ const { projectAiChatThreadToUrl } = useProjectAiChatThreadToUrl({
+ shouldPreserveClosedInbox: true,
+ });
const { refreshAgentChatThreadPermissions } =
useRefreshAgentChatThreadPermissions();
const store = useStore();
diff --git a/packages/twenty-front/src/modules/ai/hooks/useLeaveRemovedAiChatThread.ts b/packages/twenty-front/src/modules/ai/hooks/useLeaveRemovedAiChatThread.ts
index a3d39a3e6b4..6e4049e1ac9 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useLeaveRemovedAiChatThread.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useLeaveRemovedAiChatThread.ts
@@ -13,7 +13,9 @@ import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/should
export const useLeaveRemovedAiChatThread = () => {
const store = useStore();
- const { projectAiChatThreadToUrl } = useProjectAiChatThreadToUrl();
+ const { projectAiChatThreadToUrl } = useProjectAiChatThreadToUrl({
+ shouldPreserveClosedInbox: true,
+ });
const { loadAgentChatThread } = useRefreshAgentChatThreads();
const leaveRemovedAiChatThread = useCallback(async () => {
diff --git a/packages/twenty-front/src/modules/ai/hooks/useProjectAiChatThreadToUrl.ts b/packages/twenty-front/src/modules/ai/hooks/useProjectAiChatThreadToUrl.ts
index 346aa717dfc..1c20dd42ceb 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useProjectAiChatThreadToUrl.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useProjectAiChatThreadToUrl.ts
@@ -1,6 +1,7 @@
import { useStore } from 'jotai';
import { useCallback } from 'react';
import { AppPath } from 'twenty-shared/types';
+import { getAppPath } from 'twenty-shared/utils';
import { AI_CHAT_NEW_THREAD_PATH_SEGMENT } from '@/ai/constants/AiChatNewThreadPathSegment';
import { newAiChatThreadIdState } from '@/ai/states/newAiChatThreadIdState';
@@ -8,14 +9,30 @@ import { useNavigateApp } from '~/hooks/useNavigateApp';
import { getCurrentHistoryEntryState } from '~/utils/getCurrentHistoryEntryState';
import { isAiChatInboxPath } from '~/utils/isAiChatInboxPath';
import { isCurrentPathAiChatPage } from '~/utils/isCurrentPathAiChatPage';
+import { isMatchingPathname } from '~/utils/isMatchingPathname';
-export const useProjectAiChatThreadToUrl = () => {
+type UseProjectAiChatThreadToUrlParams = {
+ shouldPreserveClosedInbox?: boolean;
+};
+
+export const useProjectAiChatThreadToUrl = ({
+ shouldPreserveClosedInbox = false,
+}: UseProjectAiChatThreadToUrlParams = {}) => {
const navigateApp = useNavigateApp();
const store = useStore();
const projectAiChatThreadToUrl = useCallback(
(threadId: string) => {
- const isOnInboxPage = isAiChatInboxPath(window.location.pathname);
+ const pathname = window.location.pathname;
+ const isOnInboxPage = isAiChatInboxPath(pathname);
+ const isInboxClosed = isMatchingPathname(
+ pathname,
+ getAppPath(AppPath.AiChatInbox, { threadId: null }),
+ );
+
+ if (shouldPreserveClosedInbox && isInboxClosed) {
+ return;
+ }
if (!isCurrentPathAiChatPage() && !isOnInboxPage) {
return;
@@ -32,10 +49,10 @@ export const useProjectAiChatThreadToUrl = () => {
threadId: isNewChat ? newThreadPathSegment : threadId,
},
undefined,
- { replace: true, state: getCurrentHistoryEntryState() },
+ { replace: !isInboxClosed, state: getCurrentHistoryEntryState() },
);
},
- [navigateApp, store],
+ [navigateApp, shouldPreserveClosedInbox, store],
);
return { projectAiChatThreadToUrl };
diff --git a/packages/twenty-front/src/modules/ai/hooks/useSelectAiChatThread.ts b/packages/twenty-front/src/modules/ai/hooks/useSelectAiChatThread.ts
index cb24813e2e6..803e269b2d3 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useSelectAiChatThread.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useSelectAiChatThread.ts
@@ -3,6 +3,7 @@ import { useStore } from 'jotai';
import { useProjectAiChatThreadToUrl } from '@/ai/hooks/useProjectAiChatThreadToUrl';
import { useSwitchAgentChatThreadWithDraft } from '@/ai/hooks/useSwitchAgentChatThreadWithDraft';
import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
+import { closingAiChatInboxThreadIdState } from '@/ai/states/closingAiChatInboxThreadIdState';
import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
export const useSelectAiChatThread = () => {
@@ -11,6 +12,8 @@ export const useSelectAiChatThread = () => {
const { projectAiChatThreadToUrl } = useProjectAiChatThreadToUrl();
const selectAiChatThread = (toThreadId: string) => {
+ store.set(closingAiChatInboxThreadIdState.atom, null);
+
if (store.get(currentAiChatThreadState.atom) !== toThreadId) {
store.set(shouldOpenAiChatAfterOnboardingState.atom, false);
}
diff --git a/packages/twenty-front/src/modules/ai/states/closingAiChatInboxThreadIdState.ts b/packages/twenty-front/src/modules/ai/states/closingAiChatInboxThreadIdState.ts
new file mode 100644
index 00000000000..7cb815597b4
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/states/closingAiChatInboxThreadIdState.ts
@@ -0,0 +1,6 @@
+import { createAtomState } from '@/ui/utilities/state/jotai/utils/createAtomState';
+
+export const closingAiChatInboxThreadIdState = createAtomState<string | null>({
+ key: 'ai/closingAiChatInboxThreadIdState',
+ defaultValue: null,
+});
diff --git a/packages/twenty-front/src/modules/ai/utils/__tests__/resetClosingAiChatInboxThread.test.ts b/packages/twenty-front/src/modules/ai/utils/__tests__/resetClosingAiChatInboxThread.test.ts
new file mode 100644
index 00000000000..0920eb5ef9a
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/utils/__tests__/resetClosingAiChatInboxThread.test.ts
@@ -0,0 +1,52 @@
+import { createStore } from 'jotai';
+
+import { closingAiChatInboxThreadIdState } from '@/ai/states/closingAiChatInboxThreadIdState';
+import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
+import { shouldContinueAiChatInSidePanelState } from '@/ai/states/shouldContinueAiChatInSidePanelState';
+import { resetClosingAiChatInboxThread } from '@/ai/utils/resetClosingAiChatInboxThread';
+
+const CLOSED_THREAD_ID = '11111111-1111-4111-8111-111111111111';
+const NEXT_THREAD_ID = '22222222-2222-4222-8222-222222222222';
+
+describe('resetClosingAiChatInboxThread', () => {
+ it('clears the closed conversation without leaving a pending reset', () => {
+ const store = createStore();
+
+ store.set(currentAiChatThreadState.atom, CLOSED_THREAD_ID);
+ store.set(closingAiChatInboxThreadIdState.atom, CLOSED_THREAD_ID);
+ store.set(shouldContinueAiChatInSidePanelState.atom, true);
+
+ resetClosingAiChatInboxThread(store);
+
+ expect(store.get(currentAiChatThreadState.atom)).toBeNull();
+ expect(store.get(closingAiChatInboxThreadIdState.atom)).toBeNull();
+ expect(store.get(shouldContinueAiChatInSidePanelState.atom)).toBe(false);
+ });
+
+ it('preserves a conversation selected before the closing animation finishes', () => {
+ const store = createStore();
+
+ store.set(currentAiChatThreadState.atom, NEXT_THREAD_ID);
+ store.set(closingAiChatInboxThreadIdState.atom, CLOSED_THREAD_ID);
+
+ resetClosingAiChatInboxThread(store);
+
+ expect(store.get(currentAiChatThreadState.atom)).toBe(NEXT_THREAD_ID);
+ expect(store.get(closingAiChatInboxThreadIdState.atom)).toBeNull();
+ });
+
+ it('preserves the active conversation after Ask AI consumes the pending reset', () => {
+ const store = createStore();
+
+ store.set(currentAiChatThreadState.atom, CLOSED_THREAD_ID);
+ store.set(closingAiChatInboxThreadIdState.atom, CLOSED_THREAD_ID);
+
+ resetClosingAiChatInboxThread(store);
+ store.set(currentAiChatThreadState.atom, NEXT_THREAD_ID);
+ store.set(shouldContinueAiChatInSidePanelState.atom, true);
+ resetClosingAiChatInboxThread(store);
+
+ expect(store.get(currentAiChatThreadState.atom)).toBe(NEXT_THREAD_ID);
+ expect(store.get(shouldContinueAiChatInSidePanelState.atom)).toBe(true);
+ });
+});
diff --git a/packages/twenty-front/src/modules/ai/utils/resetClosingAiChatInboxThread.ts b/packages/twenty-front/src/modules/ai/utils/resetClosingAiChatInboxThread.ts
new file mode 100644
index 00000000000..1bcb3217fde
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/utils/resetClosingAiChatInboxThread.ts
@@ -0,0 +1,22 @@
+import { type createStore } from 'jotai';
+import { isDefined } from 'twenty-shared/utils';
+
+import { closingAiChatInboxThreadIdState } from '@/ai/states/closingAiChatInboxThreadIdState';
+import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
+import { shouldContinueAiChatInSidePanelState } from '@/ai/states/shouldContinueAiChatInSidePanelState';
+
+export const resetClosingAiChatInboxThread = (
+ store: ReturnType<typeof createStore>,
+) => {
+ const closingThreadId = store.get(closingAiChatInboxThreadIdState.atom);
+
+ store.set(closingAiChatInboxThreadIdState.atom, null);
+
+ if (
+ isDefined(closingThreadId) &&
+ store.get(currentAiChatThreadState.atom) === closingThreadId
+ ) {
+ store.set(shouldContinueAiChatInSidePanelState.atom, false);
+ store.set(currentAiChatThreadState.atom, null);
+ }
+};
diff --git a/packages/twenty-front/src/modules/side-panel/hooks/useOpenAskAiPageInSidePanel.ts b/packages/twenty-front/src/modules/side-panel/hooks/useOpenAskAiPageInSidePanel.ts
index ed3ab10d606..0833b436f23 100644
--- a/packages/twenty-front/src/modules/side-panel/hooks/useOpenAskAiPageInSidePanel.ts
+++ b/packages/twenty-front/src/modules/side-panel/hooks/useOpenAskAiPageInSidePanel.ts
@@ -1,10 +1,12 @@
import { agentChatUISessionStartTimeState } from '@/ai/states/agentChatUISessionStartTimeState';
+import { resetClosingAiChatInboxThread } from '@/ai/utils/resetClosingAiChatInboxThread';
import { useIsWorkspaceActivationStatusEqualsTo } from '@/workspace/hooks/useIsWorkspaceActivationStatusEqualsTo';
import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
import { isSidePanelOpenedState } from '@/side-panel/states/isSidePanelOpenedState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { t } from '@lingui/core/macro';
+import { useStore } from 'jotai';
import { useCallback } from 'react';
import { Temporal } from 'temporal-polyfill';
import { SidePanelPages } from 'twenty-shared/types';
@@ -14,6 +16,7 @@ import { v4 } from 'uuid';
import { isCurrentPathAiChatPage } from '~/utils/isCurrentPathAiChatPage';
export const useOpenAskAiPageInSidePanel = () => {
+ const store = useStore();
const { navigateSidePanelMenu } = useSidePanelMenu();
const isSidePanelOpened = useAtomStateValue(isSidePanelOpenedState);
const setAgentChatUISessionStartTime = useSetAtomState(
@@ -33,6 +36,8 @@ export const useOpenAskAiPageInSidePanel = () => {
return;
}
+ resetClosingAiChatInboxThread(store);
+
const shouldReset =
resetNavigationStack !== undefined
? resetNavigationStack
@@ -56,6 +61,7 @@ export const useOpenAskAiPageInSidePanel = () => {
isSidePanelOpened,
setAgentChatUISessionStartTime,
isWorkspaceSuspended,
+ store,
],
);
diff --git a/packages/twenty-front/src/modules/ui/layout/draggable-list/components/__stories__/DraggableList.stories.tsx b/packages/twenty-front/src/modules/ui/layout/draggable-list/components/__stories__/DraggableList.stories.tsx
index aaa43bd40a6..af418b6a69c 100644
--- a/packages/twenty-front/src/modules/ui/layout/draggable-list/components/__stories__/DraggableList.stories.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/draggable-list/components/__stories__/DraggableList.stories.tsx
@@ -61,7 +61,9 @@ export const Default: Story = {};
export const KeyboardReorder: Story = {
play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
- const firstItem = canvas.getByRole('button', { name: 'Draggable item 1' });
+ const firstItem = await canvas.findByRole('button', {
+ name: 'Draggable item 1',
+ });
await userEvent.tab();
await expect(firstItem).toHaveFocus();
diff --git a/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx b/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx
index 98581eb5b30..5a76d8bce85 100644
--- a/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx
+++ b/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx
@@ -1,12 +1,14 @@
import { styled } from '@linaria/react';
+import { AnimatePresence } from 'framer-motion';
import { useLingui } from '@lingui/react/macro';
-import { type MouseEvent, useRef } from 'react';
+import { type MouseEvent, useRef, useState } from 'react';
import { Navigate, useParams } from 'react-router-dom';
import { Key } from 'ts-key-enum';
import { AppPath } from 'twenty-shared/types';
import { getAppPath, isDefined, isValidUuid } from 'twenty-shared/utils';
import { IconButton } from 'twenty-ui/components/input';
-import { IconChevronLeft } from 'twenty-ui/icon';
+import { themeCssVariables } from 'twenty-ui/theme';
+import { IconChevronLeft, IconX } from 'twenty-ui/icon';
import { useIsMobile } from 'twenty-ui/utilities';
import { SkeletonLoader } from '@/activities/components/SkeletonLoader';
@@ -16,6 +18,7 @@ import { AgentChatThreadsFetchMoreTrigger } from '@/ai/components/AgentChatThrea
import { AiChatInboxBreadcrumb } from '@/ai/components/AiChatInboxBreadcrumb';
import { AiChatInboxChannelToolbar } from '@/ai/components/AiChatInboxChannelToolbar';
import { AiChatInboxCommandMenuScope } from '@/ai/components/AiChatInboxCommandMenuScope';
+import { AiChatInboxConversationPane } from '@/ai/components/AiChatInboxConversationPane';
import { AiChatInboxListHeader } from '@/ai/components/AiChatInboxListHeader';
import { AiChatInboxNewThreadChannelEffect } from '@/ai/components/AiChatInboxNewThreadChannelEffect';
import { AiChatInboxSelectionEffect } from '@/ai/components/AiChatInboxSelectionEffect';
@@ -23,6 +26,7 @@ import { AiChatInboxSelectionPane } from '@/ai/components/AiChatInboxSelectionPa
import { AiChatInboxSelectionToContextStoreEffect } from '@/ai/components/AiChatInboxSelectionToContextStoreEffect';
import { AiChatInboxThreadList } from '@/ai/components/AiChatInboxThreadList';
import { AiChatInboxThreadPagination } from '@/ai/components/AiChatInboxThreadPagination';
+import { AI_CHAT_INBOX_LIST_PANE_WIDTH } from '@/ai/constants/AiChatInboxListPaneWidth';
import { AI_CHAT_NEW_THREAD_PATH_SEGMENT } from '@/ai/constants/AiChatNewThreadPathSegment';
import { useAgentChatInboxShownThreads } from '@/ai/hooks/useAgentChatInboxShownThreads';
import { useAiChatInboxRecordSelectionInstanceId } from '@/ai/hooks/useAiChatInboxRecordSelectionInstanceId';
@@ -30,6 +34,7 @@ import { useFetchMoreAgentChatInboxShownThreads } from '@/ai/hooks/useFetchMoreA
import { useIsAiChatInboxSplitView } from '@/ai/hooks/useIsAiChatInboxSplitView';
import { agentChatShownChannelViewSelector } from '@/ai/states/selectors/agentChatShownChannelViewSelector';
import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';
+import { isSidePanelItemShowingAiChat } from '@/ai/utils/isSidePanelItemShowingAiChat';
import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';
import { RecordSelectionDragSelect } from '@/object-record/record-selection/components/RecordSelectionDragSelect';
import { RecordSelectionRecordIdsEffect } from '@/object-record/record-selection/components/RecordSelectionRecordIdsEffect';
@@ -38,9 +43,10 @@ import { useResetRecordSelection } from '@/object-record/record-selection/hooks/
import { useToggleRecordSelection } from '@/object-record/record-selection/hooks/useToggleRecordSelection';
import { RecordSelectionComponentInstanceContext } from '@/object-record/record-selection/states/contexts/RecordSelectionComponentInstanceContext';
import { selectedRecordIdsComponentSelector } from '@/object-record/record-selection/states/selectors/selectedRecordIdsComponentSelector';
+import { isSidePanelOpenedState } from '@/side-panel/states/isSidePanelOpenedState';
+import { sidePanelNavigationStackState } from '@/side-panel/states/sidePanelNavigationStackState';
import { AnimatedPlaceholder } from '@/ui/feedback/empty-state/components/AnimatedPlaceholder/AnimatedPlaceholder';
import { EmptyState } from '@/ui/feedback/empty-state/components/EmptyState';
-import { PageCardHeader } from '@/ui/layout/page/components/PageCardHeader';
import { PageCardLayout } from '@/ui/layout/page/components/PageCardLayout';
import { useGlobalHotkeys } from '@/ui/utilities/hotkey/hooks/useGlobalHotkeys';
import { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue';
@@ -53,16 +59,28 @@ import { AiChatPageEffects } from '~/pages/ai-chat/AiChatPageEffects';
import { AiChatThreadPageContent } from '~/pages/ai-chat/AiChatThreadPageContent';
const StyledInbox = styled.div`
+ --inbox-list-pane-width: ${AI_CHAT_INBOX_LIST_PANE_WIDTH}px;
+
display: flex;
flex: 1;
min-height: 0;
min-width: 0;
+ overflow: hidden;
+ position: relative;
`;
const StyledListPane = styled.div<{ $isFullWidth: boolean }>`
display: flex;
- flex: ${({ $isFullWidth }) => ($isFullWidth ? '1' : '0 0 400px')};
+ flex: 0 0 auto;
min-width: 0;
+ transition: width calc(${themeCssVariables.animation.duration.normal} * 1s)
+ ease-in-out;
+ width: ${({ $isFullWidth }) =>
+ $isFullWidth ? '100%' : 'var(--inbox-list-pane-width)'};
+
+ @media (prefers-reduced-motion: reduce) {
+ transition: none;
+ }
`;
const StyledListContent = styled.div`
@@ -91,6 +109,10 @@ const AiChatInboxPageContent = () => {
const { t } = useLingui();
const isMobile = useIsMobile();
const isSplitView = useIsAiChatInboxSplitView();
+ const isSidePanelOpened = useAtomStateValue(isSidePanelOpenedState);
+ const sidePanelNavigationStack = useAtomStateValue(
+ sidePanelNavigationStackState,
+ );
const navigate = useNavigateApp();
const { threadId } = useParams();
const isNewThreadRoute = threadId === AI_CHAT_NEW_THREAD_PATH_SEGMENT;
@@ -145,9 +167,19 @@ const AiChatInboxPageContent = () => {
toggleRecordSelection({ recordId: id, shouldSelectRange: event.shiftKey });
};
+ const [keyboardCursorThreadId, setKeyboardCursorThreadId] =
+ useState(selectedThreadId);
+
+ if (
+ isDefined(selectedThreadId) &&
+ selectedThreadId !== keyboardCursorThreadId
+ ) {
+ setKeyboardCursorThreadId(selectedThreadId);
+ }
+
const { navigateWithArrowKey } = useRecordSelectionArrowKeyNavigation({
selectableItemsContainerRef: threadListContainerRef,
- activeRecordId: selectedThreadId,
+ activeRecordId: keyboardCursorThreadId,
onActiveRecordChange: selectThread,
onEndReached: fetchMoreAgentChatInboxShownThreads,
});
@@ -167,17 +199,15 @@ const AiChatInboxPageContent = () => {
const isSelectionPaneShown = isSplitView && isSelectionShown;
const isThreadShown = isDefined(selectedThreadId) && !isSelectionPaneShown;
const isNewThreadShown = isNewThreadRoute && !isSelectionPaneShown;
- // Split view always has a chat beside the list
- const firstThreadToOpen =
- isSplitView && !isDefined(selectedThreadId) && !isNewThreadRoute
- ? threads.at(0)
- : undefined;
- const isEmptyPaneShown =
- isSplitView &&
- !isDefined(selectedThreadId) &&
- !isNewThreadRoute &&
- !isSelectionShown &&
- !isDefined(firstThreadToOpen);
+ const isSecondaryPaneShown =
+ isSelectionPaneShown || isThreadShown || isNewThreadShown;
+ const isListFullWidth = !isSplitView || !isSecondaryPaneShown;
+ const isSidePanelShowingAiChat =
+ isSidePanelOpened &&
+ isSidePanelItemShowingAiChat(sidePanelNavigationStack.at(-1));
+ const shouldRenderConversationPane =
+ !isSelectionPaneShown &&
+ (isSecondaryPaneShown || !isSidePanelShowingAiChat);
const openThreadIds =
isDefined(selectedThreadId) && !isSelectionShown ? [selectedThreadId] : [];
@@ -196,22 +226,48 @@ const AiChatInboxPageContent = () => {
options: { enableOnContentEditable: false, enableOnFormTags: false },
});
+ const backToInboxButton = (
+ <IconButton
+ size="sm"
+ variant="outline"
+ onClick={() => selectThread(null)}
+ aria-label={t`Back to inbox`}
+ >
+ <IconChevronLeft />
+ </IconButton>
+ );
+
+ const closeConversationButton = isSplitView && (
+ <IconButton
+ size="sm"
+ variant="outline"
+ onClick={() => selectThread(null)}
+ aria-label={t`Close`}
+ >
+ <IconX />
+ </IconButton>
+ );
+
+ const desktopThreadHeaderActions = isDefined(selectedThreadId) && (
+ <>
+ <AiChatInboxThreadPagination
+ threads={threads}
+ threadId={selectedThreadId}
+ onThreadSelect={selectThread}
+ />
+ {closeConversationButton}
+ </>
+ );
+
return (
<StyledInbox>
<AgentChatChannelThreadsLoadEffect />
<RecordSelectionRecordIdsEffect records={threads} />
<AiChatInboxSelectionEffect
+ key={selectedThreadId}
selectedThreadId={selectedThreadId}
threads={threads}
/>
- {isDefined(firstThreadToOpen) && (
- <Navigate
- to={getAppPath(AppPath.AiChatInbox, {
- threadId: firstThreadToOpen.id,
- })}
- replace
- />
- )}
{/* The selection takes the place of the chat on screen, so the command
menu acts on it */}
{isSelectionShown && !isThreadShown && (
@@ -221,12 +277,17 @@ const AiChatInboxPageContent = () => {
)}
<AiChatInboxCommandMenuScope>
{isListShown && (
- <StyledListPane $isFullWidth={!isSplitView}>
+ <StyledListPane
+ $isFullWidth={isListFullWidth}
+ role="region"
+ aria-label={t`Conversation list`}
+ >
<PageCardLayout
- showInformationBanner={!isSplitView}
+ showInformationBanner={isListFullWidth}
header={
<AiChatInboxListHeader
selectedThreadCount={selectedRecordIds.length}
+ isSecondaryPaneShown={isSecondaryPaneShown}
/>
}
>
@@ -285,64 +346,37 @@ const AiChatInboxPageContent = () => {
/>
)}
</AiChatInboxCommandMenuScope>
- {isNewThreadShown && (
- <>
- <AiChatPageEffects />
- <AiChatInboxNewThreadChannelEffect />
- <AiChatNewThreadPageContent
- showInformationBanner={!isSplitView}
- headerActions={
- isMobile ? (
- <IconButton
- size="sm"
- variant="outline"
- onClick={() => selectThread(null)}
- aria-label={t`Back to inbox`}
- >
- <IconChevronLeft />
- </IconButton>
- ) : undefined
- }
- />
- </>
- )}
- {isThreadShown && (
- <>
- <AiChatPageEffects />
- <AiChatThreadPageContent
- threadId={selectedThreadId}
- headerTitlePrefix={
- !isSplitView && !isMobile && <AiChatInboxBreadcrumb />
- }
- headerActions={
- isMobile ? (
- <IconButton
- size="sm"
- variant="outline"
- onClick={() => selectThread(null)}
- aria-label={t`Back to inbox`}
- >
- <IconChevronLeft />
- </IconButton>
- ) : (
- <AiChatInboxThreadPagination
- threads={threads}
- threadId={selectedThreadId}
- onThreadSelect={selectThread}
- />
- )
- }
- />
- </>
- )}
- {isEmptyPaneShown && (
- <PageCardLayout header={<PageCardHeader />}>
- <EmptyState.Root>
- <EmptyState.Content>
- <EmptyState.Title>{t`No conversation selected`}</EmptyState.Title>
- </EmptyState.Content>
- </EmptyState.Root>
- </PageCardLayout>
+ {shouldRenderConversationPane && (
+ <AnimatePresence initial={false}>
+ {(isNewThreadShown || isThreadShown) && (
+ <AiChatInboxConversationPane isSplitView={isSplitView}>
+ {isNewThreadShown && (
+ <>
+ <AiChatPageEffects />
+ <AiChatInboxNewThreadChannelEffect />
+ <AiChatNewThreadPageContent
+ showInformationBanner={!isSplitView}
+ headerActions={isMobile ? backToInboxButton : undefined}
+ />
+ </>
+ )}
+ {isThreadShown && (
+ <>
+ <AiChatPageEffects />
+ <AiChatThreadPageContent
+ threadId={selectedThreadId}
+ headerTitlePrefix={
+ !isSplitView && !isMobile && <AiChatInboxBreadcrumb />
+ }
+ headerActions={
+ isMobile ? backToInboxButton : desktopThreadHeaderActions
+ }
+ />
+ </>
+ )}
+ </AiChatInboxConversationPane>
+ )}
+ </AnimatePresence>
)}
</StyledInbox>
);
diff --git a/packages/twenty-front/src/pages/ai-chat/__stories__/AiChatInboxPage.stories.tsx b/packages/twenty-front/src/pages/ai-chat/__stories__/AiChatInboxPage.stories.tsx
index 33e56ccc4a4..990dfcfb629 100644
--- a/packages/twenty-front/src/pages/ai-chat/__stories__/AiChatInboxPage.stories.tsx
+++ b/packages/twenty-front/src/pages/ai-chat/__stories__/AiChatInboxPage.stories.tsx
@@ -1,13 +1,19 @@
import { HelmetProvider } from '@dr.pogodin/react-helmet';
+import { styled } from '@linaria/react';
import {
type Decorator,
type Meta,
type StoryObj,
} from '@storybook/react-vite';
import { graphql, HttpResponse } from 'msw';
+import { MotionGlobalConfig } from 'framer-motion';
import { MemoryRouter, Route, Routes, useNavigate } from 'react-router-dom';
-import { expect, userEvent, within } from 'storybook/test';
-import { AppPath, CoreObjectNameSingular } from 'twenty-shared/types';
+import { expect, userEvent, waitFor, within } from 'storybook/test';
+import {
+ AppPath,
+ CoreObjectNameSingular,
+ SidePanelPages,
+} from 'twenty-shared/types';
import {
assertIsDefinedOrThrow,
getAppPath,
@@ -15,15 +21,20 @@ import {
} from 'twenty-shared/utils';
import { Button } from 'twenty-ui/primitives/input';
import { ComponentDecorator } from 'twenty-ui/testing';
+import { themeCssVariables } from 'twenty-ui/theme';
import { v4 as uuidv4 } from 'uuid';
import { AGENT_CHAT_THREAD_FILTER_STATUS } from '@/ai/constants/AgentChatThreadFilterStatus';
import { AI_CHAT_INBOX_LAYOUT } from '@/ai/constants/AiChatInboxLayout';
+import { AI_CHAT_INBOX_LIST_PANE_WIDTH } from '@/ai/constants/AiChatInboxListPaneWidth';
import { AI_CHAT_NEW_THREAD_PATH_SEGMENT } from '@/ai/constants/AiChatNewThreadPathSegment';
+import { useSelectAiChatThread } from '@/ai/hooks/useSelectAiChatThread';
import { agentChatThreadFilterStatusState } from '@/ai/states/agentChatThreadFilterStatusState';
import { agentChatThreadListState } from '@/ai/states/agentChatThreadListState';
import { agentChatThreadParticipantsState } from '@/ai/states/agentChatThreadParticipantsState';
import { aiChatInboxLayoutState } from '@/ai/states/aiChatInboxLayoutState';
+import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
+import { closingAiChatInboxThreadIdState } from '@/ai/states/closingAiChatInboxThreadIdState';
import { initializeNewAiChatStory } from '@/ai/testing/initializeNewAiChatStory';
import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';
import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';
@@ -31,6 +42,9 @@ import { ContextStoreComponentInstanceContext } from '@/context-store/states/con
import { objectMetadataItemsSelector } from '@/object-metadata/states/objectMetadataItemsSelector';
import { getRecordConnectionFromRecords } from '@/object-record/cache/utils/getRecordConnectionFromRecords';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
+import { useOpenAskAiPageInSidePanel } from '@/side-panel/hooks/useOpenAskAiPageInSidePanel';
+import { isSidePanelOpenedState } from '@/side-panel/states/isSidePanelOpenedState';
+import { sidePanelNavigationStackState } from '@/side-panel/states/sidePanelNavigationStackState';
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
import { AiChatInboxPage } from '~/pages/ai-chat/AiChatInboxPage';
import { MemoryRouterAppNavigatorProvider } from '~/testing/components/MemoryRouterAppNavigatorProvider';
@@ -44,6 +58,7 @@ const SECOND_THREAD_ID = '20202020-0000-4000-8000-0000000000bb';
const FIRST_THREAD_TITLE = 'Qualify the lead';
const SECOND_THREAD_TITLE = 'Prepare the customer call';
const THREAD_ACTIVITY_AT = '2026-10-21T09:00:00.000Z';
+const THREAD_ARCHIVED_AT = '2026-10-21T11:00:00.000Z';
const CHAT_OBJECT_METADATA_ID = '20202020-0000-4000-8000-0000000000cc';
const CHAT_TARGET_OBJECT_METADATA_ID = '20202020-0000-4000-8000-0000000000dd';
const CHAT_FIELD_NAMES = ['id', 'title', 'createdAt', 'updatedAt', 'deletedAt'];
@@ -71,11 +86,27 @@ const THREADS: AgentChatThreadRecord[] = [
},
];
+const StyledInboxStory = styled.div`
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ min-height: 0;
+ min-width: 0;
+`;
+
+const StyledNavigationControls = styled.div`
+ display: flex;
+ flex-wrap: wrap;
+ gap: ${themeCssVariables.spacing[2]};
+`;
+
const InboxRouteNavigation = () => {
const navigate = useNavigate();
+ const { openAskAiPage } = useOpenAskAiPageInSidePanel();
+ const { selectAiChatThread } = useSelectAiChatThread();
return (
- <>
+ <StyledNavigationControls>
<Button onClick={() => navigate(NEW_CHAT_PATH)}>
Open new chat route
</Button>
@@ -101,7 +132,11 @@ const InboxRouteNavigation = () => {
</Button>
<Button onClick={() => navigate(-1)}>Back through history</Button>
<Button onClick={() => navigate(1)}>Forward through history</Button>
- </>
+ <Button onClick={() => openAskAiPage()}>Open Ask AI</Button>
+ <Button onClick={() => selectAiChatThread(FIRST_THREAD_ID)}>
+ Select first chat for Ask AI
+ </Button>
+ </StyledNavigationControls>
);
};
@@ -114,10 +149,12 @@ const InboxRouteDecorator: Decorator = (Story) => (
value={{ instanceId: MAIN_CONTEXT_STORE_INSTANCE_ID }}
>
<MemoryRouterAppNavigatorProvider>
- <InboxRouteNavigation />
- <Routes>
- <Route path={AppPath.AiChatInbox} element={<Story />} />
- </Routes>
+ <StyledInboxStory>
+ <InboxRouteNavigation />
+ <Routes>
+ <Route path={AppPath.AiChatInbox} element={<Story />} />
+ </Routes>
+ </StyledInboxStory>
</MemoryRouterAppNavigatorProvider>
</ContextStoreComponentInstanceContext.Provider>
</MemoryRouter>
@@ -209,6 +246,22 @@ const getThreadRow = ({
return row;
};
+const archiveThread = (threadId: string) => {
+ const participants = jotaiStore.get(agentChatThreadParticipantsState.atom);
+ const participant = participants?.[threadId];
+
+ assertIsDefinedOrThrow(participant);
+
+ jotaiStore.set(agentChatThreadParticipantsState.atom, {
+ ...participants,
+ [threadId]: {
+ ...participant,
+ archivedAt: THREAD_ARCHIVED_AT,
+ updatedAt: THREAD_ARCHIVED_AT,
+ },
+ });
+};
+
const meta = {
title: 'Pages/AiChat/AiChatInboxPage',
component: AiChatInboxPage,
@@ -387,6 +440,11 @@ export const SavedChatNavigationClearsSelection: Story = {
aiChatInboxLayoutState.atom,
AI_CHAT_INBOX_LAYOUT.SPLIT_VIEW,
);
+ await user.click(
+ within(
+ getThreadRow({ canvasElement, title: FIRST_THREAD_TITLE }),
+ ).getByText(FIRST_THREAD_TITLE),
+ );
await canvas.findByRole('button', { name: 'Chat details' });
const firstThreadRow = getThreadRow({
@@ -438,3 +496,233 @@ export const SavedChatNavigationClearsSelection: Story = {
).toBe(secondThreadRow);
},
};
+
+export const CloseConversationPane: Story = {
+ beforeEach: () => {
+ jotaiStore.set(
+ aiChatInboxLayoutState.atom,
+ AI_CHAT_INBOX_LAYOUT.SPLIT_VIEW,
+ );
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const user = userEvent.setup();
+
+ await canvas.findByText(FIRST_THREAD_TITLE);
+ loadChatRecordMetadata();
+
+ const list = canvas.getByRole('region', { name: 'Conversation list' });
+ const fullListWidth = list.getBoundingClientRect().width;
+ const firstThreadRow = getThreadRow({
+ canvasElement,
+ title: FIRST_THREAD_TITLE,
+ });
+
+ await expect(
+ canvas.queryByRole('button', { name: 'Chat details' }),
+ ).not.toBeInTheDocument();
+ await expect(
+ canvas.getByRole('button', { name: 'Command Menu' }),
+ ).toBeVisible();
+
+ await user.click(within(firstThreadRow).getByText(FIRST_THREAD_TITLE));
+ await canvas.findByRole('button', { name: 'Chat details' });
+ await waitFor(() =>
+ expect(list.getBoundingClientRect().width).toBeCloseTo(
+ AI_CHAT_INBOX_LIST_PANE_WIDTH,
+ 0,
+ ),
+ );
+
+ const splitListWidth = list.getBoundingClientRect().width;
+ const conversation = canvas.getByRole('region', { name: 'Conversation' });
+ const shouldReduceMotion = window.matchMedia(
+ '(prefers-reduced-motion: reduce)',
+ ).matches;
+
+ await user.click(canvas.getByRole('button', { name: 'Close' }));
+ await expect(
+ canvas.queryByRole('button', { name: 'Chat details' }),
+ ).not.toBeInTheDocument();
+
+ if (!shouldReduceMotion && !MotionGlobalConfig.skipAnimations) {
+ await expect(conversation).toBeInTheDocument();
+ await expect(jotaiStore.get(currentAiChatThreadState.atom)).toBe(
+ FIRST_THREAD_ID,
+ );
+ await expect(conversation).toHaveAttribute('aria-hidden', 'true');
+ await waitFor(() => {
+ const closingListWidth = list.getBoundingClientRect().width;
+
+ expect(closingListWidth).toBeGreaterThan(splitListWidth);
+ expect(closingListWidth).toBeLessThan(fullListWidth);
+ });
+ }
+
+ await waitFor(() => {
+ expect(conversation).not.toBeInTheDocument();
+ expect(list.getBoundingClientRect().width).toBeCloseTo(fullListWidth, 0);
+ expect(jotaiStore.get(currentAiChatThreadState.atom)).toBeNull();
+ });
+ await expect(
+ getThreadRow({ canvasElement, title: FIRST_THREAD_TITLE }),
+ ).toBe(firstThreadRow);
+ await expect(jotaiStore.get(aiChatInboxLayoutState.atom)).toBe(
+ AI_CHAT_INBOX_LAYOUT.SPLIT_VIEW,
+ );
+ await expect(
+ canvas.getByRole('button', { name: 'Command Menu' }),
+ ).toBeVisible();
+
+ await user.keyboard('{ArrowDown}');
+ await canvas.findByRole('button', { name: 'Chat details' });
+ await expect(canvas.getAllByText(SECOND_THREAD_TITLE)).toHaveLength(2);
+ await waitFor(() =>
+ expect(list.getBoundingClientRect().width).toBeCloseTo(splitListWidth, 0),
+ );
+
+ const reopenedConversation = canvas.getByRole('region', {
+ name: 'Conversation',
+ });
+
+ jotaiStore.set(isSidePanelOpenedState.atom, true);
+ await user.click(canvas.getByRole('button', { name: 'Close' }));
+ await waitFor(() => {
+ expect(reopenedConversation).not.toBeInTheDocument();
+ expect(list.getBoundingClientRect().width).toBeCloseTo(fullListWidth, 0);
+ expect(jotaiStore.get(currentAiChatThreadState.atom)).toBeNull();
+ });
+ await expect(jotaiStore.get(isSidePanelOpenedState.atom)).toBe(true);
+ },
+};
+
+export const AskAiAfterClosingConversation: Story = {
+ beforeEach: () => {
+ jotaiStore.set(
+ aiChatInboxLayoutState.atom,
+ AI_CHAT_INBOX_LAYOUT.SPLIT_VIEW,
+ );
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const user = userEvent.setup();
+
+ await canvas.findByText(FIRST_THREAD_TITLE);
+ loadChatRecordMetadata();
+ await user.click(
+ within(
+ getThreadRow({ canvasElement, title: FIRST_THREAD_TITLE }),
+ ).getByText(FIRST_THREAD_TITLE),
+ );
+ await canvas.findByRole('button', { name: 'Chat details' });
+
+ const conversation = canvas.getByRole('region', { name: 'Conversation' });
+
+ await user.click(canvas.getByRole('button', { name: 'Close' }));
+ await user.click(canvas.getByRole('button', { name: 'Open Ask AI' }));
+ await expect(conversation).not.toBeInTheDocument();
+ await expect(
+ jotaiStore.get(sidePanelNavigationStackState.atom).at(-1)?.page,
+ ).toBe(SidePanelPages.AskAI);
+ await expect(jotaiStore.get(currentAiChatThreadState.atom)).toBeNull();
+ await expect(
+ jotaiStore.get(closingAiChatInboxThreadIdState.atom),
+ ).toBeNull();
+
+ await user.click(
+ canvas.getByRole('button', { name: 'Select first chat for Ask AI' }),
+ );
+ await user.click(canvas.getByRole('button', { name: 'Open Ask AI' }));
+ await waitFor(() => expect(conversation).not.toBeInTheDocument());
+ await expect(jotaiStore.get(currentAiChatThreadState.atom)).toBe(
+ FIRST_THREAD_ID,
+ );
+ },
+};
+
+export const ClosedConversationHistory: Story = {
+ beforeEach: () => {
+ jotaiStore.set(
+ aiChatInboxLayoutState.atom,
+ AI_CHAT_INBOX_LAYOUT.SPLIT_VIEW,
+ );
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const user = userEvent.setup();
+
+ await canvas.findByText(FIRST_THREAD_TITLE);
+ loadChatRecordMetadata();
+ await user.click(
+ within(
+ getThreadRow({ canvasElement, title: FIRST_THREAD_TITLE }),
+ ).getByText(FIRST_THREAD_TITLE),
+ );
+ await canvas.findByRole('button', { name: 'Chat details' });
+ await user.click(canvas.getByRole('button', { name: 'Close' }));
+ archiveThread(FIRST_THREAD_ID);
+
+ await waitFor(() =>
+ expect(canvas.queryByText(FIRST_THREAD_TITLE)).not.toBeInTheDocument(),
+ );
+ await expect(
+ canvas.queryByRole('button', { name: 'Chat details' }),
+ ).not.toBeInTheDocument();
+
+ await user.click(
+ canvas.getByRole('button', { name: 'Back through history' }),
+ );
+ await canvas.findByRole('button', { name: 'Chat details' });
+ await expect(canvas.getByText(FIRST_THREAD_TITLE)).toBeVisible();
+ await expect(canvas.getAllByText(SECOND_THREAD_TITLE)).toHaveLength(1);
+
+ await user.click(
+ canvas.getByRole('button', { name: 'Forward through history' }),
+ );
+ await expect(
+ canvas.queryByRole('button', { name: 'Chat details' }),
+ ).not.toBeInTheDocument();
+ await waitFor(() =>
+ expect(canvas.queryByText(FIRST_THREAD_TITLE)).not.toBeInTheDocument(),
+ );
+ await expect(canvas.getByText(SECOND_THREAD_TITLE)).toBeVisible();
+ },
+};
+
+export const TriageAfterReopeningConversation: Story = {
+ beforeEach: () => {
+ jotaiStore.set(
+ aiChatInboxLayoutState.atom,
+ AI_CHAT_INBOX_LAYOUT.SPLIT_VIEW,
+ );
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const user = userEvent.setup();
+
+ await canvas.findByText(FIRST_THREAD_TITLE);
+ loadChatRecordMetadata();
+ await user.click(
+ within(
+ getThreadRow({ canvasElement, title: FIRST_THREAD_TITLE }),
+ ).getByText(FIRST_THREAD_TITLE),
+ );
+ await canvas.findByRole('button', { name: 'Chat details' });
+ await user.click(canvas.getByRole('button', { name: 'Close' }));
+ await user.click(
+ within(
+ getThreadRow({ canvasElement, title: SECOND_THREAD_TITLE }),
+ ).getByText(SECOND_THREAD_TITLE),
+ );
+ await canvas.findByRole('button', { name: 'Chat details' });
+ archiveThread(SECOND_THREAD_ID);
+
+ await waitFor(() => {
+ expect(canvas.queryAllByText(SECOND_THREAD_TITLE)).toHaveLength(0);
+ expect(canvas.getAllByText(FIRST_THREAD_TITLE)).toHaveLength(2);
+ });
+ await expect(
+ canvas.getByRole('button', { name: 'Chat details' }),
+ ).toBeVisible();
+ },
+};
diff --git a/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx b/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx
index 32801ce265f..11f832a6251 100644
--- a/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx
+++ b/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx
@@ -1,7 +1,7 @@
import { MemoryRouterAppNavigatorProvider } from '~/testing/components/MemoryRouterAppNavigatorProvider';
import { i18n } from '@lingui/core';
import { I18nProvider } from '@lingui/react';
-import { fireEvent, render, screen } from '@testing-library/react';
+import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { atom, Provider as JotaiProvider } from 'jotai';
import { type ReactNode } from 'react';
@@ -302,10 +302,13 @@ describe('AiChatInboxPage', () => {
expect(screen.getByText('Chat page without the inbox')).toBeInTheDocument();
});
- it('opens the first chat beside the list', () => {
+ it('shows the list without selecting a chat on the base inbox route', () => {
renderInbox('/inbox');
- expect(screen.getByText(`Chat page ${firstThread.id}`)).toBeInTheDocument();
+ expect(
+ screen.getByRole('region', { name: 'Conversation list' }),
+ ).toBeInTheDocument();
+ expect(screen.queryByText(/^Chat page /)).not.toBeInTheDocument();
expect(
screen.queryByText('No conversation selected'),
).not.toBeInTheDocument();
@@ -590,7 +593,7 @@ describe('AiChatInboxPage', () => {
).not.toBeInTheDocument();
});
- it('moves between chats and back to the list from the chat', () => {
+ it('moves between chats and back to the list from the chat', async () => {
renderInbox(`/inbox/${secondThread.id}`);
fireEvent.click(screen.getByRole('button', { name: 'Next chat' }));
@@ -602,7 +605,9 @@ describe('AiChatInboxPage', () => {
fireEvent.click(screen.getByRole('link', { name: /Open/ }));
- expect(screen.queryByText(/Chat page/)).not.toBeInTheDocument();
+ await waitFor(() =>
+ expect(screen.queryByText(/Chat page/)).not.toBeInTheDocument(),
+ );
expect(
screen.getByRole('button', { name: 'Third chat' }),
).toBeInTheDocument();