From 8e380659aa91fe6cb3cbb9976de368174284f586 Mon Sep 17 00:00:00 2001 From: Jesper Hodge Date: Fri, 13 Dec 2024 09:36:46 -0500 Subject: [PATCH] feat: add translations --- src/optimizer-page/CourseOptimizerPage.jsx | 2 - .../scan-results/ScanResults.jsx | 165 +++++++++++++----- src/optimizer-page/scan-results/messages.js | 42 +++++ 3 files changed, 160 insertions(+), 49 deletions(-) create mode 100644 src/optimizer-page/scan-results/messages.js diff --git a/src/optimizer-page/CourseOptimizerPage.jsx b/src/optimizer-page/CourseOptimizerPage.jsx index 46378442b..b6911271d 100644 --- a/src/optimizer-page/CourseOptimizerPage.jsx +++ b/src/optimizer-page/CourseOptimizerPage.jsx @@ -19,8 +19,6 @@ import { import { startLinkCheck, fetchLinkCheckStatus } from './data/thunks'; import { useModel } from '../generic/model-store'; import { ScanResults } from './scan-results'; -// import ExportModalError from './export-modal-error/ExportModalError'; -// import ExportFooter from './export-footer/ExportFooter'; const pollLinkCheckStatus = (dispatch, courseId, delay) => { const interval = setInterval(() => { diff --git a/src/optimizer-page/scan-results/ScanResults.jsx b/src/optimizer-page/scan-results/ScanResults.jsx index ef7c4c1a7..305053b22 100644 --- a/src/optimizer-page/scan-results/ScanResults.jsx +++ b/src/optimizer-page/scan-results/ScanResults.jsx @@ -1,10 +1,26 @@ +import { useState, useCallback } from 'react'; import { - Container, Layout, Button, Card, Collapsible, Icon, Table, CheckBox, OverlayTrigger, Tooltip, + Container, + Layout, + Button, + Card, + Collapsible, + Icon, + Table, + CheckBox, + OverlayTrigger, + Tooltip, } from '@openedx/paragon'; import { - ArrowRight, ArrowDropDown, OpenInNew, Question, Lock, LinkOff, + ArrowRight, + ArrowDropDown, + OpenInNew, + Question, + Lock, + LinkOff, } from '@openedx/paragon/icons'; -import { useState, useCallback } from 'react'; +import { useIntl } from '@edx/frontend-platform/i18n'; +import messages from './messages'; const SectionCollapsible = ({ title, children, redItalics, className, @@ -13,24 +29,27 @@ const SectionCollapsible = ({ const styling = 'card-lg'; const collapsibleTitle = (
- {title}{redItalics} + + {title} + {redItalics}
); return ( -
{collapsibleTitle}

} + title={( +

+ {collapsibleTitle} +

+ )} iconWhenClosed="" iconWhenOpen="" open={isOpen} onToggle={() => setIsOpen(!isOpen)} > - - {children} - + {children}
); @@ -47,26 +66,52 @@ function getBaseUrl(url) { const BrokenLinkHref = ({ href }) => (
- {href} + + {href} +
); -const GoToBlock = ({ block }) => Go to Block; - -const lockedInfoIcon = ( - - These course files are "locked" so we cannot test whether they work or not. - - )} - > - - +const GoToBlock = ({ block }) => ( + + + + Go to Block + + +); + +const LockedInfoIcon = () => { + const intl = useIntl(); + + return ( + + {intl.formatMessage(messages.lockedInfoTooltip)} + + )} + > + + + ); +}; + +const InfoCard = ({ text }) => ( + +

+ {text} +

+
); + const ScanResults = ({ data }) => { + const intl = useIntl(); const [showLockedLinks, setShowLockedLinks] = useState(true); const countBrokenLinksPerSection = useCallback(() => { @@ -86,14 +131,10 @@ const ScanResults = ({ data }) => { }, [data?.sections]); if (!data) { - return ( - -

Scan Results

- -

No data available

-
-
- ); + return ; + } + if (!data.sections) { + return ; } const { sections } = data; @@ -106,10 +147,18 @@ const ScanResults = ({ data }) => {
-

Broken Links Scan

+

{intl.formatMessage(messages.scanHeader)}

- { setShowLockedLinks(!showLockedLinks); }} label="Show Locked Course Files" /> - {lockedInfoIcon} + { + setShowLockedLinks(!showLockedLinks); + }} + label={intl.formatMessage(messages.lockedCheckboxLabel)} + /> +
@@ -118,31 +167,53 @@ const ScanResults = ({ data }) => { {section.subsections.map((subsection) => ( <> -

{subsection.displayName}

+

+ {subsection.displayName} +

{subsection.units.map((unit) => (

{unit.displayName}

{ - const blockBrokenLinks = block.brokenLinks.map((link) => ({ - blockLink: , - brokenLink: , - status: Status: Broken, - })); + 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: Status: LOCKED {lockedInfoIcon}, - })); + const blockLockedLinks = block.lockedLinks.map( + (link) => ({ + blockLink: , + brokenLink: , + status: ( + + + {intl.formatMessage(messages.lockedLinkStatus)} + + ), + }), + ); acc.push(...blockLockedLinks); return acc; }, [])} diff --git a/src/optimizer-page/scan-results/messages.js b/src/optimizer-page/scan-results/messages.js new file mode 100644 index 000000000..9e29a83cf --- /dev/null +++ b/src/optimizer-page/scan-results/messages.js @@ -0,0 +1,42 @@ +import { defineMessages } from '@edx/frontend-platform/i18n'; + +const messages = defineMessages({ + pageTitle: { + id: 'course-authoring.course-optimizer.page.title', + defaultMessage: '{headingTitle} | {courseName} | {siteName}', + }, + noDataCard: { + id: 'course-authoring.course-optimizer.noDataCard', + defaultMessage: 'No Scan data available', + }, + noBrokenLinksCard: { + id: 'course-authoring.course-optimizer.emptyResultsCard', + defaultMessage: 'No broken links found', + }, + scanHeader: { + id: 'course-authoring.course-optimizer.scanHeader', + defaultMessage: 'Broken Links Scan', + }, + lockedCheckboxLabel: { + id: 'course-authoring.course-optimizer.lockedCheckboxLabel', + defaultMessage: 'Show Locked Course Files', + }, + brokenLinksNumber: { + id: 'course-authoring.course-optimizer.brokenLinksNumber', + defaultMessage: '{count} broken links', + }, + lockedInfoTooltip: { + id: 'course-authoring.course-optimizer.lockedInfoTooltip', + defaultMessage: 'These course files are "locked", so we cannot test whether they work or not.', + }, + brokenLinkStatus: { + id: 'course-authoring.course-optimizer.brokenLinkStatus', + defaultMessage: 'Status: Broken', + }, + lockedLinkStatus: { + id: 'course-authoring.course-optimizer.lockedLinkStatus', + defaultMessage: 'Status: Locked', + }, +}); + +export default messages;