Files
prowler/components/compliance/ComplianceCard.tsx
T
Sophia Dao f676ca9078 Compliance Page & Compliance Card (#40)
* feat(compliance): Add in initial shell for Compliance page

* feat(compliance): Mock data in the same way as Services and Providers, create files for rest of page and card structure

* feat(compliance): Add in more data to json, continue building Compliance Card

* feat(compliance): Add in icons for Compliance types, update Compliance skeleton

* feat(compliance): Compliance card/page - add in colors for progress bar, styling

* feat(compliance): Add image definitions to fix CI

* feat(compliance): Add in aws.svg instead of .png

* Fix file suffix

* feat(compliance) remove duplicate spacer
2024-08-20 08:30:36 -05:00

86 lines
2.5 KiB
TypeScript

import { Card, CardBody, Progress } from "@nextui-org/react";
import Image from "next/image";
import React from "react";
import { getComplianceIcon } from "../icons";
interface ComplianceCardProps {
title: string;
passingRequirements: number;
totalRequirements: number;
prevPassingRequirements: number;
prevTotalRequirements: number;
}
export const ComplianceCard: React.FC<ComplianceCardProps> = ({
title,
passingRequirements,
totalRequirements,
prevPassingRequirements,
prevTotalRequirements,
}) => {
const ratingPercentage = Math.floor(
(passingRequirements / totalRequirements) * 100,
);
const prevRatingPercentage = Math.floor(
(prevPassingRequirements / prevTotalRequirements) * 100,
);
const getScanChange = () => {
const scanDifference = ratingPercentage - prevRatingPercentage;
if (scanDifference < 0 && scanDifference <= -1) {
return `${scanDifference}% from last scan`;
}
if (scanDifference > 0 && scanDifference >= 1) {
return `+${scanDifference}% from last scan`;
}
return "No change from last scan";
};
const getRatingColor = (ratingPercentage: number) => {
if (ratingPercentage <= 10) {
return "danger";
}
if (ratingPercentage <= 40) {
return "warning";
}
return "success";
};
return (
<Card fullWidth isPressable isHoverable shadow="sm">
<CardBody className="flex flex-row items-center space-x-4 justify-between">
<div className="flex space-x-4 items-center w-full">
<Image
src={getComplianceIcon(title)}
alt={`${title} logo`}
className="rounded-md p-1 border-gray-300 border-1 bg-white object-contain h-10 w-10 min-w-10"
/>
<div className="flex flex-col w-full">
<h4 className="font-bold text-md 3xl:text-lg leading-5">{title}</h4>
<Progress
label="Your Rating:"
size="sm"
aria-label="Your Rating"
value={ratingPercentage}
showValueLabel={true}
className="mt-2 font-semibold"
color={getRatingColor(ratingPercentage)}
/>
<div className="flex justify-between mt-2">
<small>
<span className="font-semibold mr-1">
{passingRequirements} / {totalRequirements}
</span>
Passing Requirements
</small>
<small>{getScanChange()}</small>
</div>
</div>
</div>
</CardBody>
</Card>
);
};