diff --git a/ui/src/views/devices/DeviceDashboard.tsx b/ui/src/views/devices/DeviceDashboard.tsx index 19a1747c..58571644 100644 --- a/ui/src/views/devices/DeviceDashboard.tsx +++ b/ui/src/views/devices/DeviceDashboard.tsx @@ -3,7 +3,7 @@ import { Link } from "react-router-dom"; import moment from "moment"; import { ReloadOutlined } from "@ant-design/icons"; -import { Descriptions, Space, Card, Statistic, Row, Col, Tabs, Radio, RadioChangeEvent, Button } from "antd"; +import { Descriptions, Space, Card, Statistic, Row, Col, Tabs, Radio, RadioChangeEvent, Button, Spin } from "antd"; import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb"; import { @@ -31,6 +31,8 @@ interface IState { metricsAggregation: Aggregation; deviceMetrics?: GetDeviceMetricsResponse; deviceLinkMetrics?: GetDeviceLinkMetricsResponse; + deviceMetricsLoaded: boolean; + deviceLinkMetricsLoaded: boolean; } class DeviceDashboard extends Component { @@ -39,6 +41,8 @@ class DeviceDashboard extends Component { this.state = { metricsAggregation: Aggregation.DAY, + deviceMetricsLoaded: false, + deviceLinkMetricsLoaded: false, }; } @@ -59,8 +63,16 @@ class DeviceDashboard extends Component { start = start.subtract(12, "months"); } - this.loadLinkMetrics(start.toDate(), end.toDate(), agg); - this.loadDeviceMetrics(start.toDate(), end.toDate(), agg); + this.setState( + { + deviceMetricsLoaded: false, + deviceLinkMetricsLoaded: false, + }, + () => { + this.loadLinkMetrics(start.toDate(), end.toDate(), agg); + this.loadDeviceMetrics(start.toDate(), end.toDate(), agg); + }, + ); }; loadDeviceMetrics = (start: Date, end: Date, agg: Aggregation) => { @@ -79,6 +91,7 @@ class DeviceDashboard extends Component { DeviceStore.getMetrics(req, (resp: GetDeviceMetricsResponse) => { this.setState({ deviceMetrics: resp, + deviceMetricsLoaded: true, }); }); }; @@ -99,6 +112,7 @@ class DeviceDashboard extends Component { DeviceStore.getLinkMetrics(req, (resp: GetDeviceLinkMetricsResponse) => { this.setState({ deviceLinkMetrics: resp, + deviceLinkMetricsLoaded: true, }); }); }; @@ -164,14 +178,23 @@ class DeviceDashboard extends Component { lastSeenAt = moment(this.props.lastSeenAt).format("YYYY-MM-DD HH:mm:ss"); } + const loading = !this.state.deviceLinkMetricsLoaded || !this.state.deviceMetrics; + const aggregations = ( + {loading && } - 24h - 31d - 1y + + 24h + + + 31d + + + 1y + -