From c18952ef9d92aa7fafa3710762281cd58c1b8624 Mon Sep 17 00:00:00 2001 From: Luis Novo Date: Wed, 25 Feb 2026 19:31:20 -0300 Subject: [PATCH] fix(chat): remove 50-source cap from notebook chat context (#628) * fix(chat): remove 50-source cap from notebook chat context ChatColumn was independently fetching sources via useSources() which defaults to a limit of 50 from the API. This caused the chat context to always be capped at 50 sources regardless of how many are in the notebook. ChatColumn now receives sources as a prop from the parent NotebookPage, which already fetches all sources via useNotebookSources with infinite scroll pagination. * test(chat): update ChatColumn tests for new sources prop interface --- .../app/(dashboard)/notebooks/[id]/page.tsx | 4 +++ .../notebooks/components/ChatColumn.test.tsx | 25 ++++++------------- .../notebooks/components/ChatColumn.tsx | 9 ++++--- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/frontend/src/app/(dashboard)/notebooks/[id]/page.tsx b/frontend/src/app/(dashboard)/notebooks/[id]/page.tsx index 97ec398..16792a2 100644 --- a/frontend/src/app/(dashboard)/notebooks/[id]/page.tsx +++ b/frontend/src/app/(dashboard)/notebooks/[id]/page.tsx @@ -185,6 +185,8 @@ export default function NotebookPage() { )} @@ -234,6 +236,8 @@ export default function NotebookPage() { diff --git a/frontend/src/app/(dashboard)/notebooks/components/ChatColumn.test.tsx b/frontend/src/app/(dashboard)/notebooks/components/ChatColumn.test.tsx index 5e2b7f5..70e4ea2 100644 --- a/frontend/src/app/(dashboard)/notebooks/components/ChatColumn.test.tsx +++ b/frontend/src/app/(dashboard)/notebooks/components/ChatColumn.test.tsx @@ -1,26 +1,16 @@ import { render, screen } from '@testing-library/react' import { describe, it, expect, vi } from 'vitest' import { ChatColumn } from './ChatColumn' -import { useSources } from '@/lib/hooks/use-sources' import { useNotes } from '@/lib/hooks/use-notes' import { useNotebookChat } from '@/lib/hooks/useNotebookChat' // Mock the hooks -vi.mock('@/lib/hooks/use-sources') vi.mock('@/lib/hooks/use-notes') vi.mock('@/lib/hooks/useNotebookChat') vi.mock('@/components/source/ChatPanel', () => ({ ChatPanel: () =>
})) -// Type-safe mock factory for useSources hook -function createSourcesMock(overrides: { isLoading?: boolean } = {}) { - return { - data: [], - isLoading: overrides.isLoading ?? false, - } as unknown as ReturnType -} - // Type-safe mock factory for useNotes hook function createNotesMock(overrides: { isLoading?: boolean } = {}) { return { @@ -42,32 +32,31 @@ function createChatMock() { } describe('ChatColumn', () => { - const mockProps = { + const baseProps = { notebookId: 'test-notebook', contextSelections: { sources: {}, notes: {} - } + }, + sources: [], } it('shows loading spinner when fetching data', () => { - vi.mocked(useSources).mockReturnValue(createSourcesMock({ isLoading: true })) vi.mocked(useNotes).mockReturnValue(createNotesMock({ isLoading: true })) vi.mocked(useNotebookChat).mockReturnValue(createChatMock()) - render() - + render() + // Should show loading spinner expect(screen.getByTestId('loading-spinner')).toBeInTheDocument() }) it('renders chat panel when data is loaded', () => { - vi.mocked(useSources).mockReturnValue(createSourcesMock({ isLoading: false })) vi.mocked(useNotes).mockReturnValue(createNotesMock({ isLoading: false })) vi.mocked(useNotebookChat).mockReturnValue(createChatMock()) - render() - + render() + // Should show chat panel expect(screen.getByTestId('chat-panel')).toBeInTheDocument() }) diff --git a/frontend/src/app/(dashboard)/notebooks/components/ChatColumn.tsx b/frontend/src/app/(dashboard)/notebooks/components/ChatColumn.tsx index cc7a943..181e630 100644 --- a/frontend/src/app/(dashboard)/notebooks/components/ChatColumn.tsx +++ b/frontend/src/app/(dashboard)/notebooks/components/ChatColumn.tsx @@ -2,7 +2,6 @@ import { useMemo } from 'react' import { useNotebookChat } from '@/lib/hooks/useNotebookChat' -import { useSources } from '@/lib/hooks/use-sources' import { useNotes } from '@/lib/hooks/use-notes' import { ChatPanel } from '@/components/source/ChatPanel' import { LoadingSpinner } from '@/components/common/LoadingSpinner' @@ -10,17 +9,19 @@ import { Card, CardContent } from '@/components/ui/card' import { AlertCircle } from 'lucide-react' import { ContextSelections } from '../[id]/page' import { useTranslation } from '@/lib/hooks/use-translation' +import { SourceListResponse } from '@/lib/types/api' interface ChatColumnProps { notebookId: string contextSelections: ContextSelections + sources: SourceListResponse[] + sourcesLoading: boolean } -export function ChatColumn({ notebookId, contextSelections }: ChatColumnProps) { +export function ChatColumn({ notebookId, contextSelections, sources, sourcesLoading }: ChatColumnProps) { const { t } = useTranslation() - // Fetch sources and notes for this notebook - const { data: sources = [], isLoading: sourcesLoading } = useSources(notebookId) + // Fetch notes for this notebook const { data: notes = [], isLoading: notesLoading } = useNotes(notebookId) // Initialize notebook chat hook