All files / src/components/graph/StatCell StatCell.tsx

0% Statements 0/5
0% Branches 0/8
0% Functions 0/1
0% Lines 0/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                                                         
import React from "react";
import { CountUp } from "chainr-frontend-shared";
import {
  SEV_STATES,
  SeverityLambdas,
  getSevClass,
  getValLambdaSeverity,
} from "@/objects/interfaces/states/Severity";
import { Stat } from "@/objects/interfaces/number/Stat";
import { Range } from "@/objects/interfaces/number/Range";
 
export interface StatCellProps {
  title: string;
  stat: Stat;
  range?: Range;
  sev?: SeverityLambdas;
}
 
const StatCell: React.FC<StatCellProps> = (props) => {
  let severity = SEV_STATES.OK;
  if (props.sev !== undefined) {
    severity = getValLambdaSeverity(props.stat.val, props.sev);
  }
  return (
    <div
      className={`cell absolute top-0 bottom-0 left-0 right-0 text-white ${
        props.sev !== undefined ? getSevClass(severity) : ""
      }`}
    >
      <h2>{props.title}</h2>
      <h1>
        <CountUp start={0} end={props.stat.val}></CountUp>
        {props.stat.unit + (props.sev !== undefined ? ` [${severity}]` : "")}
      </h1>
      <p>
        {props.range !== undefined
          ? `[${props.range.min}-${props.range.max}${props.stat.unit}]`
          : ""}
      </p>
    </div>
  );
};
 
export default StatCell;