import { useCurrentStateAndParams, useSrefActive } from '@uirouter/react'; import React from 'react'; import { useRecoilState } from 'recoil'; import { Icon } from '@spinnaker/presentation'; import { verticalNavExpandedAtom } from '../application/nav/navAtoms'; import { UserMenu } from '../authentication/userMenu/UserMenu'; import { CollapsibleSectionStateCache } from '../cache'; import { HelpMenu } from '../help/HelpMenu'; import { overridableComponent } from '../overrideRegistry'; import { GlobalSearch } from '../search/global/GlobalSearch'; import { logger } from '../utils'; import './SpinnakerHeader.css'; const LOG_CATEGORY = 'Navbar'; export const SpinnakerHeaderContent = () => { const { state: currentState } = useCurrentStateAndParams(); const isApplicationView = currentState.name.includes('project.application.') || currentState.name.includes('applications.application.'); const [verticalNavExpanded, setVerticalNavExpanded] = useRecoilState(verticalNavExpandedAtom); const toggleNav = () => { setVerticalNavExpanded(!verticalNavExpanded); CollapsibleSectionStateCache.setExpanded('verticalNav', !verticalNavExpanded); logger.log({ category: LOG_CATEGORY, action: !verticalNavExpanded ? 'ExpandVerticalNav' : 'CollapseVerticalNav' }); }; const isDevicePhoneOrSmaller = () => { const bodyStyles = window.getComputedStyle(document.body); const isPhone = bodyStyles.getPropertyValue('--is-phone'); return isPhone.toLowerCase() === 'true'; }; const [navExpanded] = React.useState(!isDevicePhoneOrSmaller()); const searchSref = useSrefActive('home.infrastructure', null, 'active'); const projectsSref = useSrefActive('home.projects', null, 'active'); const appsSref = useSrefActive('home.applications', null, 'active'); const templatesSref = useSrefActive('home.pipeline-templates', null, 'active'); const navItems = [ { key: 'navHome', text: 'Search', srefProps: searchSref, }, { key: 'navProjects', text: 'Projects', srefProps: projectsSref, }, { key: 'navApplications', text: 'Applications', srefProps: appsSref, }, { key: 'navPipelineTemplates', text: 'Pipeline Templates', srefProps: templatesSref, }, ]; return ( ); }; export const SpinnakerHeader = overridableComponent(SpinnakerHeaderContent, 'spinnakerHeader');