diff --git a/src/optimizer-page/scan-results/ScanResults.tsx b/src/optimizer-page/scan-results/ScanResults.tsx index a1a673cc3..b0c7cfa4b 100644 --- a/src/optimizer-page/scan-results/ScanResults.tsx +++ b/src/optimizer-page/scan-results/ScanResults.tsx @@ -9,6 +9,7 @@ import SectionCollapsible from '../SectionCollapsible'; import BrokenLinkTable from './BrokenLinkTable'; import LockedInfoIcon from './LockedInfoIcon'; import { LinkCheckResult } from '../types'; +import countBrokenLinks from '../utils'; const InfoCard: FC<{ text: string }> = ({ text }) => ( @@ -25,27 +26,14 @@ interface Props { data: LinkCheckResult | null; } + + const ScanResults: FC = ({ data }) => { const intl = useIntl(); const [showLockedLinks, setShowLockedLinks] = useState(true); const brokenLinkCounts = useMemo(() => { - if (!data?.sections) { - return []; - } - const counts: number[] = []; - data.sections.forEach((section) => { - let count = 0; - section.subsections.forEach((subsection) => { - subsection.units.forEach((unit) => { - unit.blocks.forEach((block) => { - count += block.brokenLinks.length; - }); - }); - }); - counts.push(count); - }); - return counts; + return countBrokenLinks(data); }, [data?.sections]); if (!data) { diff --git a/src/optimizer-page/utils.test.js b/src/optimizer-page/utils.test.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/optimizer-page/utils.ts b/src/optimizer-page/utils.ts new file mode 100644 index 000000000..19a626247 --- /dev/null +++ b/src/optimizer-page/utils.ts @@ -0,0 +1,22 @@ +import { LinkCheckResult } from './types'; + +const countBrokenLinks = (data: LinkCheckResult | null): number[] => { + if (!data?.sections) { + return []; + } + const counts: number[] = []; + data.sections.forEach((section) => { + let count = 0; + section.subsections.forEach((subsection) => { + subsection.units.forEach((unit) => { + unit.blocks.forEach((block) => { + count += block.brokenLinks.length; + }); + }); + }); + counts.push(count); + }); + return counts; +}; + +export default countBrokenLinks;