// // 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 { Triple } from "@/types/graph"; export default function DocumentsList() { const [loading, setLoading] = useState(true); const [triples, setTriples] = useState([]); const [entities, setEntities] = useState([]); const [error, setError] = useState(null); useEffect(() => { async function fetchTriplesAndEntities() { try { setLoading(true); // Fetch triples from Neo4j const response = await fetch('/api/neo4j/triples', { method: 'GET', headers: { 'Content-Type': 'application/json' } }); if (!response.ok) { throw new Error(`Failed to fetch triples: ${response.statusText}`); } const data = await response.json(); // Extract unique entities const uniqueEntities = new Set(); data.triples.forEach((triple: Triple) => { uniqueEntities.add(triple.subject); uniqueEntities.add(triple.object); }); // Store data in local storage, overwriting previous data localStorage.setItem("graphTriples", JSON.stringify(data.triples)); localStorage.setItem("graphDocumentName", "sample_data.csv"); // Update state setTriples(data.triples); setEntities(Array.from(uniqueEntities)); setError(null); } catch (err) { console.error("Error fetching data:", err); setError(err instanceof Error ? err.message : "Unknown error occurred"); } finally { setLoading(false); } } fetchTriplesAndEntities(); }, []); return (

Document Data

{loading && (

Loading data from Neo4j...

)} {error && (

Error

{error}

)} {!loading && !error && (

Entities ({entities.length})

    {entities.slice(0, 100).map((entity, index) => (
  • {entity}
  • ))}
{entities.length > 100 && (

Showing 100 of {entities.length} entities

)}

Triples ({triples.length})

{triples.slice(0, 50).map((triple, index) => ( ))}
Subject Predicate Object
{triple.subject} {triple.predicate} {triple.object}
{triples.length > 50 && (

Showing 50 of {triples.length} triples

)}
)}
); }