import React, { useState, useEffect } from "react"; import moment from "moment"; import { Descriptions, Space, Card, Row, Col } from "antd"; import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb"; import { Gateway, GetGatewayMetricsRequest, GetGatewayMetricsResponse, } from "@chirpstack/chirpstack-api-grpc-web/api/gateway_pb"; import { Aggregation } from "@chirpstack/chirpstack-api-grpc-web/common/common_pb"; import GatewayStore from "../../stores/GatewayStore"; import Map, { Marker } from "../../components/Map"; import MetricChart from "../../components/MetricChart"; import MetricHeatmap from "../../components/MetricHeatmap"; import MetricBar from "../../components/MetricBar"; interface IProps { gateway: Gateway; lastSeenAt?: Date; } function GatewayDashboard(props: IProps) { const [metricsAggregation, setMetricsAggregation] = useState(Aggregation.DAY); const [gatewayMetrics, setGatewayMetrics] = useState(undefined); useEffect(() => { const agg = metricsAggregation; const end = moment(); let start = moment(); if (agg === Aggregation.DAY) { start = start.subtract(30, "days"); } else if (agg === Aggregation.HOUR) { start = start.subtract(24, "hours"); } else if (agg === Aggregation.MONTH) { start = start.subtract(12, "months"); } let startPb = new Timestamp(); let endPb = new Timestamp(); startPb.fromDate(start.toDate()); endPb.fromDate(end.toDate()); let req = new GetGatewayMetricsRequest(); req.setGatewayId(props.gateway.getGatewayId()); req.setStart(startPb); req.setEnd(endPb); req.setAggregation(agg); GatewayStore.getMetrics(req, (resp: GetGatewayMetricsResponse) => { setGatewayMetrics(resp); }); }, [props, metricsAggregation]); const loc = props.gateway.getLocation()!; const location: [number, number] = [loc.getLatitude(), loc.getLongitude()]; if (gatewayMetrics === undefined) { return null; } let lastSeenAt: string = "Never"; if (props.lastSeenAt !== undefined) { lastSeenAt = moment(props.lastSeenAt).format("YYYY-MM-DD HH:mm:ss"); } return ( {lastSeenAt} {props.gateway.getMetadataMap().get("region_config_id")} {props.gateway.getMetadataMap().get("region_common_name")} {props.gateway.getDescription()} ); } export default GatewayDashboard;