-
+
{link.linkedText
@@ -369,7 +369,7 @@ const LinksReportDetails = ({
{link.linkToAsset
@@ -485,17 +485,38 @@ const getSuggestion = (error: DetailedNonPermaLinkError): string => {
const LinkReportModalNoBrokenLink = (props: Omit) => {
const { onClose } = props
+ const { siteName } = useParams<{ siteName: string }>()
return (
-
-
+
+
-
+
Hurrah! You’ve fixed all broken references on this page.
-
+
You can come back to scan this page again if you make edits to it.
- onClose()}>Back to main report
+ onClose()}>
+ Back to main report
+
+
+ Go to dashboard
+
)
@@ -513,8 +534,8 @@ const LinkReportModalLoading = () => {
Taking another closer look at this page...
diff --git a/src/layouts/SiteDashboard/SiteDashboard.tsx b/src/layouts/SiteDashboard/SiteDashboard.tsx
index 01ddc2823..149c279ee 100644
--- a/src/layouts/SiteDashboard/SiteDashboard.tsx
+++ b/src/layouts/SiteDashboard/SiteDashboard.tsx
@@ -236,7 +236,10 @@ export const SiteDashboard = (): JSX.Element => {
{brokenLinks?.status === "success" &&
- brokenLinks?.errors.length}
+ brokenLinks?.errors.filter(
+ (error) =>
+ error.type !== "duplicate-permalink"
+ ).length}
broken references found
From b3ee0180c1506ae9689385849a555349ec8a726f Mon Sep 17 00:00:00 2001
From: Hanpu Liu <26217378+hanpuliu-charles@users.noreply.github.com>
Date: Tue, 4 Jun 2024 11:58:48 +0800
Subject: [PATCH 3/9] Fixes according to comments
---
.../{paginateBtn.jsx => paginateButton.jsx} | 12 +-
src/layouts/LinkReport/LinksReport.tsx | 90 ++------
.../LinkReportModal/LinkReportModal.tsx | 192 ++++++------------
3 files changed, 87 insertions(+), 207 deletions(-)
rename src/components/{paginateBtn.jsx => paginateButton.jsx} (80%)
diff --git a/src/components/paginateBtn.jsx b/src/components/paginateButton.jsx
similarity index 80%
rename from src/components/paginateBtn.jsx
rename to src/components/paginateButton.jsx
index 60906635e..c2e3ed754 100644
--- a/src/components/paginateBtn.jsx
+++ b/src/components/paginateButton.jsx
@@ -7,7 +7,11 @@ import {
import { typography } from "theme/foundations/typography"
-export default function PaginateBtn({ currentPage, totalPage, onPageChange }) {
+export default function PaginateButton({
+ currentPage,
+ totalPage,
+ onPageChange,
+}) {
return (
@@ -18,9 +22,9 @@ export default function PaginateBtn({ currentPage, totalPage, onPageChange }) {
aria-label="Previous Page"
icon={ }
onClick={() => onPageChange(currentPage - 1)}
- isDisabled={currentPage === 1}
- marginLeft="20px"
- marginRight="12px"
+ isDisabled={currentPage <= 1}
+ marginLeft="1.25rem"
+ marginRight=".75rem"
/>
{
{
-
+
Hurrah! All your references are nice and sturdy.
-
+
We couldn't find any broken references on your site. You can come
back anytime to run the checker again.
@@ -314,7 +291,6 @@ const LinkBody = () => {
{
textStyle="h4"
alignSelf="flex-start"
textAlign="left"
- color="base.content.strong"
+ textColor="base.content.strong"
>
{sortedUniqueLinks.length} Pages with {links.length} broken
references
@@ -355,11 +331,7 @@ const LinkBody = () => {
-
+
Page
@@ -369,20 +341,12 @@ const LinkBody = () => {
textAlign="center"
padding=".375rem 1rem"
>
-
+
Broken References
-
+
View Details
@@ -399,10 +363,7 @@ const LinkBody = () => {
>
-
+
{uniqueBreadcrumb.split("/").at(-1)}
{
@@ -437,7 +397,6 @@ const LinkBody = () => {
{
setSelectedLinkCms(itemUrl)
@@ -484,7 +443,6 @@ const LinkBody = () => {
{
textStyle="h4"
alignSelf="flex-start"
textAlign="left"
- color="base.content.strong"
+ textColor="base.content.strong"
>
Pages with broken references
@@ -505,10 +463,10 @@ const LinkBody = () => {
- Click 'Review page' to view a detailed list of
- references broken on that page.
+ {`Click "Review page" to view a detailed list of
+ references broken on that page.`}
{
-
- Page
-
+ Page
{
textAlign="center"
padding=".375rem 1rem"
>
-
+
Broken References
-
+
View Details
diff --git a/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx b/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
index b8b07daa9..abee76a87 100644
--- a/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
+++ b/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
@@ -17,47 +17,27 @@ import {
Th,
Thead,
Tr,
- Flex,
Grid,
GridItem,
- Icon,
keyframes,
} from "@chakra-ui/react"
import { useFeatureIsOn } from "@growthbook/growthbook-react"
-import {
- Button,
- ModalCloseButton,
- Link,
- Badge,
- Breadcrumb,
- Pagination,
- BxRightArrowAlt,
-} from "@opengovsg/design-system-react"
-import { set } from "lodash"
-import React, { useEffect, useState } from "react"
-import { BiLoaderAlt } from "react-icons/bi"
-import { useQueryClient } from "react-query"
+import { Button, Link } from "@opengovsg/design-system-react"
+import _ from "lodash"
+import { useState } from "react"
+import { BiLoaderAlt, BiLeftArrowAlt, BiSolidInfoCircle } from "react-icons/bi"
+// import { MdInfo } from "react-icons/md";
import { useParams, Link as RouterLink } from "react-router-dom"
import { Modal as CustomModal } from "components/Modal"
-import PaginateBtn from "components/paginateBtn"
-
-import { SITE_LINK_CHECKER_STATUS_KEY } from "constants/queryKeys"
+import PaginateButton from "components/paginateButton"
-import { invalidateMergeRelatedQueries } from "hooks/reviewHooks"
-import { useGetStagingUrl } from "hooks/siteDashboardHooks"
import { useGetBrokenLinks } from "hooks/siteDashboardHooks/useGetLinkChecker"
import { useRefreshLinkChecker } from "hooks/siteDashboardHooks/useRefreshLinkChecker"
import { NoBrokenLinksImage } from "assets"
import { colors } from "theme/foundations/colors"
-import { typography } from "theme/foundations/typography"
-import {
- isBrokenRefError,
- NonPermalinkError,
- NonPermalinkErrorDto,
- RepoError,
-} from "types/linkReport"
+import { NonPermalinkError } from "types/linkReport"
export const LinkReportModal = ({
props,
@@ -74,7 +54,7 @@ export const LinkReportModal = ({
-
+
@@ -118,31 +98,26 @@ const LinkReportModalBanner = (props: Omit) => {
-
-
+
+
Back to main report
@@ -153,7 +128,7 @@ const LinkReportModalBanner = (props: Omit) => {
isDisabled={isBrokenLinksLoading}
height="1.5rem"
padding=".5rem 1rem"
- fontSize=".875rem"
+ textStyle="subhead-2"
size="xs"
>
{isBrokenLinksLoading
@@ -181,16 +156,16 @@ const LinksReportDetails = ({
const [pageNum, setPageNum] = useState(1)
// Sort based on error type
- const detailedErrorArr = generateDetailedError(linksArr).sort((a, b) => {
- return a.detailedType.localeCompare(b.detailedType)
- })
+ const detailedErrorArr = _.sortBy(
+ generateDetailedError(linksArr),
+ (err) => err.detailedType
+ )
const { siteName } = useParams<{ siteName: string }>()
const isBrokenLinksReporterEnabled = useFeatureIsOn(
"is_broken_links_report_enabled"
)
const {
data: brokenLinks,
- error: brokenLinksError,
isLoading: isBrokenLinksFetching,
} = useGetBrokenLinks(siteName, isBrokenLinksReporterEnabled)
@@ -201,7 +176,6 @@ const LinksReportDetails = ({
@@ -229,29 +200,16 @@ const LinksReportDetails = ({
width="100%"
paddingBottom="1.25rem"
>
-
+
{isBrokenLinksLoading
? "Re-scanning page..."
: `${detailedErrorArr.length} broken references found`}
-
-
- View page on staging
-
+
+ View page on staging
-
-
- Edit page on CMS
-
+
+ Edit page on CMS
{!isBrokenLinksLoading && detailedErrorArr.length === 0 && (
@@ -266,16 +224,11 @@ const LinksReportDetails = ({
width="100%"
paddingBottom="1.25rem"
>
-
- After fixing the references, you can click the "Run check
- for this page" in the top right hand corner.
+
+ {`After fixing the references , you can click the "Run check for this page" in the top right hand corner.`}
-
-
+
Type
@@ -309,11 +261,7 @@ const LinksReportDetails = ({
-
+
Reference and Error
@@ -327,23 +275,13 @@ const LinksReportDetails = ({
const isBrokenLink = link.type === "broken-link"
return (
-
-
-
- {getErrorText(link)}
-
-
+
+
+ {getErrorText(link)}
+
{isBrokenLink && (
{link.linkedText
? `"${link.linkedText}"`
@@ -367,32 +304,23 @@ const LinksReportDetails = ({
)}
{link.linkToAsset
? link.linkToAsset
: "No URL linked"}
-
-
-
+
+
{getSuggestion(link)}
@@ -425,7 +353,12 @@ const LinksReportDetails = ({
}
type DetailedNonPermaLinkError = NonPermalinkError & {
- detailedType: string
+ detailedType:
+ | "broken-image"
+ | "broken-file"
+ | "email"
+ | "missing-https"
+ | "broken-link"
}
const isEmailError = (error: NonPermalinkError): boolean => {
@@ -454,7 +387,7 @@ const generateDetailedError = (
})
}
-const getErrorText = (error: DetailedNonPermaLinkError): string => {
+const getErrorText = (error: DetailedNonPermaLinkError) => {
switch (error.detailedType) {
case "broken-image":
return "Image"
@@ -463,8 +396,12 @@ const getErrorText = (error: DetailedNonPermaLinkError): string => {
case "missing-https":
case "broken-link":
return "Hyperlink"
- default:
+ case "email":
return "Email"
+ default: {
+ const exception: never = error.detailedType
+ throw new Error(exception)
+ }
}
}
@@ -478,8 +415,12 @@ const getSuggestion = (error: DetailedNonPermaLinkError): string => {
return "Page doesn't exist."
case "missing-https":
return 'Add a "https://".'
- default:
+ case "email":
return 'Add a "mailto:".'
+ default: {
+ const exception: never = error.detailedType
+ throw new Error(exception)
+ }
}
}
@@ -490,19 +431,10 @@ const LinkReportModalNoBrokenLink = (props: Omit) => {
-
+
Hurrah! You’ve fixed all broken references on this page.
-
+
You can come back to scan this page again if you make edits to it.
onClose()}>
@@ -513,7 +445,7 @@ const LinkReportModalNoBrokenLink = (props: Omit) => {
color="interaction.links.default"
as={RouterLink}
to={`/sites/${siteName}/dashboard`}
- p=".5rem"
+ p="0.5rem"
>
Go to dashboard
From be9ebca04d4522681047827921ec30c98ab126e0 Mon Sep 17 00:00:00 2001
From: Hanpu Liu <26217378+hanpuliu-charles@users.noreply.github.com>
Date: Tue, 4 Jun 2024 12:00:46 +0800
Subject: [PATCH 4/9] Add leading 0 to decimal values.
---
.../components/LinkReportModal/LinkReportModal.tsx | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx b/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
index abee76a87..cce597a83 100644
--- a/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
+++ b/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
@@ -127,7 +127,7 @@ const LinkReportModalBanner = (props: Omit) => {
variant="solid"
isDisabled={isBrokenLinksLoading}
height="1.5rem"
- padding=".5rem 1rem"
+ padding="0.5rem 1rem"
textStyle="subhead-2"
size="xs"
>
@@ -182,7 +182,7 @@ const LinksReportDetails = ({
>
-
+
Type
-
+
Reference and Error
@@ -296,7 +296,7 @@ const LinksReportDetails = ({
{link.linkedText
? `"${link.linkedText}"`
@@ -429,7 +429,7 @@ const LinkReportModalNoBrokenLink = (props: Omit) => {
const { siteName } = useParams<{ siteName: string }>()
return (
-
+
Hurrah! You’ve fixed all broken references on this page.
From 9ec638b4005c28e095b56d44a5c0ddc020dfb39c Mon Sep 17 00:00:00 2001
From: Hanpu Liu <26217378+hanpuliu-charles@users.noreply.github.com>
Date: Tue, 4 Jun 2024 15:31:30 +0800
Subject: [PATCH 5/9] Change to typescript
---
src/components/{paginateButton.jsx => paginateButton.tsx} | 4 ++++
1 file changed, 4 insertions(+)
rename src/components/{paginateButton.jsx => paginateButton.tsx} (91%)
diff --git a/src/components/paginateButton.jsx b/src/components/paginateButton.tsx
similarity index 91%
rename from src/components/paginateButton.jsx
rename to src/components/paginateButton.tsx
index c2e3ed754..245193f5e 100644
--- a/src/components/paginateButton.jsx
+++ b/src/components/paginateButton.tsx
@@ -11,6 +11,10 @@ export default function PaginateButton({
currentPage,
totalPage,
onPageChange,
+}: {
+ currentPage: number
+ totalPage: number
+ onPageChange: (arg: number) => void
}) {
return (
From 1b41903d6596b7f0f3a1c63e332f2227d4c6def0 Mon Sep 17 00:00:00 2001
From: Hanpu Liu <26217378+hanpuliu-charles@users.noreply.github.com>
Date: Tue, 4 Jun 2024 17:19:55 +0800
Subject: [PATCH 6/9] Prevent first column of table in modal from being squeeze
when reference is long
---
src/layouts/LinkReport/LinksReport.tsx | 50 +++++++++++++------
.../LinkReportModal/LinkReportModal.tsx | 4 +-
2 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/src/layouts/LinkReport/LinksReport.tsx b/src/layouts/LinkReport/LinksReport.tsx
index bf236032b..bf3ee8e7f 100644
--- a/src/layouts/LinkReport/LinksReport.tsx
+++ b/src/layouts/LinkReport/LinksReport.tsx
@@ -81,7 +81,7 @@ export const LinksReportBanner = () => {
-
+
Experimental feature
{
const { siteName } = useParams<{ siteName: string }>()
return (
-
+
-
+
Hurrah! All your references are nice and sturdy.
@@ -298,7 +298,7 @@ const LinkBody = () => {
>
-
+
{
border="1px"
borderColor="base.divider.medium"
>
-
+
-
+
Page
@@ -339,13 +344,13 @@ const LinkBody = () => {
w="12.5rem"
h="3.5rem"
textAlign="center"
- padding=".375rem 1rem"
+ padding="0.375rem 1rem"
>
Broken References
-
+
View Details
@@ -361,15 +366,28 @@ const LinkBody = () => {
borderTop="1px"
borderColor="base.divider.medium"
>
-
-
-
+
+
+
{uniqueBreadcrumb.split("/").at(-1)}
{uniqueBreadcrumb.split("/").map((item) => (
@@ -412,7 +430,7 @@ const LinkBody = () => {
@@ -450,7 +468,7 @@ const LinkBody = () => {
>
-
+
{
-
+
Page
Broken References
-
+
View Details
diff --git a/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx b/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
index cce597a83..7849a7cfc 100644
--- a/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
+++ b/src/layouts/LinkReport/components/LinkReportModal/LinkReportModal.tsx
@@ -246,7 +246,7 @@ const LinksReportDetails = ({
border="1px"
borderColor="base.divider.medium"
>
-
+
@@ -317,7 +317,6 @@ const LinksReportDetails = ({
size="1rem"
fill={colors.utility.feedback.critical}
/>
-
)}
-
{isBrokenLinksLoading && (
From 2cd1b08b9580fb6752ecd3b453a1fbf3d92ed33f Mon Sep 17 00:00:00 2001
From: Hanpu Liu <26217378+hanpuliu-charles@users.noreply.github.com>
Date: Tue, 4 Jun 2024 18:26:44 +0800
Subject: [PATCH 7/9] Fix table width
---
src/layouts/LinkReport/LinksReport.tsx | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/layouts/LinkReport/LinksReport.tsx b/src/layouts/LinkReport/LinksReport.tsx
index bf3ee8e7f..216db252f 100644
--- a/src/layouts/LinkReport/LinksReport.tsx
+++ b/src/layouts/LinkReport/LinksReport.tsx
@@ -320,7 +320,6 @@ const LinkBody = () => {
{
Date: Fri, 7 Jun 2024 09:50:42 +0800
Subject: [PATCH 8/9] Fixing nits
---
src/components/paginateButton.tsx | 4 +-
src/layouts/LinkReport/LinksReport.tsx | 44 +++++++------------
.../LinkReportModal/LinkReportModal.tsx | 2 +-
3 files changed, 20 insertions(+), 30 deletions(-)
diff --git a/src/components/paginateButton.tsx b/src/components/paginateButton.tsx
index 245193f5e..2a760460b 100644
--- a/src/components/paginateButton.tsx
+++ b/src/components/paginateButton.tsx
@@ -18,7 +18,7 @@ export default function PaginateButton({
}) {
return (
-
+
Page {currentPage} out of {totalPage}{" "}
onPageChange(currentPage - 1)}
isDisabled={currentPage <= 1}
marginLeft="1.25rem"
- marginRight=".75rem"
+ marginRight="0.75rem"
/>
{
const paths = viewablePageInCms.split("/")
let breadcrumb = paths
- .filter((_, index) => index % 2 === 0)
+ .filter((placeholder, index) => index % 2 === 0)
.slice(2)
.join(" / ")
.replace(/-/g, " ")
@@ -110,17 +111,6 @@ export const LinksReportBanner = () => {
)
}
-const normaliseUrl = (url: string): string => {
- let normalisedUrl = url
- if (url.endsWith("/")) {
- normalisedUrl = url.slice(0, -1)
- }
- if (url.startsWith("/")) {
- normalisedUrl = url.slice(1)
- }
- return normalisedUrl
-}
-
const NoBrokenLinks = () => {
const { siteName } = useParams<{ siteName: string }>()
return (
@@ -131,8 +121,8 @@ const NoBrokenLinks = () => {
Hurrah! All your references are nice and sturdy.
- We couldn't find any broken references on your site. You can come
- back anytime to run the checker again.
+ {`We couldn't find any broken references on your site. You can come
+ back anytime to run the checker again.`}
Back to dashboard
@@ -202,11 +192,10 @@ const LinkBody = () => {
"is_broken_links_report_enabled"
)
const { siteName } = useParams<{ siteName: string }>()
- const {
- data: brokenLinks,
- isError: isBrokenLinksError,
- isLoading: isBrokenLinksFetching,
- } = useGetBrokenLinks(siteName, isBrokenLinksReporterEnabled)
+ const { data: brokenLinks, isError: isBrokenLinksError } = useGetBrokenLinks(
+ siteName,
+ isBrokenLinksReporterEnabled
+ )
if (
!isBrokenLinksReporterEnabled ||
@@ -269,11 +258,10 @@ const LinkBody = () => {
...new Set(links.map((error) => error.viewablePageInCms)),
]
- const sortedUniqueLinks = uniqueLinks.sort((a, b) => {
- const countA = links.filter((link) => link.viewablePageInCms === a).length
- const countB = links.filter((link) => link.viewablePageInCms === b).length
- return countB - countA
- })
+ const sortedUniqueLinks = _.sortBy(
+ uniqueLinks,
+ (e) => links.filter((link) => link.viewablePageInCms === e).length
+ ).reverse()
return (
<>
@@ -314,8 +302,8 @@ const LinkBody = () => {
textAlign="left"
color="base.content.medium"
>
- Click 'Review page' to view a detailed list of
- references broken on that page.
+ {`Click "Review page" to view a detailed list of
+ references broken on that page.`}
{
- Page
+
+ Page
+
Date: Fri, 7 Jun 2024 10:08:50 +0800
Subject: [PATCH 9/9] Capture case rename
---
src/components/{paginateButton.tsx => PaginateButton.tsx} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename src/components/{paginateButton.tsx => PaginateButton.tsx} (100%)
diff --git a/src/components/paginateButton.tsx b/src/components/PaginateButton.tsx
similarity index 100%
rename from src/components/paginateButton.tsx
rename to src/components/PaginateButton.tsx