All files / pages/Statistics CommonsAveragesPage.jsx

100% Statements 6/6
100% Branches 4/4
100% Functions 3/3
100% Lines 6/6

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                14x   14x                   14x 1x     14x                             52x                                                
import React, { useState } from "react";
import { Form } from "react-bootstrap";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import CommonsAveragesTable from "main/components/Statistics/CommonsAveragesTable";
import { useBackend } from "main/utils/useBackend";
import { PERIOD_OPTIONS } from "main/pages/Statistics/statisticsConstants";
 
export default function CommonsAveragesPage() {
  const [period, setPeriod] = useState("ALL");
 
  const { data: averages } = useBackend(
    ["/api/statistics/commons/averages", period],
    {
      method: "GET",
      url: "/api/statistics/commons/averages",
      params: { period },
    },
    [],
  );
 
  const onChangePeriod = (e) => {
    setPeriod(e.target.value);
  };
 
  return (
    <BasicLayout>
      <div className="pt-2">
        <h1>Dining Commons Averages</h1>
        <Form.Group className="mb-3">
          <Form.Label htmlFor="CommonsAveragesPage-period-select">
            Time period
          </Form.Label>
          <Form.Select
            id="CommonsAveragesPage-period-select"
            data-testid="CommonsAveragesPage-period-select"
            value={period}
            onChange={onChangePeriod}
          >
            {PERIOD_OPTIONS.map((opt) => (
              <option
                key={opt.value}
                value={opt.value}
                data-testid={`CommonsAveragesPage-period-option-${opt.value}`}
              >
                {opt.label}
              </option>
            ))}
          </Form.Select>
        </Form.Group>
        {averages && averages.length === 0 ? (
          <p data-testid="CommonsAveragesPage-empty">
            No reviews available yet.
          </p>
        ) : (
          <CommonsAveragesTable
            averages={averages}
            testIdPrefix="CommonsAveragesPage-table"
          />
        )}
      </div>
    </BasicLayout>
  );
}