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 ( +
+
+ Path: {currentPath} + {currentPath !== "/" && ( + + )} +
+ + + + + + + + + + {files.length === 0 ? ( + + + + ) : ( + files.map((entry, idx) => { + const name = getName(entry); + const type = getType(entry); + const encodedPath = encodeURIComponent(`${currentPath}/${name}`); + const downloadUrl = `http://192.168.29.61:8080/api/hdfs/downloadFile?hdfsPath=${encodedPath}&localPath=E:/testdownload/${name}&kalas=${ + currentPath.split("/")[1] || "user" + }`; + + return ( + + + + + + ); + }) + )} + +
+ File Name + + Type + + Action +
+ No files found. +
+ {name} + {type} + {isFile(entry) ? ( + + Download + + ) : ( + + )} +
+
+ ); +}; + +FileTable.propTypes = { + initialPath: PropTypes.string, +}; + +export default FileTable;