Skip to content

Commit b6f1cce

Browse files
fix: replace nextjs router by react-router-dom (#61)
Signed-off-by: Carlos Feria <[email protected]>
1 parent 4b3afda commit b6f1cce

File tree

10 files changed

+81
-350
lines changed

10 files changed

+81
-350
lines changed

client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"dayjs": "^1.11.7",
3333
"file-saver": "^2.0.5",
3434
"js-yaml": "^4.1.0",
35-
"next": "^14.2.29",
3635
"oidc-client-ts": "^2.4.0",
3736
"pvtsutils": "^1.3.6",
3837
"react": "^18.2.0",

client/src/app/Routes.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ import { ErrorFallback } from "./components/ErrorFallback";
88
const TrustRoot = lazy(() => import("./pages/TrustRoot"));
99
const RekorSearch = lazy(() => import("./pages/RekorSearch"));
1010

11+
export const Paths = {
12+
trustRoot: "/trust-root",
13+
rekorSearch: "/rekor-search",
14+
} as const;
15+
1116
export const AppRoutes = () => {
1217
const allRoutes = useRoutes([
13-
{ path: "/", element: <Navigate to="/trust-root" /> },
14-
{ path: "/trust-root", element: <TrustRoot /> },
15-
{ path: "/rekor-search", element: <RekorSearch /> },
18+
{ path: "/", element: <Navigate to={Paths.trustRoot} /> },
19+
{ path: Paths.trustRoot, element: <TrustRoot /> },
20+
{ path: Paths.rekorSearch, element: <RekorSearch /> },
1621
]);
1722

1823
return (

client/src/app/layout/sidebar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NavLink } from "react-router-dom";
44
import { Nav, NavList, PageSidebar, PageSidebarBody } from "@patternfly/react-core";
55
import { css } from "@patternfly/react-styles";
66
import nav from "@patternfly/react-styles/css/components/Nav/nav";
7+
import { Paths } from "@app/Routes";
78

89
const LINK_CLASS = nav.navLink;
910
const ACTIVE_LINK_CLASS = nav.modifiers.current;
@@ -15,7 +16,7 @@ export const SidebarApp: React.FC = () => {
1516
<NavList>
1617
<li className={nav.navItem}>
1718
<NavLink
18-
to="/trust-root"
19+
to={Paths.trustRoot}
1920
className={({ isActive }) => {
2021
return css(LINK_CLASS, isActive ? ACTIVE_LINK_CLASS : "");
2122
}}
@@ -25,7 +26,7 @@ export const SidebarApp: React.FC = () => {
2526
</li>
2627
<li className={nav.navItem}>
2728
<NavLink
28-
to="/rekor-search"
29+
to={Paths.rekorSearch}
2930
className={({ isActive }) => {
3031
return css(LINK_CLASS, isActive ? ACTIVE_LINK_CLASS : "");
3132
}}

client/src/app/pages/RekorSearch/Template/Intoto001.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { dump } from "js-yaml";
2-
import NextLink from "next/link";
2+
import { Link } from "react-router-dom";
33
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
44
import { atomDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
55
import { type IntotoV001Schema } from "rekor";
66
import { decodex509 } from "./x509/decode";
77
import { Panel } from "@patternfly/react-core";
8+
import { Paths } from "@app/Routes";
89

910
export function IntotoViewer001({ intoto }: { intoto: IntotoV001Schema }) {
1011
const certContent = window.atob(intoto.publicKey || "");
@@ -24,12 +25,14 @@ export function IntotoViewer001({ intoto }: { intoto: IntotoV001Schema }) {
2425
return (
2526
<Panel>
2627
<h5 style={{ paddingTop: "1.5em", paddingBottom: "1.5em" }}>
27-
<NextLink
28-
href={`/?hash=${intoto.content.payloadHash?.algorithm}:${intoto.content.payloadHash?.value}`}
29-
passHref
28+
<Link
29+
to={{
30+
pathname: Paths.rekorSearch,
31+
search: `?hash=${intoto.content.payloadHash?.algorithm}:${intoto.content.payloadHash?.value}`,
32+
}}
3033
>
3134
Hash
32-
</NextLink>
35+
</Link>
3336
</h5>
3437

3538
<SyntaxHighlighter language="text" style={atomDark}>

client/src/app/pages/RekorSearch/Template/Intoto002.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { dump } from "js-yaml";
2-
import Link from "next/link";
2+
import { Link } from "react-router-dom";
33
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
44
import { atomDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
55
import { type IntotoV002Schema } from "rekor";
66
import { decodex509 } from "./x509/decode";
77
import { Panel } from "@patternfly/react-core";
8+
import { Paths } from "@app/Routes";
89

910
export function IntotoViewer002({ intoto }: { intoto: IntotoV002Schema }) {
1011
const signature = intoto.content.envelope?.signatures[0];
@@ -25,7 +26,14 @@ export function IntotoViewer002({ intoto }: { intoto: IntotoV002Schema }) {
2526
return (
2627
<Panel>
2728
<h5 style={{ paddingTop: "1.5em", paddingBottom: "1.5em" }}>
28-
<Link href={`/?hash=${intoto.content.payloadHash?.algorithm}:${intoto.content.payloadHash?.value}`}>Hash</Link>
29+
<Link
30+
to={{
31+
pathname: Paths.rekorSearch,
32+
search: `?hash=${intoto.content.payloadHash?.algorithm}:${intoto.content.payloadHash?.value}`,
33+
}}
34+
>
35+
Hash
36+
</Link>
2937
</h5>
3038

3139
<SyntaxHighlighter language="text" style={atomDark}>

client/src/app/pages/RekorSearch/components/DSSEViewer.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { dump } from "js-yaml";
2-
import Link from "next/link";
2+
import { Link } from "react-router-dom";
33
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
44
import { atomDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
55
import { type DSSEV001Schema } from "rekor";
66
import { Panel } from "@patternfly/react-core";
77
import { decodex509 } from "../Template/x509/decode";
8+
import { Paths } from "@app/Routes";
89

910
export function DSSEViewer({ dsse }: { dsse: DSSEV001Schema }) {
1011
const sig = dsse.signatures?.[0];
@@ -25,7 +26,12 @@ export function DSSEViewer({ dsse }: { dsse: DSSEV001Schema }) {
2526
return (
2627
<Panel>
2728
<h5 style={{ paddingTop: "1em" }}>
28-
<Link href={`/?hash=${dsse.payloadHash?.algorithm}:${dsse.payloadHash?.value}`} passHref>
29+
<Link
30+
to={{
31+
pathname: Paths.rekorSearch,
32+
search: `?hash=${dsse.payloadHash?.algorithm}:${dsse.payloadHash?.value}`,
33+
}}
34+
>
2935
Hash
3036
</Link>
3137
</h5>

client/src/app/pages/RekorSearch/components/Entry.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { dump, load } from "js-yaml";
2-
import Link from "next/link";
32
import { Convert } from "pvtsutils";
43
import { Fragment, type ReactNode, useState } from "react";
54
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
@@ -30,6 +29,8 @@ import { IntotoViewer001 } from "../Template/Intoto001";
3029
import { IntotoViewer002 } from "../Template/Intoto002";
3130
import { DSSEViewer } from "./DSSEViewer";
3231
import { HashedRekordViewer } from "./HashedRekord";
32+
import { Link } from "react-router-dom";
33+
import { Paths } from "@app/Routes";
3334

3435
const DUMP_OPTIONS: jsyaml.DumpOptions = {
3536
replacer: (_key, value: string) => {
@@ -154,10 +155,7 @@ export function Entry({ entry }: { entry: LogEntry }) {
154155
textOverflow: "ellipsis",
155156
}}
156157
>
157-
Entry UUID:{" "}
158-
<Link href={`/?uuid=${uuid}`} passHref>
159-
{uuid}
160-
</Link>
158+
Entry UUID: <Link to={{ pathname: Paths.rekorSearch, search: `?uuid=${uuid}` }}>{uuid}</Link>
161159
</h2>
162160
<Divider />
163161
<Grid hasGutter={true}>
@@ -168,9 +166,7 @@ export function Entry({ entry }: { entry: LogEntry }) {
168166
<EntryCard
169167
title="Log Index"
170168
content={
171-
<Link href={`/?logIndex=${obj.logIndex}`} passHref>
172-
{obj.logIndex}
173-
</Link>
169+
<Link to={{ pathname: Paths.rekorSearch, search: `?logIndex=${obj.logIndex}` }}>{obj.logIndex}</Link>
174170
}
175171
/>
176172
</GridItem>

client/src/app/pages/RekorSearch/components/Explorer.tsx

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Fragment, useEffect, useState } from "react";
1+
import { useLocation, useNavigate } from "react-router-dom";
2+
import { Fragment, useCallback, useEffect, useState } from "react";
23
import { ApiError, type RekorError } from "rekor";
3-
import { type RekorEntries, type SearchQuery, useRekorSearch } from "../../../api/rekor-api";
4+
import { isAttribute, type RekorEntries, type SearchQuery, useRekorSearch } from "../../../api/rekor-api";
45
import { type FormInputs, SearchForm } from "./SearchForm";
56
import { Alert, Flex, Spinner, Pagination } from "@patternfly/react-core";
67
import { Entry } from "./Entry";
@@ -94,7 +95,9 @@ function LoadingIndicator() {
9495
}
9596

9697
export function Explorer() {
97-
const [formInputs, _setFormInputs] = useState<FormInputs>();
98+
const navigate = useNavigate();
99+
const location = useLocation();
100+
const [formInputs, setFormInputs] = useState<FormInputs>();
98101
const [query, setQuery] = useState<SearchQuery>();
99102
const search = useRekorSearch();
100103

@@ -121,35 +124,28 @@ export function Explorer() {
121124
fetch();
122125
}, [query, page, search]);
123126

124-
// const setQueryParams = useCallback(
125-
// (formInputs: FormInputs) => {
126-
// setPage(1);
127-
128-
// router.push(
129-
// {
130-
// pathname: router.pathname,
131-
// query: {
132-
// [formInputs.attribute]: formInputs.value,
133-
// },
134-
// },
135-
// `/?${formInputs.attribute}=${formInputs.value}`,
136-
// { shallow: true }
137-
// );
138-
// },
139-
// [router]
140-
// );
141-
142-
// useEffect(() => {
143-
// const attribute = Object.keys(router.query).find((key) => isAttribute(key)) as Attribute | undefined;
144-
// const value = attribute && router.query[attribute];
145-
146-
// if (!value || Array.isArray(value)) {
147-
// return;
148-
// }
149-
// setFormInputs({ attribute, value });
150-
// }, [router.query]);
151-
152-
const setQueryParams = () => {};
127+
const setQueryParams = useCallback(
128+
(formInputs: FormInputs) => {
129+
setPage(1);
130+
131+
navigate({
132+
pathname: location.pathname,
133+
search: `?${formInputs.attribute}=${formInputs.value}`,
134+
});
135+
},
136+
[navigate, location.pathname]
137+
);
138+
139+
useEffect(() => {
140+
const searchParams = new URLSearchParams(location.search);
141+
const attribute = Array.from(searchParams.keys()).find((key) => isAttribute(key));
142+
const value = attribute && searchParams.get(attribute);
143+
144+
if (!value || Array.isArray(value)) {
145+
return;
146+
}
147+
setFormInputs({ attribute, value });
148+
}, [location.search]);
153149

154150
useEffect(() => {
155151
if (formInputs) {

client/src/app/pages/RekorSearch/components/HashedRekord.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { dump } from "js-yaml";
2-
import Link from "next/link";
2+
import { Link } from "react-router-dom";
33
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
44
import { atomDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
55
import { type RekorSchema } from "rekor";
66
import { decodex509 } from "../Template/x509/decode";
77
import { Panel } from "@patternfly/react-core";
8+
import { Paths } from "@app/Routes";
89

910
export function HashedRekordViewer({ hashedRekord }: { hashedRekord: RekorSchema }) {
1011
const certContent = window.atob(hashedRekord.signature.publicKey?.content ?? "");
@@ -24,7 +25,12 @@ export function HashedRekordViewer({ hashedRekord }: { hashedRekord: RekorSchema
2425
return (
2526
<Panel style={{ marginTop: "1.25em" }}>
2627
<h5 style={{ margin: "1em auto" }}>
27-
<Link href={`/?hash=${hashedRekord.data.hash?.algorithm}:${hashedRekord.data.hash?.value}`} passHref>
28+
<Link
29+
to={{
30+
pathname: Paths.rekorSearch,
31+
search: `?hash=${hashedRekord.data.hash?.algorithm}:${hashedRekord.data.hash?.value}`,
32+
}}
33+
>
2834
Hash
2935
</Link>
3036
</h5>

0 commit comments

Comments
 (0)