Collection
Facilities & IT / Network · v0.2.0Validated
Inspect optical receive power across a period and compare reported readings with device limits.
Optical Receive Power · Preview
Loading widget…
Preparing source code…
Idle
Facilities & IT / Network · v0.2.0Validated
Inspect optical receive power across a period and compare reported readings with device limits.
Loading widget…
Preparing source code…
Load the Lumo theme once in your app entry point. The example uses the local Lumo workspace packages.
import "@lumo/tokens/tokens.css";
import { OpticalRxWidget } from "@lumo/widgets/catalog/network/optical-rx";
export default function Example() {
return <OpticalRxWidget />;
}Props for integrating the React component in your app.
snapshotOpticalRxSnapshot | null (optional){
"snapshot": {
"port": "Core 04 / SFP 2",
"period": "24 h · UTC",
"warningDbm": -11,
"alarmDbm": -14,
"samples": [
{
"id": "18",
"label": "18:00",
"dbm": -12.5
},
{
"id": "19",
"label": "19:00",
"dbm": null
},
{
"id": "20",
"label": "20:00",
"dbm": -7.2
}
]
}
}"use client";
import { Cable } from "lucide-react";
import { useState } from "react";
import { AnimatedNumber, Badge, Button, WidgetCard } from "@lumo/ui";
import { WidgetReadingSeries } from "../../shared/WidgetReadingSeries";
import shared from "../../shared/operations-list.module.css";
import report from "../../shared/reading-report.module.css";
import { opticalDemo } from "./optical-rx.constants";
import type { OpticalRxSnapshot } from "./optical-rx.types";
export type { OpticalRxSample, OpticalRxSnapshot } from "./optical-rx.types";
const dbm = (n: number | null | undefined): n is number => typeof n === "number" && Number.isFinite(n) && n >= -100 && n <= 100;
const print = (n: number | null | undefined) => dbm(n) ? `${n.toFixed(1)} dBm` : "Unavailable";
export function OpticalRxWidget({ snapshot = opticalDemo }: { index?: number; snapshot?: OpticalRxSnapshot | null } = {}) {
const [selected, setSelected] = useState<string>();
const samples = [...new Map((snapshot?.samples ?? []).filter(sample => sample.id).map(sample => [sample.id, sample])).values()].slice(-48);
const alarm = dbm(snapshot?.alarmDbm) ? snapshot.alarmDbm : null;
const warning = dbm(snapshot?.warningDbm) && (alarm === null || snapshot.warningDbm >= alarm) ? snapshot.warningDbm : null;
const floor = Math.min(-1, alarm ?? 0, warning ?? 0, ...samples.map(sample => dbm(sample.dbm) ? sample.dbm : 0)) - 2;
const points = samples.map(sample => ({ id: sample.id, label: sample.label, value: dbm(sample.dbm) ? sample.dbm - floor : null }));
const current = samples.find(sample => sample.id === selected) ?? samples.at(-1);
const currentDbm = current?.dbm;
const tone = !dbm(currentDbm) ? null : alarm !== null && currentDbm < alarm ? ["Below alarm", "danger"] as const
: warning !== null && currentDbm < warning ? ["Below warning", "warning"] as const
: warning !== null || alarm !== null ? ["Within limits", "success"] as const : null;
const low = samples.reduce<number | null>((min, sample) => dbm(sample.dbm) ? Math.min(min ?? sample.dbm, sample.dbm) : min, null);
return <WidgetCard title="Optical Rx Power" label="Optical receive power" description={snapshot && `${snapshot.port} · ${snapshot.period}` || undefined}
size="small" icon={<Cable />} className={`${shared.smallCard} ${report.compact}`}>
{current ? <div className={report.report}>
<div className={report.reading}><div><span>{current.label}{snapshot?.peer ? ` · ${snapshot.peer}` : ""}</span>
<strong>{dbm(currentDbm) ? <><AnimatedNumber value={currentDbm} decimals={1} blur={false} /> <small>dBm</small></> : "Unavailable"}</strong></div>
{tone && <Badge size="sm" tone={tone[1]}>{tone[0]}</Badge>}
</div>
<WidgetReadingSeries kind="line" points={points} activeId={current.id} onSelect={setSelected}
threshold={warning === null ? undefined : warning - floor}
secondaryThreshold={alarm === null ? undefined : alarm - floor}
label="Optical power samples" color="var(--tone-violet)" describe={point => `${point.label}, ${print(point.value === null ? null : point.value + floor)}`} />
<dl className={report.facts}><div><dt>Period low</dt><dd>{print(low)}</dd></div>
<div><dt>Alarm limit</dt><dd>{print(alarm)}</dd></div></dl>
<div className={report.foot}><span>{warning === null ? "Warning limit not set" : `Warning ${print(warning)}`}</span>
<Button type="button" variant="ghost" size="xs" disabled={!selected || current.id === samples.at(-1)?.id}
onClick={() => setSelected(undefined)}>Latest</Button></div>
</div> : <p className={shared.muted}>{snapshot ? "No optical samples reported" : "Optical data unavailable"}</p>}
</WidgetCard>;
}
lucide-reactmotionreactreact-dom