diff --git a/frontend/src/pages/RepositoryDetail.jsx b/frontend/src/pages/RepositoryDetail.jsx index 516f703..8253565 100644 --- a/frontend/src/pages/RepositoryDetail.jsx +++ b/frontend/src/pages/RepositoryDetail.jsx @@ -6,17 +6,17 @@ import { Database, Globe, Lock, + Search, Server, Shield, ShieldOff, Unlock, - Users, } from "lucide-react"; -import { useId, useState } from "react"; +import { useId, useMemo, useState } from "react"; -import { Link, useParams } from "react-router-dom"; -import { repositoryAPI } from "../utils/api"; +import { Link, useNavigate, useParams } from "react-router-dom"; +import { formatRelativeTime, repositoryAPI } from "../utils/api"; const RepositoryDetail = () => { const isActiveId = useId(); @@ -25,8 +25,12 @@ const RepositoryDetail = () => { const descriptionId = useId(); const { repositoryId } = useParams(); const queryClient = useQueryClient(); + const navigate = useNavigate(); const [editMode, setEditMode] = useState(false); const [formData, setFormData] = useState({}); + const [searchTerm, setSearchTerm] = useState(""); + const [currentPage, setCurrentPage] = useState(1); + const [pageSize, setPageSize] = useState(25); // Fetch repository details const { @@ -39,6 +43,49 @@ const RepositoryDetail = () => { enabled: !!repositoryId, }); + const hosts = repository?.host_repositories || []; + + // Filter and paginate hosts + const filteredAndPaginatedHosts = useMemo(() => { + let filtered = hosts; + + if (searchTerm) { + filtered = hosts.filter( + (hostRepo) => + hostRepo.hosts.friendly_name + ?.toLowerCase() + .includes(searchTerm.toLowerCase()) || + hostRepo.hosts.hostname + ?.toLowerCase() + .includes(searchTerm.toLowerCase()) || + hostRepo.hosts.ip?.toLowerCase().includes(searchTerm.toLowerCase()), + ); + } + + const startIndex = (currentPage - 1) * pageSize; + const endIndex = startIndex + pageSize; + return filtered.slice(startIndex, endIndex); + }, [hosts, searchTerm, currentPage, pageSize]); + + const totalPages = Math.ceil( + (searchTerm + ? hosts.filter( + (hostRepo) => + hostRepo.hosts.friendly_name + ?.toLowerCase() + .includes(searchTerm.toLowerCase()) || + hostRepo.hosts.hostname + ?.toLowerCase() + .includes(searchTerm.toLowerCase()) || + hostRepo.hosts.ip?.toLowerCase().includes(searchTerm.toLowerCase()), + ).length + : hosts.length) / pageSize, + ); + + const handleHostClick = (hostId) => { + navigate(`/hosts/${hostId}`); + }; + // Update repository mutation const updateRepositoryMutation = useMutation({ mutationFn: (data) => repositoryAPI.update(repositoryId, data), @@ -157,9 +204,6 @@ const RepositoryDetail = () => { {repository.is_active ? "Active" : "Inactive"} -
- Repository configuration and host assignments -
- This repository hasn't been reported by any hosts yet. -
++ {searchTerm + ? "No hosts match your search" + : "This repository hasn't been reported by any hosts yet."} +
+| + Host + | ++ Operating System + | ++ Last Checked + | ++ Last Update + | +
|---|---|---|---|
|
+
+
+
+
+
+
+ {hostRepo.hosts.friendly_name ||
+ hostRepo.hosts.hostname}
+
+ {hostRepo.hosts.friendly_name &&
+ hostRepo.hosts.hostname && (
+
+ {hostRepo.hosts.hostname}
+
+ )}
+ |
+ + {hostRepo.hosts.os_type} {hostRepo.hosts.os_version} + | ++ {hostRepo.last_checked + ? formatRelativeTime(hostRepo.last_checked) + : "Never"} + | ++ {hostRepo.hosts.last_update + ? formatRelativeTime(hostRepo.hosts.last_update) + : "Never"} + | +