Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(desktop-app): collapse sidebar when an embedded app opens
Diego Zacariasa1c4257b492d
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex 1bd3d8f4b..de1c4c0ea 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -250,6 +250,13 @@ export function App() {const [sidebarCollapsed, setSidebarCollapsed] = React.useState<boolean>(getInitialSidebarCollapsed)+ const sidebarCollapsedRef = React.useRef(sidebarCollapsed)+ sidebarCollapsedRef.current = sidebarCollapsed+ // When opening an app auto-collapses the sidebar, this remembers the user's+ // prior state so closing the app can restore it. `null` = no app-driven+ // collapse is in effect (no app open, or the user has since taken manual+ // control of the sidebar while an app was open).+ const sidebarCollapsedBeforeAppRef = React.useRef<boolean | null>(null)const [activeSandboxUiApp, setActiveSandboxUiApp] = React.useState<ActiveSandboxUiApp | null>(null)@@ -659,13 +666,39 @@ export function App() {void window.clerum.pluginSdk?.setTheme?.(themeMode)?.catch?.(() => undefined)}, [themeMode])- React.useEffect(() => {+ // Persist only user-driven sidebar changes. Auto-collapse on app open (and the+ // restore on close) is ephemeral and must not overwrite the saved preference.+ const handleSidebarCollapsedChange = React.useCallback((next: boolean) => {+ // The user took manual control: their choice wins for the rest of the app+ // session, and closing the app must not override it.+ sidebarCollapsedBeforeAppRef.current = null+ setSidebarCollapsed(next)try {- window.localStorage.setItem(SIDEBAR_COLLAPSED_KEY, sidebarCollapsed ? '1' : '0')+ window.localStorage.setItem(SIDEBAR_COLLAPSED_KEY, next ? '1' : '0')} catch {// Ignore storage failures in restricted environments.}- }, [sidebarCollapsed])+ }, [])++ // Opening an app collapses the sidebar to hand the app more workspace; closing+ // it restores whatever the sidebar was before — unless the user manually+ // toggled the sidebar while the app was open, in which case their choice+ // stands (see handleSidebarCollapsedChange). Keyed on the open/closed edge so+ // switching directly between apps neither re-collapses nor re-remembers.+ const isSandboxUiAppOpen = Boolean(activeSandboxUiApp)+ React.useEffect(() => {+ if (isSandboxUiAppOpen) {+ if (sidebarCollapsedBeforeAppRef.current === null) {+ sidebarCollapsedBeforeAppRef.current = sidebarCollapsedRef.current+ setSidebarCollapsed(true)+ }+ return+ }+ if (sidebarCollapsedBeforeAppRef.current !== null) {+ setSidebarCollapsed(sidebarCollapsedBeforeAppRef.current)+ sidebarCollapsedBeforeAppRef.current = null+ }+ }, [isSandboxUiAppOpen])React.useEffect(() => {void window.clerum.app.rendererReady().catch(error => {@@ -2002,7 +2035,7 @@ export function App() {activeSandboxUiApp={activeSandboxUiApp}availableSandboxUiApps={availableSandboxUiApps}collapsed={sidebarCollapsed}- onCollapsedChange={setSidebarCollapsed}+ onCollapsedChange={handleSidebarCollapsedChange}onNewChat={handleNewChatViewTab}onOpenSandboxUiApp={handleOpenSandboxUiApp}onSettingsMenuOpenChange={setSidebarSettingsMenuOpen}diff --git a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsxindex 107bc742d..964568d3c 100644--- a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx+++ b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx@@ -1,7 +1,7 @@// @vitest-environment jsdomimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { act, render, waitFor } from '@testing-library/react'-import { DESKTOP_ROUTES } from '@constants/navigation'+import { DESKTOP_ROUTES, SIDEBAR_COLLAPSED_KEY } from '@constants/navigation'import { useAppController } from '@hooks/useAppController'import { App } from '@/App'import type { SandboxUiDeepLinkEnvelope } from '@/App.types'@@ -31,7 +31,11 @@ const commandPaletteHarness = vi.hoisted(() => ({}))const sidebarHarness = vi.hoisted(() => ({- props: null as null | { toggleRequestId?: number },+ props: null as null | {+ toggleRequestId?: number+ collapsed?: boolean+ onCollapsedChange?: (next: boolean) => void+ },}))const sandboxUiPageHarness = vi.hoisted(() => ({@@ -51,6 +55,8 @@ const sandboxUiPageHarness = vi.hoisted(() => ({routePath?: string}) => voidonEmbeddedAppMounted?: () => void+ onEmbeddedAppBack?: () => void+ onEmbeddedAppRemoved?: () => voidonShortcutOpenResult?: (requestId: number,result: { status: 'mounted' } | { status: 'failed'; message: string }@@ -269,6 +275,117 @@ describe('App deep-link orchestration', () => {})})+ it('collapses the sidebar when an app opens and restores it when the app closes', () => {+ window.localStorage.clear()+ currentController = makeController({+ initialExperienceLoading: false,+ navItem: DESKTOP_ROUTES.apps,+ } as Partial<AppController>)+ render(<App />)+ expect(sidebarHarness.props?.collapsed).toBe(false)++ act(() => {+ sandboxUiPageHarness.props?.onEmbeddedAppOpening?.({+ appRef: 'ns/app',+ label: 'App',+ defaultPath: '/',+ })+ })+ expect(sidebarHarness.props?.collapsed).toBe(true)+ // Auto-collapse is ephemeral: it must not overwrite the saved preference.+ expect(window.localStorage.getItem(SIDEBAR_COLLAPSED_KEY)).toBeNull()++ act(() => sandboxUiPageHarness.props?.onEmbeddedAppBack?.())+ expect(sidebarHarness.props?.collapsed).toBe(false)+ })++ it('lets a manual sidebar toggle win while an app is open', () => {+ window.localStorage.clear()+ currentController = makeController({+ initialExperienceLoading: false,+ navItem: DESKTOP_ROUTES.apps,+ } as Partial<AppController>)+ render(<App />)++ act(() => {+ sandboxUiPageHarness.props?.onEmbeddedAppOpening?.({+ appRef: 'ns/app',+ label: 'App',+ defaultPath: '/',+ })+ })+ expect(sidebarHarness.props?.collapsed).toBe(true)++ // The user expands the sidebar back while the app is still open.+ act(() => sidebarHarness.props?.onCollapsedChange?.(false))+ expect(sidebarHarness.props?.collapsed).toBe(false)+ // A manual toggle is user-driven, so it persists.+ expect(window.localStorage.getItem(SIDEBAR_COLLAPSED_KEY)).toBe('0')++ // Closing the app must not override the user's manual choice.+ act(() => sandboxUiPageHarness.props?.onEmbeddedAppBack?.())+ expect(sidebarHarness.props?.collapsed).toBe(false)+ })++ it('keeps a manual expand when switching directly between apps', () => {+ window.localStorage.clear()+ currentController = makeController({+ initialExperienceLoading: false,+ navItem: DESKTOP_ROUTES.apps,+ } as Partial<AppController>)+ render(<App />)++ act(() => {+ sandboxUiPageHarness.props?.onEmbeddedAppOpening?.({+ appRef: 'ns/app-a',+ label: 'App A',+ defaultPath: '/',+ })+ })+ expect(sidebarHarness.props?.collapsed).toBe(true)++ // The user expands the sidebar back while app A is open.+ act(() => sidebarHarness.props?.onCollapsedChange?.(false))+ expect(sidebarHarness.props?.collapsed).toBe(false)+ expect(window.localStorage.getItem(SIDEBAR_COLLAPSED_KEY)).toBe('0')++ // Switching straight to another app keeps the open/closed edge unchanged, so+ // the auto-collapse effect must not re-collapse nor re-remember: the manual+ // expand stands.+ act(() => {+ sandboxUiPageHarness.props?.onEmbeddedAppOpening?.({+ appRef: 'ns/app-b',+ label: 'App B',+ defaultPath: '/',+ })+ })+ expect(sidebarHarness.props?.collapsed).toBe(false)+ expect(window.localStorage.getItem(SIDEBAR_COLLAPSED_KEY)).toBe('0')+ })++ it('restores a saved collapsed preference after an app closes', () => {+ window.localStorage.clear()+ window.localStorage.setItem(SIDEBAR_COLLAPSED_KEY, '1')+ currentController = makeController({+ initialExperienceLoading: false,+ navItem: DESKTOP_ROUTES.apps,+ } as Partial<AppController>)+ render(<App />)+ expect(sidebarHarness.props?.collapsed).toBe(true)++ act(() => {+ sandboxUiPageHarness.props?.onEmbeddedAppOpening?.({+ appRef: 'ns/app',+ label: 'App',+ defaultPath: '/',+ })+ })+ expect(sidebarHarness.props?.collapsed).toBe(true)++ act(() => sandboxUiPageHarness.props?.onEmbeddedAppRemoved?.())+ expect(sidebarHarness.props?.collapsed).toBe(true)+ })+it('runs registered new-tab and composer-focus commands through existing chat selection', () => {currentController = makeController({initialExperienceLoading: false,