All files / publisher/pages/Metrics Metrics.tsx

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

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                  1x 2x                                       7x   7x     7x       7x   7x   7x           4x       4x              
import { useParams } from "react-router-dom";
import { Row, Col } from "@canonical/react-components";
 
import ActiveDeviceMetrics from "./ActiveDeviceMetrics";
import { TerritoryMetrics } from "./TerritoryMetrics";
import { useState } from "react";
 
import { setPageTitle } from "../../utils";
 
const EmptyData = () => {
  return (
    <section className="p-strip--light is-shallow snapcraft-metrics__info">
      <Row>
        <Col size={6}>
          <h2 className="p-heading--4" style={{ marginLeft: "1.5rem" }}>
            Measure your snap's performance
          </h2>
        </Col>
        <Col size={6}>
          <p>
            You'll be able to see active devices and territories when people
            start using your snap.
          </p>
        </Col>
      </Row>
    </section>
  );
};
 
function Metrics(): React.JSX.Element {
  const { snapId } = useParams();
 
  const [isActiveDeviceMetricEmpty, setIsActiveDeviceMetricEmpty] = useState<
    boolean | null
  >(null);
  const [isCountryMetricEmpty, setIsCountryMetricEmpty] = useState<
    boolean | null
  >(null);
  const isEmpty =
    Boolean(isActiveDeviceMetricEmpty) && Boolean(isCountryMetricEmpty);
 
  setPageTitle(`Metrics for ${snapId}`);
 
  return (
    <>
      {isEmpty && <EmptyData />}
 
      <ActiveDeviceMetrics
        isEmpty={isEmpty}
        onDataLoad={(dataLength) => setIsActiveDeviceMetricEmpty(!dataLength)}
      />
      <TerritoryMetrics
        isEmpty={isEmpty}
        onDataLoad={(dataLength) => setIsCountryMetricEmpty(!dataLength)}
      />
    </>
  );
}
 
export default Metrics;