style: redesign respository details page (#739)

This commit is contained in:
Nico 2026-04-02 22:51:57 +02:00 committed by GitHub
parent e77723164b
commit 475bfb59ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 281 additions and 218 deletions

View file

@ -8,7 +8,8 @@ import type { GetRepositoryStatsResponse } from "~/client/api-client/types.gen";
import { ByteSize } from "~/client/components/bytes-size"; import { ByteSize } from "~/client/components/bytes-size";
import { useRootLoaderData } from "~/client/hooks/use-root-loader-data"; import { useRootLoaderData } from "~/client/hooks/use-root-loader-data";
import { Button } from "~/client/components/ui/button"; import { Button } from "~/client/components/ui/button";
import { Card, CardContent, CardTitle } from "~/client/components/ui/card"; import { Card, CardTitle } from "~/client/components/ui/card";
import { Separator } from "~/client/components/ui/separator";
import { parseError } from "~/client/lib/errors"; import { parseError } from "~/client/lib/errors";
import { cn } from "~/client/lib/utils"; import { cn } from "~/client/lib/utils";
import { toast } from "sonner"; import { toast } from "sonner";
@ -64,25 +65,25 @@ export function CompressionStatsChart({ repositoryShortId, initialStats }: Props
const hasStats = !!stats && (storedSize > 0 || uncompressedSize > 0 || snapshotsCount > 0); const hasStats = !!stats && (storedSize > 0 || uncompressedSize > 0 || snapshotsCount > 0);
const storedPercent = uncompressedSize > 0 ? (storedSize / uncompressedSize) * 100 : 0;
return ( return (
<Card className="flex flex-col px-6 py-6"> <Card className="flex flex-col px-6 py-6">
<div className="flex items-start justify-between gap-3 pb-4"> <div className="flex items-start justify-between mb-5">
<CardTitle className="flex items-center gap-2 w-full"> <CardTitle className="flex items-center gap-2">
<div className="flex items-center gap-2 flex-1"> <Archive className="h-4 w-4 text-muted-foreground" />
<Archive className="h-5 w-5 text-muted-foreground" /> Compression Statistics
Compression Statistics
</div>
<Button
type="button"
variant="outline"
size="sm"
onClick={() => refreshStats.mutate({ path: { shortId: repositoryShortId } })}
disabled={refreshStats.isPending}
title="Refresh statistics"
>
<RefreshCw className={refreshStats.isPending ? "h-4 w-4 animate-spin" : "h-4 w-4"} />
</Button>
</CardTitle> </CardTitle>
<Button
type="button"
variant="outline"
size="sm"
onClick={() => refreshStats.mutate({ path: { shortId: repositoryShortId } })}
disabled={refreshStats.isPending}
title="Refresh statistics"
>
<RefreshCw className={cn("h-4 w-4", { "animate-spin": refreshStats.isPending })} />
</Button>
</div> </div>
<p className={cn("text-sm text-muted-foreground", { hidden: !isPending })}>Loading compression statistics...</p> <p className={cn("text-sm text-muted-foreground", { hidden: !isPending })}>Loading compression statistics...</p>
<div className={cn("space-y-2", { hidden: !error || isPending })}> <div className={cn("space-y-2", { hidden: !error || isPending })}>
@ -92,58 +93,65 @@ export function CompressionStatsChart({ repositoryShortId, initialStats }: Props
<p className={cn("text-sm text-muted-foreground", { hidden: isPending || !!error || hasStats })}> <p className={cn("text-sm text-muted-foreground", { hidden: isPending || !!error || hasStats })}>
Stats will be populated after your first backup. You can also refresh them manually. Stats will be populated after your first backup. You can also refresh them manually.
</p> </p>
<CardContent <div className={cn({ hidden: isPending || !!error || !hasStats })}>
className={cn("grid grid-cols-2 lg:grid-cols-3 gap-y-6 gap-x-4 px-0", { <div className="space-y-4 mb-6">
hidden: isPending || !!error || !hasStats, <div>
})} <div className="flex items-center justify-between text-sm mb-1.5">
> <span className="text-muted-foreground">Stored</span>
<div className="flex flex-col gap-1.5"> <ByteSize base={1024} bytes={storedSize} className="font-mono font-semibold text-sm" />
<div className="text-sm font-medium text-muted-foreground">Stored Size</div> </div>
<div className="flex items-baseline gap-2"> <div className="h-3 bg-muted/50 rounded-full overflow-hidden">
<ByteSize base={1024} bytes={storedSize} className="text-xl font-semibold text-foreground font-mono" /> <div
className="h-full bg-strong-accent/80 rounded-full transition-all"
style={{ width: `${storedPercent}%` }}
/>
</div>
</div>
<div>
<div className="flex items-center justify-between text-sm mb-1.5">
<span className="text-muted-foreground">Uncompressed</span>
<ByteSize base={1024} bytes={uncompressedSize} className="font-mono font-semibold text-sm" />
</div>
<div className="h-3 bg-muted/50 rounded-full overflow-hidden">
<div className="h-full bg-muted-foreground/30 rounded-full" style={{ width: "100%" }} />
</div>
</div> </div>
</div> </div>
<Separator className="mb-4" />
<div className="flex flex-col gap-1.5"> <div className="grid grid-cols-2 gap-4">
<div className="text-sm font-medium text-muted-foreground">Uncompressed</div> <div className="flex flex-col gap-1.5">
<div className="flex items-baseline gap-2"> <div className="text-sm font-medium text-muted-foreground">Space Saved</div>
<ByteSize <div className="flex items-baseline gap-2">
base={1024} <span className="text-xl font-semibold text-foreground font-mono">{spaceSavingPercent.toFixed(1)}%</span>
bytes={uncompressedSize} <ByteSize base={1024} bytes={savedSize} className="text-xs text-muted-foreground font-mono" />
className="text-xl font-semibold text-foreground font-mono" </div>
/> </div>
<div className="flex flex-col gap-1.5">
<div className="text-sm font-medium text-muted-foreground">Ratio</div>
<div className="flex items-baseline gap-2">
<span className="text-xl font-semibold text-foreground font-mono">
{compressionRatio > 0 ? `${compressionRatio.toFixed(2)}x` : "-"}
</span>
</div>
</div>
<div className="flex flex-col gap-1.5">
<div className="text-sm font-medium text-muted-foreground">Snapshots</div>
<div className="flex items-baseline gap-2">
<span className="text-xl font-semibold text-foreground font-mono">
{snapshotsCount.toLocaleString(locale)}
</span>
</div>
</div>
<div className="flex flex-col gap-1.5">
<div className="text-sm font-medium text-muted-foreground">Compressed</div>
<div className="flex items-baseline gap-2">
<span className="text-xl font-semibold text-foreground font-mono">
{compressionProgressPercent.toFixed(1)}%
</span>
</div>
</div> </div>
</div> </div>
</div>
<div className="flex flex-col gap-1.5">
<div className="text-sm font-medium text-muted-foreground">Space Saved</div>
<div className="flex items-baseline gap-2">
<span className="text-xl font-semibold text-foreground font-mono">{spaceSavingPercent.toFixed(1)}%</span>
<ByteSize base={1024} bytes={savedSize} className="text-xs text-muted-foreground font-mono" />
</div>
</div>
<div className="flex flex-col gap-1.5">
<div className="text-sm font-medium text-muted-foreground">Ratio</div>
<div className="flex items-baseline gap-2">
<span className="text-xl font-semibold text-foreground font-mono">
{compressionRatio > 0 ? `${compressionRatio.toFixed(2)}x` : "-"}
</span>
</div>
</div>
<div className="flex flex-col gap-1.5 lg:col-span-2">
<div className="text-sm font-medium text-muted-foreground">Snapshots</div>
<div className="flex items-baseline gap-2">
<span className="text-xl font-semibold text-foreground font-mono">
{snapshotsCount.toLocaleString(locale)}
</span>
<span className="text-xs text-muted-foreground font-mono">
{compressionProgressPercent.toFixed(1)}% compressed
</span>
</div>
</div>
</CardContent>
</Card> </Card>
); );
} }

View file

@ -1,9 +1,27 @@
import { useMutation } from "@tanstack/react-query"; import { useMutation } from "@tanstack/react-query";
import { useState } from "react"; import { useState } from "react";
import { toast } from "sonner"; import { toast } from "sonner";
import { ChevronDown, Pencil, Square, Stethoscope, Trash2, Unlock } from "lucide-react"; import {
Archive,
ChevronDown,
Clock,
Database,
FolderOpen,
Globe,
HardDrive,
Lock,
Pencil,
Settings,
Shield,
Square,
Stethoscope,
Trash2,
Unlock,
} from "lucide-react";
import { Card, CardContent, CardTitle } from "~/client/components/ui/card"; import { Card, CardContent, CardTitle } from "~/client/components/ui/card";
import { Badge } from "~/client/components/ui/badge";
import { Button } from "~/client/components/ui/button"; import { Button } from "~/client/components/ui/button";
import { Separator } from "~/client/components/ui/separator";
import { import {
AlertDialog, AlertDialog,
AlertDialogAction, AlertDialogAction,
@ -29,14 +47,12 @@ import {
unlockRepositoryMutation, unlockRepositoryMutation,
} from "~/client/api-client/@tanstack/react-query.gen"; } from "~/client/api-client/@tanstack/react-query.gen";
import type { RepositoryConfig } from "@zerobyte/core/restic"; import type { RepositoryConfig } from "@zerobyte/core/restic";
import { TimeAgo } from "~/client/components/time-ago";
import { useTimeFormat } from "~/client/lib/datetime"; import { useTimeFormat } from "~/client/lib/datetime";
import { DoctorReport } from "../components/doctor-report"; import { DoctorReport } from "../components/doctor-report";
import { parseError } from "~/client/lib/errors"; import { parseError } from "~/client/lib/errors";
import { useNavigate } from "@tanstack/react-router"; import { useNavigate } from "@tanstack/react-router";
import { CompressionStatsChart } from "../components/compression-stats-chart"; import { CompressionStatsChart } from "../components/compression-stats-chart";
import { cn } from "~/client/lib/utils"; import { cn } from "~/client/lib/utils";
import { ManagedBadge } from "~/client/components/managed-badge";
type Props = { type Props = {
repository: Repository; repository: Repository;
@ -48,8 +64,21 @@ const getEffectiveLocalPath = (repository: Repository): string | null => {
return repository.config.path; return repository.config.path;
}; };
type ConfigRowProps = { icon: React.ReactNode; label: string; value: string; mono?: boolean; valueClassName?: string };
function ConfigRow({ icon, label, value, mono, valueClassName }: ConfigRowProps) {
return (
<div className="flex items-center gap-3 py-3 first:pt-0 last:pb-0">
<span className="text-muted-foreground shrink-0">{icon}</span>
<span className="text-sm text-muted-foreground w-40 shrink-0">{label}</span>
<span className={cn("text-sm break-all", { "font-mono bg-muted/50 px-2 py-0.5 rounded": mono }, valueClassName)}>
{value}
</span>
</div>
);
}
export const RepositoryInfoTabContent = ({ repository, initialStats }: Props) => { export const RepositoryInfoTabContent = ({ repository, initialStats }: Props) => {
const { formatDateTime } = useTimeFormat(); const { formatDateTime, formatTimeAgo } = useTimeFormat();
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
@ -104,173 +133,199 @@ export const RepositoryInfoTabContent = ({ repository, initialStats }: Props) =>
const hasCaCert = Boolean(config.cacert); const hasCaCert = Boolean(config.cacert);
const hasLastError = Boolean(repository.lastError); const hasLastError = Boolean(repository.lastError);
const hasInsecureTlsConfig = config.insecureTls !== undefined; const hasInsecureTlsConfig = config.insecureTls !== undefined;
const isTlsValidationDisabled = config.insecureTls === true;
return ( return (
<> <>
<div className="flex flex-col gap-6 @container"> <div className="flex flex-col gap-6 @container">
<div className="flex flex-col @medium:flex-row items-start @medium:items-center justify-between gap-4"> <Card className="px-6 py-5">
<div> <div className="flex flex-col @wide:flex-row @wide:items-center justify-between gap-4">
<div className="flex items-center gap-2"> <div className="flex items-center gap-4">
<h2 className="text-lg font-semibold tracking-tight">Repository Settings</h2> <div className="hidden @medium:flex items-center justify-center w-10 h-10 rounded-lg bg-muted/50 border border-border/50">
{repository.provisioningId && <ManagedBadge />} <Database className="h-5 w-5 text-muted-foreground" />
</div> </div>
</div> <div>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
{isDoctorRunning ? ( <h2 className="text-lg font-semibold tracking-tight">{repository.name}</h2>
<Button <Separator orientation="vertical" className="h-4 mx-1" />
type="button" <Badge variant="outline" className="capitalize gap-1.5">
variant="destructive"
loading={cancelDoctor.isPending}
onClick={() => cancelDoctor.mutate({ path: { shortId: repository.shortId } })}
>
<Square className="h-4 w-4 mr-2" />
Cancel doctor
</Button>
) : (
<Button
type="button"
variant="outline"
onClick={() => startDoctor.mutate({ path: { shortId: repository.shortId } })}
disabled={startDoctor.isPending}
>
<Stethoscope className="h-4 w-4 mr-2" />
Run doctor
</Button>
)}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline">
Actions
<ChevronDown className="h-4 w-4 ml-1" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => navigate({ to: `/repositories/${repository.shortId}/edit` })}>
<Pencil />
Edit
</DropdownMenuItem>
<DropdownMenuItem
onClick={() =>
toast.promise(unlockRepo.mutateAsync({ path: { shortId: repository.shortId } }), {
loading: "Unlocking repo",
success: "Repository unlocked successfully",
error: (e) => parseError(e)?.message || "Failed to unlock repository",
})
}
disabled={unlockRepo.isPending}
>
<Unlock />
Unlock
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
variant="destructive"
onClick={() => setShowDeleteConfirm(true)}
disabled={deleteRepo.isPending}
>
<Trash2 />
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<div className="grid grid-cols-1 @wide:grid-cols-2 gap-6 items-stretch">
<div className="flex flex-col gap-6">
<Card className="px-6 py-6">
<CardTitle>Overview</CardTitle>
<CardContent className="grid grid-cols-1 @medium:grid-cols-2 gap-y-6 gap-x-4 px-0">
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Name</div>
<p className="text-sm">{repository.name}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Backend</div>
<p className="text-sm">{repository.type}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Management</div>
<p className="text-sm">{repository.provisioningId ? "Provisioned" : "Manual"}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Compression Mode</div>
<p className="text-sm">{repository.compressionMode || "off"}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Created</div>
<p className="text-sm">{formatDateTime(repository.createdAt)}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Status</div>
<p className="text-sm flex items-center gap-2">
<span <span
className={cn("w-2 h-2 rounded-full", { className={cn("w-2 h-2 rounded-full shrink-0", {
"bg-success": repository.status === "healthy", "bg-success": repository.status === "healthy",
"bg-red-500": repository.status === "error", "bg-red-500": repository.status === "error",
"bg-amber-500": repository.status !== "healthy" && repository.status !== "error", "bg-amber-500": repository.status !== "healthy" && repository.status !== "error",
"animate-pulse": repository.status === "doctor", "animate-pulse": repository.status === "doctor",
})} })}
/> />
<span className="capitalize">{repository.status || "Unknown"}</span> {repository.status || "Unknown"}
</p> </Badge>
<Badge variant="secondary">{repository.type}</Badge>
{repository.provisioningId && <Badge variant="secondary">Managed</Badge>}
</div> </div>
<div className="flex flex-col gap-1"> <p className="text-sm text-muted-foreground mt-0.5">
<div className="text-sm font-medium text-muted-foreground">Last Checked</div> Created {formatDateTime(repository.createdAt)} &middot; Last checked&nbsp;
<TimeAgo date={repository.lastChecked} className="text-sm" /> {formatTimeAgo(repository.lastChecked)}
</div> </p>
{hasLocalPath && ( </div>
<div className="flex flex-col gap-1 @medium:col-span-2"> </div>
<div className="text-sm font-medium text-muted-foreground">Local Path</div> <div className="flex items-center gap-2">
<p className="text-sm font-mono bg-muted/50 p-2 rounded-md break-all">{effectiveLocalPath}</p> {isDoctorRunning ? (
</div> <Button
)} type="button"
{hasCaCert && ( variant="destructive"
<div className="flex flex-col gap-1"> loading={cancelDoctor.isPending}
<div className="text-sm font-medium text-muted-foreground">CA Certificate</div> onClick={() => cancelDoctor.mutate({ path: { shortId: repository.shortId } })}
<p className="text-sm text-success">Configured</p> >
</div> <Square className="h-4 w-4 mr-2" />
)} Cancel doctor
{hasInsecureTlsConfig && ( </Button>
<div className="flex flex-col gap-1"> ) : (
<div className="text-sm font-medium text-muted-foreground">TLS Validation</div> <Button
<p className="text-sm"> type="button"
<span className={cn("text-red-500", { hidden: !isTlsValidationDisabled })}>Disabled</span> variant="outline"
<span className={cn("text-success", { hidden: isTlsValidationDisabled })}>Enabled</span> onClick={() => startDoctor.mutate({ path: { shortId: repository.shortId } })}
</p> disabled={startDoctor.isPending}
</div> >
)} <Stethoscope className="h-4 w-4 mr-2" />
</CardContent> Run doctor
</Card> </Button>
)}
{hasLastError && ( <DropdownMenu>
<Card className="flex flex-col px-6 py-6"> <DropdownMenuTrigger asChild>
<div className="space-y-2"> <Button variant="outline">
<p className="text-sm font-medium text-destructive">Last Error</p> Actions
<p className="text-sm text-muted-foreground wrap-break-word">{repository.lastError}</p> <ChevronDown className="h-4 w-4 ml-1" />
</div> </Button>
</Card> </DropdownMenuTrigger>
)} <DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => navigate({ to: `/repositories/${repository.shortId}/edit` })}>
<div className="flex-1 flex flex-col"> <Pencil />
<DoctorReport repositoryStatus={repository.status} result={repository.doctorResult} /> Edit
</DropdownMenuItem>
<DropdownMenuItem
onClick={() =>
toast.promise(unlockRepo.mutateAsync({ path: { shortId: repository.shortId } }), {
loading: "Unlocking repo",
success: "Repository unlocked successfully",
error: (e) => parseError(e)?.message || "Failed to unlock repository",
})
}
disabled={unlockRepo.isPending}
>
<Unlock />
Unlock
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
variant="destructive"
onClick={() => setShowDeleteConfirm(true)}
disabled={deleteRepo.isPending}
>
<Trash2 />
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div> </div>
</div> </div>
</Card>
<div className="flex flex-col gap-6"> {hasLastError && (
<CompressionStatsChart repositoryShortId={repository.shortId} initialStats={initialStats} /> <Card className="px-6 py-6">
<div className="space-y-2">
<p className="text-sm font-medium text-destructive">Last Error</p>
<p className="text-sm text-muted-foreground wrap-break-word">{repository.lastError}</p>
</div>
</Card>
)}
<Card className="px-6 py-6 flex-1"> <div className="grid grid-cols-1 @wide:grid-cols-2 gap-6">
<CardTitle>Configuration</CardTitle> <CompressionStatsChart repositoryShortId={repository.shortId} initialStats={initialStats} />
<div className="bg-muted/50 rounded-md p-4 max-w-full">
<pre className="text-sm overflow-auto font-mono whitespace-pre-wrap"> <Card className="px-6 py-6">
{JSON.stringify(repository.config, null, 2)} <CardTitle className="mb-4">Overview</CardTitle>
</pre> <CardContent className="grid grid-cols-2 gap-y-4 gap-x-6 px-0">
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Name</div>
<p className="text-sm">{repository.name}</p>
</div> </div>
</Card> <div className="flex flex-col gap-1">
</div> <div className="text-sm font-medium text-muted-foreground">Backend</div>
<p className="text-sm">{repository.type}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Management</div>
<p className="text-sm">{repository.provisioningId ? "Provisioned" : "Manual"}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Compression Mode</div>
<p className="text-sm">{repository.compressionMode || "off"}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Created</div>
<p className="text-sm">{formatDateTime(repository.createdAt)}</p>
</div>
<div className="flex flex-col gap-1">
<div className="text-sm font-medium text-muted-foreground">Last Checked</div>
<p className="text-sm flex items-center gap-1.5">
<Clock className="h-3 w-3 text-muted-foreground" />
{formatTimeAgo(repository.lastChecked)}
</p>
</div>
{hasLocalPath && (
<div className="flex flex-col gap-1 col-span-2">
<div className="text-sm font-medium text-muted-foreground">Local Path</div>
<p className="text-sm font-mono bg-muted/50 p-2 rounded-md break-all">{effectiveLocalPath}</p>
</div>
)}
</CardContent>
</Card>
</div> </div>
<Card className="px-6 py-6">
<CardTitle className="flex items-center gap-2 mb-5">
<Settings className="h-4 w-4 text-muted-foreground" />
Configuration
</CardTitle>
<div className="space-y-0 divide-y divide-border/50">
<ConfigRow icon={<HardDrive className="h-4 w-4" />} label="Backend" value={repository.type} />
{hasLocalPath && (
<ConfigRow
icon={<FolderOpen className="h-4 w-4" />}
label="Local Path"
value={effectiveLocalPath!}
mono
/>
)}
<ConfigRow
icon={<Archive className="h-4 w-4" />}
label="Compression Mode"
value={repository.compressionMode || "off"}
/>
<ConfigRow
icon={<Globe className="h-4 w-4" />}
label="Management"
value={repository.provisioningId ? "Provisioned" : "Manual"}
/>
{hasCaCert && (
<ConfigRow
icon={<Lock className="h-4 w-4" />}
label="CA Certificate"
value="Configured"
valueClassName="text-success"
/>
)}
{hasInsecureTlsConfig && (
<ConfigRow
icon={<Shield className="h-4 w-4" />}
label="TLS Validation"
value={config.insecureTls ? "Disabled" : "Enabled"}
valueClassName={config.insecureTls ? "text-red-500" : "text-success"}
/>
)}
</div>
</Card>
<DoctorReport repositoryStatus={repository.status} result={repository.doctorResult} />
</div> </div>
<AlertDialog open={showDeleteConfirm} onOpenChange={setShowDeleteConfirm}> <AlertDialog open={showDeleteConfirm} onOpenChange={setShowDeleteConfirm}>