import React from 'react'; import { SideMenuitem } from 'UI'; import { connect } from 'react-redux'; import { setActiveTab } from 'Duck/search'; import { withRouter, RouteComponentProps } from 'react-router-dom'; import { sessions, fflags, withSiteId, notes } from "App/routes"; interface Props { setActiveTab: (tab: any) => void; activeTab: string; isEnterprise: boolean; } const TabToUrlMap = { all: sessions() as '/sessions', bookmark: sessions() as '/sessions', notes: notes() as '/notes', flags: fflags() as '/feature-flags', } function OverviewMenu(props: Props & RouteComponentProps) { // @ts-ignore const { activeTab, isEnterprise, history, match: { params: { siteId } }, location } = props; React.useEffect(() => { const currentLocation = location.pathname; const tab = Object.keys(TabToUrlMap).find((tab: keyof typeof TabToUrlMap) => currentLocation.includes(TabToUrlMap[tab])); if (tab && tab !== activeTab) { props.setActiveTab({ type: tab }) } }, [location.pathname]) return (
{ props.setActiveTab({ type: 'all' }) !location.pathname.includes(sessions()) && history.push(withSiteId(sessions(), siteId)) }} />
{ props.setActiveTab({ type: 'bookmark' }) !location.pathname.includes(sessions()) && history.push(withSiteId(sessions(), siteId)) }} />
{ props.setActiveTab({ type: 'notes' }) !location.pathname.includes(notes()) && history.push(withSiteId(notes(), siteId)) }} />
{ props.setActiveTab({ type: 'flags' }) !location.pathname.includes(fflags()) && history.push(withSiteId(fflags(), siteId)) }} />
); } export default connect((state: any) => ({ activeTab: state.getIn(['search', 'activeTab', 'type']), isEnterprise: state.getIn(['user', 'account', 'edition']) === 'ee', }), { setActiveTab })(withRouter(OverviewMenu));