All files / src/pages/flowsheet-page/economics/results-panel/charts ComparisonMetricMenu.tsx

68.75% Statements 22/32
35.71% Branches 5/14
33.33% Functions 2/6
68.18% Lines 15/22

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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                      2x             2x 2x                         2x 2x               2x   4x 2x   4x 2x 2x 12x                     16x 10x 8x      
import { ChevronDown } from "lucide-react";
import { Badge } from "@/ahuora-design-system/ui/badge";
import { Button } from "@/ahuora-design-system/ui/button";
import {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuTrigger,
} from "@/ahuora-design-system/ui/dropdown-menu";
import { COMPARISON_METRIC_FILTERS } from "./constants";
 
export function ComparisonMetricMenu({
  selectedKeys,
  onSelectedKeysChange,
}: {
  selectedKeys: string[];
  onSelectedKeysChange: (keys: string[]) => void;
}) {
  const selected = new Set(selectedKeys);
  const selectedCount = selectedKeys.length;
 
  const toggleMetric = (metricKey: string, checked: boolean) => {
    const next = new Set(selected);
    if (checked) {
      next.add(metricKey);
    } else if (next.size > 1) {
      next.delete(metricKey);
    }
    onSelectedKeysChange(Array.from(next));
  };
 
  return (
    <DropdownMenu>
      <DropdownMenuTrigger asChild>
        <Button
          type="button"
          variant="outline"
          size="sm"
          aria-label="Comparison chart metrics"
        >
          Metrics
          <Badge variant="secondary" size="xs" borderRadius="round">
            {selectedCount}
          </Badge>
          <ChevronDown className="size-3" aria-hidden="true" />
        </Button>
      </DropdownMenuTrigger>
      <DropdownMenuContent align="end" className="w-56">
        {COMPARISON_METRIC_FILTERS.map((option) => (
          <DropdownMenuCheckboxItem
            key={option.value}
            checked={selected.has(option.value)}
            disabled={selected.size === 1 && selected.has(option.value)}
            onSelect={(event) => event.preventDefault()}
            onCheckedChange={(checked) =>
              toggleMetric(option.value, checked === true)
            }
          >
            {option.label}
          </DropdownMenuCheckboxItem>
        ))}
      </DropdownMenuContent>
    </DropdownMenu>
  );
}