// // SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // "use client" import { useState, useEffect } from "react" import { Network, Database, Zap, AlertCircle, RefreshCw } from "lucide-react" interface Neo4jConnectionProps { className?: string } export function Neo4jConnection({ className }: Neo4jConnectionProps) { const [connectionStatus, setConnectionStatus] = useState<"connected" | "disconnected" | "checking">("disconnected") const [error, setError] = useState(null) const [nodeCount, setNodeCount] = useState(null) const [relationshipCount, setRelationshipCount] = useState(null) const [connectionUrl, setConnectionUrl] = useState("") // Check Neo4j connection status const checkConnection = async () => { setConnectionStatus("checking") setError(null) try { // Get credentials from localStorage const dbUrl = localStorage.getItem("NEO4J_URL") const dbUsername = localStorage.getItem("NEO4J_USERNAME") const dbPassword = localStorage.getItem("NEO4J_PASSWORD") // Add query parameters if credentials exist const queryParams = new URLSearchParams() if (dbUrl) queryParams.append("url", dbUrl) if (dbUsername) queryParams.append("username", dbUsername) if (dbPassword) queryParams.append("password", dbPassword) const queryString = queryParams.toString() const endpoint = queryString ? `/api/neo4j?${queryString}` : '/api/neo4j' const response = await fetch(endpoint) if (!response.ok) { const errorData = await response.json() throw new Error(errorData.error || 'Failed to connect to Neo4j') } const data = await response.json() setNodeCount(data.nodes?.length || 0) setRelationshipCount(data.links?.length || 0) // Use the connection URL from the API response if (data.connectionUrl) { setConnectionUrl(data.connectionUrl) } else if (dbUrl) { setConnectionUrl(dbUrl) } setConnectionStatus("connected") } catch (err) { console.error('Neo4j connection error:', err) setConnectionStatus("disconnected") setError(err instanceof Error ? err.message : 'Unknown error connecting to Neo4j') } } // Disconnect from Neo4j const disconnect = async () => { try { const response = await fetch('/api/neo4j/disconnect', { method: 'POST', }) if (!response.ok) { const errorData = await response.json() throw new Error(errorData.error || 'Failed to disconnect from Neo4j') } setConnectionStatus("disconnected") setNodeCount(null) setRelationshipCount(null) } catch (err) { console.error('Neo4j disconnect error:', err) setError(err instanceof Error ? err.message : 'Unknown error disconnecting from Neo4j') } } // Check connection on component mount // useEffect(() => { // checkConnection() // }, []) return (

Graph DB

{connectionStatus === "checking" && (
Checking connection...
)} {connectionStatus === "connected" && ( <>
{connectionUrl}
{(nodeCount !== null || relationshipCount !== null) && (
{nodeCount} nodes, {relationshipCount} relationships
)} )} {connectionStatus === "disconnected" && ( <>
Not connected
)}
{connectionStatus === "connected" ? ( ) : ( )}
) }