From 8dec47ff63ab0f67ecfcd012c2ae6868cc2de084 Mon Sep 17 00:00:00 2001 From: Atharva Ombase <94031822+atharvaombase@users.noreply.github.com> Date: Tue, 15 Apr 2025 04:10:27 +0530 Subject: [PATCH] Feat: Added table to list and view HDFS files with dynamic navigation --- Frontend/src/components/FileList.jsx | 134 +++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 Frontend/src/components/FileList.jsx diff --git a/Frontend/src/components/FileList.jsx b/Frontend/src/components/FileList.jsx new file mode 100644 index 0000000..22e4d1a --- /dev/null +++ b/Frontend/src/components/FileList.jsx @@ -0,0 +1,134 @@ +import React, { useState, useEffect } from "react"; +import PropTypes from "prop-types"; + +const FileTable = ({ initialPath }) => { + const [currentPath, setCurrentPath] = useState(initialPath || "/"); + const [files, setFiles] = useState([]); + + // Helpers to parse entry + const getType = (entry) => + entry.trim().startsWith("📁") ? "Folder" : "File"; + const getName = (entry) => entry.trim().replace(/^📁\s*|^📄\s*/, ""); + const isFile = (entry) => getType(entry) === "File"; + + // Fetch and show only top-level entries (indentation = 0) + const fetchFiles = async () => { + try { + const response = await fetch( + `http://192.168.29.61:8080/api/hdfs/listFiles?hdfsPath=${currentPath}` + ); + const data = await response.json(); + + // Filter entries: only those without leading spaces + const filtered = data.filter( + (entry) => entry.match(/^ */)[0].length === 0 + ); + setFiles(filtered); + } catch (error) { + console.error("Failed to fetch files:", error); + setFiles([]); + } + }; + + useEffect(() => { + fetchFiles(); + }, [currentPath]); + + // Navigate into a folder + const handleOpenFolder = (folderName) => { + const newPath = + currentPath === "/" ? `/${folderName}` : `${currentPath}/${folderName}`; + setCurrentPath(newPath); + }; + + // Go up one level + const goBack = () => { + if (currentPath === "/") return; + const parts = currentPath.split("/").filter(Boolean); + parts.pop(); + setCurrentPath(parts.length === 0 ? "/" : `/${parts.join("/")}`); + }; + + return ( +
| + File Name + | ++ Type + | ++ Action + | +
|---|---|---|
| + No files found. + | +||
| + {name} + | +{type} | ++ {isFile(entry) ? ( + + Download + + ) : ( + + )} + | +