"use client"; import React, { useState, useEffect } from 'react'; import { Sidebar } from '@/components/ui/sidebar'; import DocumentsSection from '@/components/documents/DocumentsSection'; import SearchSection from '@/components/search/SearchSection'; import ChatSection from '@/components/chat/ChatSection'; import GraphSection from '@/components/GraphSection'; import { Badge } from '@/components/ui/badge'; import { AlertSystem } from '@/components/ui/alert-system'; import { extractTokenFromUri, getApiBaseUrlFromUri } from '@/lib/utils'; import { MorphikUIProps } from '@/components/types'; // Default API base URL const DEFAULT_API_BASE_URL = 'http://localhost:8000'; const MorphikUI: React.FC = ({ connectionUri, apiBaseUrl = DEFAULT_API_BASE_URL, isReadOnlyUri = false, // Default to editable URI onUriChange, onBackClick, initialFolder = null, initialSection = 'documents' }) => { // State to manage connectionUri internally if needed const [currentUri, setCurrentUri] = useState(connectionUri); // Update internal state when prop changes useEffect(() => { setCurrentUri(connectionUri); }, [connectionUri]); // Handle URI changes from sidebar const handleUriChange = (newUri: string) => { console.log('MorphikUI: URI changed to:', newUri); setCurrentUri(newUri); if (onUriChange) { onUriChange(newUri); } }; const [activeSection, setActiveSection] = useState(initialSection); const [selectedGraphName, setSelectedGraphName] = useState(undefined); const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(false); // Extract auth token and API URL from connection URI if provided const authToken = currentUri ? extractTokenFromUri(currentUri) : null; // Derive API base URL from the URI if provided // If URI is empty, this will now connect to localhost by default const effectiveApiBaseUrl = getApiBaseUrlFromUri(currentUri, apiBaseUrl); // Log the effective API URL for debugging useEffect(() => { console.log('MorphikUI: Using API URL:', effectiveApiBaseUrl); console.log('MorphikUI: Auth token present:', !!authToken); }, [effectiveApiBaseUrl, authToken]); return ( <>
{/* Remove the header with back button */}
{/* Documents Section */} {activeSection === 'documents' && ( )} {/* Search Section */} {activeSection === 'search' && ( )} {/* Chat Section */} {activeSection === 'chat' && ( )} {/* Notebooks Section - Removed */} {/* Graphs Section */} {activeSection === 'graphs' && (
{selectedGraphName && ( Current Query Graph: {selectedGraphName} )}
setSelectedGraphName(graphName)} />
)}
{/* Global alert system - integrated directly in the component */} ); }; export default MorphikUI;