Merge branch 'tvarohohlavy-snapshots-table-and-detail-enhancement'
This commit is contained in:
commit
3a54f11b6d
4 changed files with 87 additions and 29 deletions
|
|
@ -1,11 +1,10 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { Calendar, Clock, Database, FolderTree, HardDrive, Trash2 } from "lucide-react";
|
import { Calendar, Clock, Database, HardDrive, Server, Trash2 } from "lucide-react";
|
||||||
import { Link, useNavigate } from "react-router";
|
import { Link, useNavigate } from "react-router";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { ByteSize } from "~/client/components/bytes-size";
|
import { ByteSize } from "~/client/components/bytes-size";
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table";
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table";
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from "~/client/components/ui/tooltip";
|
|
||||||
import { Button } from "~/client/components/ui/button";
|
import { Button } from "~/client/components/ui/button";
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
|
|
@ -21,6 +20,7 @@ import { formatDuration } from "~/utils/utils";
|
||||||
import { deleteSnapshotMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
import { deleteSnapshotMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
import { parseError } from "~/client/lib/errors";
|
import { parseError } from "~/client/lib/errors";
|
||||||
import type { BackupSchedule, Snapshot } from "../lib/types";
|
import type { BackupSchedule, Snapshot } from "../lib/types";
|
||||||
|
import { cn } from "../lib/utils";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
snapshots: Snapshot[];
|
snapshots: Snapshot[];
|
||||||
|
|
@ -79,7 +79,7 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
<TableHead className="uppercase">Date & Time</TableHead>
|
<TableHead className="uppercase">Date & Time</TableHead>
|
||||||
<TableHead className="uppercase">Size</TableHead>
|
<TableHead className="uppercase">Size</TableHead>
|
||||||
<TableHead className="uppercase hidden md:table-cell text-right">Duration</TableHead>
|
<TableHead className="uppercase hidden md:table-cell text-right">Duration</TableHead>
|
||||||
<TableHead className="uppercase hidden text-right lg:table-cell">Paths</TableHead>
|
<TableHead className="uppercase hidden text-right lg:table-cell">Volume</TableHead>
|
||||||
<TableHead className="uppercase text-right">Actions</TableHead>
|
<TableHead className="uppercase text-right">Actions</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
@ -108,7 +108,7 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
className="hover:underline"
|
className="hover:underline"
|
||||||
>
|
>
|
||||||
<span className="text-sm">{backup ? backup.id : "-"}</span>
|
<span className="text-sm">{backup ? backup.name : "-"}</span>
|
||||||
</Link>
|
</Link>
|
||||||
<span hidden={!!backup} className="text-sm text-muted-foreground">
|
<span hidden={!!backup} className="text-sm text-muted-foreground">
|
||||||
-
|
-
|
||||||
|
|
@ -137,23 +137,18 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="hidden lg:table-cell">
|
<TableCell className="hidden lg:table-cell">
|
||||||
<div className="flex items-center justify-end gap-2">
|
<div className="flex items-center justify-end gap-2">
|
||||||
<FolderTree className="h-4 w-4 text-muted-foreground" />
|
<Server className={cn("h-4 w-4 text-muted-foreground", { hidden: !backup })} />
|
||||||
<Tooltip>
|
<Link
|
||||||
<TooltipTrigger asChild>
|
hidden={!backup}
|
||||||
<span className="text-xs bg-primary/10 text-primary rounded-md px-2 py-1 cursor-help">
|
to={backup ? `/volumes/${backup.volume.name}` : "#"}
|
||||||
{snapshot.paths.length} {snapshot.paths.length === 1 ? "path" : "paths"}
|
onClick={(e) => e.stopPropagation()}
|
||||||
</span>
|
className="hover:underline"
|
||||||
</TooltipTrigger>
|
>
|
||||||
<TooltipContent side="top" className="max-w-md">
|
<span className="text-sm">{backup ? backup.volume.name : "-"}</span>
|
||||||
<div className="flex flex-col gap-1">
|
</Link>
|
||||||
{snapshot.paths.map((path) => (
|
<span hidden={!!backup} className="text-sm text-muted-foreground">
|
||||||
<div key={`${snapshot.short_id}-${path}`} className="text-xs font-mono">
|
-
|
||||||
{path}
|
</span>
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-right">
|
<TableCell className="text-right">
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { Button, buttonVariants } from "~/client/components/ui/button";
|
||||||
import type { Snapshot } from "~/client/lib/types";
|
import type { Snapshot } from "~/client/lib/types";
|
||||||
import { listSnapshotFilesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
import { listSnapshotFilesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
import { useFileBrowser } from "~/client/hooks/use-file-browser";
|
import { useFileBrowser } from "~/client/hooks/use-file-browser";
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
snapshot: Snapshot;
|
snapshot: Snapshot;
|
||||||
|
|
@ -87,7 +88,9 @@ export const SnapshotFileBrowser = (props: Props) => {
|
||||||
<div className="flex items-start justify-between">
|
<div className="flex items-start justify-between">
|
||||||
<div>
|
<div>
|
||||||
<CardTitle>File Browser</CardTitle>
|
<CardTitle>File Browser</CardTitle>
|
||||||
<CardDescription>{`Viewing snapshot from ${new Date(snapshot?.time ?? 0).toLocaleString()}`}</CardDescription>
|
<CardDescription
|
||||||
|
className={cn({ hidden: !snapshot.time })}
|
||||||
|
>{`Viewing snapshot from ${new Date(snapshot?.time ?? 0).toLocaleString()}`}</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Link
|
<Link
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { redirect, useParams } from "react-router";
|
import { redirect, useParams, Link, Await } from "react-router";
|
||||||
import { listSnapshotFilesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
import { listBackupSchedulesOptions, listSnapshotFilesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card";
|
||||||
import { SnapshotFileBrowser } from "~/client/modules/backups/components/snapshot-file-browser";
|
import { SnapshotFileBrowser } from "~/client/modules/backups/components/snapshot-file-browser";
|
||||||
import { getRepository, getSnapshotDetails } from "~/client/api-client";
|
import { getRepository, getSnapshotDetails } from "~/client/api-client";
|
||||||
import type { Route } from "./+types/snapshot-details";
|
import type { Route } from "./+types/snapshot-details";
|
||||||
|
import { Suspense } from "react";
|
||||||
|
|
||||||
export const handle = {
|
export const handle = {
|
||||||
breadcrumb: (match: Route.MetaArgs) => [
|
breadcrumb: (match: Route.MetaArgs) => [
|
||||||
|
|
@ -25,15 +26,14 @@ export function meta({ params }: Route.MetaArgs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const clientLoader = async ({ params }: Route.ClientLoaderArgs) => {
|
export const clientLoader = async ({ params }: Route.ClientLoaderArgs) => {
|
||||||
const snapshot = await getSnapshotDetails({
|
const snapshot = getSnapshotDetails({
|
||||||
path: { id: params.id, snapshotId: params.snapshotId },
|
path: { id: params.id, snapshotId: params.snapshotId },
|
||||||
});
|
});
|
||||||
if (!snapshot.data) return redirect("/repositories");
|
|
||||||
|
|
||||||
const repository = await getRepository({ path: { id: params.id } });
|
const repository = await getRepository({ path: { id: params.id } });
|
||||||
if (!repository.data) return redirect("/repositories");
|
if (!repository.data) return redirect("/repositories");
|
||||||
|
|
||||||
return { snapshot: snapshot.data, repository: repository.data };
|
return { snapshot: snapshot, repository: repository.data };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function SnapshotDetailsPage({ loaderData }: Route.ComponentProps) {
|
export default function SnapshotDetailsPage({ loaderData }: Route.ComponentProps) {
|
||||||
|
|
@ -50,6 +50,10 @@ export default function SnapshotDetailsPage({ loaderData }: Route.ComponentProps
|
||||||
enabled: !!id && !!snapshotId,
|
enabled: !!id && !!snapshotId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const schedules = useQuery({
|
||||||
|
...listBackupSchedulesOptions(),
|
||||||
|
});
|
||||||
|
|
||||||
if (!id || !snapshotId) {
|
if (!id || !snapshotId) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-center h-full">
|
<div className="flex items-center justify-center h-full">
|
||||||
|
|
@ -67,7 +71,22 @@ export default function SnapshotDetailsPage({ loaderData }: Route.ComponentProps
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<SnapshotFileBrowser repositoryId={id} snapshot={loaderData.snapshot} />
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<SnapshotFileBrowser
|
||||||
|
repositoryId={id}
|
||||||
|
snapshot={{ duration: 0, paths: [], short_id: "", size: 0, tags: [], time: 0 }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Await resolve={loaderData.snapshot}>
|
||||||
|
{(value) => {
|
||||||
|
if (!value.data) return <div className="text-destructive">Snapshot data not found.</div>;
|
||||||
|
|
||||||
|
return <SnapshotFileBrowser repositoryId={id} snapshot={value.data} />;
|
||||||
|
}}
|
||||||
|
</Await>
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
{data?.snapshot && (
|
{data?.snapshot && (
|
||||||
<Card>
|
<Card>
|
||||||
|
|
@ -92,6 +111,41 @@ export default function SnapshotDetailsPage({ loaderData }: Route.ComponentProps
|
||||||
<span className="text-muted-foreground">Time:</span>
|
<span className="text-muted-foreground">Time:</span>
|
||||||
<p>{new Date(data.snapshot.time).toLocaleString()}</p>
|
<p>{new Date(data.snapshot.time).toLocaleString()}</p>
|
||||||
</div>
|
</div>
|
||||||
|
<Suspense fallback={<div>Loading...</div>}>
|
||||||
|
<Await resolve={loaderData.snapshot}>
|
||||||
|
{(value) => {
|
||||||
|
if (!value.data) return null;
|
||||||
|
|
||||||
|
const backupIds = value.data.tags.map(Number).filter((tag) => !Number.isNaN(tag));
|
||||||
|
const backupSchedule = schedules.data?.find((s) => backupIds.includes(s.id));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
<span className="text-muted-foreground">Backup Schedule:</span>
|
||||||
|
<p>
|
||||||
|
<Link to={`/backups/${backupSchedule?.id}`} className="text-primary hover:underline">
|
||||||
|
{backupSchedule?.name}
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span className="text-muted-foreground">Volume:</span>
|
||||||
|
<p>
|
||||||
|
<Link
|
||||||
|
to={`/volumes/${backupSchedule?.volume.name}`}
|
||||||
|
className="text-primary hover:underline"
|
||||||
|
>
|
||||||
|
{backupSchedule?.volume.name}
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Await>
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
<div className="col-span-2">
|
<div className="col-span-2">
|
||||||
<span className="text-muted-foreground">Paths:</span>
|
<span className="text-muted-foreground">Paths:</span>
|
||||||
<div className="space-y-1 mt-1">
|
<div className="space-y-1 mt-1">
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,15 @@ export const RepositorySnapshotsTabContent = ({ repository }: Props) => {
|
||||||
const filteredSnapshots = data.filter((snapshot: Snapshot) => {
|
const filteredSnapshots = data.filter((snapshot: Snapshot) => {
|
||||||
if (!searchQuery) return true;
|
if (!searchQuery) return true;
|
||||||
const searchLower = searchQuery.toLowerCase();
|
const searchLower = searchQuery.toLowerCase();
|
||||||
|
|
||||||
|
const backupIds = snapshot.tags.map(Number).filter((tag) => !Number.isNaN(tag));
|
||||||
|
const backup = schedules.data?.find((b) => backupIds.includes(b.id));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
snapshot.short_id.toLowerCase().includes(searchLower) ||
|
snapshot.short_id.toLowerCase().includes(searchLower) ||
|
||||||
snapshot.paths.some((path) => path.toLowerCase().includes(searchLower))
|
snapshot.paths.some((path) => path.toLowerCase().includes(searchLower)) ||
|
||||||
|
backup?.name?.toLowerCase().includes(searchLower) ||
|
||||||
|
backup?.volume?.name?.toLowerCase().includes(searchLower)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue