Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "beacon-web",
"private": true,
"version": "2.3.2",
"version": "2.3.4",
"license": "AGPL-3.0-or-later",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export interface ServerInfo {
minWebVersion: string | null;
serverVersion: string;
// absent on servers that predate the flags
features?: { polling?: boolean; accounts?: string; registration?: boolean; telemetryRequests?: boolean; alerts?: boolean; atlasTelemetry?: boolean; atlas7d?: boolean; atlasPoller?: boolean; mapTelemetry?: boolean; alertChannels?: { email?: boolean; push?: boolean }; push?: { server?: string; pushId?: string }; portalUrl?: string };
features?: { polling?: boolean; accounts?: string; registration?: boolean; telemetryRequests?: boolean; alerts?: boolean; atlasTelemetry?: boolean; atlas7d?: boolean; atlasPoller?: boolean; sensors?: boolean; mapTelemetry?: boolean; alertChannels?: { email?: boolean; push?: boolean }; push?: { server?: string; pushId?: string }; portalUrl?: string };
display?: { temperatureUnit?: string; distanceUnit?: string };
limits?: { atlas?: number };
}
Expand Down
11 changes: 6 additions & 5 deletions src/features/account/alertRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fromDisplayTemp, tempSymbol, toDisplayTemp, type TemperatureUnit } from

// The order of the plan's alert kinds table; rows follow it.
export const ALERT_KINDS: AlertKind[] = [
"gone_quiet", "back_online", "battery_low", "battery_falling", "rebooted", "temperature", "noise_high", "clock", "observer_offline",
"gone_quiet", "back_online", "telemetry_stopped", "battery_low", "battery_falling", "rebooted", "temperature", "noise_high", "clock", "observer_offline",
];

// The rules that are switched on, and the ones alerting now. Profile's summary and the Atlas bell both read these.
Expand All @@ -19,9 +19,9 @@ export function channelReaches(channels: AlertChannels): boolean {
return (email.available && email.enabled) || (push.available && push.enabled && push.hasDevice);
}

export function goneQuietHours(target: AlertTarget, current: number | null): number[] {
const short = target.kind === "observer" || target.polled;
const hours = short ? [3, 6, 12, 24, 48] : [12, 24, 48];
// The hour choices of gone_quiet and telemetry_stopped, plus a stored value that is not one of them.
export function quietHours(current: number | null): number[] {
const hours = [3, 6, 12, 24, 48];
if (current != null && !hours.includes(current)) hours.push(current);
return hours.sort((a, b) => a - b);
}
Expand All @@ -38,6 +38,7 @@ export function inputsFor(kind: AlertKind, rule: AlertRule | undefined, unit: Te
const th = rule?.threshold ?? null;
switch (kind) {
case "gone_quiet": return { a: String(th ?? 24), b: "" };
case "telemetry_stopped": return { a: String(th ?? 12), b: "" };
case "battery_falling": return { a: String(th ?? 100), b: "" };
case "clock": return { a: String(th ?? 3600), b: "" };
case "observer_offline": return { a: String(th ?? 60), b: "" };
Expand Down Expand Up @@ -71,7 +72,7 @@ function num(text: string): number | null {
// Turns the typed values into the units the server takes, or an inline error key.
export function parseInputs(kind: AlertKind, { a, b }: Inputs, unit: TemperatureUnit): Parsed {
switch (kind) {
case "gone_quiet": case "battery_falling": case "clock": case "observer_offline":
case "gone_quiet": case "telemetry_stopped": case "battery_falling": case "clock": case "observer_offline":
return { ok: true, threshold: Number(a), thresholdHigh: null };
case "battery_low": {
const v = num(a);
Expand Down
5 changes: 3 additions & 2 deletions src/features/account/sections/AlertRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useDisplayUnits } from "../../../hooks/useFeatures";
import { tempSymbol } from "../../../lib/units";
import { alertErrorText } from "../errors";
import {
BATTERY_FALLING_STEPS, CLOCK_SECONDS, OBSERVER_OFFLINE_MINUTES, durationText, goneQuietHours, inputsFor, parseInputs, parseTemperature, temperatureLimits, type Inputs, type Parsed,
BATTERY_FALLING_STEPS, CLOCK_SECONDS, OBSERVER_OFFLINE_MINUTES, durationText, quietHours, inputsFor, parseInputs, parseTemperature, temperatureLimits, type Inputs, type Parsed,
} from "../alertRules";
import type { AlertKind, AlertRule, AlertTarget } from "../types";
import { useSessionEnded } from "./useSessionEnded";
Expand Down Expand Up @@ -102,7 +102,7 @@ export function AlertRow({ target, kind, rule, goneQuietOn }: { target: AlertTar

let input = null;
switch (kind) {
case "gone_quiet": input = select("hours", goneQuietHours(target, rule?.threshold ?? null), (h) => durationText(t, "hours", h)); break;
case "gone_quiet": case "telemetry_stopped": input = select("hours", quietHours(rule?.threshold ?? null), (h) => durationText(t, "hours", h)); break;
case "battery_falling": input = select("drop", BATTERY_FALLING_STEPS, (m) => t("account.alerts.voltsPerDay", { volts: (m / 1000).toFixed(1) })); break;
case "clock": input = select("drift", CLOCK_SECONDS, (s) => secondsText(t, s)); break;
case "observer_offline": input = select("offline", OBSERVER_OFFLINE_MINUTES, (m) => minutesText(t, m)); break;
Expand All @@ -127,6 +127,7 @@ export function AlertRow({ target, kind, rule, goneQuietOn }: { target: AlertTar
<Switch label={t("account.alerts.turnOn", { name })} checked={checked} disabled={blocked || save.isPending} onChange={toggle} stateText={checked ? t("account.alerts.on") : t("account.alerts.off")} />
</div>
{input && <div className="flex flex-wrap items-center gap-2">{input}{unit && <span className="font-mono text-xs text-text-muted">{unit}</span>}</div>}
{kind === "gone_quiet" && <p className="text-xs text-text-muted">{t("account.alerts.goneQuietHint")}</p>}
{blocked && <p className="text-xs text-text-muted">{t("account.alerts.backOnlineHint", { name: t("account.alerts.kinds.gone_quiet.name") })}</p>}
{stateText && (
<p className="font-mono text-xs text-text-normal">
Expand Down
2 changes: 1 addition & 1 deletion src/features/account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface TelemetryRequestList {
export type TelemetryRequestPatch = { password?: string | null; enabled?: true; acknowledgeForeign?: true };

export type AlertKind =
| "gone_quiet" | "back_online" | "battery_low" | "battery_falling" | "rebooted"
| "gone_quiet" | "back_online" | "telemetry_stopped" | "battery_low" | "battery_falling" | "rebooted"
| "temperature" | "noise_high" | "clock" | "observer_offline";
export type AlertState = "ok" | "firing" | "inactive" | "unknown";

Expand Down
2 changes: 1 addition & 1 deletion src/features/account/unavailableReason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const KEYS: Record<string, string> = {
};
const NEEDS_WHAT = new Set(["observer_no_data", "repeaters_only", "no_data"]);
const WHAT: Record<string, string> = {
battery_low: "battery", battery_falling: "battery", rebooted: "uptime", temperature: "temperature", noise_high: "noise",
telemetry_stopped: "telemetry", battery_low: "battery", battery_falling: "battery", rebooted: "uptime", temperature: "temperature", noise_high: "noise",
};

// A reason in the user's language, by its code. No code (an older server) or one this build does not know shows the
Expand Down
56 changes: 40 additions & 16 deletions src/features/atlas/AtlasCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fragment, useEffect, useId, useMemo, useRef, useState, type ReactNode } from "react";
import { Fragment, useCallback, useEffect, useId, useMemo, useRef, useState, type ReactNode } from "react";
import { useQuery } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import { isNotFound } from "../../api/client";
Expand All @@ -21,19 +21,21 @@ import { usePacketDetail } from "../packets/usePacketDetail";
import { Card, StatCard } from "../stats/cards";
import { useChartColors } from "../stats/chartTheme";
import { average } from "../stats/signal";
import { DEFAULT_TELEMETRY_TILES, DEFAULT_TILES, OBSERVER_TILES, TELEMETRY_TILES, resolveObserverNode, type AtlasPin, type AtlasSample, type AtlasRange, type AtlasView, type ObserverTile, type TelemetryTile } from "./atlas";
import { DEFAULT_TELEMETRY_TILES, DEFAULT_TILES, OBSERVER_TILES, TELEMETRY_TILES, isSensorTile, resolveObserverNode, type AtlasPin, type AtlasSample, type AtlasRange, type AtlasView, type ObserverTile, type TelemetryTile } from "./atlas";
import { AtlasAlertBell } from "./AtlasAlerts";
import { TilePicker } from "./TilePicker";
import { PollerTiles } from "./PollerTiles";
import { ATLAS_REFRESH_MS, useAtlasNode, useAtlasReadings, useAtlasTelemetry, usePollerTab, useTelemetryTab } from "./useAtlas";
import { DOT_LIMIT, sparkValues } from "./telemetry-sample";
import type { ObserverSample, PayloadShare } from "./observer-sample";
import { TileGraph } from "./TileGraph";
import { NODE_METRICS, OBSERVER_METRICS, percent, perHour, readingPoints, shortUptime, slotPoints, telemetryMetrics, type NodeTile } from "./tile-graph";
import { AIR_QUALITY, NODE_METRICS, OBSERVER_METRICS, percent, perHour, readingPoints, shortUptime, slotPoints, telemetryMetrics, type NodeTile } from "./tile-graph";
import { AccuracyChip } from "../nodes/AccuracyChip";
import { useAtlasObserver } from "./useAtlasObserver";
import type { CardHandleProps } from "./useCardDrag";
import { ViewTabs } from "./ViewTabs";
import { TelemetrySourceTag } from "../nodes/ForeignObserver";
import { telemetrySourceInfo } from "../nodes/telemetrySourceInfo";
import { allLocal } from "../nodes/poller-seats";
import { PollerClaimTags } from "../nodes/NodePollerSection";

Expand Down Expand Up @@ -86,6 +88,12 @@ const TELEMETRY_LABEL: Record<TelemetryTile, string> = {
packets: "atlas.telemetry.packets",
signal: "atlas.telemetry.signal",
errors: "atlas.telemetry.errors",
humidity: "atlas.telemetry.humidity",
pressure: "atlas.telemetry.pressure",
gas: "atlas.telemetry.gas",
power: "atlas.telemetry.power",
current: "atlas.telemetry.current",
sensorVoltage: "atlas.telemetry.sensorVoltage",
};
// Accents belong to the slot, so a card keeps its colours whatever its tiles show.
const SLOT_ACCENT = [0, 3, 2, 1];
Expand Down Expand Up @@ -410,24 +418,29 @@ export function AtlasCard({
const [graph, setGraph] = useState<GraphTile | null>(null);
const sparkButton = (label: string, tile: GraphTile) => ({ onSparkClick: () => setGraph(tile), sparkLabel: t("atlas.graph.open", { name: label }) });
const observerSample = obs.sample;
const gasIsIndex = telSample.gasIsIndex;
const telemetryLabel = useCallback((id: TelemetryTile) => (id === "gas" && gasIsIndex ? "atlas.telemetry.airQuality" : TELEMETRY_LABEL[id]), [gasIsIndex]);
const telemetrySpec = useCallback((id: TelemetryTile) => (id === "gas" && gasIsIndex ? AIR_QUALITY : telMetrics[id]), [gasIsIndex, telMetrics]);
// Memoized so the open graph is redrawn when the data changes, not on every render of the card.
const graphed = useMemo(() => {
if (!graph) return null;
if (graph.kind === "node") return { metric: t(NODE_LABEL[graph.id]), spec: NODE_METRICS[graph.id], points: slotPoints(nodeHourly(sample)[graph.id], range, now) };
if (graph.kind === "observer") return { metric: t(TILE_LABEL[graph.id]), spec: OBSERVER_METRICS[graph.id], points: slotPoints(observerHourly(observerSample)[graph.id], range, now) };
return { metric: t(TELEMETRY_LABEL[graph.id]), spec: telMetrics[graph.id], points: readingPoints(telSample[graph.id].points, telSample.bucketMs) };
}, [graph, sample, observerSample, telSample, telMetrics, range, now, t]);
const freeTelemetry = TELEMETRY_TILES.filter((id) => !telemetryTiles.includes(id) && (id !== "temperature" || telSample.temperature.values.length > 0))
.map((id) => ({ value: id, label: t(TELEMETRY_LABEL[id]) }));
return { metric: t(telemetryLabel(graph.id)), spec: telemetrySpec(graph.id), points: readingPoints(telSample[graph.id].points, telSample.bucketMs) };
}, [graph, sample, observerSample, telSample, telemetryLabel, telemetrySpec, range, now, t]);
// A tile whose value this repeater never sends is not offered: temperature, and each sensor tile.
const offered = (id: TelemetryTile) => (id !== "temperature" && !isSensorTile(id)) || telSample[id].values.length > 0;
const freeTelemetry = TELEMETRY_TILES.filter((id) => !telemetryTiles.includes(id) && offered(id))
.map((id) => ({ value: id, label: t(telemetryLabel(id)) }));
const telemetryTile = (id: TelemetryTile, slot: number) => {
const accent = c.series[SLOT_ACCENT[slot]!]!;
const common = {
compact: true,
accent,
...sparkButton(t(TELEMETRY_LABEL[id]), { kind: "telemetry", id, color: accent }),
...sparkButton(t(telemetryLabel(id)), { kind: "telemetry", id, color: accent }),
label: (
<TilePicker
label={t(TELEMETRY_LABEL[id])}
label={t(telemetryLabel(id))}
options={freeTelemetry}
up={slot >= 2}
onPick={(next) => onTelemetryTilesChange(telemetryTiles.map((old, i) => (i === slot ? (next as TelemetryTile) : old)))}
Expand All @@ -440,7 +453,7 @@ export function AtlasCard({
const tile = (
series: { latest: number | null; values: number[] },
format: (v: number) => string,
options: { peak?: boolean; sublabel?: string | null; counter?: boolean; title?: (v: number) => string } = {},
options: { peak?: boolean; sublabel?: ReactNode; counter?: boolean; title?: (v: number) => string } = {},
) => (
<StatCard
{...common}
Expand Down Expand Up @@ -468,13 +481,20 @@ export function AtlasCard({
return tile(s.signal, m.signal.format, { sublabel: s.rssi !== null ? `${Math.round(s.rssi)} dBm` : null });
case "errors":
return tile(s.errors, m.errors.format, { peak: true, counter: true });
case "humidity": case "pressure": case "gas": case "power": case "current": case "sensorVoltage":
return tile(s[id], telemetrySpec(id).format, { sublabel: id === "gas" && s.gasAccuracy !== null ? <AccuracyChip accuracy={s.gasAccuracy} compact /> : null });
}
};
// polled only says a reading was ever stored; an assigned poller is what means it is polled now.
const polledNow = tab.polling?.poller != null;
const lastReading = tab.polling?.latestReadingAt ?? telSample.latestAt;
const pollerName = tab.polling?.poller?.name;
const pollState = !tab.polling ? null : polledNow ? (pollerName ? t("atlas.telemetry.polledBy", { name: pollerName }) : t("atlas.telemetry.polled")) : t("atlas.telemetry.notPolled");
// The footer always says when the last reading was. Readings from an observer this server does not manage are
// tagged there, and with nobody here polling the tag stands in for "Not polled": the repeater is polled, only
// not by this server.
const outsideSource = tel.foreign === "all" || tel.foreign === "some";
const localSource = allLocal(tab.polling?.foreign);
const windowLabel = obs.sample.partial ? t("atlas.observerPartialCoverage") : t(`atlas.ranges.${range}`);
const observerTile = (id: ObserverTile, slot: number) => {
const sample = obs.sample;
Expand Down Expand Up @@ -652,15 +672,19 @@ export function AtlasCard({
)}
{view === "telemetry" && node && (
<div ref={body} className="flex flex-1 flex-col gap-3">
{(tel.foreign === "all" || tel.foreign === "some") && <div data-telemetry-source className="flex"><TelemetrySourceTag foreign={tel.foreign} local={allLocal(tab.polling?.foreign)} /></div>}
<div className="grid flex-1 grid-cols-2 gap-3">{telemetryTiles.map((id, slot) => <Fragment key={id}>{telemetryTile(id, slot)}</Fragment>)}</div>
{footer(
tab.polling
? lead(polledNow, t(polledNow ? "atlas.telemetry.polledShort" : "atlas.telemetry.notPolledShort"), polledNow ? lastReading : null)
: lastReading != null && lead(null, t("atlas.telemetry.lastReading"), lastReading),
polledNow && pollerName ? t("atlas.telemetry.byPoller", { name: pollerName }) : "",
<>
{polledNow
? lead(true, t("atlas.telemetry.polledShort"), lastReading)
: lastReading != null
? lead(tab.polling && !outsideSource ? false : null, t("atlas.telemetry.lastReading"), lastReading)
: tab.polling && !outsideSource && lead(false, t("atlas.telemetry.notPolledShort"), null)}
{outsideSource && <span data-telemetry-source className="flex shrink-0"><TelemetrySourceTag bare foreign={tel.foreign} local={localSource} /></span>}
</>,
polledNow ? (pollerName ? t("atlas.telemetry.byPoller", { name: pollerName }) : "") : tab.polling && !outsideSource && lastReading != null ? t("atlas.telemetry.notPolledShort") : "",
tel,
[pollState, lastReading != null && `${t("atlas.telemetry.lastReading")} ${formatAbsolute(lastReading)}`, t("atlas.telemetry.help")],
[(polledNow || !outsideSource) && pollState, outsideSource && t(telemetrySourceInfo(localSource)), lastReading != null && `${t("atlas.telemetry.lastReading")} ${formatAbsolute(lastReading)}`, t("atlas.telemetry.help")],
)}
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/features/atlas/AtlasPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export function AtlasPage({ active = true, ...actions }: AtlasActions & { active
</span>
</div>
<div className="relative min-h-0 flex-1 overflow-y-auto">
<div className="mx-auto flex w-full min-w-0 max-w-[1600px] flex-col gap-3.5 p-4">
<div className="flex w-full min-w-0 flex-col gap-3.5 p-4">
{pendingImport && (
<div role="alertdialog" aria-label={t("atlas.importTitle")} className="flex flex-wrap items-center gap-2 rounded-lg border border-warn/30 bg-warn/7 px-3.5 py-2.5 font-mono text-xs text-text-normal">
<span className="min-w-0 flex-1">
Expand Down Expand Up @@ -391,7 +391,7 @@ export function AtlasPage({ active = true, ...actions }: AtlasActions & { active
{saved.pins.length === 0 ? (
<EmptyState title={t("atlas.emptyTitle")} subtitle={t("atlas.emptyDescription", { limit: limit })} />
) : (
<div className="grid gap-3.5 md:grid-cols-2 xl:grid-cols-3">
<div className="grid gap-3.5 grid-cols-[repeat(auto-fill,minmax(min(380px,100%),1fr))]">
{saved.pins.map((pin, index) => (
<div key={pinKey(pin)} data-atlas-card {...cardProps(index)}>
<AtlasCard
Expand Down
6 changes: 5 additions & 1 deletion src/features/atlas/atlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export type ObserverTile = (typeof OBSERVER_TILES)[number];
export const DEFAULT_TILES: readonly ObserverTile[] = ["airtime", "battery", "types", "noise"];
// The metrics a Telemetry tab tile can show, from a repeater's polled readings. A pin stores its four
// only when they differ from the default.
export const TELEMETRY_TILES = ["battery", "noise", "uptime", "airtime", "temperature", "packets", "signal", "errors"] as const;
// The tiles read from a repeater's sensor channels. They need a server with features.sensors.
export const SENSOR_TILES = ["humidity", "pressure", "gas", "power", "current", "sensorVoltage"] as const;
export type SensorTile = (typeof SENSOR_TILES)[number];
export const TELEMETRY_TILES = ["battery", "noise", "uptime", "airtime", "temperature", "packets", "signal", "errors", ...SENSOR_TILES] as const;
export type TelemetryTile = (typeof TELEMETRY_TILES)[number];
export const isSensorTile = (id: string): id is SensorTile => (SENSOR_TILES as readonly string[]).includes(id);
export const DEFAULT_TELEMETRY_TILES: readonly TelemetryTile[] = ["battery", "noise", "uptime", "airtime"];
export type AtlasView = "analytics" | "heard" | "observer" | "telemetry" | "poller";
// `view` is the tab the card opens on, stored only when it is not Analytics.
Expand Down
Loading
Loading