Skip to content

Commit

Permalink
add subtle background based on rating
Browse files Browse the repository at this point in the history
  • Loading branch information
dtemkin1 committed Dec 16, 2024
1 parent 8c14e3a commit 4f2813b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/ClassTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
themeQuartz,
type IRowNode,
type ColDef,
CellClassParams,
} from "ag-grid-community";
import { Box, Group, Flex, Image, Input } from "@chakra-ui/react";
import React, { useEffect, useMemo, useRef, useState } from "react";
Expand Down Expand Up @@ -33,6 +34,14 @@ const hydrantTheme = themeQuartz.withParams({

ModuleRegistry.registerModules([AllCommunityModule]);

const getRatingColor = (rating?: number | string) => {
if (rating === undefined || rating === "N/A") return undefined;
const ratingNumber = Number(rating);
if (ratingNumber >= 6) return "success";
if (ratingNumber >= 5) return "warning";
return "error";
};

/** A single row in the class table. */
type ClassTableRow = {
number: string;
Expand Down Expand Up @@ -328,7 +337,18 @@ export function ClassTable(props: {
maxWidth: 100,
...sortProps,
},
{ field: "rating", resizable: false, ...numberSortProps },
{
field: "rating",
resizable: false,
cellStyle: (params: CellClassParams<ClassTableRow>) => {
const rating = getRatingColor(params.value);
if (!rating) return { backgroundColor: "" };
return {
backgroundColor: `var(--chakra-colors-bg-${rating})`,
};
},
...numberSortProps,
},
{ field: "hours", resizable: false, ...numberSortProps },
{ field: "name", resizable: false, sortable: false, flex: 1 },
];
Expand Down

0 comments on commit 4f2813b

Please sign in to comment.