From 701c14314927a85e186e35b2f1dcc798703a36a6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 5 Mar 2019 14:04:52 +0100 Subject: [PATCH 1/3] Updated ErrorHandler so that it logs errors in production --- src/common/ErrorHandler.js | 8 +++++++- src/common/services/provideServices.js | 3 ++- test/common/ErrorHandler.test.js | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common/ErrorHandler.js b/src/common/ErrorHandler.js index fb641a79..6dc0af26 100644 --- a/src/common/ErrorHandler.js +++ b/src/common/ErrorHandler.js @@ -3,7 +3,7 @@ import * as PropTypes from 'prop-types'; import './ErrorHandler.scss'; import { Button } from 'reactstrap'; -const ErrorHandler = ({ location }) => class ErrorHandler extends React.Component { +const ErrorHandler = ({ location }, { error }) => class ErrorHandler extends React.Component { static propTypes = { children: PropTypes.node.isRequired, }; @@ -17,6 +17,12 @@ const ErrorHandler = ({ location }) => class ErrorHandler extends React.Componen return { hasError: true }; } + componentDidCatch(e) { + if (process.env.NODE_ENV !== 'development') { + error(e); + } + } + render() { if (this.state.hasError) { return ( diff --git a/src/common/services/provideServices.js b/src/common/services/provideServices.js index 6fcc775b..f8f5c980 100644 --- a/src/common/services/provideServices.js +++ b/src/common/services/provideServices.js @@ -7,6 +7,7 @@ import ErrorHandler from '../ErrorHandler'; const provideServices = (bottle, connect, withRouter) => { bottle.constant('window', global.window); + bottle.constant('console', global.console); bottle.serviceFactory('ScrollToTop', ScrollToTop, 'window'); bottle.decorator('ScrollToTop', withRouter); @@ -31,7 +32,7 @@ const provideServices = (bottle, connect, withRouter) => { bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton'); - bottle.serviceFactory('ErrorHandler', ErrorHandler, 'window'); + bottle.serviceFactory('ErrorHandler', ErrorHandler, 'window', 'console'); }; export default provideServices; diff --git a/test/common/ErrorHandler.test.js b/test/common/ErrorHandler.test.js index 58325a65..721d7a0d 100644 --- a/test/common/ErrorHandler.test.js +++ b/test/common/ErrorHandler.test.js @@ -9,10 +9,11 @@ describe('', () => { reload: jest.fn(), }, }; + const console = { error: jest.fn() }; let wrapper; beforeEach(() => { - const ErrorHandler = createErrorHandler(window); + const ErrorHandler = createErrorHandler(window, console); wrapper = shallow(Foo} />); }); From 87a4598391d7a4da344548178bfede4b4ed5966e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 5 Mar 2019 14:09:08 +0100 Subject: [PATCH 2/3] Ensured maps modal btn is not rendered when the number of located cities is 0 --- src/visits/ShortUrlVisits.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/visits/ShortUrlVisits.js b/src/visits/ShortUrlVisits.js index cd14bc22..566074df 100644 --- a/src/visits/ShortUrlVisits.js +++ b/src/visits/ShortUrlVisits.js @@ -76,6 +76,7 @@ const ShortUrlVisits = ({ processStatsFromVisits }) => class ShortUrlVisits exte const { os, browsers, referrers, countries, cities, citiesForMap } = processStatsFromVisits( { id: this.memoizationId, visits } ); + const mapLocations = values(citiesForMap); return (
@@ -109,14 +110,9 @@ const ShortUrlVisits = ({ processStatsFromVisits }) => class ShortUrlVisits exte ( - - ), - ]} + extraHeaderContent={ + [ () => mapLocations.length > 0 && ] + } sortingItems={{ name: 'City name', amount: 'Visits amount', From 9ddd5de00853bd8a546b1b5f3caa600026423459 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 5 Mar 2019 14:12:11 +0100 Subject: [PATCH 3/3] Updated changelog --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 012b23ec..e3aa3bfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org). +## [Unreleased] + +#### Added + +* *Nothing* + +#### Changed + +* *Nothing* + +#### Deprecated + +* *Nothing* + +#### Removed + +* *Nothing* + +#### Fixed + +* [#120](https://github.com/shlinkio/shlink-web-client/issues/120) Fixed crash when visits page is loaded and there are no visits with known cities. + + ## 2.0.2 - 2019-03-04 #### Added