Skip to content

Open-source status page, incident response and uptime monitoring

feat: add search bar to external services (#2182)

Colin Ozanne6282b271e65a
diff --git a/apps/web/src/app/(landing)/status/external-status-grid.tsx b/apps/web/src/app/(landing)/status/external-status-grid.tsx
index 1e02e0631..72e1c9221 100644
--- a/apps/web/src/app/(landing)/status/external-status-grid.tsx
+++ b/apps/web/src/app/(landing)/status/external-status-grid.tsx
@@ -1,31 +1,53 @@
"use client";
+import { useQueryState } from "nuqs";
+import { useMemo } from "react";
+
import { Grid } from "@/content/mdx-components/grid";
import { api } from "@/trpc/rq-client";
import { ContentBoxLink } from "../content-box";
import { ExternalServicePill } from "./external-service-pill";
+import { filterServices } from "./filter-services";
+import { qParser } from "./search-params";
export function ExternalStatusGrid() {
const [services] = api.externalService.grid.useSuspenseQuery();
+ const [q] = useQueryState("q", qParser);
+
+ const filtered = useMemo(() => filterServices(services, q), [services, q]);
+ const hasQuery = q.trim() !== "";
return (
- <Grid cols={2}>
- {services.map((service) => (
- <ContentBoxLink
- key={service.slug}
- href={`/status/${service.slug}`}
- className="flex flex-col gap-2"
- >
- <p className="m-0! font-semibold">{service.name}</p>
- <ExternalServicePill
- indicator={service.indicator}
- status={service.status}
- statusMessage={service.statusMessage || undefined}
- className="self-start"
- />
- </ContentBoxLink>
- ))}
- </Grid>
+ <>
+ <p
+ className="not-prose my-0! text-muted-foreground text-xs"
+ role="status"
+ >
+ Showing {filtered.length} of {services.length} services
+ </p>
+ {filtered.length === 0 && hasQuery && (
+ <p className="my-0! text-muted-foreground text-sm">
+ No services match &ldquo;{q}&rdquo;.
+ </p>
+ )}
+ <Grid cols={2} className="my-0!">
+ {filtered.map((service) => (
+ <ContentBoxLink
+ key={service.slug}
+ href={`/status/${service.slug}`}
+ className="flex flex-col gap-2"
+ >
+ <p className="m-0! font-semibold">{service.name}</p>
+ <ExternalServicePill
+ indicator={service.indicator}
+ status={service.status}
+ statusMessage={service.statusMessage || undefined}
+ className="self-start"
+ />
+ </ContentBoxLink>
+ ))}
+ </Grid>
+ </>
);
}
diff --git a/apps/web/src/app/(landing)/status/filter-services.ts b/apps/web/src/app/(landing)/status/filter-services.ts
new file mode 100644
index 000000000..91b60b7fc
--- /dev/null
+++ b/apps/web/src/app/(landing)/status/filter-services.ts
@@ -0,0 +1,19 @@
+type Searchable = {
+ name: string;
+ slug: string;
+ aliases: string[];
+};
+
+export function filterServices<T extends Searchable>(
+ rows: T[],
+ q: string,
+): T[] {
+ const needle = q.trim().toLowerCase();
+ if (!needle) return rows;
+ return rows.filter(
+ (r) =>
+ r.name.toLowerCase().includes(needle) ||
+ r.slug.toLowerCase().includes(needle) ||
+ r.aliases.some((a) => a.toLowerCase().includes(needle)),
+ );
+}
diff --git a/apps/web/src/app/(landing)/status/page.tsx b/apps/web/src/app/(landing)/status/page.tsx
index 3a4a2f537..590d0b28b 100644
--- a/apps/web/src/app/(landing)/status/page.tsx
+++ b/apps/web/src/app/(landing)/status/page.tsx
@@ -18,6 +18,8 @@ import {
} from "../content-box";
import { ExternalStatusGrid } from "./external-status-grid";
+import { searchParamsCache } from "./search-params";
+import { ServiceSearch } from "./service-search";
export const dynamic = "force-dynamic";
@@ -25,33 +27,41 @@ const TITLE = "External Status";
const DESCRIPTION =
"Easily check if your external providers is working properly";
-export const metadata: Metadata = {
- ...defaultMetadata,
- title: TITLE,
- description: DESCRIPTION,
- alternates: {
- canonical: "/status",
- },
- openGraph: {
- ...ogMetadata,
- title: TITLE,
- description: DESCRIPTION,
- images: [`${BASE_URL}/api/og/external-service`],
- },
- twitter: {
- ...twitterMetadata,
+export async function generateMetadata(props: {
+ searchParams: Promise<Record<string, string | string[] | undefined>>;
+}): Promise<Metadata> {
+ const { q } = await searchParamsCache.parse(props.searchParams);
+ const hasQuery = q.trim() !== "";
+
+ return {
+ ...defaultMetadata,
title: TITLE,
description: DESCRIPTION,
- images: [`${BASE_URL}/api/og/external-service`],
- },
-};
+ alternates: {
+ canonical: "/status",
+ },
+ robots: hasQuery ? { index: false, follow: true } : defaultMetadata.robots,
+ openGraph: {
+ ...ogMetadata,
+ title: TITLE,
+ description: DESCRIPTION,
+ images: [`${BASE_URL}/api/og/external-service`],
+ },
+ twitter: {
+ ...twitterMetadata,
+ title: TITLE,
+ description: DESCRIPTION,
+ images: [`${BASE_URL}/api/og/external-service`],
+ },
+ };
+}
export default async function Page() {
await api.externalService.grid.prefetch();
return (
- <section className="prose dark:prose-invert mb-12 max-w-none">
- <ContentBoxContainer className="not-prose my-6 px-4 py-2 text-sm">
+ <section className="prose dark:prose-invert flex flex-col gap-4 mb-12 max-w-none">
+ <ContentBoxContainer className="not-prose mb-2 px-4 py-2 text-sm">
<CustomLink
href={`${APP_URL}?ref=status-index-top`}
className="font-medium underline-offset-4 hover:underline"
@@ -62,6 +72,7 @@ export default async function Page() {
</ContentBoxContainer>
<HydrateClient>
+ <ServiceSearch />
<Suspense
fallback={
<p className="text-muted-foreground">Loading external status…</p>
diff --git a/apps/web/src/app/(landing)/status/search-params.ts b/apps/web/src/app/(landing)/status/search-params.ts
new file mode 100644
index 000000000..ef1ae72a1
--- /dev/null
+++ b/apps/web/src/app/(landing)/status/search-params.ts
@@ -0,0 +1,13 @@
+import { createSearchParamsCache, parseAsString } from "nuqs/server";
+
+const baseQParser = parseAsString.withDefault("");
+
+export const searchParamsCache = createSearchParamsCache({
+ q: baseQParser,
+});
+
+export const qParser = baseQParser.withOptions({
+ throttleMs: 300,
+ shallow: true,
+ clearOnDefault: true,
+});
diff --git a/apps/web/src/app/(landing)/status/service-search.tsx b/apps/web/src/app/(landing)/status/service-search.tsx
new file mode 100644
index 000000000..2ad5e83da
--- /dev/null
+++ b/apps/web/src/app/(landing)/status/service-search.tsx
@@ -0,0 +1,68 @@
+"use client";
+
+import { SearchIcon } from "lucide-react";
+import { useQueryState } from "nuqs";
+import { useEffect, useRef } from "react";
+
+import {
+ InputGroup,
+ InputGroupAddon,
+ InputGroupInput,
+} from "@openstatus/ui/components/ui/input-group";
+
+import { qParser } from "./search-params";
+
+export function ServiceSearch() {
+ const [q, setQ] = useQueryState("q", qParser);
+ const inputRef = useRef<HTMLInputElement>(null);
+
+ useEffect(() => {
+ function onKeyDown(e: KeyboardEvent) {
+ if (e.key !== "/") return;
+ const active = document.activeElement;
+ const tag = active?.tagName.toLowerCase();
+ if (
+ tag === "input" ||
+ tag === "textarea" ||
+ tag === "select" ||
+ (active instanceof HTMLElement && active.isContentEditable)
+ ) {
+ return;
+ }
+ e.preventDefault();
+ inputRef.current?.focus();
+ }
+ window.addEventListener("keydown", onKeyDown);
+ return () => window.removeEventListener("keydown", onKeyDown);
+ }, []);
+
+ return (
+ <div className="not-prose my-0!">
+ <InputGroup className="h-auto! rounded-none py-4 ps-1 pe-2 text-base md:text-base">
+ <InputGroupAddon align="inline-start">
+ <SearchIcon />
+ </InputGroupAddon>
+ <InputGroupInput
+ ref={inputRef}
+ type="search"
+ placeholder="Search services…"
+ aria-label="Search services"
+ value={q}
+ onChange={(e) => setQ(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Escape" && q !== "") {
+ e.preventDefault();
+ setQ("");
+ inputRef.current?.blur();
+ }
+ }}
+ />
+ <InputGroupAddon align="inline-end">
+ <kbd className="hidden rounded-none! border border-border bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground sm:inline-block">
+ /
+ </kbd>
+ </InputGroupAddon>
+ </InputGroup>
+ </div>
+ );
+}
diff --git a/packages/api/src/router/externalService.ts b/packages/api/src/router/externalService.ts
index bc4364340..febc40a00 100644
--- a/packages/api/src/router/externalService.ts
+++ b/packages/api/src/router/externalService.ts
@@ -33,6 +33,7 @@ const gridItemSchema = z.object({
slug: z.string(),
name: z.string(),
url: z.string(),
+ aliases: z.array(z.string()),
indicator: z.string(),
status: z.string(),
statusMessage: z.string(),
@@ -104,6 +105,7 @@ export const externalServiceRouter = createTRPCRouter({
slug: s.slug,
name: s.name,
url: s.url,
+ aliases: Array.isArray(s.aliases) ? s.aliases : [],
indicator: snap?.indicator ?? "",
status: snap?.status ?? "",
statusMessage: snap?.status_message ?? "Status unavailable",