diff --git a/ui/src/pages/RagChatTab/ChatLayout.tsx b/ui/src/pages/RagChatTab/ChatLayout.tsx index 78502d3..0579e9d 100644 --- a/ui/src/pages/RagChatTab/ChatLayout.tsx +++ b/ui/src/pages/RagChatTab/ChatLayout.tsx @@ -53,18 +53,11 @@ const getSessionForSessionId = (sessionId?: string, sessions?: Session[]) => { return sessions?.find((session) => session.id.toString() === sessionId); }; -const getDataSourceIdForSession = (session?: Session) => { - return session?.dataSourceIds[0]; -}; - function ChatLayout() { const { data: sessions } = useSuspenseQuery(getSessionsQueryOptions); const { sessionId } = useParams({ strict: false }); - const activeSession = getSessionForSessionId(sessionId, sessions); - const dataSourceId = getDataSourceIdForSession(activeSession); const [currentQuestion, setCurrentQuestion] = useState(""); - const { data: dataSources, status: dataSourcesStatus } = useGetDataSourcesQuery(); const [excludeKnowledgeBase, setExcludeKnowledgeBase] = useState(false); @@ -72,6 +65,9 @@ function ChatLayout() { sessionId?.toString() ?? "", ); + const activeSession = getSessionForSessionId(sessionId, sessions); + const dataSourceId = activeSession?.dataSourceIds[0]; + const dataSourceSize = useMemo(() => { return ( dataSources?.find((ds) => ds.id === dataSourceId)?.totalDocSize ?? null @@ -90,7 +86,6 @@ function ChatLayout() { return ( { const defaultContextValue: RagChatContextType = { chatHistoryQuery: { chatHistoryStatus: undefined, chatHistory: [] }, currentQuestionState: ["", () => null], - dataSourceId: undefined, dataSourcesQuery: { dataSourcesStatus: undefined, dataSources: [] }, excludeKnowledgeBaseState: [false, () => null], dataSourceSize: null, @@ -125,7 +124,6 @@ describe("ChatBodyController", () => { it("renders NoSessionState when no sessionId and dataSources are available", () => { renderWithContext({ - dataSourceId: undefined, dataSourcesQuery: { dataSourcesStatus: undefined, dataSources: [] }, dataSourceSize: null, activeSession: undefined, @@ -188,7 +186,6 @@ describe("ChatBodyController", () => { it("renders NoDataSourceForSession when no currentDataSource is found", () => { renderWithContext({ dataSourcesQuery: { dataSources: [testDataSource] }, - dataSourceId: undefined, activeSession: { ...testSession, dataSourceIds: [2] }, }); diff --git a/ui/src/pages/RagChatTab/ChatOutput/ChatMessages/ChatMessageController.tsx b/ui/src/pages/RagChatTab/ChatOutput/ChatMessages/ChatMessageController.tsx index c22e035..c7b4b7e 100644 --- a/ui/src/pages/RagChatTab/ChatOutput/ChatMessages/ChatMessageController.tsx +++ b/ui/src/pages/RagChatTab/ChatOutput/ChatMessages/ChatMessageController.tsx @@ -43,9 +43,10 @@ import { RagChatContext } from "pages/RagChatTab/State/RagChatContext.tsx"; const ChatMessageController = () => { const { chatHistoryQuery: { chatHistory }, - dataSourceId, + activeSession, } = useContext(RagChatContext); const scrollEl = useRef(null); + const dataSourceId = activeSession?.dataSourceIds[0]; useEffect(() => { setTimeout(() => { diff --git a/ui/src/pages/RagChatTab/ChatOutput/Placeholders/EmptyChatState.tsx b/ui/src/pages/RagChatTab/ChatOutput/Placeholders/EmptyChatState.tsx index a45f56f..3ef2b1b 100644 --- a/ui/src/pages/RagChatTab/ChatOutput/Placeholders/EmptyChatState.tsx +++ b/ui/src/pages/RagChatTab/ChatOutput/Placeholders/EmptyChatState.tsx @@ -46,8 +46,8 @@ import { cdlGray700 } from "src/cuix/variables.ts"; import Images from "src/components/images/Images.ts"; const DataSourceSummaryCard = () => { - const { dataSourceId } = useContext(RagChatContext); - + const { activeSession } = useContext(RagChatContext); + const dataSourceId = activeSession?.dataSourceIds[0]; const dataSourceSummary = useGetDataSourceSummary({ data_source_id: dataSourceId?.toString() ?? "", queryEnabled: true, @@ -81,7 +81,9 @@ const DataSourceSummaryCard = () => { }; const EmptyChatState = ({ dataSourceSize }: { dataSourceSize: number }) => { - const { dataSourceId } = useContext(RagChatContext); + const { activeSession } = useContext(RagChatContext); + const dataSourceId = activeSession?.dataSourceIds[0]; + return ( { const { - dataSourceId, currentQuestionState: [, setCurrentQuestion], activeSession, excludeKnowledgeBaseState: [excludeKnowledgeBase], } = useContext(RagChatContext); - + const dataSourceId = activeSession?.dataSourceIds[0]; const sessionId = activeSession?.id.toString(); const { data, diff --git a/ui/src/pages/RagChatTab/ChatOutput/Sources/SourceCard.tsx b/ui/src/pages/RagChatTab/ChatOutput/Sources/SourceCard.tsx index 74b83a4..3193949 100644 --- a/ui/src/pages/RagChatTab/ChatOutput/Sources/SourceCard.tsx +++ b/ui/src/pages/RagChatTab/ChatOutput/Sources/SourceCard.tsx @@ -57,9 +57,10 @@ import { cdlGray600 } from "src/cuix/variables.ts"; import MetaData from "pages/RagChatTab/ChatOutput/Sources/MetaData.tsx"; export const SourceCard = ({ source }: { source: SourceNode }) => { - const { dataSourceId } = useContext(RagChatContext); + const { activeSession } = useContext(RagChatContext); const [showContent, setShowContent] = useState(false); const chunkContents = useGetChunkContents(); + const dataSourceId = activeSession?.dataSourceIds[0]; const documentSummary = useGetDocumentSummary({ data_source_id: dataSourceId?.toString() ?? "", doc_id: source.doc_id, diff --git a/ui/src/pages/RagChatTab/FooterComponents/RagChatQueryInput.tsx b/ui/src/pages/RagChatTab/FooterComponents/RagChatQueryInput.tsx index 8641956..682a7d4 100644 --- a/ui/src/pages/RagChatTab/FooterComponents/RagChatQueryInput.tsx +++ b/ui/src/pages/RagChatTab/FooterComponents/RagChatQueryInput.tsx @@ -51,7 +51,6 @@ import type { SwitchChangeEventHandler } from "antd/lib/switch"; const RagChatQueryInput = () => { const { - dataSourceId, excludeKnowledgeBaseState: [excludeKnowledgeBase, setExcludeKnowledgeBase], currentQuestionState: [, setCurrentQuestion], chatHistoryQuery: { chatHistory }, @@ -59,7 +58,7 @@ const RagChatQueryInput = () => { dataSourcesQuery: { dataSourcesStatus }, activeSession, } = useContext(RagChatContext); - + const dataSourceId = activeSession?.dataSourceIds[0]; const [userInput, setUserInput] = useState(""); const { sessionId } = useParams({ strict: false }); diff --git a/ui/src/pages/RagChatTab/RagChat.tsx b/ui/src/pages/RagChatTab/RagChat.tsx index 8013133..7aa4ea2 100644 --- a/ui/src/pages/RagChatTab/RagChat.tsx +++ b/ui/src/pages/RagChatTab/RagChat.tsx @@ -47,13 +47,12 @@ const { Footer, Content } = Layout; const RagChat = () => { const { - dataSourceId, dataSourcesQuery: { dataSources }, activeSession, } = useContext(RagChatContext); const currentDataSource = dataSources.find((dataSource) => { - return dataSource.id === dataSourceId; + return dataSource.id === activeSession?.dataSourceIds[0]; }); return ( diff --git a/ui/src/pages/RagChatTab/State/RagChatContext.tsx b/ui/src/pages/RagChatTab/State/RagChatContext.tsx index 171623a..02d1852 100644 --- a/ui/src/pages/RagChatTab/State/RagChatContext.tsx +++ b/ui/src/pages/RagChatTab/State/RagChatContext.tsx @@ -52,7 +52,6 @@ export interface RagChatContextType { dataSources: DataSourceType[]; dataSourcesStatus?: "error" | "success" | "pending"; }; - dataSourceId?: number; dataSourceSize: number | null; excludeKnowledgeBaseState: [boolean, Dispatch>]; } @@ -62,7 +61,6 @@ export const RagChatContext = createContext({ currentQuestionState: ["", () => null], chatHistoryQuery: { chatHistory: [], chatHistoryStatus: undefined }, dataSourcesQuery: { dataSources: [], dataSourcesStatus: undefined }, - dataSourceId: undefined, // TODO: remove this and have it pulled from active session dataSourceSize: null, excludeKnowledgeBaseState: [false, () => null], });