From 9ce1c1f30ba072b63c627d8cb75bc81320b8fa7c Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Tue, 3 Mar 2020 15:15:09 +0200 Subject: [PATCH] Add empty states to reports (#40) --- assets/js/dashboard/stats/devices.js | 78 ++++++++++++++++++-------- assets/js/dashboard/stats/more-link.js | 21 ++++--- assets/js/dashboard/stats/pages.js | 23 ++++++-- assets/js/dashboard/stats/referrers.js | 23 ++++++-- assets/tailwind.js | 1 + 5 files changed, 101 insertions(+), 45 deletions(-) diff --git a/assets/js/dashboard/stats/devices.js b/assets/js/dashboard/stats/devices.js index 5b973a6fd..4b931d822 100644 --- a/assets/js/dashboard/stats/devices.js +++ b/assets/js/dashboard/stats/devices.js @@ -72,18 +72,28 @@ class ScreenSizes extends React.Component { ) } + renderList() { + if (this.state.sizes && this.state.sizes.length > 0) { + return ( + +
+ Screen size + Visitors +
+ { this.state.sizes && this.state.sizes.map(this.renderScreenSize.bind(this)) } +
+ ) + } else { + return
No data yet
+ } + } + render() { return ( - { this.state.loading &&
} + { this.state.loading &&
} - -
- Screen size - Visitors -
- { this.state.sizes && this.state.sizes.map(this.renderScreenSize.bind(this)) } -
+ { this.renderList() }
) @@ -124,18 +134,28 @@ class Browsers extends React.Component { ) } + renderList() { + if (this.state.browsers && this.state.browsers.length > 0) { + return ( + +
+ Browser + Visitors +
+ { this.state.browsers && this.state.browsers.map(this.renderBrowser.bind(this)) } +
+ ) + } else { + return
No data yet
+ } + } + render() { return ( - { this.state.loading &&
} + { this.state.loading &&
} - -
- Browser - Visitors -
- { this.state.browsers && this.state.browsers.map(this.renderBrowser.bind(this)) } -
+ { this.renderList() }
) @@ -176,18 +196,28 @@ class OperatingSystems extends React.Component { ) } + renderList() { + if (this.state.operatingSystems && this.state.operatingSystems.length > 0) { + return ( + +
+ Operating system + Visitors +
+ { this.state.operatingSystems && this.state.operatingSystems.map(this.renderOperatingSystem.bind(this)) } +
+ ) + } else { + return
No data yet
+ } + } + render() { return ( - { this.state.loading &&
} + { this.state.loading &&
} - -
- Operating system - Visitors -
- { this.state.operatingSystems && this.state.operatingSystems.map(this.renderOperatingSystem.bind(this)) } -
+ { this.renderList() }
) diff --git a/assets/js/dashboard/stats/more-link.js b/assets/js/dashboard/stats/more-link.js index 668a72410..bb2de95e7 100644 --- a/assets/js/dashboard/stats/more-link.js +++ b/assets/js/dashboard/stats/more-link.js @@ -1,13 +1,16 @@ import React from 'react'; import { Link } from 'react-router-dom' -export default function MoreLink({site, endpoint}) { - return ( -
- - - MORE - -
- ) +export default function MoreLink({site, list, endpoint}) { + if (list.length > 0) { + return ( +
+ + + MORE + +
+ ) + } + return null } diff --git a/assets/js/dashboard/stats/pages.js b/assets/js/dashboard/stats/pages.js index 5e36ef318..54eaa254b 100644 --- a/assets/js/dashboard/stats/pages.js +++ b/assets/js/dashboard/stats/pages.js @@ -43,18 +43,29 @@ export default class Pages extends React.Component { ) } - renderContent() { - if (this.state.pages) { + renderList() { + if (this.state.pages.length > 0) { return ( -

Top Pages

-
Page url - Pageviews + Visitors
{ this.state.pages.map(this.renderPage.bind(this)) } +
+ ) + } else { + return
No data yet
+ } + } + + renderContent() { + if (this.state.pages) { + return ( + +

Top Pages

+ { this.renderList() }
) @@ -64,7 +75,7 @@ export default class Pages extends React.Component { render() { return (
- { this.state.loading &&
} + { this.state.loading &&
} { this.renderContent() } diff --git a/assets/js/dashboard/stats/referrers.js b/assets/js/dashboard/stats/referrers.js index e2d43dec1..9530fca04 100644 --- a/assets/js/dashboard/stats/referrers.js +++ b/assets/js/dashboard/stats/referrers.js @@ -49,18 +49,29 @@ export default class Referrers extends React.Component { ) } - renderContent() { - if (this.state.referrers) { + renderList() { + if (this.state.referrers.length > 0) { return ( -

Top Referrers

-
Referrer Visitors
- { this.state.referrers.map(this.renderReferrer.bind(this)) } + {this.state.referrers.map(this.renderReferrer.bind(this))} +
+ ) + } else { + return
No data yet
+ } + } + + renderContent() { + if (this.state.referrers) { + return ( + +

Top Referrers

+ { this.renderList() }
) @@ -70,7 +81,7 @@ export default class Referrers extends React.Component { render() { return (
- { this.state.loading &&
} + { this.state.loading &&
} { this.renderContent() } diff --git a/assets/tailwind.js b/assets/tailwind.js index 3d7f8c0e5..63073a3a5 100644 --- a/assets/tailwind.js +++ b/assets/tailwind.js @@ -698,6 +698,7 @@ module.exports = { '20': '5rem', '24': '6rem', '32': '8rem', + '44': '11rem', '48': '12rem', },