File size: 4,012 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { translate } from 'i18n-calypso';
import { useRef } from 'react';
import { PerformanceReport } from 'calypso/data/site-profiler/types';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { CoreWebVitalsDisplay } from 'calypso/performance-profiler/components/core-web-vitals-display';
import { Disclaimer } from 'calypso/performance-profiler/components/disclaimer-section';
import { TabType, TabTypes } from 'calypso/performance-profiler/components/header';
import { InsightsSection } from 'calypso/performance-profiler/components/insights-section';
import { MigrationBanner } from 'calypso/performance-profiler/components/migration-banner';
import { NewsletterBanner } from 'calypso/performance-profiler/components/newsletter-banner';
import { PerformanceScore } from 'calypso/performance-profiler/components/performance-score';
import { ScreenshotThumbnail } from 'calypso/performance-profiler/components/screenshot-thumbnail';
import { ScreenshotTimeline } from 'calypso/performance-profiler/components/screenshot-timeline';
import { useReportCompletedEffect } from 'calypso/performance-profiler/hooks/use-report-track-events-effect';
import './style.scss';

type PerformanceProfilerDashboardContentProps = {
	performanceReport: PerformanceReport;
	url: string;
	hash: string;
	filter?: string;
	displayThumbnail?: boolean;
	displayNewsletterBanner?: boolean;
	displayMigrationBanner?: boolean;
	activeTab?: TabType;
	overallScoreIsTab?: boolean;
	onRecommendationsFilterChange?: ( filter: string ) => void;
};

export const PerformanceProfilerDashboardContent = ( {
	performanceReport,
	url,
	hash,
	filter,
	displayNewsletterBanner = true,
	displayMigrationBanner = true,
	activeTab = TabTypes.mobile,
	overallScoreIsTab = false,
	onRecommendationsFilterChange,
}: PerformanceProfilerDashboardContentProps ) => {
	const {
		crux_score,
		overall_score,
		fcp,
		lcp,
		cls,
		inp,
		ttfb,
		tbt,
		audits,
		history,
		screenshots,
		is_wpcom,
		fullPageScreenshot,
	} = performanceReport;
	const insightsRef = useRef< HTMLDivElement >( null );

	useReportCompletedEffect( url, hash );

	return (
		<div className="performance-profiler-content">
			<div className="l-block-wrapper container">
				{ ! overallScoreIsTab && (
					<div className="top-section">
						<PerformanceScore
							value={ crux_score ? crux_score * 100 : overall_score * 100 }
							recommendationsQuantity={ Object.keys( audits ).length }
							recommendationsRef={ insightsRef }
						/>
						<ScreenshotThumbnail
							alt={ translate( 'Website thumbnail' ) }
							src={ screenshots?.[ screenshots.length - 1 ].data }
							activeTab={ activeTab }
						/>
					</div>
				) }
				<CoreWebVitalsDisplay
					fcp={ fcp }
					lcp={ lcp }
					cls={ cls }
					inp={ inp }
					ttfb={ ttfb }
					tbt={ tbt }
					overall={ overall_score * 100 }
					overallScoreIsTab={ overallScoreIsTab }
					history={ history }
					audits={ audits }
					recommendationsRef={ insightsRef }
					onRecommendationsFilterChange={ onRecommendationsFilterChange }
				/>

				{ displayNewsletterBanner && (
					<NewsletterBanner
						link={ `/speed-test-tool/weekly-report?url=${ url }&hash=${ hash }` }
						onClick={ () => {
							recordTracksEvent( 'calypso_performance_profiler_weekly_report_cta_click', {
								url,
							} );
						} }
					/>
				) }

				<ScreenshotTimeline screenshots={ screenshots ?? [] } />
				{ audits && (
					<InsightsSection
						fullPageScreenshot={ fullPageScreenshot }
						audits={ audits }
						url={ url }
						isWpcom={ is_wpcom }
						ref={ insightsRef }
						hash={ hash }
						filter={ filter }
						onRecommendationsFilterChange={ onRecommendationsFilterChange }
					/>
				) }
			</div>

			<Disclaimer />
			{ displayMigrationBanner && (
				<MigrationBanner
					url={ url }
					onClick={ () => {
						recordTracksEvent( 'calypso_performance_profiler_migration_banner_cta_click', {
							url,
						} );
					} }
				/>
			) }
		</div>
	);
};