fix(ui): сбрасывать снимок при изменении параметров speed-пробы

This commit is contained in:
Denozordec committed 2026-10-07 17:41:14 +07:00
1 parent 090206c893
commit 7f18fcb6db
11 files changed
+106 -22

No files matched your search

+4 -4
View File
@@ -1,12 +1,12 @@
import { emptySpeedProbeObservations, type SpeedProbeRead } from "@mmapp/contracts"
import { emptySpeedProbeObservations, sameSpeedMeasurement, type SpeedMeasurementParameters, type SpeedProbeRead } from "@mmapp/contracts"
type Observations = Pick<SpeedProbeRead, keyof typeof emptySpeedProbeObservations>
type Pair = { id: string; srcServerId: string; dstServerId: string }
/** Publish confirmed configuration while preserving the latest snapshot only for the same pair. */
type Pair = { id: string } & SpeedMeasurementParameters
/** Publish confirmed configuration while preserving the latest snapshot only for the same measurement parameters. */
export function publishSpeedProbeSnapshots<T extends Pair & Partial<Observations>>(previous: readonly T[], next: readonly T[]) {
const byId = new Map(previous.map(row => [row.id, row]))
return next.map(row => {
const old = byId.get(row.id)
if (!old || old.srcServerId !== row.srcServerId || old.dstServerId !== row.dstServerId) {
if (!old || !sameSpeedMeasurement(old, row)) {
return { ...row, ...emptySpeedProbeObservations }
}
const observations = Object.fromEntries(Object.keys(emptySpeedProbeObservations).map(key => [key, old[key as keyof Observations] ?? null])) as Observations