mirror of
https://github.com/henrygd/beszel.git
synced 2026-04-26 14:31:50 +02:00
updates
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import LineChartDefault, { DataPoint } from "@/components/charts/line-chart"
|
||||
import { pinnedAxisDomain } from "@/components/ui/chart"
|
||||
import LineChartDefault from "@/components/charts/line-chart"
|
||||
import type { DataPoint } from "@/components/charts/line-chart"
|
||||
import { toFixedFloat, decimalString } from "@/lib/utils"
|
||||
import { useLingui } from "@lingui/react/macro"
|
||||
import { ChartCard, FilterBar } from "../chart-card"
|
||||
@@ -31,33 +31,44 @@ export function LatencyChart({
|
||||
const { t } = useLingui()
|
||||
const filter = useStore($filter)
|
||||
|
||||
const dataPoints: DataPoint<NetworkProbeStatsRecord>[] = useMemo(() => {
|
||||
const { dataPoints, visibleKeys } = useMemo(() => {
|
||||
const count = probes.length
|
||||
return probes
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
.map((p, i) => {
|
||||
const key = probeKey(p)
|
||||
const filterTerms = filter
|
||||
? filter
|
||||
.toLowerCase()
|
||||
.split(" ")
|
||||
.filter((term) => term.length > 0)
|
||||
: []
|
||||
const filtered = filterTerms.length > 0 && !filterTerms.some((term) => key.toLowerCase().includes(term))
|
||||
const strokeOpacity = filtered ? 0.1 : 1
|
||||
return {
|
||||
label: p.name || p.target,
|
||||
dataKey: (record: NetworkProbeStatsRecord) => record.stats?.[key]?.[0] ?? null,
|
||||
color: count <= 5 ? i + 1 : `hsl(${(i * 360) / count}, var(--chart-saturation), var(--chart-lightness))`,
|
||||
strokeOpacity,
|
||||
activeDot: !filtered,
|
||||
}
|
||||
const points: DataPoint<NetworkProbeStatsRecord>[] = []
|
||||
const visibleKeys: string[] = []
|
||||
probes.sort((a, b) => a.name.localeCompare(b.name))
|
||||
const filterTerms = filter
|
||||
? filter
|
||||
.toLowerCase()
|
||||
.split(" ")
|
||||
.filter((term) => term.length > 0)
|
||||
: []
|
||||
for (let i = 0; i < count; i++) {
|
||||
const p = probes[i]
|
||||
const key = probeKey(p)
|
||||
const filtered = filterTerms.length > 0 && !filterTerms.some((term) => key.toLowerCase().includes(term))
|
||||
if (filtered) {
|
||||
continue
|
||||
}
|
||||
visibleKeys.push(key)
|
||||
points.push({
|
||||
label: p.name || p.target,
|
||||
dataKey: (record: NetworkProbeStatsRecord) => record.stats?.[key]?.[0] ?? "-",
|
||||
color: count <= 5 ? i + 1 : `hsl(${(i * 360) / count}, var(--chart-saturation), var(--chart-lightness))`,
|
||||
})
|
||||
}
|
||||
return { dataPoints: points, visibleKeys }
|
||||
}, [probes, filter])
|
||||
|
||||
const filteredProbeStats = useMemo(() => {
|
||||
if (!visibleKeys.length) return probeStats
|
||||
return probeStats.filter((record) => visibleKeys.some((key) => record.stats?.[key] != null))
|
||||
}, [probeStats, visibleKeys])
|
||||
|
||||
const legend = dataPoints.length < 10
|
||||
|
||||
return (
|
||||
<ChartCard
|
||||
legend
|
||||
legend={legend}
|
||||
cornerEl={<FilterBar store={$filter} />}
|
||||
empty={empty}
|
||||
title={t`Latency`}
|
||||
@@ -66,13 +77,18 @@ export function LatencyChart({
|
||||
>
|
||||
<LineChartDefault
|
||||
chartData={chartData}
|
||||
customData={probeStats}
|
||||
customData={filteredProbeStats}
|
||||
dataPoints={dataPoints}
|
||||
domain={pinnedAxisDomain()}
|
||||
domain={["auto", "auto"]}
|
||||
connectNulls
|
||||
tickFormatter={(value) => `${toFixedFloat(value, value >= 10 ? 0 : 1)} ms`}
|
||||
contentFormatter={({ value }) => `${decimalString(value, 2)} ms`}
|
||||
legend
|
||||
contentFormatter={({ value }) => {
|
||||
if (value === "-") {
|
||||
return value
|
||||
}
|
||||
return `${decimalString(value, 2)} ms`
|
||||
}}
|
||||
legend={legend}
|
||||
filter={filter}
|
||||
/>
|
||||
</ChartCard>
|
||||
|
||||
@@ -42,11 +42,11 @@ export function LazySystemdTable({ systemId }: { systemId: string }) {
|
||||
)
|
||||
}
|
||||
|
||||
const NetworkProbesTableNew = lazy(() => import("@/components/network-probes-table/network-probes-table"))
|
||||
const NetworkProbesTable = lazy(() => import("@/components/network-probes-table/network-probes-table"))
|
||||
|
||||
const cache = new Map<string, any>()
|
||||
|
||||
export function LazyNetworkProbesTableNew({ systemId, systemData }: { systemId: string; systemData: SystemData }) {
|
||||
export function LazyNetworkProbesTable({ systemId, systemData }: { systemId: string; systemData: SystemData }) {
|
||||
const { grid, chartData } = systemData ?? {}
|
||||
const [probes, setProbes] = useState<NetworkProbeRecord[]>([])
|
||||
const chartTime = useStore($chartTime)
|
||||
@@ -101,7 +101,7 @@ export function LazyNetworkProbesTableNew({ systemId, systemData }: { systemId:
|
||||
<div ref={ref} className={cn(isIntersecting && "contents")}>
|
||||
{isIntersecting && (
|
||||
<>
|
||||
<NetworkProbesTableNew systemId={systemId} probes={probes} setProbes={setProbes} />
|
||||
<NetworkProbesTable systemId={systemId} probes={probes} setProbes={setProbes} />
|
||||
{!!chartData && (
|
||||
<LatencyChart
|
||||
probeStats={probeStats}
|
||||
@@ -116,25 +116,3 @@ export function LazyNetworkProbesTableNew({ systemId, systemData }: { systemId:
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const NetworkProbesTable = lazy(() => import("@/components/routes/system/network-probes"))
|
||||
|
||||
export function LazyNetworkProbesTable({
|
||||
system,
|
||||
chartData,
|
||||
grid,
|
||||
probeStats,
|
||||
}: {
|
||||
system: any
|
||||
chartData: any
|
||||
grid: any
|
||||
probeStats: any
|
||||
}) {
|
||||
const { isIntersecting, ref } = useIntersectionObserver()
|
||||
return (
|
||||
<div ref={ref} className={cn(isIntersecting && "contents")}>
|
||||
{isIntersecting && (
|
||||
<NetworkProbesTable system={system} chartData={chartData} grid={grid} realtimeProbeStats={probeStats} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user