Skip to content

Commit a062f30

Browse files
committed
Added pages to side bar
Also added external redirects. This is kinda really buggy so probably need to fix this but we will see... Signed-off-by: Zoe Nickson <mnickson@sidingsmedia.com>
1 parent 1096570 commit a062f30

File tree

5 files changed

+110
-15
lines changed

5 files changed

+110
-15
lines changed

src/App.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,56 @@
22
// SPDX-License-Identifier: MIT
33

44
import * as React from "react";
5+
import DnsIcon from "@mui/icons-material/Dns";
6+
import CachedIcon from "@mui/icons-material/Cached";
57
import DashboardIcon from "@mui/icons-material/Dashboard";
6-
import PersonIcon from "@mui/icons-material/Person";
78
import { Outlet } from "react-router";
89
import { ReactRouterAppProvider } from "@toolpad/core/react-router";
910
import type { Navigation } from "@toolpad/core/AppProvider";
11+
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
1012

11-
const NAVIGATION: Navigation = [
13+
let navigation: Navigation = [
1214
{
13-
kind: "header",
14-
title: "Main items",
15-
},
16-
{
17-
title: "Dashboard",
15+
segment: "",
16+
title: "Overview",
1817
icon: <DashboardIcon />,
1918
},
19+
{ kind: "divider" },
20+
{ kind: "header", title: "Systems" },
2021
{
21-
segment: "employees",
22-
title: "Employees",
23-
icon: <PersonIcon />,
24-
pattern: "employees{/:employeeId}*",
22+
segment: "rdns",
23+
title: "Recursive DNS",
24+
icon: <DnsIcon />,
25+
children: [
26+
{
27+
segment: "rdns/cache",
28+
title: "Cache",
29+
icon: <CachedIcon />,
30+
},
31+
],
2532
},
33+
{ kind: "divider" },
34+
{ kind: "header", title: "External" },
2635
];
2736

37+
for (const link of JSON.parse(import.meta.env.VITE_EXTERNAL_SIDEBAR_LINKS)) {
38+
navigation.push({
39+
title: link.title,
40+
icon: <OpenInNewIcon />,
41+
segment: `external/${encodeURIComponent(link.href)}`,
42+
});
43+
}
44+
2845
const BRANDING = {
2946
title: "Unified Control",
30-
logo: <img alt="MUI logo" height={40} src="/logo.svg" width={40} />,
47+
logo: (
48+
<img alt="Unified Control Logo" height={40} src="/logo.svg" width={40} />
49+
),
3150
};
3251

3352
export default function App() {
3453
return (
35-
<ReactRouterAppProvider navigation={NAVIGATION} branding={BRANDING}>
54+
<ReactRouterAppProvider navigation={navigation} branding={BRANDING}>
3655
<Outlet />
3756
</ReactRouterAppProvider>
3857
);

src/main.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@
33

44
import * as React from "react";
55
import * as ReactDOM from "react-dom/client";
6-
import { createBrowserRouter, RouterProvider } from "react-router";
6+
import {
7+
createBrowserRouter,
8+
Link,
9+
RouterProvider,
10+
useNavigate,
11+
} from "react-router";
712
import App from "./App";
813
import Layout from "./layouts/dashboard";
914
import DashboardPage from "./pages";
1015
import EmployeesCrudPage from "./pages/employees";
16+
import ExternalRedirectPage from "./pages/external_redirect";
17+
import NotFoundPage from "./pages/not_found";
1118

1219
const router = createBrowserRouter([
1320
{
1421
Component: App,
22+
// errorElement: ErrorPage(),
23+
// ErrorBoundary: ErrorPage,
1524
children: [
1625
{
1726
path: "/",
1827
Component: Layout,
28+
// ErrorBoundary: ErrorPage,
1929
children: [
2030
{
2131
path: "",
@@ -25,6 +35,14 @@ const router = createBrowserRouter([
2535
path: "employees/:employeeId?/*",
2636
Component: EmployeesCrudPage,
2737
},
38+
{
39+
path: "external/:redirectLink?",
40+
Component: ExternalRedirectPage,
41+
},
42+
{
43+
path: "*",
44+
Component: NotFoundPage,
45+
},
2846
],
2947
},
3048
],

src/pages/external_redirect.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-FileCopyrightText: 2025 Sidings Media <contact@sidingsmedia.com>
2+
// SPDX-License-Identifier: MIT
3+
4+
import * as React from "react";
5+
import { useNavigate, useParams } from "react-router";
6+
import { PageContainer } from "@toolpad/core/PageContainer";
7+
8+
export default function ExternalRedirectPage() {
9+
const { redirectLink } = useParams();
10+
const navigate = useNavigate();
11+
12+
const [message, setMessage] = React.useState<React.JSX.Element>();
13+
14+
const links = JSON.parse(import.meta.env.VITE_EXTERNAL_SIDEBAR_LINKS) as {
15+
title: string;
16+
href: string;
17+
}[];
18+
19+
React.useEffect(() => {
20+
let href = decodeURIComponent(redirectLink ?? "");
21+
if (links.filter(({ href }) => href === href).length != 0) {
22+
// URL is valid
23+
window.open(href, "_blank");
24+
setMessage(
25+
<p>
26+
Redirecting to{" "}
27+
<a href={href} target="_blank" rel="noreferrer">
28+
{href}
29+
</a>
30+
{". "}
31+
If you are not automatically redirected in a moment, please click the
32+
link.
33+
</p>,
34+
);
35+
console.log(location.href);
36+
} else {
37+
setMessage(<p>The redirect link is not valid.</p>);
38+
}
39+
}, [redirectLink]);
40+
41+
return <PageContainer>{message}</PageContainer>;
42+
}

src/pages/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { PageContainer } from "@toolpad/core/PageContainer";
88
export default function HomePage() {
99
return (
1010
<PageContainer>
11-
<Typography>Welcome to Toolpad Core!</Typography>
11+
<Typography>
12+
Welcome to Unified Control! Use the sidebar to perform operations.
13+
</Typography>
1214
</PageContainer>
1315
);
1416
}

src/pages/not_found.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-FileCopyrightText: 2025 Sidings Media <contact@sidingsmedia.com>
2+
// SPDX-License-Identifier: MIT
3+
4+
import * as React from "react";
5+
import Typography from "@mui/material/Typography";
6+
import { PageContainer } from "@toolpad/core/PageContainer";
7+
8+
export default function NotFoundPage() {
9+
return (
10+
<PageContainer title="Not Found">
11+
<Typography>Sorry, this page doesn't seem to exist...</Typography>
12+
</PageContainer>
13+
);
14+
}

0 commit comments

Comments
 (0)