Navbar with AI chats (#18161)
## Summary Add Home/Chat tabs and a dedicated threads list in the navigation drawer. ## Changes - **Navbar tabs:** Tabs in the drawer to switch between Home and Chat (with “New chat” button). Shown on desktop when expanded and on mobile below the workspace selector. - **Navbar threads list:** New `NavigationDrawerAIChatThreadsList` for the Chat tab with date groups (Today / Yesterday / Older), thread rows as `NavigationDrawerItem` (IconComment, title, timestamp). Shared `useAIChatThreadClick` hook used by navbar and command menu; navbar passes `resetNavigationStack: true`. - **NavigationDrawerItem:** New `alwaysShowRightOptions` prop so the timestamp is always visible (no hover-only). --------- Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com> Co-authored-by: Félix Malfait <felix@twenty.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@@ -2,9 +2,15 @@ import { type AgentChatThread } from '~/generated-metadata/graphql';
|
||||
import { groupThreadsByDate } from '@/ai/utils/groupThreadsByDate';
|
||||
|
||||
describe('groupThreadsByDate', () => {
|
||||
const baseThread: Omit<AgentChatThread, 'createdAt' | 'id'> = {
|
||||
const today = new Date();
|
||||
const yesterday = new Date(today);
|
||||
yesterday.setDate(today.getDate() - 1);
|
||||
const twoDaysAgo = new Date(today);
|
||||
twoDaysAgo.setDate(today.getDate() - 2);
|
||||
|
||||
const baseThread: Omit<AgentChatThread, 'updatedAt' | 'id'> = {
|
||||
title: 'Test Thread',
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: twoDaysAgo.toISOString(),
|
||||
totalInputTokens: 0,
|
||||
totalOutputTokens: 0,
|
||||
contextWindowTokens: null,
|
||||
@@ -13,16 +19,10 @@ describe('groupThreadsByDate', () => {
|
||||
totalOutputCredits: 0,
|
||||
};
|
||||
|
||||
const today = new Date();
|
||||
const yesterday = new Date(today);
|
||||
yesterday.setDate(today.getDate() - 1);
|
||||
const twoDaysAgo = new Date(today);
|
||||
twoDaysAgo.setDate(today.getDate() - 2);
|
||||
|
||||
const threads: AgentChatThread[] = [
|
||||
{ ...baseThread, id: '1', createdAt: today.toISOString() },
|
||||
{ ...baseThread, id: '2', createdAt: yesterday.toISOString() },
|
||||
{ ...baseThread, id: '3', createdAt: twoDaysAgo.toISOString() },
|
||||
{ ...baseThread, id: '1', updatedAt: today.toISOString() },
|
||||
{ ...baseThread, id: '2', updatedAt: yesterday.toISOString() },
|
||||
{ ...baseThread, id: '3', updatedAt: twoDaysAgo.toISOString() },
|
||||
];
|
||||
|
||||
it('groups threads into today, yesterday, and older', () => {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export type DateGroupKey = 'today' | 'yesterday' | 'older';
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type DateGroupKey } from '@/ai/utils/dateGroupKey';
|
||||
|
||||
export const DATE_GROUP_KEYS: readonly DateGroupKey[] = [
|
||||
'today',
|
||||
'yesterday',
|
||||
'older',
|
||||
];
|
||||
@@ -0,0 +1,14 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import { type DateGroupKey } from '@/ai/utils/dateGroupKey';
|
||||
|
||||
export const getDateGroupTitle = (key: DateGroupKey): string => {
|
||||
switch (key) {
|
||||
case 'today':
|
||||
return t`Today`;
|
||||
case 'yesterday':
|
||||
return t`Yesterday`;
|
||||
case 'older':
|
||||
return t`Older`;
|
||||
}
|
||||
};
|
||||
@@ -1,17 +1,17 @@
|
||||
import { type AgentChatThread } from '~/generated-metadata/graphql';
|
||||
|
||||
export const groupThreadsByDate = (threads: AgentChatThread[]) => {
|
||||
import { type DateGroupKey } from '@/ai/utils/dateGroupKey';
|
||||
|
||||
export const groupThreadsByDate = (
|
||||
threads: AgentChatThread[],
|
||||
): Record<DateGroupKey, AgentChatThread[]> => {
|
||||
const today = new Date();
|
||||
const yesterday = new Date(today);
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
return threads.reduce<{
|
||||
today: AgentChatThread[];
|
||||
yesterday: AgentChatThread[];
|
||||
older: AgentChatThread[];
|
||||
}>(
|
||||
return threads.reduce<Record<DateGroupKey, AgentChatThread[]>>(
|
||||
(acc, thread) => {
|
||||
const threadDate = new Date(thread.createdAt);
|
||||
const threadDate = new Date(thread.updatedAt);
|
||||
const threadDateString = threadDate.toDateString();
|
||||
|
||||
if (threadDateString === today.toDateString()) {
|
||||
|
||||
Reference in New Issue
Block a user