Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(web-app): keep token stats reachable in narrow columns

James Damdc77d8c7c058
diff --git a/web-app/src/containers/TokenSpeedIndicator.tsx b/web-app/src/containers/TokenSpeedIndicator.tsx
index 71b79d361..e818810f5 100644
--- a/web-app/src/containers/TokenSpeedIndicator.tsx
+++ b/web-app/src/containers/TokenSpeedIndicator.tsx
@@ -50,29 +50,7 @@ export const TokenSpeedIndicator = memo(
if (displaySpeed === 0 && displayTokenCount === 0) return null
- if (showTokenSpeed) {
- return (
- // The footer needs ~400px with the inline stats; in a narrower column
- // (small window, Cowork's docked rail) they are the first thing to go
- // rather than wrapping it. Queries the footer's @container. The
- // compact gauge below stays, so the numbers remain reachable.
- <div className="flex items-center gap-2 text-muted-foreground text-xs @max-md:hidden">
- {displaySpeed > 0 && (
- <div className="flex items-center gap-1">
- <Gauge size={16} />
- <span>{displaySpeed} tokens/s</span>
- </div>
- )}
- {displayTokenCount > 0 && (
- <span className="text-muted-foreground">
- ({displayTokenCount} tokens)
- </span>
- )}
- </div>
- )
- }
-
- return (
+ const compact = (
<Popover>
<PopoverTrigger asChild>
<button
@@ -107,6 +85,33 @@ export const TokenSpeedIndicator = memo(
</PopoverContent>
</Popover>
)
+
+ if (showTokenSpeed) {
+ return (
+ <>
+ {/* The footer needs ~400px with the inline stats; in a narrower
+ column (small window, Cowork's docked rail) they give way to the
+ compact gauge rather than wrapping it, so the numbers stay one
+ click away. Queries the footer's @container. */}
+ <div className="flex items-center gap-2 text-muted-foreground text-xs @max-md:hidden">
+ {displaySpeed > 0 && (
+ <div className="flex items-center gap-1">
+ <Gauge size={16} />
+ <span>{displaySpeed} tokens/s</span>
+ </div>
+ )}
+ {displayTokenCount > 0 && (
+ <span className="text-muted-foreground">
+ ({displayTokenCount} tokens)
+ </span>
+ )}
+ </div>
+ <div className="hidden @max-md:flex">{compact}</div>
+ </>
+ )
+ }
+
+ return compact
}
)
diff --git a/web-app/src/containers/__tests__/TokenSpeedIndicator.test.tsx b/web-app/src/containers/__tests__/TokenSpeedIndicator.test.tsx
new file mode 100644
index 000000000..9ecc7a69f
--- /dev/null
+++ b/web-app/src/containers/__tests__/TokenSpeedIndicator.test.tsx
@@ -0,0 +1,36 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { render, screen } from '@testing-library/react'
+
+const settingsRef = vi.hoisted(() => ({ showTokenSpeed: true }))
+vi.mock('@/hooks/useInterfaceSettings', () => ({
+ useInterfaceSettings: (selector: (s: typeof settingsRef) => unknown) =>
+ selector(settingsRef),
+}))
+
+import { TokenSpeedIndicator } from '../TokenSpeedIndicator'
+
+const metadata = { tokenSpeed: { tokenSpeed: 67.4, tokenCount: 229 } }
+
+describe('TokenSpeedIndicator', () => {
+ beforeEach(() => {
+ settingsRef.showTokenSpeed = true
+ })
+
+ it('shows inline stats, with the compact gauge as the narrow-column fallback', () => {
+ render(<TokenSpeedIndicator metadata={metadata} />)
+ const inline = screen.getByText('67 tokens/s').closest('div[class*="@max-md:hidden"]')
+ expect(inline).not.toBeNull()
+ // The gauge stays reachable when the inline stats give way.
+ const gauge = screen.getByRole('button', { name: 'Token speed details' })
+ expect(gauge.closest('div')?.className).toContain('@max-md:flex')
+ })
+
+ it('shows only the compact gauge when inline stats are off', () => {
+ settingsRef.showTokenSpeed = false
+ render(<TokenSpeedIndicator metadata={metadata} />)
+ expect(screen.queryByText('67 tokens/s')).not.toBeInTheDocument()
+ expect(
+ screen.getByRole('button', { name: 'Token speed details' })
+ ).toBeInTheDocument()
+ })
+})