import { Icon, List, ListItemButton, ListItemIcon, ListItemText, styled, Typography, } from '@mui/material'; import { Link } from 'react-router-dom'; import { IconRenderer, StyledProjectIcon, } from 'component/layout/MainLayout/NavigationSidebar/IconRenderer'; import type { LastViewedPage } from 'hooks/useRecentlyVisited'; import type { Theme } from '@mui/material/styles/createTheme'; import useProjectOverview from 'hooks/api/getters/useProjectOverview/useProjectOverview'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; const listItemButtonStyle = (theme: Theme) => ({ border: `1px solid transparent`, borderLeft: `${theme.spacing(0.5)} solid transparent`, '&:hover': { border: `1px solid ${theme.palette.primary.main}`, borderLeft: `${theme.spacing(0.5)} solid ${theme.palette.primary.main}`, }, }); const StyledContainer = styled('div')(({ theme }) => ({ marginBottom: theme.spacing(3), })); const StyledButtonTypography = styled(Typography)(({ theme }) => ({ fontSize: theme.fontSizes.smallerBody, })); const ColoredStyledProjectIcon = styled(StyledProjectIcon)(({ theme }) => ({ fill: theme.palette.primary.main, stroke: theme.palette.primary.main, })); const StyledTypography = styled(Typography)(({ theme }) => ({ fontSize: theme.fontSizes.smallBody, padding: theme.spacing(0, 2.5), })); const StyledListItemIcon = styled(ListItemIcon)(({ theme }) => ({ minWidth: theme.spacing(0.5), margin: theme.spacing(0, 1, 0, 0), color: theme.palette.primary.main, })); const StyledListItemText = styled(ListItemText)(({ theme }) => ({ margin: 0, fontSize: theme.fontSizes.smallBody, })); const toListItemButton = ( item: LastViewedPage, routes: Record, index: number, ) => { const key = `recently-visited-${index}`; if (item.featureId && item.projectId) { return ( ); } if (item.projectId) { return ( ); } if (!item.pathName) return null; const name = routes[item.pathName]?.title ?? item.pathName; return ( ); }; const RecentlyVisitedFeatureButton = ({ key, projectId, featureId, }: { key: string; projectId: string; featureId: string }) => { const { trackEvent } = usePlausibleTracker(); const onClick = () => { trackEvent('command-bar', { props: { eventType: `click`, source: 'recently-visited', eventTarget: 'Flags', }, }); }; return ( {'flag'} {featureId} ); }; const RecentlyVisitedPathButton = ({ path, key, name, }: { path: string; key: string; name: string }) => { const { trackEvent } = usePlausibleTracker(); const onClick = () => { trackEvent('command-bar', { props: { eventType: `click`, source: 'recently-visited', eventTarget: 'Pages', pageType: name, }, }); }; return ( ({ color: theme.palette.primary.main })} > } elseShow={} /> {name} ); }; const RecentlyVisitedProjectButton = ({ projectId, key, }: { projectId: string; key: string }) => { const { trackEvent } = usePlausibleTracker(); const { project, loading } = useProjectOverview(projectId); const projectDeleted = !project.name && !loading; const onClick = () => { trackEvent('command-bar', { props: { eventType: `click`, source: 'recently-visited', eventTarget: 'Projects', }, }); }; if (projectDeleted) return null; return ( {project.name} ); }; export const CommandRecent = ({ lastVisited, routes, }: { lastVisited: LastViewedPage[]; routes: Record; }) => { const buttons = lastVisited.map((item, index) => toListItemButton(item, routes, index), ); return ( Recently visited {buttons} ); };