From 478a3b91f7c5e53258a2c5b64d975214c815a202 Mon Sep 17 00:00:00 2001 From: Tao Bojlen Date: Sat, 1 Sep 2018 19:34:00 +0200 Subject: [PATCH] fix stats in API --- frontend/package.json | 1 + frontend/src/components/Sidebar.tsx | 8 +++++++- frontend/yarn.lock | 4 ++++ scraper/management/commands/_util.py | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 371677c..2e03cba 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,6 +8,7 @@ "@blueprintjs/select": "^3.1.0", "classnames": "^2.2.6", "cross-fetch": "^2.2.2", + "moment": "^2.22.2", "normalize.css": "^8.0.0", "react": "^16.4.2", "react-dom": "^16.4.2", diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx index 8b4227e..0e57e60 100644 --- a/frontend/src/components/Sidebar.tsx +++ b/frontend/src/components/Sidebar.tsx @@ -1,3 +1,4 @@ +import * as moment from 'moment'; import * as React from 'react'; import { connect } from 'react-redux'; import { Dispatch } from 'redux'; @@ -74,6 +75,7 @@ class SidebarImpl extends React.Component { const userCount = this.props.instanceDetails!.userCount; const statusCount = this.props.instanceDetails!.statusCount; const domainCount = this.props.instanceDetails!.domainCount; + const lastUpdated = this.props.instanceDetails!.lastUpdated; if (!userCount && !statusCount && !domainCount) { return; } @@ -94,6 +96,10 @@ class SidebarImpl extends React.Component { Known peers {domainCount || "Unknown"} + + Last updated + {moment(lastUpdated + "Z").fromNow() || "Unknown"} + @@ -103,7 +109,7 @@ class SidebarImpl extends React.Component { private renderPeers = () => { const peers = this.props.instanceDetails!.peers; - if (!peers) { + if (!peers || peers.length === 0) { return; } const peerRows = peers.map(instance => ( diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 2a00b44..0744700 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -4680,6 +4680,10 @@ mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: dependencies: minimist "0.0.8" +moment@^2.22.2: + version "2.22.2" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66" + move-concurrently@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92" diff --git a/scraper/management/commands/_util.py b/scraper/management/commands/_util.py index 6259303..880cb3f 100644 --- a/scraper/management/commands/_util.py +++ b/scraper/management/commands/_util.py @@ -58,7 +58,7 @@ def get_key(data, keys: list): def validate_int(integer): - return isinstance(integer, int) and 0 <= integer < 2147483647 or None + return integer if (isinstance(integer, int) and 0 <= integer < 2147483647) else None def log(text):