/** * @license * Copyright 2021 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import {FunctionComponent} from 'preact'; import {useMemo} from 'preact/hooks'; import {FlowSegment, FlowStepThumbnail, Separator} from '../common'; import {getModeDescription, useFlowResult} from '../util'; import {ReportUtils} from '../../../report/renderer/report-utils.js'; import {SummaryCategory} from './category'; import {useStringFormatter, useLocalizedStrings} from '../i18n/i18n'; const DISPLAYED_CATEGORIES = ['performance', 'accessibility', 'best-practices', 'seo']; const THUMBNAIL_WIDTH = 40; const SummaryNavigationHeader: FunctionComponent<{lhr: LH.Result}> = ({lhr}) => { const strings = useLocalizedStrings(); return (
{lhr.finalDisplayedUrl}
{strings.categoryPerformance}
{strings.categoryAccessibility}
{strings.categoryBestPractices}
{strings.categorySeo}
); }; /** * The div should behave like a JSX <>.... This still allows us to identify "rows" with CSS selectors. */ const SummaryFlowStep: FunctionComponent<{ lhr: LH.Result, label: string, hashIndex: number, }> = ({lhr, label, hashIndex}) => { const reportResult = useMemo(() => ReportUtils.prepareReportResult(lhr), [lhr]); const strings = useLocalizedStrings(); const modeDescription = getModeDescription(lhr.gatherMode, strings); return (
{ lhr.gatherMode === 'navigation' || hashIndex === 0 ? :
}
{modeDescription}
{label}
{ DISPLAYED_CATEGORIES.map(c => ( )) }
); }; /** * For the summary flow, there are many different cells with different contents and different display properties. * CSS grid makes it easier to enforce things like content alignment and column width (e.g. all category columns have the same width). */ const SummaryFlow: FunctionComponent = () => { const flowResult = useFlowResult(); return (
{ flowResult.steps.map((step, index) => ) }
); }; const SummaryHeader: FunctionComponent = () => { const flowResult = useFlowResult(); const strings = useLocalizedStrings(); const str_ = useStringFormatter(); let numNavigation = 0; let numTimespan = 0; let numSnapshot = 0; for (const step of flowResult.steps) { switch (step.lhr.gatherMode) { case 'navigation': numNavigation++; break; case 'timespan': numTimespan++; break; case 'snapshot': numSnapshot++; break; } } const subtitleCounts = []; if (numNavigation) subtitleCounts.push(str_(strings.navigationReportCount, {numNavigation})); if (numTimespan) subtitleCounts.push(str_(strings.timespanReportCount, {numTimespan})); if (numSnapshot) subtitleCounts.push(str_(strings.snapshotReportCount, {numSnapshot})); const subtitle = subtitleCounts.join(' ยท '); return (
{strings.summary}
{subtitle}
); }; const SummarySectionHeader: FunctionComponent = ({children}) => { return (
{children}
); }; const Summary: FunctionComponent = () => { const strings = useLocalizedStrings(); return (
{strings.allReports}
); }; export { SummaryFlowStep, SummaryHeader, Summary, };