mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-22 03:14:21 +00:00
* fix: add suppressHydrationWarning to resolve console errors * chore: add server-only library * WIP: Mock API for providers and start rendering data * chore: relocate utils folder to proper directory * chore: install shadcn for tables, adding sttings page * refactor: improve sidebar display behavior * chore: add fake data to the dataProviders * chore: remove the old table and rename ProviderInfo component * refactor: improve sidebar display behavior adding a custom hook * feat: the Providers table is rendering real data * chore: set the default valuef or isCollapse to false * chore: Added a helper function getProviderAttributes for cleaner access to provider attributes
204 lines
5.5 KiB
TypeScript
204 lines
5.5 KiB
TypeScript
"use client";
|
|
|
|
import { Icon } from "@iconify/react";
|
|
import { Button, ScrollShadow, Spacer, Tooltip } from "@nextui-org/react";
|
|
import clsx from "clsx";
|
|
import { usePathname } from "next/navigation";
|
|
import React, { useCallback } from "react";
|
|
import { useMediaQuery } from "usehooks-ts";
|
|
|
|
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
|
|
|
import {
|
|
ProwlerExtended,
|
|
ProwlerShort,
|
|
} from "../../icons/prowler/ProwlerIcons";
|
|
import { ThemeSwitch } from "../../ThemeSwitch";
|
|
import Sidebar from "./Sidebar";
|
|
import { sectionItemsWithTeams } from "./SidebarItems";
|
|
import { UserAvatar } from "./UserAvatar";
|
|
|
|
export const SidebarWrap = () => {
|
|
const pathname = usePathname();
|
|
const [isCollapsed, setIsCollapsed] = useLocalStorage("isCollapsed", false);
|
|
|
|
const isMobile = useMediaQuery("(max-width: 768px)");
|
|
|
|
const isCompact = Boolean(isCollapsed) || isMobile;
|
|
|
|
const onToggle = useCallback(() => {
|
|
setIsCollapsed(!isCollapsed);
|
|
}, [isCollapsed]);
|
|
|
|
const currentPath = pathname === "/" ? "overview" : pathname.split("/")?.[1];
|
|
|
|
return (
|
|
<div
|
|
className={clsx(
|
|
"relative flex h-screen flex-col !border-r-small border-divider transition-width",
|
|
{
|
|
"w-72 p-6": !isCompact,
|
|
"w-16 items-center px-2 py-6": isCompact,
|
|
},
|
|
)}
|
|
>
|
|
<div
|
|
className={clsx("flex items-center gap-3 px-3 justify-center", {
|
|
"gap-0": isCompact,
|
|
})}
|
|
>
|
|
<div
|
|
className={clsx({
|
|
hidden: !isCompact,
|
|
})}
|
|
>
|
|
<ProwlerShort />
|
|
</div>
|
|
<div
|
|
className={clsx({
|
|
hidden: isCompact,
|
|
})}
|
|
>
|
|
<ProwlerExtended />
|
|
</div>
|
|
</div>
|
|
<Spacer y={8} />
|
|
|
|
<UserAvatar
|
|
userName={"User name"}
|
|
position={"Software Engineer"}
|
|
isCompact={isCompact}
|
|
/>
|
|
|
|
<ScrollShadow className="-mr-6 h-full max-h-full py-6 pr-6">
|
|
<Sidebar
|
|
defaultSelectedKey="overview"
|
|
isCompact={isCompact}
|
|
items={sectionItemsWithTeams}
|
|
selectedKeys={[currentPath]}
|
|
/>
|
|
</ScrollShadow>
|
|
<Spacer y={2} />
|
|
<div
|
|
className={clsx("mt-auto flex flex-col", {
|
|
"items-center": isCompact,
|
|
})}
|
|
>
|
|
<Tooltip
|
|
content="Help & Feedback"
|
|
isDisabled={!isCompact}
|
|
placement="right"
|
|
>
|
|
<Button
|
|
fullWidth
|
|
className={clsx(
|
|
"justify-start truncate text-default-500 data-[hover=true]:text-foreground",
|
|
{
|
|
"justify-center": isCompact,
|
|
},
|
|
)}
|
|
isIconOnly={isCompact}
|
|
startContent={
|
|
isCompact ? null : (
|
|
<Icon
|
|
className="flex-none text-default-500"
|
|
icon="solar:info-circle-line-duotone"
|
|
width={24}
|
|
/>
|
|
)
|
|
}
|
|
variant="light"
|
|
>
|
|
{isCompact ? (
|
|
<Icon
|
|
className="text-default-500"
|
|
icon="solar:info-circle-line-duotone"
|
|
width={24}
|
|
/>
|
|
) : (
|
|
"Help & Information"
|
|
)}
|
|
</Button>
|
|
</Tooltip>
|
|
<Tooltip content="Log Out" isDisabled={!isCompact} placement="right">
|
|
<Button
|
|
className={clsx(
|
|
"justify-start text-default-500 data-[hover=true]:text-foreground",
|
|
{
|
|
"justify-center": isCompact,
|
|
},
|
|
)}
|
|
isIconOnly={isCompact}
|
|
startContent={
|
|
isCompact ? null : (
|
|
<Icon
|
|
className="flex-none rotate-180 text-default-500"
|
|
icon="solar:minus-circle-line-duotone"
|
|
width={24}
|
|
/>
|
|
)
|
|
}
|
|
variant="light"
|
|
>
|
|
{isCompact ? (
|
|
<Icon
|
|
className="rotate-180 text-default-500"
|
|
icon="solar:minus-circle-line-duotone"
|
|
width={24}
|
|
/>
|
|
) : (
|
|
"Log Out"
|
|
)}
|
|
</Button>
|
|
</Tooltip>
|
|
</div>
|
|
<div
|
|
className={clsx("mt-auto flex justify-end gap-3", {
|
|
" flex-col items-center ": isCompact,
|
|
" items-baseline ": !isCompact,
|
|
})}
|
|
>
|
|
<Tooltip
|
|
content="Light | Dark mode"
|
|
placement={isCompact ? "right" : "top"}
|
|
>
|
|
<div
|
|
className={clsx(
|
|
"text-default-500 data-[hover=true]:text-foreground px-0",
|
|
{
|
|
"justify-center mt-3": isCompact,
|
|
},
|
|
)}
|
|
>
|
|
<ThemeSwitch />
|
|
</div>
|
|
</Tooltip>
|
|
<Tooltip
|
|
content="Open | Close sidebar"
|
|
placement={isCompact ? "right" : "top"}
|
|
>
|
|
<Button
|
|
className={clsx(
|
|
"text-default-500 data-[hover=true]:text-foreground px-0",
|
|
{
|
|
"justify-center": isCompact,
|
|
},
|
|
)}
|
|
isIconOnly
|
|
size="sm"
|
|
variant="light"
|
|
onPress={onToggle}
|
|
>
|
|
<Icon
|
|
className="text-default-500"
|
|
height={24}
|
|
icon="solar:sidebar-minimalistic-outline"
|
|
width={24}
|
|
/>
|
|
</Button>
|
|
</Tooltip>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|