All files / pages/Statistics CommonsMealAveragesPage.jsx

100% Statements 4/4
100% Branches 2/2
100% Functions 2/2
100% Lines 4/4

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              12x           12x   12x                             1x                              
import React, { useState } from "react";
import { Form } from "react-bootstrap";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import CommonsMealAveragesSection from "main/components/Statistics/CommonsMealAveragesSection";
import { useBackend } from "main/utils/useBackend";
 
export default function CommonsMealAveragesPage() {
  const { data: commons } = useBackend(
    ["/api/dining/all"],
    { method: "GET", url: "/api/dining/all" },
    [],
  );
 
  const [selectedCode, setSelectedCode] = useState("");
 
  const effectiveCode = selectedCode || commons[0]?.code;
 
  return (
    <BasicLayout>
      <div className="pt-2">
        <h1>Meal Averages by Dining Commons</h1>
        {commons.length > 0 && (
          <Form.Group className="mb-3">
            <Form.Label htmlFor="CommonsMealAveragesPage-commons-select">
              Dining Commons
            </Form.Label>
            <Form.Select
              id="CommonsMealAveragesPage-commons-select"
              data-testid="CommonsMealAveragesPage-commons-select"
              value={effectiveCode}
              onChange={(e) => setSelectedCode(e.target.value)}
            >
              {commons.map((c) => (
                <option key={c.code} value={c.code}>
                  {c.name}
                </option>
              ))}
            </Form.Select>
          </Form.Group>
        )}
        {effectiveCode && <CommonsMealAveragesSection code={effectiveCode} />}
      </div>
    </BasicLayout>
  );
}