Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#60 create sidebar navigation #141

Merged
merged 16 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Explorer/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"parser": "@typescript-eslint/parser",
"root": true,
"rules": {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-namespace": [
2,
{
Expand Down
2 changes: 1 addition & 1 deletion Explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"react-dom": "18.2.0",
"swr": "^2.1.5",
"tailwindcss": "3.3.2",
"typescript": "5.1.3"
"typescript": "5.0.4"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
Expand Down
Empty file modified Explorer/postcss.config.js
100755 → 100644
Empty file.
10 changes: 10 additions & 0 deletions Explorer/src/app/cluster/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { H1 } from "@/components/style_elements";

/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
return (
<div className="p-6">
<H1 content={"Cluster"} />
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function Index({
params: { id: string };
/* @ts-expect-error Async Server Component */
}): JSX.Element {
const data = await getContainerDetails(parseInt(params.id));
const data = await getContainerDetails(decodeURIComponent(params.id));
return (
<div className="p-6">
<ContainerDetailPage container_details={data} />
Expand Down
15 changes: 15 additions & 0 deletions Explorer/src/app/containers/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ContainerTable from "@/components/containerTable";
import { getContainerList } from "@/lib/db";
import { H1 } from "@/components/style_elements";

export const dynamic = "force-dynamic";
/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
const data = await getContainerList();
return (
<div className="container mx-auto px-4">
<H1 content={"Containers"} />
<ContainerTable list={data} />
</div>
);
}
10 changes: 10 additions & 0 deletions Explorer/src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { H1 } from "@/components/style_elements";

/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
return (
<div className="p-6">
<H1 content={"Dashboard"} />
</div>
);
}
10 changes: 10 additions & 0 deletions Explorer/src/app/deployments/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { H1 } from "@/components/style_elements";

/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
return (
<div className="p-6">
<H1 content={"Deployments"} />
</div>
);
}
26 changes: 25 additions & 1 deletion Explorer/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
"use client";

import "@/styles/globals.css";
import { Header } from "@/components/header";
import { SidebarProvider } from "@/context/sidebar_context";
import { ActualSidebar } from "@/components/sidebar";
import { Flowbite } from "flowbite-react";

export default function RootLayout({
children,
Expand All @@ -7,7 +13,25 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<body>{children}</body>
<body>
<Flowbite>
<SidebarProvider>
<div className="flex dark:bg-gray-900 h-screen">
<div className="order-1 float-left bg-black">
<ActualSidebar />
</div>
<main className="order-2 w-full overflow-x-hidden">
<div className="float-left w-full">
<Header />
</div>
<div className="float-left w-full">
<div className="mx-4 mt-4 mb-24">{children}</div>
</div>
</main>
</div>
</SidebarProvider>
</Flowbite>
</body>
</html>
);
}
10 changes: 10 additions & 0 deletions Explorer/src/app/nodes/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { H1 } from "@/components/style_elements";

/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
return (
<div className="p-6">
<H1 content={"Nodes"} />
</div>
);
}
10 changes: 10 additions & 0 deletions Explorer/src/app/pods/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { H1 } from "@/components/style_elements";

/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
return (
<div className="p-6">
<H1 content={"Pods"} />
</div>
);
}
10 changes: 10 additions & 0 deletions Explorer/src/app/services/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { H1 } from "@/components/style_elements";

/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
return (
<div className="p-6">
<H1 content={"Services"} />
</div>
);
}
10 changes: 10 additions & 0 deletions Explorer/src/app/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { H1 } from "@/components/style_elements";

/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
return (
<div className="p-6">
<H1 content={"Settings"} />
</div>
);
}
10 changes: 10 additions & 0 deletions Explorer/src/app/volumes/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { H1 } from "@/components/style_elements";

/* @ts-expect-error Async Server Component */
export default async function Index(): JSX.Element {
return (
<div className="p-6">
<H1 content={"Volumes"} />
</div>
);
}
4 changes: 3 additions & 1 deletion Explorer/src/components/containerTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default function ContainerTable({
<Table.Row key={index}>
<Table.Cell className="whitespace-normal font-medium text-gray-900 dark:text-white">
<a
href={`/container/${container.container_id}`}
href={`/containers/${encodeURIComponent(
container.container_id
)}`}
className="text-decoration-none text-blue-800"
id="list"
>
Expand Down
62 changes: 62 additions & 0 deletions Explorer/src/components/header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use client";

import { DarkThemeToggle, Navbar } from "flowbite-react";
import { FC } from "react";
import { useSidebarContext } from "@/context/sidebar_context";

export const Header: FC<Record<string, never>> = function () {
const { isOpenOnSmallScreens, isPageWithSidebar, setOpenOnSmallScreens } =
useSidebarContext();

return (
<header className="sticky top-0 z-20">
<Navbar fluid className="bg-slate-200">
{isPageWithSidebar && (
<button
aria-controls="sidebar"
aria-expanded="true"
className="mr-2 cursor-pointer p-2 text-gray-600 hover:bg-gray-100 hover:text-gray-900 focus:bg-gray-100 focus:ring-2 focus:ring-gray-100 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:bg-gray-700 dark:focus:ring-gray-700 lg:hidden"
onClick={() => setOpenOnSmallScreens(!isOpenOnSmallScreens)}
>
{isOpenOnSmallScreens ? (
<svg
className="h-6 w-6"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clipRule="evenodd"
></path>
</svg>
) : (
<svg
className="h-6 w-6"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h6a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z"
clipRule="evenodd"
></path>
</svg>
)}
</button>
)}
<Navbar.Brand>
<span className="self-center whitespace-nowrap px-3 text-xl font-semibold dark:text-white">
Todo/Implement/Current/Path
</span>
</Navbar.Brand>
<div className="flex md:order-2">
<Navbar.Toggle />
<DarkThemeToggle />
</div>
</Navbar>
</header>
);
};
120 changes: 120 additions & 0 deletions Explorer/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"use client";

import classNames from "classnames";
import { Sidebar as FlowbiteSidebar } from "flowbite-react";
import type { FC, PropsWithChildren } from "react";
import { useSidebarContext } from "@/context/sidebar_context";
import {
HiPresentationChartLine,
HiCog,
HiFolder,
HiServer,
HiTemplate,
HiChip,
HiTable,
HiHome,
} from "react-icons/hi";

const Sidebar: FC<PropsWithChildren<Record<string, unknown>>> = function ({
children,
}) {
const { isOpenOnSmallScreens: isSidebarOpenOnSmallScreens } =
useSidebarContext();

return (
<div
className={classNames(
"fixed overflow-auto top-0 h-screen z-10 lg:sticky lg:!block",
{
hidden: !isSidebarOpenOnSmallScreens,
}
)}
>
<FlowbiteSidebar>{children}</FlowbiteSidebar>
</div>
);
};

export default Object.assign(Sidebar, { ...FlowbiteSidebar });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I wish we had a comment on this line


import { usePathname } from "next/navigation";

export function ActualSidebar(): JSX.Element {
const pathname = usePathname();
const splitPathname = pathname.split("/");
const current_page = splitPathname[1];

return (
<FlowbiteSidebar>
<FlowbiteSidebar.Items>
<FlowbiteSidebar.ItemGroup>
<FlowbiteSidebar.Item
href="dashboard"
icon={HiPresentationChartLine}
active={current_page.localeCompare("dashboard") ? false : true}
njochens marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't like this use of the ternary.
Isn't this equivalent to this line?

Suggested change
active={current_page.localeCompare("dashboard") ? false : true}
active={current_page === "dashboard"}

>
Dashboard
</FlowbiteSidebar.Item>
<FlowbiteSidebar.Item
href="cluster"
icon={HiHome}
active={current_page.localeCompare("cluster") ? false : true}
>
Cluster
</FlowbiteSidebar.Item>
<FlowbiteSidebar.Item
href="deployments"
icon={HiTemplate}
active={current_page.localeCompare("deployments") ? false : true}
>
Deployments
</FlowbiteSidebar.Item>
<FlowbiteSidebar.Item
href="nodes"
icon={HiTemplate}
active={current_page.localeCompare("nodes") ? false : true}
>
Nodes
</FlowbiteSidebar.Item>
<FlowbiteSidebar.Item
href="pods"
icon={HiTable}
active={current_page.localeCompare("pods") ? false : true}
>
Pods
</FlowbiteSidebar.Item>
<FlowbiteSidebar.Item
href="containers"
icon={HiFolder}
active={current_page.localeCompare("containers") ? false : true}
>
Containers
</FlowbiteSidebar.Item>
<FlowbiteSidebar.Item
href="volumes"
icon={HiServer}
active={current_page.localeCompare("volumes") ? false : true}
>
Volumes
</FlowbiteSidebar.Item>
<FlowbiteSidebar.Item
href="services"
icon={HiChip}
active={current_page.localeCompare("services") ? false : true}
>
Services
</FlowbiteSidebar.Item>
</FlowbiteSidebar.ItemGroup>
<FlowbiteSidebar.ItemGroup>
<FlowbiteSidebar.Item
href="settings"
icon={HiCog}
active={current_page.localeCompare("settings") ? false : true}
>
Settings
</FlowbiteSidebar.Item>
</FlowbiteSidebar.ItemGroup>
</FlowbiteSidebar.Items>
</FlowbiteSidebar>
);
}
1 change: 1 addition & 0 deletions Explorer/src/components/style_elements.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use client";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function H1({ content }: any): JSX.Element {
return (
Expand Down
Loading