Skip to content

Open-source status page, incident response and uptime monitoring

chore: improve status page (#540)

Maximilian Kaske0270b4ce619b
diff --git a/apps/web/public/assets/changelog/individual-status-report-page.png b/apps/web/public/assets/changelog/individual-status-report-page.png
new file mode 100644
index 000000000..c63fa2285
Binary files /dev/null and b/apps/web/public/assets/changelog/individual-status-report-page.png differ
diff --git a/apps/web/public/assets/changelog/status-update-subscriber.png b/apps/web/public/assets/changelog/status-update-subscriber.png
new file mode 100644
index 000000000..fa52ef42c
Binary files /dev/null and b/apps/web/public/assets/changelog/status-update-subscriber.png differ
diff --git a/apps/web/src/app/api/og/route.tsx b/apps/web/src/app/api/og/route.tsx
index 9aa2790ee..00be764c1 100644
--- a/apps/web/src/app/api/og/route.tsx
+++ b/apps/web/src/app/api/og/route.tsx
@@ -3,7 +3,11 @@ import { ImageResponse } from "next/server";
import { DESCRIPTION, TITLE } from "@/app/shared-metadata";
import { getMonitorListData } from "@/lib/tb";
-import { cleanData, getStatus } from "@/lib/tracker";
+import {
+ addBlackListInfo,
+ getStatus,
+ getTotalUptimeString,
+} from "@/lib/tracker";
import { cn, formatDate } from "@/lib/utils";
export const runtime = "edge";
@@ -56,7 +60,8 @@ export async function GET(req: Request) {
}))) ||
[];
- const { bars, uptime } = cleanData(data, LIMIT);
+ const _data = addBlackListInfo(data);
+ const uptime = getTotalUptimeString(data);
return new ImageResponse(
(
@@ -82,7 +87,7 @@ export async function GET(req: Request) {
{title}
</h1>
<p tw="text-slate-600 text-3xl">{description}</p>
- {Boolean(data.length) && Boolean(bars.length) ? (
+ {Boolean(data.length) && Boolean(_data.length) ? (
<div tw="flex flex-col w-full mt-6">
<div tw="flex flex-row items-center justify-between -mb-1 text-black font-light">
<p tw="">{formatDate(new Date())}</p>
@@ -99,7 +104,7 @@ export async function GET(req: Request) {
);
})}
<div tw="flex flex-row-reverse absolute right-0">
- {bars.map((item, i) => {
+ {_data.map((item, i) => {
const { variant } = getStatus(item.ok / item.count);
const isBlackListed = Boolean(item.blacklist);
if (isBlackListed) {
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/_components/CopyToClipboardButton.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/_components/copy-to-clipboard-button.tsx
similarity index 73%
rename from apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/_components/CopyToClipboardButton.tsx
rename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/_components/copy-to-clipboard-button.tsx
index f61db548a..ffc325fe4 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/_components/CopyToClipboardButton.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/_components/copy-to-clipboard-button.tsx
@@ -6,7 +6,7 @@ import { Button } from "@openstatus/ui";
import type { ButtonProps } from "@openstatus/ui";
import { Icons } from "@/components/icons";
-import { copyToClipboard } from "@/lib/utils";
+import { cn, copyToClipboard } from "@/lib/utils";
export function CopyToClipboardButton({
children,
@@ -26,7 +26,7 @@ export function CopyToClipboardButton({
return (
<Button
onClick={(e) => {
- copyToClipboard(children?.toString() ?? "");
+ copyToClipboard(children?.toString() || "");
setHasCopied(true);
onClick?.(e);
}}
@@ -34,9 +34,9 @@ export function CopyToClipboardButton({
>
{children}
{!hasCopied ? (
- <Icons.copy className="ml-2 h-4 w-4" />
+ <Icons.copy className={cn("h-4 w-4", children && "ml-2")} />
) : (
- <Icons.check className="ml-2 h-4 w-4" />
+ <Icons.check className={cn("h-4 w-4", children && "ml-2")} />
)}
</Button>
);
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/page.tsx
index 930658d8c..47511569a 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/page.tsx
@@ -2,7 +2,7 @@ import { Separator } from "@openstatus/ui";
import { WorkspaceForm } from "@/components/forms/workspace-form";
import { api } from "@/trpc/server";
-import { CopyToClipboardButton } from "./_components/CopyToClipboardButton";
+import { CopyToClipboardButton } from "./_components/copy-to-clipboard-button";
export default async function GeneralPage() {
const data = await api.workspace.getWorkspace.query();
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/_components/action-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/_components/action-button.tsx
index ebb761017..1a53e03e1 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/_components/action-button.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/_components/action-button.tsx
@@ -68,6 +68,8 @@ export function ActionButton({ page }: ActionButtonProps) {
<DropdownMenuItem>Edit</DropdownMenuItem>
</Link>
<Link
+ // TODO: it would be create to extract this logic and include custom domains if they are set
+ // similar to `setPrefixUrl`
href={
process.env.NODE_ENV === "production"
? `https://${page.slug}.openstatus.dev`
diff --git a/apps/web/src/app/status-page/[domain]/_components/navbar.tsx b/apps/web/src/app/status-page/[domain]/_components/navbar.tsx
new file mode 100644
index 000000000..9f70fa7c5
--- /dev/null
+++ b/apps/web/src/app/status-page/[domain]/_components/navbar.tsx
@@ -0,0 +1,33 @@
+"use client";
+
+import Link from "next/link";
+import { useSelectedLayoutSegment } from "next/navigation";
+
+import { Button } from "@openstatus/ui";
+
+type Props = {
+ navigation: { label: string; href: string; segment: string | null }[];
+};
+
+export function Navbar({ navigation }: Props) {
+ const selectedSegment = useSelectedLayoutSegment();
+
+ return (
+ <ul className="flex items-center gap-2">
+ {navigation.map(({ label, href, segment }) => {
+ const isActive = segment === selectedSegment;
+ return (
+ <li key={segment}>
+ <Button
+ variant={isActive ? "secondary" : "ghost"}
+ size="sm"
+ asChild
+ >
+ <Link href={href}>{label}</Link>
+ </Button>
+ </li>
+ );
+ })}
+ </ul>
+ );
+}
diff --git a/apps/web/src/app/status-page/[domain]/_components/navigation-link.tsx b/apps/web/src/app/status-page/[domain]/_components/navigation-link.tsx
deleted file mode 100644
index 90f5010a1..000000000
--- a/apps/web/src/app/status-page/[domain]/_components/navigation-link.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-"use client";
-
-import Link from "next/link";
-import { usePathname, useSelectedLayoutSegment } from "next/navigation";
-
-import { Button } from "@openstatus/ui";
-
-export default function NavigationLink({
- slug,
- children,
-}: {
- slug: string | null;
- children: React.ReactNode;
-}) {
- const pathname = usePathname();
- const segment = useSelectedLayoutSegment();
- const isActive = slug === segment;
-
- // REMINDER: `/status-page/${params.domain}/${slug}` won't work for subdomain
- let href = pathname;
-
- if (!isActive) {
- if (segment && slug) {
- href = `${pathname.replace(segment, slug)}`;
- } else if (segment) {
- href = `${pathname.replace(segment, "")}`;
- } else {
- href = `${pathname}${pathname.endsWith("/") ? "" : "/"}${slug}`;
- }
- }
-
- return (
- <Button
- asChild
- variant={isActive ? "secondary" : "ghost"}
- className={isActive ? "font-bold" : ""}
- size="sm"
- >
- <Link href={href}>{children}</Link>
- </Button>
- );
-}
diff --git a/apps/web/src/app/status-page/[domain]/incidents/[id]/_components/copy-link-button.tsx b/apps/web/src/app/status-page/[domain]/incidents/[id]/_components/copy-link-button.tsx
new file mode 100644
index 000000000..ae50420e8
--- /dev/null
+++ b/apps/web/src/app/status-page/[domain]/incidents/[id]/_components/copy-link-button.tsx
@@ -0,0 +1,55 @@
+"use client";
+
+import * as React from "react";
+
+import {
+ Button,
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@openstatus/ui";
+
+import { Icons } from "@/components/icons";
+import { copyToClipboard } from "@/lib/utils";
+
+export function CopyLinkButton() {
+ const [hasCopied, setHasCopied] = React.useState(false);
+
+ React.useEffect(() => {
+ if (hasCopied) {
+ setTimeout(() => {
+ setHasCopied(false);
+ }, 2000);
+ }
+ }, [hasCopied]);
+
+ return (
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-7 w-7"
+ onClick={() => {
+ const text =
+ typeof window !== undefined ? window.location.href : "";
+ copyToClipboard(text);
+ setHasCopied(true);
+ }}
+ >
+ {!hasCopied ? (
+ <Icons.link className="h-4 w-4" />
+ ) : (
+ <Icons.check className="h-4 w-4" />
+ )}
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>Copy link</p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+}
diff --git a/apps/web/src/app/status-page/[domain]/incidents/[id]/page.tsx b/apps/web/src/app/status-page/[domain]/incidents/[id]/page.tsx
new file mode 100644
index 000000000..d3f3913cf
--- /dev/null
+++ b/apps/web/src/app/status-page/[domain]/incidents/[id]/page.tsx
@@ -0,0 +1,47 @@
+import Link from "next/link";
+import { notFound } from "next/navigation";
+import { ChevronLeft } from "lucide-react";
+
+import { Button, Separator } from "@openstatus/ui";
+
+import { Events } from "@/components/status-update/events";
+import { Summary } from "@/components/status-update/summary";
+import { api } from "@/trpc/server";
+import { setPrefixUrl } from "../../utils";
+import { CopyLinkButton } from "./_components/copy-link-button";
+
+export default async function IncidentPage({
+ params,
+}: {
+ params: { domain: string; id: string };
+}) {
+ const report = await api.statusReport.getPublicStatusReportById.query({
+ slug: params.domain,
+ id: Number(params.id),
+ });
+
+ if (!report) return notFound();
+
+ const affectedMonitors = report.monitorsToStatusReports.map(
+ ({ monitor }) => monitor,
+ );
+
+ return (
+ <div className="grid gap-4 text-left">
+ <div>
+ <Button variant="link" size="sm" className="px-0" asChild>
+ <Link href={setPrefixUrl("/", params)}>
+ <ChevronLeft className="h-4 w-4" /> Back
+ </Link>
+ </Button>
+ </div>
+ <div className="flex items-center gap-1">
+ <h3 className="text-xl font-semibold">{report.title}</h3>
+ <CopyLinkButton />
+ </div>
+ <Summary report={report} monitors={affectedMonitors} />
+ <Separator />
+ <Events statusReportUpdates={report.statusReportUpdates} />
+ </div>
+ );
+}
diff --git a/apps/web/src/app/status-page/[domain]/incidents/page.tsx b/apps/web/src/app/status-page/[domain]/incidents/page.tsx
index 8d48273de..3b5278394 100644
--- a/apps/web/src/app/status-page/[domain]/incidents/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/incidents/page.tsx
@@ -32,35 +32,3 @@ export default async function Page({ params }: Props) {
</div>
);
}
-
-export async function generateMetadata({ params }: Props): Promise<Metadata> {
- const page = await api.page.getPageBySlug.query({ slug: params.domain });
- const firstMonitor = page?.monitors?.[0]; // temporary solution
-
- return {
- ...defaultMetadata,
- title: page?.title,
- description: page?.description,
- icons: page?.icon,
- twitter: {
- ...twitterMetadata,
- images: [
- `/api/og?monitorId=${firstMonitor?.id}&title=${page?.title}&description=${
- page?.description || `The ${page?.title} status page`
- }`,
- ],
- title: page?.title,
- description: page?.description,
- },
- openGraph: {
- ...ogMetadata,
- images: [
- `/api/og?monitorId=${firstMonitor?.id}&title=${page?.title}&description=${
- page?.description || `The ${page?.title} status page`
- }`,
- ],
- title: page?.title,
- description: page?.description,
- },
- };
-}
diff --git a/apps/web/src/app/status-page/[domain]/layout.tsx b/apps/web/src/app/status-page/[domain]/layout.tsx
index ab5ac0057..2bdb73219 100644
--- a/apps/web/src/app/status-page/[domain]/layout.tsx
+++ b/apps/web/src/app/status-page/[domain]/layout.tsx
@@ -1,10 +1,20 @@
+import type { Metadata } from "next";
+import Image from "next/image";
import { notFound } from "next/navigation";
+import { Avatar, AvatarFallback, AvatarImage } from "@openstatus/ui";
+
+import {
+ defaultMetadata,
+ ogMetadata,
+ twitterMetadata,
+} from "@/app/shared-metadata";
import { Shell } from "@/components/dashboard/shell";
import { ThemeToggle } from "@/components/theme-toggle";
import { api } from "@/trpc/server";
-import NavigationLink from "./_components/navigation-link";
+import { Navbar } from "./_components/navbar";
import { SubscribeButton } from "./_components/subscribe-button";
+import { setPrefixUrl } from "./utils";
type Props = {
params: { domain: string };
@@ -15,16 +25,39 @@ export default async function StatusPageLayout({ children, params }: Props) {
const page = await api.page.getPageBySlug.query({ slug: params.domain });
if (!page) return notFound();
+ const navigation = [
+ {
+ label: "Status",
+ segment: null,
+ href: setPrefixUrl("/", params),
+ },
+ {
+ label: "Incidents",
+ segment: "incidents",
+ href: setPrefixUrl("/incidents", params),
+ },
+ ];
+
return (
<div className="flex min-h-screen w-full flex-col space-y-6 p-4 md:p-8">
<header className="mx-auto w-full max-w-xl">
<Shell className="mx-auto flex items-center justify-between gap-4 p-2 px-2 md:p-3">
- <div className="hidden w-[100px] md:block" />
- <div className="flex items-center gap-2">
- <NavigationLink slug={null}>Status</NavigationLink>
- <NavigationLink slug="incidents">Incidents</NavigationLink>
+ <div className="relative sm:w-[100px]">
+ {page?.icon ? (
+ <div className="bg-muted border-border h-10 w-10 overflow-hidden rounded-full border">
+ <Image
+ height={40}
+ width={40}
+ src={page.icon}
+ alt={page.title}
+ objectFit="cover"
+ className="rounded-full"
+ />
+ </div>
+ ) : null}
</div>
- <div className="w-[100px] text-end">
+ <Navbar navigation={navigation} />
+ <div className="text-end sm:w-[100px]">
{page.workspacePlan !== "free" ? (
<SubscribeButton slug={params.domain} />
) : null}
@@ -54,3 +87,35 @@ export default async function StatusPageLayout({ children, params }: Props) {
</div>
);
}
+
+export async function generateMetadata({ params }: Props): Promise<Metadata> {
+ const page = await api.page.getPageBySlug.query({ slug: params.domain });
+ const firstMonitor = page?.monitors?.[0]; // temporary solution
+
+ return {
+ ...defaultMetadata,
+ title: page?.title,
+ description: page?.description,
+ icons: page?.icon,
+ twitter: {
+ ...twitterMetadata,
+ images: [
+ `/api/og?monitorId=${firstMonitor?.id}&title=${page?.title}&description=${
+ page?.description || `The ${page?.title} status page`
+ }`,
+ ],
+ title: page?.title,
+ description: page?.description,
+ },
+ openGraph: {
+ ...ogMetadata,
+ images: [
+ `/api/og?monitorId=${firstMonitor?.id}&title=${page?.title}&description=${
+ page?.description || `The ${page?.title} status page`
+ }`,
+ ],
+ title: page?.title,
+ description: page?.description,
+ },
+ };
+}
diff --git a/apps/web/src/app/status-page/[domain]/page.tsx b/apps/web/src/app/status-page/[domain]/page.tsx
index 3438cdc8b..e1636d2d8 100644
--- a/apps/web/src/app/status-page/[domain]/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/page.tsx
@@ -1,14 +1,8 @@
-import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
import { Button } from "@openstatus/ui";
-import {
- defaultMetadata,
- ogMetadata,
- twitterMetadata,
-} from "@/app/shared-metadata";
import { EmptyState } from "@/components/dashboard/empty-state";
import { Header } from "@/components/dashboard/header";
import { IncidentList } from "@/components/status-page/incident-list";
@@ -26,7 +20,7 @@ type Props = {
searchParams: { [key: string]: string | string[] | undefined };
};
-export const revalidate = "600";
+export const revalidate = 600;
export default async function Page({ params }: Props) {
const page = await api.page.getPageBySlug.query({ slug: params.domain });
@@ -59,7 +53,10 @@ export default async function Page({ params }: Props) {
statusReports={page.statusReports}
monitors={page.monitors}
/>
- <MonitorList monitors={page.monitors} />
+ <MonitorList
+ monitors={page.monitors}
+ statusReports={page.statusReports}
+ />
{/* TODO: rename to StatusReportList */}
<IncidentList
incidents={page.statusReports}
@@ -71,35 +68,3 @@ export default async function Page({ params }: Props) {
</div>
);
}
-
-export async function generateMetadata({ params }: Props): Promise<Metadata> {
- const page = await api.page.getPageBySlug.query({ slug: params.domain });
- const firstMonitor = page?.monitors?.[0]; // temporary solution
-
- return {
- ...defaultMetadata,
- title: page?.title,
- description: page?.description,
- icons: page?.icon,
- twitter: {
- ...twitterMetadata,
- images: [
- `/api/og?monitorId=${firstMonitor?.id}&title=${page?.title}&description=${
- page?.description || `The ${page?.title} status page`
- }`,
- ],
- title: page?.title,
- description: page?.description,
- },
- openGraph: {
- ...ogMetadata,
- images: [
- `/api/og?monitorId=${firstMonitor?.id}&title=${page?.title}&description=${
- page?.description || `The ${page?.title} status page`
- }`,
- ],
- title: page?.title,
- description: page?.description,
- },
- };
-}
diff --git a/apps/web/src/app/status-page/[domain]/utils.tsx b/apps/web/src/app/status-page/[domain]/utils.tsx
new file mode 100644
index 000000000..73166e059
--- /dev/null
+++ b/apps/web/src/app/status-page/[domain]/utils.tsx
@@ -0,0 +1,10 @@
+/**
+ * While developing, we can also access the status page via /status-page/:domain
+ */
+export function setPrefixUrl(value: string, params: { domain: string }) {
+ const suffix = value.startsWith("/") ? value : `/${value}`;
+ if (process.env.NODE_ENV === "development") {
+ return `/status-page/${params.domain}${suffix}`;
+ }
+ return suffix;
+}
diff --git a/apps/web/src/components/content/timeline.tsx b/apps/web/src/components/content/timeline.tsx
index 86853a562..50737ad88 100644
--- a/apps/web/src/components/content/timeline.tsx
+++ b/apps/web/src/components/content/timeline.tsx
@@ -41,9 +41,13 @@ function Article({
}: ArticleProps) {
return (
<article className="grid grid-cols-1 gap-4 md:grid-cols-5 md:gap-6">
- <time className="text-muted-foreground order-2 font-mono text-sm md:order-1 md:col-span-1">
- {formatDate(new Date(publishedAt))}
- </time>
+ <div className="relative row-span-2">
+ <div className="sticky top-2">
+ <time className="text-muted-foreground order-2 font-mono text-sm md:order-1 md:col-span-1">
+ {formatDate(new Date(publishedAt))}
+ </time>
+ </div>
+ </div>
<div className="relative order-1 h-64 w-full md:order-2 md:col-span-4">
<Link href={href}>
<Image
diff --git a/apps/web/src/components/data-table/status-page/columns.tsx b/apps/web/src/components/data-table/status-page/columns.tsx
index b50af2521..c9b08b6e7 100644
--- a/apps/web/src/components/data-table/status-page/columns.tsx
+++ b/apps/web/src/components/data-table/status-page/columns.tsx
@@ -61,7 +61,7 @@ export const columns: ColumnDef<
header: "Favicon",
cell: ({ row }) => {
if (!row.getValue("icon")) {
- return <span className="text-muted-foreground">Missing</span>;
+ return <span className="text-muted-foreground">-</span>;
}
return (
<Image
diff --git a/apps/web/src/components/status-page/incident-list.tsx b/apps/web/src/components/status-page/incident-list.tsx
index e064f4882..b7f326563 100644
--- a/apps/web/src/components/status-page/incident-list.tsx
+++ b/apps/web/src/components/status-page/incident-list.tsx
@@ -1,13 +1,17 @@
"use client";
+import Link from "next/link";
+import { useParams } from "next/navigation";
+import { ChevronRight } from "lucide-react";
import type { z } from "zod";
import type {
selectPublicMonitorSchema,
selectStatusReportPageSchema,
} from "@openstatus/db/src/schema";
-import { Separator } from "@openstatus/ui";
+import { Button, Separator } from "@openstatus/ui";
+import { setPrefixUrl } from "@/app/status-page/[domain]/utils";
import { notEmpty } from "@/lib/utils";
import { Events } from "../status-update/events";
import { Summary } from "../status-update/summary";
@@ -23,6 +27,7 @@ export const IncidentList = ({
monitors: z.infer<typeof selectPublicMonitorSchema>[];
context?: "all" | "latest"; // latest 7 days
}) => {
+ const params = useParams<{ domain: string }>();
const lastWeek = Date.now() - 1000 * 60 * 60 * 24 * 7;
function getLastWeeksIncidents() {
@@ -35,36 +40,54 @@ export const IncidentList = ({
const _incidents = context === "all" ? incidents : getLastWeeksIncidents();
+ _incidents.sort((a, b) => {
+ if (a.updatedAt == undefined) return 1;
+ if (b.updatedAt == undefined) return -1;
+ return b.updatedAt.getTime() - a.updatedAt.getTime();
+ });
+
return (
<>
- {_incidents.sort((a, b) => {
- if (a.updatedAt == undefined) return 1;
- if (b.updatedAt == undefined) return -1;
- return b.updatedAt.getTime() - a.updatedAt.getTime();
- })?.length > 0 ? (
- <div className="grid gap-4">
- <h2 className="text-muted-foreground text-lg font-light">
+ {_incidents?.length > 0 ? (
+ <div className="grid gap-3">
+ <p className="text-muted-foreground text-sm font-light">
{context === "all" ? "All incidents" : "Latest incidents"}
- </h2>
- {_incidents.map((incident) => {
- const affectedMonitors = incident.monitorsToStatusReports
- .map(({ monitorId }) => {
- const monitor = monitors.find(({ id }) => monitorId === id);
- return monitor || undefined;
- })
- .filter(notEmpty);
- return (
- <div key={incident.id} className="grid gap-4 text-left">
- <div className="max-w-3xl font-semibold">{incident.title}</div>
- <Summary report={incident} monitors={affectedMonitors} />
- <Separator />
- <Events
- statusReportUpdates={incident.statusReportUpdates}
- collabsible
- />
- </div>
- );
- })}
+ </p>
+ <div className="grid gap-8">
+ {_incidents.map((incident) => {
+ const affectedMonitors = incident.monitorsToStatusReports
+ .map(({ monitorId }) => {
+ const monitor = monitors.find(({ id }) => monitorId === id);
+ return monitor || undefined;
+ })
+ .filter(notEmpty);
+ return (
+ <div key={incident.id} className="group grid gap-4 text-left">
+ <div className="flex items-center gap-1">
+ <h3 className="text-xl font-semibold">{incident.title}</h3>
+ <Button
+ variant="ghost"
+ size="icon"
+ className="hidden h-7 w-7 group-hover:inline-flex"
+ asChild
+ >
+ <Link
+ href={setPrefixUrl(`/incidents/${incident.id}`, params)}
+ >
+ <ChevronRight className="h-4 w-4" />
+ </Link>
+ </Button>
+ </div>
+ <Summary report={incident} monitors={affectedMonitors} />
+ <Separator />
+ <Events
+ statusReportUpdates={incident.statusReportUpdates}
+ collabsible
+ />
+ </div>
+ );
+ })}
+ </div>
</div>
) : (
<p className="text-muted-foreground text-center text-sm font-light">
diff --git a/apps/web/src/components/status-page/monitor-list.tsx b/apps/web/src/components/status-page/monitor-list.tsx
index 40751abfb..401b80589 100644
--- a/apps/web/src/components/status-page/monitor-list.tsx
+++ b/apps/web/src/components/status-page/monitor-list.tsx
@@ -1,22 +1,35 @@
import type { z } from "zod";
-import type { selectPublicMonitorSchema } from "@openstatus/db/src/schema";
+import type {
+ selectPublicMonitorSchema,
+ selectPublicStatusReportSchemaWithRelation,
+} from "@openstatus/db/src/schema";
import { Monitor } from "./monitor";
export const MonitorList = ({
monitors,
+ statusReports,
}: {
monitors: z.infer<typeof selectPublicMonitorSchema>[];
+ statusReports: z.infer<typeof selectPublicStatusReportSchemaWithRelation>[];
}) => {
return (
<div className="grid gap-4">
- {monitors.map((monitor, index) => (
- <div key={index}>
- {/* Fetch tracker and data */}
- <Monitor monitor={monitor} />
- </div>
- ))}
+ {monitors.map((monitor, index) => {
+ const monitorStatusReport = statusReports.filter((statusReport) =>
+ statusReport.monitorsToStatusReports.some(
+ (i) => i.monitor.id === monitor.id,
+ ),
+ );
+ return (
+ <Monitor
+ key={index}
+ monitor={monitor}
+ statusReports={monitorStatusReport}
+ />
+ );
+ })}
</div>
);
};
diff --git a/apps/web/src/components/status-page/monitor.tsx b/apps/web/src/components/status-page/monitor.tsx
index 423e80382..64e7c971e 100644
--- a/apps/web/src/components/status-page/monitor.tsx
+++ b/apps/web/src/components/status-page/monitor.tsx
@@ -1,7 +1,10 @@
import { headers } from "next/headers";
import type { z } from "zod";
-import type { selectPublicMonitorSchema } from "@openstatus/db/src/schema";
+import type {
+ selectPublicMonitorSchema,
+ selectPublicStatusReportSchemaWithRelation,
+} from "@openstatus/db/src/schema";
import { getMonitorListData } from "@/lib/tb";
import { Tracker } from "../tracker";
@@ -10,8 +13,10 @@ const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
export const Monitor = async ({
monitor,
+ statusReports,
}: {
monitor: z.infer<typeof selectPublicMonitorSchema>;
+ statusReports: z.infer<typeof selectPublicStatusReportSchemaWithRelation>[];
}) => {
const headersList = headers();
const timezone = headersList.get("x-vercel-ip-timezone") || currentTimezone;
@@ -20,15 +25,10 @@ export const Monitor = async ({
monitorId: String(monitor.id),
timezone,
});
+
+ // TODO: we could handle the `statusReports` here instead of passing it down to the tracker
+
if (!data) return <div>Something went wrong</div>;
- return (
- <Tracker
- data={data}
- id={monitor.id}
- name={monitor.name}
- url={monitor.url}
- description={monitor.description}
- />
- );
+ return <Tracker data={data} reports={statusReports} {...monitor} />;
};
diff --git a/apps/web/src/components/status-page/status-check.tsx b/apps/web/src/components/status-page/status-check.tsx
index 3807d384e..c32095532 100644
--- a/apps/web/src/components/status-page/status-check.tsx
+++ b/apps/web/src/components/status-page/status-check.tsx
@@ -12,7 +12,7 @@ import { getStatus } from "@/lib/tracker";
import { cn, notEmpty } from "@/lib/utils";
import { Icons } from "../icons";
-const check = cva("border-border rounded-full border p-2", {
+const check = cva("border-border rounded-full border p-1.5", {
variants: {
variant: {
up: "bg-green-500/80 border-green-500",
@@ -58,8 +58,9 @@ export async function StatusCheck({
},
{ count: 0, ok: 0 },
);
- const status = getStatus(ok / count);
- return status;
+ const ratio = ok / count;
+ if (isNaN(ratio)) return getStatus(1); // outsmart caching issue
+ return getStatus(ratio);
}
const status = calcStatus();
diff --git a/apps/web/src/components/tracker.tsx b/apps/web/src/components/tracker.tsx
index 8cacdbd96..3be4819ee 100644
--- a/apps/web/src/components/tracker.tsx
+++ b/apps/web/src/components/tracker.tsx
@@ -4,8 +4,12 @@ import * as React from "react";
import Link from "next/link";
import { cva } from "class-variance-authority";
import { format } from "date-fns";
-import { Eye, Info } from "lucide-react";
+import { ChevronRight, Eye, Info } from "lucide-react";
+import type {
+ StatusReport,
+ StatusReportUpdate,
+} from "@openstatus/db/src/schema";
import type { Monitor } from "@openstatus/tinybird";
import {
HoverCard,
@@ -19,8 +23,11 @@ import {
} from "@openstatus/ui";
import useWindowSize from "@/hooks/use-window-size";
-import type { CleanMonitor } from "@/lib/tracker";
-import { cleanData, getStatus } from "@/lib/tracker";
+import {
+ addBlackListInfo,
+ getStatus,
+ getTotalUptimeString,
+} from "@/lib/tracker";
// What would be cool is tracker that turn from green to red depending on the number of errors
const tracker = cva("h-10 rounded-full flex-1", {
@@ -32,9 +39,14 @@ const tracker = cva("h-10 rounded-full flex-1", {
empty: "bg-muted-foreground/20 data-[state=open]:bg-muted-foreground/30",
blacklist: "bg-green-500/80 data-[state=open]:bg-green-500",
},
+ report: {
+ 0: "",
+ 30: "bg-gradient-to-t from-blue-500/90 hover:from-blue-500 from-30% to-transparent to-30%",
+ },
},
defaultVariants: {
variant: "empty",
+ report: 0,
},
});
@@ -46,6 +58,7 @@ interface TrackerProps {
description?: string;
context?: "play" | "status-page"; // TODO: we might need to extract those two different use cases - for now it's ok I'd say.
timezone?: string;
+ reports?: (StatusReport & { statusReportUpdates: StatusReportUpdate[] })[];
}
export function Tracker({
@@ -55,12 +68,15 @@ export function Tracker({
name,
context = "status-page",
description,
- timezone,
+ reports,
}: TrackerProps) {
+ // TODO: remove the isMobile, maxSize, and _placeholder as status_timezone__v0 already returns the last 45 days
const { isMobile } = useWindowSize();
- // TODO: it is better than how it was currently, but creates a small content shift on first render
const maxSize = React.useMemo(() => (isMobile ? 35 : 45), [isMobile]);
- const { bars, uptime } = cleanData(data, maxSize, timezone);
+ const uptime = getTotalUptimeString(data);
+
+ const _data = addBlackListInfo(data);
+ const _placeholder = Array.from({ length: maxSize - _data.length });
return (
<div className="flex flex-col">
@@ -74,12 +90,25 @@ export function Tracker({
<p className="text-muted-foreground shrink-0 font-light">{uptime}</p>
</div>
<div className="relative h-full w-full">
- <div className="flex flex-row-reverse gap-0.5">
- {bars.map((props) => {
+ <div className="flex flex-row-reverse gap-px sm:gap-0.5">
+ {_data.map((props, i) => {
+ const dateReports = reports?.filter((report) => {
+ const firstStatusReportUpdate = report.statusReportUpdates.sort(
+ (a, b) => a.date.getTime() - b.date.getTime(),
+ )?.[0];
+
+ if (!firstStatusReportUpdate) return false;
+ const d = firstStatusReportUpdate.date;
+ d.setHours(0, 0, 0); // set date to midnight as cronTimestamp is midnight
+ return d.getTime() === new Date(props.day).getTime();
+ });
return (
- <Bar key={props.cronTimestamp} context={context} {...props} />
+ <Bar key={i} context={context} reports={dateReports} {...props} />
);
})}
+ {_placeholder.map((_, i) => {
+ return <div key={i} className={tracker({ variant: "empty" })} />;
+ })}
</div>
</div>
</div>
@@ -122,24 +151,31 @@ const MoreInfo = ({
);
};
+type BarProps = Monitor & { blacklist?: string } & Pick<
+ TrackerProps,
+ "context" | "reports"
+ >;
+
const Bar = ({
count,
ok,
avgLatency,
- cronTimestamp,
+ day,
blacklist,
context,
-}: CleanMonitor & Pick<TrackerProps, "context">) => {
+ reports,
+}: BarProps) => {
const [open, setOpen] = React.useState(false);
const ratio = ok / count;
+ const cronTimestamp = new Date(day).getTime();
const date = new Date(cronTimestamp);
const toDate = date.setDate(date.getDate() + 1);
const dateFormat = "dd/MM/yy";
const className = tracker({
+ report: reports && reports.length > 0 ? 30 : undefined,
variant: blacklist ? "blacklist" : getStatus(ratio).variant,
});
- // console.log({ className, blacklist });
return (
<HoverCard
@@ -149,10 +185,7 @@ const Bar = ({
onOpenChange={setOpen}
>
<HoverCardTrigger onClick={() => setOpen(true)} asChild>
- <div
- // suppressHydrationWarning
- className={className}
- />
+ <div className={className} />
</HoverCardTrigger>
<HoverCardContent side="top" className="w-64">
{blacklist ? (
@@ -170,6 +203,19 @@ const Bar = ({
</Link>
) : null}
</div>
+ <ul className="my-1.5">
+ {reports?.map((report) => (
+ <li key={report.id} className="text-muted-foreground text-sm">
+ <Link
+ href={`./incidents/${report.id}`}
+ className="hover:text-foreground group flex items-center justify-between gap-2"
+ >
+ <span className="truncate">{report.title}</span>
+ <ChevronRight className="h-4 w-4" />
+ </Link>
+ </li>
+ ))}
+ </ul>
<div className="flex justify-between">
<p className="text-xs font-light">
{format(new Date(cronTimestamp), dateFormat)}
diff --git a/apps/web/src/content/changelog/individual-status-report-page.mdx b/apps/web/src/content/changelog/individual-status-report-page.mdx
new file mode 100644
index 000000000..6619ec78a
--- /dev/null
+++ b/apps/web/src/content/changelog/individual-status-report-page.mdx
@@ -0,0 +1,9 @@
+---
+title: Invidivual Status Report Page
+description: Every created status report now has its own page.
+publishedAt: 2023-12-22
+image: /assets/changelog/individual-status-report-page.png
+---
+
+Every created status report now has its own page. That will make it easier to
+share the status report with your team and across your users.
diff --git a/apps/web/src/content/changelog/status-update-subscriber.mdx b/apps/web/src/content/changelog/status-update-subscriber.mdx
new file mode 100644
index 000000000..4d1258a23
--- /dev/null
+++ b/apps/web/src/content/changelog/status-update-subscriber.mdx
@@ -0,0 +1,11 @@
+---
+title: Status Update Subscriber
+description: You can now subscribe to pro plan status updates via email.
+publishedAt: 2023-12-11
+image: /assets/changelog/status-update-subscriber.png
+---
+
+You can now subscribe to pro plan status updates via email.
+
+As a subscriber, we require you to verify your email address to avoid spam. You
+can do this by clicking the link in the email we send you after you subscribe.
diff --git a/apps/web/src/lib/tracker.ts b/apps/web/src/lib/tracker.ts
index 7c89d2c3e..b2dd0e0c2 100644
--- a/apps/web/src/lib/tracker.ts
+++ b/apps/web/src/lib/tracker.ts
@@ -36,91 +36,6 @@ export const getStatus = (ratio: number): GetStatusReturnType => {
// TODO: move into Class component sharing the same `data`
-// FIXME: name TrackerMonitor
-
-export type CleanMonitor = {
- count: number;
- ok: number;
- avgLatency: number;
- cronTimestamp: number;
- blacklist?: string;
-};
-
-/**
- * Clean the data to show only the last X days
- * @param data array of monitors
- * @param last number of days to show
- * @param timeZone timezone of the monitor
- * @returns
- */
-export function cleanData(data: Monitor[], last: number, timeZone?: string) {
- const today = new Date(new Date().toLocaleString("en-US", { timeZone }));
-
- const currentDay = new Date(today);
- currentDay.setDate(today.getDate());
- currentDay.setHours(0, 0, 0, 0);
-
- const lastDay = new Date(today);
- lastDay.setDate(today.getDate() - last);
- lastDay.setHours(0, 0, 0, 0);
-
- const dateSequence = generateDateSequence(lastDay, currentDay);
-
- const filledData = fillEmptyData(data, dateSequence);
-
- const uptime = getTotalUptimeString(filledData);
-
- return { bars: filledData, uptime }; // possibly only return filledData?
-}
-
-function fillEmptyData(data: Monitor[], dateSequence: Date[]) {
- const filledData: CleanMonitor[] = [];
- let dataIndex = 0;
-
- for (const date of dateSequence) {
- const timestamp = date.getTime();
- const cronTimestamp =
- dataIndex < data.length
- ? new Date(data[dataIndex].day).getTime()
- : undefined;
-
- if (
- cronTimestamp &&
- areDatesEqualByDayMonthYear(date, new Date(cronTimestamp))
- ) {
- const blacklist = isInBlacklist(cronTimestamp);
-
- /**
- * automatically remove the data from the array to avoid wrong uptime
- * that provides time to remove cursed logs from tinybird via mv migration
- */
- if (blacklist) {
- filledData.push({
- ...emptyData(cronTimestamp),
- blacklist,
- });
- } else {
- const { day, ...props } = data[dataIndex];
- filledData.push({ ...props, cronTimestamp });
- }
- dataIndex++;
- } else {
- filledData.push(emptyData(timestamp));
- }
- }
-
- return filledData;
-}
-
-function emptyData(cronTimestamp: number) {
- return {
- count: 0,
- ok: 0,
- avgLatency: 0,
- cronTimestamp,
- };
-}
-
/**
* equal days - fixes issue with daylight saving
* @param date1
@@ -137,22 +52,11 @@ function areDatesEqualByDayMonthYear(date1: Date, date2: Date) {
return date1.toUTCString() === date2.toUTCString();
}
-/**
- *
- * @param startDate
- * @param endDate
- * @returns
- */
-export function generateDateSequence(startDate: Date, endDate: Date): Date[] {
- const dateSequence: Date[] = [];
- const currentDate = new Date(startDate);
-
- while (currentDate <= endDate) {
- dateSequence.push(new Date(currentDate));
- currentDate.setDate(currentDate.getDate() + 1);
- }
-
- return dateSequence.reverse();
+export function addBlackListInfo(data: Monitor[]) {
+ return data.map((monitor) => {
+ const blacklist = isInBlacklist(new Date(monitor.day).getTime());
+ return { ...monitor, blacklist };
+ });
}
export function getTotalUptime(data: { ok: number; count: number }[]) {
diff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.ts
index 3c3c4e29f..599c81e22 100644
--- a/packages/api/src/router/page.ts
+++ b/packages/api/src/router/page.ts
@@ -219,7 +219,7 @@ export const pageRouter = createTRPCRouter({
where: or(inArray(statusReport.id, statusReportIds)),
with: {
statusReportUpdates: true,
- monitorsToStatusReports: true,
+ monitorsToStatusReports: { with: { monitor: true } },
pagesToStatusReports: true,
},
})
diff --git a/packages/api/src/router/statusReport.ts b/packages/api/src/router/statusReport.ts
index 4088948f2..6e66fc5f4 100644
--- a/packages/api/src/router/statusReport.ts
+++ b/packages/api/src/router/statusReport.ts
@@ -1,6 +1,6 @@
import { z } from "zod";
-import { and, eq, inArray, isNotNull } from "@openstatus/db";
+import { and, eq, inArray, isNotNull, sql } from "@openstatus/db";
import {
insertStatusReportSchema,
insertStatusReportUpdateSchema,
@@ -9,6 +9,7 @@ import {
pagesToStatusReports,
pageSubscriber,
selectMonitorSchema,
+ selectPublicStatusReportSchemaWithRelation,
selectStatusReportSchema,
selectStatusReportUpdateSchema,
statusReport,
@@ -18,7 +19,7 @@ import {
} from "@openstatus/db/src/schema";
import { sendEmailHtml } from "@openstatus/emails/emails/send";
-import { createTRPCRouter, protectedProcedure } from "../trpc";
+import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";
export const statusReportRouter = createTRPCRouter({
createStatusReport: protectedProcedure
@@ -306,7 +307,7 @@ export const statusReportRouter = createTRPCRouter({
getStatusReportById: protectedProcedure
.input(z.object({ id: z.number() }))
.query(async (opts) => {
- const selectStatusReportSchemaWithRelation =
+ const selectPublicStatusReportSchemaWithRelation =
selectStatusReportSchema.extend({
status: statusReportStatusSchema.default("investigating"), // TODO: remove!
monitorsToStatusReports: z
@@ -341,7 +342,7 @@ export const statusReportRouter = createTRPCRouter({
},
});
- return selectStatusReportSchemaWithRelation.parse(data);
+ return selectPublicStatusReportSchemaWithRelation.parse(data);
}),
getStatusReportUpdateById: protectedProcedure
@@ -384,4 +385,29 @@ export const statusReportRouter = createTRPCRouter({
console.log(result);
return z.array(selectStatusSchemaWithRelation).parse(result);
}),
+
+ getPublicStatusReportById: publicProcedure
+ .input(z.object({ slug: z.string().toLowerCase(), id: z.number() }))
+ .query(async (opts) => {
+ const result = await opts.ctx.db.query.page.findFirst({
+ where: sql`lower(${page.slug}) = ${opts.input.slug} OR lower(${page.customDomain}) = ${opts.input.slug}`,
+ });
+
+ if (!result) return;
+
+ const _statusReport = await opts.ctx.db.query.statusReport.findFirst({
+ where: and(
+ eq(statusReport.id, opts.input.id),
+ eq(statusReport.workspaceId, result.id),
+ ),
+ with: {
+ monitorsToStatusReports: { with: { monitor: true } },
+ statusReportUpdates: true,
+ },
+ });
+
+ if (!_statusReport) return;
+
+ return selectPublicStatusReportSchemaWithRelation.parse(_statusReport);
+ }),
});
diff --git a/packages/db/src/schema/shared.ts b/packages/db/src/schema/shared.ts
index 1fb693682..0ef246197 100644
--- a/packages/db/src/schema/shared.ts
+++ b/packages/db/src/schema/shared.ts
@@ -8,13 +8,26 @@ import {
} from "./status_reports";
import { workspacePlanSchema } from "./workspaces";
-// FIXME: delete this file!
+// TODO: create a 'public-status' schema with all the different types and validations
+
+export const selectPublicMonitorSchema = selectMonitorSchema.omit({
+ body: true,
+ headers: true,
+ regions: true,
+ method: true,
+});
export const selectStatusReportPageSchema = z.array(
selectStatusReportSchema.extend({
statusReportUpdates: z.array(selectStatusReportUpdateSchema).default([]),
monitorsToStatusReports: z
- .array(z.object({ monitorId: z.number(), statusReportId: z.number() }))
+ .array(
+ z.object({
+ monitorId: z.number(),
+ statusReportId: z.number(),
+ monitor: selectPublicMonitorSchema,
+ }),
+ )
.default([]),
}),
);
@@ -23,13 +36,6 @@ export const selectPageSchemaWithRelation = selectPageSchema.extend({
statusReports: selectStatusReportPageSchema,
});
-export const selectPublicMonitorSchema = selectMonitorSchema.omit({
- body: true,
- headers: true,
- regions: true,
- method: true,
-});
-
export const selectPublicPageSchemaWithRelation = selectPageSchema
.extend({
monitors: z.array(selectPublicMonitorSchema),
@@ -43,3 +49,11 @@ export const selectPublicPageSchemaWithRelation = selectPageSchema
workspaceId: true,
id: true,
});
+
+export const selectPublicStatusReportSchemaWithRelation =
+ selectStatusReportSchema.extend({
+ monitorsToStatusReports: z
+ .array(z.object({ monitor: selectPublicMonitorSchema }))
+ .default([]),
+ statusReportUpdates: z.array(selectStatusReportUpdateSchema),
+ });
diff --git a/packages/tinybird/pipes/status_timezone.pipe b/packages/tinybird/pipes/status_timezone.pipe
index bc86bd481..2a22e5103 100644
--- a/packages/tinybird/pipes/status_timezone.pipe
+++ b/packages/tinybird/pipes/status_timezone.pipe
@@ -41,7 +41,14 @@ SQL >
round(avg(avgLatency)) as avgLatency
FROM group_by_cronTimestamp
GROUP BY start_of_day
- ORDER BY start_of_day DESC
+ -- ORDER BY start_of_day DESC WITH FILL STEP INTERVAL -1 DAY
+ ORDER BY start_of_day
+ WITH FILL
+ FROM
+ toStartOfDay(toTimezone(now(), {{ String(timezone, 'Europe/Berlin') }}))
+ TO toStartOfDay(
+ toTimezone(date_sub(DAY, 46, now()), {{ String(timezone, 'Europe/Berlin') }})
+ ) STEP INTERVAL -1 DAY
LIMIT {{ Int32(limit, 100) }}