Skip to content

Open-source status page, incident response and uptime monitoring

feat: add icon to monitor description (#1082)

Maximilian Kaskefc7ef55bbe96
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/layout.tsx
index c829f0134..36b5c8c9a 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/layout.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/layout.tsx
@@ -5,6 +5,7 @@ import { Badge } from "@openstatus/ui/src/components/badge";
import { Header } from "@/components/dashboard/header";
import AppPageWithSidebarLayout from "@/components/layout/app-page-with-sidebar-layout";
import { JobTypeIconWithTooltip } from "@/components/monitor/job-type-icon-with-tooltip";
+import { NotificationIconWithTooltip } from "@/components/monitor/notification-icon-with-tooltip";
import { StatusDotWithTooltip } from "@/components/monitor/status-dot-with-tooltip";
import { TagBadgeWithTooltip } from "@/components/monitor/tag-badge-with-tooltip";
import { api } from "@/trpc/server";
@@ -72,6 +73,12 @@ export default async function Layout({
<Badge variant="secondary">public</Badge>
</>
) : null}
+ <span className="text-muted-foreground/50 text-xs">•</span>
+ <NotificationIconWithTooltip
+ notifications={monitor.monitorsToNotifications.map(
+ ({ notification }) => notification,
+ )}
+ />
</div>
}
/>
diff --git a/apps/web/src/components/data-table/monitor/columns.tsx b/apps/web/src/components/data-table/monitor/columns.tsx
index 2a6e7170b..e81247a12 100644
--- a/apps/web/src/components/data-table/monitor/columns.tsx
+++ b/apps/web/src/components/data-table/monitor/columns.tsx
@@ -80,11 +80,7 @@ export const columns: ColumnDef<{
{
accessorKey: "active",
accessorFn: (row) => row.monitor.active,
- header: () => (
- <div className="w-4">
- <Radio className="h-4 w-4" />
- </div>
- ),
+ header: () => <Radio className="h-4 w-4" />,
cell: ({ row }) => {
const { active, status } = row.original.monitor;
const maintenance = isActiveMaintenance(row.original.maintenances);
@@ -102,6 +98,9 @@ export const columns: ColumnDef<{
if (!Array.isArray(value)) return true;
return value.includes(row.original.monitor.active);
},
+ meta: {
+ headerClassName: "w-4",
+ },
},
{
accessorKey: "name",
@@ -130,6 +129,8 @@ export const columns: ColumnDef<{
header: "Tags",
cell: ({ row }) => {
const { tags } = row.original;
+ if (!tags?.length)
+ return <span className="text-muted-foreground">-</span>;
return <TagBadgeWithTooltip tags={tags} />;
},
filterFn: (row, _id, value) => {
diff --git a/apps/web/src/components/data-table/monitor/data-table.tsx b/apps/web/src/components/data-table/monitor/data-table.tsx
index fdeaaedc6..3aa4f4fdf 100644
--- a/apps/web/src/components/data-table/monitor/data-table.tsx
+++ b/apps/web/src/components/data-table/monitor/data-table.tsx
@@ -118,7 +118,10 @@ export function DataTable<TData, TValue>({
{headerGroup.headers.map((header) => {
return (
// FIXME: className="[&:has(svg)]:w-4" takes the svg of the button > checkbox into account
- <TableHead key={header.id}>
+ <TableHead
+ key={header.id}
+ className={header.column.columnDef.meta?.headerClassName}
+ >
{header.isPlaceholder
? null
: flexRender(
@@ -139,7 +142,10 @@ export function DataTable<TData, TValue>({
data-state={row.getIsSelected() && "selected"}
>
{row.getVisibleCells().map((cell) => (
- <TableCell key={cell.id}>
+ <TableCell
+ key={cell.id}
+ className={cell.column.columnDef.meta?.cellClassName}
+ >
{flexRender(
cell.column.columnDef.cell,
cell.getContext(),
diff --git a/apps/web/src/components/monitor/notification-icon-with-tooltip.tsx b/apps/web/src/components/monitor/notification-icon-with-tooltip.tsx
new file mode 100644
index 000000000..e897959e7
--- /dev/null
+++ b/apps/web/src/components/monitor/notification-icon-with-tooltip.tsx
@@ -0,0 +1,32 @@
+import type { Notification } from "@openstatus/db/src/schema";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@openstatus/ui/src/components/tooltip";
+
+import { Bell, BellOff } from "lucide-react";
+
+export function NotificationIconWithTooltip({
+ notifications,
+}: {
+ notifications?: Notification[];
+}) {
+ return (
+ <TooltipProvider>
+ <Tooltip delayDuration={200}>
+ <TooltipTrigger className="text-muted-foreground">
+ {notifications?.length ? (
+ <Bell className="h-4 w-4" />
+ ) : (
+ <BellOff className="h-4 w-4" />
+ )}
+ </TooltipTrigger>
+ <TooltipContent side="top" className="flex gap-2">
+ {`${notifications?.length || "No"} notification channels`}
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+}
diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.ts
index 7ee0785eb..12ee50829 100644
--- a/packages/api/src/router/monitor.ts
+++ b/packages/api/src/router/monitor.ts
@@ -190,6 +190,7 @@ export const monitorRouter = createTRPCRouter({
with: { maintenance: true },
where: eq(maintenancesToMonitors.monitorId, opts.input.id),
},
+ monitorsToNotifications: { with: { notification: true } },
},
});
@@ -201,6 +202,11 @@ export const monitorRouter = createTRPCRouter({
})
.array(),
maintenance: z.boolean().default(false).optional(),
+ monitorsToNotifications: z
+ .object({
+ notification: selectNotificationSchema,
+ })
+ .array(),
})
.safeParse({
..._monitor,