import { CheckCircleTwoTone, WarningOutlined } from '@ant-design/icons'; import { Menu, Space, Typography } from 'antd'; import getLocalStorageKey from 'api/browser/localstorage/get'; import { IS_SIDEBAR_COLLAPSED } from 'constants/app'; import ROUTES from 'constants/routes'; import history from 'lib/history'; import React, { useCallback, useLayoutEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import { useLocation } from 'react-router-dom'; import { SideBarCollapse } from 'store/actions/app'; import { AppState } from 'store/reducers'; import AppReducer from 'types/reducer/app'; import { styles } from './config'; import menus from './menuItems'; import Slack from './Slack'; import { RedDot, Sider, SlackButton, SlackMenuItemContainer, Tags, VersionContainer, } from './styles'; function SideNav(): JSX.Element { const dispatch = useDispatch(); const [collapsed, setCollapsed] = useState( getLocalStorageKey(IS_SIDEBAR_COLLAPSED) === 'true', ); const { currentVersion, latestVersion, isCurrentVersionError } = useSelector< AppState, AppReducer >((state) => state.app); const { pathname } = useLocation(); const { t } = useTranslation(''); const onCollapse = useCallback(() => { setCollapsed((collapsed) => !collapsed); }, []); useLayoutEffect(() => { dispatch(SideBarCollapse(collapsed)); }, [collapsed, dispatch]); const onClickHandler = useCallback( (to: string) => { if (pathname !== to) { history.push(`${to}`); } }, [pathname], ); const onClickSlackHandler = (): void => { window.open('https://signoz.io/slack', '_blank'); }; const onClickVersionHandler = (): void => { history.push(ROUTES.VERSION); }; const isNotCurrentVersion = currentVersion !== latestVersion; const sidebar: SidebarItem[] = [ { onClick: onClickSlackHandler, icon: , text: Support, key: 'slack', }, { onClick: onClickVersionHandler, key: 'version', icon: isNotCurrentVersion ? ( ) : ( ), text: ( {!isCurrentVersionError ? ( {currentVersion} ) : ( {t('n_a')} )} {isNotCurrentVersion && } ), }, ]; const currentMenu = useMemo( () => menus.find((menu) => pathname.startsWith(menu.to)), [pathname], ); const items = [ ...menus.map(({ to, Icon, name, tags, children }) => ({ key: to, icon: , onClick: (): void => onClickHandler(to), label: (
{name}
{tags && tags.map((e) => ( {e} ))}
), children, })), ]; const sidebarItems = (props: SidebarItem, index: number): SidebarItem => ({ key: `${index}`, icon: props.icon, onClick: props.onClick, label: props.text, }); return ( {sidebar.map((props, index) => ( ))} ); } interface SidebarItem { onClick: VoidFunction; icon?: React.ReactNode; text?: React.ReactNode; key: string; label?: React.ReactNode; } export default SideNav;