From 08850e408e8abb0f416357e9fef681558b9f3f2e Mon Sep 17 00:00:00 2001 From: Jesper Hodge Date: Fri, 13 Dec 2024 14:28:42 -0500 Subject: [PATCH] refactor: extract components --- src/optimizer-page/SectionCollapsible.tsx | 51 ++++++++ .../scan-results/ScanResults.jsx | 118 ++++++++++-------- .../scan-results/ScanResults.scss | 2 +- 3 files changed, 121 insertions(+), 50 deletions(-) create mode 100644 src/optimizer-page/SectionCollapsible.tsx diff --git a/src/optimizer-page/SectionCollapsible.tsx b/src/optimizer-page/SectionCollapsible.tsx new file mode 100644 index 000000000..418b29b2f --- /dev/null +++ b/src/optimizer-page/SectionCollapsible.tsx @@ -0,0 +1,51 @@ +import { useState, FC } from 'react'; +import { + Collapsible, + Icon, +} from '@openedx/paragon'; +import { + ArrowRight, + ArrowDropDown, +} from '@openedx/paragon/icons'; + +interface Props { + title: string; + children: React.ReactNode; + redItalics: string; + className: string; +} + +const SectionCollapsible: FC = ({ + title, children, redItalics, className, +}) => { + const [isOpen, setIsOpen] = useState(false); + const styling = 'card-lg'; + const collapsibleTitle = ( +
+ + {title} + {redItalics} +
+ ); + + return ( +
+ + {collapsibleTitle} +

+ )} + iconWhenClosed="" + iconWhenOpen="" + open={isOpen} + onToggle={() => setIsOpen(!isOpen)} + > + {children} +
+
+ ); +}; + +export default SectionCollapsible; diff --git a/src/optimizer-page/scan-results/ScanResults.jsx b/src/optimizer-page/scan-results/ScanResults.jsx index 305053b22..9f1947149 100644 --- a/src/optimizer-page/scan-results/ScanResults.jsx +++ b/src/optimizer-page/scan-results/ScanResults.jsx @@ -1,10 +1,6 @@ import { useState, useCallback } from 'react'; import { - Container, - Layout, - Button, Card, - Collapsible, Icon, Table, CheckBox, @@ -12,8 +8,6 @@ import { Tooltip, } from '@openedx/paragon'; import { - ArrowRight, - ArrowDropDown, OpenInNew, Question, Lock, @@ -21,48 +15,7 @@ import { } from '@openedx/paragon/icons'; import { useIntl } from '@edx/frontend-platform/i18n'; import messages from './messages'; - -const SectionCollapsible = ({ - title, children, redItalics, className, -}) => { - const [isOpen, setIsOpen] = useState(false); - const styling = 'card-lg'; - const collapsibleTitle = ( -
- - {title} - {redItalics} -
- ); - - return ( -
- - {collapsibleTitle} -

- )} - iconWhenClosed="" - iconWhenOpen="" - open={isOpen} - onToggle={() => setIsOpen(!isOpen)} - > - {children} -
-
- ); -}; - -function getBaseUrl(url) { - try { - const parsedUrl = new URL(url); - return `${parsedUrl.origin}`; - } catch (error) { - return null; - } -} +import SectionCollapsible from '../SectionCollapsible'; const BrokenLinkHref = ({ href }) => (
@@ -110,6 +63,73 @@ const InfoCard = ({ text }) => ( ); +const BrokenLinkTable = ({ unit }) => ( + <> +

{unit.displayName}

+ { + const blockBrokenLinks = block.brokenLinks.map( + (link) => ({ + blockLink: , + brokenLink: , + status: ( + + + {intl.formatMessage(messages.brokenLinkStatus)} + + ), + }), + ); + acc.push(...blockBrokenLinks); + if (!showLockedLinks) { + return acc; + } + + const blockLockedLinks = block.lockedLinks.map( + (link) => ({ + blockLink: , + brokenLink: , + status: ( + + + {intl.formatMessage(messages.lockedLinkStatus)} + + ), + }), + ); + acc.push(...blockLockedLinks); + return acc; + }, [])} + columns={[ + { + key: 'blockLink', + columnSortable: true, + onSort: () => {}, + width: 'col-3', + hideHeader: true, + }, + { + key: 'brokenLink', + columnSortable: false, + onSort: () => {}, + width: 'col-6', + hideHeader: true, + }, + { + key: 'status', + columnSortable: false, + onSort: () => {}, + width: 'col-6', + hideHeader: true, + }, + ]} + /> + +); + const ScanResults = ({ data }) => { const intl = useIntl(); const [showLockedLinks, setShowLockedLinks] = useState(true); @@ -179,7 +199,7 @@ const ScanResults = ({ data }) => { {subsection.units.map((unit) => (
-

{unit.displayName}

+

{unit.displayName}

{ const blockBrokenLinks = block.brokenLinks.map( diff --git a/src/optimizer-page/scan-results/ScanResults.scss b/src/optimizer-page/scan-results/ScanResults.scss index 2b772ff52..6a3e94765 100644 --- a/src/optimizer-page/scan-results/ScanResults.scss +++ b/src/optimizer-page/scan-results/ScanResults.scss @@ -44,7 +44,7 @@ } /* Unit Header */ - .block-header { + .unit-header { font-size: 14px; font-weight: 700; margin-bottom: 5px;