Astra: PO/GL actions, usage coverage, assisted sign-in, self-healing, recorder, new top navigation and theme (172a4e22a2bf)
fb62a97 verified Download web/src/components/shell/TopNav.tsx from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 4.88 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/shell/TopNav.tsx
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/components/shell/TopNav.tsx
-
curl -L -o TopNav.tsx https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/shell/TopNav.tsx
4.88 kB
| import './topnav.css'; | |
| import { Menu, useComputedColorScheme, useMantineColorScheme } from '@mantine/core'; | |
| import { IconChevronDown, IconHandStop, IconMenu2, IconMoon, IconSearch, IconSun } from '@/components/icons'; | |
| import { Link, NavLink as RouterLink, useLocation, useNavigate } from 'react-router-dom'; | |
| import { useBrand, useKill, useRuns } from '../../api/hooks'; | |
| import { useAuth } from '../../auth/AuthContext'; | |
| import { NotificationBell } from '../../notify/NotificationBell'; | |
| import { useWaitsOnMe } from '../../domain/waiting'; | |
| import { AccountMenu, AGENT_STUDIO, AI_MONITORING, INTEGRATIONS, LIBRARY, MAIN, SETTINGS, SETUP, type NavItem } from './AppSidebar'; | |
| import { EnvSwitcher } from './EnvSwitcher'; | |
| import { useShell } from './prefs'; | |
| import { isMac } from './TopBar'; | |
| const isActive = (item: NavItem, path: string) => (item.match ? item.match(path) : path === item.to || path.startsWith(`${item.to}/`)); | |
| /** The app's navigation: brand at left, main pages across the center, and environment and account tools at right. | |
| * Setup and admin pages are grouped under More; phones keep the menu drawer. */ | |
| export function TopNav() { | |
| const { can } = useAuth(); | |
| const loc = useLocation(); | |
| const nav = useNavigate(); | |
| const brand = useBrand(); | |
| const runs = useRuns(40, 0); | |
| const mine = useWaitsOnMe(); | |
| const kill = useKill(); | |
| const { size, openNav, openPalette } = useShell(); | |
| const { setColorScheme } = useMantineColorScheme(); | |
| const scheme = useComputedColorScheme('dark'); | |
| const dark = scheme === 'dark'; | |
| const waiting = (runs.data?.items ?? []).filter(mine).length; | |
| const name = brand.data?.product_name ?? 'Astra'; | |
| const phone = size === 'phone'; | |
| const main = [...MAIN.filter((i) => i.to !== '/assistant'), ...LIBRARY, ...MAIN.filter((i) => i.to === '/assistant')]; | |
| const more = [...SETUP, ...(can('admin') ? [AGENT_STUDIO, AI_MONITORING, INTEGRATIONS, SETTINGS] : [])]; | |
| const moreActive = more.find((i) => isActive(i, loc.pathname)); | |
| return ( | |
| <header className="pw-nav" aria-label="Main navigation" data-size={size}> | |
| {phone && <button type="button" className="pw-nav-menu" aria-label="Open the menu" onClick={openNav}><IconMenu2 size={19} aria-hidden /></button>} | |
| <Link to="/" className="pw-nav-brand" aria-label={`${name} home`} data-testid="brand"> | |
| <img className="astra-logo" src="/astra-logo.png" alt="" height={28} /> | |
| <span className="pw-nav-name"><b className="astra-wordmark">{name}</b></span> | |
| </Link> | |
| <nav className="pw-nav-pill" aria-label="Pages"> | |
| {main.map((it) => { | |
| const active = isActive(it, loc.pathname); | |
| const badge = it.to === '/runs' ? waiting : 0; | |
| return ( | |
| <RouterLink key={it.to} to={it.to} className="pw-nav-item" data-active={active || undefined} aria-current={active ? 'page' : undefined} | |
| aria-label={badge ? `${it.label}, ${badge} waiting for you` : it.label}> | |
| {it.icon}<span>{it.to === '/runs' ? 'Runs' : it.label}</span> | |
| {badge > 0 && <span className="pw-nav-badge" aria-hidden>{badge > 9 ? '9+' : badge}</span>} | |
| </RouterLink> | |
| ); | |
| })} | |
| {more.length > 0 && ( | |
| <Menu position="bottom-end" width={230} withinPortal> | |
| <Menu.Target> | |
| <button type="button" className="pw-nav-item" data-active={!!moreActive || undefined} aria-label={moreActive ? `More: ${moreActive.label}` : 'More pages'}> | |
| {moreActive?.icon}<span>{moreActive ? moreActive.label : 'More'}</span><IconChevronDown size={13} aria-hidden /> | |
| </button> | |
| </Menu.Target> | |
| <Menu.Dropdown> | |
| {more.map((it) => <Menu.Item key={it.to} leftSection={it.icon} onClick={() => nav(it.to)}>{it.label}</Menu.Item>)} | |
| </Menu.Dropdown> | |
| </Menu> | |
| )} | |
| </nav> | |
| <div className="pw-nav-right"> | |
| {kill.data?.engaged && <span className="pw-nav-warn" role="status" data-testid="kill-indicator" aria-label="Emergency stop is on"><IconHandStop size={16} aria-hidden />Stopped</span>} | |
| <EnvSwitcher iconOnly className="pw-nav-env" /> | |
| <button type="button" className="pw-nav-icon" data-tool="search" onClick={openPalette} aria-label={`Search or ask ${isMac() ? '⌘K' : 'Ctrl K'}`} title="Search, go to a page or ask a question"> | |
| <IconSearch size={17} aria-hidden /> | |
| </button> | |
| <button type="button" className="pw-nav-icon" data-tool="theme" onClick={() => setColorScheme(dark ? 'light' : 'dark')} | |
| aria-label={dark ? 'Switch to light mode' : 'Switch to dark mode'} title={dark ? 'Light mode' : 'Dark mode'}> | |
| {dark ? <IconSun size={17} aria-hidden /> : <IconMoon size={17} aria-hidden />} | |
| </button> | |
| <NotificationBell /> | |
| <AccountMenu compact /> | |
| </div> | |
| </header> | |
| ); | |
| } | |