All files / app/components Alert.tsx

100% Statements 12/12
50% Branches 1/2
100% Functions 3/3
100% Lines 11/11

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      45x 45x 45x 45x 45x   71x                     45x         91x   91x   273x     91x                    
import {
  Alert as MuiAlert,
  AlertProps as MuiAlertProps,
} from "@material-ui/lab/";
import { grpcErrorStrings, ObscureGrpcErrorMessages } from "appConstants";
import classNames from "classnames";
import React from "react";
import makeStyles from "utils/makeStyles";
 
const useStyles = makeStyles((theme) => ({
  root: {
    marginBottom: theme.spacing(2),
  },
}));
 
interface AlertProps extends MuiAlertProps {
  severity: MuiAlertProps["severity"];
  children: string;
}
 
export default function Alert({
  className,
  children,
  ...otherProps
}: AlertProps) {
  const classes = useStyles();
 
  const oldErrorKey = Object.keys(grpcErrorStrings).find(
    (oldError): oldError is ObscureGrpcErrorMessages =>
      children.includes(oldError)
  );
 
  return (
    <MuiAlert {...otherProps} className={classNames(classes.root, className)}>
      {
        // Search for the error in the ugly grpc error object keys
        // Replace it with the nice error if found
        oldErrorKey ? grpcErrorStrings[oldErrorKey] : children
      }
    </MuiAlert>
  );
}