mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-17 18:56:17 +01:00
refactor: add getMeterState function
This commit is contained in:
@@ -21,3 +21,10 @@ export enum Unit {
|
||||
Celsius,
|
||||
Fahrenheit,
|
||||
}
|
||||
|
||||
/** Meter state for color */
|
||||
export enum MeterState {
|
||||
Good,
|
||||
Warn,
|
||||
Crit,
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { useEffect, useState } from "react"
|
||||
import { CpuIcon, HardDriveIcon, MemoryStickIcon, ServerIcon } from "lucide-react"
|
||||
import { EthernetIcon, HourglassIcon, ThermometerIcon } from "@/components/ui/icons"
|
||||
import { prependBasePath } from "@/components/router"
|
||||
import { Unit } from "./enums"
|
||||
import { MeterState, Unit } from "./enums"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
@@ -507,3 +507,9 @@ export const parseSemVer = (semVer = ""): SemVer => {
|
||||
const parts = semVer.split(".").map(Number)
|
||||
return { major: parts?.[0] ?? 0, minor: parts?.[1] ?? 0, patch: parts?.[2] ?? 0 }
|
||||
}
|
||||
|
||||
/** Get meter state from 0-100 value. Used for color coding meters. */
|
||||
export function getMeterState(value: number): MeterState {
|
||||
const { colorWarn = 65, colorCrit = 90 } = $userSettings.get()
|
||||
return value >= colorCrit ? MeterState.Crit : value >= colorWarn ? MeterState.Warn : MeterState.Good
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user