Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: data table floating actions (#872)
Maximilian Kaske9fb258ae0f6c
diff --git a/apps/server/src/v1/check/post.test.ts b/apps/server/src/v1/check/post.test.tsindex 2f54ba144..183a5b282 100644--- a/apps/server/src/v1/check/post.test.ts+++ b/apps/server/src/v1/check/post.test.ts@@ -25,9 +25,9 @@ test("Create a single check ", async () => {Promise.resolve(new Response('{"status":200,"latency":100,"body":"Hello World","headers":{"Content-Type":"application/json"},"time":1234567890,"timing":{"dnsStart":1,"dnsDone":2,"connectStart":3,"connectDone":4,"tlsHandshakeStart":5,"tlsHandshakeDone":6,"firstByteStart":7,"firstByteDone":8,"transferStart":9,"transferDone":10},"region":"ams"}',- { status: 200, headers: { "content-type": "application/json" } }- )- )+ { status: 200, headers: { "content-type": "application/json" } },+ ),+ ),);const res = await api.request("/check", {@@ -94,9 +94,9 @@ test.todo("Create a multiple check ", async () => {Promise.resolve(new Response('{"status":200,"latency":100,"body":"Hello World","headers":{"Content-Type":"application/json"},"time":1234567890,"timing":{"dnsStart":1,"dnsDone":2,"connectStart":3,"connectDone":4,"tlsHandshakeStart":5,"tlsHandshakeDone":6,"firstByteStart":7,"firstByteDone":8,"transferStart":9,"transferDone":10},"region":"ams"}',- { status: 200, headers: { "content-type": "application/json" } }- )- )+ { status: 200, headers: { "content-type": "application/json" } },+ ),+ ),);const res = await api.request("/check", {diff --git a/apps/server/src/v1/check/post.ts b/apps/server/src/v1/check/post.tsindex 950c4988f..5cab30c8a 100644--- a/apps/server/src/v1/check/post.ts+++ b/apps/server/src/v1/check/post.ts@@ -107,40 +107,40 @@ export function registerPostCheck(api: typeof checkAPI) {if (aggregated) {// This is uglyconst dnsArray = fulfilledRequest.map(- (r) => r.timing.dnsDone - r.timing.dnsStart+ (r) => r.timing.dnsDone - r.timing.dnsStart,);const connectArray = fulfilledRequest.map(- (r) => r.timing.connectDone - r.timing.connectStart+ (r) => r.timing.connectDone - r.timing.connectStart,);const tlsArray = fulfilledRequest.map(- (r) => r.timing.tlsHandshakeDone - r.timing.tlsHandshakeStart+ (r) => r.timing.tlsHandshakeDone - r.timing.tlsHandshakeStart,);const firstArray = fulfilledRequest.map(- (r) => r.timing.firstByteDone - r.timing.firstByteStart+ (r) => r.timing.firstByteDone - r.timing.firstByteStart,);const transferArray = fulfilledRequest.map(- (r) => r.timing.transferDone - r.timing.transferStart+ (r) => r.timing.transferDone - r.timing.transferStart,);const latencyArray = fulfilledRequest.map((r) => r.latency);const dnsPercentile = percentile([50, 75, 95, 99], dnsArray) as number[];const connectPercentile = percentile([50, 75, 95, 99],- connectArray+ connectArray,) as number[];const tlsPercentile = percentile([50, 75, 95, 99], tlsArray) as number[];const firstPercentile = percentile([50, 75, 95, 99],- firstArray+ firstArray,) as number[];const transferPercentile = percentile([50, 75, 95, 99],- transferArray+ transferArray,) as number[];const latencyPercentile = percentile([50, 75, 95, 99],- latencyArray+ latencyArray,) as number[];const aggregatedDNS = AggregatedResponseSchema.parse({diff --git a/apps/web/package.json b/apps/web/package.jsonindex de96843d8..bc4417ac8 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -35,6 +35,7 @@"@openstatus/ui": "workspace:*","@openstatus/upstash": "workspace:*","@openstatus/utils": "workspace:*",+ "@radix-ui/react-portal": "^1.0.4","@sentry/integrations": "7.116.0","@sentry/nextjs": "7.116.0","@stripe/stripe-js": "2.1.6",diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/(overview)/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/(overview)/layout.tsxindex 66b7759aa..e30805750 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/(overview)/layout.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/(overview)/layout.tsx@@ -5,7 +5,7 @@ import AppPageLayout from "@/components/layout/app-page-layout";export default async function Layout({ children }: { children: ReactNode }) {return (- <AppPageLayout withHelpCallout>+ <AppPageLayout><Headertitle="Incidents"description="Overview of all your incidents."diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/layout.tsxindex be0d16069..2f16bf790 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/layout.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/layout.tsx@@ -12,7 +12,7 @@ export default async function Layout({ children }: { children: ReactNode }) {const isLimitReached = await api.monitor.isMonitorLimitReached.query();return (- <AppPageLayout withHelpCallout>+ <AppPageLayout><Headertitle="Monitors"description="Overview of all your monitors."diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/(overview)/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/(overview)/layout.tsxindex 4492d2d5f..1dee24c14 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/(overview)/layout.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/(overview)/layout.tsx@@ -14,7 +14,7 @@ export default async function Layout({const isLimitReached =await api.notification.isNotificationLimitReached.query();return (- <AppPageLayout withHelpCallout>+ <AppPageLayout><Headertitle="Notifications"description="Overview of all your notification channels."diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/layout.tsxindex f971890bd..45b6ff403 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/layout.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/layout.tsx@@ -7,7 +7,7 @@ export default async function Layout({children: React.ReactNode;}) {return (- <AppPageLayout withHelpCallout>+ <AppPageLayout><Headertitle="Real User Monitoring"description="Get speed insights for your application."diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/(overview)/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/(overview)/layout.tsxindex f0e985646..95f56675f 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/(overview)/layout.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/(overview)/layout.tsx@@ -10,7 +10,7 @@ export default async function Layout({ children }: { children: ReactNode }) {const isLimitReached = await api.page.isPageLimitReached.query();return (- <AppPageLayout withHelpCallout>+ <AppPageLayout><Headertitle="Status Pages"description="Overview of all your pages."diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/(overview)/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/(overview)/layout.tsxindex d50523c49..db1b2ccee 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/(overview)/layout.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/(overview)/layout.tsx@@ -8,7 +8,7 @@ import AppPageLayout from "@/components/layout/app-page-layout";export default async function Layout({ children }: { children: ReactNode }) {return (- <AppPageLayout withHelpCallout>+ <AppPageLayout><Headertitle="Status Reports"description="Overview of all your status reports and updates."diff --git a/apps/web/src/components/data-table/data-table-skeleton.tsx b/apps/web/src/components/data-table/data-table-skeleton.tsxindex e70c27337..f7b772634 100644--- a/apps/web/src/components/data-table/data-table-skeleton.tsx+++ b/apps/web/src/components/data-table/data-table-skeleton.tsx@@ -16,6 +16,8 @@ interface DataTableSkeletonProps {rows?: number;}+// TODO: add checkbox skeleton (for MonitorTable e.g.)+export function DataTableSkeleton({ rows = 3 }: DataTableSkeletonProps) {return (<div className="rounded-md border">diff --git a/apps/web/src/components/data-table/monitor/columns.tsx b/apps/web/src/components/data-table/monitor/columns.tsxindex f52ee38cd..5f29a8912 100644--- a/apps/web/src/components/data-table/monitor/columns.tsx+++ b/apps/web/src/components/data-table/monitor/columns.tsx@@ -17,6 +17,7 @@ import type {import { Tracker } from "@openstatus/tracker";import {Badge,+ Checkbox,Tooltip,TooltipContent,TooltipProvider,@@ -28,6 +29,7 @@ import { TagBadgeWithTooltip } from "@/components/monitor/tag-badge-with-tooltipimport { Bar } from "@/components/tracker/tracker";import { isActiveMaintenance } from "@/lib/maintenances/utils";+import { Eye, EyeOff, Radio, View } from "lucide-react";import { DataTableRowActions } from "./data-table-row-actions";export const columns: ColumnDef<{@@ -38,24 +40,67 @@ export const columns: ColumnDef<{maintenances?: Maintenance[];tags?: MonitorTag[];}>[] = [+ {+ id: "id",+ accessorKey: "id",+ accessorFn: (row) => row.monitor.id,+ },+ {+ id: "select",+ header: ({ table }) => (+ <Checkbox+ checked={+ table.getIsAllPageRowsSelected() ||+ (table.getIsSomePageRowsSelected() && "indeterminate")+ }+ onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}+ aria-label="Select all"+ className="translate-y-[2px]"+ />+ ),+ cell: ({ row }) => (+ <Checkbox+ checked={row.getIsSelected()}+ onCheckedChange={(value) => row.toggleSelected(!!value)}+ aria-label="Select row"+ className="translate-y-[2px]"+ />+ ),+ },+ {+ accessorKey: "active",+ accessorFn: (row) => row.monitor.active,+ header: () => (+ <div className="w-4">+ <Radio className="h-4 w-4" />+ </div>+ ),+ cell: ({ row }) => {+ const { active, status } = row.original.monitor;+ const maintenance = isActiveMaintenance(row.original.maintenances);+ return (+ <div className="flex w-4 items-center justify-center">+ <StatusDotWithTooltip+ active={active}+ status={status}+ maintenance={maintenance}+ />+ </div>+ );+ },+ },{accessorKey: "name",accessorFn: (row) => row.monitor.name, // used for filtering as name is nested within the monitor objectheader: "Name",cell: ({ row }) => {- const { active, status, name, public: _public } = row.original.monitor;- const maintenance = isActiveMaintenance(row.original.maintenances);+ const { name, public: _public } = row.original.monitor;return (<div className="flex gap-2"><Linkhref={`./monitors/${row.original.monitor.id}/overview`}- className="group flex max-w-[150px] items-center gap-2 md:max-w-[250px]"+ className="group flex max-w-full items-center gap-2">- <StatusDotWithTooltip- active={active}- status={status}- maintenance={maintenance}- /><span className="truncate group-hover:underline">{name}</span></Link>{_public ? <Badge variant="secondary">public</Badge> : null}@@ -63,15 +108,6 @@ export const columns: ColumnDef<{);},},- {- // REMINDER: visibility is handled within the `<DataTable />`- accessorKey: "public",- accessorFn: (row) => row.monitor.public,- filterFn: (row, _id, value) => {- if (!Array.isArray(value)) return true;- return value.includes(row.original.monitor.public);- },- },{accessorKey: "tags",header: "Tags",@@ -88,6 +124,31 @@ export const columns: ColumnDef<{);},},+ {+ accessorKey: "public",+ accessorFn: (row) => row.monitor.public,+ header: () => (+ <div className="w-4">+ <View className="h-4 w-4" />+ </div>+ ),+ cell: ({ row }) => {+ const { public: _public } = row.original.monitor;+ return (+ <>+ {_public ? (+ <Eye className="h-4 w-4" />+ ) : (+ <EyeOff className="h-4 w-4" />+ )}+ </>+ );+ },+ filterFn: (row, _id, value) => {+ if (!Array.isArray(value)) return true;+ return value.includes(row.original.monitor.public);+ },+ },{accessorKey: "tracker",header: () => (diff --git a/apps/web/src/components/data-table/monitor/data-table-floating-actions.tsx b/apps/web/src/components/data-table/monitor/data-table-floating-actions.tsxnew file mode 100644index 000000000..a041e0900--- /dev/null+++ b/apps/web/src/components/data-table/monitor/data-table-floating-actions.tsx@@ -0,0 +1,358 @@+"use client";++import * as Portal from "@radix-ui/react-portal";+import type { Table } from "@tanstack/react-table";+import { useEffect, useState, useTransition } from "react";++import { Kbd } from "@/components/kbd";+import { LoadingAnimation } from "@/components/loading-animation";+import { toast, toastAction } from "@/lib/toast";+import { cn } from "@/lib/utils";+import { api } from "@/trpc/client";+import type { Monitor, MonitorTag } from "@openstatus/db/src/schema";+import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+ AlertDialogTrigger,+ Button,+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+ Popover,+ PopoverContent,+ PopoverTrigger,+ Select,+ SelectContent,+ SelectGroup,+ SelectItem,+ SelectLabel,+ SelectTrigger,+ SelectValue,+ Tooltip,+ TooltipContent,+ TooltipProvider,+ TooltipTrigger,+} from "@openstatus/ui";+import { Check, Minus, X } from "lucide-react";+import { useRouter } from "next/navigation";++interface DataTableFloatingActions<TData> {+ table: Table<TData>;+ actions?: [];+ tags?: MonitorTag[];+}++export function DataTableFloatingActions<TData>({+ table,+ tags,+}: DataTableFloatingActions<TData>) {+ const router = useRouter();+ const [alertOpen, setAlertOpen] = useState(false);+ const [isPending, startTransition] = useTransition();+ const [method, setMethod] = useState<+ "delete" | "active" | "public" | "tag" | null+ >(null);+ const rows = table.getFilteredSelectedRowModel().rows;++ // clear selection on escape key+ useEffect(() => {+ function handleKeyDown(event: KeyboardEvent) {+ if (event.key === "Escape") {+ table.toggleAllRowsSelected(false);+ }+ }++ window.addEventListener("keydown", handleKeyDown);+ return () => window.removeEventListener("keydown", handleKeyDown);+ }, [table]);++ if (table.getFilteredSelectedRowModel().rows.length === 0) {+ return null;+ }++ function handleUpdates(props: Partial<Pick<Monitor, "active" | "public">>) {+ startTransition(async () => {+ toast.promise(+ async () => {+ await api.monitor.updateMonitors.mutate({+ ids: rows.map((row) => row.getValue("id")),+ ...props,+ });+ router.refresh();+ },+ {+ loading: "Updating monitor(s)...",+ success: "Monitor(s) updated!",+ error: "Something went wrong!",+ finally: () => {},+ },+ );+ });+ }++ function handleTagUpdates(props: {+ tagId: number;+ action: "add" | "remove";+ }) {+ startTransition(async () => {+ toast.promise(+ async () => {+ await api.monitor.updateMonitorsTag.mutate({+ ids: rows.map((row) => row.getValue("id")),+ ...props,+ });+ router.refresh();+ },+ {+ loading:+ props.action === "add"+ ? "Adding tag to monitor(s)..."+ : "Removing tag from monitor(s)...",+ success:+ props.action === "add"+ ? "Tag added to monitor(s)!"+ : "Tag removed from monitor(s)",+ error: "Something went wrong!",+ finally: () => {},+ },+ );+ });+ }++ function handleDeletes() {+ startTransition(async () => {+ try {+ await api.monitor.deleteMonitors.mutate({+ ids: rows.map((row) => row.getValue("id")),+ });+ setAlertOpen(false);+ table.toggleAllRowsSelected(false);+ router.refresh();+ } catch (error) {+ console.error(error);+ toastAction("error");+ }+ });+ }++ // TODO: can we make it smarter! Its ugly as hell++ const statusValue = rows.every((row) => row.getValue("active") === true)+ ? "true"+ : rows.every((row) => row.getValue("active") === false)+ ? "false"+ : undefined;++ const visibilityValue = rows.every((row) => row.getValue("public") === true)+ ? "true"+ : rows.every((row) => row.getValue("public") === false)+ ? "false"+ : undefined;++ const everyTagValue =+ tags?.filter((tag) => {+ return rows.every((row) => {+ const _tags = row.getValue("tags");+ if (Array.isArray(_tags)) {+ return _tags.map(({ id }) => id)?.includes(tag.id);+ }+ return false;+ });+ }) || [];++ const someTagValue =+ tags?.filter((tag) => {+ return rows.some((row) => {+ const _tags = row.getValue("tags");+ if (Array.isArray(_tags)) {+ return _tags.map(({ id }) => id)?.includes(tag.id);+ }+ return false;+ });+ }) || [];++ return (+ <Portal.Root>+ <div className="fixed inset-x-0 bottom-4 z-50 mx-auto w-fit px-4">+ <div className="flex flex-wrap items-center gap-2 rounded-md border bg-background px-4 py-2 shadow">+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ variant="ghost"+ onClick={() => table.toggleAllRowsSelected(false)}+ className="border border-dashed"+ >+ <span className="whitespace-nowrap">+ {rows.length} selected+ </span>+ <X className="ml-1.5 size-4 shrink-0" />+ </Button>+ </TooltipTrigger>+ <TooltipContent className="flex items-center">+ <p className="mr-2">Clear selection</p>+ <Kbd abbrTitle="Escape" variant="outline">+ Esc+ </Kbd>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ <AlertDialog+ open={alertOpen}+ onOpenChange={(value) => setAlertOpen(value)}+ >+ <AlertDialogTrigger asChild>+ <Button variant="destructive">Delete</Button>+ </AlertDialogTrigger>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>+ <AlertDialogDescription>+ This action cannot be undone. This will permanently delete the+ selected monitor(s).+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogCancel>Cancel</AlertDialogCancel>+ <AlertDialogAction+ onClick={() => {+ setMethod("delete");+ handleDeletes();+ }}+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"+ >+ {isPending && method === "delete" ? (+ <LoadingAnimation />+ ) : (+ "Delete"+ )}+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ <Select+ disabled={isPending && method === "active"}+ value={statusValue}+ onValueChange={(value) => {+ setMethod("active");+ handleUpdates({ active: value === "true" });+ }}+ >+ <SelectTrigger className="h-9 max-w-fit">+ <SelectValue placeholder="Status" />+ </SelectTrigger>+ <SelectContent>+ <SelectGroup>+ <SelectLabel>Status</SelectLabel>+ <SelectItem value="true">Active</SelectItem>+ <SelectItem value="false">Inactive</SelectItem>+ </SelectGroup>+ </SelectContent>+ </Select>+ <Popover>+ <PopoverTrigger disabled={isPending && method === "tag"} asChild>+ <Button variant="outline" className="flex items-center gap-2">+ <span>Tags</span>+ {everyTagValue.length ? (+ <div className="relative flex overflow-hidden">+ {everyTagValue.map((tag) => (+ <div+ key={tag.id}+ style={{ backgroundColor: tag.color }}+ className="h-2.5 w-2.5 rounded-full ring-2 ring-background"+ />+ ))}+ </div>+ ) : null}+ </Button>+ </PopoverTrigger>+ <PopoverContent className="w-[200px] p-0" align="start">+ <Command>+ <CommandInput placeholder={"Tags"} />+ <CommandList>+ <CommandEmpty>No results found.</CommandEmpty>+ <CommandGroup>+ {tags?.map((tag) => {+ const isSelected = everyTagValue+ .map((tag) => tag.id)+ ?.includes(tag.id);+ const isIndeterminated = !isSelected+ ? someTagValue.map((tag) => tag.id)?.includes(tag.id)+ : false;+ return (+ <CommandItem+ key={String(tag.name)}+ onSelect={() => {+ setMethod("tag");+ handleTagUpdates({+ tagId: tag.id,+ action:+ !isSelected || isIndeterminated+ ? "add"+ : "remove",+ });+ }}+ >+ <div+ className={cn(+ "mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",+ {+ "bg-primary text-primary-foreground":+ isSelected,+ "text-muted-foreground": isIndeterminated,+ "opacity-50 [&_svg]:invisible":+ !isSelected && !isIndeterminated,+ },+ )}+ >+ <Check className={cn("h-4 w-4")} />+ </div>+ <div className="flex w-full items-center justify-between">+ <span>{tag.name}</span>+ <div+ key={tag.id}+ style={{ backgroundColor: tag.color }}+ className="h-2.5 w-2.5 rounded-full"+ />+ </div>+ </CommandItem>+ );+ })}+ </CommandGroup>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover>+ <Select+ disabled={isPending && method === "public"}+ value={visibilityValue}+ onValueChange={(value) => {+ setMethod("public");+ handleUpdates({ public: value === "true" });+ }}+ >+ <SelectTrigger className="h-9 max-w-fit">+ <SelectValue placeholder="Visibility" />+ </SelectTrigger>+ <SelectContent>+ <SelectGroup>+ <SelectLabel>Visibility</SelectLabel>+ <SelectItem value="true">Public</SelectItem>+ <SelectItem value="false">Private</SelectItem>+ </SelectGroup>+ </SelectContent>+ </Select>+ </div>+ </div>+ </Portal.Root>+ );+}diff --git a/apps/web/src/components/data-table/monitor/data-table-pagination.tsx b/apps/web/src/components/data-table/monitor/data-table-pagination.tsxnew file mode 100644index 000000000..91e3db192--- /dev/null+++ b/apps/web/src/components/data-table/monitor/data-table-pagination.tsx@@ -0,0 +1,125 @@+"use client";++import type { Table } from "@tanstack/react-table";+import {+ ChevronLeft,+ ChevronRight,+ ChevronsLeft,+ ChevronsRight,+} from "lucide-react";+import { useRouter } from "next/navigation";++import {+ Button,+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@openstatus/ui";++import useUpdateSearchParams from "@/hooks/use-update-search-params";++// REMINDER: pageIndex pagination issue - jumping back to 0 after change++interface DataTablePaginationProps<TData> {+ table: Table<TData>;+}++export function DataTablePagination<TData>({+ table,+}: DataTablePaginationProps<TData>) {+ const updateSearchParams = useUpdateSearchParams();+ const router = useRouter();++ const updatePageSearchParams = (+ values: Record<string, number | string | null>,+ ) => {+ const newSearchParams = updateSearchParams(values);+ router.replace(`?${newSearchParams}`, { scroll: false });+ };++ return (+ <div className="flex flex-wrap-reverse items-center justify-between gap-4 px-2">+ <div>+ <p className="text-muted-foreground text-sm">+ {table.getFilteredSelectedRowModel().rows.length} of{" "}+ {table.getFilteredRowModel().rows.length} row(s) selected.+ </p>+ </div>+ <div className="flex items-center space-x-6 lg:space-x-8">+ <div className="flex items-center space-x-2">+ <p className="font-medium text-sm">Rows per page</p>+ <Select+ value={`${table.getState().pagination.pageSize}`}+ onValueChange={(value) => {+ table.setPageSize(Number(value));+ updatePageSearchParams({ pageSize: value });+ }}+ >+ <SelectTrigger className="h-8 w-[70px]">+ <SelectValue placeholder={table.getState().pagination.pageSize} />+ </SelectTrigger>+ <SelectContent side="top">+ {[10, 20, 30, 40, 50].map((pageSize) => (+ <SelectItem key={pageSize} value={`${pageSize}`}>+ {pageSize}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </div>+ <div className="flex w-[100px] items-center justify-center font-medium text-sm">+ Page {table.getState().pagination.pageIndex + 1} of{" "}+ {table.getPageCount()}+ </div>+ <div className="flex items-center space-x-2">+ <Button+ variant="outline"+ className="hidden h-8 w-8 p-0 lg:flex"+ onClick={() => {+ table.setPageIndex(0);+ }}+ disabled={!table.getCanPreviousPage()}+ >+ <span className="sr-only">Go to first page</span>+ <ChevronsLeft className="h-4 w-4" />+ </Button>+ <Button+ variant="outline"+ className="h-8 w-8 p-0"+ onClick={() => {+ table.previousPage();+ }}+ disabled={!table.getCanPreviousPage()}+ >+ <span className="sr-only">Go to previous page</span>+ <ChevronLeft className="h-4 w-4" />+ </Button>+ <Button+ variant="outline"+ className="h-8 w-8 p-0"+ onClick={() => {+ table.nextPage();+ }}+ disabled={!table.getCanNextPage()}+ >+ <span className="sr-only">Go to next page</span>+ <ChevronRight className="h-4 w-4" />+ </Button>+ <Button+ variant="outline"+ className="hidden h-8 w-8 p-0 lg:flex"+ onClick={() => {+ table.setPageIndex(table.getPageCount() - 1);+ }}+ disabled={!table.getCanNextPage()}+ >+ <span className="sr-only">Go to last page</span>+ <ChevronsRight className="h-4 w-4" />+ </Button>+ </div>+ </div>+ </div>+ );+}diff --git a/apps/web/src/components/data-table/monitor/data-table-row-actions.tsx b/apps/web/src/components/data-table/monitor/data-table-row-actions.tsxindex 54bf0ba8d..bd4eaeb54 100644--- a/apps/web/src/components/data-table/monitor/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/monitor/data-table-row-actions.tsx@@ -59,23 +59,8 @@ export function DataTableRowActions<TData>({});}- async function onToggleActive() {- startTransition(async () => {- try {- // biome-ignore lint/correctness/noUnusedVariables: <explanation>- const { jobType, ...rest } = monitor;- if (!monitor.id) return;- await api.monitor.toggleMonitorActive.mutate({- id: monitor.id,- });- toastAction("success");- router.refresh();- } catch {- toastAction("error");- }- });- }-+ // FIXME: the test doenst take the assertions into account!+ // FIXME: improve (similar to the one in the edit form - also include toast.promise + better error message!)async function onTest() {startTransition(async () => {const { url, body, method, headers } = monitor;@@ -120,11 +105,7 @@ export function DataTableRowActions<TData>({<Link href={`./monitors/${monitor.id}/overview`}><DropdownMenuItem>Details</DropdownMenuItem></Link>- <DropdownMenuSeparator />- <DropdownMenuItem onClick={onTest}>Test endpoint</DropdownMenuItem>- <DropdownMenuItem onClick={onToggleActive}>- {monitor.active ? "Pause" : "Resume"} monitor- </DropdownMenuItem>+ <DropdownMenuItem onClick={onTest}>Test</DropdownMenuItem><DropdownMenuSeparator /><AlertDialogTrigger asChild><DropdownMenuItem className="text-destructive focus:bg-destructive focus:text-background">diff --git a/apps/web/src/components/data-table/monitor/data-table.tsx b/apps/web/src/components/data-table/monitor/data-table.tsxindex 656b9d88f..ab981e2e2 100644--- a/apps/web/src/components/data-table/monitor/data-table.tsx+++ b/apps/web/src/components/data-table/monitor/data-table.tsx@@ -27,6 +27,8 @@ import {TableRow,} from "@openstatus/ui";+import { DataTableFloatingActions } from "./data-table-floating-actions";+import { DataTablePagination } from "./data-table-pagination";import { DataTableToolbar } from "./data-table-toolbar";interface DataTableProps<TData, TValue> {@@ -47,6 +49,7 @@ export function DataTable<TData, TValue>({const [columnVisibility, setColumnVisibility] =React.useState<VisibilityState>({public: false, // default is true+ id: false, // we hide the id column});const table = useReactTable({@@ -104,6 +107,7 @@ export function DataTable<TData, TValue>({<TableRow key={headerGroup.id} className="hover:bg-transparent">{headerGroup.headers.map((header) => {return (+ // FIXME: className="[&:has(svg)]:w-4" takes the svg of the button > checkbox into account<TableHead key={header.id}>{header.isPlaceholder? null@@ -147,6 +151,8 @@ export function DataTable<TData, TValue>({</TableBody></Table></div>+ <DataTablePagination table={table} />+ <DataTableFloatingActions table={table} tags={tags} /></div>);}diff --git a/apps/web/src/components/forms/shared/save-button.tsx b/apps/web/src/components/forms/shared/save-button.tsxindex 2168a97b2..eafcfe748 100644--- a/apps/web/src/components/forms/shared/save-button.tsx+++ b/apps/web/src/components/forms/shared/save-button.tsx@@ -40,10 +40,10 @@ export function SaveButton({ isPending, isDirty, onSubmit, form }: Props) {form={form}>{!isPending ? (- <span className="flex gap-2">+ <span className="flex items-center gap-2">Confirm<Kbd>- <span>⌘</span>+ <span className="mr-0.5">⌘</span><span>S</span></Kbd></span>diff --git a/apps/web/src/components/kbd.tsx b/apps/web/src/components/kbd.tsxindex 191c8fd6c..eb742811a 100644--- a/apps/web/src/components/kbd.tsx+++ b/apps/web/src/components/kbd.tsx@@ -1,7 +1,55 @@-export function Kbd({ children }: { children: React.ReactNode }) {- return (- <kbd className="pointer-events-none flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-medium font-mono font-mono text-[10px] text-foreground opacity-100">- {children}- </kbd>- );+import { type VariantProps, cva } from "class-variance-authority";+// Copy Pasta from: https://github.com/sadmann7/shadcn-table/blob/main/src/components/kbd.tsx#L54+import * as React from "react";++import { cn } from "@/lib/utils";++const kbdVariants = cva(+ "select-none rounded border px-1.5 py-px font-mono text-[0.7rem] font-normal shadow-sm disabled:opacity-50",+ {+ variants: {+ variant: {+ default: "bg-accent text-accent-foreground",+ outline: "bg-background text-foreground",+ },+ },+ defaultVariants: {+ variant: "default",+ },+ },+);++export interface KbdProps+ extends React.ComponentPropsWithoutRef<"kbd">,+ VariantProps<typeof kbdVariants> {+ /**+ * The title of the `abbr` element inside the `kbd` element.+ * @default undefined+ * @type string | undefined+ * @example title="Command"+ */+ abbrTitle?: string;}++const Kbd = React.forwardRef<HTMLUnknownElement, KbdProps>(+ ({ abbrTitle, children, className, variant, ...props }, ref) => {+ return (+ <kbd+ className={cn(kbdVariants({ variant, className }))}+ ref={ref}+ {...props}+ >+ {abbrTitle ? (+ <abbr title={abbrTitle} className="no-underline">+ {children}+ </abbr>+ ) : (+ children+ )}+ </kbd>+ );+ },+);+Kbd.displayName = "Kbd";++export { Kbd };diff --git a/apps/web/src/components/layout/app-page-layout.tsx b/apps/web/src/components/layout/app-page-layout.tsxindex a86152029..b7f61f397 100644--- a/apps/web/src/components/layout/app-page-layout.tsx+++ b/apps/web/src/components/layout/app-page-layout.tsx@@ -1,15 +1,12 @@import { Shell } from "@/components/dashboard/shell";import { cn } from "@/lib/utils";-import { HelpCallout } from "../dashboard/help-callout";export default function AppPageLayout({children,className,- withHelpCallout = false,}: {children: React.ReactNode;className?: string;- withHelpCallout?: boolean;}) {return (<Shell className="relative flex flex-1 flex-col overflow-x-hidden">@@ -18,11 +15,6 @@ export default function AppPageLayout({>{children}</div>- {withHelpCallout ? (- <div className="mt-4">- <HelpCallout />- </div>- ) : null}</Shell>);}diff --git a/apps/web/src/components/monitor/status-dot.tsx b/apps/web/src/components/monitor/status-dot.tsxindex de5ebdefb..d77fe633c 100644--- a/apps/web/src/components/monitor/status-dot.tsx+++ b/apps/web/src/components/monitor/status-dot.tsx@@ -17,7 +17,7 @@ export function StatusDot({ active, status, maintenance }: StatusDotProps) {if (maintenance) {return (<span className="relative flex h-2 w-2">- <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-blue-500/80 opacity-75 duration-1000" />+ <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-blue-500/80 opacity-75 duration-[2000ms]" /><span className="relative inline-flex h-2 w-2 rounded-full bg-blue-500" /></span>);@@ -25,7 +25,7 @@ export function StatusDot({ active, status, maintenance }: StatusDotProps) {if (status === "error") {return (<span className="relative flex h-2 w-2">- <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-red-500/80 opacity-75 duration-1000" />+ <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-red-500/80 opacity-75 duration-[2000ms]" /><span className="absolute inline-flex h-2 w-2 rounded-full bg-red-500" /></span>);@@ -33,7 +33,7 @@ export function StatusDot({ active, status, maintenance }: StatusDotProps) {return (<span className="relative flex h-2 w-2">- <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-green-500/80 opacity-75 duration-1000" />+ <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-green-500/80 opacity-75 duration-[2000ms]" /><span className="relative inline-flex h-2 w-2 rounded-full bg-green-500" /></span>);diff --git a/apps/web/src/components/support/bubble.tsx b/apps/web/src/components/support/bubble.tsxindex 7003a17e7..262763ee6 100644--- a/apps/web/src/components/support/bubble.tsx+++ b/apps/web/src/components/support/bubble.tsx@@ -29,7 +29,7 @@ export function Bubble() {setOpen(value);}}>- <PopoverTrigger className="rounded-full border p-2 shadow">+ <PopoverTrigger className="rounded-full border p-2 shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"><MessageCircle className="h-6 w-6" /></PopoverTrigger><PopoverContentdiff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.tsindex 4f59a6940..3d1651b7b 100644--- a/packages/api/src/router/monitor.ts+++ b/packages/api/src/router/monitor.ts@@ -405,6 +405,82 @@ export const monitorRouter = createTRPCRouter({}}),+ updateMonitors: protectedProcedure+ .input(+ insertMonitorSchema+ .pick({ public: true, active: true })+ .partial() // batched updates+ .extend({ ids: z.number().array() }), // array of monitor ids to update+ )+ .mutation(async (opts) => {+ const _monitors = await opts.ctx.db+ .update(monitor)+ .set(opts.input)+ .where(+ and(+ inArray(monitor.id, opts.input.ids),+ eq(monitor.workspaceId, opts.ctx.workspace.id),+ isNull(monitor.deletedAt),+ ),+ );+ }),++ updateMonitorsTag: protectedProcedure+ .input(+ z.object({+ ids: z.number().array(),+ tagId: z.number(),+ action: z.enum(["add", "remove"]),+ }),+ )+ .mutation(async (opts) => {+ const _monitorTag = await opts.ctx.db.query.monitorTag.findFirst({+ where: and(+ eq(monitorTag.workspaceId, opts.ctx.workspace.id),+ eq(monitorTag.id, opts.input.tagId),+ ),+ });++ const _monitors = await opts.ctx.db.query.monitor.findMany({+ where: and(+ eq(monitor.workspaceId, opts.ctx.workspace.id),+ inArray(monitor.id, opts.input.ids),+ ),+ });++ if (!_monitorTag || _monitors.length !== opts.input.ids.length) {+ throw new TRPCError({+ code: "BAD_REQUEST",+ message: "Invalid tag",+ });+ }++ if (opts.input.action === "add") {+ await opts.ctx.db+ .insert(monitorTagsToMonitors)+ .values(+ opts.input.ids.map((id) => ({+ monitorId: id,+ monitorTagId: opts.input.tagId,+ })),+ )+ .onConflictDoNothing()+ .run();+ }++ if (opts.input.action === "remove") {+ await opts.ctx.db+ .delete(monitorTagsToMonitors)+ .where(+ and(+ inArray(monitorTagsToMonitors.monitorId, opts.input.ids),+ eq(monitorTagsToMonitors.monitorTagId, opts.input.tagId),+ ),+ )+ .run();+ }+ }),+delete: protectedProcedure.input(z.object({ id: z.number() })).mutation(async (opts) => {@@ -439,6 +515,55 @@ export const monitorRouter = createTRPCRouter({await tx.delete(notificationsToMonitors).where(eq(notificationsToMonitors.monitorId, monitorToDelete.id));+ await tx+ .delete(maintenancesToMonitors)+ .where(eq(maintenancesToMonitors.monitorId, monitorToDelete.id));+ });+ }),++ deleteMonitors: protectedProcedure+ .input(z.object({ ids: z.number().array() }))+ .mutation(async (opts) => {+ const _monitors = await opts.ctx.db+ .select()+ .from(monitor)+ .where(+ and(+ inArray(monitor.id, opts.input.ids),+ eq(monitor.workspaceId, opts.ctx.workspace.id),+ ),+ )+ .all();++ if (_monitors.length !== opts.input.ids.length) {+ throw new TRPCError({+ code: "NOT_FOUND",+ message: "Monitor not found.",+ });+ }++ await opts.ctx.db+ .update(monitor)+ .set({ deletedAt: new Date(), active: false })+ .where(inArray(monitor.id, opts.input.ids))+ .run();++ await opts.ctx.db.transaction(async (tx) => {+ await tx+ .delete(monitorsToPages)+ .where(inArray(monitorsToPages.monitorId, opts.input.ids));+ await tx+ .delete(monitorTagsToMonitors)+ .where(inArray(monitorTagsToMonitors.monitorId, opts.input.ids));+ await tx+ .delete(monitorsToStatusReport)+ .where(inArray(monitorsToStatusReport.monitorId, opts.input.ids));+ await tx+ .delete(notificationsToMonitors)+ .where(inArray(notificationsToMonitors.monitorId, opts.input.ids));+ await tx+ .delete(maintenancesToMonitors)+ .where(inArray(maintenancesToMonitors.monitorId, opts.input.ids));});}),diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 1a86f89c1..cc4b4bd2f 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -305,6 +305,9 @@ importers:'@openstatus/utils':specifier: workspace:*version: link:../../packages/utils+ '@radix-ui/react-portal':+ specifier: ^1.0.4+ version: 1.0.4(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])'@sentry/integrations':specifier: 7.116.0version: 7.116.0@@ -10676,6 +10679,16 @@ snapshots:'@types/react': 18.2.64'@types/react-dom': 18.2.21+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@babel/runtime': 7.23.2+ '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.64+ '@types/react-dom': 18.2.21+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.23.2@@ -10727,6 +10740,16 @@ snapshots:react: 18.2.0react-dom: 18.3.1([email protected])+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@babel/runtime': 7.23.2+ '@radix-ui/react-slot': 1.0.2(@types/[email protected])([email protected])+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.64+ '@types/react-dom': 18.2.21+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.23.2