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
This commit is contained in:
parent
a25a10f7e8
commit
c18952ef9d
3 changed files with 16 additions and 22 deletions
|
|
@ -185,6 +185,8 @@ export default function NotebookPage() {
|
|||
<ChatColumn
|
||||
notebookId={notebookId}
|
||||
contextSelections={contextSelections}
|
||||
sources={sources}
|
||||
sourcesLoading={sourcesLoading}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
|
@ -234,6 +236,8 @@ export default function NotebookPage() {
|
|||
<ChatColumn
|
||||
notebookId={notebookId}
|
||||
contextSelections={contextSelections}
|
||||
sources={sources}
|
||||
sourcesLoading={sourcesLoading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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: () => <div data-testid="chat-panel" />
|
||||
}))
|
||||
|
||||
// Type-safe mock factory for useSources hook
|
||||
function createSourcesMock(overrides: { isLoading?: boolean } = {}) {
|
||||
return {
|
||||
data: [],
|
||||
isLoading: overrides.isLoading ?? false,
|
||||
} as unknown as ReturnType<typeof useSources>
|
||||
}
|
||||
|
||||
// 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(<ChatColumn {...mockProps} />)
|
||||
|
||||
render(<ChatColumn {...baseProps} sourcesLoading={true} />)
|
||||
|
||||
// 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(<ChatColumn {...mockProps} />)
|
||||
|
||||
render(<ChatColumn {...baseProps} sourcesLoading={false} />)
|
||||
|
||||
// Should show chat panel
|
||||
expect(screen.getByTestId('chat-panel')).toBeInTheDocument()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue