cloudCostRow.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import * as React from "react";
  2. import { TableCell, TableRow } from "@material-ui/core";
  3. import { toCurrency } from "../util";
  4. import { primary } from "../constants/colors";
  5. const displayCurrencyAsLessThanPenny = (amount, currency) =>
  6. amount > 0 && amount < 0.01
  7. ? `<${toCurrency(0.01, currency)}`
  8. : toCurrency(amount, currency);
  9. const CloudCostRow = ({
  10. cost,
  11. costSuffix,
  12. currency,
  13. drilldown,
  14. kubernetesPercent,
  15. name,
  16. row,
  17. sampleData,
  18. }) => {
  19. function calculatePercent() {
  20. const totalPercent = (kubernetesPercent * 100).toFixed();
  21. return `${totalPercent}%`;
  22. }
  23. const whichPercent = sampleData
  24. ? `${(kubernetesPercent * 100).toFixed(1)}%`
  25. : calculatePercent();
  26. return (
  27. <TableRow onClick={() => drilldown(row)}>
  28. <TableCell
  29. align={"left"}
  30. style={{ cursor: "pointer", color: "#346ef2", padding: "1rem" }}
  31. >
  32. {name}
  33. </TableCell>
  34. <TableCell align={"right"}>{whichPercent}</TableCell>
  35. {/* total cost */}
  36. <TableCell align={"right"} style={{ paddingRight: "2em" }}>
  37. {`${displayCurrencyAsLessThanPenny(cost, currency)}${costSuffix}`}
  38. </TableCell>
  39. </TableRow>
  40. );
  41. };
  42. export { CloudCostRow };