import React, { useCallback } from "react"; import { useLargeLayout, useNavigationController } from "../hooks"; import { useNavigate } from "react-router-dom"; import { CMSAnalyticsEvent, TopNavigationEntry, TopNavigationResult } from "../types"; import { IconForView } from "../util"; import { cn, IconButton, Menu, MenuItem, MoreVertIcon, Tooltip, Typography } from "@firecms/ui"; import { useAnalyticsController } from "../hooks/useAnalyticsController"; import { useDrawer } from "./Scaffold"; import { DrawerNavigationItem } from "./DrawerNavigationItem"; /** * Props used in case you need to override the default drawer * @group Core */ export type DrawerProps = { hovered: boolean, drawerOpen: boolean, openDrawer: () => void, closeDrawer: () => void, autoOpenDrawer?: boolean } /** * Default drawer used in the CMS * @group Core */ export function Drawer() { const { hovered, drawerOpen, closeDrawer, } = useDrawer(); const analyticsController = useAnalyticsController(); const navigation = useNavigationController(); const tooltipsOpen = hovered && !drawerOpen; const largeLayout = useLargeLayout(); const navigate = useNavigate(); const [adminMenuOpen, setAdminMenuOpen] = React.useState(false); if (!navigation.topLevelNavigation) throw Error("Navigation not ready in Drawer"); const { navigationEntries, groups }: TopNavigationResult = navigation.topLevelNavigation; const adminViews = navigationEntries.filter(e => e.type === "admin") ?? []; const groupsWithoutAdmin = groups.filter(g => g !== "Admin"); const buildGroupHeader = useCallback((group?: string) => { if (!drawerOpen) return
; return