Skip to content

Commit 086e593

Browse files
committed
feat(#3511): Add DS 2 upgrade notification & component links
1 parent 7f7accf commit 086e593

7 files changed

Lines changed: 35 additions & 48 deletions

File tree

src/components/component-header/ComponentHeader.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { GoabBadge, GoabBlock, GoabText } from "@abgov/react-components";
22
import "./ComponentHeader.css";
3-
import { Link } from "react-router-dom";
3+
import { Link, useLocation } from "react-router-dom";
44
import { useEffect, useState } from "react";
5-
import { toSentenceCase, fetchAllIssueCounts, fetchComponentMetadataFromProject } from "../../utils";
5+
import { toSentenceCase, fetchAllIssueCounts, fetchComponentMetadataFromProject, getV2Link } from "../../utils";
66

77
export enum Category {
88
CONTENT_AND_LAYOUT = "Content and layout",
@@ -23,6 +23,7 @@ interface Props {
2323

2424
export const ComponentHeader: React.FC<Props> = (props) => {
2525
const [issueCount, setIssueCount] = useState<number | null>(null);
26+
const v2Link = getV2Link(useLocation().pathname);
2627

2728
useEffect(() => {
2829
if (!props.githubLink) return;
@@ -49,6 +50,7 @@ export const ComponentHeader: React.FC<Props> = (props) => {
4950
</GoabText>
5051
{(props.githubLink || props.figmaLink) && (
5152
<GoabBlock gap="l" direction="row" mt="l">
53+
<a className="small" target="_blank" rel="noopener noreferrer" href={v2Link}>New version</a>
5254
{/* GitHub Issues link, if we have a "githubLink" */}
5355
<GoabBlock gap="2xs" direction="row">
5456
{props.githubLink && (

src/components/example-header/ExampleHeader.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { GoabBlock, GoabText, GoabBadge } from "@abgov/react-components";
22
import "../component-header/ComponentHeader.css"; // reusing existing styling from component pages
3+
import { getV2Link } from "../../utils";
4+
import { useLocation } from "react-router-dom";
35

46
interface Props {
57
name: string;
@@ -10,6 +12,9 @@ interface Props {
1012
}
1113

1214
export const ExampleHeader: React.FC<Props> = ({ name, description, githubLink, figmaLink, tags }) => {
15+
16+
const v2Link = getV2Link(useLocation().pathname);
17+
1318
return (
1419
<div className="component-header">
1520

@@ -46,6 +51,7 @@ export const ExampleHeader: React.FC<Props> = ({ name, description, githubLink,
4651
{(githubLink || figmaLink) && (
4752

4853
<GoabBlock gap="l" direction="row">
54+
<a className="small" target="_blank" rel="noopener noreferrer" href={v2Link}>New version</a>
4955
{githubLink && (
5056
<GoabBlock gap="2xs" direction="row">
5157
<goa-icon type="logo-github" size="2xsmall" mb="xs" fillcolor="#666666" />

src/components/version-language-switcher/HelpButton.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
import { useContext } from "react";
2-
import { useLocation } from "react-router-dom";
32
import { GoabIconButton, GoabTooltip } from "@abgov/react-components";
43

54
import { useVersionUpdateNotification } from "@components/version-language-switcher/VersionUpdateNotificationContext";
6-
import { useSiteWideNotification } from "@contexts/SiteWideNotificationContext";
75
import { LanguageVersionContext } from "@contexts/LanguageVersionContext";
86

97
export function HelpButton() {
108
const { reset: resetVersion } = useVersionUpdateNotification();
11-
const { reset: resetSiteWideNotification } = useSiteWideNotification();
129
useContext(LanguageVersionContext);
13-
const location = useLocation();
1410

15-
const handleHelpClick = () => {
16-
const isComponentOrExamplePage =
17-
location.pathname.startsWith("/components") || location.pathname.startsWith("/examples");
18-
19-
if (isComponentOrExamplePage) {
20-
resetVersion();
21-
} else {
22-
resetSiteWideNotification();
23-
}
11+
const handleHelpClick = () => {
12+
resetVersion();
2413
};
2514

2615
return (
27-
<GoabTooltip content="Version and framework info">
16+
<GoabTooltip content="Version info">
2817
<GoabIconButton ml={"xs"}
2918
variant="color"
3019
size="small"

src/components/version-language-switcher/VersionUpdateNotification.tsx

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import { useEffect } from "react";
22
import { GoabNotification } from "@abgov/react-components";
33
import { MAX_CONTENT_WIDTH } from "../../global-constants";
44
import { useVersionUpdateNotification } from "./VersionUpdateNotificationContext";
5-
import type { LanguageVersion } from "@components/version-language-switcher/version-language-constants";
5+
import { getV2Link } from "../../utils";
66

7-
interface VersionUpdateNotificationProps {
8-
version: LanguageVersion;
9-
}
10-
11-
export function VersionUpdateNotification({ version }: VersionUpdateNotificationProps) {
12-
const { isDismissed, dismiss, oldLinkRef, newLinkRef } = useVersionUpdateNotification();
7+
export function VersionUpdateNotification() {
8+
const { isDismissed, dismiss, newLinkRef } = useVersionUpdateNotification();
9+
const v2UpgradeLink = getV2Link("/upgrade-guide");
1310

1411
useEffect(() => {
1512
const el = document.querySelector("goa-notification");
@@ -24,22 +21,19 @@ export function VersionUpdateNotification({ version }: VersionUpdateNotification
2421
if (isDismissed) return null;
2522

2623
return (
27-
<GoabNotification type={version === "old" ? "important" : "information"} maxContentWidth={MAX_CONTENT_WIDTH}>
28-
{version === "old" ? (
24+
<GoabNotification type="information" maxContentWidth={MAX_CONTENT_WIDTH}>
2925
<>
30-
Support for v3 (Angular) and v5 (React) has ended. Read the{" "}
31-
<a ref={oldLinkRef} href="/get-started/developers/update">
26+
Design System 2 is now available! Check out the{" "}
27+
<a
28+
ref={newLinkRef}
29+
href={v2UpgradeLink}
30+
className="no-external-icon"
31+
target="_blank"
32+
rel="noopener noreferrer"
33+
>
3234
<span style={{ whiteSpace: "nowrap" }}>upgrade guide</span>
33-
</a>
34-
</>
35-
) : (
36-
<>
37-
Upgrading to the latest version of the design system?{" "}
38-
<a ref={newLinkRef} href="/get-started/developers/update">
39-
<span style={{ whiteSpace: "nowrap" }}>View the upgrade guide</span>
40-
</a>
35+
</a>.
4136
</>
42-
)}
4337
</GoabNotification>
4438
);
4539
}

src/components/version-language-switcher/VersionUpdateNotificationContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ export const VersionUpdateNotificationProvider = ({
2525
const newLinkRef = useRef<HTMLAnchorElement>(null);
2626

2727
useEffect(() => {
28-
const storedValue = localStorage.getItem(storageKey);
28+
const storedValue = sessionStorage.getItem(storageKey);
2929
setIsDismissed(storedValue === "true");
3030
}, [version]);
3131

3232
const dismiss = () => {
33-
localStorage.setItem(storageKey, "true");
33+
sessionStorage.setItem(storageKey, "true");
3434
setIsDismissed(true);
3535
};
3636

3737
const reset = () => {
38-
localStorage.removeItem(storageKey);
38+
sessionStorage.removeItem(storageKey);
3939
setIsDismissed(false);
4040
};
4141

src/routes/root.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ import { HelpButton } from "@components/version-language-switcher/HelpButton";
2222
import {
2323
VersionLanguageSwitcher
2424
} from "@components/version-language-switcher/VersionLanguageSwitcher";
25-
import { LanguageVersionContext } from "@contexts/LanguageVersionContext";
26-
import { useContext } from "react";
27-
import SiteWideNotification from "@components/version-language-switcher/SiteWideNotification";
28-
2925

3026
function ScrollToTop() {
3127
const { pathname } = useLocation();
@@ -38,10 +34,7 @@ function ScrollToTop() {
3834
}
3935

4036
export default function Root() {
41-
const { version } = useContext(LanguageVersionContext);
4237
const location = useLocation();
43-
const showNotification =
44-
location.pathname.startsWith("/components") || location.pathname.startsWith("/examples");
4538
const [visible, setVisibility] = useState<boolean>(false);
4639

4740
// to show temporary notification on examples route, except temporary-notification playground which needs playground bindings
@@ -81,8 +74,7 @@ export default function Root() {
8174
<Link to="/design-tokens">Tokens</Link>
8275
<Link to="/get-started/support" className="interactive">Get support</Link>
8376
</GoabAppHeader>
84-
{showNotification && <VersionUpdateNotification version={version} />}
85-
<SiteWideNotification />
77+
<VersionUpdateNotification />
8678
<Outlet />
8779
</section>
8880

src/utils/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66

77
type IssueGroup = "Components" | "Examples";
88

9+
export function getV2Link(pathname: string): string {
10+
return `https://design.alberta.ca${pathname}`;
11+
}
12+
913
export function toKebabCase(str: string) {
1014
return str
1115
.replace(/\s+/g, "-") // Replace spaces with -

0 commit comments

Comments
 (0)