The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Cap Recent chats at 5 in the AI chat inbox drawer (#28231)
Félix Malfaite7743ba77003
diff --git a/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatContent.tsx b/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatContent.tsxindex 8e958e3e7d1..8b83885ec1f 100644--- a/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatContent.tsx+++ b/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatContent.tsx@@ -7,6 +7,7 @@ import { AgentChatThreadsFetchMoreTrigger } from '@/ai/components/AgentChatThreaimport { AiChatSkeletonLoader } from '@/ai/components/internal/AiChatSkeletonLoader';import { NavigationDrawerAiChatThreadSection } from '@/ai/components/NavigationDrawerAiChatThreadSection';import { NavigationDrawerAiChatTriageSection } from '@/ai/components/NavigationDrawerAiChatTriageSection';+import { AI_CHAT_INBOX_RECENT_THREADS_MAX_COUNT } from '@/ai/constants/AiChatInboxRecentThreadsMaxCount';import { useAiChatThreadClick } from '@/ai/hooks/useAiChatThreadClick';import { useChatThreads } from '@/ai/hooks/useChatThreads';import { agentChatRecentThreadsSelector } from '@/ai/states/selectors/agentChatRecentThreadsSelector';@@ -71,9 +72,12 @@ export const NavigationDrawerAiChatContent = () => {const agentChatFavoriteThreadIds = new Set(agentChatFavoriteThreads.map(({ id }) => id),);- const recentThreads = threads.filter(+ const nonFavoriteThreads = threads.filter(({ id }) => !agentChatFavoriteThreadIds.has(id),);+ const recentThreads = isAiChatInboxEnabled+ ? nonFavoriteThreads.slice(0, AI_CHAT_INBOX_RECENT_THREADS_MAX_COUNT)+ : nonFavoriteThreads;return (<StyledContainer>@@ -99,7 +103,7 @@ export const NavigationDrawerAiChatContent = () => {/>)}</StyledSectionsContainer>- <AgentChatThreadsFetchMoreTrigger />+ {!isAiChatInboxEnabled && <AgentChatThreadsFetchMoreTrigger />}</StyledThreadList></StyledContainer>);diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatContent.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatContent.test.tsxindex 7ce9bc0db12..145bac0935f 100644--- a/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatContent.test.tsx+++ b/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatContent.test.tsx@@ -64,7 +64,7 @@ jest.mock('@/workspace/hooks/useIsFeatureEnabled', () => ({}));jest.mock('@/ai/components/AgentChatThreadsFetchMoreTrigger', () => ({- AgentChatThreadsFetchMoreTrigger: () => null,+ AgentChatThreadsFetchMoreTrigger: () => <div>Load more chats</div>,}));jest.mock('@/ai/components/NavigationDrawerAiChatThreadSection', () => ({@@ -132,6 +132,39 @@ describe('NavigationDrawerAiChatContent', () => {expect(queryByRole('region', { name: 'Recent' })).toBeInTheDocument();});+ it('caps Recent at 5 non-favorite chats with the inbox feature flag on', () => {+ mockThreads = Array.from({ length: 8 }, (_, index) =>+ buildThread(`chat-${index}`, `Chat ${index}`),+ );+ jotaiStore.set(mockFavoriteThreadsAtom, [+ { id: 'chat-0', title: 'Chat 0', deletedAt: null },+ ]);++ const { getByRole, queryByText } = renderContent();++ const recents = getByRole('region', { name: 'Recent' });++ expect(within(recents).getAllByText(/^Chat \d$/)).toHaveLength(5);+ expect(within(recents).queryByText('Chat 0')).toBeNull();+ expect(within(recents).getByText('Chat 5')).toBeInTheDocument();+ expect(within(recents).queryByText('Chat 6')).toBeNull();+ expect(queryByText('Load more chats')).toBeNull();+ });++ it('does not cap Recent while the inbox feature flag is off', () => {+ mockIsAiChatInboxEnabled = false;+ mockThreads = Array.from({ length: 7 }, (_, index) =>+ buildThread(`chat-${index}`, `Chat ${index}`),+ );++ const { getByRole, getByText } = renderContent();++ const recents = getByRole('region', { name: 'Recent' });++ expect(within(recents).getAllByText(/^Chat \d$/)).toHaveLength(7);+ expect(getByText('Load more chats')).toBeInTheDocument();+ });+it('shows no Favorites section without favorite chats', () => {jotaiStore.set(mockFavoriteThreadsAtom, []);diff --git a/packages/twenty-front/src/modules/ai/constants/AiChatInboxRecentThreadsMaxCount.ts b/packages/twenty-front/src/modules/ai/constants/AiChatInboxRecentThreadsMaxCount.tsnew file mode 100644index 00000000000..17320a5c782--- /dev/null+++ b/packages/twenty-front/src/modules/ai/constants/AiChatInboxRecentThreadsMaxCount.ts@@ -0,0 +1 @@+export const AI_CHAT_INBOX_RECENT_THREADS_MAX_COUNT = 5;