The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Bring the inbox multi-select closer to the design (#27426)
Félix Malfaitb66f14f6e4fe
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxCommandMenuScope.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxCommandMenuScope.tsxindex 9ddea2d5978..4ee1e00ec9b 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatInboxCommandMenuScope.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxCommandMenuScope.tsx@@ -22,7 +22,9 @@ export const AiChatInboxCommandMenuScope = ({<CommandMenuComponentInstanceContext.Providervalue={{ instanceId: AI_CHAT_INBOX_INSTANCE_ID }}>- <AiChatInboxSelectionToContextStoreEffect />+ <AiChatInboxSelectionToContextStoreEffect+ contextStoreInstanceId={AI_CHAT_INBOX_INSTANCE_ID}+ /><CommandMenuContextProviderdisplayType="dropdownItem"containerType={CommandMenuItemContainerType.IndexPageDropdown}diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxListHeader.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxListHeader.tsxnew file mode 100644index 00000000000..79792ffc775--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxListHeader.tsx@@ -0,0 +1,75 @@+import { useLingui } from '@lingui/react/macro';+import { IconPlus } from 'twenty-ui/icon';+import { Button } from 'twenty-ui/primitives/input';+import { useTheme } from 'twenty-ui/theme';++import { AiChatInboxTriageCommandMenuItems } from '@/ai/components/AiChatInboxTriageCommandMenuItems';+import { AGENT_CHAT_THREAD_FILTER_STATUS_ICONS } from '@/ai/constants/AgentChatThreadFilterStatusIcons';+import { AGENT_CHAT_THREAD_FILTER_STATUS_LABELS } from '@/ai/constants/AgentChatThreadFilterStatusLabels';+import { useSwitchToNewAiChat } from '@/ai/hooks/useSwitchToNewAiChat';+import { agentChatThreadFilterStatusState } from '@/ai/states/agentChatThreadFilterStatusState';+import { CommandMenuContextProvider } from '@/command-menu-item/contexts/CommandMenuContextProvider';+import { PinnedCommandMenuItemButtons } from '@/command-menu-item/display/components/PinnedCommandMenuItemButtons';+import { CommandMenuItemContainerType } from '@/command-menu-item/types/CommandMenuItemContainerType';+import { RecordIndexPageHeaderTitle } from '@/object-record/record-index/components/RecordIndexPageHeaderTitle';+import { SidePanelToggleButton } from '@/side-panel/components/SidePanelToggleButton';+import { PageCardHeader } from '@/ui/layout/page/components/PageCardHeader';+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';++type AiChatInboxListHeaderProps = {+ selectedThreadCount: number;+};++export const AiChatInboxListHeader = ({+ selectedThreadCount,+}: AiChatInboxListHeaderProps) => {+ const { t } = useLingui();+ const theme = useTheme();+ const agentChatThreadFilterStatus = useAtomStateValue(+ agentChatThreadFilterStatusState,+ );+ const FilterStatusIcon =+ AGENT_CHAT_THREAD_FILTER_STATUS_ICONS[agentChatThreadFilterStatus];+ const { switchToNewChat } = useSwitchToNewAiChat({+ shouldOpenInFullPage: true,+ });++ return (+ <PageCardHeader+ icon={<FilterStatusIcon size={theme.icon.size.md} />}+ title={+ <RecordIndexPageHeaderTitle+ label={t(+ AGENT_CHAT_THREAD_FILTER_STATUS_LABELS[agentChatThreadFilterStatus],+ )}+ numberOfSelectedRecords={selectedThreadCount}+ />+ }+ actionButton={+ selectedThreadCount > 0 ? (+ <>+ <CommandMenuContextProvider+ displayType="button"+ containerType={CommandMenuItemContainerType.IndexPageHeader}+ >+ <AiChatInboxTriageCommandMenuItems>+ <PinnedCommandMenuItemButtons />+ </AiChatInboxTriageCommandMenuItems>+ </CommandMenuContextProvider>+ <SidePanelToggleButton />+ </>+ ) : (+ <Button+ size="sm"+ variant="solid"+ color="accent"+ startIcon={<IconPlus />}+ onClick={switchToNewChat}+ >+ {t`New chat`}+ </Button>+ )+ }+ />+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionPane.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionPane.tsxindex 589cfc1eaec..adba587e3ee 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionPane.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionPane.tsx@@ -1,26 +1,44 @@import { plural } from '@lingui/core/macro';import { useLingui } from '@lingui/react/macro';+import { styled } from '@linaria/react';import { Key } from 'ts-key-enum';-import { IconX } from 'twenty-ui/icon';import { Button } from 'twenty-ui/primitives/input';+import { themeCssVariables } from 'twenty-ui/theme';-import { CommandMenuContextProvider } from '@/command-menu-item/contexts/CommandMenuContextProvider';-import { PinnedCommandMenuItemButtons } from '@/command-menu-item/display/components/PinnedCommandMenuItemButtons';-import { CommandMenuItemContainerType } from '@/command-menu-item/types/CommandMenuItemContainerType';+import { AiChatInboxSelectionPile } from '@/ai/components/AiChatInboxSelectionPile';+import { AiChatInboxSelectionToContextStoreEffect } from '@/ai/components/AiChatInboxSelectionToContextStoreEffect';+import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';+import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';import { useResetRecordSelection } from '@/object-record/record-selection/hooks/useResetRecordSelection';-import { selectedRecordIdsComponentSelector } from '@/object-record/record-selection/states/selectors/selectedRecordIdsComponentSelector';+import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';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';-export const AiChatInboxSelectionPane = () => {+const StyledSelection = styled(EmptyState.Root)`+ box-sizing: border-box;+ gap: ${themeCssVariables.spacing[8]};+ padding: ${themeCssVariables.spacing[10]} ${themeCssVariables.spacing[4]};+`;++const StyledButtons = styled.div`+ display: flex;+ flex-wrap: wrap;+ gap: ${themeCssVariables.spacing[2]};+ justify-content: center;+`;++type AiChatInboxSelectionPaneProps = {+ selectedThreads: AgentChatThreadRecord[];+};++export const AiChatInboxSelectionPane = ({+ selectedThreads,+}: AiChatInboxSelectionPaneProps) => {const { t } = useLingui();- const selectedRecordIds = useAtomComponentSelectorValue(- selectedRecordIdsComponentSelector,- );const { resetRecordSelection } = useResetRecordSelection();+ const { openSidePanelMenu } = useSidePanelMenu();useGlobalHotkeys({keys: [Key.Escape],@@ -33,34 +51,47 @@ export const AiChatInboxSelectionPane = () => {<PageCardLayoutheader={<PageCardHeader- actionButton={- <CommandMenuContextProvider- displayType="button"- containerType={CommandMenuItemContainerType.ShowPageHeader}- >- <PinnedCommandMenuItemButtons />- </CommandMenuContextProvider>- }+ title={plural(selectedThreads.length, {+ one: '# chat',+ other: '# chats',+ })}/>}>- <EmptyState.Root>+ {/* The selection takes the place of the chat on screen, so the command+ menu acts on it */}+ <AiChatInboxSelectionToContextStoreEffect+ contextStoreInstanceId={MAIN_CONTEXT_STORE_INSTANCE_ID}+ />+ <StyledSelection>+ <AiChatInboxSelectionPile threads={selectedThreads} /><EmptyState.Content><EmptyState.Title>- {plural(selectedRecordIds.length, {+ {plural(selectedThreads.length, {one: '# chat selected',other: '# chats selected',})}</EmptyState.Title>+ <StyledButtons>+ <Button+ size="sm"+ variant="outline"+ shortcut={['Esc']}+ onClick={resetRecordSelection}+ >+ {t`Clear selection`}+ </Button>+ <Button+ size="sm"+ variant="outline"+ shortcut={['Mod', 'K']}+ onClick={openSidePanelMenu}+ >+ {t`All actions`}+ </Button>+ </StyledButtons></EmptyState.Content>- <Button- variant="outline"- startIcon={<IconX />}- onClick={resetRecordSelection}- >- {t`Clear selection`}- </Button>- </EmptyState.Root>+ </StyledSelection></PageCardLayout>);};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionPile.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionPile.tsxnew file mode 100644index 00000000000..d78bee9f184--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionPile.tsx@@ -0,0 +1,86 @@+import { styled } from '@linaria/react';+import { themeCssVariables } from 'twenty-ui/theme';++import { AiChatThreadActivityTime } from '@/ai/components/AiChatThreadActivityTime';+import { AiChatThreadAvatar } from '@/ai/components/AiChatThreadAvatar';+import { AiChatThreadSubtitle } from '@/ai/components/AiChatThreadSubtitle';+import { AiChatThreadTitle } from '@/ai/components/AiChatThreadTitle';+import { AI_CHAT_INBOX_SELECTION_PILE_MAX_CARDS } from '@/ai/constants/AiChatInboxSelectionPileMaxCards';+import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';++const StyledPile = styled.div`+ display: flex;+ flex-direction: column;+ max-width: 480px;+ width: 100%;+`;++// Each card sits a step lower and wider than the one behind it, leaving the+// title of the cards behind in view+const StyledCard = styled.div<{ $depth: number }>`+ align-items: flex-start;+ background: ${themeCssVariables.background.primary};+ border: 1px solid ${themeCssVariables.border.color.light};+ border-radius: ${themeCssVariables.border.radius.md};+ box-shadow: ${themeCssVariables.boxShadow.light};+ display: flex;+ gap: ${themeCssVariables.spacing[3]};+ margin: 0 calc(${themeCssVariables.spacing[3]} * ${({ $depth }) => $depth});+ padding: ${themeCssVariables.spacing[4]};+ text-align: left;++ & + & {+ margin-top: calc(-1 * ${themeCssVariables.spacing[8]});+ }+`;++const StyledLeading = styled.div`+ display: flex;+ flex-shrink: 0;+ justify-content: center;+ padding-top: ${themeCssVariables.spacing['0.5']};+ width: ${themeCssVariables.spacing[7]};+`;++const StyledContent = styled.div`+ display: flex;+ flex: 1;+ flex-direction: column;+ min-width: 0;+`;++const StyledHeading = styled.div`+ align-items: center;+ display: flex;+ gap: ${themeCssVariables.spacing[2]};+ min-width: 0;+`;++type AiChatInboxSelectionPileProps = {+ threads: AgentChatThreadRecord[];+};++export const AiChatInboxSelectionPile = ({+ threads,+}: AiChatInboxSelectionPileProps) => {+ const pileThreads = threads.slice(0, AI_CHAT_INBOX_SELECTION_PILE_MAX_CARDS);++ return (+ <StyledPile aria-hidden>+ {pileThreads.map((thread, index) => (+ <StyledCard key={thread.id} $depth={pileThreads.length - 1 - index}>+ <StyledLeading>+ <AiChatThreadAvatar thread={thread} />+ </StyledLeading>+ <StyledContent>+ <StyledHeading>+ <AiChatThreadTitle thread={thread} />+ <AiChatThreadActivityTime thread={thread} />+ </StyledHeading>+ <AiChatThreadSubtitle thread={thread} />+ </StyledContent>+ </StyledCard>+ ))}+ </StyledPile>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionToContextStoreEffect.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionToContextStoreEffect.tsxindex 6ea3eb18e8a..5882012dcde 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionToContextStoreEffect.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxSelectionToContextStoreEffect.tsx@@ -1,11 +1,16 @@import { useEffect } from 'react';-import { AI_CHAT_INBOX_INSTANCE_ID } from '@/ai/constants/AiChatInboxInstanceId';import { useTargetAiChatThreadsInContextStore } from '@/ai/hooks/useTargetAiChatThreadsInContextStore';import { selectedRecordIdsComponentSelector } from '@/object-record/record-selection/states/selectors/selectedRecordIdsComponentSelector';import { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue';-export const AiChatInboxSelectionToContextStoreEffect = () => {+type AiChatInboxSelectionToContextStoreEffectProps = {+ contextStoreInstanceId: string;+};++export const AiChatInboxSelectionToContextStoreEffect = ({+ contextStoreInstanceId,+}: AiChatInboxSelectionToContextStoreEffectProps) => {const selectedRecordIds = useAtomComponentSelectorValue(selectedRecordIdsComponentSelector,);@@ -14,17 +19,21 @@ export const AiChatInboxSelectionToContextStoreEffect = () => {useEffect(() => {targetAiChatThreadsInContextStore({- contextStoreInstanceId: AI_CHAT_INBOX_INSTANCE_ID,+ contextStoreInstanceId,threadIds: selectedRecordIds,});return () => {targetAiChatThreadsInContextStore({- contextStoreInstanceId: AI_CHAT_INBOX_INSTANCE_ID,+ contextStoreInstanceId,threadIds: [],});};- }, [selectedRecordIds, targetAiChatThreadsInContextStore]);+ }, [+ contextStoreInstanceId,+ selectedRecordIds,+ targetAiChatThreadsInContextStore,+ ]);return null;};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxThreadList.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxThreadList.tsxindex ab55eced265..ef1de064042 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatInboxThreadList.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxThreadList.tsx@@ -7,16 +7,23 @@ import { useOpenRecordContextMenu } from '@/object-record/record-selection/hookstype AiChatInboxThreadListProps = {threads: AgentChatThreadRecord[];selectedThreadIds: string[];+ checkedThreadIds: string[];onThreadClick: (thread: AgentChatThreadRecord,event: MouseEvent<HTMLDivElement>,) => void;+ onThreadCheckboxClick?: (+ thread: AgentChatThreadRecord,+ event: MouseEvent<HTMLDivElement>,+ ) => void;};export const AiChatInboxThreadList = ({threads,selectedThreadIds,+ checkedThreadIds,onThreadClick,+ onThreadCheckboxClick,}: AiChatInboxThreadListProps) => {const { openRecordContextMenu } = useOpenRecordContextMenu();@@ -24,7 +31,9 @@ export const AiChatInboxThreadList = ({<AiChatThreadListthreads={threads}selectedThreadIds={selectedThreadIds}+ checkedThreadIds={checkedThreadIds}onThreadClick={onThreadClick}+ onThreadCheckboxClick={onThreadCheckboxClick}onThreadContextMenu={(thread, event) =>openRecordContextMenu({ event, recordId: thread.id })}diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxTriageCommandMenuItems.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxTriageCommandMenuItems.tsxnew file mode 100644index 00000000000..fb0c983952b--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxTriageCommandMenuItems.tsx@@ -0,0 +1,30 @@+import { type ReactNode, useContext } from 'react';++import { AI_CHAT_INBOX_TRIAGE_ENGINE_COMPONENT_KEYS } from '@/ai/constants/AiChatInboxTriageEngineComponentKeys';+import { CommandMenuContext } from '@/command-menu-item/contexts/CommandMenuContext';++type AiChatInboxTriageCommandMenuItemsProps = {+ children: ReactNode;+};++// The list header only has room for triage; every other command stays in the+// command menu+export const AiChatInboxTriageCommandMenuItems = ({+ children,+}: AiChatInboxTriageCommandMenuItemsProps) => {+ const commandMenuContext = useContext(CommandMenuContext);++ return (+ <CommandMenuContext.Provider+ value={{+ ...commandMenuContext,+ commandMenuItems: commandMenuContext.commandMenuItems.filter(+ ({ engineComponentKey }) =>+ AI_CHAT_INBOX_TRIAGE_ENGINE_COMPONENT_KEYS.has(engineComponentKey),+ ),+ }}+ >+ {children}+ </CommandMenuContext.Provider>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadActivityTime.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadActivityTime.tsxnew file mode 100644index 00000000000..ee6d5506a84--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadActivityTime.tsx@@ -0,0 +1,54 @@+import { styled } from '@linaria/react';+import { useLingui } from '@lingui/react/macro';+import { themeCssVariables } from 'twenty-ui/theme';++import { useFormatAgentChatThreadDate } from '@/ai/hooks/useFormatAgentChatThreadDate';+import { agentChatThreadInboxStatusFamilySelector } from '@/ai/states/selectors/agentChatThreadInboxStatusFamilySelector';+import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';+import { getAgentChatThreadLastActivityAt } from '@/ai/utils/getAgentChatThreadLastActivityAt';+import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';+import { beautifyPastDateRelativeToNowShort } from '~/utils/date-utils';++const StyledActivityTime = styled.div`+ color: ${themeCssVariables.font.color.tertiary};+ flex-shrink: 0;+ font-size: ${themeCssVariables.font.size.sm};+`;++type AiChatThreadActivityTimeProps = {+ thread: AgentChatThreadRecord;+};++export const AiChatThreadActivityTime = ({+ thread,+}: AiChatThreadActivityTimeProps) => {+ const { t } = useLingui();+ const { event } = useAtomFamilySelectorValue(+ agentChatThreadInboxStatusFamilySelector,+ thread.id,+ );+ const { formatAgentChatThreadDay } = useFormatAgentChatThreadDate();++ const getActivityTimeLabel = () => {+ switch (event?.type) {+ case 'SNOOZED': {+ const snoozedUntilDay = formatAgentChatThreadDay(new Date(event.at));++ return t`Until ${snoozedUntilDay}`;+ }+ case 'SNOOZE_ENDED':+ return t`Snooze ended`;+ case 'DONE': {+ const doneTime = beautifyPastDateRelativeToNowShort(event.at);++ return t`Done ${doneTime}`;+ }+ default:+ return beautifyPastDateRelativeToNowShort(+ getAgentChatThreadLastActivityAt(thread),+ );+ }+ };++ return <StyledActivityTime>{getActivityTimeLabel()}</StyledActivityTime>;+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadAvatar.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadAvatar.tsxnew file mode 100644index 00000000000..a7dfc56a651--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadAvatar.tsx@@ -0,0 +1,22 @@+import { useLingui } from '@lingui/react/macro';++import { useAgentChatThreadMembers } from '@/ai/hooks/useAgentChatThreadMembers';+import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';+import { WorkspaceMemberAvatarStack } from '@/workspace-member/components/WorkspaceMemberAvatarStack';++type AiChatThreadAvatarProps = {+ thread: AgentChatThreadRecord;+};++export const AiChatThreadAvatar = ({ thread }: AiChatThreadAvatarProps) => {+ const { t } = useLingui();+ const threadMembers = useAgentChatThreadMembers(thread);++ return (+ <WorkspaceMemberAvatarStack+ workspaceMembers={threadMembers}+ defaultAvatarName={t`Member`}+ maxVisible={2}+ />+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadList.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadList.tsxindex eac99bd2589..04b5762a478 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadList.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadList.tsx@@ -11,17 +11,22 @@ const StyledGroupTitle = styled.div`color: ${themeCssVariables.font.color.light};font-size: ${themeCssVariables.font.size.xs};font-weight: ${themeCssVariables.font.weight.semiBold};- padding: ${themeCssVariables.spacing[2]} ${themeCssVariables.spacing[1]}+ padding: ${themeCssVariables.spacing[3]} ${themeCssVariables.spacing[4]}${themeCssVariables.spacing[1]};`;type AiChatThreadListProps = {threads: AgentChatThreadRecord[];selectedThreadIds?: string[];+ checkedThreadIds?: string[];onThreadClick: (thread: AgentChatThreadRecord,event: MouseEvent<HTMLDivElement>,) => void;+ onThreadCheckboxClick?: (+ thread: AgentChatThreadRecord,+ event: MouseEvent<HTMLDivElement>,+ ) => void;onThreadContextMenu?: (thread: AgentChatThreadRecord,event: MouseEvent<HTMLDivElement>,@@ -32,18 +37,23 @@ type AiChatThreadListProps = {export const AiChatThreadList = ({threads,selectedThreadIds = [],+ checkedThreadIds = [],onThreadClick,+ onThreadCheckboxClick,onThreadContextMenu,onDetachThread,}: AiChatThreadListProps) => {const selectedThreadIdSet = new Set(selectedThreadIds);+ const checkedThreadIdSet = new Set(checkedThreadIds);const renderThread = (thread: AgentChatThreadRecord) => (<AiChatThreadListItemkey={thread.id}thread={thread}isSelected={selectedThreadIdSet.has(thread.id)}+ isChecked={checkedThreadIdSet.has(thread.id)}onClick={onThreadClick}+ onCheckboxClick={onThreadCheckboxClick}onContextMenu={onThreadContextMenu}onDetach={isDefined(onDetachThread) ? () => onDetachThread(thread.id) : undefineddiff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsxindex 1026585f021..678c23df782 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx@@ -2,119 +2,95 @@ import { styled } from '@linaria/react';import { type MouseEvent, useId } from 'react';import { useLingui } from '@lingui/react/macro';import { Key } from 'ts-key-enum';-import { isDefined, isNonEmptyString } from 'twenty-shared/utils';-import { IconHandClick } from 'twenty-ui/icon';-import { themeCssVariables, useTheme } from 'twenty-ui/theme';+import { isDefined } from 'twenty-shared/utils';+import { Checkbox } from 'twenty-ui/primitives/input';+import { themeCssVariables } from 'twenty-ui/theme';import { AiChatThreadActionsDropdown } from '@/ai/components/AiChatThreadActionsDropdown';+import { AiChatThreadActivityTime } from '@/ai/components/AiChatThreadActivityTime';+import { AiChatThreadAvatar } from '@/ai/components/AiChatThreadAvatar';+import { AiChatThreadSubtitle } from '@/ai/components/AiChatThreadSubtitle';+import { AiChatThreadTitle } from '@/ai/components/AiChatThreadTitle';import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';-import { useAgentChatThreadMembers } from '@/ai/hooks/useAgentChatThreadMembers';import { useAiChatThreadRename } from '@/ai/hooks/useAiChatThreadRename';-import { agentChatThreadInboxStatusFamilySelector } from '@/ai/states/selectors/agentChatThreadInboxStatusFamilySelector';-import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';import { getCommandMenuDropdownIdFromCommandMenuId } from '@/command-menu-item/utils/getCommandMenuDropdownIdFromCommandMenuId';import { TextInput } from '@/ui/input/components/TextInput';import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';-import { VisibilityHidden } from 'twenty-ui/primitives/accessibility';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';-import { useFormatAgentChatThreadDate } from '@/ai/hooks/useFormatAgentChatThreadDate';-import { beautifyPastDateRelativeToNowShort } from '~/utils/date-utils';-import { getAgentChatThreadLastActivityAt } from '@/ai/utils/getAgentChatThreadLastActivityAt';-import { getAgentChatThreadPreviewText } from '@/ai/utils/getAgentChatThreadPreviewText';-import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';-import { currentWorkspaceMembersState } from '@/auth/states/currentWorkspaceMembersState';-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';-import { WorkspaceMemberAvatarStack } from '@/workspace-member/components/WorkspaceMemberAvatarStack';-const StyledThreadItem = styled.div<{ $isSelected: boolean }>`+const StyledThreadItem = styled.div<{+ $isSelected: boolean;+ $isChecked: boolean;+}>`align-items: flex-start;- background: ${({ $isSelected }) =>- $isSelected ? themeCssVariables.background.transparent.light : 'none'};- border-radius: ${themeCssVariables.border.radius.sm};+ background: ${({ $isSelected, $isChecked }) =>+ $isChecked+ ? themeCssVariables.accent.tertiary+ : $isSelected+ ? themeCssVariables.background.transparent.light+ : 'none'};+ border-bottom: 1px solid ${themeCssVariables.border.color.light};cursor: pointer;display: flex;- gap: ${themeCssVariables.spacing[2]};- padding: ${themeCssVariables.spacing[2]};+ gap: ${themeCssVariables.spacing[3]};+ padding: ${themeCssVariables.spacing[4]};position: relative;&:hover {- background: ${themeCssVariables.background.transparent.light};+ background: ${({ $isChecked }) =>+ $isChecked+ ? themeCssVariables.accent.tertiary+ : themeCssVariables.background.transparent.light};}`;const StyledLeading = styled.div`display: flex;flex-shrink: 0;+ justify-content: center;padding-top: ${themeCssVariables.spacing['0.5']};- width: ${themeCssVariables.spacing[10]};+ width: ${themeCssVariables.spacing[7]};`;-const StyledThreadContent = styled.div`- display: flex;- flex: 1;- flex-direction: column;- gap: ${themeCssVariables.spacing['0.5']};- min-width: 0;-`;+// The checkbox takes the avatar's place while the chat is checked, or while+// the row is hovered or focused, so a click on it starts a selection+const StyledCheckboxContainer = styled.div<{ $isChecked: boolean }>`+ display: ${({ $isChecked }) => ($isChecked ? 'flex' : 'none')};-const StyledThreadHeading = styled.div`- align-items: center;- display: flex;- gap: ${themeCssVariables.spacing[2]};- min-height: ${themeCssVariables.spacing[5]};- min-width: 0;+ ${StyledThreadItem}:hover &,+ ${StyledThreadItem}:focus-within & {+ display: flex;+ }`;-const StyledThreadTitle = styled.div<{ $isUnread: boolean }>`- color: ${({ $isUnread }) =>- $isUnread- ? themeCssVariables.font.color.primary- : themeCssVariables.font.color.secondary};- flex: 1;- font-size: ${themeCssVariables.font.size.md};- font-weight: ${({ $isUnread }) =>- $isUnread- ? themeCssVariables.font.weight.semiBold- : themeCssVariables.font.weight.medium};- min-width: 0;- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;+const StyledAvatarContainer = styled.div<{+ $isCheckable: boolean;+ $isChecked: boolean;+}>`+ display: ${({ $isChecked }) => ($isChecked ? 'none' : 'flex')};++ ${StyledThreadItem}:hover &,+ ${StyledThreadItem}:focus-within & {+ display: ${({ $isCheckable, $isChecked }) =>+ $isCheckable || $isChecked ? 'none' : 'flex'};+ }`;-const StyledThreadSubtitle = styled.div`- align-items: center;- color: ${themeCssVariables.font.color.tertiary};+const StyledThreadContent = styled.div`display: flex;- font-size: ${themeCssVariables.font.size.sm};- gap: ${themeCssVariables.spacing[1]};- min-height: ${themeCssVariables.spacing[4]};+ flex: 1;+ flex-direction: column;min-width: 0;`;-const StyledNeedsInput = styled.div<{ $isUnread: boolean }>`+const StyledThreadHeading = styled.div`align-items: center;- color: ${({ $isUnread }) =>- $isUnread- ? themeCssVariables.color.blue- : themeCssVariables.font.color.tertiary};display: flex;- flex-shrink: 0;- font-weight: ${themeCssVariables.font.weight.medium};- gap: ${themeCssVariables.spacing[1]};-`;--const StyledThreadPreview = styled.div`+ gap: ${themeCssVariables.spacing[2]};min-width: 0;- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;`;-const StyledActivityTime = styled.div<{ $isDropdownOpen: boolean }>`- color: ${themeCssVariables.font.color.tertiary};- flex-shrink: 0;- font-size: ${themeCssVariables.font.size.sm};+const StyledActivityTimeContainer = styled.div<{ $isDropdownOpen: boolean }>`visibility: ${({ $isDropdownOpen }) =>$isDropdownOpen ? 'hidden' : 'visible'};@@ -128,8 +104,8 @@ const StyledMenuTrigger = styled.div<{ $isDropdownOpen: boolean }>`pointer-events: ${({ $isDropdownOpen }) =>$isDropdownOpen ? 'auto' : 'none'};position: absolute;- right: ${themeCssVariables.spacing[1]};- top: ${themeCssVariables.spacing[1]};+ right: ${themeCssVariables.spacing[3]};+ top: ${themeCssVariables.spacing[3]};transition: opacity 150ms;${StyledThreadItem}:hover & {@@ -141,10 +117,15 @@ const StyledMenuTrigger = styled.div<{ $isDropdownOpen: boolean }>`type AiChatThreadListItemProps = {thread: AgentChatThreadRecord;isSelected: boolean;+ isChecked?: boolean;onClick: (thread: AgentChatThreadRecord,event: MouseEvent<HTMLDivElement>,) => void;+ onCheckboxClick?: (+ thread: AgentChatThreadRecord,+ event: MouseEvent<HTMLDivElement>,+ ) => void;onContextMenu?: (thread: AgentChatThreadRecord,event: MouseEvent<HTMLDivElement>,@@ -155,12 +136,13 @@ type AiChatThreadListItemProps = {export const AiChatThreadListItem = ({thread,isSelected,+ isChecked = false,onClick,+ onCheckboxClick,onContextMenu,onDetach,}: AiChatThreadListItemProps) => {const { t } = useLingui();- const theme = useTheme();const {isRenaming,draftTitle,@@ -170,48 +152,6 @@ export const AiChatThreadListItem = ({commitRename,} = useAiChatThreadRename(thread);- const { isUnread, event } = useAtomFamilySelectorValue(- agentChatThreadInboxStatusFamilySelector,- thread.id,- );- const currentWorkspaceMember = useAtomStateValue(currentWorkspaceMemberState);- const currentWorkspaceMembers = useAtomStateValue(- currentWorkspaceMembersState,- );- const threadMembers = useAgentChatThreadMembers(thread);- const isShownAsUnread = !isDefined(thread.deletedAt) && isUnread;- const isAwaitingAnswer =- !isDefined(thread.deletedAt) && isDefined(thread.pendingQuestionMessageId);- const previewText = getAgentChatThreadPreviewText({- thread,- workspaceMembers: currentWorkspaceMembers,- currentWorkspaceMemberId: currentWorkspaceMember?.id,- });- const displayTitle = isNonEmptyString(thread.title)- ? thread.title- : t`Untitled`;- const { formatAgentChatThreadDay } = useFormatAgentChatThreadDate();-- const getActivityTimeLabel = () => {- switch (event?.type) {- case 'SNOOZED': {- const snoozedUntilDay = formatAgentChatThreadDay(new Date(event.at));-- return t`Until ${snoozedUntilDay}`;- }- case 'SNOOZE_ENDED':- return t`Snooze ended`;- case 'DONE': {- const doneTime = beautifyPastDateRelativeToNowShort(event.at);-- return t`Done ${doneTime}`;- }- default:- return beautifyPastDateRelativeToNowShort(- getAgentChatThreadLastActivityAt(thread),- );- }- };const actionsInstanceId = useId();const itemMenuDropdownId =getCommandMenuDropdownIdFromCommandMenuId(actionsInstanceId);@@ -219,9 +159,11 @@ export const AiChatThreadListItem = ({isDropdownOpenComponentState,itemMenuDropdownId,);+return (<StyledThreadItem$isSelected={isSelected}+ $isChecked={isChecked}data-selectable-id={thread.id}data-select-disable={isRenaming || undefined}onMouseDown={(event) => {@@ -242,11 +184,24 @@ export const AiChatThreadListItem = ({}}><StyledLeading>- <WorkspaceMemberAvatarStack- workspaceMembers={threadMembers}- defaultAvatarName={t`Member`}- maxVisible={2}- />+ {isDefined(onCheckboxClick) && (+ <StyledCheckboxContainer+ $isChecked={isChecked}+ data-select-disable+ onClick={(event) => {+ event.stopPropagation();+ onCheckboxClick(thread, event);+ }}+ >+ <Checkbox checked={isChecked} aria-label={t`Select chat`} />+ </StyledCheckboxContainer>+ )}+ <StyledAvatarContainer+ $isCheckable={isDefined(onCheckboxClick)}+ $isChecked={isChecked}+ >+ <AiChatThreadAvatar thread={thread} />+ </StyledAvatarContainer></StyledLeading><StyledThreadContent>{isRenaming ? (@@ -275,29 +230,13 @@ export const AiChatThreadListItem = ({/>) : (<StyledThreadHeading>- <StyledThreadTitle $isUnread={isShownAsUnread}>- {displayTitle}- {isShownAsUnread && (- <VisibilityHidden>{t`, unread`}</VisibilityHidden>- )}- </StyledThreadTitle>- <StyledActivityTime $isDropdownOpen={isDropdownOpen}>- {getActivityTimeLabel()}- </StyledActivityTime>+ <AiChatThreadTitle thread={thread} />+ <StyledActivityTimeContainer $isDropdownOpen={isDropdownOpen}>+ <AiChatThreadActivityTime thread={thread} />+ </StyledActivityTimeContainer></StyledThreadHeading>)}- <StyledThreadSubtitle>- {isAwaitingAnswer && (- <StyledNeedsInput $isUnread={isShownAsUnread}>- <IconHandClick size={theme.icon.size.sm} />- {t`Needs input`}- </StyledNeedsInput>- )}- {isAwaitingAnswer && isNonEmptyString(previewText) && (- <span aria-hidden>·</span>- )}- <StyledThreadPreview>{previewText}</StyledThreadPreview>- </StyledThreadSubtitle>+ <AiChatThreadSubtitle thread={thread} /></StyledThreadContent><StyledMenuTrigger$isDropdownOpen={isDropdownOpen}diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadSubtitle.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadSubtitle.tsxnew file mode 100644index 00000000000..d5e892bc857--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadSubtitle.tsx@@ -0,0 +1,77 @@+import { styled } from '@linaria/react';+import { useLingui } from '@lingui/react/macro';+import { isDefined, isNonEmptyString } from 'twenty-shared/utils';+import { IconHandClick } from 'twenty-ui/icon';+import { themeCssVariables, useTheme } from 'twenty-ui/theme';++import { useIsAgentChatThreadShownAsUnread } from '@/ai/hooks/useIsAgentChatThreadShownAsUnread';+import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';+import { getAgentChatThreadPreviewText } from '@/ai/utils/getAgentChatThreadPreviewText';+import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';+import { currentWorkspaceMembersState } from '@/auth/states/currentWorkspaceMembersState';+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';++const StyledSubtitle = styled.div`+ align-items: center;+ color: ${themeCssVariables.font.color.tertiary};+ display: flex;+ font-size: ${themeCssVariables.font.size.sm};+ gap: ${themeCssVariables.spacing[1]};+ min-height: ${themeCssVariables.spacing[4]};+ min-width: 0;+`;++const StyledNeedsInput = styled.div<{ $isUnread: boolean }>`+ align-items: center;+ color: ${({ $isUnread }) =>+ $isUnread+ ? themeCssVariables.color.blue+ : themeCssVariables.font.color.tertiary};+ display: flex;+ flex-shrink: 0;+ font-weight: ${themeCssVariables.font.weight.medium};+ gap: ${themeCssVariables.spacing[1]};+`;++const StyledPreview = styled.div`+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+`;++type AiChatThreadSubtitleProps = {+ thread: AgentChatThreadRecord;+};++export const AiChatThreadSubtitle = ({ thread }: AiChatThreadSubtitleProps) => {+ const { t } = useLingui();+ const theme = useTheme();+ const isUnread = useIsAgentChatThreadShownAsUnread(thread);+ const currentWorkspaceMember = useAtomStateValue(currentWorkspaceMemberState);+ const currentWorkspaceMembers = useAtomStateValue(+ currentWorkspaceMembersState,+ );+ const isAwaitingAnswer =+ !isDefined(thread.deletedAt) && isDefined(thread.pendingQuestionMessageId);+ const previewText = getAgentChatThreadPreviewText({+ thread,+ workspaceMembers: currentWorkspaceMembers,+ currentWorkspaceMemberId: currentWorkspaceMember?.id,+ });++ return (+ <StyledSubtitle>+ {isAwaitingAnswer && (+ <StyledNeedsInput $isUnread={isUnread}>+ <IconHandClick size={theme.icon.size.sm} />+ {t`Needs input`}+ </StyledNeedsInput>+ )}+ {isAwaitingAnswer && isNonEmptyString(previewText) && (+ <span aria-hidden>·</span>+ )}+ <StyledPreview>{previewText}</StyledPreview>+ </StyledSubtitle>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadTitle.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadTitle.tsxnew file mode 100644index 00000000000..c04914854cd--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadTitle.tsx@@ -0,0 +1,41 @@+import { styled } from '@linaria/react';+import { useLingui } from '@lingui/react/macro';+import { isNonEmptyString } from 'twenty-shared/utils';+import { VisibilityHidden } from 'twenty-ui/primitives/accessibility';+import { themeCssVariables } from 'twenty-ui/theme';++import { useIsAgentChatThreadShownAsUnread } from '@/ai/hooks/useIsAgentChatThreadShownAsUnread';+import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';++const StyledTitle = styled.div<{ $isUnread: boolean }>`+ color: ${({ $isUnread }) =>+ $isUnread+ ? themeCssVariables.font.color.primary+ : themeCssVariables.font.color.secondary};+ flex: 1;+ font-size: ${themeCssVariables.font.size.md};+ font-weight: ${({ $isUnread }) =>+ $isUnread+ ? themeCssVariables.font.weight.semiBold+ : themeCssVariables.font.weight.medium};+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+`;++type AiChatThreadTitleProps = {+ thread: AgentChatThreadRecord;+};++export const AiChatThreadTitle = ({ thread }: AiChatThreadTitleProps) => {+ const { t } = useLingui();+ const isUnread = useIsAgentChatThreadShownAsUnread(thread);++ return (+ <StyledTitle $isUnread={isUnread}>+ {isNonEmptyString(thread.title) ? thread.title : t`Untitled`}+ {isUnread && <VisibilityHidden>{t`, unread`}</VisibilityHidden>}+ </StyledTitle>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadListItem.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadListItem.test.tsxindex 3b0c5284ee8..138cf0341c0 100644--- a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadListItem.test.tsx+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadListItem.test.tsx@@ -1,6 +1,8 @@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 { type ComponentProps } from 'react';import { Provider as JotaiProvider } from 'jotai';import { SOURCE_LOCALE } from 'twenty-shared/translations';@@ -43,20 +45,38 @@ const buildThread = (...thread,});-const renderListItem = (thread: AgentChatThreadRecord) =>+const renderListItem = (+ thread: AgentChatThreadRecord,+ {+ isChecked = false,+ onClick = jest.fn(),+ onCheckboxClick,+ }: Pick<+ ComponentProps<typeof AiChatThreadListItem>,+ 'isChecked' | 'onCheckboxClick'+ > &+ Partial<Pick<ComponentProps<typeof AiChatThreadListItem>, 'onClick'>> = {},+) =>render(<JotaiProvider store={jotaiStore}><I18nProvider i18n={i18n}><AiChatThreadListItemthread={thread}isSelected={false}- onClick={jest.fn()}+ isChecked={isChecked}+ onClick={onClick}+ onCheckboxClick={onCheckboxClick}/></I18nProvider></JotaiProvider>,);describe('AiChatThreadListItem', () => {+ beforeAll(() => {+ // jsdom has no PointerEvent, which the checkbox dispatches on click+ window.PointerEvent ??= MouseEvent as typeof PointerEvent;+ });+beforeEach(() => {resetJotaiStore();});@@ -89,4 +109,37 @@ describe('AiChatThreadListItem', () => {expect(screen.queryByText('Needs input')).not.toBeInTheDocument();});++ it('has no checkbox where chats cannot be selected', () => {+ renderListItem(buildThread({}));++ expect(+ screen.queryByRole('checkbox', { name: 'Select chat' }),+ ).not.toBeInTheDocument();+ });++ it('checks the chat from its checkbox without opening it', async () => {+ const onClick = jest.fn();+ const onCheckboxClick = jest.fn();+ const thread = buildThread({});++ renderListItem(thread, { onClick, onCheckboxClick });++ await userEvent.click(+ screen.getByRole('checkbox', { name: 'Select chat' }),+ );++ expect(onCheckboxClick).toHaveBeenCalledTimes(1);+ expect(onCheckboxClick).toHaveBeenCalledWith(thread, expect.anything());+ expect(onClick).not.toHaveBeenCalled();+ });++ it('shows a checked chat as checked', () => {+ renderListItem(buildThread({}), {+ isChecked: true,+ onCheckboxClick: jest.fn(),+ });++ expect(screen.getByRole('checkbox', { name: 'Select chat' })).toBeChecked();+ });});diff --git a/packages/twenty-front/src/modules/ai/constants/AiChatInboxSelectionPileMaxCards.ts b/packages/twenty-front/src/modules/ai/constants/AiChatInboxSelectionPileMaxCards.tsnew file mode 100644index 00000000000..d45157bd7d5--- /dev/null+++ b/packages/twenty-front/src/modules/ai/constants/AiChatInboxSelectionPileMaxCards.ts@@ -0,0 +1 @@+export const AI_CHAT_INBOX_SELECTION_PILE_MAX_CARDS = 3;diff --git a/packages/twenty-front/src/modules/ai/constants/AiChatInboxTriageEngineComponentKeys.ts b/packages/twenty-front/src/modules/ai/constants/AiChatInboxTriageEngineComponentKeys.tsnew file mode 100644index 00000000000..944c7988af3--- /dev/null+++ b/packages/twenty-front/src/modules/ai/constants/AiChatInboxTriageEngineComponentKeys.ts@@ -0,0 +1,8 @@+import { EngineComponentKey } from '~/generated-metadata/graphql';++export const AI_CHAT_INBOX_TRIAGE_ENGINE_COMPONENT_KEYS =+ new Set<EngineComponentKey>([+ EngineComponentKey.SNOOZE_AI_CHAT,+ EngineComponentKey.MARK_AI_CHAT_AS_DONE,+ EngineComponentKey.REOPEN_AI_CHAT,+ ]);diff --git a/packages/twenty-front/src/modules/ai/hooks/useIsAgentChatThreadShownAsUnread.ts b/packages/twenty-front/src/modules/ai/hooks/useIsAgentChatThreadShownAsUnread.tsnew file mode 100644index 00000000000..14488c5ded2--- /dev/null+++ b/packages/twenty-front/src/modules/ai/hooks/useIsAgentChatThreadShownAsUnread.ts@@ -0,0 +1,16 @@+import { isDefined } from 'twenty-shared/utils';++import { agentChatThreadInboxStatusFamilySelector } from '@/ai/states/selectors/agentChatThreadInboxStatusFamilySelector';+import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';+import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';++export const useIsAgentChatThreadShownAsUnread = (+ thread: Pick<AgentChatThreadRecord, 'id' | 'deletedAt'>,+) => {+ const { isUnread } = useAtomFamilySelectorValue(+ agentChatThreadInboxStatusFamilySelector,+ thread.id,+ );++ return !isDefined(thread.deletedAt) && isUnread;+};diff --git a/packages/twenty-front/src/modules/command-menu-item/display/components/CommandMenuItemRenderer.tsx b/packages/twenty-front/src/modules/command-menu-item/display/components/CommandMenuItemRenderer.tsxindex 902bc5bc259..ddca61d2304 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/components/CommandMenuItemRenderer.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/components/CommandMenuItemRenderer.tsx@@ -6,6 +6,7 @@ import { CommandMenuItemButtonHotkeyEffect } from '@/command-menu-item/display/cimport { CommandListItemLoader } from '@/command-menu-item/display/components/CommandListItemLoader';import { CommandMenuDropdownActionItem } from '@/command-menu-item/display/components/CommandMenuDropdownActionItem';import { useCommandMenuItemDisplay } from '@/command-menu-item/display/hooks/useCommandMenuItemDisplay';+import { getCommandMenuItemButtonHotKey } from '@/command-menu-item/display/utils/getCommandMenuItemButtonHotKey';import { CommandMenuButton } from '@/command-menu/components/CommandMenuButton';import { CommandMenuItem } from '@/command-menu/components/CommandMenuItem';import { SelectableListItem } from '@/ui/layout/selectable-list/components/SelectableListItem';@@ -15,7 +16,7 @@ import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/comimport { useAtomComponentFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentFamilyStateValue';import { styled } from '@linaria/react';import { useContext } from 'react';-import { assertUnreachable } from 'twenty-shared/utils';+import { assertUnreachable, isDefined } from 'twenty-shared/utils';const StyledPreviewWrapper = styled.div`cursor: not-allowed;@@ -29,6 +30,7 @@ type CommandMenuItemRendererProps = {item: CommandMenuItemDefinition;isPrimaryAction?: boolean;shouldHideLabel?: boolean;+ shouldShowHotKey?: boolean;};type CommandMenuItemButtonRendererProps = CommandMenuItemRendererProps;@@ -37,6 +39,7 @@ const CommandMenuItemButtonRenderer = ({item,isPrimaryAction = false,shouldHideLabel = false,+ shouldShowHotKey = false,}: CommandMenuItemButtonRendererProps) => {const { isInPreviewMode } = useContext(CommandMenuContext);const {@@ -57,17 +60,14 @@ const CommandMenuItemButtonRenderer = ({hotKeys: item.hotKeys,};- // A letter runs the button it labels; symbols such as / and @ open the- // command menu from anywhere, and key sequences belong to it too- const [hotKey] = item.hotKeys ?? [];- const runsOnHotKey =- item.hotKeys?.length === 1 && /^[a-z]$/i.test(hotKey ?? '');+ const buttonHotKey = getCommandMenuItemButtonHotKey(item);if (isInPreviewMode) {return (<StyledPreviewWrapper><CommandMenuButtoncommand={command}+ hotKey={shouldShowHotKey ? buttonHotKey : undefined}isPrimaryAction={isPrimaryAction}shouldHideLabel={shouldHideLabel}/>@@ -77,15 +77,16 @@ const CommandMenuItemButtonRenderer = ({return (<>- {runsOnHotKey && (+ {isDefined(buttonHotKey) && (<CommandMenuItemButtonHotkeyEffect- hotKey={hotKey}+ hotKey={buttonHotKey}disabled={disabled}onHotkeyTriggered={handleClick}/>)}<CommandMenuButtoncommand={command}+ hotKey={shouldShowHotKey ? buttonHotKey : undefined}onClick={disabled ? undefined : handleClick}disabled={disabled}progress={progress}@@ -166,6 +167,7 @@ export const CommandMenuItemRenderer = ({item,isPrimaryAction,shouldHideLabel,+ shouldShowHotKey,}: CommandMenuItemRendererProps) => {const { displayType } = useContext(CommandMenuContext);@@ -175,6 +177,7 @@ export const CommandMenuItemRenderer = ({item={item}isPrimaryAction={isPrimaryAction}shouldHideLabel={shouldHideLabel}+ shouldShowHotKey={shouldShowHotKey}/>);}diff --git a/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemButtons.tsx b/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemButtons.tsxindex 111ab4e6c1e..b667a3c9846 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemButtons.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemButtons.tsx@@ -79,6 +79,7 @@ export const PinnedCommandMenuItemButtons = ({const {pinnedInlineCommandMenuItems,pinnedOverflowCommandMenuItems,+ shouldShowHotKeys,onContainerDimensionChange,onCommandMenuItemDimensionChange,} = usePinnedCommandMenuItemsInlineLayout({@@ -117,6 +118,7 @@ export const PinnedCommandMenuItemButtons = ({<CommandMenuItemRendereritem={item}shouldHideLabel={shouldHideCommandMenuItemLabel(item.id)}+ shouldShowHotKey={shouldShowHotKeys}isPrimaryAction={item.engineComponentKey ===EngineComponentKey.CREATE_NEW_RECORD ||diff --git a/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemsInlineMeasurements.tsx b/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemsInlineMeasurements.tsxindex 0fbfebf4799..45827fd2d06 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemsInlineMeasurements.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemsInlineMeasurements.tsx@@ -1,11 +1,14 @@import { CommandMenuContext } from '@/command-menu-item/contexts/CommandMenuContext';import { PINNED_COMMAND_MENU_ITEMS_GAP } from '@/command-menu-item/display/constants/PinnedCommandMenuItemsGap';+import { getCommandMenuItemButtonHotKey } from '@/command-menu-item/display/utils/getCommandMenuItemButtonHotKey';+import { getPinnedCommandMenuItemWidthKey } from '@/command-menu-item/display/utils/getPinnedCommandMenuItemWidthKey';import { interpolateCommandMenuItemFields } from '@/command-menu-item/display/utils/interpolateCommandMenuItemFields';import { CommandMenuButton } from '@/command-menu/components/CommandMenuButton';import { NodeDimension } from '@/ui/utilities/dimensions/components/NodeDimension';import { COMMAND_MENU_DEFAULT_ICON } from '@/workflow/workflow-trigger/constants/CommandMenuDefaultIcon';import { styled } from '@linaria/react';-import { useContext } from 'react';+import { Fragment, useContext } from 'react';+import { isDefined } from 'twenty-shared/utils';import { useIcons } from 'twenty-ui/icon';import { type CommandMenuItemFieldsFragment } from '~/generated-metadata/graphql';@@ -48,22 +51,39 @@ export const PinnedCommandMenuItemsInlineMeasurements = ({);const Icon = getIcon(iconKey, COMMAND_MENU_DEFAULT_ICON);+ const hotKey = getCommandMenuItemButtonHotKey(item);++ const renderMeasurement = (shouldShowHotKey: boolean) => {+ const widthKey = getPinnedCommandMenuItemWidthKey({+ commandMenuItemId: item.id,+ shouldShowHotKey,+ });++ return (+ <NodeDimension+ onDimensionChange={onPinnedCommandMenuItemDimensionChange(+ widthKey,+ )}+ >+ <CommandMenuButton+ command={{+ key: `${widthKey}-inline-measurement`,+ label,+ shortLabel,+ Icon,+ }}+ hotKey={shouldShowHotKey ? hotKey : undefined}+ shouldHideLabel={shouldHideCommandMenuItemLabel(item.id)}+ />+ </NodeDimension>+ );+ };return (- <NodeDimension- key={item.id}- onDimensionChange={onPinnedCommandMenuItemDimensionChange(item.id)}- >- <CommandMenuButton- command={{- key: `${item.id}-inline-measurement`,- label,- shortLabel,- Icon,- }}- shouldHideLabel={shouldHideCommandMenuItemLabel(item.id)}- />- </NodeDimension>+ <Fragment key={item.id}>+ {renderMeasurement(true)}+ {isDefined(hotKey) && renderMeasurement(false)}+ </Fragment>);})}</StyledHiddenMeasurementsContainer>diff --git a/packages/twenty-front/src/modules/command-menu-item/display/hooks/__tests__/usePinnedCommandMenuItemsInlineLayout.test.tsx b/packages/twenty-front/src/modules/command-menu-item/display/hooks/__tests__/usePinnedCommandMenuItemsInlineLayout.test.tsxnew file mode 100644index 00000000000..1943bd339bf--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/display/hooks/__tests__/usePinnedCommandMenuItemsInlineLayout.test.tsx@@ -0,0 +1,104 @@+import { renderHook } from '@testing-library/react';+import { Provider as JotaiProvider } from 'jotai';+import { type ReactNode } from 'react';++import { usePinnedCommandMenuItemsInlineLayout } from '@/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout';+import { commandMenuPinnedInlineLayoutFamilyState } from '@/command-menu-item/display/states/commandMenuPinnedInlineLayoutFamilyState';+import { getPinnedCommandMenuItemWidthKey } from '@/command-menu-item/display/utils/getPinnedCommandMenuItemWidthKey';+import {+ jotaiStore,+ resetJotaiStore,+} from '@/ui/utilities/state/jotai/jotaiStore';+import {+ CommandMenuItemAvailabilityType,+ type CommandMenuItemFieldsFragment,+ EngineComponentKey,+} from '~/generated-metadata/graphql';++const buildPinnedCommandMenuItem = ({+ id,+ hotKeys,+}: Pick<+ CommandMenuItemFieldsFragment,+ 'id' | 'hotKeys'+>): CommandMenuItemFieldsFragment => ({+ id,+ hotKeys,+ label: id,+ position: 0,+ isPinned: true,+ isActive: true,+ engineComponentKey: EngineComponentKey.SNOOZE_AI_CHAT,+ availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,+});++const SNOOZE = buildPinnedCommandMenuItem({ id: 'snooze', hotKeys: ['H'] });+const DONE = buildPinnedCommandMenuItem({ id: 'done', hotKeys: ['E'] });++const ITEM_WIDTHS = {+ [getPinnedCommandMenuItemWidthKey({+ commandMenuItemId: 'snooze',+ shouldShowHotKey: true,+ })]: 100,+ [getPinnedCommandMenuItemWidthKey({+ commandMenuItemId: 'snooze',+ shouldShowHotKey: false,+ })]: 80,+ [getPinnedCommandMenuItemWidthKey({+ commandMenuItemId: 'done',+ shouldShowHotKey: true,+ })]: 90,+ [getPinnedCommandMenuItemWidthKey({+ commandMenuItemId: 'done',+ shouldShowHotKey: false,+ })]: 70,+};++const Wrapper = ({ children }: { children: ReactNode }) => (+ <JotaiProvider store={jotaiStore}>{children}</JotaiProvider>+);++const renderLayout = (containerWidth: number) => {+ jotaiStore.set(+ commandMenuPinnedInlineLayoutFamilyState.atomFamily('page-header'),+ { containerWidth, commandMenuItemWidthsByKey: ITEM_WIDTHS },+ );++ return renderHook(+ () =>+ usePinnedCommandMenuItemsInlineLayout({+ pinnedCommandMenuItems: [SNOOZE, DONE],+ layoutKey: 'page-header',+ }),+ { wrapper: Wrapper },+ ).result.current;+};++describe('usePinnedCommandMenuItemsInlineLayout', () => {+ beforeEach(() => {+ resetJotaiStore();+ });++ it('shows hot keys when every button fits with them', () => {+ const layout = renderLayout(200);++ expect(layout.shouldShowHotKeys).toBe(true);+ expect(layout.pinnedInlineCommandMenuItems).toEqual([SNOOZE, DONE]);+ });++ it('drops the hot keys before dropping a button', () => {+ const layout = renderLayout(160);++ expect(layout.shouldShowHotKeys).toBe(false);+ expect(layout.pinnedInlineCommandMenuItems).toEqual([SNOOZE, DONE]);+ expect(layout.pinnedOverflowCommandMenuItems).toEqual([]);+ });++ it('keeps the hot keys when dropping them would not save a button', () => {+ const layout = renderLayout(120);++ expect(layout.shouldShowHotKeys).toBe(true);+ expect(layout.pinnedInlineCommandMenuItems).toEqual([SNOOZE]);+ expect(layout.pinnedOverflowCommandMenuItems).toEqual([DONE]);+ });+});diff --git a/packages/twenty-front/src/modules/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout.ts b/packages/twenty-front/src/modules/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout.tsindex f774adcb3e5..294805529d6 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout.ts+++ b/packages/twenty-front/src/modules/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout.ts@@ -1,10 +1,13 @@import { PINNED_COMMAND_MENU_ITEMS_GAP } from '@/command-menu-item/display/constants/PinnedCommandMenuItemsGap';import { commandMenuPinnedInlineLayoutFamilyState } from '@/command-menu-item/display/states/commandMenuPinnedInlineLayoutFamilyState';import { type PinnedCommandMenuItemsLayoutKey } from '@/command-menu-item/display/types/PinnedCommandMenuItemsLayoutKey';+import { getCommandMenuItemButtonHotKey } from '@/command-menu-item/display/utils/getCommandMenuItemButtonHotKey';+import { getPinnedCommandMenuItemWidthKey } from '@/command-menu-item/display/utils/getPinnedCommandMenuItemWidthKey';import { getVisibleCommandMenuItemCountForContainerWidth } from '@/command-menu-item/display/utils/getVisibleCommandMenuItemCountForContainerWidth';import { useAtomFamilyState } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyState';import { isNumber } from '@sniptt/guards';import { useCallback, useMemo } from 'react';+import { isDefined } from 'twenty-shared/utils';import { type CommandMenuItemFieldsFragment } from '~/generated-metadata/graphql';type ElementDimensions = {@@ -30,47 +33,45 @@ export const usePinnedCommandMenuItemsInlineLayout = ({const effectiveContainerWidth =containerWidth ?? commandMenuPinnedInlineLayout.containerWidth;- const pinnedCommandMenuItemKeysInDisplayOrder = useMemo(- () => pinnedCommandMenuItems.map((item) => item.id),- [pinnedCommandMenuItems],- );-- const hasKnownPinnedInlineLayout = useMemo(- () =>+ const getVisiblePinnedCommandMenuItemCount = (shouldShowHotKeys: boolean) => {+ const widthKeysInDisplayOrder = pinnedCommandMenuItems.map((item) =>+ getPinnedCommandMenuItemWidthKey({+ commandMenuItemId: item.id,+ shouldShowHotKey:+ shouldShowHotKeys || !isDefined(getCommandMenuItemButtonHotKey(item)),+ }),+ );+ const isLayoutKnown =effectiveContainerWidth > 0 &&- pinnedCommandMenuItemKeysInDisplayOrder.every((commandMenuItemKey) =>+ widthKeysInDisplayOrder.every((widthKey) =>isNumber(- commandMenuPinnedInlineLayout.commandMenuItemWidthsByKey[- commandMenuItemKey- ],+ commandMenuPinnedInlineLayout.commandMenuItemWidthsByKey[widthKey],),- ),- [- commandMenuPinnedInlineLayout,- effectiveContainerWidth,- pinnedCommandMenuItemKeysInDisplayOrder,- ],- );+ );- const visiblePinnedCommandMenuItemCount = useMemo(- () =>- hasKnownPinnedInlineLayout- ? getVisibleCommandMenuItemCountForContainerWidth({- commandMenuItemKeysInDisplayOrder:- pinnedCommandMenuItemKeysInDisplayOrder,- commandMenuItemWidthsByKey:- commandMenuPinnedInlineLayout.commandMenuItemWidthsByKey,- commandMenuItemsContainerWidth: effectiveContainerWidth,- commandMenuItemsGapWidth: PINNED_COMMAND_MENU_ITEMS_GAP,- })- : 0,- [- commandMenuPinnedInlineLayout,- effectiveContainerWidth,- hasKnownPinnedInlineLayout,- pinnedCommandMenuItemKeysInDisplayOrder,- ],- );+ return isLayoutKnown+ ? getVisibleCommandMenuItemCountForContainerWidth({+ commandMenuItemKeysInDisplayOrder: widthKeysInDisplayOrder,+ commandMenuItemWidthsByKey:+ commandMenuPinnedInlineLayout.commandMenuItemWidthsByKey,+ commandMenuItemsContainerWidth: effectiveContainerWidth,+ commandMenuItemsGapWidth: PINNED_COMMAND_MENU_ITEMS_GAP,+ })+ : 0;+ };++ const visiblePinnedCommandMenuItemCountWithHotKeys =+ getVisiblePinnedCommandMenuItemCount(true);+ const visiblePinnedCommandMenuItemCountWithoutHotKeys =+ getVisiblePinnedCommandMenuItemCount(false);++ const shouldShowHotKeys =+ visiblePinnedCommandMenuItemCountWithHotKeys >=+ visiblePinnedCommandMenuItemCountWithoutHotKeys;++ const visiblePinnedCommandMenuItemCount = shouldShowHotKeys+ ? visiblePinnedCommandMenuItemCountWithHotKeys+ : visiblePinnedCommandMenuItemCountWithoutHotKeys;const pinnedInlineCommandMenuItems = useMemo(() => pinnedCommandMenuItems.slice(0, visiblePinnedCommandMenuItemCount),@@ -121,6 +122,7 @@ export const usePinnedCommandMenuItemsInlineLayout = ({return {pinnedInlineCommandMenuItems,pinnedOverflowCommandMenuItems,+ shouldShowHotKeys,onContainerDimensionChange,onCommandMenuItemDimensionChange,};diff --git a/packages/twenty-front/src/modules/command-menu-item/display/utils/getCommandMenuItemButtonHotKey.ts b/packages/twenty-front/src/modules/command-menu-item/display/utils/getCommandMenuItemButtonHotKey.tsnew file mode 100644index 00000000000..95ffd2aceb9--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/display/utils/getCommandMenuItemButtonHotKey.ts@@ -0,0 +1,11 @@+import { type CommandMenuItemFieldsFragment } from '~/generated-metadata/graphql';++// A letter runs the button it labels; symbols such as / and @ open the+// command menu from anywhere, and key sequences belong to it too+export const getCommandMenuItemButtonHotKey = ({+ hotKeys,+}: Pick<CommandMenuItemFieldsFragment, 'hotKeys'>) => {+ const [hotKey] = hotKeys ?? [];++ return hotKeys?.length === 1 && /^[a-z]$/i.test(hotKey) ? hotKey : undefined;+};diff --git a/packages/twenty-front/src/modules/command-menu-item/display/utils/getPinnedCommandMenuItemWidthKey.ts b/packages/twenty-front/src/modules/command-menu-item/display/utils/getPinnedCommandMenuItemWidthKey.tsnew file mode 100644index 00000000000..3ad0157b6c3--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/display/utils/getPinnedCommandMenuItemWidthKey.ts@@ -0,0 +1,10 @@+// A button with a hot key is measured with and without its hint, so the hint+// can give way before the button does+export const getPinnedCommandMenuItemWidthKey = ({+ commandMenuItemId,+ shouldShowHotKey,+}: {+ commandMenuItemId: string;+ shouldShowHotKey: boolean;+}) =>+ shouldShowHotKey ? commandMenuItemId : `${commandMenuItemId}-without-hot-key`;diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsxindex 9a83660124b..57fe8da37c5 100644--- a/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx+++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx@@ -19,6 +19,7 @@ export type CommandMenuButtonProps = {Icon: IconComponent;isPrimaryCTA?: boolean;};+ hotKey?: string;onClick?: (event?: MouseEvent<HTMLElement>) => void;to?: string;disabled?: boolean;@@ -30,6 +31,7 @@ export type CommandMenuButtonProps = {export const CommandMenuButton = ({command,+ hotKey,onClick,to,disabled = false,@@ -74,6 +76,7 @@ export const CommandMenuButton = ({aria-label={command.label}variant={buttonAccent === 'blue' ? 'solid' : 'outline'}color={buttonAccent === 'blue' ? 'accent' : 'neutral'}+ shortcut={isDefined(hotKey) ? [hotKey] : undefined}>{resolvedShortLabel}</NavigationButton>diff --git a/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx b/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsxindex 36f83073999..ab16a103844 100644--- a/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx+++ b/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx@@ -5,22 +5,17 @@ import { useParams } from 'react-router-dom';import { AppPath } from 'twenty-shared/types';import { isDefined, isValidUuid } from 'twenty-shared/utils';import { IconButton } from 'twenty-ui/components/input';-import { IconChevronLeft, IconPlus } from 'twenty-ui/icon';-import { Button } from 'twenty-ui/primitives/input';-import { themeCssVariables, useTheme } from 'twenty-ui/theme';+import { IconChevronLeft } from 'twenty-ui/icon';import { useIsMobile } from 'twenty-ui/utilities';import { SkeletonLoader } from '@/activities/components/SkeletonLoader';import { AgentChatThreadsFetchMoreTrigger } from '@/ai/components/AgentChatThreadsFetchMoreTrigger';import { AiChatInboxSelectionEffect } from '@/ai/components/AiChatInboxSelectionEffect';import { AiChatInboxCommandMenuScope } from '@/ai/components/AiChatInboxCommandMenuScope';+import { AiChatInboxListHeader } from '@/ai/components/AiChatInboxListHeader';import { AiChatInboxSelectionPane } from '@/ai/components/AiChatInboxSelectionPane';import { AiChatInboxThreadList } from '@/ai/components/AiChatInboxThreadList';-import { AGENT_CHAT_THREAD_FILTER_STATUS_ICONS } from '@/ai/constants/AgentChatThreadFilterStatusIcons';-import { AGENT_CHAT_THREAD_FILTER_STATUS_LABELS } from '@/ai/constants/AgentChatThreadFilterStatusLabels';import { useChatThreads } from '@/ai/hooks/useChatThreads';-import { useSwitchToNewAiChat } from '@/ai/hooks/useSwitchToNewAiChat';-import { agentChatThreadFilterStatusState } from '@/ai/states/agentChatThreadFilterStatusState';import { agentChatVisibleThreadsSelector } from '@/ai/states/selectors/agentChatVisibleThreadsSelector';import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';import { RecordSelectionDragSelect } from '@/object-record/record-selection/components/RecordSelectionDragSelect';@@ -34,7 +29,6 @@ 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 { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue';-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useNavigateApp } from '~/hooks/useNavigateApp';import { AiChatPageEffects } from '~/pages/ai-chat/AiChatPageEffects';import { AiChatThreadPageContent } from '~/pages/ai-chat/AiChatThreadPageContent';@@ -63,10 +57,8 @@ const StyledThreadList = styled.div`display: flex;flex: 1;flex-direction: column;- gap: ${themeCssVariables.spacing[1]};min-height: 0;overflow: auto;- padding: ${themeCssVariables.spacing[2]};`;const AiChatInboxPageContent = () => {@@ -76,16 +68,7 @@ const AiChatInboxPageContent = () => {const { threadId } = useParams();const selectedThreadId =isDefined(threadId) && isValidUuid(threadId) ? threadId : undefined;- const theme = useTheme();- const agentChatThreadFilterStatus = useAtomStateValue(- agentChatThreadFilterStatusState,- );- const FilterStatusIcon =- AGENT_CHAT_THREAD_FILTER_STATUS_ICONS[agentChatThreadFilterStatus];const { threads, loading } = useChatThreads(agentChatVisibleThreadsSelector);- const { switchToNewChat } = useSwitchToNewAiChat({- shouldOpenInFullPage: true,- });const selectedRecordIds = useAtomComponentSelectorValue(selectedRecordIdsComponentSelector,@@ -123,14 +106,15 @@ const AiChatInboxPageContent = () => {toggleRecordSelection({ recordId: id, shouldSelectRange: event.shiftKey });};- const isSelectionShown =- selectedRecordIds.length > 1 ||- (selectedRecordIds.length === 1 &&- selectedRecordIds[0] !== selectedThreadId);- const openThreadIds = isDefined(selectedThreadId) ? [selectedThreadId] : [];- const highlightedThreadIds = isSelectionShown- ? selectedRecordIds- : openThreadIds;+ const handleThreadCheckboxClick = (+ { id }: AgentChatThreadRecord,+ event: MouseEvent<HTMLDivElement>,+ ) =>+ toggleRecordSelection({ recordId: id, shouldSelectRange: event.shiftKey });++ const isSelectionShown = selectedRecordIds.length > 0;+ const openThreadIds =+ isDefined(selectedThreadId) && !isSelectionShown ? [selectedThreadId] : [];// A phone has room for the list or the chat, not bothconst isListShown = !isMobile || !isDefined(selectedThreadId);@@ -151,24 +135,8 @@ const AiChatInboxPageContent = () => {<PageCardLayoutshowInformationBanner={isMobile}header={- <PageCardHeader- icon={<FilterStatusIcon size={theme.icon.size.md} />}- title={t(- AGENT_CHAT_THREAD_FILTER_STATUS_LABELS[- agentChatThreadFilterStatus- ],- )}- actionButton={- <Button- size="sm"- variant="solid"- color="accent"- startIcon={<IconPlus />}- onClick={switchToNewChat}- >- {t`New chat`}- </Button>- }+ <AiChatInboxListHeader+ selectedThreadCount={selectedRecordIds.length}/>}>@@ -189,8 +157,12 @@ const AiChatInboxPageContent = () => {) : (<AiChatInboxThreadListthreads={threads}- selectedThreadIds={highlightedThreadIds}+ selectedThreadIds={openThreadIds}+ checkedThreadIds={selectedRecordIds}onThreadClick={handleThreadClick}+ onThreadCheckboxClick={+ isMobile ? undefined : handleThreadCheckboxClick+ }/>)}<AgentChatThreadsFetchMoreTrigger />@@ -204,7 +176,13 @@ const AiChatInboxPageContent = () => {</PageCardLayout></StyledListPane>)}- {isThreadShown && isSelectionShown && <AiChatInboxSelectionPane />}+ {isThreadShown && isSelectionShown && (+ <AiChatInboxSelectionPane+ selectedThreads={threads.filter(({ id }) =>+ selectedRecordIds.includes(id),+ )}+ />+ )}</AiChatInboxCommandMenuScope>{isThreadShown &&!isSelectionShown &&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.tsxindex 70192d31eb1..d4f7097eca4 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@@ -9,6 +9,7 @@ import { SOURCE_LOCALE } from 'twenty-shared/translations';import { getCommandMenuDropdownIdFromCommandMenuId } from '@/command-menu-item/utils/getCommandMenuDropdownIdFromCommandMenuId';import { CommandMenuComponentInstanceContext } from '@/command-menu/states/contexts/CommandMenuComponentInstanceContext';+import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';import { AI_CHAT_INBOX_INSTANCE_ID } from '@/ai/constants/AiChatInboxInstanceId';@@ -59,29 +60,45 @@ jest.mock('@/ai/components/AiChatThreadList', () => ({AiChatThreadList: ({threads,selectedThreadIds,+ checkedThreadIds,onThreadClick,+ onThreadCheckboxClick,onThreadContextMenu,}: {threads: AgentChatThreadRecord[];selectedThreadIds: string[];+ checkedThreadIds: string[];onThreadClick: (thread: AgentChatThreadRecord,- event: React.MouseEvent<HTMLButtonElement>,+ event: React.MouseEvent<HTMLElement>,+ ) => void;+ onThreadCheckboxClick?: (+ thread: AgentChatThreadRecord,+ event: React.MouseEvent<HTMLElement>,) => void;onThreadContextMenu?: (thread: AgentChatThreadRecord,- event: React.MouseEvent<HTMLButtonElement>,+ event: React.MouseEvent<HTMLElement>,) => void;}) =>threads.map((thread) => (- <button- key={thread.id}- aria-pressed={selectedThreadIds.includes(thread.id)}- onClick={(event) => onThreadClick(thread, event)}- onContextMenu={(event) => onThreadContextMenu?.(thread, event)}- >- {thread.title}- </button>+ <div key={thread.id}>+ <input+ type="checkbox"+ aria-label={`Select ${thread.title}`}+ checked={checkedThreadIds.includes(thread.id)}+ disabled={!onThreadCheckboxClick}+ readOnly+ onClick={(event) => onThreadCheckboxClick?.(thread, event)}+ />+ <button+ aria-pressed={selectedThreadIds.includes(thread.id)}+ onClick={(event) => onThreadClick(thread, event)}+ onContextMenu={(event) => onThreadContextMenu?.(thread, event)}+ >+ {thread.title}+ </button>+ </div>)),}));@@ -139,10 +156,20 @@ const renderInbox = () =></JotaiProvider>,);-const isRowHighlighted = (title: string) =>+const isRowOpen = (title: string) =>screen.getByRole('button', { name: title }).getAttribute('aria-pressed') ==='true';+const getRowCheckbox = (title: string) =>+ screen.getByRole('checkbox', { name: `Select ${title}` });++const getTargetedThreadIds = (contextStoreInstanceId: string) =>+ jotaiStore.get(+ contextStoreTargetedRecordsRuleComponentState.atomFamily({+ instanceId: contextStoreInstanceId,+ }),+ );+describe('AiChatInboxPage', () => {beforeEach(() => {resetJotaiStore();@@ -166,19 +193,75 @@ describe('AiChatInboxPage', () => {});expect(screen.getByText('2 chats selected')).toBeInTheDocument();+ expect(getTargetedThreadIds(AI_CHAT_INBOX_INSTANCE_ID)).toEqual({+ mode: 'selection',+ selectedRecordIds: [firstThread.id, thirdThread.id],+ });+ expect(getRowCheckbox('First chat')).toBeChecked();+ expect(getRowCheckbox('Second chat')).not.toBeChecked();+ expect(getRowCheckbox('Third chat')).toBeChecked();+ expect(isRowOpen('First chat')).toBe(false);+ });++ it('checks a chat from its checkbox, leaving the chat on screen out', () => {+ renderInbox();++ fireEvent.click(+ screen.getByRole('checkbox', { name: 'Select Third chat' }),+ );++ expect(screen.getByText('1 chat selected')).toBeInTheDocument();+ expect(getRowCheckbox('First chat')).not.toBeChecked();+ expect(getRowCheckbox('Third chat')).toBeChecked();+ });++ it('checks the chat on screen from its checkbox', () => {+ renderInbox();++ fireEvent.click(+ screen.getByRole('checkbox', { name: 'Select First chat' }),+ );++ expect(screen.getByText('1 chat selected')).toBeInTheDocument();+ expect(getRowCheckbox('First chat')).toBeChecked();+ expect(screen.getByText('1 selected')).toBeInTheDocument();+ });++ it('counts the selection in the list header instead of offering a new chat', () => {+ renderInbox();+expect(- jotaiStore.get(- contextStoreTargetedRecordsRuleComponentState.atomFamily({- instanceId: AI_CHAT_INBOX_INSTANCE_ID,- }),- ),- ).toEqual({+ screen.getByRole('button', { name: 'New chat' }),+ ).toBeInTheDocument();++ fireEvent.click(screen.getByRole('button', { name: 'Third chat' }), {+ metaKey: true,+ });++ expect(screen.getByText('2 selected')).toBeInTheDocument();+ expect(+ screen.queryByRole('button', { name: 'New chat' }),+ ).not.toBeInTheDocument();+ });++ it('lets the command menu act on the selection while it is shown', () => {+ renderInbox();++ fireEvent.click(screen.getByRole('button', { name: 'Third chat' }), {+ metaKey: true,+ });++ expect(getTargetedThreadIds(MAIN_CONTEXT_STORE_INSTANCE_ID)).toEqual({mode: 'selection',selectedRecordIds: [firstThread.id, thirdThread.id],});- expect(isRowHighlighted('First chat')).toBe(true);- expect(isRowHighlighted('Second chat')).toBe(false);- expect(isRowHighlighted('Third chat')).toBe(true);++ fireEvent.click(screen.getByRole('button', { name: 'Clear selection' }));++ expect(getTargetedThreadIds(MAIN_CONTEXT_STORE_INSTANCE_ID)).toEqual({+ mode: 'selection',+ selectedRecordIds: [],+ });});it('opens the command menu on the right-clicked chats', () => {@@ -188,13 +271,7 @@ describe('AiChatInboxPage', () => {fireEvent.contextMenu(screen.getByRole('button', { name: 'Third chat' }));expect(screen.getByText('2 chats selected')).toBeInTheDocument();- expect(- jotaiStore.get(- contextStoreTargetedRecordsRuleComponentState.atomFamily({- instanceId: AI_CHAT_INBOX_INSTANCE_ID,- }),- ),- ).toEqual({+ expect(getTargetedThreadIds(AI_CHAT_INBOX_INSTANCE_ID)).toEqual({mode: 'selection',selectedRecordIds: [secondThread.id, thirdThread.id],});@@ -228,6 +305,7 @@ describe('AiChatInboxPage', () => {fireEvent.click(screen.getByRole('button', { name: 'Clear selection' }));expect(screen.getByText(`Chat page ${firstThread.id}`)).toBeInTheDocument();+ expect(isRowOpen('First chat')).toBe(true);});it('starts with no selection when coming back to the inbox', () => {@@ -238,17 +316,14 @@ describe('AiChatInboxPage', () => {});unmount();- expect(- jotaiStore.get(- contextStoreTargetedRecordsRuleComponentState.atomFamily({- instanceId: AI_CHAT_INBOX_INSTANCE_ID,- }),- ),- ).toEqual({ mode: 'selection', selectedRecordIds: [] });+ expect(getTargetedThreadIds(AI_CHAT_INBOX_INSTANCE_ID)).toEqual({+ mode: 'selection',+ selectedRecordIds: [],+ });renderInbox();expect(screen.getByText(`Chat page ${firstThread.id}`)).toBeInTheDocument();- expect(isRowHighlighted('Second chat')).toBe(false);+ expect(getRowCheckbox('Second chat')).not.toBeChecked();});});