Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(ui): bring back the sidebar Jan label on Windows and Linux (#9242)
James Damf89f039881db
diff --git a/web-app/src/components/left-sidebar/__tests__/headerLabel.test.tsx b/web-app/src/components/left-sidebar/__tests__/headerLabel.test.tsxnew file mode 100644index 000000000..cc470cdca--- /dev/null+++ b/web-app/src/components/left-sidebar/__tests__/headerLabel.test.tsx@@ -0,0 +1,76 @@+import '@testing-library/jest-dom/vitest'+import type { ReactNode } from 'react'+import { afterEach, beforeEach, expect, it, vi } from 'vitest'+import { render, screen } from '@testing-library/react'++const titlebar = vi.hoisted(() => ({ left: [] as string[] }))++vi.mock('@tanstack/react-router', () => ({+ useLocation: () => ({ pathname: '/' }),+ Link: ({ to, children, ...props }: { to: string; children: ReactNode }) => (+ <a {...props} href={to}>+ {children}+ </a>+ ),+}))+vi.mock('@/i18n/react-i18next-compat', () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}))+vi.mock('@/hooks/useLeftPanel', () => ({+ useLeftPanel: () => ({ open: true }),+}))+vi.mock('@/stores/titlebar-layout-store', () => ({+ useTitlebarLayout: (+ selector: (state: { layout: { left: string[]; right: string[] } }) => unknown+ ) => selector({ layout: { left: titlebar.left, right: [] } }),+}))+vi.mock('@/containers/DownloadManegement', () => ({+ DownloadManagement: () => null,+}))+vi.mock('../NavCowork', () => ({ NavCowork: () => null }))+vi.mock('../NavMain', () => ({ NavMain: () => null }))+vi.mock('../NavChats', () => ({ NavChats: () => null }))+vi.mock('../NavProjects', () => ({ NavProjects: () => null }))+vi.mock('../NavTabs', () => ({ NavTabs: () => null }))+vi.mock('@/components/ui/sidebar', () => {+ const Box = ({ children }: { children: ReactNode }) => <div>{children}</div>+ return {+ Sidebar: Box,+ SidebarContent: Box,+ SidebarHeader: Box,+ SidebarTrigger: () => null,+ SidebarRail: () => null,+ }+})++import { LeftSidebar } from '..'++beforeEach(() => {+ titlebar.left = []+ vi.stubGlobal('IS_MACOS', false)+})++afterEach(() => {+ vi.unstubAllGlobals()+})++it('shows the Jan label on Windows and Linux with window buttons on the right', () => {+ render(<LeftSidebar />)++ expect(screen.getByText('Jan')).toBeInTheDocument()+})++// The traffic lights own the top-left on macOS (#8943).+it('hides the Jan label on macOS', () => {+ vi.stubGlobal('IS_MACOS', true)+ render(<LeftSidebar />)++ expect(screen.queryByText('Jan')).not.toBeInTheDocument()+})++it('hides the Jan label when a Linux desktop puts window buttons on the left', () => {+ titlebar.left = ['close', 'minimize', 'maximize']+ render(<LeftSidebar />)++ expect(screen.queryByText('Jan')).not.toBeInTheDocument()+})diff --git a/web-app/src/components/left-sidebar/index.tsx b/web-app/src/components/left-sidebar/index.tsxindex 9155d62d9..79ebaf11c 100644--- a/web-app/src/components/left-sidebar/index.tsx+++ b/web-app/src/components/left-sidebar/index.tsx@@ -14,6 +14,8 @@ import {SidebarHeader,SidebarRail,} from '@/components/ui/sidebar'+import { cn } from '@/lib/utils'+import { useTitlebarLayout } from '@/stores/titlebar-layout-store'import { useLocation } from '@tanstack/react-router'import { isCoworkRoute, route } from '@/constants/routes'import { isCoworkEnabled } from '@/lib/version'@@ -27,11 +29,16 @@ export function LeftSidebar() {if (!inSettings && lastSurfacePath !== pathname) setLastSurfacePath(pathname)const surfacePath = inSettings ? lastSurfacePath : pathnameconst isCowork = isCoworkRoute(surfacePath) && isCoworkEnabled()+ // Right-align the header and hide "Jan" when native controls own the top-left+ // (macOS, or a Linux DE placing buttons left).+ const leftButtons = useTitlebarLayout((s) => s.layout.left.length)+ const reserveLeft = IS_MACOS || leftButtons > 0return (<div className='relative z-50'><Sidebar variant="floating" collapsible="offcanvas"><SidebarHeader className="flex px-1">- <div className="flex items-center w-full justify-end">+ <div className={cn("flex items-center w-full justify-between", reserveLeft && "justify-end")}>+ {!reserveLeft && <span className="ml-2 font-medium font-studio">Jan</span>}<div className="flex items-center">{isLeftPanelOpen && <DownloadManagement />}<SidebarTrigger className="text-muted-foreground rounded-full hover:bg-sidebar-foreground/8! -mt-0.5 relative z-50 ml-0.5" />