From 160469d78741a18be7ebfeea15497bf8488a53f4 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Wed, 28 Sep 2022 11:57:07 +0200 Subject: [PATCH] Improved analytics page loading states refs https://github.com/TryGhost/Team/issues/1976 - Wait to show any module until everything has been loaded --- .../admin/app/controllers/posts/analytics.js | 26 +++++- ghost/admin/app/templates/posts/analytics.hbs | 85 +++++++------------ 2 files changed, 56 insertions(+), 55 deletions(-) diff --git a/ghost/admin/app/controllers/posts/analytics.js b/ghost/admin/app/controllers/posts/analytics.js index 1655b4cb43..fb8ad4c835 100644 --- a/ghost/admin/app/controllers/posts/analytics.js +++ b/ghost/admin/app/controllers/posts/analytics.js @@ -14,6 +14,7 @@ export default class AnalyticsController extends Controller { @service settings; @service membersUtils; @service utils; + @service feature; @tracked sources = null; @tracked links = null; @@ -30,8 +31,17 @@ export default class AnalyticsController extends Controller { @action loadData() { - this.fetchReferrersStats(); - this.fetchLinks(); + if (this.showSources) { + this.fetchReferrersStats(); + } else { + this.sources = []; + } + + if (this.showLinks) { + this.fetchLinks(); + } else { + this.links = []; + } } async fetchReferrersStats() { @@ -89,4 +99,16 @@ export default class AnalyticsController extends Controller { this.links = Object.values(linksByTitle); } + + get showLinks() { + return this.settings.get('emailTrackClicks') && (this.post.isSent || (this.post.isPublished && this.post.email)); + } + + get showSources() { + return this.feature.get('sourceAttribution') && !this.post.emailOnly; + } + + get isLoaded() { + return this.links !== null && this.souces !== null; + } } diff --git a/ghost/admin/app/templates/posts/analytics.hbs b/ghost/admin/app/templates/posts/analytics.hbs index 616f99f066..d1ba372fc5 100644 --- a/ghost/admin/app/templates/posts/analytics.hbs +++ b/ghost/admin/app/templates/posts/analytics.hbs @@ -80,8 +80,8 @@ {{/if}} - {{#if (and this.settings.emailTrackClicks (or this.post.isSent (and this.post.isPublished this.post.email)))}} - {{#if (not-eq this.links null)}} + {{#if this.isLoaded }} + {{#if this.showLinks }} {{#if (is-empty this.links) }} {{!-- Empty state --}} {{else}} @@ -99,23 +99,9 @@ {{/if}} - {{else}} - {{!-- TODO: better way to stop repeating code for loading? --}} -

- Newsletter clicks -

-
-
-
-
-
-
-
{{/if}} - {{/if}} - {{#if (and (feature 'sourceAttribution') (not this.post.emailOnly))}} - {{#if (not-eq this.sources null) }} + {{#if this.showSources }} {{#if (is-empty this.sources) }} {{!-- Empty state --}} {{else}} @@ -143,45 +129,38 @@ {{/if}} - {{else}} - {{!-- TODO: better way to stop repeating code for loading? --}} -

- Source attribution -

-
-
-
-
-
-
-
{{/if}} - {{/if}} -

- Get started with analytics -

-
- -
-