From bd4255108d65f32508a9822ea0c0b1c75ec49f64 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 4 Apr 2020 12:58:04 +0200 Subject: [PATCH] Improved VisitsTable performance by memoizing visits lists --- src/utils/Message.js | 4 ++-- src/utils/helpers/numbers.js | 4 ++++ src/visits/ShortUrlVisits.js | 5 +++-- src/visits/VisitsTable.js | 36 ++++++++++++++---------------------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/utils/Message.js b/src/utils/Message.js index 67b8c087..2aa723f8 100644 --- a/src/utils/Message.js +++ b/src/utils/Message.js @@ -35,8 +35,8 @@ const Message = ({ children, loading = false, noMargin = false, type = 'default'

{loading && } - {loading && !children && Loading...} - {children} + {loading && {children || 'Loading...'}} + {!loading && children}

diff --git a/src/utils/helpers/numbers.js b/src/utils/helpers/numbers.js index 7cfe751b..b9e0757f 100644 --- a/src/utils/helpers/numbers.js +++ b/src/utils/helpers/numbers.js @@ -1,4 +1,8 @@ const TEN_ROUNDING_NUMBER = 10; const { ceil } = Math; +const formatter = new Intl.NumberFormat('en-US'); + +export const prettify = (number) => formatter.format(number); + export const roundTen = (number) => ceil(number / TEN_ROUNDING_NUMBER) * TEN_ROUNDING_NUMBER; diff --git a/src/visits/ShortUrlVisits.js b/src/visits/ShortUrlVisits.js index d18dbd66..5a5ed3ec 100644 --- a/src/visits/ShortUrlVisits.js +++ b/src/visits/ShortUrlVisits.js @@ -78,6 +78,7 @@ const ShortUrlVisits = ( render() { const { shortUrlVisits, shortUrlDetail } = this.props; const { visits, loading, loadingLarge, error } = shortUrlVisits; + const showTableControls = !loading && visits.length > 0; const renderVisitsContent = () => { if (loading) { @@ -166,7 +167,7 @@ const ShortUrlVisits = ( />
- {visits.length > 0 && ( + {showTableControls && (