import { useLocation, useNavigate } from '@tanstack/react-router' import { LOCAL_STORAGE_KEYS, useFlag, useIsMFAEnabled, useMountEffect, useParams } from 'common' import { Home } from 'icons' import { isUndefined } from 'lodash' import { BlocksIcon, BoxesIcon, ChartAreaIcon, PanelLeftDashedIcon, ReceiptIcon, SettingsIcon, UsersIcon, } from 'lucide-react' import { AnimatePresence, motion, MotionProps } from 'motion/react' import { ComponentProps, ComponentPropsWithoutRef, FC, ReactNode, useEffect } from 'react' import { Badge, Button, cn, DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, Separator, SidebarContent as SidebarContentPrimitive, SidebarFooter, SidebarGroup, SidebarMenu, SidebarMenuButton, SidebarMenuItem, Sidebar as SidebarPrimitive, useSidebar, } from 'ui' import { Shortcut } from '../ui/Shortcut' import { Route } from '../ui/ui.types' import { generateProductRoutes, generateSettingsRoutes, useGenerateOtherRoutes, useGenerateToolRoutes, } from '@/components/layouts/Navigation/NavigationBar/NavigationBar.utils' import { ORG_SETTINGS_ROUTES } from '@/components/layouts/OrganizationLayout/OrganizationLayout.utils' import { DynamicLink } from '@/components/ui/DynamicLink' import { ProjectIndexPageLink } from '@/data/prefetchers/project.$ref' import { useHideSidebar } from '@/hooks/misc/useHideSidebar' import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' import { useLints } from '@/hooks/misc/useLints' import { useLocalStorage, useLocalStorageQuery } from '@/hooks/misc/useLocalStorage' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { navigateToUrl } from '@/lib/navigation' import { useTrack } from '@/lib/telemetry/track' import { SHORTCUT_IDS } from '@/state/shortcuts/registry' export const ICON_SIZE = 32 export const ICON_STROKE_WIDTH = 1.5 export type SidebarBehaviourType = 'expandable' | 'open' | 'closed' export const DEFAULT_SIDEBAR_BEHAVIOR = 'expandable' const SidebarMotion = motion.create(SidebarPrimitive) as FC< ComponentProps & { transition?: MotionProps['transition'] } > export interface SidebarProps extends ComponentPropsWithoutRef {} export const Sidebar = ({ className, ...props }: SidebarProps) => { const { setOpen } = useSidebar() const hideSideBar = useHideSidebar() // useLocalStorageQuery returns data after the first render, so seed it with the stored value const [storedBehavior] = useLocalStorage( LOCAL_STORAGE_KEYS.SIDEBAR_BEHAVIOR, DEFAULT_SIDEBAR_BEHAVIOR ) const [sidebarBehaviour, setSidebarBehaviour] = useLocalStorageQuery( LOCAL_STORAGE_KEYS.SIDEBAR_BEHAVIOR, storedBehavior ) // account pages keep the provider but not this component, so a hover-expand choice made there must close it here useMountEffect(() => { if (sidebarBehaviour === 'expandable') setOpen(false) }) useEffect(() => { // logic to toggle sidebar open based on sidebarBehaviour state if (sidebarBehaviour === 'open') setOpen(true) if (sidebarBehaviour === 'closed') setOpen(false) }, [sidebarBehaviour, setOpen]) return ( {!hideSideBar && ( { if (sidebarBehaviour === 'expandable') setOpen(true) }} onMouseLeave={() => { if (sidebarBehaviour === 'expandable') setOpen(false) }} >