Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: dashboard status-page v2 configuration (#1360)
Maximilian Kaske0387ae05bb78
diff --git a/apps/dashboard/src/components/forms/monitor/form-visibility.tsx b/apps/dashboard/src/components/forms/monitor/form-visibility.tsxindex b571a04c6..d2d41b4b9 100644--- a/apps/dashboard/src/components/forms/monitor/form-visibility.tsx+++ b/apps/dashboard/src/components/forms/monitor/form-visibility.tsx@@ -94,17 +94,8 @@ export function FormVisibility({<div className="space-y-0.5"><FormLabel>Allow public access</FormLabel><FormDescription>- Change monitor visibility. When checked, the monitor stats- from the overview page will be public. You will be able to- share it via a connected status page or{" "}- <Link- href={`https://openstatus.dev/public/monitors/${id}`}- target="_blank"- rel="noopener noreferrer"- >- https://openstatus.dev/public/monitors/{id}- </Link>- .+ Change monitor visibility. The monitor stats will be+ attached to the status page the monitor is connected to.</FormDescription></div><FormControl>diff --git a/apps/dashboard/src/components/forms/status-page/form-appearance.tsx b/apps/dashboard/src/components/forms/status-page/form-appearance.tsxindex f8d115a0c..74f552b6e 100644--- a/apps/dashboard/src/components/forms/status-page/form-appearance.tsx+++ b/apps/dashboard/src/components/forms/status-page/form-appearance.tsx@@ -86,7 +86,7 @@ export function FormAppearance({Forced theme will override the user's preference.</FormCardDescription></FormCardHeader>- <FormCardContent>+ <FormCardContent className="grid gap-4 sm:grid-cols-3"><FormFieldcontrol={form.control}name="forceTheme"@@ -98,7 +98,7 @@ export function FormAppearance({defaultValue={field.value}><FormControl>- <SelectTrigger>+ <SelectTrigger className="w-full"><SelectValue placeholder="Select a theme" /></SelectTrigger></FormControl>diff --git a/apps/dashboard/src/components/forms/status-page/form-configuration.tsx b/apps/dashboard/src/components/forms/status-page/form-configuration.tsxnew file mode 100644index 000000000..4dc8bfdb3--- /dev/null+++ b/apps/dashboard/src/components/forms/status-page/form-configuration.tsx@@ -0,0 +1,368 @@+import { useEffect, useTransition } from "react";+import { z } from "zod";++import { Link } from "@/components/common/link";+import { Note } from "@/components/common/note";+import {+ FormCard,+ FormCardContent,+ FormCardDescription,+ FormCardFooter,+ FormCardFooterInfo,+ FormCardHeader,+ FormCardSeparator,+ FormCardTitle,+} from "@/components/forms/form-card";+import { Button } from "@/components/ui/button";+import {+ Form,+ FormControl,+ FormDescription,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "@/components/ui/form";+import { Input } from "@/components/ui/input";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";+import { Switch } from "@/components/ui/switch";+import { zodResolver } from "@hookform/resolvers/zod";+import { isTRPCClientError } from "@trpc/client";+import { useForm } from "react-hook-form";+import { toast } from "sonner";++const schema = z.object({+ new: z.boolean(),+ configuration: z.record(z.string(), z.string().or(z.boolean()).optional()),+ homepageUrl: z.string().optional(),+ contactUrl: z.string().optional(),+});++type FormValues = z.infer<typeof schema>;++export function FormConfiguration({+ defaultValues,+ onSubmit,+}: {+ defaultValues?: FormValues;+ onSubmit: (values: FormValues) => Promise<void>;+}) {+ const [isPending, startTransition] = useTransition();+ const form = useForm<FormValues>({+ resolver: zodResolver(schema),+ defaultValues: defaultValues ?? {+ new: false,+ configuration: {},+ homepageUrl: "",+ contactUrl: "",+ },+ });+ const watchNew = form.watch("new");+ const watchConfigurationType = form.watch("configuration.type") as+ | "manual"+ | "absolute";+ const watchConfigurationValue = form.watch("configuration.value") as+ | "duration"+ | "requests";+ const watchConfigurationUptime = form.watch("configuration.uptime") as+ | "true"+ | "false";++ useEffect(() => {+ if (watchConfigurationType === "manual") {+ // TODO: this is not working+ form.setValue("configuration.value", undefined);+ } else {+ form.setValue("configuration.value", "duration");+ form.setValue("configuration.type", "absolute");+ if (!watchConfigurationUptime) {+ form.setValue("configuration.uptime", "true");+ }+ }+ }, [watchConfigurationType, watchConfigurationUptime, form]);++ function submitAction(values: FormValues) {+ if (isPending) return;++ startTransition(async () => {+ try {+ const promise = onSubmit(values);+ toast.promise(promise, {+ loading: "Saving...",+ success: "Saved",+ error: (error) => {+ if (isTRPCClientError(error)) {+ return error.message;+ }+ return "Failed to save";+ },+ });+ await promise;+ } catch (error) {+ console.error(error);+ }+ });+ }++ return (+ <Form {...form}>+ <form onSubmit={form.handleSubmit(submitAction)}>+ <FormCard>+ <FormCardHeader>+ <FormCardTitle>Status Page Redesign (beta)</FormCardTitle>+ <FormCardDescription>+ Use the latest version of the status page and customize it.+ </FormCardDescription>+ </FormCardHeader>+ <FormCardContent>+ <FormField+ control={form.control}+ name="new"+ render={({ field }) => (+ <FormItem className="flex flex-row items-center">+ <FormLabel>Enable New Version</FormLabel>+ <FormControl>+ <Switch+ checked={field.value}+ onCheckedChange={field.onChange}+ />+ </FormControl>+ </FormItem>+ )}+ />+ </FormCardContent>+ {watchNew && (+ <>+ <FormCardSeparator />+ <FormCardContent className="grid gap-4 sm:grid-cols-3">+ <FormCardHeader className="col-span-full px-0 pt-0 pb-0">+ <FormCardTitle>Tracker Configuration</FormCardTitle>+ <FormCardDescription>+ Configure which data should be shown in the monitor tracker.+ </FormCardDescription>+ </FormCardHeader>+ <FormField+ control={form.control}+ name="configuration.type"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Bar Type</FormLabel>+ <Select+ onValueChange={field.onChange}+ defaultValue={String(field.value) ?? "absolute"}+ >+ <FormControl>+ <SelectTrigger className="w-full capitalize">+ <SelectValue placeholder="Select a type" />+ </SelectTrigger>+ </FormControl>+ <SelectContent>+ {["absolute", "manual"].map((type) => (+ <SelectItem+ key={type}+ value={type}+ className="capitalize"+ >+ {type}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="configuration.value"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Card Value</FormLabel>+ <Select+ onValueChange={field.onChange}+ defaultValue={String(field.value) ?? "duration"}+ disabled={watchConfigurationType === "manual"}+ >+ <FormControl>+ <SelectTrigger className="w-full capitalize">+ <SelectValue placeholder="Select a type" />+ </SelectTrigger>+ </FormControl>+ <SelectContent>+ {["duration", "requests"].map((type) => (+ <SelectItem+ key={type}+ value={type}+ className="capitalize"+ >+ {type}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="configuration.uptime"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Show Uptime</FormLabel>+ <Select+ onValueChange={field.onChange}+ defaultValue={String(field.value) ?? "true"}+ >+ <FormControl>+ <SelectTrigger className="w-full capitalize">+ <SelectValue placeholder="Select a type" />+ </SelectTrigger>+ </FormControl>+ <SelectContent>+ {["true", "false"].map((type) => (+ <SelectItem+ key={type}+ value={type}+ className="capitalize"+ >+ {type}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <FormMessage />+ </FormItem>+ )}+ />+ <Note color="info" className="col-span-full">+ <ul className="list-inside list-disc">+ <li>+ <span className="font-medium">+ Bar Type{" "}+ <span className="font-semibold">+ {watchConfigurationType}+ </span>+ </span>+ : {message.type[watchConfigurationType]}+ </li>+ <li>+ <span className="font-medium">+ Card Value{" "}+ <span className="font-semibold">+ {watchConfigurationValue}+ </span>+ </span>+ :{" "}+ {message.value[watchConfigurationValue] ??+ message.value.default}+ </li>+ <li>+ <span className="font-medium">+ Show Uptime{" "}+ <span className="font-semibold">+ {watchConfigurationUptime}+ </span>+ </span>+ : {message.uptime[watchConfigurationUptime]}+ </li>+ </ul>+ </Note>+ </FormCardContent>+ <FormCardSeparator />+ <FormCardContent className="grid gap-4">+ <FormCardHeader className="col-span-full px-0 pt-0 pb-0">+ <FormCardTitle>Links</FormCardTitle>+ <FormCardDescription>+ Configure the links for the status page.+ </FormCardDescription>+ </FormCardHeader>+ <FormField+ control={form.control}+ name="homepageUrl"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Homepage URL</FormLabel>+ <FormControl>+ <Input placeholder="https://acme.com" {...field} />+ </FormControl>+ <FormMessage />+ <FormDescription>+ What URL should the logo link to? Leave empty to hide.+ </FormDescription>+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="contactUrl"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Contact URL</FormLabel>+ <FormControl>+ <Input+ placeholder="https://acme.com/contact"+ {...field}+ />+ </FormControl>+ <FormMessage />+ <FormDescription>+ Enter the URL for your contact page. Or start with{" "}+ <code className="rounded-md bg-muted px-1 py-0.5">+ mailto:+ </code>{" "}+ to open the email client. Leave empty to hide.+ </FormDescription>+ </FormItem>+ )}+ />+ </FormCardContent>+ </>+ )}+ <FormCardFooter>+ <FormCardFooterInfo>+ Learn more about{" "}+ <Link+ href="https://docs.openstatus.dev/"+ rel="noreferrer"+ target="_blank"+ >+ Status Page Redesign (beta)+ </Link>+ .+ </FormCardFooterInfo>+ <Button type="submit" disabled={isPending}>+ {isPending ? "Submitting..." : "Submit"}+ </Button>+ </FormCardFooter>+ </FormCard>+ </form>+ </Form>+ );+}++// TODO:+const message = {+ type: {+ manual:+ "only shares the duration of reports and maintenaces you are setting up - nothing else.",+ absolute:+ "shares the status of your endpoint for the duration of the different statuses.",+ },+ value: {+ duration: "shares the duration of the different statuses.",+ requests:+ "shares the number of requests received (success, degraded, error).",+ default: "shares only the worse status of the day",+ },+ uptime: {+ true: "shares the uptime percentage and current status of your endpoint.",+ false: "shares only the current status.",+ },+} as const;diff --git a/apps/dashboard/src/components/forms/status-page/form-general.tsx b/apps/dashboard/src/components/forms/status-page/form-general.tsxindex ba82b43a0..0e3c423e7 100644--- a/apps/dashboard/src/components/forms/status-page/form-general.tsx+++ b/apps/dashboard/src/components/forms/status-page/form-general.tsx@@ -250,7 +250,7 @@ export function FormGeneral({<FormMessage /><FormDescription>Select an icon for your status page. Ideally sized- 512x512px.+ 512x512px. Will be used as favicon.</FormDescription></FormItem>)}diff --git a/apps/dashboard/src/components/forms/status-page/update.tsx b/apps/dashboard/src/components/forms/status-page/update.tsxindex c408a9385..dcb59c283 100644--- a/apps/dashboard/src/components/forms/status-page/update.tsx+++ b/apps/dashboard/src/components/forms/status-page/update.tsx@@ -3,6 +3,7 @@ import { useTRPC } from "@/lib/trpc/client";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { useParams, useRouter } from "next/navigation";import { FormAppearance } from "./form-appearance";+import { FormConfiguration } from "./form-configuration";import { FormCustomDomain } from "./form-custom-domain";import { FormDangerZone } from "./form-danger-zone";import { FormGeneral } from "./form-general";@@ -71,6 +72,12 @@ export function FormStatusPageUpdate() {}),);+ const updatePageConfigurationMutation = useMutation(+ trpc.page.updatePageConfiguration.mutationOptions({+ onSuccess: () => refetch(),+ }),+ );+if (!statusPage || !monitors || !workspace) return null;return (@@ -132,6 +139,33 @@ export function FormStatusPageUpdate() {});}}/>+ {/* TODO: feature flagged - remove once we have the new version in production */}+ {process.env.NEXT_PUBLIC_STATUS_PAGE_V2 === "true" ? (+ <FormConfiguration+ defaultValues={{+ new: !statusPage.legacyPage,+ configuration: statusPage.configuration ?? {},+ homepageUrl: statusPage.homepageUrl ?? "",+ contactUrl: statusPage.contactUrl ?? "",+ }}+ onSubmit={async (values) => {+ await updatePageConfigurationMutation.mutateAsync({+ id: Number.parseInt(id),+ configuration: values.new+ ? {+ // NOTE: convert to boolean+ uptime: values.configuration.uptime === "true",+ value: values.configuration.value ?? "duration",+ type: values.configuration.type ?? "absolute",+ }+ : undefined,+ legacyPage: !values.new,+ homepageUrl: values.homepageUrl ?? undefined,+ contactUrl: values.contactUrl ?? undefined,+ });+ }}+ />+ ) : null}<FormPasswordProtectionlocked={workspace.limits["password-protection"] === false}defaultValues={{diff --git a/apps/web/src/components/forms/status-page/form.tsx b/apps/web/src/components/forms/status-page/form.tsxindex a7b325aa7..99255fa2e 100644--- a/apps/web/src/components/forms/status-page/form.tsx+++ b/apps/web/src/components/forms/status-page/form.tsx@@ -32,7 +32,7 @@ import { SectionVisibility } from "./section-visibility";interface Props {defaultSection?: string;- defaultValues?: InsertPage;+ defaultValues?: Omit<InsertPage, "configuration">;allMonitors?: Monitor[];/*** gives the possibility to check all the monitors@@ -55,7 +55,7 @@ export function StatusPageForm({plan,workspaceSlug,}: Props) {- const form = useForm<InsertPage>({+ const form = useForm<Omit<InsertPage, "configuration">>({resolver: zodResolver(insertPageSchema),defaultValues: {title: defaultValues?.title || "", // FIXME: you can save a page without title, causing unexpected slug behaviordiff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.tsindex 6d659ed72..04dda413f 100644--- a/packages/api/src/router/page.ts+++ b/packages/api/src/router/page.ts@@ -67,7 +67,8 @@ export const pageRouter = createTRPCRouter({.meta({ track: Events.CreatePage, trackProps: ["slug"] }).input(insertPageSchema).mutation(async (opts) => {- const { monitors, workspaceId, id, ...pageProps } = opts.input;+ const { monitors, workspaceId, id, configuration, ...pageProps } =+ opts.input;const monitorIds = monitors?.map((item) => item.monitorId) || [];@@ -101,7 +102,11 @@ export const pageRouter = createTRPCRouter({const newPage = await opts.ctx.db.insert(page)- .values({ workspaceId: opts.ctx.workspace.id, ...pageProps })+ .values({+ workspaceId: opts.ctx.workspace.id,+ configuration: JSON.stringify(configuration),+ ...pageProps,+ }).returning().get();@@ -751,6 +756,38 @@ export const pageRouter = createTRPCRouter({.run();}),+ updatePageConfiguration: protectedProcedure+ .meta({ track: Events.UpdatePage })+ .input(+ z.object({+ id: z.number(),+ configuration: z+ .record(z.string(), z.string().or(z.boolean()).optional())+ .nullish(),+ legacyPage: z.boolean(),+ homepageUrl: z.string().nullish(),+ contactUrl: z.string().nullish(),+ }),+ )+ .mutation(async (opts) => {+ const whereConditions: SQL[] = [+ eq(page.workspaceId, opts.ctx.workspace.id),+ eq(page.id, opts.input.id),+ ];++ await opts.ctx.db+ .update(page)+ .set({+ configuration: opts.input.configuration,+ legacyPage: opts.input.legacyPage,+ homepageUrl: opts.input.homepageUrl,+ contactUrl: opts.input.contactUrl,+ updatedAt: new Date(),+ })+ .where(and(...whereConditions))+ .run();+ }),+updateMonitors: protectedProcedure.meta({ track: Events.UpdatePage }).input(diff --git a/packages/db/src/schema/pages/validation.ts b/packages/db/src/schema/pages/validation.tsindex b6b5ed88a..68898eb71 100644--- a/packages/db/src/schema/pages/validation.ts+++ b/packages/db/src/schema/pages/validation.ts@@ -40,6 +40,10 @@ export const insertPageSchema = createInsertSchema(page, {export const selectPageSchema = createSelectSchema(page).extend({password: z.string().optional().nullable().default(""),+ configuration: z+ .record(z.string(), z.string().or(z.boolean()).optional())+ .nullish()+ .default({}),});export type InsertPage = z.infer<typeof insertPageSchema>;