import React, { useMemo } from 'react';
import { faWindowMaximize } from '@fortawesome/free-regular-svg-icons';
import { faChartBar } from '@fortawesome/free-solid-svg-icons/faChartBar';
import { faColumns } from '@fortawesome/free-solid-svg-icons/faColumns';
import { faFileAlt } from '@fortawesome/free-solid-svg-icons/faFileAlt';
import { faCog } from '@fortawesome/free-solid-svg-icons/faCog';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons/faInfoCircle';
import { faSlack } from '@fortawesome/free-brands-svg-icons/faSlack';
import { faGithub } from '@fortawesome/free-brands-svg-icons/faGithub';
import { faChevronLeft } from '@fortawesome/free-solid-svg-icons/faChevronLeft';
import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons/faSignOutAlt';
import { faSync } from '@fortawesome/free-solid-svg-icons/faSync';
import { faSearch } from '@fortawesome/free-solid-svg-icons/faSearch';
import Sidebar, {
MenuItem,
SidebarHeader,
SidebarFooter,
SidebarContent,
SubMenu,
Menu,
} from '@webapp/ui/Sidebar';
import { useAppSelector, useAppDispatch } from '@webapp/redux/hooks';
import {
selectSidebarCollapsed,
collapseSidebar,
uncollapseSidebar,
recalculateSidebar,
} from '@webapp/redux/reducers/ui';
// import useColorMode from '@webapp/hooks/colorMode.hook';
import { useLocation, NavLink } from 'react-router-dom';
import {
isAdhocUIEnabled,
isAuthRequired,
isExemplarsPageEnabled,
} from '@webapp/util/features';
import Icon from '@webapp/ui/Icon';
import clsx from 'clsx';
import { useWindowWidth } from '@react-hook/window-size';
import {
AdhocIcon,
ExemplarsIcon,
MergeExemplarsIcon,
} from './SidebarCustomIcons';
import styles from './Sidebar.module.css';
import { PAGES } from '../pages/constants';
import { mountURL } from '../services/base';
function signOut() {
// By visiting /logout we're clearing jwtCookie
window.location.href = mountURL('/logout');
}
export function SidebarComponent() {
const collapsed = useAppSelector(selectSidebarCollapsed);
// const { changeColorMode, colorMode } = useColorMode();
const dispatch = useAppDispatch();
const { search, pathname } = useLocation();
const windowWidth = useWindowWidth();
const authEnabled = isAuthRequired;
// the component doesn't seem to support setting up an active item
// so we must set it up manually
// https://github.com/azouaoui-med/react-pro-sidebar/issues/84
const isRouteActive = (route: string) => {
if (
route === PAGES.CONTINOUS_SINGLE_VIEW ||
route === PAGES.COMPARISON_VIEW ||
route === PAGES.ADHOC_COMPARISON ||
route === PAGES.TRACING_EXEMPLARS_SINGLE ||
route === PAGES.TRACING_EXEMPLARS_MERGE
) {
return pathname === route;
}
return pathname.startsWith(route);
};
const isSidebarVisible = useMemo(
() =>
(
[
PAGES.CONTINOUS_SINGLE_VIEW,
PAGES.COMPARISON_VIEW,
PAGES.ADHOC_COMPARISON,
PAGES.COMPARISON_DIFF_VIEW,
PAGES.SETTINGS,
PAGES.SERVICE_DISCOVERY,
PAGES.ADHOC_SINGLE,
PAGES.ADHOC_COMPARISON,
PAGES.ADHOC_COMPARISON_DIFF,
PAGES.TAG_EXPLORER,
PAGES.TRACING_EXEMPLARS_MERGE,
PAGES.TRACING_EXEMPLARS_SINGLE,
] as string[]
).includes(pathname) || pathname.startsWith(PAGES.SETTINGS),
[pathname]
);
React.useLayoutEffect(() => {
dispatch(recalculateSidebar());
}, [windowWidth]);
// TODO
// simplify this
const isContinuousActive =
isRouteActive(PAGES.CONTINOUS_SINGLE_VIEW) ||
isRouteActive(PAGES.COMPARISON_VIEW) ||
isRouteActive(PAGES.COMPARISON_DIFF_VIEW) ||
isRouteActive(PAGES.TAG_EXPLORER);
const isAdhocActive =
isRouteActive(PAGES.ADHOC_SINGLE) ||
isRouteActive(PAGES.ADHOC_COMPARISON) ||
isRouteActive(PAGES.ADHOC_COMPARISON_DIFF);
const isTracingActive =
isRouteActive(PAGES.TRACING_EXEMPLARS_MERGE) ||
isRouteActive(PAGES.TRACING_EXEMPLARS_SINGLE);
const isSettingsActive = isRouteActive(PAGES.SETTINGS);
const adhoc = (
}
active={isAdhocActive}
defaultOpen={isAdhocActive}
data-testid="sidebar-adhoc"
>
{collapsed && (
Adhoc Profiling
)}
}
>
Single View
}
>
Comparison View
}
>
Diff View
);
const toggleCollapse = () => {
const action = collapsed ? uncollapseSidebar : collapseSidebar;
dispatch(action());
};
return isSidebarVisible ? (
{/* */}
) : null;
}
export default SidebarComponent;