Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions web/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,55 @@ import { Providers } from "./providers";
import stylesheet from "./globals.css?url";

export const links: LinksFunction = () => [
{
rel: "stylesheet",
href: "https://fonts.googleapis.com/css2?family=Geist:wght@100..900&family=Geist+Mono:wght@100..900&display=swap",
},
{ rel: "stylesheet", href: stylesheet },
{
rel: "icon",
href: "/icon-light-32x32.png",
media: "(prefers-color-scheme: light)",
},
{
rel: "icon",
href: "/icon-dark-32x32.png",
media: "(prefers-color-scheme: dark)",
},
{
rel: "icon",
href: "/icon.svg",
type: "image/svg+xml",
},
{
rel: "apple-touch-icon",
href: "/apple-icon.png",
},
{
rel: "stylesheet",
href: "https://fonts.googleapis.com/css2?family=Geist:wght@100..900&family=Geist+Mono:wght@100..900&display=swap",
},
{ rel: "stylesheet", href: stylesheet },
{
rel: "icon",
href: "/icon.png",
media: "(prefers-color-scheme: light)",
},
{
rel: "icon",
href: "/icon.png",
media: "(prefers-color-scheme: dark)",
},
{
rel: "icon",
href: "/icon.png",
type: "image/png",
},
{
rel: "apple-touch-icon",
href: "/apple-icon.png",
},
];

export const meta: MetaFunction = () => [
{ title: "Webhook Dashboard" },
{ name: "description", content: "Manage webhook endpoints and deliveries" },
{ title: "Webhook Dashboard" },
{ name: "description", content: "Manage webhook endpoints and deliveries" },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body className="font-sans antialiased">
<Providers>{children}</Providers>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
return (
<html lang="en" suppressHydrationWarning>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body className="font-sans antialiased">
<Providers>{children}</Providers>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
return <Outlet />;
}
24 changes: 19 additions & 5 deletions web/app/routes/logs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getLogs } from "@/lib/api";
import type { Log } from "@/lib/types";
import { getLogs, getWebhooks } from "@/lib/api";
import type { LogWithWebhook } from "@/lib/types";
import { LogsPage } from "@/components/pages/logs";
import { Skeleton } from "@/components/ui/skeleton";

Expand All @@ -9,8 +9,22 @@ export async function clientLoader({ request }: { request: Request }) {
const url = new URL(request.url);
const page = Number(url.searchParams.get("page")) || 0;
const limit = Number(url.searchParams.get("limit")) || DEFAULT_LIMIT;
const logs = await getLogs({ page, limit });
return { logs, page, limit };
const [logs, webhooks] = await Promise.all([
getLogs({ page, limit }),
getWebhooks({ limit: 200 }),
]);
const webhookNames = new Map(
webhooks.map((webhook) => [webhook.id, webhook.name])
);

const logsWithWebhooks: LogWithWebhook[] = logs.map((log) => ({
...log,
webhook_name: log.webhook_id
? webhookNames.get(log.webhook_id) ?? "Deleted webhook"
: null,
}));

return { logs: logsWithWebhooks, page, limit };
}

export function HydrateFallback() {
Expand Down Expand Up @@ -39,7 +53,7 @@ export function HydrateFallback() {
export default function Logs({
loaderData,
}: {
loaderData: { logs: Log[]; page: number; limit: number };
loaderData: { logs: LogWithWebhook[]; page: number; limit: number };
}) {
return (
<LogsPage
Expand Down
2 changes: 1 addition & 1 deletion web/components/logs-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function LogsFilter({ logLevel, onLogLevelChange }: LogsFilterProps) {
return (
<Tabs value={logLevel} onValueChange={onLogLevelChange}>
<TabsList className=" justify-start p-1">
{["all", "info", "warn", "error"].map((level) => (
{["all", "debug", "info", "warn", "error"].map((level) => (
<TabsTrigger
key={level}
value={level}
Expand Down
168 changes: 113 additions & 55 deletions web/components/logs-list.tsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,130 @@
import { FileText } from "lucide-react";
import { Link } from "react-router";
import { Card } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";
import {
Table,
TableBody,
TableCell,
TableHeader,
TableRow,
Table,
TableBody,
TableCell,
TableHeader,
TableRow,
} from "@/components/ui/table";
import type { Log } from "@/lib/types";
import type { LogWithWebhook } from "@/lib/types";

const levelDot: Record<string, string> = {
info: "bg-muted-foreground/70",
warn: "bg-yellow-500/80",
error: "bg-red-500/80",
trace: "bg-sky-500/80",
debug: "bg-blue-500/80",
info: "bg-muted-foreground/70",
warn: "bg-yellow-500/80",
error: "bg-red-500/80",
};

const levelText: Record<string, string> = {
trace: "text-sky-500",
debug: "text-blue-500",
info: "text-muted-foreground",
warn: "text-yellow-500",
error: "text-red-500",
};

interface LogsListProps {
logs: Log[];
logs: LogWithWebhook[];
}

function truncate(value: string, maxLength = 28) {
return value.length > maxLength
? `${value.slice(0, maxLength - 1)}...`
: value;
}

export function LogsList({ logs }: LogsListProps) {
if (logs.length === 0) {
return (
<Card className="rounded-2xl border w-full">
<div className="flex flex-col items-center justify-center py-16 text-center">
<FileText
className="h-10 w-10 text-muted-foreground/40 mb-3"
strokeWidth={1.5}
/>
<h3 className="text-sm font-medium text-foreground">No logs</h3>
<p className="text-sm text-muted-foreground mt-1">
Logs will appear here as activity occurs.
</p>
</div>
</Card>
);
}
if (logs.length === 0) {
return (
<Card className="w-full rounded-2xl border">
<div className="flex flex-col items-center justify-center px-6 py-16 text-center">
<div className="mb-4 rounded-full border bg-muted/30 p-3">
<FileText
className="h-6 w-6 text-muted-foreground/50"
strokeWidth={1.75}
/>
</div>

<h3 className="text-sm font-medium text-foreground">No logs yet</h3>

<p className="mt-1 max-w-sm text-sm text-muted-foreground">
Webhook activity and system events will appear here.
</p>
</div>
</Card>
);
}

return (
<Card className="w-full overflow-hidden rounded-2xl border">
<ScrollArea className="h-fit">
<Table className="w-full text-sm">
<TableHeader className="sr-only" />

<TableBody>
{logs.map((log) => (
<TableRow
key={log.id}
className="group border-border/60 transition-colors hover:bg-muted/35"
>
<TableCell className="w-4 py-3 pl-4 pr-2">
<span
className={`inline-block h-2 w-2 rounded-full ${
levelDot[log.level] ?? "bg-muted-foreground/70"
}`}
/>
</TableCell>

<TableCell className="w-[125px] max-w-[125px] py-3 text-xs text-muted-foreground/70">
<span className="block truncate" title={log.timestamp}>
{log.timestamp}
</span>
</TableCell>

<TableCell className="w-[170px] max-w-[170px] py-3">
{log.webhook_id && log.webhook_name ? (
<Link
to={`/webhooks/${log.webhook_id}`}
title={log.webhook_name}
className="block truncate text-sm font-medium text-foreground hover:underline"
>
{truncate(log.webhook_name)}
</Link>
) : (
<span className="block truncate text-sm font-medium text-foreground">
System
</span>
)}
</TableCell>

return (
<Card className="rounded-2xl border w-full">
<ScrollArea className="h-fit">
<Table className="w-full text-sm font-mono">
<TableHeader className="sr-only" />
<TableBody>
{logs.map((log) => (
<TableRow
key={log.id}
className="hover:bg-muted/30 transition-colors"
>
<TableCell className="w-[10px] pr-2">
<span
className={`inline-block h-2 w-2 rounded-full ${levelDot[log.level] ?? "bg-muted-foreground/70"}`}
/>
</TableCell>
<TableCell className="w-[210px] max-w-[210px] py-3 font-mono text-xs text-muted-foreground/70">
<span className="block truncate" title={log.target}>
{log.target}
</span>
</TableCell>

<TableCell className="w-[110px] text-xs text-muted-foreground/70">
{log.timestamp}
</TableCell>
<TableCell className="w-[68px] py-3">
<span
className={`rounded-md bg-muted px-1.5 py-0.5 ${levelText[log.level]} font-mono text-[10px] uppercase tracking-wide`}
>
{log.level}
</span>
</TableCell>

<TableCell className="text-sm text-foreground whitespace-normal">
{log.message}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</ScrollArea>
</Card>
);
<TableCell className="max-w-0 py-3 pr-4 text-sm text-foreground">
<span className="block truncate" title={log.message}>
{log.message}
</span>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</ScrollArea>
</Card>
);
}
13 changes: 11 additions & 2 deletions web/components/pages/edit-webhook.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Form, useActionData, useNavigate, useNavigation } from "react-router";
import { ArrowLeft } from "lucide-react";
import { ArrowLeft, Save } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
Expand All @@ -12,6 +12,7 @@ import {
CardTitle,
} from "@/components/ui/card";
import type { Webhook } from "@/lib/types";
import { Spinner } from "../ui/spinner";

interface EditWebhookPageProps {
webhook: Webhook;
Expand Down Expand Up @@ -104,7 +105,15 @@ export function EditWebhookPage({ webhook }: EditWebhookPageProps) {
Cancel
</Button>
<Button type="submit" disabled={isSubmitting}>
{isSubmitting ? "Saving..." : "Save Changes"}
{isSubmitting ? (
<>
<Spinner className="mr-2 h-4 w-4 animate-spin" /> Saving
</>
) : (
<>
<Save className="mr-2 h-4 w-4" /> Save Changes
</>
)}
</Button>
</CardFooter>
</Card>
Expand Down
4 changes: 2 additions & 2 deletions web/components/pages/logs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useState } from "react";
import { useNavigate } from "react-router";
import type { Log } from "@/lib/types";
import type { LogWithWebhook } from "@/lib/types";
import { LogsFilter } from "../logs-filter";
import { LogsList } from "../logs-list";
import {
Expand All @@ -12,7 +12,7 @@ import {
} from "@/components/ui/pagination";

interface LogsPageProps {
logs: Log[];
logs: LogWithWebhook[];
page: number;
limit: number;
}
Expand Down
Loading