From 1196583fe211dc20ce3ec57f6ff692660ea21f2e Mon Sep 17 00:00:00 2001 From: wsp Date: Wed, 18 Nov 2026 14:43:40 +0800 Subject: [PATCH] fix(ui): Hide the session canvas in Settings Show Settings on its own when it replaces a session beside the session canvas. Preserve the session tabs and pane state for when the user returns, and keep Settings compatible with split views alongside other selected pages. --- src/web-ui/src/app/layout/AppLayout.tsx | 25 ++++++++-- .../src/app/scenes/SceneViewport.test.tsx | 12 +++++ src/web-ui/src/app/scenes/SceneViewport.tsx | 9 ++-- src/web-ui/src/app/stores/sceneStore.ts | 8 +++- src/web-ui/src/app/workbench/README.md | 4 ++ .../app/workbench/WorkbenchLayout.test.tsx | 48 +++++++++++++++++++ .../src/app/workbench/WorkbenchLayout.tsx | 22 +++++---- .../src/app/workbench/scenePaneModel.ts | 7 +++ .../app/workbench/workbenchPaneLayoutStore.ts | 12 ++++- 9 files changed, 125 insertions(+), 22 deletions(-) diff --git a/src/web-ui/src/app/layout/AppLayout.tsx b/src/web-ui/src/app/layout/AppLayout.tsx index 108eafee35..d837c64630 100644 --- a/src/web-ui/src/app/layout/AppLayout.tsx +++ b/src/web-ui/src/app/layout/AppLayout.tsx @@ -46,9 +46,17 @@ import { AcpSessionNotifications } from './AcpSessionNotifications'; import { api } from '@/infrastructure/api/service-api/ApiClient'; import { AppearanceBackgroundMediaLayer, appearanceRuntime, useAppearance } from '@/infrastructure/appearance'; import { PeerConnectionStatus } from '@/infrastructure/peer-device/PeerConnectionStatus'; +import { useSceneStore } from '../stores/sceneStore'; +import { standaloneSettingsPane } from '../workbench/scenePaneModel'; +import { selectWorkbenchPaneHasSession, workbenchPaneLayoutStore } from '../workbench/workbenchPaneLayoutStore'; type TransitionDirection = 'entering' | 'returning' | null; +function isStandaloneSettingsActive(): boolean { + const { paneSelections } = useSceneStore.getState(); + return standaloneSettingsPane(paneSelections, selectWorkbenchPaneHasSession(workbenchPaneLayoutStore.getState())) !== null; +} + const log = createLogger('AppLayout'); const ToolbarMode = lazyWithRecovery(() => import('../../flow_chat/components/toolbar-mode/ToolbarMode').then(module => ({ @@ -116,6 +124,9 @@ const AppLayout: React.FC = ({ className = '' }) => { const { isFullscreenChrome } = useFullscreenChrome(isFullscreen); const { state, switchLeftPanelTab, toggleLeftPanel, toggleRightPanel } = useApp(); + const toggleAvailableRightPanel = useCallback(() => { + if (!isStandaloneSettingsActive()) toggleRightPanel(); + }, [toggleRightPanel]); const [windowModeHint, setWindowModeHint] = useState(null); const windowModeHintTimerRef = useRef(null); @@ -494,14 +505,14 @@ const AppLayout: React.FC = ({ className = '' }) => { const handleSwitchToFilesPanel = () => { switchLeftPanelTab('files'); if (state.layout.leftPanelCollapsed) toggleLeftPanel(); - if (state.layout.rightPanelCollapsed) { - setTimeout(() => toggleRightPanel(), 100); + if (state.layout.rightPanelCollapsed && !isStandaloneSettingsActive()) { + setTimeout(toggleAvailableRightPanel, 100); } }; window.addEventListener('switch-to-files-panel', handleSwitchToFilesPanel); return () => window.removeEventListener('switch-to-files-panel', handleSwitchToFilesPanel); - }, [state.layout.leftPanelCollapsed, state.layout.rightPanelCollapsed, switchLeftPanelTab, toggleLeftPanel, toggleRightPanel]); + }, [state.layout.leftPanelCollapsed, state.layout.rightPanelCollapsed, switchLeftPanelTab, toggleLeftPanel, toggleAvailableRightPanel]); // Toolbar send message React.useEffect(() => { @@ -534,13 +545,17 @@ const AppLayout: React.FC = ({ className = '' }) => { 'panel.toggleBoth', { key: 'B', ctrl: true, shift: true, scope: 'app' }, () => { + if (isStandaloneSettingsActive()) { + toggleLeftPanel(); + return; + } const bothCollapsed = state.layout.leftPanelCollapsed && state.layout.rightPanelCollapsed; if (bothCollapsed) { toggleLeftPanel(); - setTimeout(() => toggleRightPanel(), 50); + setTimeout(toggleAvailableRightPanel, 50); } else { if (!state.layout.leftPanelCollapsed) toggleLeftPanel(); - if (!state.layout.rightPanelCollapsed) toggleRightPanel(); + if (!state.layout.rightPanelCollapsed) toggleAvailableRightPanel(); } }, { priority: 5, description: 'keyboard.shortcuts.panel.toggleBoth' } diff --git a/src/web-ui/src/app/scenes/SceneViewport.test.tsx b/src/web-ui/src/app/scenes/SceneViewport.test.tsx index 3cc23c8cfb..82e90f03ef 100644 --- a/src/web-ui/src/app/scenes/SceneViewport.test.tsx +++ b/src/web-ui/src/app/scenes/SceneViewport.test.tsx @@ -208,6 +208,18 @@ describe('SceneViewport transitions', () => { expect(visibleScenes().map(scene => scene.getAttribute('data-scene-id'))).toEqual(['settings']); }); + it('activates standalone Settings in the secondary pane even when the session pane was collapsed', () => { + sessionPaneLayoutStore.getState().activate('local', 'session'); + sceneHarness.state = { + openTabs: [{ id: 'settings', lastUsed: 1, pane: 'secondary' }], + activeTabId: 'settings', navigationMotion: 'instant', navigationSequence: 1, + paneSelections: { primary: { kind: 'canvas' }, secondary: sceneSelection('settings') }, + }; + act(() => root.render()); + expect(container.querySelector('[data-testid="settings-scene-content"]')?.getAttribute('data-scene-prop-active')).toBe('true'); + expect(visibleScenes().map(scene => scene.getAttribute('data-scene-id'))).toEqual(['settings']); + }); + it('keeps a visible secondary Todos clock active even while another pane is focused', async () => { sessionPaneLayoutStore.getState().showContent(); sceneHarness.state = { diff --git a/src/web-ui/src/app/scenes/SceneViewport.tsx b/src/web-ui/src/app/scenes/SceneViewport.tsx index 591d290881..5583d62eb4 100644 --- a/src/web-ui/src/app/scenes/SceneViewport.tsx +++ b/src/web-ui/src/app/scenes/SceneViewport.tsx @@ -26,9 +26,9 @@ import { useSceneManager } from '../hooks/useSceneManager'; import { useI18n } from '@/infrastructure/i18n/hooks/useI18n'; import { useDialogCompletionNotify } from '../hooks/useDialogCompletionNotify'; import { Spinner, SplitViewSurface } from '@openbitfun/ui'; -import { selectedScene, tabPane } from '../workbench/scenePaneModel'; +import { selectedScene, standaloneSettingsPane, tabPane } from '../workbench/scenePaneModel'; +import { useWorkbenchPaneLayout, workbenchSplitMode } from '../workbench/workbenchPaneLayoutStore'; import { useSceneStore } from '../stores/sceneStore'; -import { useSessionPaneLayout } from './session/sessionPaneLayoutStore'; import SettingsScene from './settings/SettingsScene'; import { DEFAULT_SETTINGS_PAGE_ID, preloadSettingsPage } from './settings/settingsRegistry'; import { backgroundTaskScheduler } from '@/shared/utils/backgroundTaskScheduler'; @@ -161,7 +161,8 @@ const SceneViewport: React.FC = ({ workspacePath, isEntering } = useSceneManager(); const { t } = useI18n('common'); const resources = useContentResourceStore(state => state.resources); - const pane = useSessionPaneLayout(); + const { mode, hasSession } = useWorkbenchPaneLayout(); + const splitMode = paned ? workbenchSplitMode(mode, standaloneSettingsPane(paneSelections, hasSession)) : 'split'; const primaryTabId = paned ? selectedScene(paneSelections.primary) : activeTabId; const secondaryTabId = paned ? selectedScene(paneSelections.secondary) : null; const activeRenderedSceneId: RenderedSceneId | null = primaryTabId ? getSceneViewId(primaryTabId) @@ -204,7 +205,7 @@ const SceneViewport: React.FC = ({ workspacePath, isEntering const location = paned && isSecondary ? 'secondary' : 'primary'; const selectedId = location === 'secondary' ? secondarySceneId : activeRenderedSceneId; const transition = location === 'secondary' ? secondaryTransition : primaryTransition; - const paneVisible = !paned || (location === 'secondary' ? pane.mode !== 'chat-only' : pane.mode !== 'content-only'); + const paneVisible = splitMode === 'split' || splitMode === location; const isActive = tabId === selectedId && paneVisible; const isOutgoing = !isActive && tabId === transition.outgoingTabId; const isIncoming = isActive && transition.pendingTransition?.incomingTabId === tabId; diff --git a/src/web-ui/src/app/stores/sceneStore.ts b/src/web-ui/src/app/stores/sceneStore.ts index a391581790..9a46909de5 100644 --- a/src/web-ui/src/app/stores/sceneStore.ts +++ b/src/web-ui/src/app/stores/sceneStore.ts @@ -33,13 +33,14 @@ import { selectedSessionTab, selectCanvasInPane, selectSceneInPane, + standaloneSettingsPane, tabPane, vacantSelection, workbenchPanes, type ScenePaneState, type WorkbenchPane, } from '../workbench/scenePaneModel'; -import { sessionPaneLayoutStore } from '../scenes/session/sessionPaneLayoutStore'; +import { selectWorkbenchPaneHasSession, workbenchPaneLayoutStore } from '../workbench/workbenchPaneLayoutStore'; import { useContentResourceStore } from '../workbench/contentResourceStore'; import { requestContentClose } from '../workbench/contentResourceLifecycle'; import { requestMiniAppClose } from '../scenes/miniapps/miniAppLifecycle'; @@ -624,7 +625,10 @@ function navigateWorkbench(build: (state: SceneState) => WorkbenchNavigationPlan && useSceneStore.getState().paneSelections === previous.paneSelections; const commit = () => { if (!unchanged()) return false; - sessionPaneLayoutStore.getState().revealPanes(plan.reveal ?? [plan.panes.focusedPane]); + const paneLayout = workbenchPaneLayoutStore.getState(); + if (standaloneSettingsPane(plan.panes.paneSelections, selectWorkbenchPaneHasSession(paneLayout)) === null) { + paneLayout.revealPanes(plan.reveal ?? [plan.panes.focusedPane]); + } useSceneStore.setState({ ...projectPaneState(plan.panes), ...plan.history, pendingTabId: null, navigationMotion: plan.motion ?? getInteractionMotion(), navigationSequence: previous.navigationSequence + 1 }); options.onCommitted?.(); diff --git a/src/web-ui/src/app/workbench/README.md b/src/web-ui/src/app/workbench/README.md index 054788ae05..3481cae270 100644 --- a/src/web-ui/src/app/workbench/README.md +++ b/src/web-ui/src/app/workbench/README.md @@ -79,6 +79,10 @@ changing sessions cannot inherit a neighbour's pane or hide a moved page. The le retains old preference keys/legacy layout projection. The `session.auxiliary` Appearance address stays on the shell wrapper for legacy appearance customization. +When Settings replaces a conversation beside its canvas, it fills the workbench +and temporarily hides that canvas. The session keeps its tabs and remembered +pane mode. Settings can share the workbench with a scene selected in the other pane. + SceneTopBar owns both tab regions and the short separator. SplitView supplies the header's live column geometry, including clamping, resizing and overlay placement; header actions and native controls do not shift that boundary. The outer shell is diff --git a/src/web-ui/src/app/workbench/WorkbenchLayout.test.tsx b/src/web-ui/src/app/workbench/WorkbenchLayout.test.tsx index 84989f4139..5548ffef5d 100644 --- a/src/web-ui/src/app/workbench/WorkbenchLayout.test.tsx +++ b/src/web-ui/src/app/workbench/WorkbenchLayout.test.tsx @@ -9,6 +9,7 @@ import SessionPanelSettingsSection from '../scenes/settings/pages/application/Se import { useSceneStore, resetSceneStoreForTest } from '../stores/sceneStore'; import { getSessionSceneTabId } from '../components/SceneBar/types'; import { useWindowResizeLayout } from '../layout/windowResizeScheduler'; +import { activateSurface } from '@/infrastructure/peer-device/deviceSurface'; const mocks = vi.hoisted(() => ({ selectLayout: null as null | ((value: string) => void), terminalPosition: 'right' })); @@ -72,6 +73,7 @@ describe('workbench pane layout integration', () => { afterEach(() => { act(() => root.unmount()); + activateSurface('local'); useWindowResizeLayout.setState(useWindowResizeLayout.getInitialState()); container.remove(); sessionPaneLayoutStore.setState(sessionPaneLayoutStore.getInitialState()); @@ -254,4 +256,50 @@ describe('workbench pane layout integration', () => { expect(container.querySelector('iframe')).toBe(canvas); expect(host().getAttribute('data-split-surface')).toBe('secondary'); }); + + it.each([ + ['split', 'primary', 'local'], + ['overlay', 'secondary', 'peer:review'], + ] as const)('hides the session canvas beside Settings in %s layout with Settings in %s on %s', async (layout, settingsPane, surfaceId) => { + activateSurface(surfaceId); + const panes = sessionPaneLayoutStore.getState(); + const scenes = useSceneStore.getState(); + const target = { surfaceId, workspaceKey: 'project', sessionId: 'session' }; + panes.activate(target.surfaceId, target.sessionId); + panes.setDisplayMode(layout); + scenes.openScene('settings'); + await scenes.moveScene('settings', settingsPane); + scenes.openSessionScene(target); + await scenes.moveScene(getSessionSceneTabId(target), settingsPane); + scenes.revealCanvas(); + + act(() => root.render(
)); + const canvas = container.querySelector('iframe')!; + const host = canvas.closest('[data-split-surface]')!; + const savedModes = sessionPaneLayoutStore.getState().modes; + expect(split().getAttribute('data-mode')).toBe('split'); + expect(host.getAttribute('data-split-active')).toBe('true'); + + act(() => scenes.openScene('settings')); + expect(split().getAttribute('data-mode')).toBe(settingsPane); + expect(host.getAttribute('data-split-active')).toBe('false'); + expect(host.hasAttribute('hidden')).toBe(true); + expect(sessionPaneLayoutStore.getState().modes).toBe(savedModes); + + act(() => scenes.goBack()); + expect(split().getAttribute('data-mode')).toBe('split'); + expect(container.querySelector('iframe')).toBe(canvas); + expect(host.getAttribute('data-split-active')).toBe('true'); + }); + + it('keeps Settings and a deliberately split session visible together', async () => { + const scenes = useSceneStore.getState(); + sessionPaneLayoutStore.getState().activate('local', 'session'); + scenes.openSessionScene({ surfaceId: 'local', workspaceKey: 'project', sessionId: 'session' }); + scenes.openScene('settings'); + await scenes.moveScene('settings', 'secondary'); + + act(() => root.render(
)); + expect(split().getAttribute('data-mode')).toBe('split'); + }); }); diff --git a/src/web-ui/src/app/workbench/WorkbenchLayout.tsx b/src/web-ui/src/app/workbench/WorkbenchLayout.tsx index dc7fbd5c9f..2eccbdca0e 100644 --- a/src/web-ui/src/app/workbench/WorkbenchLayout.tsx +++ b/src/web-ui/src/app/workbench/WorkbenchLayout.tsx @@ -10,11 +10,11 @@ import { useSceneStore } from '../stores/sceneStore'; import { dropSceneTab, isSceneTabDrag } from './sceneTabTransfer'; import { dropSessionTabOnWorkbench, isSessionTabDrag } from './canvasTabTransfer'; import { observeTabDragLifecycle } from './tabDragLifecycle'; -import { selectedScene, type WorkbenchPane } from './scenePaneModel'; +import { selectedScene, standaloneSettingsPane, type WorkbenchPane } from './scenePaneModel'; import { SceneTopBar } from '../components/SceneTopBar'; import { CanvasToolbarHost, CanvasToolbarProvider } from '../components/panels/content-canvas/CanvasToolbar'; import AuxPane from '../scenes/session/AuxPane'; -import { useWorkbenchPaneLayout } from './workbenchPaneLayoutStore'; +import { useWorkbenchPaneLayout, workbenchSplitMode } from './workbenchPaneLayoutStore'; import { WorkbenchResizeContext } from './workbenchResize'; import { useWindowResizeLayout } from '../layout/windowResizeScheduler'; import { PANEL_COMMON_CONFIG, RIGHT_PANEL_CONFIG } from '../layout/panelConfig'; @@ -40,9 +40,11 @@ export default function WorkbenchLayout({ workspacePath, navigationResizing = fa }), [resizing, navigationResizing, settling, windowMeasurementSuspended]); const [offeredTab, setOfferedTab] = useState(false); const [dropTarget, setDropTarget] = useState<'leading' | 'trailing' | null>(null); - const panelOpen = pane.mode !== 'chat-only'; - const panelMaximized = pane.mode === 'content-only'; const selections = useSceneStore(state => state.paneSelections); + const settingsPane = standaloneSettingsPane(selections, pane.hasSession); + const mode = workbenchSplitMode(pane.mode, settingsPane); + const panelOpen = mode !== 'primary'; + const panelMaximized = mode === 'secondary'; const hasSecondaryScenes = useSceneStore(state => state.openTabs.some(tab => tab.pane === 'secondary')); const canvasPane = useSceneStore(state => state.canvasPane); const canvasActive = selections[canvasPane].kind === 'canvas'; @@ -66,9 +68,9 @@ export default function WorkbenchLayout({ workspacePath, navigationResizing = fa frame = requestAnimationFrame(() => setSettling(false)); }); return () => cancelAnimationFrame(frame); - }, [pane.mode, pane.contentSide, pane.displayMode, pane.preferredRightPaneWidth, pane.preferredOverlayWidth, navigationResizing]); + }, [mode, pane.contentSide, pane.displayMode, pane.preferredRightPaneWidth, pane.preferredOverlayWidth, navigationResizing]); const panelLabel = tCommon(panelOpen ? 'header.collapseRightPanel' : 'header.expandRightPanel'); - const maximizeLabel = t(pane.mode === 'content-only' ? 'canvas.restorePanel' : 'canvas.maximizePanel'); + const maximizeLabel = t(panelMaximized ? 'canvas.restorePanel' : 'canvas.maximizePanel'); const dropOnPane = (event: React.DragEvent, location: WorkbenchPane) => { if (!accepts(event.dataTransfer)) return; event.preventDefault(); @@ -119,10 +121,10 @@ export default function WorkbenchLayout({ workspacePath, navigationResizing = fa event.dataTransfer.dropEffect = 'move'; }} onPanelDrop={event => dropOnPane(event, trailingPane)} - panelToggle={ + panelToggle={settingsPane === null && {panelOpen && - } + } onClick={pane.toggleMaximized} /> } @@ -135,7 +137,7 @@ export default function WorkbenchLayout({ workspacePath, navigationResizing = fa return
pane === 'prima export const sceneSelection = (tabId: SceneTabId): PaneSelection => ({ kind: 'scene', tabId }); export const selectedScene = (selection: PaneSelection): SceneTabId | null => selection.kind === 'scene' ? selection.tabId : null; +/** Settings fills its pane when the only other selection is the session canvas. */ +export function standaloneSettingsPane(selections: PaneSelections, hasSession: boolean): WorkbenchPane | null { + if (!hasSession) return null; + return workbenchPanes.find(pane => selectedScene(selections[pane]) === 'settings' + && selections[otherPane(pane)].kind === 'canvas') ?? null; +} + export interface ScenePaneState { openTabs: SceneTab[]; paneSelections: PaneSelections; diff --git a/src/web-ui/src/app/workbench/workbenchPaneLayoutStore.ts b/src/web-ui/src/app/workbench/workbenchPaneLayoutStore.ts index 43e1a7a855..8932127fea 100644 --- a/src/web-ui/src/app/workbench/workbenchPaneLayoutStore.ts +++ b/src/web-ui/src/app/workbench/workbenchPaneLayoutStore.ts @@ -1,5 +1,6 @@ import { createStore } from 'zustand/vanilla'; import { useStore } from 'zustand'; +import type { SplitViewMode } from '@openbitfun/ui'; import { surfaceScopedKey } from '@/infrastructure/peer-device/deviceSurface'; import { RIGHT_PANEL_CONFIG, STORAGE_KEYS } from '../layout/panelConfig'; import type { WorkbenchPane } from './scenePaneModel'; @@ -55,10 +56,18 @@ const DISPLAY_MODE_KEY = 'openbitfun:sessionPaneDisplayMode'; const OVERLAY_WIDTH_KEY = 'openbitfun:sessionOverlayWidth'; const scopeKey = (surfaceId: string, sessionId: string | null) => surfaceScopedKey(surfaceId, sessionId); +export const selectWorkbenchPaneHasSession = (state: WorkbenchPaneLayoutState): boolean => ( + state.activeKey !== scopeKey(state.surfaceId, null) +); + export const selectWorkbenchPaneMode = (state: WorkbenchPaneLayoutState): SessionPaneMode => ( state.modes.get(state.activeKey) ?? 'chat-only' ); +export function workbenchSplitMode(mode: SessionPaneMode, standalonePane: WorkbenchPane | null): SplitViewMode { + return standalonePane ?? (mode === 'chat-only' ? 'primary' : mode === 'content-only' ? 'secondary' : 'split'); +} + export function projectLegacySessionPaneLayout(state: WorkbenchPaneLayoutState): LegacySessionPaneLayout { const mode = selectWorkbenchPaneMode(state); return { @@ -195,11 +204,12 @@ export type WorkbenchPaneLayoutStore = ReturnType state.contentSide); const preferredRightPaneWidth = useStore(workbenchPaneLayoutStore, state => state.preferredRightPaneWidth); const displayMode = useStore(workbenchPaneLayoutStore, state => state.displayMode); const preferredOverlayWidth = useStore(workbenchPaneLayoutStore, state => state.preferredOverlayWidth); const { showContent, hideContent, toggleContent, toggleMaximized, swapPanes, resizeRightPane, resizeOverlay } = workbenchPaneLayoutStore.getState(); - return { mode, contentSide, displayMode, preferredOverlayWidth, preferredRightPaneWidth, + return { mode, hasSession, contentSide, displayMode, preferredOverlayWidth, preferredRightPaneWidth, showContent, hideContent, toggleContent, toggleMaximized, swapPanes, resizeRightPane, resizeOverlay }; }