Skip to content

The open alternative to Salesforce, designed for AI.

Show the unread inbox count in the blue badge (#29133)

Raphaël Bosi85780b39b77d
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
index 1726f864e7a..b1ea5a0c03e 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
@@ -99,6 +99,7 @@ type AgentChatOpenThreadsSummary {
hasUnreadOpenThread: Boolean!
needsInputThreadCount: Int!
openThreadCount: Int!
+ unreadOpenThreadCount: Int!
}
type AgentChatThread {
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
index dbfbe3ab581..5662b6606eb 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
@@ -94,6 +94,7 @@ export interface AgentChatOpenThreadsSummary {
hasUnreadOpenThread: Scalars['Boolean']
needsInputThreadCount: Scalars['Int']
openThreadCount: Scalars['Int']
+ unreadOpenThreadCount: Scalars['Int']
__typename: 'AgentChatOpenThreadsSummary'
}
@@ -4290,6 +4291,7 @@ export interface AgentChatOpenThreadsSummaryGenqlSelection{
hasUnreadOpenThread?: boolean | number
needsInputThreadCount?: boolean | number
openThreadCount?: boolean | number
+ unreadOpenThreadCount?: boolean | number
__typename?: boolean | number
__scalar?: boolean | number
}
diff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.ts
index b7a69086339..b1405bf167c 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts
@@ -325,6 +325,9 @@ export default {
"openThreadCount": [
10
],
+ "unreadOpenThreadCount": [
+ 10
+ ],
"__typename": [
1
]
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index be8946bf32e..3c154d510bd 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -323,7 +323,7 @@ export type GetAgentChatChannelsQuery = { agentChatChannels: Array<{ __typename:
export type GetAgentChatOpenThreadsSummaryQueryVariables = Exact<{ [key: string]: never; }>;
-export type GetAgentChatOpenThreadsSummaryQuery = { agentChatOpenThreadsSummary: { __typename: 'AgentChatOpenThreadsSummary', openThreadCount: number, needsInputThreadCount: number, hasUnreadOpenThread: boolean, hasUnreadMentionThread: boolean, hasUnreadAssignedThread: boolean } };
+export type GetAgentChatOpenThreadsSummaryQuery = { agentChatOpenThreadsSummary: { __typename: 'AgentChatOpenThreadsSummary', openThreadCount: number, unreadOpenThreadCount: number, needsInputThreadCount: number, hasUnreadOpenThread: boolean, hasUnreadMentionThread: boolean, hasUnreadAssignedThread: boolean } };
export type GetAgentRunsQueryVariables = Exact<{
agentId: string;
@@ -2938,7 +2938,7 @@ export const GetAgentChatChannelRolesDocument = {"kind":"Document","definitions"
export const GetAgentChatChannelSummariesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAgentChatChannelSummaries"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"agentChatChannelSummaries"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"channelId"}},{"kind":"Field","name":{"kind":"Name","value":"openCount"}},{"kind":"Field","name":{"kind":"Name","value":"hasUnreadOpen"}},{"kind":"Field","name":{"kind":"Name","value":"assignedToMeCount"}},{"kind":"Field","name":{"kind":"Name","value":"hasUnreadAssignedToMe"}},{"kind":"Field","name":{"kind":"Name","value":"snoozedCount"}},{"kind":"Field","name":{"kind":"Name","value":"doneCount"}}]}}]}}]} as unknown as DocumentNode<GetAgentChatChannelSummariesQuery, GetAgentChatChannelSummariesQueryVariables>;
export const GetAgentChatChannelThreadIdsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAgentChatChannelThreadIds"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"channelId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"status"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"AgentChatChannelThreadStatus"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"assignment"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"AgentChatChannelAssignmentFilter"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"agentChatChannelThreadIds"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"channelId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"channelId"}}},{"kind":"Argument","name":{"kind":"Name","value":"status"},"value":{"kind":"Variable","name":{"kind":"Name","value":"status"}}},{"kind":"Argument","name":{"kind":"Name","value":"assignment"},"value":{"kind":"Variable","name":{"kind":"Name","value":"assignment"}}},{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"threadIds"}},{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}}]}}]} as unknown as DocumentNode<GetAgentChatChannelThreadIdsQuery, GetAgentChatChannelThreadIdsQueryVariables>;
export const GetAgentChatChannelsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAgentChatChannels"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"agentChatChannels"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"color"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"roleIds"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"isAccessible"}}]}}]}}]} as unknown as DocumentNode<GetAgentChatChannelsQuery, GetAgentChatChannelsQueryVariables>;
-export const GetAgentChatOpenThreadsSummaryDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAgentChatOpenThreadsSummary"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"agentChatOpenThreadsSummary"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"openThreadCount"}},{"kind":"Field","name":{"kind":"Name","value":"needsInputThreadCount"}},{"kind":"Field","name":{"kind":"Name","value":"hasUnreadOpenThread"}},{"kind":"Field","name":{"kind":"Name","value":"hasUnreadMentionThread"}},{"kind":"Field","name":{"kind":"Name","value":"hasUnreadAssignedThread"}}]}}]}}]} as unknown as DocumentNode<GetAgentChatOpenThreadsSummaryQuery, GetAgentChatOpenThreadsSummaryQueryVariables>;
+export const GetAgentChatOpenThreadsSummaryDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAgentChatOpenThreadsSummary"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"agentChatOpenThreadsSummary"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"openThreadCount"}},{"kind":"Field","name":{"kind":"Name","value":"unreadOpenThreadCount"}},{"kind":"Field","name":{"kind":"Name","value":"needsInputThreadCount"}},{"kind":"Field","name":{"kind":"Name","value":"hasUnreadOpenThread"}},{"kind":"Field","name":{"kind":"Name","value":"hasUnreadMentionThread"}},{"kind":"Field","name":{"kind":"Name","value":"hasUnreadAssignedThread"}}]}}]}}]} as unknown as DocumentNode<GetAgentChatOpenThreadsSummaryQuery, GetAgentChatOpenThreadsSummaryQueryVariables>;
export const GetAgentRunsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAgentRuns"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"agentRuns"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"agentId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"threadTitle"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"errorMessage"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"startedAt"}},{"kind":"Field","name":{"kind":"Name","value":"endedAt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"inputTokens"}},{"kind":"Field","name":{"kind":"Name","value":"outputTokens"}},{"kind":"Field","name":{"kind":"Name","value":"credits"}},{"kind":"Field","name":{"kind":"Name","value":"creatorSource"}},{"kind":"Field","name":{"kind":"Name","value":"creatorName"}},{"kind":"Field","name":{"kind":"Name","value":"input"}},{"kind":"Field","name":{"kind":"Name","value":"reply"}},{"kind":"Field","name":{"kind":"Name","value":"toolNames"}}]}}]}}]} as unknown as DocumentNode<GetAgentRunsQuery, GetAgentRunsQueryVariables>;
export const GetAiChatUsageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAiChatUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"aiChatUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"limitValue"}},{"kind":"Field","name":{"kind":"Name","value":"consumedValue"}},{"kind":"Field","name":{"kind":"Name","value":"periodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"kind"}}]}},{"kind":"Field","name":{"kind":"Name","value":"aiChatUserCreditsUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"limitValue"}},{"kind":"Field","name":{"kind":"Name","value":"consumedValue"}},{"kind":"Field","name":{"kind":"Name","value":"periodEnd"}}]}}]}}]} as unknown as DocumentNode<GetAiChatUsageQuery, GetAiChatUsageQueryVariables>;
export const GetChatMessagesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetChatMessages"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chatMessages"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"turnId"}},{"kind":"Field","name":{"kind":"Name","value":"senderWorkspaceMemberId"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"processedAt"}},{"kind":"Field","name":{"kind":"Name","value":"parts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"messageId"}},{"kind":"Field","name":{"kind":"Name","value":"orderIndex"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"textContent"}},{"kind":"Field","name":{"kind":"Name","value":"reasoningContent"}},{"kind":"Field","name":{"kind":"Name","value":"toolName"}},{"kind":"Field","name":{"kind":"Name","value":"toolCallId"}},{"kind":"Field","name":{"kind":"Name","value":"toolInput"}},{"kind":"Field","name":{"kind":"Name","value":"toolOutput"}},{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"providerExecuted"}},{"kind":"Field","name":{"kind":"Name","value":"errorMessage"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlUrl"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"fileFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileUrl"}},{"kind":"Field","name":{"kind":"Name","value":"fileId"}},{"kind":"Field","name":{"kind":"Name","value":"providerMetadata"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}}]}},{"kind":"Field","name":{"kind":"Name","value":"reactions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"emoji"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceMemberIds"}},{"kind":"Field","name":{"kind":"Name","value":"agentIds"}},{"kind":"Field","name":{"kind":"Name","value":"hasAssistantReacted"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"chatStreamCatchupChunks"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chunks"}},{"kind":"Field","name":{"kind":"Name","value":"maxSeq"}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"message"}}]}}]}}]}}]} as unknown as DocumentNode<GetChatMessagesQuery, GetChatMessagesQueryVariables>;
diff --git a/packages/twenty-front/src/generated-metadata/schema.ts b/packages/twenty-front/src/generated-metadata/schema.ts
index 82f95bcc96a..552843223c8 100644
--- a/packages/twenty-front/src/generated-metadata/schema.ts
+++ b/packages/twenty-front/src/generated-metadata/schema.ts
@@ -124,6 +124,7 @@ export type AgentChatOpenThreadsSummary = {
hasUnreadOpenThread: Scalars['Boolean']['output'];
needsInputThreadCount: Scalars['Int']['output'];
openThreadCount: Scalars['Int']['output'];
+ unreadOpenThreadCount: Scalars['Int']['output'];
};
export type AgentChatThread = {
diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatTriageSection.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatTriageSection.test.tsx
index a1fd8e1735b..96a46510112 100644
--- a/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatTriageSection.test.tsx
+++ b/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatTriageSection.test.tsx
@@ -44,6 +44,7 @@ type OpenThreadsSummary =
const READ_SUMMARY: OpenThreadsSummary = {
__typename: 'AgentChatOpenThreadsSummary',
openThreadCount: 2,
+ unreadOpenThreadCount: 0,
needsInputThreadCount: 0,
hasUnreadOpenThread: false,
hasUnreadMentionThread: false,
diff --git a/packages/twenty-front/src/modules/ai/graphql/queries/getAgentChatOpenThreadsSummary.ts b/packages/twenty-front/src/modules/ai/graphql/queries/getAgentChatOpenThreadsSummary.ts
index 89bad124d27..6f87f530a9d 100644
--- a/packages/twenty-front/src/modules/ai/graphql/queries/getAgentChatOpenThreadsSummary.ts
+++ b/packages/twenty-front/src/modules/ai/graphql/queries/getAgentChatOpenThreadsSummary.ts
@@ -4,6 +4,7 @@ export const GET_AGENT_CHAT_OPEN_THREADS_SUMMARY = gql`
query GetAgentChatOpenThreadsSummary {
agentChatOpenThreadsSummary {
openThreadCount
+ unreadOpenThreadCount
needsInputThreadCount
hasUnreadOpenThread
hasUnreadMentionThread
diff --git a/packages/twenty-front/src/modules/ai/hooks/useAgentChatOpenThreadsSummary.ts b/packages/twenty-front/src/modules/ai/hooks/useAgentChatOpenThreadsSummary.ts
index 723f1785e6b..f7fec05a47d 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useAgentChatOpenThreadsSummary.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useAgentChatOpenThreadsSummary.ts
@@ -10,6 +10,7 @@ import {
const EMPTY_AGENT_CHAT_OPEN_THREADS_SUMMARY = {
openThreadCount: 0,
+ unreadOpenThreadCount: 0,
needsInputThreadCount: 0,
hasUnreadOpenThread: false,
hasUnreadMentionThread: false,
diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx
index 86815d77e5f..e1d5d7ad006 100644
--- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx
@@ -2,6 +2,7 @@ import { NAVIGATION_DRAWER_COLLAPSED_BUTTON_SIZE } from '@/ui/navigation/navigat
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { motion, useReducedMotion } from 'framer-motion';
+import { Badge } from 'twenty-ui/primitives/data-display';
import { Tooltip } from 'twenty-ui/primitives/surfaces';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
@@ -12,7 +13,6 @@ import { useIsNavigationDrawerContentExpanded } from '@/ui/navigation/navigation
import { useNavigationDrawerModes } from '@/navigation/hooks/useNavigationDrawerModes';
import { useSwitchNavigationDrawerMode } from '@/navigation/hooks/useSwitchNavigationDrawerMode';
import { TooltipDelay } from '@/ui/layout/tooltip/constants/TooltipDelay';
-import { StyledNavigationDrawerUnreadDot } from '@/ui/navigation/navigation-drawer/components/StyledNavigationDrawerUnreadDot';
import {
type NavigationDrawerActiveTab,
NAVIGATION_DRAWER_TABS,
@@ -22,6 +22,8 @@ import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { FeatureFlagKey } from '~/generated-metadata/graphql';
import { useIsMobile } from 'twenty-ui/utilities';
+const MAX_DISPLAYED_UNREAD_COUNT = 99;
+
// Expanded, the row matches the page card header so their borders read as one line.
const StyledSwitcher = styled.div<{ isExpanded: boolean }>`
align-items: ${({ isExpanded }) => (isExpanded ? 'center' : 'flex-start')};
@@ -118,6 +120,13 @@ const StyledModeLabelBase = styled.span`
const StyledModeLabel = motion.create(StyledModeLabelBase);
+const StyledUnreadBadge = styled.span`
+ pointer-events: none;
+ position: absolute;
+ right: calc(-1 * ${themeCssVariables.spacing['1.5']});
+ top: calc(-1 * ${themeCssVariables.spacing['1.5']});
+`;
+
export const MainNavigationDrawerModeSwitcher = () => {
const { t } = useLingui();
const theme = useTheme();
@@ -131,7 +140,7 @@ export const MainNavigationDrawerModeSwitcher = () => {
const activeNavigationDrawerMode = useActiveNavigationDrawerMode();
const { switchNavigationDrawerMode } = useSwitchNavigationDrawerMode();
const shouldReduceMotion = useReducedMotion();
- const { hasUnreadOpenThread } = useAgentChatOpenThreadsSummary();
+ const { unreadOpenThreadCount } = useAgentChatOpenThreadsSummary();
const isAiChatInboxEnabled = useIsFeatureEnabled(
FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,
);
@@ -164,7 +173,7 @@ export const MainNavigationDrawerModeSwitcher = () => {
const isUnread =
isAiChatInboxEnabled &&
mode === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY &&
- hasUnreadOpenThread &&
+ unreadOpenThreadCount > 0 &&
!isActive;
const isDisabled =
mode !== NAVIGATION_DRAWER_TABS.NAVIGATION_MENU &&
@@ -183,7 +192,9 @@ export const MainNavigationDrawerModeSwitcher = () => {
type="button"
isActive={isActive}
isExpanded={isExpanded}
- aria-label={isUnread ? t`${label}, unread` : label}
+ aria-label={
+ isUnread ? t`${label}, ${unreadOpenThreadCount} unread` : label
+ }
aria-current={isActive || undefined}
aria-disabled={isDisabled}
onClick={() => {
@@ -196,7 +207,19 @@ export const MainNavigationDrawerModeSwitcher = () => {
>
<StyledModeIcon>
<Icon size={theme.icon.size.md} />
- {isUnread && <StyledNavigationDrawerUnreadDot />}
+ {isUnread && (
+ <Badge
+ render={<StyledUnreadBadge />}
+ aria-hidden="true"
+ size="xs"
+ color="primary"
+ shape={unreadOpenThreadCount < 10 ? 'circle' : 'pill'}
+ >
+ {unreadOpenThreadCount > MAX_DISPLAYED_UNREAD_COUNT
+ ? `${MAX_DISPLAYED_UNREAD_COUNT}+`
+ : unreadOpenThreadCount}
+ </Badge>
+ )}
</StyledModeIcon>
<StyledModeLabel
initial={false}
diff --git a/packages/twenty-front/src/modules/navigation/components/__stories__/MainNavigationDrawerModeSwitcher.stories.tsx b/packages/twenty-front/src/modules/navigation/components/__stories__/MainNavigationDrawerModeSwitcher.stories.tsx
new file mode 100644
index 00000000000..c42c5c95307
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/components/__stories__/MainNavigationDrawerModeSwitcher.stories.tsx
@@ -0,0 +1,198 @@
+import { MockedProvider } from '@apollo/client/testing/react';
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { createStore, Provider } from 'jotai';
+import { useState } from 'react';
+import { MemoryRouter } from 'react-router-dom';
+import { expect, userEvent, within } from 'storybook/test';
+import { Button } from 'twenty-ui/primitives/input';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+import { currentUserWorkspaceState } from '@/auth/states/currentUserWorkspaceState';
+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
+import { MainNavigationDrawerModeSwitcher } from '@/navigation/components/MainNavigationDrawerModeSwitcher';
+import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
+import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
+import {
+ FeatureFlagKey,
+ GetAgentChatOpenThreadsSummaryDocument,
+ PermissionFlagType,
+} from '~/generated-metadata/graphql';
+import { ToastDecorator } from '~/testing/decorators/ToastDecorator';
+import {
+ mockCurrentWorkspace,
+ mockedUserData,
+} from '~/testing/mock-data/users';
+
+type ModeSwitcherStoryProps = {
+ unreadOpenThreadCount: number;
+ isExpanded: boolean;
+ isInboxEnabled: boolean;
+ routePath: string;
+};
+
+const ModeSwitcherWithCollapseControl = () => {
+ const [isExpanded, setIsExpanded] = useAtomState(
+ isNavigationDrawerExpandedState,
+ );
+
+ return (
+ <>
+ <MainNavigationDrawerModeSwitcher />
+ <Button onClick={() => setIsExpanded(!isExpanded)}>
+ {isExpanded ? 'Collapse sidebar' : 'Expand sidebar'}
+ </Button>
+ </>
+ );
+};
+
+const ModeSwitcherStory = ({
+ unreadOpenThreadCount,
+ isExpanded,
+ isInboxEnabled,
+ routePath,
+}: ModeSwitcherStoryProps) => {
+ const [store] = useState(() => {
+ const initialStore = createStore();
+
+ initialStore.set(isNavigationDrawerExpandedState.atom, isExpanded);
+ initialStore.set(currentWorkspaceState.atom, {
+ ...mockCurrentWorkspace,
+ featureFlags: [
+ { key: FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED, value: isInboxEnabled },
+ ],
+ });
+ initialStore.set(currentUserWorkspaceState.atom, {
+ ...mockedUserData.currentUserWorkspace,
+ permissionFlags: [PermissionFlagType.AI],
+ });
+
+ return initialStore;
+ });
+
+ const summaryMock = {
+ request: { query: GetAgentChatOpenThreadsSummaryDocument },
+ result: {
+ data: {
+ agentChatOpenThreadsSummary: {
+ __typename: 'AgentChatOpenThreadsSummary' as const,
+ openThreadCount: unreadOpenThreadCount + 3,
+ unreadOpenThreadCount,
+ needsInputThreadCount: 0,
+ hasUnreadOpenThread: unreadOpenThreadCount > 0,
+ hasUnreadMentionThread: false,
+ hasUnreadAssignedThread: false,
+ },
+ },
+ },
+ };
+
+ return (
+ <Provider store={store}>
+ <MockedProvider mocks={[summaryMock]}>
+ <MemoryRouter initialEntries={[routePath]}>
+ <ModeSwitcherWithCollapseControl />
+ </MemoryRouter>
+ </MockedProvider>
+ </Provider>
+ );
+};
+
+const meta: Meta<ModeSwitcherStoryProps> = {
+ title: 'Modules/Navigation/MainNavigationDrawerModeSwitcher',
+ component: MainNavigationDrawerModeSwitcher,
+ decorators: [ComponentDecorator, ToastDecorator],
+ parameters: { container: { width: 240, height: 180 } },
+ args: {
+ unreadOpenThreadCount: 3,
+ isExpanded: true,
+ isInboxEnabled: true,
+ routePath: '/',
+ },
+ render: (args) => (
+ <ModeSwitcherStory
+ key={`${args.unreadOpenThreadCount}-${args.isExpanded}-${args.isInboxEnabled}-${args.routePath}`}
+ unreadOpenThreadCount={args.unreadOpenThreadCount}
+ isExpanded={args.isExpanded}
+ isInboxEnabled={args.isInboxEnabled}
+ routePath={args.routePath}
+ />
+ ),
+ play: async ({ args, canvasElement }) => {
+ const canvas = within(canvasElement);
+ const label = args.isInboxEnabled ? 'Inbox' : 'AI';
+ const shouldShowUnreadCount =
+ args.isInboxEnabled &&
+ args.unreadOpenThreadCount > 0 &&
+ args.routePath !== '/inbox';
+ const inboxButton = await canvas.findByRole('button', {
+ name: shouldShowUnreadCount
+ ? `${label}, ${args.unreadOpenThreadCount} unread`
+ : label,
+ });
+
+ if (shouldShowUnreadCount) {
+ await expect(
+ within(inboxButton).getByText(String(args.unreadOpenThreadCount)),
+ ).toBeVisible();
+ return;
+ }
+
+ await expect(
+ within(inboxButton).queryByText(String(args.unreadOpenThreadCount)),
+ ).not.toBeInTheDocument();
+ },
+};
+
+export default meta;
+type Story = StoryObj<ModeSwitcherStoryProps>;
+
+export const UnreadCount: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const inboxButton = await canvas.findByRole('button', {
+ name: 'Inbox, 3 unread',
+ });
+
+ await expect(within(inboxButton).getByText('3')).toBeVisible();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Collapse sidebar' }),
+ );
+ await expect(within(inboxButton).getByText('3')).toBeVisible();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Expand sidebar' }),
+ );
+ await expect(within(inboxButton).getByText('3')).toBeVisible();
+ },
+};
+
+export const DoubleDigitCount: Story = {
+ args: { unreadOpenThreadCount: 24 },
+};
+
+export const LargeCount: Story = {
+ args: { unreadOpenThreadCount: 128 },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const inboxButton = await canvas.findByRole('button', {
+ name: 'Inbox, 128 unread',
+ });
+
+ await expect(within(inboxButton).getByText('99+')).toBeVisible();
+ },
+};
+
+export const Collapsed: Story = {
+ args: { isExpanded: false },
+};
+
+export const AllRead: Story = {
+ args: { unreadOpenThreadCount: 0 },
+};
+
+export const InboxActive: Story = {
+ args: { routePath: '/inbox' },
+};
+
+export const InboxDisabled: Story = {
+ args: { isInboxEnabled: false },
+};
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.tsx
index 5cb397b9771..e08e9083b92 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
@@ -48,6 +48,7 @@ const buildOpenThreadsSummaryMock = (hasUnreadOpenThread: boolean) => ({
agentChatOpenThreadsSummary: {
__typename: 'AgentChatOpenThreadsSummary' as const,
openThreadCount: 1,
+ unreadOpenThreadCount: hasUnreadOpenThread ? 1 : 0,
needsInputThreadCount: 0,
hasUnreadOpenThread,
hasUnreadMentionThread: false,
@@ -193,7 +194,7 @@ describe('MainNavigationDrawerModeSwitcher', () => {
renderModeSwitcher({ hasUnreadOpenThread: true });
expect(
- await screen.findByRole('button', { name: 'AI, unread' }),
+ await screen.findByRole('button', { name: 'AI, 1 unread' }),
).toBeInTheDocument();
});
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/agent-chat-open-threads-summary.dto.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/agent-chat-open-threads-summary.dto.ts
index 321e0e641e0..771b6dfaa8a 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/agent-chat-open-threads-summary.dto.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/agent-chat-open-threads-summary.dto.ts
@@ -5,6 +5,9 @@ export class AgentChatOpenThreadsSummaryDTO {
@Field(() => Int)
openThreadCount: number;
+ @Field(() => Int)
+ unreadOpenThreadCount: number;
+
@Field(() => Int)
needsInputThreadCount: number;
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-participant.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-participant.service.ts
index b5ab0e71d11..e22fdface93 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-participant.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-participant.service.ts
@@ -112,6 +112,7 @@ const INBOX_ACTION_QUERIES: Record<
const EMPTY_OPEN_THREADS_SUMMARY: AgentChatOpenThreadsSummaryDTO = {
openThreadCount: 0,
+ unreadOpenThreadCount: 0,
needsInputThreadCount: 0,
hasUnreadOpenThread: false,
hasUnreadMentionThread: false,
@@ -493,6 +494,7 @@ export class AgentChatThreadParticipantService {
)
SELECT
COUNT(*)::int AS "openThreadCount",
+ COUNT(*) FILTER (WHERE "isUnread")::int AS "unreadOpenThreadCount",
COUNT("pendingQuestionMessageId")::int AS "needsInputThreadCount",
COALESCE(BOOL_OR("isUnread"), false) AS "hasUnreadOpenThread",
COALESCE(BOOL_OR("isUnread" AND "lastMentionedAt" IS NOT NULL), false) AS "hasUnreadMentionThread",
diff --git a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant.integration-spec.ts
index 5b7575849e2..524a117e340 100644
--- a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant.integration-spec.ts
@@ -90,11 +90,12 @@ type Participant = {
};
const OPEN_THREADS_SUMMARY = parse(
- `query OpenThreadsSummary { agentChatOpenThreadsSummary { openThreadCount needsInputThreadCount hasUnreadOpenThread hasUnreadMentionThread hasUnreadAssignedThread } }`,
+ `query OpenThreadsSummary { agentChatOpenThreadsSummary { openThreadCount unreadOpenThreadCount needsInputThreadCount hasUnreadOpenThread hasUnreadMentionThread hasUnreadAssignedThread } }`,
);
type OpenThreadsSummary = {
openThreadCount: number;
+ unreadOpenThreadCount: number;
needsInputThreadCount: number;
hasUnreadOpenThread: boolean;
hasUnreadMentionThread: boolean;
@@ -1117,6 +1118,7 @@ describe('Chat thread participant state through the authenticated API', () => {
expect(await findOpenThreadsSummary()).toMatchObject({
openThreadCount: before.openThreadCount + 1,
+ unreadOpenThreadCount: before.unreadOpenThreadCount,
needsInputThreadCount: before.needsInputThreadCount + 1,
hasUnreadOpenThread: before.hasUnreadOpenThread,
});
@@ -1127,9 +1129,24 @@ describe('Chat thread participant state through the authenticated API', () => {
expect(await findOpenThreadsSummary()).toMatchObject({
openThreadCount: before.openThreadCount + 1,
+ unreadOpenThreadCount: before.unreadOpenThreadCount + 1,
hasUnreadOpenThread: true,
});
+ await runInboxAction('READ', threadId, {
+ token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ });
+
+ expect(await findOpenThreadsSummary()).toMatchObject({
+ openThreadCount: before.openThreadCount + 1,
+ unreadOpenThreadCount: before.unreadOpenThreadCount,
+ hasUnreadOpenThread: before.hasUnreadOpenThread,
+ });
+
+ await runInboxAction('UNREAD', threadId, {
+ token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ });
+
await runInboxAction('ARCHIVE', threadId, {
token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
});
@@ -1159,6 +1176,7 @@ describe('Chat thread participant state through the authenticated API', () => {
});
it('flags the open chats the member was mentioned in or assigned that are unread', async () => {
+ const initialSummary = await findOpenThreadsSummary();
const mentionedThreadId = await createTestThread();
const assignedThreadId = await createTestThread();
@@ -1168,6 +1186,7 @@ describe('Chat thread participant state through the authenticated API', () => {
await assign(assignedThreadId, WORKSPACE_MEMBER_DATA_SEED_IDS.JONY);
expect(await findOpenThreadsSummary()).toMatchObject({
+ unreadOpenThreadCount: initialSummary.unreadOpenThreadCount + 2,
hasUnreadMentionThread: true,
hasUnreadAssignedThread: true,
});
@@ -1186,14 +1205,19 @@ describe('Chat thread participant state through the authenticated API', () => {
const before = await findOpenThreadsSummary();
+ expect(before.unreadOpenThreadCount).toBe(
+ initialSummary.unreadOpenThreadCount,
+ );
+
// Activity brings back a chat filed under done, but not one the member left
await global.testDataSource.query(
`UPDATE ${SCHEMA}."agentChatThread" SET "lastActivityAt" = clock_timestamp() WHERE id = ANY($1)`,
[[mentionedThreadId, assignedThreadId]],
);
- expect((await findOpenThreadsSummary()).openThreadCount).toBe(
- before.openThreadCount + 1,
- );
+ expect(await findOpenThreadsSummary()).toMatchObject({
+ openThreadCount: before.openThreadCount + 1,
+ unreadOpenThreadCount: before.unreadOpenThreadCount + 1,
+ });
});
});