feat: add list controls and DNS check history
This commit is contained in:
parent
11b16ac3cf
commit
24351eb897
14 changed files with 511 additions and 28 deletions
|
|
@ -12,6 +12,7 @@ import { Label } from "@minmon/ui/components/label";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
|
|
@ -28,8 +29,8 @@ import {
|
||||||
} from "@minmon/ui/components/table";
|
} from "@minmon/ui/components/table";
|
||||||
import { Textarea } from "@minmon/ui/components/textarea";
|
import { Textarea } from "@minmon/ui/components/textarea";
|
||||||
import { Link } from "@tanstack/react-router";
|
import { Link } from "@tanstack/react-router";
|
||||||
import { Check, ChevronRight, Trash2 } from "lucide-react";
|
import { Check, ChevronLeft, ChevronRight, Trash2, X } from "lucide-react";
|
||||||
import { useEffect, useState, type ReactNode } from "react";
|
import { useEffect, useId, useMemo, useState, type ReactNode } from "react";
|
||||||
|
|
||||||
type BadgeVariant = "neutral" | "success" | "warning" | "destructive" | "info";
|
type BadgeVariant = "neutral" | "success" | "warning" | "destructive" | "info";
|
||||||
|
|
||||||
|
|
@ -80,6 +81,7 @@ export function ResourceListCard<TItem extends { id: string }>({
|
||||||
items,
|
items,
|
||||||
emptyTitle,
|
emptyTitle,
|
||||||
emptyDescription,
|
emptyDescription,
|
||||||
|
controls,
|
||||||
}: {
|
}: {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
|
@ -87,15 +89,139 @@ export function ResourceListCard<TItem extends { id: string }>({
|
||||||
items: TItem[];
|
items: TItem[];
|
||||||
emptyTitle: string;
|
emptyTitle: string;
|
||||||
emptyDescription: string;
|
emptyDescription: string;
|
||||||
|
controls?: {
|
||||||
|
search: {
|
||||||
|
placeholder: string;
|
||||||
|
getText: (item: TItem) => string;
|
||||||
|
};
|
||||||
|
filter?: {
|
||||||
|
label: string;
|
||||||
|
allLabel: string;
|
||||||
|
options: readonly { value: string; label: string }[];
|
||||||
|
getValue: (item: TItem) => string | string[];
|
||||||
|
};
|
||||||
|
initialPageSize?: number;
|
||||||
|
pageSizeOptions?: readonly number[];
|
||||||
|
};
|
||||||
}) {
|
}) {
|
||||||
|
const allFilterValue = "__all";
|
||||||
|
const controlId = useId();
|
||||||
|
const searchInputId = `${controlId}-search`;
|
||||||
|
const filterInputId = `${controlId}-filter`;
|
||||||
|
const pageSizeOptions = controls?.pageSizeOptions ?? [5, 10, 25];
|
||||||
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
const [filterValue, setFilterValue] = useState(allFilterValue);
|
||||||
|
const [pageSize, setPageSize] = useState(controls?.initialPageSize ?? 10);
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
|
||||||
|
const filteredItems = useMemo(() => {
|
||||||
|
if (!controls) return items;
|
||||||
|
|
||||||
|
const normalizedQuery = searchQuery.trim().toLocaleLowerCase();
|
||||||
|
|
||||||
|
return items.filter((item) => {
|
||||||
|
const matchesSearch =
|
||||||
|
!normalizedQuery || controls.search.getText(item).toLocaleLowerCase().includes(normalizedQuery);
|
||||||
|
const itemFilterValue = controls.filter?.getValue(item);
|
||||||
|
const matchesFilter =
|
||||||
|
!controls.filter ||
|
||||||
|
filterValue === allFilterValue ||
|
||||||
|
(Array.isArray(itemFilterValue)
|
||||||
|
? itemFilterValue.includes(filterValue)
|
||||||
|
: itemFilterValue === filterValue);
|
||||||
|
|
||||||
|
return matchesSearch && matchesFilter;
|
||||||
|
});
|
||||||
|
}, [controls, filterValue, items, searchQuery]);
|
||||||
|
|
||||||
|
const pageCount = controls ? Math.max(1, Math.ceil(filteredItems.length / pageSize)) : 1;
|
||||||
|
const currentPage = Math.min(page, pageCount);
|
||||||
|
const visibleItems = controls
|
||||||
|
? filteredItems.slice((currentPage - 1) * pageSize, currentPage * pageSize)
|
||||||
|
: filteredItems;
|
||||||
|
const hasActiveControls = Boolean(searchQuery || filterValue !== allFilterValue);
|
||||||
|
const selectedFilterLabel = controls?.filter
|
||||||
|
? filterValue === allFilterValue
|
||||||
|
? controls.filter.allLabel
|
||||||
|
: controls.filter.options.find((option) => option.value === filterValue)?.label
|
||||||
|
: undefined;
|
||||||
|
const firstVisibleItem = filteredItems.length ? (currentPage - 1) * pageSize + 1 : 0;
|
||||||
|
const lastVisibleItem = Math.min(currentPage * pageSize, filteredItems.length);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (page > pageCount) {
|
||||||
|
setPage(pageCount);
|
||||||
|
}
|
||||||
|
}, [page, pageCount]);
|
||||||
|
|
||||||
|
function resetControls() {
|
||||||
|
setSearchQuery("");
|
||||||
|
setFilterValue(allFilterValue);
|
||||||
|
setPage(1);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="py-0 pt-4 gap-0">
|
<Card className="py-0 pt-4 gap-0">
|
||||||
<CardHeader className="border-b">
|
<CardHeader className="border-b">
|
||||||
<CardTitle>{title}</CardTitle>
|
<CardTitle>{title}</CardTitle>
|
||||||
<CardDescription>{description}</CardDescription>
|
<CardDescription>{description}</CardDescription>
|
||||||
|
{controls && items.length ? (
|
||||||
|
<div className="flex flex-col gap-2 pt-2 sm:flex-row sm:items-center">
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<Label htmlFor={searchInputId} className="sr-only">
|
||||||
|
Search {title.toLocaleLowerCase()}
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id={searchInputId}
|
||||||
|
type="search"
|
||||||
|
aria-label={`Search ${title.toLocaleLowerCase()}`}
|
||||||
|
value={searchQuery}
|
||||||
|
placeholder={controls.search.placeholder}
|
||||||
|
onChange={(event) => {
|
||||||
|
setSearchQuery(event.target.value);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{controls.filter ? (
|
||||||
|
<div className="sm:w-44">
|
||||||
|
<Label htmlFor={filterInputId} className="sr-only">
|
||||||
|
{controls.filter.label}
|
||||||
|
</Label>
|
||||||
|
<Select
|
||||||
|
value={filterValue}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
setFilterValue(value ?? allFilterValue);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger id={filterInputId} className="w-full" aria-label={controls.filter.label}>
|
||||||
|
<SelectValue>{selectedFilterLabel}</SelectValue>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
<SelectItem value={allFilterValue}>{controls.filter.allLabel}</SelectItem>
|
||||||
|
{controls.filter.options.map((option) => (
|
||||||
|
<SelectItem key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{hasActiveControls ? (
|
||||||
|
<Button type="button" variant="ghost" onClick={resetControls}>
|
||||||
|
<X data-icon="inline-start" />
|
||||||
|
Clear
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="px-0">
|
<CardContent className="px-0">
|
||||||
{items.length ? (
|
{visibleItems.length ? (
|
||||||
<TableWrapper className="border-0">
|
<TableWrapper className="border-0">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
|
|
@ -108,7 +234,7 @@ export function ResourceListCard<TItem extends { id: string }>({
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{items.map((item) => (
|
{visibleItems.map((item) => (
|
||||||
<TableRow key={item.id}>
|
<TableRow key={item.id}>
|
||||||
{columns.map((column) => (
|
{columns.map((column) => (
|
||||||
<TableCell key={column.key} className={column.className}>
|
<TableCell key={column.key} className={column.className}>
|
||||||
|
|
@ -120,10 +246,74 @@ export function ResourceListCard<TItem extends { id: string }>({
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableWrapper>
|
</TableWrapper>
|
||||||
|
) : items.length ? (
|
||||||
|
<EmptyState
|
||||||
|
title="No matching results"
|
||||||
|
description="Try another search term or clear the current filter."
|
||||||
|
action={
|
||||||
|
<Button type="button" variant="outline" onClick={resetControls}>
|
||||||
|
Clear search and filter
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
className="border-0"
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<EmptyState title={emptyTitle} description={emptyDescription} className="border-0" />
|
<EmptyState title={emptyTitle} description={emptyDescription} className="border-0" />
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
{controls && items.length ? (
|
||||||
|
<CardFooter className="flex-col items-stretch gap-3 border-t py-3 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<p className="text-xs text-muted-foreground tabular-nums" aria-live="polite">
|
||||||
|
Showing {firstVisibleItem}–{lastVisibleItem} of {filteredItems.length}
|
||||||
|
</p>
|
||||||
|
<div className="flex items-center justify-between gap-2 sm:justify-end">
|
||||||
|
<Select
|
||||||
|
value={String(pageSize)}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
if (!value) return;
|
||||||
|
setPageSize(Number(value));
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger aria-label="Rows per page">
|
||||||
|
<SelectValue>{pageSize} per page</SelectValue>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
{pageSizeOptions.map((option) => (
|
||||||
|
<SelectItem key={option} value={String(option)}>
|
||||||
|
{option} per page
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<span className="min-w-20 text-center text-xs text-muted-foreground tabular-nums">
|
||||||
|
Page {currentPage} of {pageCount}
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
aria-label="Previous page"
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
onClick={() => setPage((current) => Math.max(1, current - 1))}
|
||||||
|
>
|
||||||
|
<ChevronLeft />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
aria-label="Next page"
|
||||||
|
disabled={currentPage === pageCount}
|
||||||
|
onClick={() => setPage((current) => Math.min(pageCount, current + 1))}
|
||||||
|
>
|
||||||
|
<ChevronRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardFooter>
|
||||||
|
) : null}
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -329,11 +519,13 @@ export function SelectField({
|
||||||
</SelectValue>
|
</SelectValue>
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{options.map((option) => (
|
<SelectGroup>
|
||||||
<SelectItem key={option.value} value={option.value}>
|
{options.map((option) => (
|
||||||
{option.label}
|
<SelectItem key={option.value} value={option.value}>
|
||||||
</SelectItem>
|
{option.label}
|
||||||
))}
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,32 @@ function RouteComponent() {
|
||||||
items={domains.data}
|
items={domains.data}
|
||||||
emptyTitle="No domains added"
|
emptyTitle="No domains added"
|
||||||
emptyDescription="Create a domain after adding a service."
|
emptyDescription="Create a domain after adding a service."
|
||||||
|
controls={{
|
||||||
|
search: {
|
||||||
|
placeholder: "Search domain, service, or IP address…",
|
||||||
|
getText: (item) =>
|
||||||
|
[
|
||||||
|
item.name,
|
||||||
|
serviceMap.get(item.serviceId),
|
||||||
|
item.expectedServerIp,
|
||||||
|
item.lastResolvedIp,
|
||||||
|
...item.lastResolvedIps,
|
||||||
|
item.remarks,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(" "),
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
label: "Filter by DNS status",
|
||||||
|
allLabel: "All DNS statuses",
|
||||||
|
options: [
|
||||||
|
{ value: "MATCH", label: "Match" },
|
||||||
|
{ value: "MISMATCH", label: "Mismatch" },
|
||||||
|
{ value: "UNRESOLVED", label: "Unresolved" },
|
||||||
|
],
|
||||||
|
getValue: (item) => item.resolutionStatus,
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { DetailCard, FormCard, PageSection, QueryStateCard, SelectField, TextAreaField, TextField } from "@/components/dashboard-ui";
|
import { DetailCard, FormCard, PageSection, QueryStateCard, ResourceListCard, SelectField, TextAreaField, TextField } from "@/components/dashboard-ui";
|
||||||
import { queryClient, trpc, trpcClient } from "@/utils/trpc";
|
import { queryClient, trpc, trpcClient } from "@/utils/trpc";
|
||||||
import { Button } from "@minmon/ui/components/button";
|
import { Button } from "@minmon/ui/components/button";
|
||||||
import { StatusBadge } from "@minmon/ui/components/status-badge";
|
import { StatusBadge } from "@minmon/ui/components/status-badge";
|
||||||
|
|
@ -29,6 +29,7 @@ function RouteComponent() {
|
||||||
const { domainId } = Route.useParams();
|
const { domainId } = Route.useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const domain = useQuery(trpc.domains.byId.queryOptions({ id: domainId }));
|
const domain = useQuery(trpc.domains.byId.queryOptions({ id: domainId }));
|
||||||
|
const history = useQuery(trpc.domains.history.queryOptions({ id: domainId }));
|
||||||
const services = useQuery(trpc.domains.serviceOptions.queryOptions());
|
const services = useQuery(trpc.domains.serviceOptions.queryOptions());
|
||||||
|
|
||||||
const updateDomain = useMutation({
|
const updateDomain = useMutation({
|
||||||
|
|
@ -51,6 +52,7 @@ function RouteComponent() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await queryClient.invalidateQueries({ queryKey: trpc.domains.byId.queryKey({ id: domainId }) });
|
await queryClient.invalidateQueries({ queryKey: trpc.domains.byId.queryKey({ id: domainId }) });
|
||||||
|
await queryClient.invalidateQueries({ queryKey: trpc.domains.history.queryKey({ id: domainId }) });
|
||||||
await queryClient.invalidateQueries({ queryKey: trpc.domains.list.queryKey() });
|
await queryClient.invalidateQueries({ queryKey: trpc.domains.list.queryKey() });
|
||||||
},
|
},
|
||||||
onError: (error) => toast.error(error.message),
|
onError: (error) => toast.error(error.message),
|
||||||
|
|
@ -60,6 +62,7 @@ function RouteComponent() {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
toast.success("DNS check completed");
|
toast.success("DNS check completed");
|
||||||
await queryClient.invalidateQueries({ queryKey: trpc.domains.byId.queryKey({ id: domainId }) });
|
await queryClient.invalidateQueries({ queryKey: trpc.domains.byId.queryKey({ id: domainId }) });
|
||||||
|
await queryClient.invalidateQueries({ queryKey: trpc.domains.history.queryKey({ id: domainId }) });
|
||||||
await queryClient.invalidateQueries({ queryKey: trpc.domains.list.queryKey() });
|
await queryClient.invalidateQueries({ queryKey: trpc.domains.list.queryKey() });
|
||||||
},
|
},
|
||||||
onError: (error) => toast.error(error.message),
|
onError: (error) => toast.error(error.message),
|
||||||
|
|
@ -119,6 +122,82 @@ function RouteComponent() {
|
||||||
/>
|
/>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
|
|
||||||
|
<PageSection
|
||||||
|
title="DNS check history"
|
||||||
|
description="A chronological record of every DNS check run for this domain."
|
||||||
|
>
|
||||||
|
{history.isLoading ? (
|
||||||
|
<QueryStateCard title="Loading DNS history" description="Fetching earlier resolution checks." />
|
||||||
|
) : history.isError || !history.data ? (
|
||||||
|
<QueryStateCard title="DNS history unavailable" description="Earlier DNS checks could not be loaded." />
|
||||||
|
) : (
|
||||||
|
<ResourceListCard
|
||||||
|
title="Resolution timeline"
|
||||||
|
description="Compare resolved A records with the expected server IP at the time of each check."
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
key: "checkedAt",
|
||||||
|
header: "Checked",
|
||||||
|
className: "w-48",
|
||||||
|
render: (item: (typeof history.data)[number]) => (
|
||||||
|
<span className="tabular-nums">{new Date(item.checkedAt).toLocaleString()}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "status",
|
||||||
|
header: "Status",
|
||||||
|
className: "w-36",
|
||||||
|
render: (item: (typeof history.data)[number]) => (
|
||||||
|
<StatusBadge variant={dnsStatusVariant(item.status)}>{item.status}</StatusBadge>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "expectedServerIp",
|
||||||
|
header: "Expected IP",
|
||||||
|
render: (item: (typeof history.data)[number]) => item.expectedServerIp,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "resolvedIps",
|
||||||
|
header: "Resolved IPv4",
|
||||||
|
render: (item: (typeof history.data)[number]) => item.resolvedIps.join(", ") || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "message",
|
||||||
|
header: "Result",
|
||||||
|
render: (item: (typeof history.data)[number]) =>
|
||||||
|
item.message ||
|
||||||
|
(item.status === "MATCH"
|
||||||
|
? "Expected IP found"
|
||||||
|
: "Expected IP not found in the A records"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
items={history.data}
|
||||||
|
emptyTitle="No DNS checks yet"
|
||||||
|
emptyDescription="Run Check DNS to create the first history entry for this domain."
|
||||||
|
controls={{
|
||||||
|
search: {
|
||||||
|
placeholder: "Search IP address, status, or result…",
|
||||||
|
getText: (item) =>
|
||||||
|
[item.status, item.expectedServerIp, ...item.resolvedIps, item.message]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(" "),
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
label: "Filter by DNS status",
|
||||||
|
allLabel: "All DNS statuses",
|
||||||
|
options: [
|
||||||
|
{ value: "MATCH", label: "Match" },
|
||||||
|
{ value: "MISMATCH", label: "Mismatch" },
|
||||||
|
{ value: "UNRESOLVED", label: "Unresolved" },
|
||||||
|
],
|
||||||
|
getValue: (item) => item.status,
|
||||||
|
},
|
||||||
|
initialPageSize: 5,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</PageSection>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
className="grid gap-4"
|
className="grid gap-4"
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,19 @@ function RouteComponent() {
|
||||||
items={notes.data}
|
items={notes.data}
|
||||||
emptyTitle="No notes yet"
|
emptyTitle="No notes yet"
|
||||||
emptyDescription="Add a note to document maintenance, incidents, or general server information."
|
emptyDescription="Add a note to document maintenance, incidents, or general server information."
|
||||||
|
controls={{
|
||||||
|
search: {
|
||||||
|
placeholder: "Search title, note, category, or server…",
|
||||||
|
getText: (item) =>
|
||||||
|
[item.title, item.content, item.category, serverMap.get(item.serverId)].filter(Boolean).join(" "),
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
label: "Filter by server",
|
||||||
|
allLabel: "All servers",
|
||||||
|
options: servers.data.map((item) => ({ value: item.id, label: item.name })),
|
||||||
|
getValue: (item) => item.serverId,
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,33 @@ function RouteComponent() {
|
||||||
items={servers.data}
|
items={servers.data}
|
||||||
emptyTitle="No servers added"
|
emptyTitle="No servers added"
|
||||||
emptyDescription="Add your first server to start managing services, notes, and domains."
|
emptyDescription="Add your first server to start managing services, notes, and domains."
|
||||||
|
controls={{
|
||||||
|
search: {
|
||||||
|
placeholder: "Search name, IP, location, or provider…",
|
||||||
|
getText: (item) =>
|
||||||
|
[
|
||||||
|
item.name,
|
||||||
|
item.primaryIpAddress,
|
||||||
|
item.secondaryIpAddress,
|
||||||
|
item.operatingSystem,
|
||||||
|
item.location,
|
||||||
|
item.provider,
|
||||||
|
item.description,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(" "),
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
label: "Filter by server status",
|
||||||
|
allLabel: "All statuses",
|
||||||
|
options: [
|
||||||
|
{ value: "active", label: "Active" },
|
||||||
|
{ value: "maintenance", label: "Maintenance" },
|
||||||
|
{ value: "inactive", label: "Inactive" },
|
||||||
|
],
|
||||||
|
getValue: (item) => item.status,
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,12 @@ function RouteComponent() {
|
||||||
items={notes.data}
|
items={notes.data}
|
||||||
emptyTitle="No notes for this server"
|
emptyTitle="No notes for this server"
|
||||||
emptyDescription="Add a note to document maintenance, incidents, or internal server context."
|
emptyDescription="Add a note to document maintenance, incidents, or internal server context."
|
||||||
|
controls={{
|
||||||
|
search: {
|
||||||
|
placeholder: "Search attached notes…",
|
||||||
|
getText: (item) => [item.title, item.content, item.category].filter(Boolean).join(" "),
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,33 @@ function RouteComponent() {
|
||||||
items={services.data}
|
items={services.data}
|
||||||
emptyTitle="No services added"
|
emptyTitle="No services added"
|
||||||
emptyDescription="Create a service after adding at least one server."
|
emptyDescription="Create a service after adding at least one server."
|
||||||
|
controls={{
|
||||||
|
search: {
|
||||||
|
placeholder: "Search service, server, port, or protocol…",
|
||||||
|
getText: (item) =>
|
||||||
|
[
|
||||||
|
item.name,
|
||||||
|
serverMap.get(item.serverId),
|
||||||
|
item.internalPort,
|
||||||
|
item.externalPort,
|
||||||
|
item.protocol,
|
||||||
|
item.type,
|
||||||
|
item.description,
|
||||||
|
]
|
||||||
|
.filter((value) => value !== null && value !== undefined)
|
||||||
|
.join(" "),
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
label: "Filter by service status",
|
||||||
|
allLabel: "All statuses",
|
||||||
|
options: [
|
||||||
|
{ value: "active", label: "Active" },
|
||||||
|
{ value: "maintenance", label: "Maintenance" },
|
||||||
|
{ value: "down", label: "Down" },
|
||||||
|
],
|
||||||
|
getValue: (item) => item.status,
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,18 @@ function RoleAssignmentCard({ roles, permissions }: { roles: RoleOption[]; permi
|
||||||
items={users.data}
|
items={users.data}
|
||||||
emptyTitle="No users found"
|
emptyTitle="No users found"
|
||||||
emptyDescription="Users appear here after they sign up or are seeded."
|
emptyDescription="Users appear here after they sign up or are seeded."
|
||||||
|
controls={{
|
||||||
|
search: {
|
||||||
|
placeholder: "Search name, email, or role…",
|
||||||
|
getText: (item) => [item.name, item.email, ...item.roles.map((role) => role.name)].join(" "),
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
label: "Filter by role",
|
||||||
|
allLabel: "All roles",
|
||||||
|
options: roles.map((role) => ({ value: role.id, label: role.name })),
|
||||||
|
getValue: (item) => item.roles.map((role) => role.id),
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { createDb, domain } from "@minmon/db";
|
import { createDb, domain, domainCheckHistory } from "@minmon/db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { resolve4 } from "node:dns/promises";
|
import { resolve4 } from "node:dns/promises";
|
||||||
import { Effect } from "effect";
|
import { Effect } from "effect";
|
||||||
|
|
@ -46,22 +46,41 @@ export async function persistDomainCheck(
|
||||||
database: ReturnType<typeof createDb>,
|
database: ReturnType<typeof createDb>,
|
||||||
input: {
|
input: {
|
||||||
domainId: string;
|
domainId: string;
|
||||||
|
expectedServerIp: string;
|
||||||
result: DomainCheckResult;
|
result: DomainCheckResult;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const [updatedDomain] = await database
|
return database.transaction(async (transaction) => {
|
||||||
.update(domain)
|
const [historyEntry] = await transaction
|
||||||
.set({
|
.insert(domainCheckHistory)
|
||||||
resolutionStatus: input.result.status,
|
.values({
|
||||||
lastResolvedIps: input.result.resolvedIps,
|
id: crypto.randomUUID(),
|
||||||
lastResolvedIp: input.result.resolvedIps[0] ?? null,
|
domainId: input.domainId,
|
||||||
lastCheckedAt: input.result.checkedAt,
|
expectedServerIp: input.expectedServerIp,
|
||||||
lastCheckMessage: input.result.message,
|
status: input.result.status,
|
||||||
})
|
resolvedIps: input.result.resolvedIps,
|
||||||
.where(eq(domain.id, input.domainId))
|
message: input.result.message,
|
||||||
.returning();
|
checkedAt: input.result.checkedAt,
|
||||||
|
})
|
||||||
|
.returning();
|
||||||
|
|
||||||
return updatedDomain ?? null;
|
const [updatedDomain] = await transaction
|
||||||
|
.update(domain)
|
||||||
|
.set({
|
||||||
|
resolutionStatus: input.result.status,
|
||||||
|
lastResolvedIps: input.result.resolvedIps,
|
||||||
|
lastResolvedIp: input.result.resolvedIps[0] ?? null,
|
||||||
|
lastCheckedAt: input.result.checkedAt,
|
||||||
|
lastCheckMessage: input.result.message,
|
||||||
|
})
|
||||||
|
.where(eq(domain.id, input.domainId))
|
||||||
|
.returning();
|
||||||
|
|
||||||
|
return {
|
||||||
|
domain: updatedDomain ?? null,
|
||||||
|
historyEntry: historyEntry ?? null,
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runAndPersistDomainCheck(
|
export async function runAndPersistDomainCheck(
|
||||||
|
|
@ -79,13 +98,15 @@ export async function runAndPersistDomainCheck(
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const updatedDomain = await persistDomainCheck(database, {
|
const persisted = await persistDomainCheck(database, {
|
||||||
domainId: input.domainId,
|
domainId: input.domainId,
|
||||||
|
expectedServerIp: input.expectedServerIp,
|
||||||
result,
|
result,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result,
|
result,
|
||||||
domain: updatedDomain,
|
domain: persisted.domain,
|
||||||
|
historyEntry: persisted.historyEntry,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { db } from "@minmon/db";
|
import { db } from "@minmon/db";
|
||||||
import { domain, service } from "@minmon/db";
|
import { domain, domainCheckHistory, service } from "@minmon/db";
|
||||||
import { desc, eq } from "drizzle-orm";
|
import { desc, eq } from "drizzle-orm";
|
||||||
|
|
||||||
import { runAndPersistDomainCheck } from "../lib/domain-check";
|
import { runAndPersistDomainCheck } from "../lib/domain-check";
|
||||||
|
|
@ -37,6 +37,16 @@ export const domainsRouter = router({
|
||||||
return requireDomain(input.id);
|
return requireDomain(input.id);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
history: permissionedProcedure("domains.read").input(byIdSchema).query(async ({ input }) => {
|
||||||
|
await requireDomain(input.id);
|
||||||
|
|
||||||
|
return db
|
||||||
|
.select()
|
||||||
|
.from(domainCheckHistory)
|
||||||
|
.where(eq(domainCheckHistory.domainId, input.id))
|
||||||
|
.orderBy(desc(domainCheckHistory.checkedAt), desc(domainCheckHistory.id));
|
||||||
|
}),
|
||||||
|
|
||||||
create: permissionedProcedure("domains.create").input(domainCreateSchema).mutation(async ({ input }) => {
|
create: permissionedProcedure("domains.create").input(domainCreateSchema).mutation(async ({ input }) => {
|
||||||
const { service: parentService, server: parentServer } = await requireServiceWithServer(input.serviceId);
|
const { service: parentService, server: parentServer } = await requireServiceWithServer(input.serviceId);
|
||||||
|
|
||||||
|
|
@ -96,6 +106,7 @@ export const domainsRouter = router({
|
||||||
return {
|
return {
|
||||||
domain: result.domain ?? existing,
|
domain: result.domain ?? existing,
|
||||||
check: result.result,
|
check: result.result,
|
||||||
|
historyEntry: result.historyEntry,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
|
||||||
17
packages/db/src/migrations/0003_add_domain_check_history.sql
Normal file
17
packages/db/src/migrations/0003_add_domain_check_history.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS "domain_check_history" (
|
||||||
|
"id" text PRIMARY KEY NOT NULL,
|
||||||
|
"domain_id" text NOT NULL,
|
||||||
|
"expected_server_ip" text NOT NULL,
|
||||||
|
"status" "domain_resolution_status" NOT NULL,
|
||||||
|
"resolved_ips" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||||
|
"message" text,
|
||||||
|
"checked_at" timestamp DEFAULT now() NOT NULL
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "domain_check_history" ADD CONSTRAINT "domain_check_history_domain_id_domain_id_fk" FOREIGN KEY ("domain_id") REFERENCES "public"."domain"("id") ON DELETE cascade ON UPDATE no action;
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "domain_check_history_domain_id_idx" ON "domain_check_history" USING btree ("domain_id");
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "domain_check_history_checked_at_idx" ON "domain_check_history" USING btree ("checked_at");
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "domain_check_history_status_idx" ON "domain_check_history" USING btree ("status");
|
||||||
|
|
@ -22,6 +22,13 @@
|
||||||
"when": 1782698400000,
|
"when": 1782698400000,
|
||||||
"tag": "0002_user_lifecycle_permissions",
|
"tag": "0002_user_lifecycle_permissions",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 3,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1786104000000,
|
||||||
|
"tag": "0003_add_domain_check_history",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,29 @@ export const domain = pgTable(
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const domainCheckHistory = pgTable(
|
||||||
|
"domain_check_history",
|
||||||
|
{
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
domainId: text("domain_id")
|
||||||
|
.notNull()
|
||||||
|
.references(() => domain.id, { onDelete: "cascade" }),
|
||||||
|
expectedServerIp: text("expected_server_ip").notNull(),
|
||||||
|
status: domainResolutionStatusEnum("status").notNull(),
|
||||||
|
resolvedIps: jsonb("resolved_ips")
|
||||||
|
.$type<string[]>()
|
||||||
|
.default(sql`'[]'::jsonb`)
|
||||||
|
.notNull(),
|
||||||
|
message: text("message"),
|
||||||
|
checkedAt: timestamp("checked_at").defaultNow().notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
index("domain_check_history_domain_id_idx").on(table.domainId),
|
||||||
|
index("domain_check_history_checked_at_idx").on(table.checkedAt),
|
||||||
|
index("domain_check_history_status_idx").on(table.status),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
export const note = pgTable(
|
export const note = pgTable(
|
||||||
"note",
|
"note",
|
||||||
{
|
{
|
||||||
|
|
@ -153,11 +176,19 @@ export const serviceRelations = relations(service, ({ one, many }) => ({
|
||||||
domains: many(domain),
|
domains: many(domain),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const domainRelations = relations(domain, ({ one }) => ({
|
export const domainRelations = relations(domain, ({ one, many }) => ({
|
||||||
service: one(service, {
|
service: one(service, {
|
||||||
fields: [domain.serviceId],
|
fields: [domain.serviceId],
|
||||||
references: [service.id],
|
references: [service.id],
|
||||||
}),
|
}),
|
||||||
|
checks: many(domainCheckHistory),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const domainCheckHistoryRelations = relations(domainCheckHistory, ({ one }) => ({
|
||||||
|
domain: one(domain, {
|
||||||
|
fields: [domainCheckHistory.domainId],
|
||||||
|
references: [domain.id],
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const noteRelations = relations(note, ({ one }) => ({
|
export const noteRelations = relations(note, ({ one }) => ({
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ dotenv.config({
|
||||||
|
|
||||||
import { db } from "./index";
|
import { db } from "./index";
|
||||||
import { account, permission, role, rolePermission, user, userRole } from "./schema/auth";
|
import { account, permission, role, rolePermission, user, userRole } from "./schema/auth";
|
||||||
import { domain, note, server, service } from "./schema/monitoring";
|
import { domain, domainCheckHistory, note, server, service } from "./schema/monitoring";
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const earlierToday = new Date(now.getTime() - 45 * 60 * 1000);
|
const earlierToday = new Date(now.getTime() - 45 * 60 * 1000);
|
||||||
|
|
@ -293,6 +293,20 @@ async function seedMonitoringData() {
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await db.insert(domainCheckHistory).values(
|
||||||
|
domains
|
||||||
|
.filter((item) => item.lastCheckedAt)
|
||||||
|
.map((item) => ({
|
||||||
|
id: `history_${item.id}`,
|
||||||
|
domainId: item.id,
|
||||||
|
expectedServerIp: item.expectedServerIp,
|
||||||
|
status: item.resolutionStatus,
|
||||||
|
resolvedIps: item.lastResolvedIps,
|
||||||
|
message: item.lastCheckMessage,
|
||||||
|
checkedAt: item.lastCheckedAt,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
await db.insert(note).values(
|
await db.insert(note).values(
|
||||||
notes.map((item) => ({
|
notes.map((item) => ({
|
||||||
...item,
|
...item,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue