@haakco/custd-react 3.72.0 → 3.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/monitoring-section.d.ts +16 -0
- package/dist/monitoring-section.js +9 -0
- package/dist/site-lighthouse-panel.d.ts +14 -0
- package/dist/site-lighthouse-panel.js +21 -0
- package/dist/site-status-page.d.ts +14 -0
- package/dist/site-status-page.js +23 -0
- package/dist/site-uptime-panel.d.ts +34 -0
- package/dist/site-uptime-panel.js +42 -0
- package/dist/uptime-charts.d.ts +27 -0
- package/dist/uptime-charts.js +56 -0
- package/monitoring.css +72 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -24,6 +24,12 @@ GitHub tags with checked-in distributions are the publication owner, not a
|
|
|
24
24
|
private registry. The state-display component renders DOM elements and is for
|
|
25
25
|
web applications; native apps use the core SDK and authenticated backend relay.
|
|
26
26
|
|
|
27
|
+
## Site monitoring templates
|
|
28
|
+
|
|
29
|
+
Use the [site monitoring templates](../README.md#site-monitoring-templates) for
|
|
30
|
+
drop-in uptime history, Lighthouse scores, and a public status view. Each can
|
|
31
|
+
use your site's CSS and display copy.
|
|
32
|
+
|
|
27
33
|
## Query and display
|
|
28
34
|
|
|
29
35
|
```tsx
|
package/dist/index.d.ts
CHANGED
|
@@ -42,3 +42,7 @@ export { QuantityHistogram, type QuantityHistogramLabels, type QuantityHistogram
|
|
|
42
42
|
export { SafeMarkdown, type SafeMarkdownProps } from "./safe-markdown.js";
|
|
43
43
|
export { rankSensitivityInputs, SensitivityView, type SensitivityViewLabels, type SensitivityViewProps, } from "./sensitivity-view.js";
|
|
44
44
|
export { type CustdSession, CustdSessionProvider, type CustdSessionProviderProps, useCustdSession } from "./session.js";
|
|
45
|
+
export { SiteLighthousePanel, type SiteLighthousePanelProps } from "./site-lighthouse-panel.js";
|
|
46
|
+
export { SiteStatusPageView, type SiteStatusPageViewProps } from "./site-status-page.js";
|
|
47
|
+
export { SiteUptimePanel, type SiteUptimePanelProps } from "./site-uptime-panel.js";
|
|
48
|
+
export { DailyUptimeChart, type DailyUptimeChartProps, UptimeResponseChart, type UptimeResponseChartProps, } from "./uptime-charts.js";
|
package/dist/index.js
CHANGED
|
@@ -66,3 +66,7 @@ export { QuantityHistogram, } from "./quantity-histogram.js";
|
|
|
66
66
|
export { SafeMarkdown } from "./safe-markdown.js";
|
|
67
67
|
export { rankSensitivityInputs, SensitivityView, } from "./sensitivity-view.js";
|
|
68
68
|
export { CustdSessionProvider, useCustdSession } from "./session.js";
|
|
69
|
+
export { SiteLighthousePanel } from "./site-lighthouse-panel.js";
|
|
70
|
+
export { SiteStatusPageView } from "./site-status-page.js";
|
|
71
|
+
export { SiteUptimePanel } from "./site-uptime-panel.js";
|
|
72
|
+
export { DailyUptimeChart, UptimeResponseChart, } from "./uptime-charts.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from "react";
|
|
2
|
+
export type MonitoringAppearance = {
|
|
3
|
+
className?: string;
|
|
4
|
+
style?: CSSProperties;
|
|
5
|
+
};
|
|
6
|
+
type MonitoringSectionProps = MonitoringAppearance & {
|
|
7
|
+
part: "uptime-panel" | "lighthouse-panel" | "status-page";
|
|
8
|
+
title: string;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare function MonitoringSection({ part, title, className, style, children }: MonitoringSectionProps): import("react").JSX.Element;
|
|
12
|
+
export declare function MonitoringMetrics({ part, children, }: {
|
|
13
|
+
part: "uptime-windows" | "lighthouse-scores";
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
export function MonitoringSection({ part, title, className, style, children }) {
|
|
4
|
+
const titleId = useId();
|
|
5
|
+
return (_jsxs("section", { className: className, style: style, "aria-labelledby": titleId, "data-custd-monitoring": "", "data-custd-part": part, children: [_jsx("h2", { id: titleId, children: title }), children] }));
|
|
6
|
+
}
|
|
7
|
+
export function MonitoringMetrics({ part, children, }) {
|
|
8
|
+
return (_jsx("dl", { "data-custd-metrics": "", "data-custd-part": part, children: children }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SiteLighthouseHistory, SiteLighthouseProfile, SiteLighthouseScores } from "@haakco/custd-sdk";
|
|
2
|
+
import { type MonitoringAppearance } from "./monitoring-section.js";
|
|
3
|
+
export type SiteLighthousePanelProps = MonitoringAppearance & {
|
|
4
|
+
history: SiteLighthouseHistory;
|
|
5
|
+
labels?: Partial<{
|
|
6
|
+
title: string;
|
|
7
|
+
empty: string;
|
|
8
|
+
failed: string;
|
|
9
|
+
unavailable: string;
|
|
10
|
+
} & Record<SiteLighthouseProfile | keyof SiteLighthouseScores, string>>;
|
|
11
|
+
formatTime?: (timestamp: string) => string;
|
|
12
|
+
formatScore?: (score: number) => string;
|
|
13
|
+
};
|
|
14
|
+
export declare function SiteLighthousePanel({ history, className, style, labels, formatTime, formatScore, }: SiteLighthousePanelProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MonitoringMetrics, MonitoringSection } from "./monitoring-section.js";
|
|
3
|
+
const profiles = ["desktop", "mobile"];
|
|
4
|
+
const scoreLabels = {
|
|
5
|
+
performance: "Performance",
|
|
6
|
+
accessibility: "Accessibility",
|
|
7
|
+
bestPractices: "Best practices",
|
|
8
|
+
seo: "SEO",
|
|
9
|
+
};
|
|
10
|
+
const scores = Object.keys(scoreLabels);
|
|
11
|
+
export function SiteLighthousePanel({ history, className, style, labels, formatTime = (value) => value, formatScore = String, }) {
|
|
12
|
+
return (_jsx(MonitoringSection, { part: "lighthouse-panel", title: labels?.title ?? "Lighthouse scores", className: className, style: style, children: profiles.map((profile) => {
|
|
13
|
+
const run = history.runs
|
|
14
|
+
.filter((run) => run.profile === profile)
|
|
15
|
+
.reduce((latest, current) => !latest || Date.parse(current.observedAt) > Date.parse(latest.observedAt) ? current : latest, undefined);
|
|
16
|
+
return (_jsxs("div", { "data-custd-part": "lighthouse-profile", "data-profile": profile, children: [_jsx("h3", { children: labels?.[profile] ?? (profile === "desktop" ? "Desktop" : "Mobile") }), run && _jsx("time", { dateTime: run.observedAt, children: formatTime(run.observedAt) }), !run && _jsx("p", { children: labels?.empty ?? "No runs yet." }), run?.outcome === "failed" && _jsx("p", { children: labels?.failed ?? "The latest run failed." }), run?.outcome === "success" && (_jsx(MonitoringMetrics, { part: "lighthouse-scores", children: scores.map((key) => {
|
|
17
|
+
const score = run.scores[key];
|
|
18
|
+
return (_jsxs("div", { "data-score": key, children: [_jsx("dt", { children: labels?.[key] ?? scoreLabels[key] }), _jsx("dd", { children: score === undefined ? (labels?.unavailable ?? "Unavailable") : formatScore(score) })] }, key));
|
|
19
|
+
}) }))] }, profile));
|
|
20
|
+
}) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SiteStatusComponentStatus, SiteStatusPage } from "@haakco/custd-sdk";
|
|
2
|
+
import { type MonitoringAppearance } from "./monitoring-section.js";
|
|
3
|
+
export type SiteStatusPageViewProps = MonitoringAppearance & {
|
|
4
|
+
page: SiteStatusPage;
|
|
5
|
+
labels?: Partial<{
|
|
6
|
+
components: string;
|
|
7
|
+
updates: string;
|
|
8
|
+
noComponents: string;
|
|
9
|
+
noUpdates: string;
|
|
10
|
+
}>;
|
|
11
|
+
statusLabels?: Partial<Record<SiteStatusComponentStatus, string>>;
|
|
12
|
+
formatTime?: (timestamp: string) => string;
|
|
13
|
+
};
|
|
14
|
+
export declare function SiteStatusPageView({ page, className, style, labels, statusLabels, formatTime, }: SiteStatusPageViewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MonitoringSection } from "./monitoring-section.js";
|
|
3
|
+
const defaultStatusLabels = {
|
|
4
|
+
up: "Operational",
|
|
5
|
+
down: "Outage",
|
|
6
|
+
failing: "Degraded",
|
|
7
|
+
maintenance: "Maintenance",
|
|
8
|
+
paused: "Monitoring paused",
|
|
9
|
+
unknown: "Status unknown",
|
|
10
|
+
};
|
|
11
|
+
// Public status data omits internal IDs and allows duplicate public labels.
|
|
12
|
+
function labelledKeys(values, labelOf) {
|
|
13
|
+
const counts = new Map();
|
|
14
|
+
return values.map((value) => {
|
|
15
|
+
const label = labelOf(value);
|
|
16
|
+
const count = (counts.get(label) ?? 0) + 1;
|
|
17
|
+
counts.set(label, count);
|
|
18
|
+
return { value, key: JSON.stringify([label, count]) };
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function SiteStatusPageView({ page, className, style, labels, statusLabels, formatTime = (value) => value, }) {
|
|
22
|
+
return (_jsxs(MonitoringSection, { part: "status-page", title: page.title, className: className, style: style, children: [_jsx("h3", { children: labels?.components ?? "Components" }), page.components.length === 0 ? (_jsx("p", { children: labels?.noComponents ?? "No components listed." })) : (_jsx("ul", { "data-custd-part": "status-components", children: labelledKeys(page.components, (component) => component.label).map(({ value: component, key }) => (_jsxs("li", { "data-custd-part": "status-component", "data-state": component.status, children: [_jsx("span", { children: component.label }), " ", _jsx("strong", { children: statusLabels?.[component.status] ?? defaultStatusLabels[component.status] }), component.lastCheckedAt && (_jsxs(_Fragment, { children: [" ", _jsx("time", { dateTime: component.lastCheckedAt, children: formatTime(component.lastCheckedAt) })] }))] }, key))) })), _jsx("h3", { children: labels?.updates ?? "Updates" }), page.updates.length === 0 ? (_jsx("p", { children: labels?.noUpdates ?? "No updates published." })) : (_jsx("ul", { "data-custd-part": "status-updates", children: labelledKeys(page.updates, (update) => update.publishedAt).map(({ value: update, key }) => (_jsxs("li", { "data-custd-part": "status-update", children: [_jsx("time", { dateTime: update.publishedAt, children: formatTime(update.publishedAt) }), _jsx("p", { children: update.message })] }, key))) }))] }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SiteUptimeHistory } from "@haakco/custd-sdk";
|
|
2
|
+
import { type QueryKey } from "@tanstack/react-query";
|
|
3
|
+
import { type MonitoringAppearance } from "./monitoring-section.js";
|
|
4
|
+
import { type DailyUptimeChartProps, type UptimeResponseChartProps } from "./uptime-charts.js";
|
|
5
|
+
declare const defaultLabels: {
|
|
6
|
+
title: string;
|
|
7
|
+
range: string;
|
|
8
|
+
daily: string;
|
|
9
|
+
response: string;
|
|
10
|
+
last24h: string;
|
|
11
|
+
last7d: string;
|
|
12
|
+
last30d: string;
|
|
13
|
+
loading: string;
|
|
14
|
+
error: string;
|
|
15
|
+
refreshError: string;
|
|
16
|
+
retry: string;
|
|
17
|
+
noData: string;
|
|
18
|
+
};
|
|
19
|
+
export type SiteUptimePanelProps = MonitoringAppearance & {
|
|
20
|
+
/** Include the domain and the application's tenant/session scope, without any credentials. */
|
|
21
|
+
queryKey: QueryKey;
|
|
22
|
+
loadHistory: (responseDays: number, signal: AbortSignal) => Promise<SiteUptimeHistory>;
|
|
23
|
+
ranges?: readonly {
|
|
24
|
+
days: number;
|
|
25
|
+
label: string;
|
|
26
|
+
}[];
|
|
27
|
+
initialDays?: number;
|
|
28
|
+
labels?: Partial<typeof defaultLabels>;
|
|
29
|
+
formatPercent?: (percent: number) => string;
|
|
30
|
+
dailyChart?: Omit<DailyUptimeChartProps, "days">;
|
|
31
|
+
responseChart?: Omit<UptimeResponseChartProps, "hours">;
|
|
32
|
+
};
|
|
33
|
+
export declare function SiteUptimePanel({ queryKey, loadHistory, ranges, initialDays, labels, formatPercent, className, style, dailyChart, responseChart, }: SiteUptimePanelProps): import("react").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { MonitoringMetrics, MonitoringSection } from "./monitoring-section.js";
|
|
5
|
+
import { DailyUptimeChart, UptimeResponseChart, uptimePercent, } from "./uptime-charts.js";
|
|
6
|
+
const defaultRanges = [
|
|
7
|
+
{ days: 1, label: "Last day" },
|
|
8
|
+
{ days: 7, label: "Last 7 days" },
|
|
9
|
+
{ days: 30, label: "Last 30 days" },
|
|
10
|
+
];
|
|
11
|
+
const defaultLabels = {
|
|
12
|
+
title: "Site uptime",
|
|
13
|
+
range: "Response time range",
|
|
14
|
+
daily: "Daily uptime",
|
|
15
|
+
response: "Response time",
|
|
16
|
+
last24h: "Last 24 hours",
|
|
17
|
+
last7d: "Last 7 days",
|
|
18
|
+
last30d: "Last 30 days",
|
|
19
|
+
loading: "Loading uptime history…",
|
|
20
|
+
error: "Couldn’t load uptime history.",
|
|
21
|
+
refreshError: "Couldn’t refresh uptime history.",
|
|
22
|
+
retry: "Retry",
|
|
23
|
+
noData: "No data",
|
|
24
|
+
};
|
|
25
|
+
const windowKeys = ["last24h", "last7d", "last30d"];
|
|
26
|
+
export function SiteUptimePanel({ queryKey, loadHistory, ranges = defaultRanges, initialDays = 7, labels, formatPercent = (value) => `${value}%`, className, style, dailyChart, responseChart, }) {
|
|
27
|
+
const text = { ...defaultLabels, ...labels };
|
|
28
|
+
const [selectedDays, setSelectedDays] = useState(initialDays);
|
|
29
|
+
const days = ranges.find((range) => range.days === selectedDays)?.days ?? ranges[0]?.days ?? initialDays;
|
|
30
|
+
const history = useQuery({
|
|
31
|
+
queryKey: ["custd-site-uptime", queryKey, days],
|
|
32
|
+
// Global keepPreviousData may otherwise carry history across a tenant or domain change.
|
|
33
|
+
placeholderData: undefined,
|
|
34
|
+
queryFn: ({ signal }) => loadHistory(days, signal),
|
|
35
|
+
});
|
|
36
|
+
const data = history.data;
|
|
37
|
+
function formatWindow(window) {
|
|
38
|
+
const percent = uptimePercent(window);
|
|
39
|
+
return percent === undefined ? text.noData : formatPercent(percent);
|
|
40
|
+
}
|
|
41
|
+
return (_jsxs(MonitoringSection, { part: "uptime-panel", title: text.title, className: className, style: style, children: [_jsxs("label", { "data-custd-part": "uptime-range", children: [text.range, " ", _jsx("select", { value: days, onChange: (event) => setSelectedDays(Number(event.currentTarget.value)), children: ranges.map((range) => (_jsx("option", { value: range.days, children: range.label }, range.days))) })] }), history.isPending && _jsx("p", { role: "status", children: text.loading }), history.isError && (_jsxs("div", { "data-custd-part": "uptime-error", children: [_jsx("p", { role: "alert", children: history.data ? text.refreshError : text.error }), _jsx("button", { type: "button", disabled: history.isFetching, onClick: () => void history.refetch(), children: text.retry })] })), data && (_jsxs(_Fragment, { children: [_jsx(MonitoringMetrics, { part: "uptime-windows", children: windowKeys.map((key) => (_jsxs("div", { children: [_jsx("dt", { children: text[key] }), _jsx("dd", { children: formatWindow(data.windows[key]) })] }, key))) }), _jsx("h3", { children: text.daily }), _jsx(DailyUptimeChart, { days: data.days, label: text.daily, ...dailyChart }), _jsx("h3", { children: text.response }), _jsx(UptimeResponseChart, { hours: data.hours, ...responseChart })] }))] }));
|
|
42
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SiteResponseHour, SiteUptimeDay, SiteUptimeWindow } from "@haakco/custd-sdk";
|
|
2
|
+
import type { CSSProperties } from "react";
|
|
3
|
+
/** Round down so a missed check never displays as 100%. */
|
|
4
|
+
export declare function uptimePercent({ checks, upChecks }: SiteUptimeWindow): number | undefined;
|
|
5
|
+
export type DailyUptimeChartProps = {
|
|
6
|
+
days: readonly SiteUptimeDay[];
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
label?: string;
|
|
10
|
+
emptyLabel?: string;
|
|
11
|
+
formatDayLabel?: (day: SiteUptimeDay) => string;
|
|
12
|
+
};
|
|
13
|
+
export declare function DailyUptimeChart({ days, className, style, label, emptyLabel, formatDayLabel, }: DailyUptimeChartProps): import("react").JSX.Element;
|
|
14
|
+
export type UptimeResponseChartProps = {
|
|
15
|
+
hours: readonly SiteResponseHour[];
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
emptyLabel?: string;
|
|
19
|
+
averageLabel?: string;
|
|
20
|
+
slowestLabel?: string;
|
|
21
|
+
formatSummary?: (metrics: {
|
|
22
|
+
averageMs: number;
|
|
23
|
+
slowestMs: number;
|
|
24
|
+
}) => string;
|
|
25
|
+
formatTime?: (timestamp: string) => string;
|
|
26
|
+
};
|
|
27
|
+
export declare function UptimeResponseChart({ hours, className, style, emptyLabel, averageLabel, slowestLabel, formatSummary, formatTime, }: UptimeResponseChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { scaleLinear } from "./chart-scale.js";
|
|
3
|
+
/** Round down so a missed check never displays as 100%. */
|
|
4
|
+
export function uptimePercent({ checks, upChecks }) {
|
|
5
|
+
return checks === 0 ? undefined : Math.floor((upChecks * 10000) / checks) / 100;
|
|
6
|
+
}
|
|
7
|
+
export function DailyUptimeChart({ days, className, style, label = "Daily uptime", emptyLabel = "No uptime checks in this range.", formatDayLabel, }) {
|
|
8
|
+
if (!days.some((day) => day.checks > 0))
|
|
9
|
+
return (_jsx("p", { className: className, style: style, children: emptyLabel }));
|
|
10
|
+
return (_jsx("ul", { "aria-label": label, className: className, "data-custd-part": "daily-chart", style: { display: "flex", gap: 1, margin: 0, padding: 0, listStyle: "none", ...style }, children: days.map((day) => {
|
|
11
|
+
const { date, checks, upChecks } = day;
|
|
12
|
+
const share = checks ? upChecks / checks : null;
|
|
13
|
+
const percent = uptimePercent(day);
|
|
14
|
+
const detail = percent === undefined ? "No data" : `${percent}% up (${checks} checks)`;
|
|
15
|
+
const dayLabel = formatDayLabel?.(day) ?? `${date}: ${detail}`;
|
|
16
|
+
const tone = share === null ? "no-data" : share >= 0.999 ? "up" : share >= 0.99 ? "degraded" : "down";
|
|
17
|
+
const color = dailyColors[tone];
|
|
18
|
+
return (_jsx("li", { "aria-label": dayLabel, title: dayLabel, "data-custd-part": "uptime-day", "data-state": tone, style: { flex: 1, minWidth: 0, height: "var(--custd-uptime-bar-height, 1.5rem)", backgroundColor: color } }, date));
|
|
19
|
+
}) }));
|
|
20
|
+
}
|
|
21
|
+
const dailyColors = {
|
|
22
|
+
"no-data": "var(--custd-uptime-no-data, #94a3b8)",
|
|
23
|
+
up: "var(--custd-uptime-up, #15803d)",
|
|
24
|
+
degraded: "var(--custd-uptime-degraded, #a16207)",
|
|
25
|
+
down: "var(--custd-uptime-down, #b91c1c)",
|
|
26
|
+
};
|
|
27
|
+
const HOUR_MS = 3600000;
|
|
28
|
+
const WIDTH = 640;
|
|
29
|
+
const HEIGHT = 160;
|
|
30
|
+
export function UptimeResponseChart({ hours, className, style, emptyLabel = "No passing checks in this range.", averageLabel = "Average", slowestLabel = "Slowest", formatSummary, formatTime, }) {
|
|
31
|
+
const passing = hours.filter((hour) => hour.avgMs != null && hour.upChecks > 0);
|
|
32
|
+
if (passing.length === 0)
|
|
33
|
+
return (_jsx("p", { className: className, style: style, children: emptyLabel }));
|
|
34
|
+
const maximum = Math.max(...passing.map((hour) => hour.maxMs ?? hour.avgMs ?? 0));
|
|
35
|
+
const checks = passing.reduce((sum, hour) => sum + hour.upChecks, 0);
|
|
36
|
+
const average = Math.round(passing.reduce((sum, hour) => sum + (hour.avgMs ?? 0) * hour.upChecks, 0) / checks);
|
|
37
|
+
const start = Date.parse(hours[0].hourStart);
|
|
38
|
+
const end = Date.parse(hours[hours.length - 1].hourStart);
|
|
39
|
+
const x = scaleLinear({ start: start - HOUR_MS / 2, end: end + HOUR_MS / 2 }, 4, WIDTH - 4);
|
|
40
|
+
const y = scaleLinear({ start: 0, end: Math.max(1, maximum) }, HEIGHT - 4, 4);
|
|
41
|
+
const summary = formatSummary?.({ averageMs: average, slowestMs: maximum }) ??
|
|
42
|
+
`Response time: ${average} ms on average, slowest ${maximum} ms.`;
|
|
43
|
+
return (_jsxs("figure", { className: className, "data-custd-part": "response-chart", style: { margin: 0, ...style }, children: [_jsx("svg", { viewBox: `0 0 ${WIDTH} ${HEIGHT}`, style: { display: "block", width: "100%" }, role: "img", "aria-label": summary, children: ["avgMs", "maxMs"].map((field) => {
|
|
44
|
+
const color = field === "avgMs" ? "var(--custd-chart-primary, #2563eb)" : "var(--custd-chart-secondary, #9333ea)";
|
|
45
|
+
return (_jsx("g", { "data-series": field, fill: color, stroke: color, children: passing.map((hour, index) => {
|
|
46
|
+
const value = hour[field];
|
|
47
|
+
if (value == null)
|
|
48
|
+
return null;
|
|
49
|
+
const time = Date.parse(hour.hourStart);
|
|
50
|
+
const previous = passing[index - 1];
|
|
51
|
+
const previousValue = previous?.[field];
|
|
52
|
+
const joined = previousValue != null && time - Date.parse(previous.hourStart) === HOUR_MS;
|
|
53
|
+
return (_jsxs("g", { children: [_jsx("title", { children: `${formatTime?.(hour.hourStart) ?? hour.hourStart} · ${field === "avgMs" ? averageLabel : slowestLabel} ${value} ms` }), joined && (_jsx("line", { x1: x(time - HOUR_MS), y1: y(previousValue), x2: x(time), y2: y(value), strokeDasharray: field === "maxMs" ? "5 3" : undefined })), _jsx("circle", { cx: x(time), cy: y(value), r: 2 })] }, hour.hourStart));
|
|
54
|
+
}) }, field));
|
|
55
|
+
}) }), _jsx("figcaption", { children: summary })] }));
|
|
56
|
+
}
|
package/monitoring.css
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* Set these variables at the site or theme root to style every monitoring template. */
|
|
2
|
+
:where([data-custd-monitoring]) {
|
|
3
|
+
display: grid;
|
|
4
|
+
gap: var(--custd-monitoring-space, 1rem);
|
|
5
|
+
padding: var(--custd-monitoring-padding, 1rem);
|
|
6
|
+
border: 1px solid var(--custd-monitoring-border, color-mix(in srgb, currentColor 20%, transparent));
|
|
7
|
+
border-radius: var(--custd-monitoring-radius, 0.75rem);
|
|
8
|
+
background: var(--custd-monitoring-surface, transparent);
|
|
9
|
+
color: var(--custd-monitoring-text, inherit);
|
|
10
|
+
font-family: var(--custd-monitoring-font, inherit);
|
|
11
|
+
min-width: 0;
|
|
12
|
+
overflow-wrap: anywhere;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
:where([data-custd-monitoring] h2, [data-custd-monitoring] h3, [data-custd-monitoring] p) {
|
|
16
|
+
margin: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
:where([data-custd-metrics]) {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-wrap: wrap;
|
|
22
|
+
gap: var(--custd-monitoring-space, 1rem);
|
|
23
|
+
margin: 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:where([data-custd-metrics] dd) {
|
|
27
|
+
margin: 0;
|
|
28
|
+
font-weight: 600;
|
|
29
|
+
font-variant-numeric: tabular-nums;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
:where([data-custd-part="lighthouse-profile"], [data-custd-part="uptime-error"]) {
|
|
33
|
+
display: grid;
|
|
34
|
+
gap: calc(var(--custd-monitoring-space, 1rem) / 2);
|
|
35
|
+
justify-items: start;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
:where([data-custd-part="status-components"], [data-custd-part="status-updates"]) {
|
|
39
|
+
display: grid;
|
|
40
|
+
gap: calc(var(--custd-monitoring-space, 1rem) / 2);
|
|
41
|
+
margin: 0;
|
|
42
|
+
padding: 0;
|
|
43
|
+
list-style: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
:where([data-custd-part="status-component"]) {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-wrap: wrap;
|
|
49
|
+
align-items: baseline;
|
|
50
|
+
gap: calc(var(--custd-monitoring-space, 1rem) / 2);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
:where([data-custd-part="status-update"] p) {
|
|
54
|
+
white-space: pre-wrap;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:where([data-custd-monitoring] select, [data-custd-monitoring] button) {
|
|
58
|
+
font: inherit;
|
|
59
|
+
border-radius: var(--custd-monitoring-radius, 0.75rem);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
:where([data-custd-part="status-component"][data-state="up"] strong) {
|
|
63
|
+
color: var(--custd-uptime-up, inherit);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
:where([data-custd-part="status-component"][data-state="failing"] strong, [data-custd-part="status-component"][data-state="maintenance"] strong) {
|
|
67
|
+
color: var(--custd-uptime-degraded, inherit);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
:where([data-custd-part="status-component"][data-state="down"] strong) {
|
|
71
|
+
color: var(--custd-uptime-down, inherit);
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haakco/custd-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.73.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24 <27"
|
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
"./testing": {
|
|
17
17
|
"types": "./dist/testing.d.ts",
|
|
18
18
|
"import": "./dist/testing.js"
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"./monitoring.css": "./monitoring.css"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|
|
22
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"monitoring.css"
|
|
23
25
|
],
|
|
24
26
|
"scripts": {
|
|
25
27
|
"build": "tsc -p tsconfig.build.json",
|