import { useQuery } from "@tanstack/react-query"; import { Database } from "lucide-react"; import { useState } from "react"; import { listSnapshotsOptions } from "~/client/api-client/@tanstack/react-query.gen"; import { SnapshotsTable } from "~/client/components/snapshots-table"; import { Button } from "~/client/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "~/client/components/ui/card"; import { Input } from "~/client/components/ui/input"; import { Table, TableBody, TableCell, TableRow } from "~/client/components/ui/table"; import type { Repository, Snapshot } from "~/client/lib/types"; type Props = { repository: Repository; }; export const RepositorySnapshotsTabContent = ({ repository }: Props) => { const [searchQuery, setSearchQuery] = useState(""); const { data, isFetching, failureReason } = useQuery({ ...listSnapshotsOptions({ path: { name: repository.name } }), refetchInterval: 10000, refetchOnWindowFocus: true, initialData: [], }); const filteredSnapshots = data.filter((snapshot: Snapshot) => { if (!searchQuery) return true; const searchLower = searchQuery.toLowerCase(); return ( snapshot.short_id.toLowerCase().includes(searchLower) || snapshot.paths.some((path) => path.toLowerCase().includes(searchLower)) ); }); const hasNoFilteredSnapshots = !filteredSnapshots?.length; if (repository.status === "error") { return (

Repository Error

This repository is in an error state and cannot be accessed.

{repository.lastError && (

{repository.lastError}

)}
); } if (failureReason) { return (

Failed to Load Snapshots

{failureReason.message}

); } if (isFetching && !data.length) { return (

Loading snapshots

); } if (!data.length) { return (

No snapshots yet

Snapshots are point-in-time backups of your data. Create your first backup to see it here.

); } return (
Snapshots Backup snapshots stored in this repository. Total: {data.length}
setSearchQuery(e.target.value)} />
{hasNoFilteredSnapshots ? (

No snapshots match your search.

) : ( )}
{hasNoFilteredSnapshots ? "No snapshots match filters." : `Showing ${filteredSnapshots.length} of ${data.length}`}
); };